安卓低内存下应用程序不能被kill掉

首先,ActivityManagerService.java中增加如下

private ArrayList mLmkWhiteList = new ArrayList<>();

 private void initLmkWhiteList(){

    String [] stWhiteList = mContext.getResources().getStringArray(com.android.internal.R.array.lmk_white_list);

    for(int i=0;i

            mLmkWhiteList.add(stWhiteList[i]);

    }

}

void increaseAppAdjLocked(ProcessRecord app){

    final long nowElapsed = SystemClock.elapsedRealtime();

    final long now = SystemClock.uptimeMillis();

    if(app.info != null && mLmkWhiteList.contains(app.info.packageName)){

        if(app.curAdj>ProcessList.SERVICE_ADJ){

               app.curAdj = app.modifyRawOomAdj(ProcessList.PERCEPTIBLE_APP_ADJ);

                app.curProcState = ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;

                app.cached = false;

                app.adjType = "fg-service";

        }

}

}


其次applayOomAdjLocked中起始位置调用increaseAPPAdjLocked(app);

readAppAsState(UserHandle.myUserId());下面调用白名单列表initLmkWhiteList();


最后就是在framework 中增加资源文件,就不多讲了。

你可能感兴趣的:(Android)