blob: 0fba7c3603af0cc443d24497acc2bf362bdef044 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package com.android.server;
18
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080019import android.app.Notification;
20import android.app.NotificationManager;
21import android.app.PendingIntent;
22import android.content.ContentResolver;
23import android.content.Context;
24import android.content.Intent;
25import android.content.pm.IPackageDataObserver;
26import android.content.pm.IPackageManager;
27import android.os.Binder;
28import android.os.Handler;
29import android.os.Message;
30import android.os.Process;
31import android.os.RemoteException;
32import android.os.ServiceManager;
33import android.os.StatFs;
34import android.os.SystemClock;
35import android.os.SystemProperties;
Doug Zongker43866e02010-01-07 12:09:54 -080036import android.provider.Settings;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.util.Config;
38import android.util.EventLog;
Joe Onorato8a9b2202010-02-26 18:56:32 -080039import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040
41/**
Doug Zongker43866e02010-01-07 12:09:54 -080042 * This class implements a service to monitor the amount of disk
43 * storage space on the device. If the free storage on device is less
44 * than a tunable threshold value (a secure settings parameter;
45 * default 10%) a low memory notification is displayed to alert the
46 * user. If the user clicks on the low memory notification the
47 * Application Manager application gets launched to let the user free
48 * storage space.
49 *
50 * Event log events: A low memory event with the free storage on
51 * device in bytes is logged to the event log when the device goes low
52 * on storage space. The amount of free storage on the device is
53 * periodically logged to the event log. The log interval is a secure
54 * settings parameter with a default value of 12 hours. When the free
55 * storage differential goes below a threshold (again a secure
56 * settings parameter with a default value of 2MB), the free memory is
57 * logged to the event log.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 */
59class DeviceStorageMonitorService extends Binder {
60 private static final String TAG = "DeviceStorageMonitorService";
61 private static final boolean DEBUG = false;
62 private static final boolean localLOGV = DEBUG ? Config.LOGD : Config.LOGV;
63 private static final int DEVICE_MEMORY_WHAT = 1;
64 private static final int MONITOR_INTERVAL = 1; //in minutes
65 private static final int LOW_MEMORY_NOTIFICATION_ID = 1;
66 private static final int DEFAULT_THRESHOLD_PERCENTAGE = 10;
Dianne Hackborn247fe742011-01-08 17:25:57 -080067 private static final int DEFAULT_THRESHOLD_MAX_BYTES = 500*1024*1024; // 500MB
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080068 private static final int DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES = 12*60; //in minutes
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069 private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB
70 private static final long DEFAULT_CHECK_INTERVAL = MONITOR_INTERVAL*60*1000;
Jake Hambybb371632010-08-23 18:16:48 -070071 private static final int DEFAULT_FULL_THRESHOLD_BYTES = 1024*1024; // 1MB
Doug Zongker3161795b2009-10-07 15:14:03 -070072 private long mFreeMem; // on /data
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 private long mLastReportedFreeMem;
74 private long mLastReportedFreeMemTime;
75 private boolean mLowMemFlag=false;
Jake Hambybb371632010-08-23 18:16:48 -070076 private boolean mMemFullFlag=false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080077 private Context mContext;
78 private ContentResolver mContentResolver;
Doug Zongker3161795b2009-10-07 15:14:03 -070079 private long mTotalMemory; // on /data
80 private StatFs mDataFileStats;
81 private StatFs mSystemFileStats;
82 private StatFs mCacheFileStats;
83 private static final String DATA_PATH = "/data";
84 private static final String SYSTEM_PATH = "/system";
85 private static final String CACHE_PATH = "/cache";
86 private long mThreadStartTime = -1;
87 private boolean mClearSucceeded = false;
88 private boolean mClearingCache;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 private Intent mStorageLowIntent;
90 private Intent mStorageOkIntent;
Jake Hambybb371632010-08-23 18:16:48 -070091 private Intent mStorageFullIntent;
92 private Intent mStorageNotFullIntent;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080093 private CachePackageDataObserver mClearCacheObserver;
94 private static final int _TRUE = 1;
95 private static final int _FALSE = 0;
Jake Hambybb371632010-08-23 18:16:48 -070096 private long mMemLowThreshold;
97 private int mMemFullThreshold;
Doug Zongker3161795b2009-10-07 15:14:03 -070098
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 /**
100 * This string is used for ServiceManager access to this class.
101 */
102 static final String SERVICE = "devicestoragemonitor";
Doug Zongker3161795b2009-10-07 15:14:03 -0700103
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800104 /**
Doug Zongker3161795b2009-10-07 15:14:03 -0700105 * Handler that checks the amount of disk space on the device and sends a
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800106 * notification if the device runs low on disk space
107 */
108 Handler mHandler = new Handler() {
109 @Override
110 public void handleMessage(Message msg) {
Jake Hambybb371632010-08-23 18:16:48 -0700111 //don't handle an invalid message
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800112 if (msg.what != DEVICE_MEMORY_WHAT) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800113 Slog.e(TAG, "Will not process invalid message");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114 return;
115 }
116 checkMemory(msg.arg1 == _TRUE);
117 }
118 };
Doug Zongker3161795b2009-10-07 15:14:03 -0700119
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 class CachePackageDataObserver extends IPackageDataObserver.Stub {
121 public void onRemoveCompleted(String packageName, boolean succeeded) {
122 mClearSucceeded = succeeded;
123 mClearingCache = false;
Joe Onorato8a9b2202010-02-26 18:56:32 -0800124 if(localLOGV) Slog.i(TAG, " Clear succeeded:"+mClearSucceeded
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 +", mClearingCache:"+mClearingCache+" Forcing memory check");
126 postCheckMemoryMsg(false, 0);
Doug Zongker3161795b2009-10-07 15:14:03 -0700127 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800128 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700129
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 private final void restatDataDir() {
Doug Zongker3161795b2009-10-07 15:14:03 -0700131 try {
132 mDataFileStats.restat(DATA_PATH);
133 mFreeMem = (long) mDataFileStats.getAvailableBlocks() *
134 mDataFileStats.getBlockSize();
135 } catch (IllegalArgumentException e) {
136 // use the old value of mFreeMem
137 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800138 // Allow freemem to be overridden by debug.freemem for testing
139 String debugFreeMem = SystemProperties.get("debug.freemem");
140 if (!"".equals(debugFreeMem)) {
141 mFreeMem = Long.parseLong(debugFreeMem);
142 }
Doug Zongker43866e02010-01-07 12:09:54 -0800143 // Read the log interval from secure settings
144 long freeMemLogInterval = Settings.Secure.getLong(mContentResolver,
145 Settings.Secure.SYS_FREE_STORAGE_LOG_INTERVAL,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 DEFAULT_FREE_STORAGE_LOG_INTERVAL_IN_MINUTES)*60*1000;
147 //log the amount of free memory in event log
148 long currTime = SystemClock.elapsedRealtime();
Doug Zongker3161795b2009-10-07 15:14:03 -0700149 if((mLastReportedFreeMemTime == 0) ||
150 (currTime-mLastReportedFreeMemTime) >= freeMemLogInterval) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800151 mLastReportedFreeMemTime = currTime;
Doug Zongker3161795b2009-10-07 15:14:03 -0700152 long mFreeSystem = -1, mFreeCache = -1;
153 try {
154 mSystemFileStats.restat(SYSTEM_PATH);
155 mFreeSystem = (long) mSystemFileStats.getAvailableBlocks() *
156 mSystemFileStats.getBlockSize();
157 } catch (IllegalArgumentException e) {
158 // ignore; report -1
159 }
160 try {
161 mCacheFileStats.restat(CACHE_PATH);
162 mFreeCache = (long) mCacheFileStats.getAvailableBlocks() *
163 mCacheFileStats.getBlockSize();
164 } catch (IllegalArgumentException e) {
165 // ignore; report -1
166 }
167 mCacheFileStats.restat(CACHE_PATH);
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800168 EventLog.writeEvent(EventLogTags.FREE_STORAGE_LEFT,
Doug Zongker3161795b2009-10-07 15:14:03 -0700169 mFreeMem, mFreeSystem, mFreeCache);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800170 }
Doug Zongker43866e02010-01-07 12:09:54 -0800171 // Read the reporting threshold from secure settings
172 long threshold = Settings.Secure.getLong(mContentResolver,
173 Settings.Secure.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800174 DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD);
175 // If mFree changed significantly log the new value
176 long delta = mFreeMem - mLastReportedFreeMem;
177 if (delta > threshold || delta < -threshold) {
178 mLastReportedFreeMem = mFreeMem;
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800179 EventLog.writeEvent(EventLogTags.FREE_STORAGE_CHANGED, mFreeMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800180 }
181 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700182
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800183 private final void clearCache() {
184 if (mClearCacheObserver == null) {
185 // Lazy instantiation
186 mClearCacheObserver = new CachePackageDataObserver();
187 }
188 mClearingCache = true;
189 try {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800190 if (localLOGV) Slog.i(TAG, "Clearing cache");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800191 IPackageManager.Stub.asInterface(ServiceManager.getService("package")).
Jake Hambybb371632010-08-23 18:16:48 -0700192 freeStorageAndNotify(mMemLowThreshold, mClearCacheObserver);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800193 } catch (RemoteException e) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800194 Slog.w(TAG, "Failed to get handle for PackageManger Exception: "+e);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800195 mClearingCache = false;
196 mClearSucceeded = false;
197 }
198 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700199
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800200 private final void checkMemory(boolean checkCache) {
Doug Zongker3161795b2009-10-07 15:14:03 -0700201 //if the thread that was started to clear cache is still running do nothing till its
202 //finished clearing cache. Ideally this flag could be modified by clearCache
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800203 // and should be accessed via a lock but even if it does this test will fail now and
204 //hopefully the next time this flag will be set to the correct value.
205 if(mClearingCache) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800206 if(localLOGV) Slog.i(TAG, "Thread already running just skip");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800207 //make sure the thread is not hung for too long
208 long diffTime = System.currentTimeMillis() - mThreadStartTime;
209 if(diffTime > (10*60*1000)) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800210 Slog.w(TAG, "Thread that clears cache file seems to run for ever");
Doug Zongker3161795b2009-10-07 15:14:03 -0700211 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800212 } else {
213 restatDataDir();
Joe Onorato8a9b2202010-02-26 18:56:32 -0800214 if (localLOGV) Slog.v(TAG, "freeMemory="+mFreeMem);
Doug Zongker3161795b2009-10-07 15:14:03 -0700215
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800216 //post intent to NotificationManager to display icon if necessary
Jake Hambybb371632010-08-23 18:16:48 -0700217 if (mFreeMem < mMemLowThreshold) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800218 if (!mLowMemFlag) {
219 if (checkCache) {
220 // See if clearing cache helps
221 // Note that clearing cache is asynchronous and so we do a
222 // memory check again once the cache has been cleared.
223 mThreadStartTime = System.currentTimeMillis();
224 mClearSucceeded = false;
225 clearCache();
226 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800227 Slog.i(TAG, "Running low on memory. Sending notification");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228 sendNotification();
229 mLowMemFlag = true;
230 }
231 } else {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800232 if (localLOGV) Slog.v(TAG, "Running low on memory " +
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800233 "notification already sent. do nothing");
234 }
235 } else {
236 if (mLowMemFlag) {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800237 Slog.i(TAG, "Memory available. Cancelling notification");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 cancelNotification();
239 mLowMemFlag = false;
240 }
241 }
Jake Hambybb371632010-08-23 18:16:48 -0700242 if (mFreeMem < mMemFullThreshold) {
243 if (!mMemFullFlag) {
244 sendFullNotification();
245 mMemFullFlag = true;
246 }
247 } else {
248 if (mMemFullFlag) {
249 cancelFullNotification();
250 mMemFullFlag = false;
251 }
252 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800253 }
Joe Onorato8a9b2202010-02-26 18:56:32 -0800254 if(localLOGV) Slog.i(TAG, "Posting Message again");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800255 //keep posting messages to itself periodically
256 postCheckMemoryMsg(true, DEFAULT_CHECK_INTERVAL);
257 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700258
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 private void postCheckMemoryMsg(boolean clearCache, long delay) {
260 // Remove queued messages
261 mHandler.removeMessages(DEVICE_MEMORY_WHAT);
262 mHandler.sendMessageDelayed(mHandler.obtainMessage(DEVICE_MEMORY_WHAT,
263 clearCache ?_TRUE : _FALSE, 0),
264 delay);
265 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700266
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800267 /*
Doug Zongker3161795b2009-10-07 15:14:03 -0700268 * just query settings to retrieve the memory threshold.
Doug Zongker43866e02010-01-07 12:09:54 -0800269 * Preferred this over using a ContentObserver since Settings.Secure caches the value
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800270 * any way
271 */
272 private long getMemThreshold() {
Dianne Hackborn247fe742011-01-08 17:25:57 -0800273 long value = Settings.Secure.getInt(
Doug Zongker3161795b2009-10-07 15:14:03 -0700274 mContentResolver,
Doug Zongker43866e02010-01-07 12:09:54 -0800275 Settings.Secure.SYS_STORAGE_THRESHOLD_PERCENTAGE,
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800276 DEFAULT_THRESHOLD_PERCENTAGE);
Joe Onorato8a9b2202010-02-26 18:56:32 -0800277 if(localLOGV) Slog.v(TAG, "Threshold Percentage="+value);
Dianne Hackborn247fe742011-01-08 17:25:57 -0800278 value *= mTotalMemory;
279 long maxValue = Settings.Secure.getInt(
280 mContentResolver,
281 Settings.Secure.SYS_STORAGE_THRESHOLD_MAX_BYTES,
282 DEFAULT_THRESHOLD_MAX_BYTES);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800283 //evaluate threshold value
Dianne Hackborn247fe742011-01-08 17:25:57 -0800284 return value < maxValue ? value : maxValue;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800285 }
286
Jake Hambybb371632010-08-23 18:16:48 -0700287 /*
288 * just query settings to retrieve the memory full threshold.
289 * Preferred this over using a ContentObserver since Settings.Secure caches the value
290 * any way
291 */
292 private int getMemFullThreshold() {
293 int value = Settings.Secure.getInt(
294 mContentResolver,
295 Settings.Secure.SYS_STORAGE_FULL_THRESHOLD_BYTES,
296 DEFAULT_FULL_THRESHOLD_BYTES);
297 if(localLOGV) Slog.v(TAG, "Full Threshold Bytes="+value);
298 return value;
299 }
300
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800301 /**
302 * Constructor to run service. initializes the disk space threshold value
303 * and posts an empty message to kickstart the process.
304 */
305 public DeviceStorageMonitorService(Context context) {
306 mLastReportedFreeMemTime = 0;
307 mContext = context;
308 mContentResolver = mContext.getContentResolver();
309 //create StatFs object
Doug Zongker3161795b2009-10-07 15:14:03 -0700310 mDataFileStats = new StatFs(DATA_PATH);
311 mSystemFileStats = new StatFs(SYSTEM_PATH);
312 mCacheFileStats = new StatFs(CACHE_PATH);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800313 //initialize total storage on device
Doug Zongker3161795b2009-10-07 15:14:03 -0700314 mTotalMemory = ((long)mDataFileStats.getBlockCount() *
315 mDataFileStats.getBlockSize())/100L;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800316 mStorageLowIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_LOW);
Jeff Hamilton4b330922010-06-04 15:16:06 -0500317 mStorageLowIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800318 mStorageOkIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_OK);
Jeff Hamilton4b330922010-06-04 15:16:06 -0500319 mStorageOkIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
Jake Hambybb371632010-08-23 18:16:48 -0700320 mStorageFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_FULL);
321 mStorageFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
322 mStorageNotFullIntent = new Intent(Intent.ACTION_DEVICE_STORAGE_NOT_FULL);
323 mStorageNotFullIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
324 // cache storage thresholds
325 mMemLowThreshold = getMemThreshold();
326 mMemFullThreshold = getMemFullThreshold();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 checkMemory(true);
328 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700329
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800330
331 /**
332 * This method sends a notification to NotificationManager to display
333 * an error dialog indicating low disk space and launch the Installer
334 * application
335 */
336 private final void sendNotification() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800337 if(localLOGV) Slog.i(TAG, "Sending low memory notification");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800338 //log the event to event log with the amount of free storage(in bytes) left on the device
Doug Zongkerab5c49c2009-12-04 10:31:43 -0800339 EventLog.writeEvent(EventLogTags.LOW_STORAGE, mFreeMem);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800340 // Pack up the values and broadcast them to everyone
341 Intent lowMemIntent = new Intent(Intent.ACTION_MANAGE_PACKAGE_STORAGE);
342 lowMemIntent.putExtra("memory", mFreeMem);
343 lowMemIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Doug Zongker3161795b2009-10-07 15:14:03 -0700344 NotificationManager mNotificationMgr =
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800345 (NotificationManager)mContext.getSystemService(
346 Context.NOTIFICATION_SERVICE);
347 CharSequence title = mContext.getText(
348 com.android.internal.R.string.low_internal_storage_view_title);
349 CharSequence details = mContext.getText(
350 com.android.internal.R.string.low_internal_storage_view_text);
351 PendingIntent intent = PendingIntent.getActivity(mContext, 0, lowMemIntent, 0);
352 Notification notification = new Notification();
353 notification.icon = com.android.internal.R.drawable.stat_notify_disk_full;
354 notification.tickerText = title;
355 notification.flags |= Notification.FLAG_NO_CLEAR;
356 notification.setLatestEventInfo(mContext, title, details, intent);
357 mNotificationMgr.notify(LOW_MEMORY_NOTIFICATION_ID, notification);
358 mContext.sendStickyBroadcast(mStorageLowIntent);
359 }
360
361 /**
362 * Cancels low storage notification and sends OK intent.
363 */
364 private final void cancelNotification() {
Joe Onorato8a9b2202010-02-26 18:56:32 -0800365 if(localLOGV) Slog.i(TAG, "Canceling low memory notification");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800366 NotificationManager mNotificationMgr =
367 (NotificationManager)mContext.getSystemService(
368 Context.NOTIFICATION_SERVICE);
369 //cancel notification since memory has been freed
370 mNotificationMgr.cancel(LOW_MEMORY_NOTIFICATION_ID);
371
372 mContext.removeStickyBroadcast(mStorageLowIntent);
373 mContext.sendBroadcast(mStorageOkIntent);
374 }
Doug Zongker3161795b2009-10-07 15:14:03 -0700375
Jake Hambybb371632010-08-23 18:16:48 -0700376 /**
377 * Send a notification when storage is full.
378 */
379 private final void sendFullNotification() {
380 if(localLOGV) Slog.i(TAG, "Sending memory full notification");
381 mContext.sendStickyBroadcast(mStorageFullIntent);
382 }
383
384 /**
385 * Cancels memory full notification and sends "not full" intent.
386 */
387 private final void cancelFullNotification() {
388 if(localLOGV) Slog.i(TAG, "Canceling memory full notification");
389 mContext.removeStickyBroadcast(mStorageFullIntent);
390 mContext.sendBroadcast(mStorageNotFullIntent);
391 }
392
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800393 public void updateMemory() {
394 int callingUid = getCallingUid();
395 if(callingUid != Process.SYSTEM_UID) {
396 return;
397 }
398 // force an early check
399 postCheckMemoryMsg(true, 0);
400 }
401}