summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yvonne Jiang <yvonnejiang@google.com> 2020-07-07 15:12:05 -0700
committer Yvonne Jiang <yvonnejiang@google.com> 2020-09-13 22:58:23 -0700
commit756df8e3b347002a99f2b73ddebefaad0d4686d8 (patch)
tree500adc0c965cab7e640db951fff57a0679db94ed
parent17efd71b2762a26461d1e325faa38279964c4273 (diff)
Allow the supervision component requirement for DPM#setSecondaryLockscreenEnabled to be bypassed for testOnly admins.
This allows for CTS test coverage of the API. Bug: 155120891 Test: atest FrameworksServicesTests:DevicePolicyManagerTest Test: atest -c 'CtsDevicePolicyManagerTestCases:com.android.cts.devicepolicy.MixedProfileOwnerTest#testSecondaryLockscreen' Change-Id: Ife0ede63bf7dc10f082451ea0b32ce01f14f97fc
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java18
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java10
2 files changed, 25 insertions, 3 deletions
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 4b9fab4d8ed6..d649bf14c767 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -7866,15 +7866,21 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
return null;
}
synchronized (getLockObject()) {
+ final ComponentName doComponent = mOwners.getDeviceOwnerComponent();
+ final ComponentName poComponent =
+ mOwners.getProfileOwnerComponent(userHandle.getIdentifier());
+ // Return test only admin by default.
+ if (isAdminTestOnlyLocked(doComponent, userHandle.getIdentifier())) {
+ return doComponent;
+ } else if (isAdminTestOnlyLocked(poComponent, userHandle.getIdentifier())) {
+ return poComponent;
+ }
final String supervisor = mContext.getResources().getString(
com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent);
if (supervisor == null) {
return null;
}
final ComponentName supervisorComponent = ComponentName.unflattenFromString(supervisor);
- final ComponentName doComponent = mOwners.getDeviceOwnerComponent();
- final ComponentName poComponent =
- mOwners.getProfileOwnerComponent(userHandle.getIdentifier());
if (supervisorComponent.equals(doComponent) || supervisorComponent.equals(
poComponent)) {
return supervisorComponent;
@@ -10224,6 +10230,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
throw new SecurityException(
"User " + userId + " is not allowed to call setSecondaryLockscreenEnabled");
}
+ synchronized (getLockObject()) {
+ if (isAdminTestOnlyLocked(who, userId)) {
+ // Allow testOnly admins to bypass supervision config requirement.
+ return;
+ }
+ }
// Only the default supervision app can use this API.
final String supervisor = mContext.getResources().getString(
com.android.internal.R.string.config_defaultSupervisionProfileOwnerComponent);
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 8759077ea0ad..3a8d9c3e9ff5 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -4392,6 +4392,16 @@ public class DevicePolicyManagerTest extends DpmTestBase {
public void testSecondaryLockscreen_nonSupervisionApp() throws Exception {
mContext.binder.callingUid = DpmMockContext.CALLER_UID;
+ // Ensure packages are *not* flagged as test_only.
+ doReturn(new ApplicationInfo()).when(getServices().ipackageManager).getApplicationInfo(
+ eq(admin1.getPackageName()),
+ anyInt(),
+ eq(CALLER_USER_HANDLE));
+ doReturn(new ApplicationInfo()).when(getServices().ipackageManager).getApplicationInfo(
+ eq(admin2.getPackageName()),
+ anyInt(),
+ eq(CALLER_USER_HANDLE));
+
// Initial state is disabled.
assertFalse(dpm.isSecondaryLockscreenEnabled(UserHandle.of(CALLER_USER_HANDLE)));