Mtk Android app 默认激活设备管理器

代码路径:
frameworks/base/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java

流程:
每次开机时,loadSettingsLocked()方法会读取data/system/device_policies.xml文件
手动激活时,saveSettingsLocked()方法会写入对应的信息到data/system/device_policies.xml文件

具体方法:
先手动激活,然后pull出该文件,根据里面的多出的信息,在loadSettingsLocked()方法读取xml之前写入xml文件即可。

//写入标签名
out.startTag(null, “policies”);
//写入标签属性和值d
out.attribute(null, “flags”, “31”);
//关闭标签
out.endTag(null, “policies”);

================================================

/zhanghao add begin/
private void setSettingsLocked(int userHandle) {
JournaledFile journal = makeJournaledFile(userHandle);
FileOutputStream stream = null;
try {
stream = new FileOutputStream(journal.chooseForWrite(), false);
XmlSerializer out = new FastXmlSerializer();
out.setOutput(stream, StandardCharsets.UTF_

8.name());
out.startDocument(null, true);

        out.startTag(null, "policies");

        out.attribute(null, ATTR_SETUP_COMPLETE,
                Boolean.toString(true));

            //com.xueleyun.xlylauncher
            out.startTag(null, "admin");
            out.attribute(null, "name", "com.xueleyun.xlylauncher/com.xueleyun.xlylauncher.deviceAdminReceiver");
                 out.startTag(null, "policies");
                 out.attribute(null, "flags", "31");
                 out.endTag(null, "policies");

                 out.startTag(null, "disable-bt-contacts-sharing");
                 out.attribute(null, "value", "true");
                out.endTag(null, "disable-bt-contacts-sharing");
                out.endTag(null, "admin");

                out.endTag(null, "policies");

	            out.endDocument();
	            stream.flush();
	            FileUtils.sync(stream);
	            stream.close();
	            journal.commit();
	            sendChangedNotification(userHandle);

    } catch (IOException e) {
        try {
            if (stream != null) {
                stream.close();
            }
        } catch (IOException ex) {
            // Ignore
        }
        journal.rollback();
    }
}
/*zhanghao add end*/

private void loadSettingsLocked(DevicePolicyData policy, int userHandle) {
    /*zhanghao add begin*/
    String tempString = SystemProperties.get("persist.sys.firstboot", "");
    boolean isFirstBoot = (tempString != null && "".equals(tempString)) ? true : false;
    if (isFirstBoot) {
        SystemProperties.set("persist.sys.firstboot", "false");
        setSettingsLocked(userHandle);
    }
    /*zhanghao end*/

你可能感兴趣的:(MTK,GMS)