Loading services/java/com/android/server/DeviceStorageMonitorService.java +65 −39 Original line number Diff line number Diff line Loading @@ -68,19 +68,22 @@ class DeviceStorageMonitorService extends Binder { 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_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000; private long mFreeMem; private long mFreeMem; // on /data private long mLastReportedFreeMem; private long mLastReportedFreeMemTime; private boolean mLowMemFlag=false; private Context mContext; private ContentResolver mContentResolver; long mBlkSize; long mTotalMemory; StatFs mFileStats; private long mTotalMemory; // on /data private StatFs mDataFileStats; private StatFs mSystemFileStats; private StatFs mCacheFileStats; private static final String DATA_PATH = "/data"; long mThreadStartTime = -1; boolean mClearSucceeded = false; boolean mClearingCache; private static final String SYSTEM_PATH = "/system"; private static final String CACHE_PATH = "/cache"; private long mThreadStartTime = -1; private boolean mClearSucceeded = false; private boolean mClearingCache; private Intent mStorageLowIntent; private Intent mStorageOkIntent; private CachePackageDataObserver mClearCacheObserver; Loading Loading @@ -119,8 +122,13 @@ class DeviceStorageMonitorService extends Binder { } private final void restatDataDir() { mFileStats.restat(DATA_PATH); mFreeMem = mFileStats.getAvailableBlocks()*mBlkSize; try { 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 String debugFreeMem = SystemProperties.get("debug.freemem"); if (!"".equals(debugFreeMem)) { Loading @@ -135,7 +143,24 @@ class DeviceStorageMonitorService extends Binder { if((mLastReportedFreeMemTime == 0) || (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) { 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 long threshold = Gservices.getLong(mContentResolver, Loading Loading @@ -247,11 +272,12 @@ class DeviceStorageMonitorService extends Binder { mContext = context; mContentResolver = mContext.getContentResolver(); //create StatFs object mFileStats = new StatFs(DATA_PATH); //initialize block size mBlkSize = mFileStats.getBlockSize(); mDataFileStats = new StatFs(DATA_PATH); mSystemFileStats = new StatFs(SYSTEM_PATH); mCacheFileStats = new StatFs(CACHE_PATH); //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); mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK); checkMemory(true); Loading Loading
services/java/com/android/server/DeviceStorageMonitorService.java +65 −39 Original line number Diff line number Diff line Loading @@ -68,19 +68,22 @@ class DeviceStorageMonitorService extends Binder { 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_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000; private long mFreeMem; private long mFreeMem; // on /data private long mLastReportedFreeMem; private long mLastReportedFreeMemTime; private boolean mLowMemFlag=false; private Context mContext; private ContentResolver mContentResolver; long mBlkSize; long mTotalMemory; StatFs mFileStats; private long mTotalMemory; // on /data private StatFs mDataFileStats; private StatFs mSystemFileStats; private StatFs mCacheFileStats; private static final String DATA_PATH = "/data"; long mThreadStartTime = -1; boolean mClearSucceeded = false; boolean mClearingCache; private static final String SYSTEM_PATH = "/system"; private static final String CACHE_PATH = "/cache"; private long mThreadStartTime = -1; private boolean mClearSucceeded = false; private boolean mClearingCache; private Intent mStorageLowIntent; private Intent mStorageOkIntent; private CachePackageDataObserver mClearCacheObserver; Loading Loading @@ -119,8 +122,13 @@ class DeviceStorageMonitorService extends Binder { } private final void restatDataDir() { mFileStats.restat(DATA_PATH); mFreeMem = mFileStats.getAvailableBlocks()*mBlkSize; try { 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 String debugFreeMem = SystemProperties.get("debug.freemem"); if (!"".equals(debugFreeMem)) { Loading @@ -135,7 +143,24 @@ class DeviceStorageMonitorService extends Binder { if((mLastReportedFreeMemTime == 0) || (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) { 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 long threshold = Gservices.getLong(mContentResolver, Loading Loading @@ -247,11 +272,12 @@ class DeviceStorageMonitorService extends Binder { mContext = context; mContentResolver = mContext.getContentResolver(); //create StatFs object mFileStats = new StatFs(DATA_PATH); //initialize block size mBlkSize = mFileStats.getBlockSize(); mDataFileStats = new StatFs(DATA_PATH); mSystemFileStats = new StatFs(SYSTEM_PATH); mCacheFileStats = new StatFs(CACHE_PATH); //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); mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK); checkMemory(true); Loading