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

Commit f358351b authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] changeScene even if going to same scene

Removed unnecessary (and incorrect) check from SceneInteactor.validateSceneChange that was causing a bug where the change to Lockscreen triggered by device sleep (power button) while dragging up from Lockscreen to reveal the Bouncer wasn't actually going to the Lockscreen scene.

The check is unnecessary because the upstream logic in STL is already
protecting us and is incorrect because it was using the current scene as
the "from" scene, even though that's not necessarily correct when
transitioning from scene A to scene B.

Fix: 379844479
Test: manually verified that dragging up on the Lockscreen scene, not
removing the finger, and then pressing the power button correctly
transitioned to the Lockscreen scene even though the finger wasn't
removed. Also made sure that additional gestures afterwards work as
intended.
Flag: com.android.systemui.scene_container

Change-Id: I4065506623cac2e33a38004cc4a88dbb56b97b18
parent 9477f6b2
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import com.android.systemui.flags.andSceneContainer
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState
@@ -494,6 +495,7 @@ class CommunalSceneStartableTest(flags: FlagsParameterization) : SysuiTestCase()

                // Start dreaming.
                updateDreaming(true)
                advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)

                // Hub times out immediately.
                assertThat(scene).isEqualTo(CommunalScenes.Blank)
@@ -650,6 +652,7 @@ class CommunalSceneStartableTest(flags: FlagsParameterization) : SysuiTestCase()

                // Start dreaming.
                updateDreaming(true)
                advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)

                // Hub times out immediately.
                assertThat(scene).isEqualTo(Scenes.Dream)
+32 −6
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ import com.android.systemui.keyguard.data.repository.fakeTrustRepository
import com.android.systemui.keyguard.data.repository.keyguardRepository
import com.android.systemui.keyguard.data.repository.keyguardTransitionRepository
import com.android.systemui.keyguard.dismissCallbackRegistry
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.dozeInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
@@ -1270,8 +1271,11 @@ class SceneContainerStartableTest : SysuiTestCase() {
                authenticationMethod = AuthenticationMethodModel.None,
                isLockscreenEnabled = false,
            )
            assertThat(currentSceneKey).isEqualTo(Scenes.Lockscreen)
            powerInteractor.setAsleepForTest()
            underTest.start()
            runCurrent()
            assertThat(currentSceneKey).isEqualTo(Scenes.Lockscreen)

            powerInteractor.setAwakeForTest()
            runCurrent()

@@ -2139,6 +2143,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val transitionStateFlow = prepareState()
            underTest.start()
            runCurrent()
            emulateSceneTransition(transitionStateFlow, toScene = Scenes.Bouncer)
            assertThat(currentScene).isNotEqualTo(Scenes.Lockscreen)

@@ -2153,6 +2158,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val transitionStateFlow = prepareState()
            underTest.start()
            runCurrent()
            emulateSceneTransition(transitionStateFlow, toScene = Scenes.Bouncer)
            assertThat(currentScene).isEqualTo(Scenes.Bouncer)

@@ -2269,6 +2275,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
            assertThat(currentScene).isEqualTo(Scenes.Gone)
            assertThat(kosmos.deviceEntryInteractor.isDeviceEntered.value).isTrue()
            underTest.start()
            runCurrent()
            sceneInteractor.changeScene(Scenes.Shade, "")
            assertThat(currentScene).isEqualTo(Scenes.Shade)
            assertThat(kosmos.deviceEntryInteractor.isDeviceEntered.value).isTrue()
@@ -2350,6 +2357,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            prepareState()
            underTest.start()
            runCurrent()

            // run all pending dismiss succeeded/cancelled calls from setup:
            kosmos.fakeExecutor.runAllReady()
@@ -2461,13 +2469,18 @@ class SceneContainerStartableTest : SysuiTestCase() {
    @Test
    fun switchFromDreamToLockscreen_whenLockedAndDreamStopped() =
        testScope.runTest {
            keyguardInteractor.setDreaming(true)
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            prepareState(initialSceneKey = Scenes.Dream)
            assertThat(currentScene).isEqualTo(Scenes.Dream)
            underTest.start()
            advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
            runCurrent()
            keyguardInteractor.setDreaming(true)
            advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
            runCurrent()
            assertThat(currentScene).isEqualTo(Scenes.Dream)

            keyguardInteractor.setDreaming(false)
            advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
            runCurrent()
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)
        }
