Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 756df8e3 authored by Yvonne Jiang's avatar Yvonne Jiang
Browse files

Allow the supervision component requirement for...

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
parent 17efd71b
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -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);
+10 −0
Original line number Diff line number Diff line
@@ -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)));