Android 禁止带有home属性的APP安装

过滤Home属性的应用,然后禁止此类应用的安装,目前定制项目中十有八九都是客户提供launcher,然后禁止别的launcher安装,如何屏蔽呢?修改文件frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java,修改里面的私有方法installNewPackageLIF,

    private static boolean hasLauncherCatagory(ActivityIntentInfo filter) {
        return filter.hasCategory(Intent.CATEGORY_HOME);
    }


    /*
     * Install a non-existing package.
     */
    private void installNewPackageLIF(PackageParser.Package pkg, final int policyFlags,
            int scanFlags, UserHandle user, String installerPackageName, String volumeUuid,
            PackageInstalledInfo res) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "installNewPackage");

        // Remember this for later, in case we need to rollback this install
        String pkgName = pkg.packageName;

        .......//省略若干行

        try {
            PackageParser.Package newPackage = scanPackageTracedLI(pkg, policyFlags, scanFlags,System.currentTimeMillis(), user);

           //add for prevent 3rd app  to be installed start 
            for (PackageParser.Activity a : newPackage.activities) {
                for (ActivityIntentInfo filter : a.intents) {
                    if (hasLauncherCatagory(filter) && !pkgName.equals("com.vc")) { //判断是否是launcher
                        deletePackageLIF(pkgName, UserHandle.ALL, false, null, 0,res.removedInfo, false,null);    //如果是launcher就删除文件,并且提示无法安装
                        res.setError(INSTALL_FAILED_INVALID_INSTALL_LOCATION,
                                "Cannot install updates to system or vendor apps on sdcard");
                        return;

                    }
                }
            }
            //add for prevent 3rd app  to be installed end

            updateSettingsLI(newPackage, installerPackageName, null, res, user);
            ......//省略若干行

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值