DPM API review: Remove "ForUser" method
Replace the setProfileOwnerCanAccessDeviceIdsForUser with
setProfileOwnerCanAccessDeviceIds that takes the DPM's user ID.
Per automated API review, new methods that target a specific user (by
taking in a UserHandle) are discouraged.
Instead, the caller should get the user-specific service from the user
context.
Bug: 126700461
Bug: 126699845
Test: Manually, flashed a device and set-up TestDPC on it straight to
work profile, then verified it can do Device ID attestation.
Test: atest FrameworksServicesTests:DevicePolicyManagerTest
Change-Id: I13f20f4a434394f266a3dc2373152cb1b9ea2d2b
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index 28a815e..bd7774a 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -5021,8 +5021,7 @@
configureContextForAccess(mContext, false);
assertExpectException(SecurityException.class, /* messageRegex= */ null,
- () -> dpm.setProfileOwnerCanAccessDeviceIdsForUser(admin2,
- UserHandle.of(DpmMockContext.CALLER_UID)));
+ () -> dpm.setProfileOwnerCanAccessDeviceIds(admin2));
}
public void testGrantDeviceIdsAccess_notByAuthorizedCaller() throws Exception {
@@ -5030,8 +5029,7 @@
configureContextForAccess(mContext, false);
assertExpectException(SecurityException.class, /* messageRegex= */ null,
- () -> dpm.setProfileOwnerCanAccessDeviceIdsForUser(admin1,
- UserHandle.of(DpmMockContext.CALLER_UID)));
+ () -> dpm.setProfileOwnerCanAccessDeviceIds(admin1));
}
public void testGrantDeviceIdsAccess_byAuthorizedSystemCaller() throws Exception {
@@ -5060,8 +5058,7 @@
DpmMockContext.CALLER_MANAGED_PROVISIONING_UID);
try {
runAsCaller(mServiceContext, dpms, dpm -> {
- dpm.setProfileOwnerCanAccessDeviceIdsForUser(admin1,
- UserHandle.of(DpmMockContext.CALLER_USER_HANDLE));
+ dpm.setProfileOwnerCanAccessDeviceIds(admin1);
});
} finally {
mServiceContext.binder.restoreCallingIdentity(ident);
@@ -5314,7 +5311,7 @@
mServiceContext.binder.callingUid =
UserHandle.getUid(DpmMockContext.CALLER_USER_HANDLE, DpmMockContext.SYSTEM_UID);
runAsCaller(mServiceContext, dpms, dpm -> {
- dpm.setProfileOwnerCanAccessDeviceIdsForUser(who, UserHandle.of(userId));
+ dpm.setProfileOwnerCanAccessDeviceIds(who);
});
mServiceContext.binder.restoreCallingIdentity(ident);
}