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

Commit 0917bb89 authored by Lucas Silva's avatar Lucas Silva
Browse files

Fix GONE transition from the hub

We are currently transitioning to LOCKSCREEN instead of GONE because its
the default. This change updates the logic to only go to LOCKSCREEN if
its currently visible.

Fixes: 357002287
Test: atest CommunalSceneTransitionInteractorTest
Flag: com.android.systemui.communal_scene_ktf_refactor
Change-Id: I1eb488a5d1d5064d93c23e47f18c63ae984fc9c1
parent acdbc9c1
Loading
Loading
Loading
Loading
+45 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
@@ -78,6 +79,7 @@ class CommunalSceneTransitionInteractorTest : SysuiTestCase() {

    private val underTest by lazy { kosmos.communalSceneTransitionInteractor }
    private val keyguardTransitionRepository by lazy { kosmos.realKeyguardTransitionRepository }
    private val keyguardRepository by lazy { kosmos.fakeKeyguardRepository }

    private val ownerName = CommunalSceneTransitionInteractor::class.java.simpleName
    private val progress = MutableSharedFlow<Float>()
@@ -789,4 +791,47 @@ class CommunalSceneTransitionInteractorTest : SysuiTestCase() {
                    )
                )
        }

    /** Verifies that we correctly transition to GONE after keyguard goes away */
    @Test
    fun transition_to_blank_after_unlock_should_go_to_gone() =
        testScope.runTest {
            keyguardRepository.setKeyguardShowing(true)
            sceneTransitions.value = Idle(CommunalScenes.Communal)

            val currentStep by collectLastValue(keyguardTransitionRepository.transitions)

            assertThat(currentStep)
                .isEqualTo(
                    TransitionStep(
                        from = LOCKSCREEN,
                        to = GLANCEABLE_HUB,
                        transitionState = FINISHED,
                        value = 1f,
                        ownerName = ownerName,
                    )
                )

            // Keyguard starts exiting after a while, then fully exits after some time.
            advanceTimeBy(1.seconds)
            keyguardRepository.setKeyguardGoingAway(true)
            advanceTimeBy(2.seconds)
            keyguardRepository.setKeyguardGoingAway(false)
            keyguardRepository.setKeyguardShowing(false)
            runCurrent()

            // We snap to the blank scene as a result of keyguard going away.
            sceneTransitions.value = Idle(CommunalScenes.Blank)

            assertThat(currentStep)
                .isEqualTo(
                    TransitionStep(
                        from = GLANCEABLE_HUB,
                        to = GONE,
                        transitionState = FINISHED,
                        value = 1f,
                        ownerName = ownerName,
                    )
                )
        }
}
+20 −14
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch

@@ -88,22 +90,26 @@ constructor(
                keyguardInteractor.isAbleToDream,
                keyguardInteractor.isKeyguardOccluded,
                keyguardInteractor.isKeyguardGoingAway,
        ) { dreaming, occluded, keyguardGoingAway ->
                keyguardInteractor.isKeyguardShowing,
            ) { dreaming, occluded, keyguardGoingAway, keyguardShowing ->
                if (keyguardGoingAway) {
                    KeyguardState.GONE
                } else if (occluded && !dreaming) {
                    KeyguardState.OCCLUDED
                } else if (dreaming) {
                    KeyguardState.DREAMING
            } else {
                } else if (keyguardShowing) {
                    KeyguardState.LOCKSCREEN
                } else {
                    null
                }
            }
            .filterNotNull()

    private val nextKeyguardState: StateFlow<KeyguardState> =
        combine(
                repository.nextLockscreenTargetState,
                nextKeyguardStateInternal,
                nextKeyguardStateInternal.onStart { emit(KeyguardState.LOCKSCREEN) },
            ) { override, nextState ->
                override ?: nextState
            }