需求
增加系统黑白名单,用于控制进程是否常驻,进程优化等。
1).白名单应用避免被系统杀掉,保持常驻
2).黑名单应用,针对性的进行限制,避免常驻内存,系统内存吃紧时,将其杀掉
开发者可以根据自己的策略进行修改扩展。动态的设置oomAdj 或者 直接进行杀掉。
增加黑白名单接口
frameworks/base / core/java/android/app/IActivityManager.aidl
List<String> getProtectedAppList();
void setProtectedAppList(in List<String> protectedAppList);
List<String> getStoppedAppList();
void setStoppedAppList(in List<String> stopAppList);
frameworks/base/core/java/android/app/ActivityManager.java
public List<String> getProtectedAppList() {
try {
return getService().getProtectedAppList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
public void setProtectedAppList(List<String> protectedAppList) {
try {
getService().setProtectedAppList(protectedAppList);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
public List<String> getStoppedAppList() {
try {
return getService().getStoppedAppList();
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
public void setStoppedAppList(List<String> stopAppList) {
try {
getService().setStoppedAppList(stopAppList);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer

本文介绍了如何在Android系统中实现进程的黑白名单管理,白名单保护常驻应用,黑名单限制内存占用。通过修改IActivityManager和ActivityManagerService接口,开发者可以动态设置oomAdj或根据策略杀掉进程。内容涵盖了内存优化机制,如白名单对CACHED_ACTIVITY和CACHED_ACTIVITY_CLIENT的处理,以及黑名单在Service自启动限制的应用。
最低0.47元/天 解锁文章
2286





