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

Commit ac36f36b authored by Matt Pietal's avatar Matt Pietal
Browse files

Allow DOZING->DREAMING

DreamManagerService can start a dream after the device has gone
to sleep, and after transitions have begun to DOZING. This should
prevent situations where the lockscreen content is still visible
after DREAMING has started.

Fixes: 383977604
Test: atest FromDozingTransitionInteractorTest
Flag: EXEMPT bugfix

Change-Id: I833578cad26c3f24cd372f047e12ba435d6ec0b0
parent a708b619
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepos
import com.android.systemui.keyguard.data.repository.keyguardOcclusionRepository
import com.android.systemui.keyguard.data.repository.keyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
@@ -154,6 +156,22 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
                .startedTransition(from = KeyguardState.DOZING, to = KeyguardState.GONE)
        }

    @Test
    fun testTransitionToDreaming() =
        kosmos.runTest {
            // Ensure dozing is off
            fakeKeyguardRepository.setDozeTransitionModel(
                DozeTransitionModel(from = DozeStateModel.DOZE, to = DozeStateModel.FINISH)
            )
            testScope.advanceTimeBy(600L)

            keyguardInteractor.setDreaming(true)
            testScope.advanceTimeBy(60L)

            assertThat(transitionRepository)
                .startedTransition(from = KeyguardState.DOZING, to = KeyguardState.DREAMING)
        }

    @Test
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    @DisableFlags(FLAG_COMMUNAL_SCENE_KTF_REFACTOR, FLAG_GLANCEABLE_HUB_V2)
+15 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ constructor(

    override fun start() {
        listenForDozingToAny()
        listenForDozingToDreaming()
        listenForDozingToGoneViaBiometrics()
        listenForWakeFromDozing()
        listenForTransitionToCamera(scope, keyguardInteractor)
@@ -128,6 +129,18 @@ constructor(
            isCommunalAvailable && dreamManager.canStartDreaming(false)
        }

    @OptIn(FlowPreview::class)
    @SuppressLint("MissingPermission")
    private fun listenForDozingToDreaming() {
        scope.launch {
            keyguardInteractor.isAbleToDream
                .filterRelevantKeyguardStateAnd { isAbleToDream -> isAbleToDream }
                .collect {
                    startTransitionTo(KeyguardState.DREAMING, ownerReason = "isAbleToDream")
                }
        }
    }

    @OptIn(FlowPreview::class)
    @SuppressLint("MissingPermission")
    private fun listenForDozingToAny() {
@@ -284,6 +297,7 @@ constructor(
            interpolator = Interpolators.LINEAR
            duration =
                when (toState) {
                    KeyguardState.DREAMING -> TO_DREAMING_DURATION
                    KeyguardState.GONE -> TO_GONE_DURATION
                    KeyguardState.GLANCEABLE_HUB -> TO_GLANCEABLE_HUB_DURATION
                    KeyguardState.LOCKSCREEN -> TO_LOCKSCREEN_DURATION
@@ -297,6 +311,7 @@ constructor(
    companion object {
        const val TAG = "FromDozingTransitionInteractor"
        private val DEFAULT_DURATION = 500.milliseconds
        val TO_DREAMING_DURATION = 300.milliseconds
        val TO_GLANCEABLE_HUB_DURATION = DEFAULT_DURATION
        val TO_GONE_DURATION = DEFAULT_DURATION
        val TO_LOCKSCREEN_DURATION = DEFAULT_DURATION
+42 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.viewmodel

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.domain.interactor.FromDozingTransitionInteractor
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState.DOZING
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.ui.KeyguardTransitionAnimationFlow
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

/**
 * Breaks down DOZING->DREAMING transition into discrete steps for corresponding views to consume.
 */
@SysUISingleton
class DozingToDreamingTransitionViewModel
@Inject
constructor(animationFlow: KeyguardTransitionAnimationFlow) {
    private val transitionAnimation =
        animationFlow.setup(
            duration = FromDozingTransitionInteractor.TO_DREAMING_DURATION,
            edge = Edge.create(from = DOZING, to = DREAMING),
        )

    val lockscreenAlpha: Flow<Float> = transitionAnimation.immediatelyTransitionTo(0f)
}
+2 −0
Original line number Diff line number Diff line
@@ -96,6 +96,7 @@ constructor(
    private val aodToLockscreenTransitionViewModel: AodToLockscreenTransitionViewModel,
    private val aodToOccludedTransitionViewModel: AodToOccludedTransitionViewModel,
    private val aodToPrimaryBouncerTransitionViewModel: AodToPrimaryBouncerTransitionViewModel,
    private val dozingToDreamingTransitionViewModel: DozingToDreamingTransitionViewModel,
    private val dozingToGoneTransitionViewModel: DozingToGoneTransitionViewModel,
    private val dozingToLockscreenTransitionViewModel: DozingToLockscreenTransitionViewModel,
    private val dozingToOccludedTransitionViewModel: DozingToOccludedTransitionViewModel,
@@ -247,6 +248,7 @@ constructor(
                        aodToLockscreenTransitionViewModel.lockscreenAlpha(viewState),
                        aodToOccludedTransitionViewModel.lockscreenAlpha(viewState),
                        aodToPrimaryBouncerTransitionViewModel.lockscreenAlpha,
                        dozingToDreamingTransitionViewModel.lockscreenAlpha,
                        dozingToGoneTransitionViewModel.lockscreenAlpha(viewState),
                        dozingToLockscreenTransitionViewModel.lockscreenAlpha,
                        dozingToOccludedTransitionViewModel.lockscreenAlpha(viewState),
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.viewmodel

import com.android.systemui.keyguard.ui.keyguardTransitionAnimationFlow
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture

val Kosmos.dozingToDreamingTransitionViewModel by Fixture {
    DozingToDreamingTransitionViewModel(animationFlow = keyguardTransitionAnimationFlow)
}
Loading