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

Commit 3da4fe9f authored by Lucas Silva's avatar Lucas Silva
Browse files

Handle dream->glanceable_hub transitions

Bug: 325102385
Test: atest KeyguardTransitionScenariosTest
Flag: ACONFIG com.android.systemui.communal_hub STAGING
Change-Id: I81171f045f98d4c253bd9bcf5e2d06ca5703c772
parent e62c492c
Loading
Loading
Loading
Loading
+0 −26
Original line number Diff line number Diff line
@@ -82,25 +82,6 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            }
        }

    @Test
    fun deviceDreaming_forceBlankScene() =
        with(kosmos) {
            testScope.runTest {
                val scene by collectLastValue(communalInteractor.desiredScene)

                communalInteractor.onSceneChanged(CommunalSceneKey.Communal)
                assertThat(scene).isEqualTo(CommunalSceneKey.Communal)

                fakeKeyguardTransitionRepository.sendTransitionSteps(
                    from = KeyguardState.GLANCEABLE_HUB,
                    to = KeyguardState.DREAMING,
                    testScope = this
                )

                assertThat(scene).isEqualTo(CommunalSceneKey.Blank)
            }
        }

    @Test
    fun deviceDocked_forceCommunalScene() =
        with(kosmos) {
@@ -115,13 +96,6 @@ class CommunalSceneStartableTest : SysuiTestCase() {
                    testScope = this
                )
                assertThat(scene).isEqualTo(CommunalSceneKey.Communal)

                fakeKeyguardTransitionRepository.sendTransitionSteps(
                    from = KeyguardState.GLANCEABLE_HUB,
                    to = KeyguardState.DREAMING,
                    testScope = this
                )
                assertThat(scene).isEqualTo(CommunalSceneKey.Blank)
            }
        }

+0 −1
Original line number Diff line number Diff line
@@ -88,7 +88,6 @@ constructor(
        val docked = dockManager.isDocked

        return when {
            to == KeyguardState.DREAMING -> CommunalSceneKey.Blank
            docked && to == KeyguardState.LOCKSCREEN && from != KeyguardState.GLANCEABLE_HUB -> {
                CommunalSceneKey.Communal
            }
+8 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.keyguard.domain.interactor

import android.animation.ValueAnimator
import com.android.app.animation.Interpolators
import com.android.app.tracing.coroutines.launch
import com.android.systemui.Flags.communalHub
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
@@ -64,13 +65,14 @@ constructor(

    private fun listenForDreamingToGlanceableHub() {
        if (!communalHub()) return
        scope.launch("$TAG#listenForDreamingToGlanceableHub", mainDispatcher) {
            glanceableHubTransitions.listenForGlanceableHubTransition(
            transitionName = "listenForDreamingToGlanceableHub",
                transitionOwnerName = TAG,
                fromState = KeyguardState.DREAMING,
                toState = KeyguardState.GLANCEABLE_HUB,
            )
        }
    }

    fun startToLockscreenTransition() {
        scope.launch {
+29 −32
Original line number Diff line number Diff line
@@ -27,13 +27,16 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionModeOnCanceled
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleMultiple
import com.android.systemui.util.kotlin.BooleanFlowOperators.and
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

@SysUISingleton
class FromGlanceableHubTransitionInteractor
@@ -58,13 +61,12 @@ constructor(
        if (!Flags.communalHub()) {
            return
        }
        listenForHubToLockscreen()
        listenForHubToLockscreenOrDreaming()
        listenForHubToDozing()
        listenForHubToPrimaryBouncer()
        listenForHubToAlternateBouncer()
        listenForHubToOccluded()
        listenForHubToGone()
        listenForHubToDreaming()
    }

    override fun getDefaultAnimatorForTransitionsToState(toState: KeyguardState): ValueAnimator {
@@ -82,14 +84,25 @@ constructor(
     * Listens for the glanceable hub transition to lock screen and directly drives the keyguard
     * transition.
     */
    private fun listenForHubToLockscreen() {
    private fun listenForHubToLockscreenOrDreaming() {
        scope.launch("$TAG#listenForGlanceableHubToLockscreenOrDream") {
            keyguardInteractor.isDreaming.collectLatest { dreaming ->
                withContext(mainDispatcher) {
                    val toState =
                        if (dreaming) {
                            KeyguardState.DREAMING
                        } else {
                            KeyguardState.LOCKSCREEN
                        }
                    glanceableHubTransitions.listenForGlanceableHubTransition(
            transitionName = "listenForHubToLockscreen",
                        transitionOwnerName = TAG,
                        fromState = KeyguardState.GLANCEABLE_HUB,
            toState = KeyguardState.LOCKSCREEN,
                        toState = toState,
                    )
                }
            }
        }
    }

    private fun listenForHubToPrimaryBouncer() {
        scope.launch("$TAG#listenForHubToPrimaryBouncer") {
@@ -137,28 +150,12 @@ constructor(
        }
    }

    private fun listenForHubToDreaming() {
        val invalidFromStates = setOf(KeyguardState.AOD, KeyguardState.DOZING)
        scope.launch("$TAG#listenForHubToDreaming") {
            keyguardInteractor.isAbleToDream
                .sampleMultiple(startedKeyguardTransitionStep, finishedKeyguardState)
                .collect { (isAbleToDream, lastStartedTransition, finishedKeyguardState) ->
                    val isOnHub = finishedKeyguardState == KeyguardState.GLANCEABLE_HUB
                    val isTransitionInterruptible =
                        lastStartedTransition.to == KeyguardState.GLANCEABLE_HUB &&
                            !invalidFromStates.contains(lastStartedTransition.from)
                    if (isAbleToDream && (isOnHub || isTransitionInterruptible)) {
                        startTransitionTo(KeyguardState.DREAMING)
                    }
                }
        }
    }

    private fun listenForHubToOccluded() {
        scope.launch {
            keyguardInteractor.isKeyguardOccluded.sample(startedKeyguardState, ::Pair).collect {
                (isOccluded, keyguardState) ->
                if (isOccluded && keyguardState == fromState) {
            and(keyguardInteractor.isKeyguardOccluded, not(keyguardInteractor.isDreaming))
                .sample(startedKeyguardState, ::Pair)
                .collect { (isOccludedAndNotDreaming, keyguardState) ->
                    if (isOccludedAndNotDreaming && keyguardState == fromState) {
                        startTransitionTo(KeyguardState.OCCLUDED)
                    }
                }
+7 −7
Original line number Diff line number Diff line
@@ -360,14 +360,14 @@ constructor(
        if (!com.android.systemui.Flags.communalHub()) {
            return
        }

        scope.launch(mainDispatcher) {
            glanceableHubTransitions.listenForGlanceableHubTransition(
            transitionName = "listenForLockscreenToGlanceableHub",
                transitionOwnerName = TAG,
                fromState = KeyguardState.LOCKSCREEN,
                toState = KeyguardState.GLANCEABLE_HUB,
            )
        }
    }

    override fun getDefaultAnimatorForTransitionsToState(toState: KeyguardState): ValueAnimator {
        return ValueAnimator().apply {
Loading