Merge "Preserve flags for non-runtime permissions upon package update." into udc-dev

This commit is contained in:
Treehugger Robot
2023-05-18 18:03:44 +00:00
committed by Android (Google) Code Review

View File

@@ -2810,29 +2810,55 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
+ pkg.getPackageName());
}
if ((bp.isNormal() && shouldGrantNormalPermission)
|| (bp.isSignature()
&& (!bp.isPrivileged() || CollectionUtils.contains(
isPrivilegedPermissionAllowlisted, permName))
&& (CollectionUtils.contains(shouldGrantSignaturePermission,
permName)
|| (((bp.isPrivileged() && CollectionUtils.contains(
shouldGrantPrivilegedPermissionIfWasGranted,
permName)) || bp.isDevelopment() || bp.isRole())
&& origState.isPermissionGranted(permName))))
|| (bp.isInternal()
&& (!bp.isPrivileged() || CollectionUtils.contains(
isPrivilegedPermissionAllowlisted, permName))
&& (CollectionUtils.contains(shouldGrantInternalPermission,
permName)
|| (((bp.isPrivileged() && CollectionUtils.contains(
shouldGrantPrivilegedPermissionIfWasGranted,
permName)) || bp.isDevelopment() || bp.isRole())
&& origState.isPermissionGranted(permName))))) {
// Grant an install permission.
if (uidState.grantPermission(bp)) {
installPermissionsChangedForUser = true;
if (bp.isNormal() || bp.isSignature() || bp.isInternal()) {
if ((bp.isNormal() && shouldGrantNormalPermission)
|| (bp.isSignature()
&& (!bp.isPrivileged() || CollectionUtils.contains(
isPrivilegedPermissionAllowlisted, permName))
&& (CollectionUtils.contains(shouldGrantSignaturePermission,
permName)
|| (((bp.isPrivileged() && CollectionUtils.contains(
shouldGrantPrivilegedPermissionIfWasGranted,
permName)) || bp.isDevelopment()
|| bp.isRole())
&& origState.isPermissionGranted(
permName))))
|| (bp.isInternal()
&& (!bp.isPrivileged() || CollectionUtils.contains(
isPrivilegedPermissionAllowlisted, permName))
&& (CollectionUtils.contains(shouldGrantInternalPermission,
permName)
|| (((bp.isPrivileged() && CollectionUtils.contains(
shouldGrantPrivilegedPermissionIfWasGranted,
permName)) || bp.isDevelopment()
|| bp.isRole())
&& origState.isPermissionGranted(
permName))))) {
// Grant an install permission.
if (uidState.grantPermission(bp)) {
installPermissionsChangedForUser = true;
}
} else {
if (DEBUG_PERMISSIONS) {
boolean wasGranted = uidState.isPermissionGranted(bp.getName());
if (wasGranted || bp.isAppOp()) {
Slog.i(TAG, (wasGranted ? "Un-granting" : "Not granting")
+ " permission " + perm
+ " from package " + friendlyName
+ " (protectionLevel=" + bp.getProtectionLevel()
+ " flags=0x"
+ Integer.toHexString(PackageInfoUtils.appInfoFlags(pkg,
ps))
+ ")");
}
}
if (uidState.revokePermission(bp)) {
installPermissionsChangedForUser = true;
}
}
PermissionState origPermState = origState.getPermissionState(perm);
int flags = origPermState != null ? origPermState.getFlags() : 0;
uidState.updatePermissionFlags(bp, MASK_PERMISSION_FLAGS_ALL, flags);
} else if (bp.isRuntime()) {
boolean hardRestricted = bp.isHardRestricted();
boolean softRestricted = bp.isSoftRestricted();
@@ -2956,22 +2982,8 @@ public class PermissionManagerServiceImpl implements PermissionManagerServiceInt
uidState.updatePermissionFlags(bp, MASK_PERMISSION_FLAGS_ALL,
flags);
} else {
if (DEBUG_PERMISSIONS) {
boolean wasGranted = uidState.isPermissionGranted(bp.getName());
if (wasGranted || bp.isAppOp()) {
Slog.i(TAG, (wasGranted ? "Un-granting" : "Not granting")
+ " permission " + perm
+ " from package " + friendlyName
+ " (protectionLevel=" + bp.getProtectionLevel()
+ " flags=0x"
+ Integer.toHexString(PackageInfoUtils.appInfoFlags(pkg,
ps))
+ ")");
}
}
if (uidState.removePermissionState(bp.getName())) {
installPermissionsChangedForUser = true;
}
Slog.wtf(LOG_TAG, "Unknown permission protection " + bp.getProtection()
+ " for permission " + bp.getName());
}
}