Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9d805dda authored by Beverly's avatar Beverly Committed by Beverly Tai
Browse files

Don't listen for alternateBouncerChanges if unnecessary

Bug: 335673842
Flag: ACONFIG com.android.systemui.device_entry_udfps_refactor NEXTFOOD
Test: run TurnOffUnlockScreenToAoD test and take trace
Test: atest AlternateBouncerWindowViewModelTest
Change-Id: Ibd17fa747e34c73b21694a47992b4fa4d6feeeb4
parent 5876053b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -34,8 +34,8 @@ constructor(
    alternateBouncerInteractor: AlternateBouncerInteractor,
    keyguardTransitionInteractor: KeyguardTransitionInteractor,
) {
    private val deviceSupportsAlternateBouncer: Flow<Boolean> =
        alternateBouncerInteractor.alternateBouncerSupported
    val canShowAlternateBouncer: Flow<Boolean> = alternateBouncerInteractor.canShowAlternateBouncer

    private val isTransitioningToOrFromOrShowingAlternateBouncer: Flow<Boolean> =
        keyguardTransitionInteractor
            .transitionValue(KeyguardState.ALTERNATE_BOUNCER)
@@ -43,8 +43,8 @@ constructor(
            .distinctUntilChanged()

    val alternateBouncerWindowRequired: Flow<Boolean> =
        deviceSupportsAlternateBouncer.flatMapLatest { deviceSupportsAlternateBouncer ->
            if (deviceSupportsAlternateBouncer) {
        canShowAlternateBouncer.flatMapLatest { canShowAlternateBouncer ->
            if (canShowAlternateBouncer) {
                isTransitioningToOrFromOrShowingAlternateBouncer
            } else {
                flowOf(false)
+111 −10
Original line number Diff line number Diff line
@@ -18,15 +18,19 @@
package com.android.systemui.keyguard.ui.viewmodel

import androidx.test.filters.SmallTest
import com.android.keyguard.keyguardUpdateMonitor
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.data.repository.fakeFingerprintPropertyRepository
import com.android.systemui.bouncer.data.repository.fakeKeyguardBouncerRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.fakeBiometricSettingsRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.policy.keyguardStateController
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -34,6 +38,7 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.mockito.kotlin.whenever

@ExperimentalCoroutinesApi
@RunWith(JUnit4::class)
@@ -49,13 +54,35 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
    fun alternateBouncerTransition_alternateBouncerWindowRequiredTrue() =
        testScope.runTest {
            mSetFlagsRule.enableFlags(Flags.FLAG_DEVICE_ENTRY_UDFPS_REFACTOR)
            val canShowAlternateBouncer by collectLastValue(underTest.canShowAlternateBouncer)
            val alternateBouncerWindowRequired by
                collectLastValue(underTest.alternateBouncerWindowRequired)
            givenCanShowAlternateBouncer()
            fingerprintPropertyRepository.supportsUdfps()
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepToLockscreen(0f, TransitionState.STARTED),
                    stepToLockscreen(.4f),
                    stepToLockscreen(1f, TransitionState.FINISHED),
                ),
                testScope,
            )
            assertThat(canShowAlternateBouncer).isTrue()
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromLockscreenToAlternateBouncer(0f, TransitionState.STARTED),
                    stepFromLockscreenToAlternateBouncer(.4f),
                    stepFromLockscreenToAlternateBouncer(.6f),
                ),
                testScope,
            )
            assertThat(canShowAlternateBouncer).isTrue()
            assertThat(alternateBouncerWindowRequired).isTrue()

            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromAlternateBouncer(0f, TransitionState.STARTED),
                    stepFromAlternateBouncer(.4f),
                    stepFromAlternateBouncer(.2f),
                    stepFromAlternateBouncer(.6f),
                ),
                testScope,
@@ -77,13 +104,21 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
            mSetFlagsRule.disableFlags(Flags.FLAG_DEVICE_ENTRY_UDFPS_REFACTOR)
            val alternateBouncerWindowRequired by
                collectLastValue(underTest.alternateBouncerWindowRequired)
            givenCanShowAlternateBouncer()
            fingerprintPropertyRepository.supportsUdfps()
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromAlternateBouncer(0f, TransitionState.STARTED),
                    stepFromAlternateBouncer(.4f),
                    stepFromAlternateBouncer(.6f),
                    stepFromAlternateBouncer(1f),
                    stepToLockscreen(0f, TransitionState.STARTED),
                    stepToLockscreen(.4f),
                    stepToLockscreen(1f, TransitionState.FINISHED),
                ),
                testScope,
            )
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromLockscreenToAlternateBouncer(0f, TransitionState.STARTED),
                    stepFromLockscreenToAlternateBouncer(.4f),
                    stepFromLockscreenToAlternateBouncer(.6f),
                ),
                testScope,
            )
