CanPHP框架技术讨论

导航

 
有一种方法可以设置app永远不会被kill,AndroidManifest.xml 中添加:
android:persistent="true"
适用于放在/system/app下的app
 
设置后app提升为系统核心级别,任何情况下不会被kill掉, settings->applications里面也会屏蔽掉stop操作,
设置前 Proc #19: adj=svc  /B 4067b028 255:com.xxx.xxx/10001 (started-services)
# cat /proc/255/oom_adj
4
设置后 PERS #19: adj=core /F 406291f0 155:com.xxx.xxx/10001 (fixed)
# cat /proc/155/oom_adj
-12

 

lowmemorykiller的操作规则比如为

write /sys/module/lowmemorykiller/parameters/adj 0,1,2,4,7,15

write /sys/module/lowmemorykiller/parameters/minfree 2048,3072,4096,6144,7168,8192

 

可以看到,设置persistent后, oom_adj=-12,永远没有机会被lowmemorykiller处理

 

android:persistent 
Whether or not the application should remain running at all times — "true" if it should, and "false" if not. The default value is "false". Applications should not normally set this flag; persistence mode is intended only for certain system applications

 

代码

[java] view plaincopy
 
    1. ActivityManagerService.java  
    2.     final ProcessRecord addAppLocked(ApplicationInfo info) {  
    3.         ProcessRecord app = getProcessRecordLocked(info.processName, info.uid);  
    4.   
    5.         if (app == null) {  
    6.             app = newProcessRecordLocked(null, info, null);  
    7.             mProcessNames.put(info.processName, info.uid, app);  
    8.             updateLruProcessLocked(app, truetrue);  
    9.         }  
    10.   
    11.         if ((info.flags&(ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT))  
    12.                 == (ApplicationInfo.FLAG_SYSTEM|ApplicationInfo.FLAG_PERSISTENT)) {  
    13.             app.persistent = true;  
    14.             app.maxAdj = CORE_SERVER_ADJ;  
    15.         }  
    16.         if (app.thread == null && mPersistentStartingProcesses.indexOf(app) < 0) {  
    17.             mPersistentStartingProcesses.add(app);  
    18.             startProcessLocked(app, "added application", app.processName);  
    19.         }  
    20.   
    21.         return app;  
    22.     }  
posted on 2014-01-07 15:08  創丗仼  阅读(368)  评论(0编辑  收藏  举报