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

Commit d2ba4a0f authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Allow the supervision component requirement for...

Merge "Allow the supervision component requirement for DPM#setSecondaryLockscreenEnabled to be bypassed for testOnly admins."
parents de50855f 756df8e3
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -7867,15 +7867,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;
@@ -10225,6 +10231,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)));