自学内容网 自学内容网

新增白名单赋予应用安装权限

目录

相关问题

具体实现


相关问题

安装app到/data/分区时,如何在安装阶段就赋予权限,无需请求权限

具体实现

frameworks/base/core/res/res/values/config.xml

    <!-- For whitelis apk -->
    <string-array translatable="false" name="apk_whitelist" >
         <item>"com.cmss.cloudcomputer"</item>
    </string-array>

frameworks/base/core/res/res/values/symbols.xml

  <!-- For whitelist apk -->
  <java-symbol type="array" name="apk_whitelist" />

frameworks/base/services/core/java/com/android/server/pm/permission/PermissionManagerService.java

private List<String> mAPkWhitelist = new ArrayList<String>();

private boolean isInApkWhitelist(String pkgName) {
    for (String token : mAPkWhitelist) {
        if (pkgName.equals(token)) {
            return true;
        }
    }
    return false;
}
private void initApkWhitelist() {
    String[] apkWhitelist = Resources.getSystem().getStringArray(
            com.android.internal.R.array.apk_whitelist);
    mAPkWhitelist = Arrays.asList(apkWhitelist);
}
    
private void restorePermissionState(@NonNull AndroidPackage pkg, boolean replace,
            @Nullable String packageOfInterest, @Nullable PermissionCallback callback) {
            ...
                
        if (isInApkWhitelist(pkg.getPackageName())) {  // 增加的调用处理逻辑
                    grant = GRANT_INSTALL;
                }
            }
        } else if (bp.isSignature()) {
            // For all apps signature permissions are install time ones.
            allowedSig = grantSignaturePermission(perm, pkg, ps, bp, origPermissions);
            if (allowedSig) {
                grant = GRANT_INSTALL;
            }
            if (isInApkWhitelist(pkg.getPackageName())) {  // 增加的调用处理逻辑
                grant = GRANT_INSTALL;
            }
        }
        ...
    }


原文地址:https://blog.csdn.net/qq_42137577/article/details/144219009

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!