From 68bfe3e09eadb15c237d6fb6838f3336c5713afd Mon Sep 17 00:00:00 2001 From: Elis Elliott Date: Tue, 21 Feb 2023 18:02:15 +0000 Subject: [PATCH] Fix delegates access to API with permission checks. Fixes: 267304739 Test: btest a.d.c.PermissionGrantTest -c yes Test: btest a.d.c.SecurityLoggingTest -c yes Test: btest a.d.c.ApplicationRestrictionsTest -c yes Test: btest a.d.c.ApplicationHiddenTest -c yes Test: btest a.d.c.BlockUninstallTest -c yes Change-Id: Ib5f2dbd877e513655fc014d4a0438b603b75bf2e --- .../devicepolicy/DevicePolicyManagerService.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 3c3cb2b49ba3b..b7a7e32a03682 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -11338,7 +11338,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { DevicePolicyEventLogger .createEvent(DevicePolicyEnums.SET_APPLICATION_RESTRICTIONS) .setAdmin(caller.getPackageName()) - .setBoolean(/* isDelegate */ who == null) + .setBoolean(/* isDelegate */ isCallerDelegate(caller)) .setStrings(packageName) .write(); } @@ -13379,7 +13379,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { DevicePolicyEventLogger .createEvent(DevicePolicyEnums.SET_APPLICATION_HIDDEN) .setAdmin(caller.getPackageName()) - .setBoolean(/* isDelegate */ who == null) + .setBoolean(/* isDelegate */ isCallerDelegate(caller)) .setStrings(packageName, hidden ? "hidden" : "not_hidden", parent ? CALLED_FROM_PARENT : NOT_CALLED_FROM_PARENT) .write(); @@ -13731,7 +13731,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { DevicePolicyEventLogger .createEvent(DevicePolicyEnums.SET_UNINSTALL_BLOCKED) .setAdmin(caller.getPackageName()) - .setBoolean(/* isDelegate */ who == null) + .setBoolean(/* isDelegate */ isCallerDelegate(caller)) .setStrings(packageName) .write(); } @@ -16281,7 +16281,8 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { .setAdmin(caller.getPackageName()) .setStrings(permission) .setInt(grantState) - .setBoolean(/* isDelegate */ admin == null) + .setBoolean( + /* isDelegate */ isCallerDelegate(caller)) .write(); callback.sendResult(Bundle.EMPTY); @@ -22184,6 +22185,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { private static final HashMap DELEGATE_SCOPES = new HashMap<>(); { DELEGATE_SCOPES.put(MANAGE_DEVICE_POLICY_RUNTIME_PERMISSIONS, DELEGATION_PERMISSION_GRANT); + DELEGATE_SCOPES.put(MANAGE_DEVICE_POLICY_APP_RESTRICTIONS, DELEGATION_APP_RESTRICTIONS); + DELEGATE_SCOPES.put(MANAGE_DEVICE_POLICY_APPS_CONTROL, DELEGATION_BLOCK_UNINSTALL); + DELEGATE_SCOPES.put(MANAGE_DEVICE_POLICY_SECURITY_LOGGING, DELEGATION_SECURITY_LOGGING); + DELEGATE_SCOPES.put(MANAGE_DEVICE_POLICY_PACKAGE_STATE, DELEGATION_PACKAGE_ACCESS); } private static final HashMap CROSS_USER_PERMISSIONS = @@ -22372,6 +22377,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { + permission + ", " + CROSS_USER_PERMISSIONS.get(permission) + + "(if calling cross-user)" + "}"); } }