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

Commit cea23efa authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Fix issue where we could return to GONE during GONE -> AOD/DOZING.

Bug: 278086361
Test: atest KeyguardWakeDirectlyToGoneInteractorTest
Flag: com.android.systemui.keyguard_wm_state_refactor
Change-Id: Ife8ac1222d05a68940e05e0090793fb001414573
parent 0a6de0a0
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
@@ -406,4 +407,48 @@ class KeyguardWakeDirectlyToGoneInteractorTest : SysuiTestCase() {
            // It should not have any effect.
            assertEquals(listOf(false, true, false, true), canWake)
        }

    @Test
    @EnableFlags(Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testCanWakeDirectlyToGone_falseAsSoonAsTransitionsAwayFromGone() =
        testScope.runTest {
            val canWake by collectValues(underTest.canWakeDirectlyToGone)

            assertEquals(
                listOf(
                    false // Defaults to false.
                ),
                canWake,
            )

            transitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GONE,
                testScope,
            )

            assertEquals(
                listOf(
                    false,
                    true, // Because we're GONE.
                ),
                canWake,
            )

            transitionRepository.sendTransitionSteps(
                from = KeyguardState.LOCKSCREEN,
                to = KeyguardState.GONE,
                testScope = testScope,
                throughTransitionState = TransitionState.RUNNING,
            )

            assertEquals(
                listOf(
                    false,
                    true,
                    false, // False as soon as we start a transition away from GONE.
                ),
                canWake,
            )
        }
}
+3 −1
Original line number Diff line number Diff line
@@ -132,6 +132,8 @@ constructor(
                            if (SceneContainerFlag.isEnabled) return@collect
                            startTransitionTo(
                                toState = KeyguardState.GONE,
                                modeOnCanceled = TransitionModeOnCanceled.REVERSE,
                                ownerReason = "canWakeDirectlyToGone = true",
                            )
                        } else if (shouldTransitionToLockscreen) {
                            val modeOnCanceled =
@@ -146,7 +148,7 @@ constructor(
                            startTransitionTo(
                                toState = KeyguardState.LOCKSCREEN,
                                modeOnCanceled = modeOnCanceled,
                                ownerReason = "listen for aod to awake"
                                ownerReason = "listen for aod to awake",
                            )
                        } else if (shouldTransitionToOccluded) {
                            startTransitionTo(
+6 −4
Original line number Diff line number Diff line
@@ -116,9 +116,10 @@ constructor(
     * - We're wake and unlocking (fingerprint auth occurred while asleep).
     * - We're allowed to ignore auth and return to GONE, due to timeouts not elapsing.
     * - We're DREAMING and dismissible.
     * - We're already GONE. Technically you're already awake when GONE, but this makes it easier to
     *   reason about this state (for example, if canWakeDirectlyToGone, don't tell WM to pause the
     *   top activity - something you should never do while GONE as well).
     * - We're already GONE and not transitioning out of GONE. Technically you're already awake when
     *   GONE, but this makes it easier to reason about this state (for example, if
     *   canWakeDirectlyToGone, don't tell WM to pause the top activity - something you should never
     *   do while GONE as well).
     */
    val canWakeDirectlyToGone =
        combine(
@@ -138,7 +139,8 @@ constructor(
                    canIgnoreAuthAndReturnToGone ||
                    (currentState == KeyguardState.DREAMING &&
                        keyguardInteractor.isKeyguardDismissible.value) ||
                    currentState == KeyguardState.GONE
                    (currentState == KeyguardState.GONE &&
                        transitionInteractor.getStartedState() == KeyguardState.GONE)
            }
            .distinctUntilChanged()