卓派观点

“存储空间不足”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

版权所有,转载请注明出处。
转载自 <a href="http://www.jwisp.com/?p=97" title="“存储空间不足”data过小的通知分析DeviceStorageMonitorService类" rel="bookmark">“存储空间不足”data过小的通知分析DeviceStorageMonitorService类 | 卓派</a>

我简单说几句


随机推荐

最新评论

固定链接

随机链接