Merge "Hide the alternate bouncer on device unlocked" into tm-qpr-dev

This commit is contained in:
Beverly Tai
2023-03-20 16:57:36 +00:00
committed by Android (Google) Code Review
2 changed files with 55 additions and 0 deletions

View File

@@ -48,6 +48,17 @@ constructor(
val isVisible: Flow<Boolean> = bouncerRepository.alternateBouncerVisible val isVisible: Flow<Boolean> = 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. * 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 { companion object {
private const val MIN_VISIBILITY_DURATION_UNTIL_TOUCHES_DISMISS_ALTERNATE_BOUNCER_MS = 200L private const val MIN_VISIBILITY_DURATION_UNTIL_TOUCHES_DISMISS_ALTERNATE_BOUNCER_MS = 200L
private const val NOT_VISIBLE = -1L private const val NOT_VISIBLE = -1L

View File

@@ -39,8 +39,10 @@ import org.junit.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.Mock import org.mockito.Mock
import org.mockito.Mockito.mock import org.mockito.Mockito.mock
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations import org.mockito.MockitoAnnotations
@OptIn(ExperimentalCoroutinesApi::class) @OptIn(ExperimentalCoroutinesApi::class)
@@ -169,6 +171,42 @@ class AlternateBouncerInteractorTest : SysuiTestCase() {
assertFalse(bouncerRepository.alternateBouncerVisible.value) 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() { private fun givenCanShowAlternateBouncer() {
bouncerRepository.setAlternateBouncerUIAvailable(true) bouncerRepository.setAlternateBouncerUIAvailable(true)
biometricSettingsRepository.setFingerprintEnrolled(true) biometricSettingsRepository.setFingerprintEnrolled(true)