Loading core/java/com/android/internal/widget/LockPatternUtils.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -1320,8 +1320,8 @@ public class LockPatternUtils { } } public boolean isUserInLockdown(int userId) { public boolean isUserInLockdown(int userId) { return getStrongAuthForUser(userId) return (getStrongAuthForUser(userId) == StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; & StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN) != 0; } } private static class WrappedCallback extends ICheckCredentialProgressCallback.Stub { private static class WrappedCallback extends ICheckCredentialProgressCallback.Stub { Loading core/tests/utiltests/src/com/android/internal/util/LockPatternUtilsTest.java +34 −5 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,9 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_MANAGED; import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -70,12 +72,15 @@ import java.util.List; @SmallTest @SmallTest public class LockPatternUtilsTest { public class LockPatternUtilsTest { private ILockSettings mLockSettings; private static final int USER_ID = 1; private static final int DEMO_USER_ID = 5; private static final int DEMO_USER_ID = 5; private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils; private void configureTest(boolean isSecure, boolean isDemoUser, int deviceDemoMode) private void configureTest(boolean isSecure, boolean isDemoUser, int deviceDemoMode) throws Exception { throws Exception { mLockSettings = Mockito.mock(ILockSettings.class); final Context context = spy(new ContextWrapper(InstrumentationRegistry.getTargetContext())); final Context context = spy(new ContextWrapper(InstrumentationRegistry.getTargetContext())); final MockContentResolver cr = new MockContentResolver(context); final MockContentResolver cr = new MockContentResolver(context); Loading @@ -83,15 +88,14 @@ public class LockPatternUtilsTest { when(context.getContentResolver()).thenReturn(cr); when(context.getContentResolver()).thenReturn(cr); Settings.Global.putInt(cr, Settings.Global.DEVICE_DEMO_MODE, deviceDemoMode); Settings.Global.putInt(cr, Settings.Global.DEVICE_DEMO_MODE, deviceDemoMode); final ILockSettings ils = Mockito.mock(ILockSettings.class); when(mLockSettings.getCredentialType(DEMO_USER_ID)).thenReturn( when(ils.getCredentialType(DEMO_USER_ID)).thenReturn( isSecure ? LockPatternUtils.CREDENTIAL_TYPE_PASSWORD isSecure ? LockPatternUtils.CREDENTIAL_TYPE_PASSWORD : LockPatternUtils.CREDENTIAL_TYPE_NONE); : LockPatternUtils.CREDENTIAL_TYPE_NONE); when(ils.getLong("lockscreen.password_type", PASSWORD_QUALITY_UNSPECIFIED, DEMO_USER_ID)) when(mLockSettings.getLong("lockscreen.password_type", PASSWORD_QUALITY_UNSPECIFIED, .thenReturn((long) PASSWORD_QUALITY_MANAGED); DEMO_USER_ID)).thenReturn((long) PASSWORD_QUALITY_MANAGED); // TODO(b/63758238): stop spying the class under test // TODO(b/63758238): stop spying the class under test mLockPatternUtils = spy(new LockPatternUtils(context)); mLockPatternUtils = spy(new LockPatternUtils(context)); when(mLockPatternUtils.getLockSettings()).thenReturn(ils); when(mLockPatternUtils.getLockSettings()).thenReturn(mLockSettings); doReturn(true).when(mLockPatternUtils).hasSecureLockScreen(); doReturn(true).when(mLockPatternUtils).hasSecureLockScreen(); final UserInfo userInfo = Mockito.mock(UserInfo.class); final UserInfo userInfo = Mockito.mock(UserInfo.class); Loading @@ -101,6 +105,31 @@ public class LockPatternUtilsTest { when(context.getSystemService(Context.USER_SERVICE)).thenReturn(um); when(context.getSystemService(Context.USER_SERVICE)).thenReturn(um); } } @Test public void isUserInLockDown() throws Exception { configureTest(true, false, 2); // GIVEN strong auth not required when(mLockSettings.getStrongAuthForUser(USER_ID)).thenReturn(STRONG_AUTH_NOT_REQUIRED); // THEN user isn't in lockdown assertFalse(mLockPatternUtils.isUserInLockdown(USER_ID)); // GIVEN lockdown when(mLockSettings.getStrongAuthForUser(USER_ID)).thenReturn( STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); // THEN user is in lockdown assertTrue(mLockPatternUtils.isUserInLockdown(USER_ID)); // GIVEN lockdown and lockout when(mLockSettings.getStrongAuthForUser(USER_ID)).thenReturn( STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN | STRONG_AUTH_REQUIRED_AFTER_LOCKOUT); // THEN user is in lockdown assertTrue(mLockPatternUtils.isUserInLockdown(USER_ID)); } @Test @Test public void isLockScreenDisabled_isDemoUser_true() throws Exception { public void isLockScreenDisabled_isDemoUser_true() throws Exception { configureTest(false, true, 2); configureTest(false, true, 2); Loading Loading
core/java/com/android/internal/widget/LockPatternUtils.java +2 −2 Original line number Original line Diff line number Diff line Loading @@ -1320,8 +1320,8 @@ public class LockPatternUtils { } } public boolean isUserInLockdown(int userId) { public boolean isUserInLockdown(int userId) { return getStrongAuthForUser(userId) return (getStrongAuthForUser(userId) == StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; & StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN) != 0; } } private static class WrappedCallback extends ICheckCredentialProgressCallback.Stub { private static class WrappedCallback extends ICheckCredentialProgressCallback.Stub { Loading
core/tests/utiltests/src/com/android/internal/util/LockPatternUtilsTest.java +34 −5 Original line number Original line Diff line number Diff line Loading @@ -20,7 +20,9 @@ import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_MANAGED; import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.SOME_AUTH_REQUIRED_AFTER_TRUSTAGENT_EXPIRED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT; import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat; Loading Loading @@ -70,12 +72,15 @@ import java.util.List; @SmallTest @SmallTest public class LockPatternUtilsTest { public class LockPatternUtilsTest { private ILockSettings mLockSettings; private static final int USER_ID = 1; private static final int DEMO_USER_ID = 5; private static final int DEMO_USER_ID = 5; private LockPatternUtils mLockPatternUtils; private LockPatternUtils mLockPatternUtils; private void configureTest(boolean isSecure, boolean isDemoUser, int deviceDemoMode) private void configureTest(boolean isSecure, boolean isDemoUser, int deviceDemoMode) throws Exception { throws Exception { mLockSettings = Mockito.mock(ILockSettings.class); final Context context = spy(new ContextWrapper(InstrumentationRegistry.getTargetContext())); final Context context = spy(new ContextWrapper(InstrumentationRegistry.getTargetContext())); final MockContentResolver cr = new MockContentResolver(context); final MockContentResolver cr = new MockContentResolver(context); Loading @@ -83,15 +88,14 @@ public class LockPatternUtilsTest { when(context.getContentResolver()).thenReturn(cr); when(context.getContentResolver()).thenReturn(cr); Settings.Global.putInt(cr, Settings.Global.DEVICE_DEMO_MODE, deviceDemoMode); Settings.Global.putInt(cr, Settings.Global.DEVICE_DEMO_MODE, deviceDemoMode); final ILockSettings ils = Mockito.mock(ILockSettings.class); when(mLockSettings.getCredentialType(DEMO_USER_ID)).thenReturn( when(ils.getCredentialType(DEMO_USER_ID)).thenReturn( isSecure ? LockPatternUtils.CREDENTIAL_TYPE_PASSWORD isSecure ? LockPatternUtils.CREDENTIAL_TYPE_PASSWORD : LockPatternUtils.CREDENTIAL_TYPE_NONE); : LockPatternUtils.CREDENTIAL_TYPE_NONE); when(ils.getLong("lockscreen.password_type", PASSWORD_QUALITY_UNSPECIFIED, DEMO_USER_ID)) when(mLockSettings.getLong("lockscreen.password_type", PASSWORD_QUALITY_UNSPECIFIED, .thenReturn((long) PASSWORD_QUALITY_MANAGED); DEMO_USER_ID)).thenReturn((long) PASSWORD_QUALITY_MANAGED); // TODO(b/63758238): stop spying the class under test // TODO(b/63758238): stop spying the class under test mLockPatternUtils = spy(new LockPatternUtils(context)); mLockPatternUtils = spy(new LockPatternUtils(context)); when(mLockPatternUtils.getLockSettings()).thenReturn(ils); when(mLockPatternUtils.getLockSettings()).thenReturn(mLockSettings); doReturn(true).when(mLockPatternUtils).hasSecureLockScreen(); doReturn(true).when(mLockPatternUtils).hasSecureLockScreen(); final UserInfo userInfo = Mockito.mock(UserInfo.class); final UserInfo userInfo = Mockito.mock(UserInfo.class); Loading @@ -101,6 +105,31 @@ public class LockPatternUtilsTest { when(context.getSystemService(Context.USER_SERVICE)).thenReturn(um); when(context.getSystemService(Context.USER_SERVICE)).thenReturn(um); } } @Test public void isUserInLockDown() throws Exception { configureTest(true, false, 2); // GIVEN strong auth not required when(mLockSettings.getStrongAuthForUser(USER_ID)).thenReturn(STRONG_AUTH_NOT_REQUIRED); // THEN user isn't in lockdown assertFalse(mLockPatternUtils.isUserInLockdown(USER_ID)); // GIVEN lockdown when(mLockSettings.getStrongAuthForUser(USER_ID)).thenReturn( STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); // THEN user is in lockdown assertTrue(mLockPatternUtils.isUserInLockdown(USER_ID)); // GIVEN lockdown and lockout when(mLockSettings.getStrongAuthForUser(USER_ID)).thenReturn( STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN | STRONG_AUTH_REQUIRED_AFTER_LOCKOUT); // THEN user is in lockdown assertTrue(mLockPatternUtils.isUserInLockdown(USER_ID)); } @Test @Test public void isLockScreenDisabled_isDemoUser_true() throws Exception { public void isLockScreenDisabled_isDemoUser_true() throws Exception { configureTest(false, true, 2); configureTest(false, true, 2); Loading