Skip to content
Snippets Groups Projects
Commit 8831b577 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "isUserInLockDown can be true when there are other strong auth...

Merge "isUserInLockDown can be true when there are other strong auth requirements" into rvc-dev am: 19075fd6 am: 976d59d1 am: 3201f762

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/25948484



Change-Id: Ie8f508aa1d91045e3f06ce79ba295457645d9f2a
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents eb709f44 3201f762
No related branches found
No related tags found
No related merge requests found
......@@ -1295,8 +1295,8 @@ public class LockPatternUtils {
}
public boolean isUserInLockdown(int userId) {
return getStrongAuthForUser(userId)
== StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN;
return (getStrongAuthForUser(userId)
& StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN) != 0;
}
private static class WrappedCallback extends ICheckCredentialProgressCallback.Stub {
......
......@@ -19,6 +19,10 @@ package com.android.internal.util;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
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_USER_LOCKDOWN;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
......@@ -48,12 +52,15 @@ import org.mockito.Mockito;
@SmallTest
public class LockPatternUtilsTest {
private ILockSettings mLockSettings;
private static final int USER_ID = 1;
private static final int DEMO_USER_ID = 5;
private LockPatternUtils mLockPatternUtils;
private void configureTest(boolean isSecure, boolean isDemoUser, int deviceDemoMode)
throws Exception {
mLockSettings = Mockito.mock(ILockSettings.class);
final Context context = spy(new ContextWrapper(InstrumentationRegistry.getTargetContext()));
final MockContentResolver cr = new MockContentResolver(context);
......@@ -61,15 +68,14 @@ public class LockPatternUtilsTest {
when(context.getContentResolver()).thenReturn(cr);
Settings.Global.putInt(cr, Settings.Global.DEVICE_DEMO_MODE, deviceDemoMode);
final ILockSettings ils = Mockito.mock(ILockSettings.class);
when(ils.getCredentialType(DEMO_USER_ID)).thenReturn(
when(mLockSettings.getCredentialType(DEMO_USER_ID)).thenReturn(
isSecure ? LockPatternUtils.CREDENTIAL_TYPE_PASSWORD
: LockPatternUtils.CREDENTIAL_TYPE_NONE);
when(ils.getLong("lockscreen.password_type", PASSWORD_QUALITY_UNSPECIFIED, DEMO_USER_ID))
.thenReturn((long) PASSWORD_QUALITY_MANAGED);
when(mLockSettings.getLong("lockscreen.password_type", PASSWORD_QUALITY_UNSPECIFIED,
DEMO_USER_ID)).thenReturn((long) PASSWORD_QUALITY_MANAGED);
// TODO(b/63758238): stop spying the class under test
mLockPatternUtils = spy(new LockPatternUtils(context));
when(mLockPatternUtils.getLockSettings()).thenReturn(ils);
when(mLockPatternUtils.getLockSettings()).thenReturn(mLockSettings);
doReturn(true).when(mLockPatternUtils).hasSecureLockScreen();
final UserInfo userInfo = Mockito.mock(UserInfo.class);
......@@ -79,6 +85,31 @@ public class LockPatternUtilsTest {
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
public void isLockScreenDisabled_isDemoUser_true() throws Exception {
configureTest(false, true, 2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment