2022-04-10 20:24:01 -04:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: inthewaves <inthewaves@pm.me>
|
|
|
|
Date: Sat, 12 Sep 2020 12:28:34 -0700
|
|
|
|
Subject: [PATCH] support new special runtime permissions
|
|
|
|
|
|
|
|
These are treated as a runtime permission even for legacy apps. They
|
|
|
|
need to be granted by default for all apps to maintain compatibility.
|
|
|
|
|
|
|
|
Ported from 10: 4d5d82f4e2fb9ff68158bf30f3944591bb74dd04
|
|
|
|
|
|
|
|
Changes from 10:
|
|
|
|
- It seems like parts of PackageManagerService#resetUserChangesToRuntimePermissionsAndFlagsLPw
|
|
|
|
were refactored into PermissionManagerService#resetRuntimePermissionsInternal.
|
|
|
|
As a result, PackageManagerService is no longer modified.
|
|
|
|
---
|
|
|
|
.../permission/PermissionManagerService.java | 24 +++++++++++++++----
|
|
|
|
1 file changed, 19 insertions(+), 5 deletions(-)
|
|
|
|
|
|
|
|
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
|
2024-07-15 14:10:41 -04:00
|
|
|
index 53164c7424d5..64a1b5b6bb6a 100644
|
2022-04-10 20:24:01 -04:00
|
|
|
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
|
|
|
|
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -1462,7 +1462,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
// to keep the review required permission flag per user while an
|
|
|
|
// install permission's state is shared across all users.
|
|
|
|
if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M
|
|
|
|
- && bp.isRuntime()) {
|
|
|
|
+ && bp.isRuntime() && !isSpecialRuntimePermission(permName)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -1514,7 +1514,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
+ permName + " for package " + packageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
- if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M) {
|
|
|
|
+ if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M
|
|
|
|
+ && !isSpecialRuntimePermission(permName)) {
|
|
|
|
Slog.w(TAG, "Cannot grant runtime permission to a legacy app");
|
|
|
|
return;
|
|
|
|
}
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -1624,7 +1625,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
// to keep the review required permission flag per user while an
|
|
|
|
// install permission's state is shared across all users.
|
|
|
|
if (pkg.getTargetSdkVersion() < Build.VERSION_CODES.M
|
|
|
|
- && bp.isRuntime()) {
|
|
|
|
+ && bp.isRuntime() && !isSpecialRuntimePermission(bp.name)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -1848,7 +1849,8 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
|
|
|
|
// If this permission was granted by default or role, make sure it is.
|
|
|
|
if ((oldFlags & FLAG_PERMISSION_GRANTED_BY_DEFAULT) != 0
|
|
|
|
- || (oldFlags & FLAG_PERMISSION_GRANTED_BY_ROLE) != 0) {
|
|
|
|
+ || (oldFlags & FLAG_PERMISSION_GRANTED_BY_ROLE) != 0
|
|
|
|
+ || isSpecialRuntimePermission(bp.getName())) {
|
|
|
|
// PermissionPolicyService will handle the app op for runtime permissions later.
|
|
|
|
grantRuntimePermissionInternal(permName, packageName, false,
|
|
|
|
Process.SYSTEM_UID, userId, delayingPermCallback);
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -2647,6 +2649,10 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static boolean isSpecialRuntimePermission(final String permission) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* Restore the permission state for a package.
|
|
|
|
*
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -2999,6 +3005,14 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ if (isSpecialRuntimePermission(bp.name) &&
|
|
|
|
+ origPermissions.getRuntimePermissionState(bp.name, userId) == null) {
|
|
|
|
+ if (permissionsState.grantRuntimePermission(bp, userId)
|
|
|
|
+ != PERMISSION_OPERATION_FAILURE) {
|
|
|
|
+ wasChanged = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
} else {
|
|
|
|
if (permState == null) {
|
|
|
|
// New permission
|
2024-06-17 02:18:04 -04:00
|
|
|
@@ -3961,7 +3975,7 @@ public class PermissionManagerService extends IPermissionManager.Stub {
|
2022-04-10 20:24:01 -04:00
|
|
|
&& (grantedPermissions == null
|
|
|
|
|| ArrayUtils.contains(grantedPermissions, permission))) {
|
|
|
|
final int flags = permissionsState.getPermissionFlags(permission, userId);
|
|
|
|
- if (supportsRuntimePermissions) {
|
|
|
|
+ if (supportsRuntimePermissions || isSpecialRuntimePermission(bp.name)) {
|
|
|
|
// Installer cannot change immutable permissions.
|
|
|
|
if ((flags & immutableFlags) == 0) {
|
|
|
|
grantRuntimePermissionInternal(permission, pkg.getPackageName(), false,
|