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

Commit 8da44513 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Add more udfps legacy support for transitions" into main

parents 6818815c 53747dcb
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.testing.TestableLooper
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.keyguard.KeyguardSecurityModel
import com.android.systemui.biometrics.UdfpsKeyguardViewLegacy.ANIMATE_APPEAR_ON_SCREEN_OFF
import com.android.systemui.biometrics.UdfpsKeyguardViewLegacy.ANIMATION_BETWEEN_AOD_AND_LOCKSCREEN
import com.android.systemui.biometrics.data.repository.FakeFingerprintPropertyRepository
import com.android.systemui.bouncer.data.repository.KeyguardBouncerRepository
import com.android.systemui.bouncer.data.repository.KeyguardBouncerRepositoryImpl
@@ -56,10 +58,12 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentMatchers.any
import org.mockito.ArgumentMatchers.anyInt
import org.mockito.ArgumentMatchers.eq
import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.Mockito.mock
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations

@@ -539,4 +543,77 @@ class UdfpsKeyguardViewLegacyControllerWithCoroutinesTest :
                .onDozeAmountChanged(eq(0f), eq(0f), eq(UdfpsKeyguardViewLegacy.ANIMATION_NONE))
            job.cancel()
        }

    @Test
    fun cancelledLockscreenToAod_dozeAmountNotUpdatedToZero() =
        testScope.runTest {
            // GIVEN view is attached
            mController.onViewAttached()
            Mockito.reset(mView)

            val job = mController.listenForLockscreenAodTransitions(this)
            // WHEN lockscreen to aod transition is cancelled
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.AOD,
                    value = 1f,
                    transitionState = TransitionState.CANCELED
                )
            )
            runCurrent()

            // THEN doze amount is NOT updated to zero
            verify(mView, never()).onDozeAmountChanged(eq(0f), eq(0f), anyInt())
            job.cancel()
        }

    @Test
    fun dreamingToAod_dozeAmountChanged() =
        testScope.runTest {
            // GIVEN view is attached
            mController.onViewAttached()
            Mockito.reset(mView)

            val job = mController.listenForDreamingToAodTransitions(this)
            // WHEN dreaming to aod transition in progress
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.DREAMING,
                    to = KeyguardState.AOD,
                    value = .3f,
                    transitionState = TransitionState.RUNNING
                )
            )
            runCurrent()

            // THEN doze amount is updated to
            verify(mView).onDozeAmountChanged(eq(.3f), eq(.3f), eq(ANIMATE_APPEAR_ON_SCREEN_OFF))
            job.cancel()
        }

    @Test
    fun alternateBouncerToAod_dozeAmountChanged() =
        testScope.runTest {
            // GIVEN view is attached
            mController.onViewAttached()
            Mockito.reset(mView)

            val job = mController.listenForAlternateBouncerToAodTransitions(this)
            // WHEN alternate bouncer to aod transition in progress
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.ALTERNATE_BOUNCER,
                    to = KeyguardState.AOD,
                    value = .3f,
                    transitionState = TransitionState.RUNNING
                )
            )
            runCurrent()

            // THEN doze amount is updated to
            verify(mView)
                .onDozeAmountChanged(eq(.3f), eq(.3f), eq(ANIMATION_BETWEEN_AOD_AND_LOCKSCREEN))
            job.cancel()
        }
}
+35 −1
Original line number Diff line number Diff line
@@ -197,6 +197,37 @@ open class UdfpsKeyguardViewControllerLegacy(
                listenForGoneToAodTransition(this)
                listenForLockscreenAodTransitions(this)
                listenForAodToOccludedTransitions(this)
                listenForAlternateBouncerToAodTransitions(this)
                listenForDreamingToAodTransitions(this)
            }
        }
    }

    @VisibleForTesting
    suspend fun listenForDreamingToAodTransitions(scope: CoroutineScope): Job {
        return scope.launch {
            transitionInteractor.transition(KeyguardState.DREAMING, KeyguardState.AOD).collect {
                transitionStep ->
                view.onDozeAmountChanged(
                    transitionStep.value,
                    transitionStep.value,
                    ANIMATE_APPEAR_ON_SCREEN_OFF,
                )
            }
        }
    }

    @VisibleForTesting
    suspend fun listenForAlternateBouncerToAodTransitions(scope: CoroutineScope): Job {
        return scope.launch {
            transitionInteractor
                .transition(KeyguardState.ALTERNATE_BOUNCER, KeyguardState.AOD)
                .collect { transitionStep ->
                    view.onDozeAmountChanged(
                        transitionStep.value,
                        transitionStep.value,
                        UdfpsKeyguardViewLegacy.ANIMATION_BETWEEN_AOD_AND_LOCKSCREEN,
                    )
                }
        }
    }
