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

Commit ec2b7356 authored by Andreas Miko's avatar Andreas Miko
Browse files

Consolidate startedKeyguardTransitionStep and make it a StateFlow

I'm reducing the API surface of KTI such that there are fewer
non-flexiglass aware APIs that can eventually be removed or at least
deprecated. Also making this a stateFlow as we are trying to migrate
everything to stateFlows eventually.

Bug: b/330311871
Flag: EXEMPT refactor
Test: REFACTOR_ONLY
Change-Id: I5087008afa407fd9f775007a93a82b40eabd780f
parent ae8f24a3
Loading
Loading
Loading
Loading
+0 −23
Original line number Diff line number Diff line
@@ -112,29 +112,6 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            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 {
+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
@@ -224,7 +224,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)
+1 −1
Original line number Diff line number Diff line
@@ -89,7 +89,7 @@ constructor(
                .filterRelevantKeyguardStateAnd { wakefulness -> wakefulness.isAwake() }
                .debounce(50L)
                .sample(
                    startedKeyguardTransitionStep,
                    transitionInteractor.startedKeyguardTransitionStep,
                    wakeToGoneInteractor.canWakeDirectlyToGone,
                )
                .collect {
+2 −2
Original line number Diff line number Diff line
@@ -117,7 +117,7 @@ constructor(
        if (SceneContainerFlag.isEnabled) return
        scope.launch {
            keyguardInteractor.primaryBouncerShowing
                .sample(startedKeyguardTransitionStep, ::Pair)
                .sample(transitionInteractor.startedKeyguardTransitionStep, ::Pair)
                .collect { pair ->
                    val (isBouncerShowing, lastStartedTransitionStep) = pair
                    if (
@@ -132,7 +132,7 @@ constructor(
    fun startToLockscreenOrGlanceableHubTransition(openHub: Boolean) {
        scope.launch {
            if (
                transitionInteractor.startedKeyguardState.replayCache.last() ==
                transitionInteractor.startedKeyguardTransitionStep.value.to ==
                    KeyguardState.DREAMING
            ) {
                if (powerInteractor.detailedWakefulness.value.isAwake()) {
Loading