1. 程式人生 > >Android儲存空間不足

Android儲存空間不足

“儲存空間不足”data過小的通知分析DeviceStorageMonitorService類

位置

DeviceStorageMonitorService.java (frameworks\base\services\java\com\android\server\)

一. 三個關鍵變數:

private static final int DEFAULT_THRESHOLD_PERCENTAGE = 10;
private static final int DEFAULT_FULL_THRESHOLD_BYTES = 1*1024*1024; // 1MB
private static final long DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD = 2 * 1024 * 1024; // 2MB

二. 引數呼叫的地方
在整個android目錄中, 三個常量被呼叫的地方, 都只是在DeviceStorageMonitorService.java中

DEFAULT_THRESHOLD_PERCENTAGE(10) : private long getMemThreshold();
return 1300234 * 10 = 13,002,340

DEFAULT_FULL_THRESHOLD_BYTES(10M) : private int getMemFullThreshold()
return 10,485,760

DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD(5M=5,242,880) : private final void restatDataDir();
threshold = 5,242,880 delta = mFreeMem = 101,482,696

三. 函式被呼叫的地方
DeviceStorageMonitorService構造中

private long mMemLowThreshold = getMemThreshold();

四. DeviceStorageMonitorService的呼叫追蹤

private final void checkMemory(boolean checkCache) -> 判斷() ->
private final void sendNotification()

在sendNotification()中將剩餘記憶體的值存入intent中, 然後廣播出去, 廣播型別為ACTION_MANAGE_PACKAGE_STORAGE
此通知的標題為 “儲存空間不足(Low on space)”
通知的內容為 “手機記憶體空間所剩不多了(Phone storage space is getting low)”

五. DEFAULT_FULL_THRESHOLD_BYTES的呼叫追蹤

private final void checkMemory(boolean checkCache) -> 判斷() ->
private final void sendFullNotification() ->
sendStickyBroadcast(intent.ACTION_DEVICE_STORAGE_FULL)

若data目錄小於DEFAULT_FULL_THRESHOLD_BYTES, 則不在接收簡訊.

六. DEFAULT_DISK_FREE_CHANGE_REPORTING_THRESHOLD 呼叫追蹤

private final void checkMemory(boolean checkCache) ->
EventLog.writeEvent(EventLogTags.FREE_STORAGE_CHANGED, mFreeMem)

經過jwisp燒錄到真機上發現, 真正有可能有用的是百分比報警, 那隻需要設定下面這個引數即可:
DEFAULT_THRESHOLD_PERCENTAGE