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

Commit 7143609a authored by Andreas Miko's avatar Andreas Miko
Browse files

[KTF integration] Fix CommunalDreamStartable

Test: None
Bug: b/330311871
Flag: com.android.systemui.scene_container
Change-Id: Id5362cf8cb4a74b8c8ca8c3f6d8f15d55868c662
parent f0898b11
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.communal.domain.interactor.communalInteractor
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.keyguardRepository
@@ -66,7 +65,6 @@ class CommunalDreamStartableTest : SysuiTestCase() {
                    powerInteractor = kosmos.powerInteractor,
                    keyguardInteractor = kosmos.keyguardInteractor,
                    keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor,
                    communalInteractor = kosmos.communalInteractor,
                    dreamManager = dreamManager,
                    bgScope = kosmos.applicationCoroutineScope,
                )
+22 −24
Original line number Diff line number Diff line
@@ -19,23 +19,25 @@ package com.android.systemui.communal
import android.annotation.SuppressLint
import android.app.DreamManager
import com.android.systemui.CoreStartable
import com.android.systemui.Flags.glanceableHubAllowKeyguardWhenDreaming
import com.android.systemui.Flags.communalHub
import com.android.systemui.Flags.glanceableHubAllowKeyguardWhenDreaming
import com.android.systemui.Flags.restartDreamOnUnocclude
import com.android.systemui.communal.domain.interactor.CommunalInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.filterState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.util.kotlin.Utils.Companion.sample
import com.android.systemui.util.kotlin.sample
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.util.kotlin.Utils.Companion.sampleFilter
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import javax.inject.Inject

/**
 * A [CoreStartable] responsible for automatically starting the dream when the communal hub is
@@ -48,7 +50,6 @@ constructor(
    private val powerInteractor: PowerInteractor,
    private val keyguardInteractor: KeyguardInteractor,
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val communalInteractor: CommunalInteractor,
    private val dreamManager: DreamManager,
    @Background private val bgScope: CoroutineScope,
) : CoreStartable {
@@ -60,31 +61,28 @@ constructor(

        // Return to dream from occluded when not already dreaming.
        if (restartDreamOnUnocclude()) {
            keyguardTransitionInteractor.startedKeyguardTransitionStep
                .sample(keyguardInteractor.isDreaming, ::Pair)
                .filter { (step, isDreaming) ->
                    step.from == KeyguardState.OCCLUDED &&
                        step.to == KeyguardState.DREAMING &&
                        !isDreaming
                }
            keyguardTransitionInteractor
                .transition(Edge.create(from = KeyguardState.OCCLUDED, to = KeyguardState.DREAMING))
                .filterState(TransitionState.STARTED)
                .sampleFilter(keyguardInteractor.isDreaming) { isDreaming -> !isDreaming }
                .onEach { dreamManager.startDream() }
                .launchIn(bgScope)
        }

        // Restart the dream underneath the hub in order to support the ability to swipe
        // away the hub to enter the dream.
        keyguardTransitionInteractor.finishedKeyguardState
            .sample(powerInteractor.isAwake, keyguardInteractor.isDreaming)
            .onEach { (finishedState, isAwake, dreaming) ->
                if (
                    finishedState == KeyguardState.GLANCEABLE_HUB &&
                        !dreaming &&
                        !glanceableHubAllowKeyguardWhenDreaming() &&
        keyguardTransitionInteractor
            .transition(
                edge = Edge.create(to = Scenes.Communal),
                edgeWithoutSceneContainer = Edge.create(to = KeyguardState.GLANCEABLE_HUB)
            )
            .filterState(TransitionState.FINISHED)
            .sampleFilter(powerInteractor.isAwake) { isAwake ->
                dreamManager.canStartDreaming(isAwake)
                ) {
                    dreamManager.startDream()
                }
            }
            .sampleFilter(keyguardInteractor.isDreaming) { isDreaming -> !isDreaming }
            .filter { !glanceableHubAllowKeyguardWhenDreaming() }
            .onEach { dreamManager.startDream() }
            .launchIn(bgScope)
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -265,8 +265,6 @@ constructor(
            .map { step -> step.to }
            .shareIn(scope, SharingStarted.Eagerly, replay = 1)

    val currentTransitionInfo: StateFlow<TransitionInfo> = repository.currentTransitionInfoInternal

    /** The from state of the last [TransitionState.STARTED] transition. */
    // TODO: is it performant to have several SharedFlows side by side instead of one?
    @SuppressLint("SharedFlowCreation")
+3 −3
Original line number Diff line number Diff line
@@ -131,7 +131,7 @@ constructor(
        val newTransition =
            TransitionInfo(
                ownerName = this::class.java.simpleName,
                from = transitionInteractor.currentTransitionInfo.value.to,
                from = transitionInteractor.currentTransitionInfoInternal.value.to,
                to = state,
                animator = null,
                modeOnCanceled = TransitionModeOnCanceled.REVERSE
@@ -150,7 +150,7 @@ constructor(
    private suspend fun handleTransition(transition: ObservableTransitionState.Transition) {
        if (transition.fromScene == Scenes.Lockscreen) {
            if (currentTransitionId != null) {
                val currentToState = transitionInteractor.currentTransitionInfo.value.to
                val currentToState = transitionInteractor.currentTransitionInfoInternal.value.to
                if (currentToState == UNDEFINED) {
                    transitionKtfTo(transitionInteractor.getStartedFromState())
                }
@@ -201,7 +201,7 @@ constructor(
    }

    private suspend fun startTransitionFromLockscreen() {
        val currentState = transitionInteractor.currentTransitionInfo.value.to
        val currentState = transitionInteractor.currentTransitionInfoInternal.value.to
        val newTransition =
            TransitionInfo(
                ownerName = this::class.java.simpleName,
+6 −0
Original line number Diff line number Diff line
@@ -15,6 +15,9 @@
 */
package com.android.systemui.keyguard.shared.model

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.filter

/** This information will flow from the [KeyguardTransitionRepository] to control the UI layer */
data class TransitionStep
@JvmOverloads
@@ -39,3 +42,6 @@ constructor(
        return to == state && transitionState == TransitionState.FINISHED
    }
}

fun Flow<TransitionStep>.filterState(transitionState: TransitionState) =
    this.filter { it.transitionState == transitionState }
Loading