andorid系统定制白名单

Source

修改路径:

framworks/base/services/java/com/android/server/am/ActivityManagerService.java

初始化白名单集合:

ArrayList<String> mWhitelist = new ArrayList<String>();

更新集合:

    private void readApplicationWhiteLists() {
        FileInputStream inputStream = null;
        XmlPullParser xmlPullParser = Xml.newPullParser();

        try {
            inputStream = new FileInputStream(new File("/system/etc/ApplicationWhitelist.xml"));

            xmlPullParser.setInput(inputStream, "utf-8");
            int type = xmlPullParser.getEventType();
            while(type != XmlPullParser.END_DOCUMENT) {
                switch (type) {
                    case XmlPullParser.START_TAG:
                        if(xmlPullParser.getName().equals("Whitelist")) {
                            mWhitelist.add(xmlPullParser.nextText());
                        }
                        break;
                }

                type = xmlPullParser.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(inputStream != null) {
                    inputStream.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        Slog.d(TAG, "mWhitelist:" + mWhitelist.toString());
    }

初始化读取(系统开机时):

 private ActivityManagerService() {
 		......省略
        Slog.d(TAG, "start readApplicationWhiteLists");
        readApplicationWhiteLists();
        ......省略
}

更新白名单里app的相关数据:

    //if apk in whitelists, change oom_adj
    final void updateWhiteListAppOomAdjLocked(ProcessRecord app) {
        for(int i = 0; i < mWhitelist.size(); i++) {
            if(mWhitelist.get(i).equals(app.processName)) {
                app.curProcState = ActivityManager.PROCESS_STATE_PERSISTENT;
                app.curAdj = ProcessList.SYSTEM_ADJ;
                break;
            }
        }
    }
final void updateOomAdjLocked() {
     updateWhiteListAppOomAdjLocked(app);	
}

cat /system/etc/ApplicationWhitelist.xml

<?xml version="1.0" encoding="utf-8"?>

<whitelists>
  <Whitelist>com.iflytek.xiri2.system</Whitelist>
  <Whitelist>com.iflytek.xiri</Whitelist>
</whitelists>

发布了65 篇原创文章 · 获赞 23 · 访问量 7234