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

Commit c938ac9d authored by Andreas Miko's avatar Andreas Miko Committed by Android (Google) Code Review
Browse files

Merge changes I07be68ab,I5087008a into main

* changes:
  Consolidate finishedKeyguardStep and make it a StateFlow
  Consolidate startedKeyguardTransitionStep and make it a StateFlow
parents 8963bd0e 60fa7d9a
Loading
Loading
Loading
Loading
+24 −7
Original line number Diff line number Diff line
@@ -39,12 +39,15 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.keyguardOcclusionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat
@@ -53,6 +56,7 @@ import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.domain.interactor.keyguardOcclusionInteractor
import com.android.systemui.testKosmos
import junit.framework.Assert.assertEquals
@@ -166,6 +170,10 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToGone_onWakeUp_ifPowerButtonGestureDetected_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
@@ -175,7 +183,7 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
            runCurrent()

            // Make sure we're GONE.
            assertEquals(KeyguardState.GONE, kosmos.keyguardTransitionInteractor.getFinishedState())
            assertEquals(true, isGone)

            // Get part way to AOD.
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
@@ -204,6 +212,10 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToOccluded_onWakeUp_ifPowerButtonGestureDetectedAfterFinishedInAod_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
@@ -213,7 +225,7 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
            runCurrent()

            // Make sure we're GONE.
            assertEquals(KeyguardState.GONE, kosmos.keyguardTransitionInteractor.getFinishedState())
            assertEquals(true, isGone)

            // Get all the way to AOD
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
@@ -239,6 +251,10 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToOccluded_onWakeUp_ifPowerButtonGestureDetected_fromLockscreen() =
        testScope.runTest {
            val isLockscreen by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Lockscreen, LOCKSCREEN)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
@@ -248,10 +264,7 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
            runCurrent()

            // Make sure we're in LOCKSCREEN.
            assertEquals(
                KeyguardState.LOCKSCREEN,
                kosmos.keyguardTransitionInteractor.getFinishedState()
            )
            assertEquals(true, isLockscreen)

            // Get part way to AOD.
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
@@ -327,6 +340,10 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
    @DisableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToGone_onWakeUp_ifPowerButtonGestureDetectedInAod_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
@@ -336,7 +353,7 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
            runCurrent()

            // Make sure we're GONE.
            assertEquals(KeyguardState.GONE, kosmos.keyguardTransitionInteractor.getFinishedState())
            assertEquals(true, isGone)

            // Start going to AOD on first button push
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
+19 −6
Original line number Diff line number Diff line
@@ -48,12 +48,15 @@ import com.android.systemui.communal.data.repository.fakeCommunalSceneRepository
import com.android.systemui.communal.domain.interactor.setCommunalAvailable
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.CommunalTransitionKeys
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.keyguardOcclusionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat
import com.android.systemui.kosmos.applicationCoroutineScope
@@ -62,6 +65,7 @@ import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -316,6 +320,10 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToGone_onWakeUp_ifPowerButtonGestureDetected_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.DOZING,
@@ -325,7 +333,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
            runCurrent()

            // Make sure we're GONE.
            assertEquals(KeyguardState.GONE, kosmos.keyguardTransitionInteractor.getFinishedState())
            assertEquals(true, isGone)

            // Get part way to AOD.
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
@@ -355,6 +363,10 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
    @Suppress("ktlint:standard:max-line-length")
    fun testTransitionToOccluded_onWakeUp_ifPowerButtonGestureDetectedAfterFinishedInAod_fromGone() =
        testScope.runTest {
            val isGone by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Gone, GONE)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.DOZING,
