diff options
| author | 2019-07-02 22:45:13 +0000 | |
|---|---|---|
| committer | 2019-07-02 22:45:13 +0000 | |
| commit | 95a52f6387d08a402bf554c7c83ec6813a3d0c75 (patch) | |
| tree | 489fb4a06d9cbfcd745f2d62f53ac5114919099f | |
| parent | 2f9b6f8cd4755dcfc528bae599bc17f3d0909a87 (diff) | |
| parent | 8eec2687060b570d85fd355f98886ca3ad12daf0 (diff) | |
Merge "Show bouncer after rebooting" into qt-r1-dev
4 files changed, 109 insertions, 14 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index 0a834c88d803..05e14a779a17 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -30,6 +30,12 @@ import static android.os.BatteryManager.EXTRA_PLUGGED; import static android.os.BatteryManager.EXTRA_STATUS; import static android.telephony.PhoneStateListener.LISTEN_ACTIVE_DATA_SUBSCRIPTION_ID_CHANGE; +import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT; +import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW; +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_TIMEOUT; +import static com.android.internal.widget.LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; + import android.annotation.AnyThread; import android.annotation.MainThread; import android.app.ActivityManager; @@ -672,8 +678,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } if (msgId == FingerprintManager.FINGERPRINT_ERROR_LOCKOUT_PERMANENT) { - mLockPatternUtils.requireStrongAuth( - LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, + mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, getCurrentUser()); } @@ -833,8 +838,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } if (msgId == FaceManager.FACE_ERROR_LOCKOUT_PERMANENT) { - mLockPatternUtils.requireStrongAuth( - LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, + mLockPatternUtils.requireStrongAuth(STRONG_AUTH_REQUIRED_AFTER_LOCKOUT, getCurrentUser()); } @@ -953,8 +957,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } public boolean isUserInLockdown(int userId) { - return mStrongAuthTracker.getStrongAuthForUser(userId) - == LockPatternUtils.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; + return containsFlag(mStrongAuthTracker.getStrongAuthForUser(userId), + STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); } public boolean userNeedsStrongAuth() { @@ -962,6 +966,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { != LockPatternUtils.StrongAuthTracker.STRONG_AUTH_NOT_REQUIRED; } + private boolean containsFlag(int haystack, int needle) { + return (haystack & needle) != 0; + } + public boolean needsSlowUnlockTransition() { return mNeedsSlowUnlockTransition; } @@ -1680,8 +1688,12 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { final int user = getCurrentUser(); final int strongAuth = mStrongAuthTracker.getStrongAuthForUser(user); final boolean isLockOutOrLockDown = - strongAuth == StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT - || strongAuth == StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN; + containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_LOCKOUT) + || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_DPM_LOCK_NOW) + || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); + final boolean isEncryptedOrTimedOut = + containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_BOOT) + || containsFlag(strongAuth, STRONG_AUTH_REQUIRED_AFTER_TIMEOUT); boolean canBypass = mKeyguardBypassController != null && mKeyguardBypassController.canBypass(); @@ -1690,13 +1702,18 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { // TrustAgents or biometrics are keeping the device unlocked. boolean becauseCannotSkipBouncer = !getUserCanSkipBouncer(user) || canBypass; + // Scan even when encrypted or timeout to show a preemptive bouncer when bypassing. + // Lockout/lockdown modes shouldn't scan, since they are more explicit. + boolean strongAuthAllowsScanning = (!isEncryptedOrTimedOut || canBypass && !mBouncer) + && !isLockOutOrLockDown; + // Only listen if this KeyguardUpdateMonitor belongs to the primary user. There is an // instance of KeyguardUpdateMonitor for each user but KeyguardUpdateMonitor is user-aware. return (mBouncer || mAuthInterruptActive || awakeKeyguard || shouldListenForFaceAssistant()) && !mSwitchingUser && !isFaceDisabled(user) && becauseCannotSkipBouncer && !mKeyguardGoingAway && mFaceSettingEnabledForUser && !mLockIconPressed - && mUserManager.isUserUnlocked(user) && mIsPrimaryUser - && !mSecureCameraLaunched && !isLockOutOrLockDown; + && strongAuthAllowsScanning && mIsPrimaryUser + && !mSecureCameraLaunched; } /** diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java index fdf18e0c7912..e6a88b158733 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BiometricUnlockController.java @@ -410,7 +410,7 @@ public class BiometricUnlockController extends KeyguardUpdateMonitorCallback { } else if (unlockingAllowed) { return faceStayingOnKeyguard ? MODE_ONLY_WAKE : MODE_UNLOCK; } else if (face) { - return MODE_NONE; + return faceStayingOnKeyguard ? MODE_NONE : MODE_SHOW_BOUNCER; } else if (!mStatusBarKeyguardViewManager.isBouncerShowing()) { return MODE_SHOW_BOUNCER; } diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java index 2e02fd598e56..bdc6341bde91 100644 --- a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java +++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardUpdateMonitorTest.java @@ -21,6 +21,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.clearInvocations; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.never; import static org.mockito.Mockito.reset; @@ -317,13 +318,44 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { @Test public void skipsAuthentication_whenEncryptedKeyguard() { - reset(mUserManager); - when(mUserManager.isUserUnlocked(anyInt())).thenReturn(false); + when(mStrongAuthTracker.getStrongAuthForUser(anyInt())).thenReturn( + KeyguardUpdateMonitor.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT); + mKeyguardUpdateMonitor.setKeyguardBypassController(mKeyguardBypassController); mKeyguardUpdateMonitor.dispatchStartedWakingUp(); mTestableLooper.processAllMessages(); mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); - verify(mFaceManager, never()).authenticate(any(), any(), anyInt(), any(), any()); + verify(mFaceManager, never()).authenticate(any(), any(), anyInt(), any(), any(), anyInt()); + } + + @Test + public void requiresAuthentication_whenEncryptedKeyguard_andBypass() { + testStrongAuthExceptOnBouncer( + KeyguardUpdateMonitor.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_BOOT); + } + + @Test + public void requiresAuthentication_whenTimeoutKeyguard_andBypass() { + testStrongAuthExceptOnBouncer( + KeyguardUpdateMonitor.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_TIMEOUT); + } + + private void testStrongAuthExceptOnBouncer(int strongAuth) { + when(mKeyguardBypassController.canBypass()).thenReturn(true); + mKeyguardUpdateMonitor.setKeyguardBypassController(mKeyguardBypassController); + when(mStrongAuthTracker.getStrongAuthForUser(anyInt())).thenReturn(strongAuth); + + mKeyguardUpdateMonitor.dispatchStartedWakingUp(); + mTestableLooper.processAllMessages(); + mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); + verify(mFaceManager).authenticate(any(), any(), anyInt(), any(), any(), anyInt()); + + // Stop scanning when bouncer becomes visible + mKeyguardUpdateMonitor.sendKeyguardBouncerChanged(true /* showingBouncer */); + mTestableLooper.processAllMessages(); + clearInvocations(mFaceManager); + mKeyguardUpdateMonitor.requestFaceAuth(); + verify(mFaceManager, never()).authenticate(any(), any(), anyInt(), any(), any(), anyInt()); } @Test @@ -357,6 +389,28 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase { } @Test + public void testIgnoresAuth_whenLockdown() { + mKeyguardUpdateMonitor.dispatchStartedWakingUp(); + mTestableLooper.processAllMessages(); + when(mStrongAuthTracker.getStrongAuthForUser(anyInt())).thenReturn( + KeyguardUpdateMonitor.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_USER_LOCKDOWN); + + mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); + verify(mFaceManager, never()).authenticate(any(), any(), anyInt(), any(), any(), anyInt()); + } + + @Test + public void testIgnoresAuth_whenLockout() { + mKeyguardUpdateMonitor.dispatchStartedWakingUp(); + mTestableLooper.processAllMessages(); + when(mStrongAuthTracker.getStrongAuthForUser(anyInt())).thenReturn( + KeyguardUpdateMonitor.StrongAuthTracker.STRONG_AUTH_REQUIRED_AFTER_LOCKOUT); + + mKeyguardUpdateMonitor.onKeyguardVisibilityChanged(true); + verify(mFaceManager, never()).authenticate(any(), any(), anyInt(), any(), any(), anyInt()); + } + + @Test public void testOnFaceAuthenticated_skipsFaceWhenAuthenticated() { mKeyguardUpdateMonitor.onFaceAuthenticated(KeyguardUpdateMonitor.getCurrentUser()); mKeyguardUpdateMonitor.sendKeyguardBouncerChanged(true); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java index 4e86f194c0cf..748f5097f9e9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/BiometricsUnlockControllerTest.java @@ -155,6 +155,30 @@ public class BiometricsUnlockControllerTest extends SysuiTestCase { } @Test + public void onBiometricAuthenticated_whenFace_andBypass_encrypted_showBouncer() { + when(mKeyguardBypassController.getBypassEnabled()).thenReturn(true); + mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); + + when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(false); + mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, + BiometricSourceType.FACE); + + verify(mStatusBarKeyguardViewManager).showBouncer(eq(false)); + } + + @Test + public void onBiometricAuthenticated_whenFace_noBypass_encrypted_doNothing() { + mBiometricUnlockController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager); + + when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(false); + mBiometricUnlockController.onBiometricAuthenticated(UserHandle.USER_CURRENT, + BiometricSourceType.FACE); + + verify(mStatusBarKeyguardViewManager, never()).showBouncer(anyBoolean()); + verify(mStatusBarKeyguardViewManager, never()).animateCollapsePanels(anyFloat()); + } + + @Test public void onBiometricAuthenticated_whenFaceOnBouncer_dismissBouncer() { when(mUpdateMonitor.isUnlockingWithBiometricAllowed()).thenReturn(true); when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true); |