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

Commit 8ce93390 authored by Jigar Thakkar's avatar Jigar Thakkar Committed by Android (Google) Code Review
Browse files

Merge "Auto lock private space on device restarts" into main

parents 0056f713 3d211df6
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -78,3 +78,10 @@ flag {
    description: "Move the quiet mode operations, happening on a background thread today, to a separate thread."
    bug: "320483504"
}

flag {
    name: "enable_private_space_autolock_on_restarts"
    namespace: "profile_experiences"
    description: "Enable auto-locking private space on device restarts"
    bug: "296993385"
}
 No newline at end of file
+22 −8
Original line number Diff line number Diff line
@@ -712,6 +712,13 @@ public class UserManagerService extends IUserManager.Stub {
            boolean isAutoLockOnDeviceLockSelected =
                    autoLockPreference == Settings.Secure.PRIVATE_SPACE_AUTO_LOCK_ON_DEVICE_LOCK;
            if (isKeyguardLocked && isAutoLockOnDeviceLockSelected) {
                autoLockPrivateSpace();
            }
        }
    }

    @VisibleForTesting
    void autoLockPrivateSpace() {
        int privateProfileUserId = getPrivateProfileUserId();
        if (privateProfileUserId != UserHandle.USER_NULL) {
            Slog.i(LOG_TAG, "Auto-locking private space with user-id "
@@ -721,8 +728,6 @@ public class UserManagerService extends IUserManager.Stub {
                    mContext.getPackageName());
        }
    }
        }
    }

    @VisibleForTesting
    void setQuietModeEnabledAsync(@UserIdInt int userId, boolean enableQuietMode,
@@ -1036,9 +1041,18 @@ public class UserManagerService extends IUserManager.Stub {
            }
        }

        if (isAutoLockingPrivateSpaceOnRestartsEnabled()) {
            autoLockPrivateSpace();
        }

        markEphemeralUsersForRemoval();
    }

    private boolean isAutoLockingPrivateSpaceOnRestartsEnabled() {
        return android.os.Flags.allowPrivateProfile()
                && android.multiuser.Flags.enablePrivateSpaceAutolockOnRestarts();
    }

    /**
     * This method retrieves the  {@link UserManagerInternal} only for the purpose of
     * PackageManagerService construction.
+17 −0
Original line number Diff line number Diff line
@@ -568,6 +568,23 @@ public final class UserManagerServiceTest {
        assertTrue(hasRestrictionsInUserXMLFile(user.id));
    }

    @Test
    public void testAutoLockPrivateProfile() {
        UserManagerService mSpiedUms = spy(mUms);
        UserInfo privateProfileUser =
                mSpiedUms.createProfileForUserEvenWhenDisallowedWithThrow("TestPrivateProfile",
                        USER_TYPE_PROFILE_PRIVATE, 0, 0, null);
        Mockito.doNothing().when(mSpiedUms).setQuietModeEnabledAsync(
                eq(privateProfileUser.getUserHandle().getIdentifier()), eq(true), any(),
                any());

        mSpiedUms.autoLockPrivateSpace();

        Mockito.verify(mSpiedUms).setQuietModeEnabledAsync(
                eq(privateProfileUser.getUserHandle().getIdentifier()), eq(true),
                any(), any());
    }

    @Test
    public void testAutoLockOnDeviceLockForPrivateProfile() {
        mSetFlagsRule.enableFlags(Flags.FLAG_SUPPORT_AUTOLOCK_FOR_PRIVATE_SPACE);