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

Commit 033f684d authored by Lucas Silva's avatar Lucas Silva
Browse files

Handle communal transitions during other KTF transitions

This change handles the hub closing in the middle of another KTF
transition. In this case, we should cancel the existing transition and
transition immediately to the GLANCEABLE_HUB state, so that we can
properly transition away from it.

This causes KeyguardTransitionScenariosTest to fail, as that test uses a
FakeKeyguardTransitionRepository which behaves differently that a real
one - and doesn't properly support manual transitions. Decided to remove
some duplicate test cases there which are already covered by
CommunalSceneTransitionInteractorTest

Fixes: 360207879
Test: atest KeyguardTransitionScenariosTest
Test: atest CommunalSceneTransitionInteractorTest
Flag: com.android.systemui.communal_scene_ktf_refactor
Change-Id: Id2a00fa44dbf8508373da3ba276df6f591d41fd5
parent e252157b
Loading
Loading
Loading
Loading
+83 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.keyguard.data.repository.keyguardTransitionRepositor
import com.android.systemui.keyguard.data.repository.realKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
import com.android.systemui.keyguard.shared.model.KeyguardState.ALTERNATE_BOUNCER
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.GLANCEABLE_HUB
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
@@ -834,4 +835,86 @@ class CommunalSceneTransitionInteractorTest : SysuiTestCase() {
                    )
                )
        }

    /**
     * KTF: LOCKSCREEN -> ALTERNATE_BOUNCER starts but then STL: GLANCEABLE_HUB -> BLANK interrupts.
     *
     * Verifies that we correctly cancel the previous KTF state before starting the glanceable hub
     * transition.
     */
    @Test
    fun transition_to_blank_after_ktf_started_another_transition() =
        testScope.runTest {
            // Another transition has already started to the alternate bouncer.
            keyguardTransitionRepository.startTransition(
                TransitionInfo(
                    from = LOCKSCREEN,
                    to = ALTERNATE_BOUNCER,
                    animator = null,
                    ownerName = "external",
                    modeOnCanceled = TransitionModeOnCanceled.RESET
                ),
            )

            val allSteps by collectValues(keyguardTransitionRepository.transitions)
            // Keep track of existing size to drop any pre-existing steps that we don't
            // care about.
            val numToDrop = allSteps.size

            sceneTransitions.value = hubToBlank
            runCurrent()
            progress.emit(0.4f)
            runCurrent()
            // We land on blank.
            sceneTransitions.value = Idle(CommunalScenes.Blank)

            // We should cancel the previous ALTERNATE_BOUNCER transition and transition back
            // to the GLANCEABLE_HUB before we can transition away from it.
            assertThat(allSteps.drop(numToDrop))
                .containsExactly(
                    TransitionStep(
                        from = LOCKSCREEN,
                        to = ALTERNATE_BOUNCER,
                        transitionState = CANCELED,
                        value = 0f,
                        ownerName = "external",
                    ),
                    TransitionStep(
                        from = ALTERNATE_BOUNCER,
                        to = GLANCEABLE_HUB,
                        transitionState = STARTED,
                        value = 1f,
                        ownerName = ownerName,
                    ),
                    TransitionStep(
                        from = ALTERNATE_BOUNCER,
                        to = GLANCEABLE_HUB,
                        transitionState = FINISHED,
                        value = 1f,
                        ownerName = ownerName,
                    ),
                    TransitionStep(
                        from = GLANCEABLE_HUB,
                        to = LOCKSCREEN,
                        transitionState = STARTED,
                        value = 0f,
                        ownerName = ownerName,
                    ),
                    TransitionStep(
                        from = GLANCEABLE_HUB,
                        to = LOCKSCREEN,
                        transitionState = RUNNING,
                        value = 0.4f,
                        ownerName = ownerName,
                    ),
                    TransitionStep(
                        from = GLANCEABLE_HUB,
                        to = LOCKSCREEN,
                        transitionState = FINISHED,
                        value = 1f,
                        ownerName = ownerName,
                    ),
                )
                .inOrder()
        }
}
+0 −89
Original line number Diff line number Diff line
@@ -1966,47 +1966,6 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
            coroutineContext.cancelChildren()
        }

    @Test
    @DisableSceneContainer
    @EnableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    fun glanceableHubToLockscreen_communalKtfRefactor() =
        testScope.runTest {
            // GIVEN a prior transition has run to GLANCEABLE_HUB
            communalSceneInteractor.changeScene(CommunalScenes.Communal, "test")
            runCurrent()
            clearInvocations(transitionRepository)

            // WHEN a transition away from glanceable hub starts
            val currentScene = CommunalScenes.Communal
            val targetScene = CommunalScenes.Blank

            val progress = MutableStateFlow(0f)
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition(
                        fromScene = currentScene,
                        toScene = targetScene,
                        currentScene = flowOf(targetScene),
                        progress = progress,
                        isInitiatedByUserInput = false,
                        isUserInputOngoing = flowOf(false),
                    )
                )
            communalSceneInteractor.setTransitionState(transitionState)
            progress.value = .1f
            runCurrent()

            assertThat(transitionRepository)
                .startedTransition(
                    ownerName = CommunalSceneTransitionInteractor::class.simpleName,
                    from = KeyguardState.GLANCEABLE_HUB,
                    to = KeyguardState.LOCKSCREEN,
                    animatorAssertion = { it.isNull() }, // transition should be manually animated
                )

            coroutineContext.cancelChildren()
        }

    @Test
    @DisableSceneContainer
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
@@ -2259,54 +2218,6 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
            coroutineContext.cancelChildren()
        }

    @Test
    @DisableSceneContainer
    @EnableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
    fun glanceableHubToDreaming_communalKtfRefactor() =
        testScope.runTest {
            // GIVEN that we are dreaming and not dozing
            powerInteractor.setAwakeForTest()
            keyguardRepository.setDreaming(true)
            keyguardRepository.setDreamingWithOverlay(true)
            keyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(from = DozeStateModel.DOZE, to = DozeStateModel.FINISH)
            )
            advanceTimeBy(600L)

            // GIVEN a prior transition has run to GLANCEABLE_HUB
            communalSceneInteractor.changeScene(CommunalScenes.Communal, "test")
            runCurrent()
            clearInvocations(transitionRepository)

            // WHEN a transition away from glanceable hub starts
            val currentScene = CommunalScenes.Communal
            val targetScene = CommunalScenes.Blank

            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition(
                        fromScene = currentScene,
                        toScene = targetScene,
                        currentScene = flowOf(targetScene),
                        progress = flowOf(0f, 0.1f),
                        isInitiatedByUserInput = false,
                        isUserInputOngoing = flowOf(false),
                    )
                )
            communalSceneInteractor.setTransitionState(transitionState)
            runCurrent()

            assertThat(transitionRepository)
                .startedTransition(
                    ownerName = CommunalSceneTransitionInteractor::class.simpleName,
                    from = KeyguardState.GLANCEABLE_HUB,
                    to = KeyguardState.DREAMING,
                    animatorAssertion = { it.isNull() }, // transition should be manually animated
                )

            coroutineContext.cancelChildren()
        }

    @Test
    @BrokenWithSceneContainer(339465026)
    @EnableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR)
+5 −9
Original line number Diff line number Diff line
@@ -223,19 +223,15 @@ constructor(
            // KTF for this case and just collect the new progress instead.
            collectProgress(transition)
        } else if (transition.toScene == CommunalScenes.Communal) {
            if (currentTransitionId != null) {
            if (currentToState == KeyguardState.GLANCEABLE_HUB) {
                transitionKtfTo(transitionInteractor.getStartedFromState())
            }
            }
            startTransitionToGlanceableHub()
            collectProgress(transition)
        } else if (transition.toScene == CommunalScenes.Blank) {
            if (currentTransitionId != null) {
            // Another transition started before this one is completed. Transition to the
            // GLANCEABLE_HUB state so that we can properly transition away from it.
            transitionKtfTo(KeyguardState.GLANCEABLE_HUB)
            }
            startTransitionFromGlanceableHub()
            collectProgress(transition)
        }