Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
isUserInLockDown can be true when there are other strong auth
Browse files Browse the repository at this point in the history
requirements

Bug: 315206668
Bug: 218495634
Flag: None
Test: manual, atest LockPatternUtilsTest
(cherry picked from commit d341f1e)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:93149616ba8255ec82877e43d4b41c2ebd6abf24)
Merged-In: I5e979a7822dd7254b4579ab28ecf96df1db44179
Change-Id: I5e979a7822dd7254b4579ab28ecf96df1db44179
  • Loading branch information
Beverly authored and thestinger committed Apr 1, 2024
1 parent ced999c commit 2938b22
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
4 changes: 2 additions & 2 deletions core/java/com/android/internal/widget/LockPatternUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1384,8 +1384,8 @@ public boolean isBiometricAllowedForUser(int userId) {
}

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
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.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 com.google.common.truth.Truth.assertThat;

Expand Down Expand Up @@ -76,28 +78,30 @@ public class LockPatternUtilsTest {
@Rule
public final RavenwoodRule mRavenwood = new RavenwoodRule();

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);
cr.addProvider(Settings.AUTHORITY, new FakeSettingsProvider());
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);
Expand All @@ -107,6 +111,31 @@ private void configureTest(boolean isSecure, boolean isDemoUser, int deviceDemoM
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);
Expand Down

0 comments on commit 2938b22

Please sign in to comment.