@@ -96,13 +131,23 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
            mSetFlagsRule.enableFlags(Flags.FLAG_DEVICE_ENTRY_UDFPS_REFACTOR)
            val alternateBouncerWindowRequired by
                collectLastValue(underTest.alternateBouncerWindowRequired)
            givenCanShowAlternateBouncer()
            fingerprintPropertyRepository.supportsUdfps()
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromLockscreenToDozing(0f, TransitionState.STARTED),
                    stepFromLockscreenToDozing(.4f),
                    stepFromLockscreenToDozing(.6f),
                    stepFromLockscreenToDozing(1f, TransitionState.FINISHED),
                ),
                testScope,
            )
            assertThat(alternateBouncerWindowRequired).isFalse()
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromDozingToLockscreen(0f, TransitionState.STARTED),
                    stepFromDozingToLockscreen(.4f),
                    stepFromDozingToLockscreen(.6f),
                    stepFromDozingToLockscreen(1f),
                ),
                testScope,
            )
@@ -115,19 +160,39 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
            mSetFlagsRule.enableFlags(Flags.FLAG_DEVICE_ENTRY_UDFPS_REFACTOR)
            val alternateBouncerWindowRequired by
                collectLastValue(underTest.alternateBouncerWindowRequired)
            givenCanShowAlternateBouncer()
            fingerprintPropertyRepository.supportsRearFps()
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromAlternateBouncer(0f, TransitionState.STARTED),
                    stepFromAlternateBouncer(.4f),
                    stepFromAlternateBouncer(.6f),
                    stepFromAlternateBouncer(1f),
                    stepToLockscreen(0f, TransitionState.STARTED),
                    stepToLockscreen(.4f),
                    stepToLockscreen(1f, TransitionState.FINISHED),
                ),
                testScope,
            )
            transitionRepository.sendTransitionSteps(
                listOf(
                    stepFromLockscreenToAlternateBouncer(0f, TransitionState.STARTED),
                    stepFromLockscreenToAlternateBouncer(.4f),
                    stepFromLockscreenToAlternateBouncer(.6f),
                ),
                testScope,
            )
            assertThat(alternateBouncerWindowRequired).isFalse()
        }

    private fun stepToLockscreen(
        value: Float,
        state: TransitionState = TransitionState.RUNNING
    ): TransitionStep {
        return step(
            from = KeyguardState.GONE,
            to = KeyguardState.LOCKSCREEN,
            value = value,
            transitionState = state,
        )
    }

    private fun stepFromAlternateBouncer(
        value: Float,
        state: TransitionState = TransitionState.RUNNING
@@ -140,6 +205,18 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
        )
    }

    private fun stepFromLockscreenToAlternateBouncer(
        value: Float,
        state: TransitionState = TransitionState.RUNNING
    ): TransitionStep {
        return step(
            from = KeyguardState.LOCKSCREEN,
            to = KeyguardState.ALTERNATE_BOUNCER,
            value = value,
            transitionState = state,
        )
    }

    private fun stepFromDozingToLockscreen(
        value: Float,
        state: TransitionState = TransitionState.RUNNING
@@ -152,6 +229,18 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
        )
    }

    private fun stepFromLockscreenToDozing(
        value: Float,
        state: TransitionState = TransitionState.RUNNING
    ): TransitionStep {
        return step(
            from = KeyguardState.LOCKSCREEN,
            to = KeyguardState.DOZING,
            value = value,
            transitionState = state,
        )
    }

    private fun step(
        from: KeyguardState,
        to: KeyguardState,
@@ -166,4 +255,16 @@ class AlternateBouncerWindowViewModelTest : SysuiTestCase() {
            ownerName = "AlternateBouncerViewModelTest"
        )
    }

    /**
     * Given the alternate bouncer parameters are set so that the alternate bouncer can show, aside
     * from the fingerprint modality.
     */
    private fun givenCanShowAlternateBouncer() {
        kosmos.fakeKeyguardBouncerRepository.setPrimaryShow(false)
        kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthEnrolledAndEnabled(true)
        kosmos.fakeBiometricSettingsRepository.setIsFingerprintAuthCurrentlyAllowed(true)
        whenever(kosmos.keyguardUpdateMonitor.isFingerprintLockedOut).thenReturn(false)
        whenever(kosmos.keyguardStateController.isUnlocked).thenReturn(false)
    }
}