From a0192082e75222158aa637b1537ef1ca524ec97c Mon Sep 17 00:00:00 2001 From: Chandru S Date: Mon, 17 Apr 2023 19:03:53 -0700 Subject: [PATCH] Minor face auth fixes 1. Reset auth state on device going to sleep 2. Stop face auth when user input is happening on primary bouncer 3. Fix some logging inconsistencies Fixes: 275802536, 278627459 Test: atest DeviceEntryFaceAuthRepositoryTest, KeyguardFaceAuthInteractorTest Change-Id: I6f10ec30d6ce08072b33fa66759568f026e35fdb --- .../KeyguardSecurityContainerController.java | 1 + .../DeviceEntryFaceAuthRepository.kt | 25 +++++---- .../interactor/KeyguardFaceAuthInteractor.kt | 1 + .../NoopKeyguardFaceAuthInteractor.kt | 1 + .../SystemUIKeyguardFaceAuthInteractor.kt | 4 ++ .../DeviceEntryFaceAuthRepositoryTest.kt | 52 +++++++++++++++++++ .../KeyguardFaceAuthInteractorTest.kt | 17 ++++++ 7 files changed, 92 insertions(+), 9 deletions(-) diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java index 76e051ea25f33..693268d730a4b 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainerController.java @@ -178,6 +178,7 @@ public class KeyguardSecurityContainerController extends ViewController - if (goingAwayOrUserSwitchingInProgress) { + // Clear auth status when keyguard is going away or when the user is switching or device + // starts going to sleep. + merge( + keyguardRepository.wakefulness.map { + WakefulnessModel.isSleepingOrStartingToSleep(it) + }, + keyguardRepository.isKeyguardGoingAway, + userRepository.userSwitchingInProgress + ) + .onEach { anyOfThemIsTrue -> + if (anyOfThemIsTrue) { _isAuthenticated.value = false retryCount = 0 halErrorRetryJob?.cancel() @@ -248,8 +255,8 @@ constructor( "nonStrongBiometricIsNotAllowed", faceDetectLog ), - // We don't want to run face detect if it's not possible to authenticate with FP - // from the bouncer. UDFPS is the only fp sensor type that won't support this. + // We don't want to run face detect if fingerprint can be used to unlock the device + // but it's not possible to authenticate with FP from the bouncer (UDFPS) logAndObserve( and(isUdfps(), deviceEntryFingerprintAuthRepository.isRunning).isFalse(), "udfpsAuthIsNotPossibleAnymore", @@ -306,7 +313,7 @@ constructor( logAndObserve( combine( keyguardInteractor.isSecureCameraActive, - alternateBouncerInteractor.isVisible, + alternateBouncerInteractor.isVisible ) { a, b -> !a || b }, @@ -334,12 +341,12 @@ constructor( logAndObserve(isLockedOut.isFalse(), "isNotInLockOutState", faceAuthLog), logAndObserve( deviceEntryFingerprintAuthRepository.isLockedOut.isFalse(), - "fpLockedOut", + "fpIsNotLockedOut", faceAuthLog ), logAndObserve( trustRepository.isCurrentUserTrusted.isFalse(), - "currentUserTrusted", + "currentUserIsNotTrusted", faceAuthLog ), logAndObserve( diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractor.kt index 06ae11fe810ca..74ef7a50fd44c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractor.kt @@ -59,6 +59,7 @@ interface KeyguardFaceAuthInteractor { fun onQsExpansionStared() fun onNotificationPanelClicked() fun onSwipeUpOnBouncer() + fun onPrimaryBouncerUserInput() } /** diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/NoopKeyguardFaceAuthInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/NoopKeyguardFaceAuthInteractor.kt index cad40aac00d37..5005b6c7f0dfe 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/NoopKeyguardFaceAuthInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/NoopKeyguardFaceAuthInteractor.kt @@ -59,4 +59,5 @@ class NoopKeyguardFaceAuthInteractor @Inject constructor() : KeyguardFaceAuthInt override fun onNotificationPanelClicked() {} override fun onSwipeUpOnBouncer() {} + override fun onPrimaryBouncerUserInput() {} } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/SystemUIKeyguardFaceAuthInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/SystemUIKeyguardFaceAuthInteractor.kt index 20ebb711c42d5..6b515dab79f6d 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/SystemUIKeyguardFaceAuthInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/SystemUIKeyguardFaceAuthInteractor.kt @@ -151,6 +151,10 @@ constructor( return featureFlags.isEnabled(Flags.FACE_AUTH_REFACTOR) } + override fun onPrimaryBouncerUserInput() { + repository.cancel() + } + /** Provide the status of face authentication */ override val authenticationStatus = repository.authenticationStatus diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt index a76d03b8ba930..ea569a5aad1ac 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepositoryTest.kt @@ -652,6 +652,58 @@ class DeviceEntryFaceAuthRepositoryTest : SysuiTestCase() { assertThat(authenticated()).isFalse() } + @Test + fun isAuthenticatedIsResetToFalseWhenDeviceStartsGoingToSleep() = + testScope.runTest { + initCollectors() + allPreconditionsToRunFaceAuthAreTrue() + + triggerFaceAuth(false) + + authenticationCallback.value.onAuthenticationSucceeded( + mock(FaceManager.AuthenticationResult::class.java) + ) + + assertThat(authenticated()).isTrue() + + keyguardRepository.setWakefulnessModel( + WakefulnessModel( + WakefulnessState.STARTING_TO_SLEEP, + isWakingUpOrAwake = false, + lastWakeReason = WakeSleepReason.POWER_BUTTON, + lastSleepReason = WakeSleepReason.POWER_BUTTON + ) + ) + + assertThat(authenticated()).isFalse() + } + + @Test + fun isAuthenticatedIsResetToFalseWhenDeviceGoesToSleep() = + testScope.runTest { + initCollectors() + allPreconditionsToRunFaceAuthAreTrue() + + triggerFaceAuth(false) + + authenticationCallback.value.onAuthenticationSucceeded( + mock(FaceManager.AuthenticationResult::class.java) + ) + + assertThat(authenticated()).isTrue() + + keyguardRepository.setWakefulnessModel( + WakefulnessModel( + WakefulnessState.ASLEEP, + isWakingUpOrAwake = false, + lastWakeReason = WakeSleepReason.POWER_BUTTON, + lastSleepReason = WakeSleepReason.POWER_BUTTON + ) + ) + + assertThat(authenticated()).isFalse() + } + @Test fun isAuthenticatedIsResetToFalseWhenUserIsSwitching() = testScope.runTest { diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractorTest.kt index 3d1d2f46a65e5..5da1a846fbfd5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardFaceAuthInteractorTest.kt @@ -278,6 +278,23 @@ class KeyguardFaceAuthInteractorTest : SysuiTestCase() { ) } + @Test + fun faceAuthIsCancelledWhenUserInputOnPrimaryBouncer() = + testScope.runTest { + underTest.start() + + underTest.onSwipeUpOnBouncer() + + runCurrent() + assertThat(faceAuthRepository.isAuthRunning.value).isTrue() + + underTest.onPrimaryBouncerUserInput() + + runCurrent() + + assertThat(faceAuthRepository.isAuthRunning.value).isFalse() + } + @Test fun faceAuthIsRequestedWhenSwipeUpOnBouncer() = testScope.runTest {