Loading core/java/android/content/pm/multiuser.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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 services/core/java/com/android/server/pm/UserManagerService.java +22 −8 Original line number Diff line number Diff line Loading @@ -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 " Loading @@ -721,8 +728,6 @@ public class UserManagerService extends IUserManager.Stub { mContext.getPackageName()); } } } } @VisibleForTesting void setQuietModeEnabledAsync(@UserIdInt int userId, boolean enableQuietMode, Loading Loading @@ -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. Loading services/tests/mockingservicestests/src/com/android/server/pm/UserManagerServiceTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -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); Loading Loading
core/java/android/content/pm/multiuser.aconfig +7 −0 Original line number Diff line number Diff line Loading @@ -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
services/core/java/com/android/server/pm/UserManagerService.java +22 −8 Original line number Diff line number Diff line Loading @@ -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 " Loading @@ -721,8 +728,6 @@ public class UserManagerService extends IUserManager.Stub { mContext.getPackageName()); } } } } @VisibleForTesting void setQuietModeEnabledAsync(@UserIdInt int userId, boolean enableQuietMode, Loading Loading @@ -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. Loading
services/tests/mockingservicestests/src/com/android/server/pm/UserManagerServiceTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -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); Loading