Android 7 添加安装白名单

Android 7 添加安装白名单

项目场景:

提示:某些系统只支持已经的apk 安装
例如:项目场景: 车机系统


pm.java代码:

        final File systemDir;
        final File whiteListFile;
        final ArrayList<String> whiteListApps = new ArrayList<String>();
        systemDir = new File("/system/", "etc");
        whiteListFile = new File(systemDir, "whitelistapps.txt");
        if (!whiteListFile.exists()) {
            Log.e(TAG, "isWhiteListApp: whiteListApps.txt file no exists");
            return false;
        }
        try {
            whiteListApps.clear();
            BufferedReader br = new BufferedReader(new FileReader(whiteListFile));
            String line = br.readLine();
            while (line != null) {
                Log.d(TAG, "whiteListApps readLine:" + line);
                whiteListApps.add(line);
                line = br.readLine();
            }
            br.close();
        } catch (IOException e) {
            Log.e(TAG, "IO Exception happened while reading whiteListApps");
            e.printStackTrace();
            return false;
        }
        Iterator<String> it = whiteListApps.iterator();
        while (it.hasNext()) {
            String whitelistItem = it.next();
            if (pkgName.equals(whitelistItem)) {
                Log.e(TAG, "isWhiteListApp: find matching package name "+pkgName);
                return true;
            }
        }
        Log.e(TAG, "isWhiteListApp: cann't find matching package name "+pkgName);
        return false;
    }

   * Moving the implementation of "pm install" to "cmd package install" changes the executing
 * context. Instead of being a stand alone process, "cmd package install" runs in the
 * system_server process. Due to SELinux rules, system_server cannot access many directories;
 * one of which being the package install staging directory [/data/local/tmp].
 *
 * The use of "adb install" or "cmd package install" over "pm install" is highly encouraged.
 */
private int runInstall() throws RemoteException {
    final InstallParams params = makeInstallParams();
    final String inPath = nextArg();

    String installerPackageName = "";
    if (mPm == null) {
        System.err.println(PM_NOT_RUNNING_ERR);
        return 1;
    }
    installerPackageName = mPm.getNameForUid(Binder.getCallingUid());
    Log.d(TAG, "Binder.getCallingUid() : " + Binder.getCallingUid());

    Log.d(TAG, "apkFilePath = "+inPath+", installerPackageName = "+installerPackageName);
    if (SystemProperties.getBoolean("persist.sys.whitelist", true)) {
        if(!isWhiteListApp(installerPackageName)) {
            System.err.println("Error: the app is not in app whitelist packageName " + installerPackageName);
            Log.e(TAG, installerPackageName + " is not in the whitelist.   install(pm way) not allowed");
            return 1;
        }
    }
    -----省略
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值