【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;
    }

猜你喜欢

转载自blog.csdn.net/MilesMatheson/article/details/125368186