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

Commit dd6255c1 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
Browse files

Merge "Do not transition to hub from doze/aod on motion/lift" into main

parents 26302b2e 0342d6ad
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -443,4 +443,24 @@ class FromAodTransitionInteractorTest : SysuiTestCase() {
            Truth.assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
            assertThat(transitionRepository).noTransitionsStarted()
        }

    @Test
    @EnableFlags(FLAG_GLANCEABLE_HUB_V2)
    fun testDoNotTransitionToGlanceableHub_onWakeUpFromAodDueToMotion() =
        kosmos.runTest {
            setCommunalV2Available(true)

            val currentScene by collectLastValue(communalSceneInteractor.currentScene)
            fakeCommunalSceneRepository.changeScene(CommunalScenes.Blank)

            // Communal is not showing
            Truth.assertThat(currentScene).isEqualTo(CommunalScenes.Blank)

            powerInteractor.setAwakeForTest(reason = PowerManager.WAKE_REASON_LIFT)
            testScope.advanceTimeBy(100) // account for debouncing

            Truth.assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
            assertThat(transitionRepository)
                .startedTransition(from = KeyguardState.AOD, to = KeyguardState.LOCKSCREEN)
        }
}
+21 −23
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.os.PowerManager
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.FlagsParameterization
import android.provider.Settings
import android.service.dream.dreamManager
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
@@ -30,8 +29,6 @@ import com.android.systemui.Flags.FLAG_KEYGUARD_WM_STATE_REFACTOR
import com.android.systemui.Flags.FLAG_SCENE_CONTAINER
import com.android.systemui.Flags.glanceableHubV2
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.data.repository.batteryRepository
import com.android.systemui.common.data.repository.fake
import com.android.systemui.communal.data.repository.FakeCommunalSceneRepository
import com.android.systemui.communal.data.repository.communalSceneRepository
import com.android.systemui.communal.data.repository.fakeCommunalSceneRepository
@@ -61,8 +58,6 @@ import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.se
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.fakeUserRepository
import com.android.systemui.util.settings.fakeSettings
import com.google.common.truth.Truth
import junit.framework.Assert.assertEquals
import kotlinx.coroutines.flow.flowOf
@@ -171,15 +166,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
    fun testTransitionToLockscreen_onWake_canDream_ktfRefactor() =
        kosmos.runTest {
            setCommunalAvailable(true)
            if (glanceableHubV2()) {
                val user = fakeUserRepository.asMainUser()
                fakeSettings.putIntForUser(
                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
                    1,
                    user.id,
                )
                batteryRepository.fake.setDevicePluggedIn(true)
            } else {
            if (!glanceableHubV2()) {
                whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
            }

@@ -226,15 +213,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
    fun testTransitionToGlanceableHub_onWakeup_ifAvailable() =
        kosmos.runTest {
            setCommunalAvailable(true)
            if (glanceableHubV2()) {
                val user = fakeUserRepository.asMainUser()
                fakeSettings.putIntForUser(
                    Settings.Secure.SCREENSAVER_ACTIVATE_ON_SLEEP,
                    1,
                    user.id,
                )
                batteryRepository.fake.setDevicePluggedIn(true)
            } else {
            if (!glanceableHubV2()) {
                whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
            }

@@ -249,6 +228,25 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
            assertThat(transitionRepository).noTransitionsStarted()
        }

    @Test
    @DisableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR, FLAG_SCENE_CONTAINER)
    @EnableFlags(FLAG_GLANCEABLE_HUB_V2)
    fun testTransitionToLockscreen_onWakeupFromLift() =
        kosmos.runTest {
            setCommunalAvailable(true)
            if (!glanceableHubV2()) {
                whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
            }

            // Device turns on.
            powerInteractor.setAwakeForTest(reason = PowerManager.WAKE_REASON_LIFT)
            testScope.advanceTimeBy(51L)

            // We transition to the lockscreen instead of the hub.
            assertThat(transitionRepository)
                .startedTransition(from = KeyguardState.DOZING, to = KeyguardState.LOCKSCREEN)
        }

    @Test
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToOccluded_onWakeup_whenOccludingActivityOnTop() =
+7 −3
Original line number Diff line number Diff line
@@ -101,14 +101,14 @@ constructor(
                )
                .collect {
                    (
                        _,
                        detailedWakefulness,
                        startedStep,
                        canWakeDirectlyToGone,
                    ) ->
                    val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
                    val biometricUnlockMode = keyguardInteractor.biometricUnlockState.value.mode
                    val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value
                    val shouldShowCommunal = communalSettingsInteractor.autoOpenEnabled.value
                    val autoOpenCommunal = communalSettingsInteractor.autoOpenEnabled.value

                    if (!maybeHandleInsecurePowerGesture()) {
                        val shouldTransitionToLockscreen =
@@ -135,8 +135,12 @@ constructor(
                            (!KeyguardWmStateRefactor.isEnabled && canDismissLockscreen()) ||
                                (KeyguardWmStateRefactor.isEnabled && canWakeDirectlyToGone)

                        // Avoid transitioning to communal automatically if the device is waking
                        // up due to motion.
                        val shouldTransitionToCommunal =
                            communalSettingsInteractor.isV2FlagEnabled() && shouldShowCommunal
                            communalSettingsInteractor.isV2FlagEnabled() &&
                                autoOpenCommunal &&
                                !detailedWakefulness.isAwakeFromMotionOrLift()

                        if (shouldTransitionToGone) {
                            // TODO(b/360368320): Adapt for scene framework
+20 −10
Original line number Diff line number Diff line
@@ -34,8 +34,9 @@ import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepositor
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode.Companion.isWakeAndUnlock
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.WakefulnessModel
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.util.kotlin.Utils.Companion.sample
import com.android.systemui.util.kotlin.Utils.Companion.sample as sampleCombine
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
@@ -121,9 +122,10 @@ constructor(
    private fun shouldTransitionToCommunal(
        shouldShowCommunal: Boolean,
        isCommunalAvailable: Boolean,
        wakefulness: WakefulnessModel,
    ) =
        if (communalSettingsInteractor.isV2FlagEnabled()) {
            shouldShowCommunal
            shouldShowCommunal && !wakefulness.isAwakeFromMotionOrLift()
        } else {
            isCommunalAvailable && dreamManager.canStartDreaming(false)
        }
@@ -148,14 +150,14 @@ constructor(
        }

        scope.launch {
            powerInteractor.isAwake
            powerInteractor.detailedWakefulness
                .debounce(50L)
                .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
                .sample(
                .filterRelevantKeyguardStateAnd { wakefulness -> wakefulness.isAwake() }
                .sampleCombine(
                    communalInteractor.isCommunalAvailable,
                    communalSettingsInteractor.autoOpenEnabled,
                )
                .collect { (_, isCommunalAvailable, shouldShowCommunal) ->
                .collect { (detailedWakefulness, isCommunalAvailable, shouldShowCommunal) ->
                    val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
                    val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value
                    val isKeyguardGoingAway = keyguardInteractor.isKeyguardGoingAway.value
@@ -186,7 +188,11 @@ constructor(
                    } else if (isKeyguardOccludedLegacy) {
                        startTransitionTo(KeyguardState.OCCLUDED)
                    } else if (
                        shouldTransitionToCommunal(shouldShowCommunal, isCommunalAvailable)
                        shouldTransitionToCommunal(
                            shouldShowCommunal,
                            isCommunalAvailable,
                            detailedWakefulness,
                        )
                    ) {
                        if (!SceneContainerFlag.isEnabled) {
                            transitionToGlanceableHub()
@@ -208,7 +214,7 @@ constructor(
        scope.launch {
            powerInteractor.detailedWakefulness
                .filterRelevantKeyguardStateAnd { it.isAwake() }
                .sample(
                .sampleCombine(
                    communalSettingsInteractor.autoOpenEnabled,
                    communalInteractor.isCommunalAvailable,
                    keyguardInteractor.biometricUnlockState,
@@ -217,7 +223,7 @@ constructor(
                )
                .collect {
                    (
                        _,
                        detailedWakefulness,
                        shouldShowCommunal,
                        isCommunalAvailable,
                        biometricUnlockState,
@@ -245,7 +251,11 @@ constructor(
                                )
                            }
                        } else if (
                            shouldTransitionToCommunal(shouldShowCommunal, isCommunalAvailable)
                            shouldTransitionToCommunal(
                                shouldShowCommunal,
                                isCommunalAvailable,
                                detailedWakefulness,
                            )
                        ) {
                            if (!SceneContainerFlag.isEnabled) {
                                transitionToGlanceableHub()
+5 −0
Original line number Diff line number Diff line
@@ -61,6 +61,11 @@ data class WakefulnessModel(
            (lastWakeReason == WakeSleepReason.TAP || lastWakeReason == WakeSleepReason.GESTURE)
    }

    fun isAwakeFromMotionOrLift(): Boolean {
        return isAwake() &&
            (lastWakeReason == WakeSleepReason.MOTION || lastWakeReason == WakeSleepReason.LIFT)
    }

    override fun logDiffs(prevVal: WakefulnessModel, row: TableRowLogger) {
        row.logChange(columnName = "wakefulness", value = toString())
    }