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

Commit a2bb7b0f authored by Lucas Silva's avatar Lucas Silva
Browse files

Prevent dream starting on top of edit mode

Due to b/362830856, the dream may start over edit mode because we
briefly transition back to GLANCEABLE_HUB before transitioning away from
it again. This fix ignores that duplicate transition by only starting
the dream if we are on keyguard (eg not if the device is unlocked).

This is a short-term fix, the longer-term fix for b/362830856 is more
involved as it requires re-working the edit mode transition.

Fixes: 362719648
Test: atest CommunalDreamStartableTest
Flag: com.android.systemui.communal_hub
Change-Id: I1515bdc45ac3ae90434c6a7f05eb2bdfacab2f96
parent 69cafe0e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ class CommunalDreamStartableTest : SysuiTestCase() {
    @Test
    fun startDreamWhenTransitioningToHub() =
        testScope.runTest {
            keyguardRepository.setKeyguardShowing(true)
            keyguardRepository.setDreaming(false)
            powerRepository.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            whenever(dreamManager.canStartDreaming(/* isScreenOn= */ true)).thenReturn(true)
+17 −9
Original line number Diff line number Diff line
@@ -32,11 +32,14 @@ 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.scene.shared.model.Scenes
import com.android.systemui.util.kotlin.BooleanFlowOperators.allOf
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
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.map
import kotlinx.coroutines.flow.onEach

/**
@@ -54,6 +57,18 @@ constructor(
    private val dreamManager: DreamManager,
    @Background private val bgScope: CoroutineScope,
) : CoreStartable {
    /** Flow that emits when the dream should be started underneath the glanceable hub. */
    val startDream =
        allOf(
                keyguardTransitionInteractor
                    .transitionValue(Scenes.Communal, KeyguardState.GLANCEABLE_HUB)
                    .map { it == 1f },
                not(keyguardInteractor.isDreaming),
                // TODO(b/362830856): Remove this workaround.
                keyguardInteractor.isKeyguardShowing,
            )
            .filter { it }

    @SuppressLint("MissingPermission")
    override fun start() {
        if (!communalSettingsInteractor.isCommunalFlagEnabled()) {
@@ -72,17 +87,10 @@ constructor(

        // Restart the dream underneath the hub in order to support the ability to swipe
        // away the hub to enter the dream.
        keyguardTransitionInteractor
            .transition(
                edge = Edge.create(to = Scenes.Communal),
                edgeWithoutSceneContainer = Edge.create(to = KeyguardState.GLANCEABLE_HUB)
            )
            .filterState(TransitionState.FINISHED)
        startDream
            .sampleFilter(powerInteractor.isAwake) { isAwake ->
                dreamManager.canStartDreaming(isAwake)
                !glanceableHubAllowKeyguardWhenDreaming() && dreamManager.canStartDreaming(isAwake)
            }
            .sampleFilter(keyguardInteractor.isDreaming) { isDreaming -> !isDreaming }
            .filter { !glanceableHubAllowKeyguardWhenDreaming() }
            .onEach { dreamManager.startDream() }
            .launchIn(bgScope)
    }
+1 −0
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ constructor(
    }

    private suspend fun finishCurrentTransition() {
        if (currentTransitionId == null) return
        internalTransitionInteractor.updateTransition(
            currentTransitionId!!,
            1f,