summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Elis Elliott <eliselliott@google.com> 2023-05-11 15:24:10 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-05-11 15:24:10 +0000
commit03a43c31c3e13fb80bc1ca7235ee23a3a895320d (patch)
tree5be51c2531050217589689104c942c1d008bbcb1
parent28ce92a21fbdf10d77543425525c4ef5638f4c2a (diff)
parent78bcc2f399b0deec3215910e0ea4f40692aea16f (diff)
Merge "Fix APIs which use admin policies in permission check" into udc-dev
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java40
1 files changed, 24 insertions, 16 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 7b01a3af46a7..187e51ad9cf6 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -5553,7 +5553,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
if (isPermissionCheckFlagEnabled()) {
CallerIdentity caller = getCallerIdentity(who, callerPackageName);
ap = enforcePermissionAndGetEnforcingAdmin(
- who, MANAGE_DEVICE_POLICY_WIPE_DATA,
+ who,
+ /*permission=*/ MANAGE_DEVICE_POLICY_WIPE_DATA,
+ /* adminPolicy=*/ DeviceAdminInfo.USES_POLICY_WIPE_DATA,
caller.getPackageName(), affectedUserId).getActiveAdmin();
} else {
// This API can only be called by an active device admin,
@@ -5835,9 +5837,11 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
ActiveAdmin ap;
if (isPermissionCheckFlagEnabled()) {
CallerIdentity caller = getCallerIdentity(who, callerPackageName);
- // TODO: Allow use of USES_POLICY_FORCE_LOCK
ap = enforcePermissionAndGetEnforcingAdmin(
- who, MANAGE_DEVICE_POLICY_LOCK, caller.getPackageName(),
+ who,
+ /*permission=*/ MANAGE_DEVICE_POLICY_LOCK,
+ /*AdminPolicy=*/DeviceAdminInfo.USES_POLICY_FORCE_LOCK,
+ caller.getPackageName(),
affectedUserId).getActiveAdmin();
} else {
ap = getActiveAdminForCallerLocked(
@@ -11802,9 +11806,10 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
if (isPermissionCheckFlagEnabled()) {
CallerIdentity caller = getCallerIdentity(admin, callerPackageName);
int affectedUserId = parent ? getProfileParentId(userHandle) : userHandle;
- // TODO: Support USES_POLICY_DISABLE_KEYGUARD_FEATURES
ap = enforcePermissionAndGetEnforcingAdmin(
- admin, MANAGE_DEVICE_POLICY_KEYGUARD,
+ admin,
+ /*permission=*/MANAGE_DEVICE_POLICY_KEYGUARD,
+ /*adminPolicy=*/DeviceAdminInfo.USES_POLICY_DISABLE_KEYGUARD_FEATURES,
caller.getPackageName(), affectedUserId).getActiveAdmin();
} else {
ap = getActiveAdminForCallerLocked(admin,
@@ -13350,23 +13355,23 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
caller = getCallerIdentity(who);
}
int userId = caller.getUserId();
+ int affectedUserId = parent ? getProfileParentId(userId) : userId;
checkCanExecuteOrThrowUnsafe(DevicePolicyManager.OPERATION_SET_USER_RESTRICTION);
if (isPolicyEngineForFinanceFlagEnabled()) {
if (!isDeviceOwner(caller) && !isProfileOwner(caller)) {
+ EnforcingAdmin admin = enforcePermissionForUserRestriction(
+ who,
+ key,
+ caller.getPackageName(),
+ affectedUserId);
if (!mInjector.isChangeEnabled(ENABLE_COEXISTENCE_CHANGE, callerPackage, userId)) {
throw new IllegalStateException("Calling package is not targeting Android U.");
}
if (!UserRestrictionsUtils.isValidRestriction(key)) {
throw new IllegalArgumentException("Invalid restriction key: " + key);
}
- int affectedUserId = parent ? getProfileParentId(userId) : userId;
- EnforcingAdmin admin = enforcePermissionForUserRestriction(
- who,
- key,
- caller.getPackageName(),
- affectedUserId);
PolicyDefinition<Boolean> policyDefinition =
PolicyDefinition.getPolicyDefinitionForUserRestriction(key);
if (enabledFromThisOwner) {
@@ -22998,6 +23003,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
MANAGE_DEVICE_POLICY_FACTORY_RESET,
MANAGE_DEVICE_POLICY_INSTALL_UNKNOWN_SOURCES,
MANAGE_DEVICE_POLICY_KEYGUARD,
+ MANAGE_DEVICE_POLICY_LOCK_CREDENTIALS,
MANAGE_DEVICE_POLICY_LOCK_TASK,
MANAGE_DEVICE_POLICY_ORGANIZATION_IDENTITY,
MANAGE_DEVICE_POLICY_RUNTIME_PERMISSIONS,
@@ -23005,7 +23011,7 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
MANAGE_DEVICE_POLICY_SUPPORT_MESSAGE,
MANAGE_DEVICE_POLICY_TIME,
MANAGE_DEVICE_POLICY_USERS,
- MANAGE_DEVICE_POLICY_LOCK_CREDENTIALS
+ MANAGE_DEVICE_POLICY_WIPE_DATA
);
/**
@@ -23525,14 +23531,15 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
*
* @param callerPackageName The package name of the calling application.
* @param adminPolicy The admin policy that should grant holders permission.
- * @param permission The name of the permission being checked.
+ * @param permissions The names of the permissions being checked.
* @param targetUserId The userId of the user which the caller needs permission to act on.
* @throws SecurityException if the caller has not been granted the given permission,
* the associated cross-user permission if the caller's user is different to the target user.
*/
private void enforcePermissions(String[] permissions, int adminPolicy,
String callerPackageName, int targetUserId) throws SecurityException {
- if (hasAdminPolicy(adminPolicy, callerPackageName)) {
+ if (hasAdminPolicy(adminPolicy, callerPackageName)
+ && mInjector.userHandleGetCallingUserId() == targetUserId) {
return;
}
enforcePermissions(permissions, callerPackageName, targetUserId);
@@ -23561,8 +23568,9 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub {
private boolean hasAdminPolicy(int adminPolicy, String callerPackageName) {
CallerIdentity caller = getCallerIdentity(callerPackageName);
- ActiveAdmin deviceAdmin = getActiveAdminForCaller(null, caller);
- return deviceAdmin != null && deviceAdmin.info.usesPolicy(adminPolicy);
+ ActiveAdmin deviceAdmin = getActiveAdminWithPolicyForUidLocked(
+ null, adminPolicy, caller.getUid());
+ return deviceAdmin != null;
}
/**