am 9af53ea6: am 3161795b: when logging free space on /data, log /system and /cache as well

Merge commit '9af53ea6ef9a986bc65bcd11deb7994f1f4ba8ec' into eclair-mr2

* commit '9af53ea6ef9a986bc65bcd11deb7994f1f4ba8ec':
  when logging free space on /data, log /system and /cache as well
This commit is contained in:
Doug Zongker
2009-10-07 18:24:03 -07:00
committed by Android Git Automerger

View File

@@ -68,19 +68,22 @@ class DeviceStorageMonitorService extends Binder {
private static final int EVENT_LOG_FREE_STORAGE_LEFT = 2746; private static final int EVENT_LOG_FREE_STORAGE_LEFT = 2746;
private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB
private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000; private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000;
private long mFreeMem; private long mFreeMem; // on /data
private long mLastReportedFreeMem; private long mLastReportedFreeMem;
private long mLastReportedFreeMemTime; private long mLastReportedFreeMemTime;
private boolean mLowMemFlag=false; private boolean mLowMemFlag=false;
private Context mContext; private Context mContext;
private ContentResolver mContentResolver; private ContentResolver mContentResolver;
long mBlkSize; private long mTotalMemory; // on /data
long mTotalMemory; private StatFs mDataFileStats;
StatFs mFileStats; private StatFs mSystemFileStats;
private static final String DATA_PATH="/data"; private StatFs mCacheFileStats;
long mThreadStartTime = -1; private static final String DATA_PATH = "/data";
boolean mClearSucceeded = false; private static final String SYSTEM_PATH = "/system";
boolean mClearingCache; private static final String CACHE_PATH = "/cache";
private long mThreadStartTime = -1;
private boolean mClearSucceeded = false;
private boolean mClearingCache;
private Intent mStorageLowIntent; private Intent mStorageLowIntent;
private Intent mStorageOkIntent; private Intent mStorageOkIntent;
private CachePackageDataObserver mClearCacheObserver; private CachePackageDataObserver mClearCacheObserver;
@@ -119,8 +122,13 @@ class DeviceStorageMonitorService extends Binder {
} }
private final void restatDataDir() { private final void restatDataDir() {
mFileStats.restat(DATA_PATH); try {
mFreeMem = mFileStats.getAvailableBlocks()*mBlkSize; mDataFileStats.restat(DATA_PATH);
mFreeMem = (long) mDataFileStats.getAvailableBlocks() *
mDataFileStats.getBlockSize();
} catch (IllegalArgumentException e) {
// use the old value of mFreeMem
}
// Allow freemem to be overridden by debug.freemem for testing // Allow freemem to be overridden by debug.freemem for testing
String debugFreeMem = SystemProperties.get("debug.freemem"); String debugFreeMem = SystemProperties.get("debug.freemem");
if (!"".equals(debugFreeMem)) { if (!"".equals(debugFreeMem)) {
@@ -133,9 +141,26 @@ class DeviceStorageMonitorService extends Binder {
//log the amount of free memory in event log //log the amount of free memory in event log
long currTime = SystemClock.elapsedRealtime(); long currTime = SystemClock.elapsedRealtime();
if((mLastReportedFreeMemTime == 0) || if((mLastReportedFreeMemTime == 0) ||
(currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) { (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) {
mLastReportedFreeMemTime = currTime; mLastReportedFreeMemTime = currTime;
EventLog.writeEvent(EVENT_LOG_FREE_STORAGE_LEFT, mFreeMem); long mFreeSystem = -1, mFreeCache = -1;
try {
mSystemFileStats.restat(SYSTEM_PATH);
mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() *
mSystemFileStats.getBlockSize();
} catch (IllegalArgumentException e) {
// ignore; report -1
}
try {
mCacheFileStats.restat(CACHE_PATH);
mFreeCache = (long) mCacheFileStats.getAvailableBlocks() *
mCacheFileStats.getBlockSize();
} catch (IllegalArgumentException e) {
// ignore; report -1
}
mCacheFileStats.restat(CACHE_PATH);
EventLog.writeEvent(EVENT_LOG_FREE_STORAGE_LEFT,
mFreeMem, mFreeSystem, mFreeCache);
} }
// Read the reporting threshold from Gservices // Read the reporting threshold from Gservices
long threshold = Gservices.getLong(mContentResolver, long threshold = Gservices.getLong(mContentResolver,
@@ -247,11 +272,12 @@ class DeviceStorageMonitorService extends Binder {
mContext = context; mContext = context;
mContentResolver = mContext.getContentResolver(); mContentResolver = mContext.getContentResolver();
//create StatFs object //create StatFs object
mFileStats = new StatFs(DATA_PATH); mDataFileStats = new StatFs(DATA_PATH);
//initialize block size mSystemFileStats = new StatFs(SYSTEM_PATH);
mBlkSize = mFileStats.getBlockSize(); mCacheFileStats = new StatFs(CACHE_PATH);
//initialize total storage on device //initialize total storage on device
mTotalMemory = ((long)mFileStats.getBlockCount()*mBlkSize)/100L; mTotalMemory = ((long)mDataFileStats.getBlockCount() *
mDataFileStats.getBlockSize())/100L;
mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW); mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW);
mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK); mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK);
checkMemory(true); checkMemory(true);