【android系统修改】RestoreActivity过滤应用

问题:

Android 9.0系统的一个项目中需要放两个设置,隐藏其中一个。但是会导致同一个Action启动设置会弹出应用选择。隐藏的设置会暴露出来。

解决:

使用同一个Action启动设置应用,弹出的应用选择弹窗其实是系统的RestoreActivity。

framework/base 中搜索ResolverListController.java,可以到以下方法

    @VisibleForTesting
    public ArrayList<ResolverActivity.ResolvedComponentInfo> filterIneligibleActivities(
            List<ResolverActivity.ResolvedComponentInfo> inputList,
            boolean returnCopyOfOriginalListIfModified) {
        ArrayList<ResolverActivity.ResolvedComponentInfo> listToReturn = null;
        for (int i = inputList.size()-1; i >= 0; i--) {
            ActivityInfo ai = inputList.get(i)
                    .getResolveInfoAt(0).activityInfo;
            int granted = ActivityManager.checkComponentPermission(
                    ai.permission, mLaunchedFromUid,
                    ai.applicationInfo.uid, ai.exported);
            boolean suspended = (ai.applicationInfo.flags
                    & ApplicationInfo.FLAG_SUSPENDED) != 0;
            if (granted != PackageManager.PERMISSION_GRANTED || suspended
                    || isComponentFiltered(ai.getComponentName())) {
                // Access not allowed! We're about to filter an item,
                // so modify the unfiltered version if it hasn't already been modified.
                if (returnCopyOfOriginalListIfModified && listToReturn == null) {
                    listToReturn = new ArrayList<>(inputList);
                }
                inputList.remove(i);
            }
        }
        return listToReturn;
    }

发现此过滤方法 isComponentFiltered(ai.getComponentName(),假设要应用选择界面想要隐藏的应用包名为com.test.setting,做如下修改过滤掉即可

    boolean isComponentFiltered(ComponentName componentName) {
        Log.e(TAG,"isComponentFiltered: componentName: " + componentName);
        if("com.test.setting".equals(componentName.getPackageName())){
            Log.e(TAG,"isComponentFiltered: return true");
            return true;
        }
        return false;
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值