The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 17 | package com.android.server.storage; |
| 18 | |
| 19 | import com.android.server.EventLogTags; |
| 20 | import com.android.server.SystemService; |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 21 | import com.android.server.pm.InstructionSets; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.app.Notification; |
| 23 | import android.app.NotificationManager; |
| 24 | import android.app.PendingIntent; |
| 25 | import android.content.ContentResolver; |
| 26 | import android.content.Context; |
| 27 | import android.content.Intent; |
| 28 | import android.content.pm.IPackageDataObserver; |
| 29 | import android.content.pm.IPackageManager; |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 30 | import android.content.pm.PackageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.Binder; |
Dianne Hackborn | f882efa | 2012-04-11 16:04:12 -0700 | [diff] [blame] | 32 | import android.os.Environment; |
Jeff Sharkey | 4b49657 | 2012-04-19 14:17:03 -0700 | [diff] [blame] | 33 | import android.os.FileObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.os.Handler; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 35 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.os.Message; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.RemoteException; |
| 38 | import android.os.ServiceManager; |
| 39 | import android.os.StatFs; |
| 40 | import android.os.SystemClock; |
| 41 | import android.os.SystemProperties; |
Dianne Hackborn | 5ac72a2 | 2012-08-29 18:32:08 -0700 | [diff] [blame] | 42 | import android.os.UserHandle; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 43 | import android.os.storage.StorageManager; |
Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 44 | import android.provider.Settings; |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 45 | import android.text.format.Formatter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.util.EventLog; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 47 | import android.util.Slog; |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 48 | import android.util.TimeUtils; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 50 | import java.io.File; |
| 51 | import java.io.FileDescriptor; |
| 52 | import java.io.PrintWriter; |
| 53 | |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 54 | import dalvik.system.VMRuntime; |
| 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | /** |
Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 57 | * This class implements a service to monitor the amount of disk |
| 58 | * storage space on the device. If the free storage on device is less |
| 59 | * than a tunable threshold value (a secure settings parameter; |
| 60 | * default 10%) a low memory notification is displayed to alert the |
| 61 | * user. If the user clicks on the low memory notification the |
| 62 | * Application Manager application gets launched to let the user free |
| 63 | * storage space. |
| 64 | * |
| 65 | * Event log events: A low memory event with the free storage on |
| 66 | * device in bytes is logged to the event log when the device goes low |
| 67 | * on storage space. The amount of free storage on the device is |
| 68 | * periodically logged to the event log. The log interval is a secure |
| 69 | * settings parameter with a default value of 12 hours. When the free |
| 70 | * storage differential goes below a threshold (again a secure |
| 71 | * settings parameter with a default value of 2MB), the free memory is |
| 72 | * logged to the event log. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 74 | public class DeviceStorageMonitorService extends SystemService { |
| 75 | static final String TAG = "DeviceStorageMonitorService"; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 76 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 77 | static final boolean DEBUG = false; |
| 78 | static final boolean localLOGV = false; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 79 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 80 | static final int DEVICE_MEMORY_WHAT = 1; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | private static final int MONITOR_INTERVAL = 1; //in minutes |
| 82 | private static final int LOW_MEMORY_NOTIFICATION_ID = 1; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 83 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | private static final int DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES = 12*60; //in minutes |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB |
| 86 | private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 87 | |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 88 | private long mFreeMem; // on /data |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 89 | private long mFreeMemAfterLastCacheClear; // on /data |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | private long mLastReportedFreeMem; |
| 91 | private long mLastReportedFreeMemTime; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 92 | boolean mLowMemFlag=false; |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 93 | private boolean mMemFullFlag=false; |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 94 | private final boolean mIsBootImageOnDisk; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 95 | private final ContentResolver mResolver; |
| 96 | private final long mTotalMemory; // on /data |
| 97 | private final StatFs mDataFileStats; |
| 98 | private final StatFs mSystemFileStats; |
| 99 | private final StatFs mCacheFileStats; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 100 | |
| 101 | private static final File DATA_PATH = Environment.getDataDirectory(); |
| 102 | private static final File SYSTEM_PATH = Environment.getRootDirectory(); |
| 103 | private static final File CACHE_PATH = Environment.getDownloadCacheDirectory(); |
| 104 | |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 105 | private long mThreadStartTime = -1; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 106 | boolean mClearSucceeded = false; |
| 107 | boolean mClearingCache; |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 108 | private final Intent mStorageLowIntent; |
| 109 | private final Intent mStorageOkIntent; |
| 110 | private final Intent mStorageFullIntent; |
| 111 | private final Intent mStorageNotFullIntent; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | private CachePackageDataObserver mClearCacheObserver; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 113 | private CacheFileDeletedObserver mCacheFileDeletedObserver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 114 | private static final int _TRUE = 1; |
| 115 | private static final int _FALSE = 0; |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 116 | // This is the raw threshold that has been set at which we consider |
| 117 | // storage to be low. |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 118 | long mMemLowThreshold; |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 119 | // This is the threshold at which we start trying to flush caches |
| 120 | // to get below the low threshold limit. It is less than the low |
| 121 | // threshold; we will allow storage to get a bit beyond the limit |
| 122 | // before flushing and checking if we are actually low. |
| 123 | private long mMemCacheStartTrimThreshold; |
| 124 | // This is the threshold that we try to get to when deleting cache |
| 125 | // files. This is greater than the low threshold so that we will flush |
| 126 | // more files than absolutely needed, to reduce the frequency that |
| 127 | // flushing takes place. |
| 128 | private long mMemCacheTrimToThreshold; |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 129 | private long mMemFullThreshold; |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 130 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | /** |
| 132 | * This string is used for ServiceManager access to this class. |
| 133 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 134 | static final String SERVICE = "devicestoragemonitor"; |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 135 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | /** |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 137 | * Handler that checks the amount of disk space on the device and sends a |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | * notification if the device runs low on disk space |
| 139 | */ |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 140 | private final Handler mHandler = new Handler() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 141 | @Override |
| 142 | public void handleMessage(Message msg) { |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 143 | //don't handle an invalid message |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 144 | if (msg.what != DEVICE_MEMORY_WHAT) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 145 | Slog.e(TAG, "Will not process invalid message"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | return; |
| 147 | } |
| 148 | checkMemory(msg.arg1 == _TRUE); |
| 149 | } |
| 150 | }; |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 151 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 152 | private class CachePackageDataObserver extends IPackageDataObserver.Stub { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 153 | public void onRemoveCompleted(String packageName, boolean succeeded) { |
| 154 | mClearSucceeded = succeeded; |
| 155 | mClearingCache = false; |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 156 | if(localLOGV) Slog.i(TAG, " Clear succeeded:"+mClearSucceeded |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | +", mClearingCache:"+mClearingCache+" Forcing memory check"); |
| 158 | postCheckMemoryMsg(false, 0); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 159 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 161 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 162 | private void restatDataDir() { |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 163 | try { |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 164 | mDataFileStats.restat(DATA_PATH.getAbsolutePath()); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 165 | mFreeMem = (long) mDataFileStats.getAvailableBlocks() * |
| 166 | mDataFileStats.getBlockSize(); |
| 167 | } catch (IllegalArgumentException e) { |
| 168 | // use the old value of mFreeMem |
| 169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | // Allow freemem to be overridden by debug.freemem for testing |
| 171 | String debugFreeMem = SystemProperties.get("debug.freemem"); |
| 172 | if (!"".equals(debugFreeMem)) { |
| 173 | mFreeMem = Long.parseLong(debugFreeMem); |
| 174 | } |
Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 175 | // Read the log interval from secure settings |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 176 | long freeMemLogInterval = Settings.Global.getLong(mResolver, |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 177 | Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 178 | DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000; |
| 179 | //log the amount of free memory in event log |
| 180 | long currTime = SystemClock.elapsedRealtime(); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 181 | if((mLastReportedFreeMemTime == 0) || |
| 182 | (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | mLastReportedFreeMemTime = currTime; |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 184 | long mFreeSystem = -1, mFreeCache = -1; |
| 185 | try { |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 186 | mSystemFileStats.restat(SYSTEM_PATH.getAbsolutePath()); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 187 | mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() * |
| 188 | mSystemFileStats.getBlockSize(); |
| 189 | } catch (IllegalArgumentException e) { |
| 190 | // ignore; report -1 |
| 191 | } |
| 192 | try { |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 193 | mCacheFileStats.restat(CACHE_PATH.getAbsolutePath()); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 194 | mFreeCache = (long) mCacheFileStats.getAvailableBlocks() * |
| 195 | mCacheFileStats.getBlockSize(); |
| 196 | } catch (IllegalArgumentException e) { |
| 197 | // ignore; report -1 |
| 198 | } |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 199 | EventLog.writeEvent(EventLogTags.FREE_STORAGE_LEFT, |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 200 | mFreeMem, mFreeSystem, mFreeCache); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 201 | } |
Doug Zongker | 43866e0 | 2010-01-07 12:09:54 -0800 | [diff] [blame] | 202 | // Read the reporting threshold from secure settings |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 203 | long threshold = Settings.Global.getLong(mResolver, |
Jeff Sharkey | 625239a | 2012-09-26 22:03:49 -0700 | [diff] [blame] | 204 | Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD); |
| 206 | // If mFree changed significantly log the new value |
| 207 | long delta = mFreeMem - mLastReportedFreeMem; |
| 208 | if (delta > threshold || delta < -threshold) { |
| 209 | mLastReportedFreeMem = mFreeMem; |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 210 | EventLog.writeEvent(EventLogTags.FREE_STORAGE_CHANGED, mFreeMem); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | } |
| 212 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 213 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 214 | private void clearCache() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | if (mClearCacheObserver == null) { |
| 216 | // Lazy instantiation |
| 217 | mClearCacheObserver = new CachePackageDataObserver(); |
| 218 | } |
| 219 | mClearingCache = true; |
| 220 | try { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 221 | if (localLOGV) Slog.i(TAG, "Clearing cache"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | IPackageManager.Stub.asInterface(ServiceManager.getService("package")). |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 223 | freeStorageAndNotify(mMemCacheTrimToThreshold, mClearCacheObserver); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | } catch (RemoteException e) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 225 | Slog.w(TAG, "Failed to get handle for PackageManger Exception: "+e); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | mClearingCache = false; |
| 227 | mClearSucceeded = false; |
| 228 | } |
| 229 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 230 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 231 | void checkMemory(boolean checkCache) { |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 232 | //if the thread that was started to clear cache is still running do nothing till its |
| 233 | //finished clearing cache. Ideally this flag could be modified by clearCache |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | // and should be accessed via a lock but even if it does this test will fail now and |
| 235 | //hopefully the next time this flag will be set to the correct value. |
| 236 | if(mClearingCache) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 237 | if(localLOGV) Slog.i(TAG, "Thread already running just skip"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 238 | //make sure the thread is not hung for too long |
| 239 | long diffTime = System.currentTimeMillis() - mThreadStartTime; |
| 240 | if(diffTime > (10*60*1000)) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 241 | Slog.w(TAG, "Thread that clears cache file seems to run for ever"); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 242 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } else { |
| 244 | restatDataDir(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 245 | if (localLOGV) Slog.v(TAG, "freeMemory="+mFreeMem); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 246 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 247 | //post intent to NotificationManager to display icon if necessary |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 248 | if (mFreeMem < mMemLowThreshold) { |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 249 | if (checkCache) { |
| 250 | // We are allowed to clear cache files at this point to |
| 251 | // try to get down below the limit, because this is not |
| 252 | // the initial call after a cache clear has been attempted. |
| 253 | // In this case we will try a cache clear if our free |
| 254 | // space has gone below the cache clear limit. |
| 255 | if (mFreeMem < mMemCacheStartTrimThreshold) { |
| 256 | // We only clear the cache if the free storage has changed |
| 257 | // a significant amount since the last time. |
| 258 | if ((mFreeMemAfterLastCacheClear-mFreeMem) |
| 259 | >= ((mMemLowThreshold-mMemCacheStartTrimThreshold)/4)) { |
| 260 | // See if clearing cache helps |
| 261 | // Note that clearing cache is asynchronous and so we do a |
| 262 | // memory check again once the cache has been cleared. |
| 263 | mThreadStartTime = System.currentTimeMillis(); |
| 264 | mClearSucceeded = false; |
| 265 | clearCache(); |
| 266 | } |
| 267 | } |
| 268 | } else { |
| 269 | // This is a call from after clearing the cache. Note |
| 270 | // the amount of free storage at this point. |
| 271 | mFreeMemAfterLastCacheClear = mFreeMem; |
| 272 | if (!mLowMemFlag) { |
| 273 | // We tried to clear the cache, but that didn't get us |
| 274 | // below the low storage limit. Tell the user. |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 275 | Slog.i(TAG, "Running low on memory. Sending notification"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | sendNotification(); |
| 277 | mLowMemFlag = true; |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 278 | } else { |
| 279 | if (localLOGV) Slog.v(TAG, "Running low on memory " + |
| 280 | "notification already sent. do nothing"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 282 | } |
| 283 | } else { |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 284 | mFreeMemAfterLastCacheClear = mFreeMem; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | if (mLowMemFlag) { |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 286 | Slog.i(TAG, "Memory available. Cancelling notification"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 287 | cancelNotification(); |
| 288 | mLowMemFlag = false; |
| 289 | } |
| 290 | } |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 291 | if (!mLowMemFlag && !mIsBootImageOnDisk) { |
| 292 | Slog.i(TAG, "No boot image on disk due to lack of space. Sending notification"); |
| 293 | sendNotification(); |
| 294 | } |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 295 | if (mFreeMem < mMemFullThreshold) { |
| 296 | if (!mMemFullFlag) { |
| 297 | sendFullNotification(); |
| 298 | mMemFullFlag = true; |
| 299 | } |
| 300 | } else { |
| 301 | if (mMemFullFlag) { |
| 302 | cancelFullNotification(); |
| 303 | mMemFullFlag = false; |
| 304 | } |
| 305 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 306 | } |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 307 | if(localLOGV) Slog.i(TAG, "Posting Message again"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | //keep posting messages to itself periodically |
| 309 | postCheckMemoryMsg(true, DEFAULT_CHECK_INTERVAL); |
| 310 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 311 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 312 | void postCheckMemoryMsg(boolean clearCache, long delay) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | // Remove queued messages |
| 314 | mHandler.removeMessages(DEVICE_MEMORY_WHAT); |
| 315 | mHandler.sendMessageDelayed(mHandler.obtainMessage(DEVICE_MEMORY_WHAT, |
| 316 | clearCache ?_TRUE : _FALSE, 0), |
| 317 | delay); |
| 318 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 319 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 320 | public DeviceStorageMonitorService(Context context) { |
| 321 | super(context); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | mLastReportedFreeMemTime = 0; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 323 | mResolver = context.getContentResolver(); |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 324 | mIsBootImageOnDisk = isBootImageOnDisk(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | //create StatFs object |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 326 | mDataFileStats = new StatFs(DATA_PATH.getAbsolutePath()); |
| 327 | mSystemFileStats = new StatFs(SYSTEM_PATH.getAbsolutePath()); |
| 328 | mCacheFileStats = new StatFs(CACHE_PATH.getAbsolutePath()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | //initialize total storage on device |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 330 | mTotalMemory = (long)mDataFileStats.getBlockCount() * |
| 331 | mDataFileStats.getBlockSize(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW); |
Jeff Hamilton | 4b33092 | 2010-06-04 15:16:06 -0500 | [diff] [blame] | 333 | mStorageLowIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK); |
Jeff Hamilton | 4b33092 | 2010-06-04 15:16:06 -0500 | [diff] [blame] | 335 | mStorageOkIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 336 | mStorageFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_FULL); |
| 337 | mStorageFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
| 338 | mStorageNotFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_NOT_FULL); |
| 339 | mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 340 | } |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 341 | |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 342 | private static boolean isBootImageOnDisk() { |
Fyodor Kupolov | eeea67b | 2015-02-23 17:14:45 -0800 | [diff] [blame] | 343 | for (String instructionSet : InstructionSets.getAllDexCodeInstructionSets()) { |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 344 | if (!VMRuntime.isBootClassPathOnDisk(instructionSet)) { |
| 345 | return false; |
| 346 | } |
| 347 | } |
| 348 | return true; |
| 349 | } |
| 350 | |
Jeff Brown | b880d88 | 2014-02-10 19:47:07 -0800 | [diff] [blame] | 351 | /** |
| 352 | * Initializes the disk space threshold value and posts an empty message to |
| 353 | * kickstart the process. |
| 354 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 355 | @Override |
| 356 | public void onStart() { |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 357 | // cache storage thresholds |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 358 | final StorageManager sm = StorageManager.from(getContext()); |
Jeff Sharkey | be72215 | 2013-02-15 16:56:38 -0800 | [diff] [blame] | 359 | mMemLowThreshold = sm.getStorageLowBytes(DATA_PATH); |
| 360 | mMemFullThreshold = sm.getStorageFullBytes(DATA_PATH); |
| 361 | |
Dianne Hackborn | 197a0c8 | 2012-07-12 14:46:04 -0700 | [diff] [blame] | 362 | mMemCacheStartTrimThreshold = ((mMemLowThreshold*3)+mMemFullThreshold)/4; |
| 363 | mMemCacheTrimToThreshold = mMemLowThreshold |
| 364 | + ((mMemLowThreshold-mMemCacheStartTrimThreshold)*2); |
| 365 | mFreeMemAfterLastCacheClear = mTotalMemory; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 366 | checkMemory(true); |
Jeff Sharkey | 4b49657 | 2012-04-19 14:17:03 -0700 | [diff] [blame] | 367 | |
| 368 | mCacheFileDeletedObserver = new CacheFileDeletedObserver(); |
| 369 | mCacheFileDeletedObserver.startWatching(); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 370 | |
| 371 | publishBinderService(SERVICE, mRemoteService); |
| 372 | publishLocalService(DeviceStorageMonitorInternal.class, mLocalService); |
| 373 | } |
| 374 | |
| 375 | private final DeviceStorageMonitorInternal mLocalService = new DeviceStorageMonitorInternal() { |
| 376 | @Override |
| 377 | public void checkMemory() { |
| 378 | // force an early check |
| 379 | postCheckMemoryMsg(true, 0); |
| 380 | } |
| 381 | |
| 382 | @Override |
| 383 | public boolean isMemoryLow() { |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 384 | return mLowMemFlag || !mIsBootImageOnDisk; |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | @Override |
| 388 | public long getMemoryLowThreshold() { |
| 389 | return mMemLowThreshold; |
| 390 | } |
| 391 | }; |
| 392 | |
| 393 | private final IBinder mRemoteService = new Binder() { |
| 394 | @Override |
| 395 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 396 | if (getContext().checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 397 | != PackageManager.PERMISSION_GRANTED) { |
| 398 | |
| 399 | pw.println("Permission Denial: can't dump " + SERVICE + " from from pid=" |
| 400 | + Binder.getCallingPid() |
| 401 | + ", uid=" + Binder.getCallingUid()); |
| 402 | return; |
| 403 | } |
| 404 | |
| 405 | dumpImpl(pw); |
| 406 | } |
| 407 | }; |
| 408 | |
| 409 | void dumpImpl(PrintWriter pw) { |
| 410 | final Context context = getContext(); |
| 411 | |
| 412 | pw.println("Current DeviceStorageMonitor state:"); |
| 413 | |
| 414 | pw.print(" mFreeMem="); pw.print(Formatter.formatFileSize(context, mFreeMem)); |
| 415 | pw.print(" mTotalMemory="); |
| 416 | pw.println(Formatter.formatFileSize(context, mTotalMemory)); |
| 417 | |
| 418 | pw.print(" mFreeMemAfterLastCacheClear="); |
| 419 | pw.println(Formatter.formatFileSize(context, mFreeMemAfterLastCacheClear)); |
| 420 | |
| 421 | pw.print(" mLastReportedFreeMem="); |
| 422 | pw.print(Formatter.formatFileSize(context, mLastReportedFreeMem)); |
| 423 | pw.print(" mLastReportedFreeMemTime="); |
| 424 | TimeUtils.formatDuration(mLastReportedFreeMemTime, SystemClock.elapsedRealtime(), pw); |
| 425 | pw.println(); |
| 426 | |
| 427 | pw.print(" mLowMemFlag="); pw.print(mLowMemFlag); |
| 428 | pw.print(" mMemFullFlag="); pw.println(mMemFullFlag); |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 429 | pw.print(" mIsBootImageOnDisk="); pw.print(mIsBootImageOnDisk); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 430 | |
| 431 | pw.print(" mClearSucceeded="); pw.print(mClearSucceeded); |
| 432 | pw.print(" mClearingCache="); pw.println(mClearingCache); |
| 433 | |
| 434 | pw.print(" mMemLowThreshold="); |
| 435 | pw.print(Formatter.formatFileSize(context, mMemLowThreshold)); |
| 436 | pw.print(" mMemFullThreshold="); |
| 437 | pw.println(Formatter.formatFileSize(context, mMemFullThreshold)); |
| 438 | |
| 439 | pw.print(" mMemCacheStartTrimThreshold="); |
| 440 | pw.print(Formatter.formatFileSize(context, mMemCacheStartTrimThreshold)); |
| 441 | pw.print(" mMemCacheTrimToThreshold="); |
| 442 | pw.println(Formatter.formatFileSize(context, mMemCacheTrimToThreshold)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 444 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | /** |
| 446 | * This method sends a notification to NotificationManager to display |
| 447 | * an error dialog indicating low disk space and launch the Installer |
| 448 | * application |
| 449 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 450 | private void sendNotification() { |
| 451 | final Context context = getContext(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 452 | if(localLOGV) Slog.i(TAG, "Sending low memory notification"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 453 | //log the event to event log with the amount of free storage(in bytes) left on the device |
Doug Zongker | ab5c49c | 2009-12-04 10:31:43 -0800 | [diff] [blame] | 454 | EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 455 | // Pack up the values and broadcast them to everyone |
Dianne Hackborn | f882efa | 2012-04-11 16:04:12 -0700 | [diff] [blame] | 456 | Intent lowMemIntent = new Intent(Environment.isExternalStorageEmulated() |
| 457 | ? Settings.ACTION_INTERNAL_STORAGE_SETTINGS |
| 458 | : Intent.ACTION_MANAGE_PACKAGE_STORAGE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 459 | lowMemIntent.putExtra("memory", mFreeMem); |
| 460 | lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 461 | NotificationManager mNotificationMgr = |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 462 | (NotificationManager)context.getSystemService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | Context.NOTIFICATION_SERVICE); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 464 | CharSequence title = context.getText( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | com.android.internal.R.string.low_internal_storage_view_title); |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 466 | CharSequence details = context.getText(mIsBootImageOnDisk |
| 467 | ? com.android.internal.R.string.low_internal_storage_view_text |
| 468 | : com.android.internal.R.string.low_internal_storage_view_text_no_boot); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 469 | PendingIntent intent = PendingIntent.getActivityAsUser(context, 0, lowMemIntent, 0, |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 470 | null, UserHandle.CURRENT); |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 471 | Notification notification = new Notification.Builder(context) |
| 472 | .setSmallIcon(com.android.internal.R.drawable.stat_notify_disk_full) |
| 473 | .setTicker(title) |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 474 | .setColor(context.getColor( |
Brian Carlstrom | a39871e | 2014-09-29 13:44:04 -0700 | [diff] [blame] | 475 | com.android.internal.R.color.system_notification_accent_color)) |
| 476 | .setContentTitle(title) |
| 477 | .setContentText(details) |
| 478 | .setContentIntent(intent) |
| 479 | .setStyle(new Notification.BigTextStyle() |
| 480 | .bigText(details)) |
| 481 | .setVisibility(Notification.VISIBILITY_PUBLIC) |
| 482 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 483 | .build(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | notification.flags |= Notification.FLAG_NO_CLEAR; |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 485 | mNotificationMgr.notifyAsUser(null, LOW_MEMORY_NOTIFICATION_ID, notification, |
| 486 | UserHandle.ALL); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 487 | context.sendStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Cancels low storage notification and sends OK intent. |
| 492 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 493 | private void cancelNotification() { |
| 494 | final Context context = getContext(); |
Joe Onorato | 8a9b220 | 2010-02-26 18:56:32 -0800 | [diff] [blame] | 495 | if(localLOGV) Slog.i(TAG, "Canceling low memory notification"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 496 | NotificationManager mNotificationMgr = |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 497 | (NotificationManager)context.getSystemService( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | Context.NOTIFICATION_SERVICE); |
| 499 | //cancel notification since memory has been freed |
Dianne Hackborn | 50cdf7c3 | 2012-09-23 17:08:57 -0700 | [diff] [blame] | 500 | mNotificationMgr.cancelAsUser(null, LOW_MEMORY_NOTIFICATION_ID, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 501 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 502 | context.removeStickyBroadcastAsUser(mStorageLowIntent, UserHandle.ALL); |
| 503 | context.sendBroadcastAsUser(mStorageOkIntent, UserHandle.ALL); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 504 | } |
Doug Zongker | 3161795b | 2009-10-07 15:14:03 -0700 | [diff] [blame] | 505 | |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 506 | /** |
| 507 | * Send a notification when storage is full. |
| 508 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 509 | private void sendFullNotification() { |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 510 | if(localLOGV) Slog.i(TAG, "Sending memory full notification"); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 511 | getContext().sendStickyBroadcastAsUser(mStorageFullIntent, UserHandle.ALL); |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Cancels memory full notification and sends "not full" intent. |
| 516 | */ |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 517 | private void cancelFullNotification() { |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 518 | if(localLOGV) Slog.i(TAG, "Canceling memory full notification"); |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 519 | getContext().removeStickyBroadcastAsUser(mStorageFullIntent, UserHandle.ALL); |
| 520 | getContext().sendBroadcastAsUser(mStorageNotFullIntent, UserHandle.ALL); |
Jake Hamby | bb37163 | 2010-08-23 18:16:48 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Adam Lesinski | 182f73f | 2013-12-05 16:48:06 -0800 | [diff] [blame] | 523 | private static class CacheFileDeletedObserver extends FileObserver { |
Jeff Sharkey | 4b49657 | 2012-04-19 14:17:03 -0700 | [diff] [blame] | 524 | public CacheFileDeletedObserver() { |
| 525 | super(Environment.getDownloadCacheDirectory().getAbsolutePath(), FileObserver.DELETE); |
| 526 | } |
| 527 | |
| 528 | @Override |
| 529 | public void onEvent(int event, String path) { |
| 530 | EventLogTags.writeCacheFileDeleted(path); |
| 531 | } |
| 532 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 533 | } |