当系统处于低内存时,lmkd会将一些前台apk kill掉,这时我们需要防止前台apk被kill。
修改 system\memory\lmkd\lmkd.cpp
static const char* const pAppWhitelist[] ={
"com.antutu.benchmark.full",
"com.antutu.ABenchMark",
"com.netflix.mediaclient",
"net.megogo.tv.preinstall",
"com.movistarplus.androidtv",
"com.amazon.avod.thirdpartyclient",
"com.disney.disneyplus",
"com.tencent.qqmusic",
"iflix.play",
"org.mozilla.tv.firefox",
"com.instagram.android:mqtt",
};
static bool is_app_whitelist(char *task_name)
{
unsigned int i = 0;
for (i = 0; i < sizeof(pAppWhitelist)/sizeof(pAppWhitelist[0]); i++ ) {
if (strlen(pAppWhitelist[i]) > strlen(task_name)) {
if (strstr(pAppWhitelist[i], task_name)) {
return true;
}
} else {
if (strstr(task_name, pAppWhitelist[i])) {
return true;
}
}
}
return false;
}
此外需要在kill_one_process调用kill_one_process
if (is_app_whitelist(taskname)) {
if (procp->oomadj <= PERCEPTIBLE_APP_ADJ) {
ALOGI("Process in whitelist be preserved in LMKD: '%s' (%d), uid %d, oom_adj %d",
taskname, pid, uid, procp->oomadj);
pid_remove(pid);
goto out;
}