某厂商定制系统设置应用自启动

系统分析

Posted by JovenHe on November 30, 2021

有个厂商设备的适配项目,值得记录一下

设备是双系统手机,在安全系统内安装应用后,需要设置自启动,打开设备自启动管理页面

Screenshot_20211130_110114493_自启动管理.jpg

adb查看页面,得到组件名

mCurrentFocus=Window{23b6e81 u0 com.hmct.mobilesafe.tools.autorun/com.hmct.mobilesafe.tools.autorun.AutorunActivity}

在Android studio的DeviceFileExplorer中找到com.hmct.mobilesafe.tools.autorun对应的系统应用

用jadx反编译打开,在Manifest中查找AutorunActivity

Screenshot_20211130_111714493_自启动管理Activity.jpg

能找到AutorunActivity只是别名,真正的Activity是AutoRunMainActivity

打开AutoRunMainActivity代码

Screenshot_20211130_112014493_AutoRunMainActivity.jpg

可以看到代码都未加混淆,很容易找到关键代码

Screenshot_20211130_112214493_ItemClick.jpg

Screenshot_20211130_112414493_setRestricted.jpg

自启动管理页面点击对应应用后进行修改,判断是否限制自启动自然是isRestricted方法

mPM是通过 this.mPM = getPackageManager();生成的,而setPackageRestrictState与isRestricted方法在PackageManager类中是没有的,是厂商修改rom中的系统方法增加的,只能反射调用即可


   public static boolean isPackageRestricted(PackageManager packageManager, String packageName) {
        try {
            Method method_isPackageRestricted = PackageManager.class.getMethod("isPackageRestricted", String.class);

            boolean isPackageRestricted = (boolean) method_isPackageRestricted.invoke(packageManager, packageName);
            return isPackageRestricted;
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return false;
    }

    public static void setPackageRestricted(PackageManager packageManager, String packageName, boolean restricted) {
        try {
            Method method_setPackageRestrictState = PackageManager.class.getMethod("setPackageRestrictState", String.class, boolean.class);

            method_setPackageRestrictState.invoke(packageManager, packageName, restricted);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

使用如下

        val packageRestricted = DevUtil.isPackageRestricted(packageManager, packageName)
        if (packageRestricted) {
            DevUtil.setPackageRestricted(packageManager, packageName, false)
        }

如果该应用有限制的话,设置为无限制