From 356c90dd454bb8070aee23e6491abe1800647e09 Mon Sep 17 00:00:00 2001 From: Beverly Date: Thu, 16 Mar 2023 22:05:43 +0000 Subject: [PATCH] Hide the alternate bouncer on device unlocked Test: atest AlternateBouncerInteractorTest Test: tap on a notification from the lock screen and active unlock succeeds => user proceeds to the notification intent Fixes: 271870159 Change-Id: I246437852ced99b9649468caf752debdaf859136 --- .../interactor/AlternateBouncerInteractor.kt | 17 +++++++++ .../AlternateBouncerInteractorTest.kt | 38 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt index eae40d61cdb61..e1702c5d61c43 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractor.kt @@ -48,6 +48,17 @@ constructor( val isVisible: Flow = bouncerRepository.alternateBouncerVisible + private val keyguardStateControllerCallback: KeyguardStateController.Callback = + object : KeyguardStateController.Callback { + override fun onUnlockedChanged() { + maybeHide() + } + } + + init { + keyguardStateController.addCallback(keyguardStateControllerCallback) + } + /** * Sets the correct bouncer states to show the alternate bouncer if it can show. * @@ -127,6 +138,12 @@ constructor( } } + private fun maybeHide() { + if (isVisibleState() && !canShowAlternateBouncerForFingerprint()) { + hide() + } + } + companion object { private const val MIN_VISIBILITY_DURATION_UNTIL_TOUCHES_DISMISS_ALTERNATE_BOUNCER_MS = 200L private const val NOT_VISIBLE = -1L diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt index 1365132d6dacc..2060e3d5d3bd6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/AlternateBouncerInteractorTest.kt @@ -39,8 +39,10 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mockito.ArgumentCaptor import org.mockito.Mock import org.mockito.Mockito.mock +import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations @OptIn(ExperimentalCoroutinesApi::class) @@ -169,6 +171,42 @@ class AlternateBouncerInteractorTest : SysuiTestCase() { assertFalse(bouncerRepository.alternateBouncerVisible.value) } + @Test + fun onUnlockedIsFalse_doesNotHide() { + // GIVEN alternate bouncer is showing + bouncerRepository.setAlternateVisible(true) + + val keyguardStateControllerCallbackCaptor = + ArgumentCaptor.forClass(KeyguardStateController.Callback::class.java) + verify(keyguardStateController).addCallback(keyguardStateControllerCallbackCaptor.capture()) + + // WHEN isUnlocked=false + givenCanShowAlternateBouncer() + whenever(keyguardStateController.isUnlocked).thenReturn(false) + keyguardStateControllerCallbackCaptor.value.onUnlockedChanged() + + // THEN the alternate bouncer is still visible + assertTrue(bouncerRepository.alternateBouncerVisible.value) + } + + @Test + fun onUnlockedChangedIsTrue_hide() { + // GIVEN alternate bouncer is showing + bouncerRepository.setAlternateVisible(true) + + val keyguardStateControllerCallbackCaptor = + ArgumentCaptor.forClass(KeyguardStateController.Callback::class.java) + verify(keyguardStateController).addCallback(keyguardStateControllerCallbackCaptor.capture()) + + // WHEN isUnlocked=true + givenCanShowAlternateBouncer() + whenever(keyguardStateController.isUnlocked).thenReturn(true) + keyguardStateControllerCallbackCaptor.value.onUnlockedChanged() + + // THEN the alternate bouncer is hidden + assertFalse(bouncerRepository.alternateBouncerVisible.value) + } + private fun givenCanShowAlternateBouncer() { bouncerRepository.setAlternateBouncerUIAvailable(true) biometricSettingsRepository.setFingerprintEnrolled(true)