在系统产品的定制化需求中,往往需要去掉app起来后的运行权限申请
android9 - android11
源码位置
base/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
if (bp.isNormal()) {
// For all apps normal permissions are install time ones.
grant = GRANT_INSTALL;
} else if (bp.isRuntime()) {
if (mPermissionReviewRequiredWhiteList.contains(pkg.getPackageName())) {
//白名单判断条件,根据自己需求添加
grant = GRANT_INSTALL;
} else if (origPermissions.hasInstallPermission(bp.getName())
|| upgradedActivityRecognitionPermission != null) {
// Before Q we represented some runtime permissions as install permissions,
// in Q we cannot do this anymore. Hence upgrade them all.
grant = GRANT_UPGRADE;
} else {
// For modern apps keep runtime permissions unchanged.
//grant = GRANT_RUNTIME;
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;
}
}
android13
源码位置
base/services/core/java/com/android/server/pm/permission/PermissionManagerServiceImpl.java
uidState.revokePermission(bp);
uidState.updatePermissionFlags(bp, MASK_PERMISSION_FLAGS_ALL, 0);
updatedUserIds = ArrayUtils.appendInt(updatedUserIds, userId);
// Grant an install permission.
if (uidState.grantPermission(bp)) {
changedInstallPermission = true;
}