@@ -364,7 +376,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
            runCurrent()

            // Make sure we're GONE.
            assertEquals(KeyguardState.GONE, kosmos.keyguardTransitionInteractor.getFinishedState())
            assertEquals(true, isGone)

            // Get all the way to AOD
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
@@ -390,6 +402,10 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToOccluded_onWakeUp_ifPowerButtonGestureDetected_fromLockscreen() =
        testScope.runTest {
            val isLockscreen by
                collectLastValue(
                    kosmos.keyguardTransitionInteractor.isFinishedIn(Scenes.Lockscreen, LOCKSCREEN)
                )
            powerInteractor.setAwakeForTest()
            transitionRepository.sendTransitionSteps(
                from = KeyguardState.DOZING,
@@ -399,10 +415,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
            runCurrent()

            // Make sure we're in LOCKSCREEN.
            assertEquals(
                KeyguardState.LOCKSCREEN,
                kosmos.keyguardTransitionInteractor.getFinishedState()
            )
            assertEquals(true, isLockscreen)

            // Get part way to AOD.
            powerInteractor.onStartedGoingToSleep(PowerManager.GO_TO_SLEEP_REASON_MIN)
+0 −135
Original line number Diff line number Diff line
@@ -89,52 +89,6 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            assertThat(lockscreenToAodSteps).isEqualTo(steps.subList(5, 8))
        }

    @Test
    fun finishedKeyguardStateTests() =
        testScope.runTest {
            val finishedSteps by collectValues(underTest.finishedKeyguardState)
            runCurrent()
            val steps = mutableListOf<TransitionStep>()

            steps.add(TransitionStep(AOD, PRIMARY_BOUNCER, 0f, STARTED))
            steps.add(TransitionStep(AOD, PRIMARY_BOUNCER, 0.5f, RUNNING))
            steps.add(TransitionStep(AOD, PRIMARY_BOUNCER, 1f, FINISHED))
            steps.add(TransitionStep(PRIMARY_BOUNCER, AOD, 0f, STARTED))
            steps.add(TransitionStep(PRIMARY_BOUNCER, AOD, 0.9f, RUNNING))
            steps.add(TransitionStep(PRIMARY_BOUNCER, AOD, 1f, FINISHED))
            steps.add(TransitionStep(AOD, GONE, 1f, STARTED))

            steps.forEach {
                repository.sendTransitionStep(it)
                runCurrent()
            }

            assertThat(finishedSteps).isEqualTo(listOf(LOCKSCREEN, PRIMARY_BOUNCER, AOD))
        }

    @Test
    fun startedKeyguardStateTests() =
        testScope.runTest {
            val startedStates by collectValues(underTest.startedKeyguardState)
            runCurrent()
            val steps = mutableListOf<TransitionStep>()

            steps.add(TransitionStep(AOD, PRIMARY_BOUNCER, 0f, STARTED))
            steps.add(TransitionStep(AOD, PRIMARY_BOUNCER, 0.5f, RUNNING))
            steps.add(TransitionStep(AOD, PRIMARY_BOUNCER, 1f, FINISHED))
            steps.add(TransitionStep(PRIMARY_BOUNCER, AOD, 0f, STARTED))
            steps.add(TransitionStep(PRIMARY_BOUNCER, AOD, 0.9f, RUNNING))
            steps.add(TransitionStep(PRIMARY_BOUNCER, AOD, 1f, FINISHED))
            steps.add(TransitionStep(AOD, GONE, 1f, STARTED))

            steps.forEach {
                repository.sendTransitionStep(it)
                runCurrent()
            }

            assertThat(startedStates).isEqualTo(listOf(LOCKSCREEN, PRIMARY_BOUNCER, AOD, GONE))
        }

    @Test
    fun startedKeyguardTransitionStepTests() =
        testScope.runTest {
@@ -1205,95 +1159,6 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
                )
        }

    @Test
    fun finishedKeyguardState_emitsAgainIfCancelledAndReversed() =
        testScope.runTest {
            val finishedStates by collectValues(underTest.finishedKeyguardState)

            // We default FINISHED in LOCKSCREEN.
            assertEquals(listOf(LOCKSCREEN), finishedStates)

            sendSteps(
                TransitionStep(LOCKSCREEN, AOD, 0f, STARTED),
                TransitionStep(LOCKSCREEN, AOD, 0.5f, RUNNING),
                TransitionStep(LOCKSCREEN, AOD, 1f, FINISHED),
            )

            // We're FINISHED in AOD.
            assertEquals(
                listOf(
                    LOCKSCREEN,
                    AOD,
                ),
                finishedStates
            )

            // Transition back to LOCKSCREEN.
            sendSteps(
                TransitionStep(AOD, LOCKSCREEN, 0f, STARTED),
                TransitionStep(AOD, LOCKSCREEN, 0.5f, RUNNING),
                TransitionStep(AOD, LOCKSCREEN, 1f, FINISHED),
            )

            // We're FINISHED in LOCKSCREEN.
            assertEquals(
                listOf(
                    LOCKSCREEN,
                    AOD,
                    LOCKSCREEN,
                ),
                finishedStates
            )

            sendSteps(
                TransitionStep(LOCKSCREEN, GONE, 0f, STARTED),
                TransitionStep(LOCKSCREEN, GONE, 0.5f, RUNNING),
            )

            // We've STARTED a transition to GONE but not yet finished it so we're still FINISHED in
            // LOCKSCREEN.
            assertEquals(
                listOf(
                    LOCKSCREEN,
                    AOD,
                    LOCKSCREEN,
                ),
                finishedStates
            )

            sendSteps(
                TransitionStep(LOCKSCREEN, GONE, 0.6f, CANCELED),
            )

            // We've CANCELED a transition to GONE, we're still FINISHED in LOCKSCREEN.
            assertEquals(
                listOf(
                    LOCKSCREEN,
                    AOD,
                    LOCKSCREEN,
                ),
                finishedStates
            )

            sendSteps(
                TransitionStep(GONE, LOCKSCREEN, 0.6f, STARTED),
                TransitionStep(GONE, LOCKSCREEN, 0.9f, RUNNING),
                TransitionStep(GONE, LOCKSCREEN, 1f, FINISHED),
            )

            // Expect another emission of LOCKSCREEN, as we have FINISHED a second transition to
            // LOCKSCREEN after the cancellation.
            assertEquals(
                listOf(
                    LOCKSCREEN,
                    AOD,
                    LOCKSCREEN,
                    LOCKSCREEN,
                ),
                finishedStates
            )
        }

    @Test
    fun testCurrentState() =
        testScope.runTest {
+29 −17
Original line number Diff line number Diff line
@@ -19,18 +19,20 @@ package com.android.systemui.keyguard.domain.interactor
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectValues
import com.android.systemui.keyguard.data.fakeLightRevealScrimRepository
import com.android.systemui.keyguard.data.repository.DEFAULT_REVEAL_EFFECT
import com.android.systemui.keyguard.data.repository.FakeLightRevealScrimRepository
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.LightRevealEffect
import com.android.systemui.statusbar.LightRevealScrim
import com.android.systemui.testKosmos
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Assert.assertEquals
import org.junit.Test
@@ -64,35 +66,45 @@ class LightRevealScrimInteractorTest : SysuiTestCase() {

    @Test
    fun lightRevealEffect_doesNotChangeDuringKeyguardTransition() =
        runTest(UnconfinedTestDispatcher()) {
            val values = mutableListOf<LightRevealEffect>()
            val job = underTest.lightRevealEffect.onEach(values::add).launchIn(this)
        kosmos.testScope.runTest {
            val values by collectValues(underTest.lightRevealEffect)
            runCurrent()
            assertEquals(listOf(DEFAULT_REVEAL_EFFECT), values)

            fakeLightRevealScrimRepository.setRevealEffect(reveal1)

            runCurrent()
            // The reveal effect shouldn't emit anything until a keyguard transition starts.
            assertEquals(values.size, 0)
            assertEquals(listOf(DEFAULT_REVEAL_EFFECT), values)

            // Once it starts, it should emit reveal1.
            fakeKeyguardTransitionRepository.sendTransitionStep(
                TransitionStep(transitionState = TransitionState.STARTED)
                TransitionStep(to = KeyguardState.AOD, transitionState = TransitionState.STARTED)
            )
            assertEquals(values, listOf(reveal1))
            runCurrent()
            assertEquals(listOf(DEFAULT_REVEAL_EFFECT, reveal1), values)

            // Until the next transition starts, reveal2 should not be emitted.
            fakeLightRevealScrimRepository.setRevealEffect(reveal2)
            runCurrent()
            fakeKeyguardTransitionRepository.sendTransitionStep(
                TransitionStep(transitionState = TransitionState.RUNNING)
                TransitionStep(
                    to = KeyguardState.LOCKSCREEN,
                    transitionState = TransitionState.RUNNING
                )
            )
            runCurrent()
            fakeKeyguardTransitionRepository.sendTransitionStep(
                TransitionStep(transitionState = TransitionState.FINISHED)
                TransitionStep(to = KeyguardState.AOD, transitionState = TransitionState.FINISHED)
            )
            assertEquals(values, listOf(reveal1))
            runCurrent()
            assertEquals(listOf(DEFAULT_REVEAL_EFFECT, reveal1), values)
            fakeKeyguardTransitionRepository.sendTransitionStep(
                TransitionStep(transitionState = TransitionState.STARTED)
                TransitionStep(
                    to = KeyguardState.LOCKSCREEN,
                    transitionState = TransitionState.STARTED
                )
            assertEquals(values, listOf(reveal1, reveal2))

            job.cancel()
            )
            runCurrent()
            assertEquals(listOf(DEFAULT_REVEAL_EFFECT, reveal1, reveal2), values)
        }
}
+1 −1
Original line number Diff line number Diff line
@@ -225,7 +225,7 @@ constructor(
            collectProgress(transition)
        } else if (transition.toScene == CommunalScenes.Communal) {
            if (currentToState == KeyguardState.GLANCEABLE_HUB) {
                transitionKtfTo(transitionInteractor.getStartedFromState())
                transitionKtfTo(transitionInteractor.startedKeyguardTransitionStep.value.from)
            }
            startTransitionToGlanceableHub()
            collectProgress(transition)
Loading