@@ -2475,13 +2488,18 @@ class SceneContainerStartableTest : SysuiTestCase() {
    @Test
    fun switchFromDreamToGone_whenUnlockedAndDreamStopped() =
        testScope.runTest {
            keyguardInteractor.setDreaming(true)
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            prepareState(initialSceneKey = Scenes.Dream, isDeviceUnlocked = true)
            assertThat(currentScene).isEqualTo(Scenes.Dream)
            underTest.start()
            advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
            runCurrent()
            keyguardInteractor.setDreaming(true)
            advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
            runCurrent()
            assertThat(currentScene).isEqualTo(Scenes.Dream)

            keyguardInteractor.setDreaming(false)
            advanceTimeBy(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
            runCurrent()
            assertThat(currentScene).isEqualTo(Scenes.Gone)
        }
@@ -2684,6 +2702,7 @@ class SceneContainerStartableTest : SysuiTestCase() {
            underTest.start()
            val currentScene by collectLastValue(sceneInteractor.currentScene)
            val currentOverlays by collectLastValue(sceneInteractor.currentOverlays)
            runCurrent()
            sceneInteractor.changeScene(Scenes.Shade, "reason")
            sceneInteractor.showOverlay(Overlays.NotificationsShade, "reason")
            assertThat(currentScene).isEqualTo(Scenes.Shade)
@@ -2835,8 +2854,15 @@ class SceneContainerStartableTest : SysuiTestCase() {
            )
        sceneInteractor.setTransitionState(transitionStateFlow)
        initialSceneKey?.let {
            if (isDeviceUnlocked && initialSceneKey != Scenes.Gone) {
                // Pass through the Gone scene to populate device entry state properly.
                transitionStateFlow.value = ObservableTransitionState.Idle(Scenes.Gone)
                sceneInteractor.changeScene(Scenes.Gone, "prepareState, passing through Gone scene")
                runCurrent()
            }

            transitionStateFlow.value = ObservableTransitionState.Idle(it)
            sceneInteractor.changeScene(it, "reason")
            sceneInteractor.changeScene(it, "prepareState, initialSceneKey isn't null")
        }
        if (startsAwake) {
            powerInteractor.setAwakeForTest()
+7 −6
Original line number Diff line number Diff line
@@ -127,12 +127,6 @@ class KeyguardBypassInteractorTest : SysuiTestCase() {
        kosmos.configureKeyguardBypass(isBypassAvailable = skipIsBypassAvailableCheck)
        underTest = kosmos.keyguardBypassInteractor

        // bouncerShowing false, !onLockscreenScene false
        // !onLockscreenScene false
        setScene(
            bouncerShowing = !skipBouncerShowingCheck,
            onLockscreenScene = skipOnLockscreenSceneCheck,
        )
        // alternateBouncerShowing false
        setAlternateBouncerShowing(!skipAlternateBouncerShowingCheck)
        // launchingAffordance false
@@ -141,6 +135,13 @@ class KeyguardBypassInteractorTest : SysuiTestCase() {
        setPulseExpanding(!skipPulseExpandingCheck)
        // qsExpanding false
        setQsExpanded(!skipQsExpandedCheck)

        // bouncerShowing false, !onLockscreenScene false
        // !onLockscreenScene false
        setScene(
            bouncerShowing = !skipBouncerShowingCheck,
            onLockscreenScene = skipOnLockscreenSceneCheck,
        )
    }

    private fun setAlternateBouncerShowing(alternateBouncerVisible: Boolean) {
+6 −1
Original line number Diff line number Diff line
@@ -183,7 +183,12 @@ constructor(
                    this@CommunalSceneStartable.isDreaming = isDreaming
                    if (scene.isCommunal() && isDreaming && timeoutJob == null) {
                        // If dreaming starts after timeout has expired, ex. if dream restarts under
                        // the hub, just close the hub immediately.
                        // the hub, wait for IS_ABLE_TO_DREAM_DELAY_MS and then close the hub. The
                        // delay is necessary so the KeyguardInteractor.isAbleToDream flow passes
                        // through that same amount of delay and publishes a new value which is then
                        // picked up by the HomeSceneFamilyResolver such that the next call to
                        // SceneInteractor.changeScene(Home) will resolve "Home" to "Dream".
                        delay(KeyguardInteractor.IS_ABLE_TO_DREAM_DELAY_MS)
                        communalSceneInteractor.changeScene(
                            CommunalScenes.Blank,
                            "dream started after timeout",
+11 −2
Original line number Diff line number Diff line
@@ -200,7 +200,10 @@ constructor(
     * Dozing and dreaming have overlapping events. If the doze state remains in FINISH, it means
     * that doze mode is not running and DREAMING is ok to commence.
     *
     * Allow a brief moment to prevent rapidly oscillating between true/false signals.
     * Allow a brief moment to prevent rapidly oscillating between true/false signals. The amount of
     * time is [IS_ABLE_TO_DREAM_DELAY_MS] - consumers should consider waiting for that long before
     * examining the value of this flow, to let other consumers have enough time to also see that
     * same new value.
     */
    val isAbleToDream: Flow<Boolean> =
        dozeTransitionModel
@@ -212,7 +215,7 @@ constructor(
                    // do not immediately process any dreaming information when exiting AOD. It
                    // should actually be quite strange to leave AOD and then go straight to
                    // DREAMING so this should be fine.
                    delay(500L)
                    delay(IS_ABLE_TO_DREAM_DELAY_MS)
                    isDreaming
                        .sample(powerInteractor.isAwake) { isDreaming, isAwake ->
                            isDreaming && isAwake
@@ -550,5 +553,11 @@ constructor(

    companion object {
        private const val TAG = "KeyguardInteractor"
        /**
         * Amount of time that [KeyguardInteractor.isAbleToDream] is delayed; consumers of that flow
         * should consider waiting this amount of time before check the value of this flow, to let
         * other consumers have enough time to see the new value.
         */
        const val IS_ABLE_TO_DREAM_DELAY_MS = 500L
    }
}
Loading