@@ -246,7 +277,10 @@ open class UdfpsKeyguardViewControllerLegacy(
    suspend fun listenForLockscreenAodTransitions(scope: CoroutineScope): Job {
        return scope.launch {
            transitionInteractor.dozeAmountTransition.collect { transitionStep ->
                if (transitionStep.transitionState == TransitionState.CANCELED) {
                if (
                    transitionStep.from == KeyguardState.AOD &&
                        transitionStep.transitionState == TransitionState.CANCELED
                ) {
                    if (
                        transitionInteractor.startedKeyguardTransitionStep.first().to !=
                            KeyguardState.AOD
+8 −7
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ constructor(
    override fun start() {
        listenForDreamingToOccluded()
        listenForDreamingToGone()
        listenForDreamingToDozing()
        listenForDreamingToAodOrDozing()
        listenForTransitionToCamera(scope, keyguardInteractor)
    }

@@ -94,7 +94,7 @@ constructor(
        }
    }

    private fun listenForDreamingToDozing() {
    private fun listenForDreamingToAodOrDozing() {
        scope.launch {
            combine(
                    keyguardInteractor.dozeTransitionModel,
@@ -102,11 +102,12 @@ constructor(
                    ::Pair
                )
                .collect { (dozeTransitionModel, keyguardState) ->
                    if (
                        dozeTransitionModel.to == DozeStateModel.DOZE &&
                            keyguardState == KeyguardState.DREAMING
                    ) {
                    if (keyguardState == KeyguardState.DREAMING) {
                        if (dozeTransitionModel.to == DozeStateModel.DOZE) {
                            startTransitionTo(KeyguardState.DOZING)
                        } else if (dozeTransitionModel.to == DozeStateModel.DOZE_AOD) {
                            startTransitionTo(KeyguardState.AOD)
                        }
                    }
                }
        }
+31 −1
Original line number Diff line number Diff line
@@ -1137,7 +1137,7 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            runCurrent()

            // WHEN primary bouncer shows
            bouncerRepository.setPrimaryShow(true) // beverlyt
            bouncerRepository.setPrimaryShow(true)
            runCurrent()

            val info =
@@ -1231,6 +1231,36 @@ class KeyguardTransitionScenariosTest : SysuiTestCase() {
            coroutineContext.cancelChildren()
        }

    @Test
    fun dreamingToAod() =
        testScope.runTest {
            // GIVEN a prior transition has run to DREAMING
            keyguardRepository.setDreaming(true)
            runTransitionAndSetWakefulness(KeyguardState.LOCKSCREEN, KeyguardState.DREAMING)
            runCurrent()

            // WHEN the device starts DOZE_AOD
            keyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(
                    from = DozeStateModel.INITIALIZED,
                    to = DozeStateModel.DOZE_AOD,
                )
            )
            runCurrent()

            val info =
                withArgCaptor<TransitionInfo> {
                    verify(transitionRepository).startTransition(capture())
                }
            // THEN a transition to AOD should occur
            assertThat(info.ownerName).isEqualTo("FromDreamingTransitionInteractor")
            assertThat(info.from).isEqualTo(KeyguardState.DREAMING)
            assertThat(info.to).isEqualTo(KeyguardState.AOD)
            assertThat(info.animator).isNotNull()

            coroutineContext.cancelChildren()
        }

    @Test
    fun lockscreenToOccluded() =
        testScope.runTest {