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

Commit 67a79b2e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Disable showing hub on power-button press." into main

parents 4e7c2337 59a07010
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -153,13 +153,12 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT

    @Test
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    @DisableSceneContainer // Specifically testing keyguard_wm_state_refactor enabled w/o flexi.
    fun testTransitionToLockscreen_onWake_canDream_ktfRefactor() =
        kosmos.runTest {
            setCommunalAvailable(true)
            if (!glanceableHubV2()) {
            whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
            }

            clearInvocations(fakeCommunalSceneRepository)
            powerInteractor.setAwakeForTest()
@@ -187,7 +186,8 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT

    @Test
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToLockscreen_onWake_canNDream_glanceableHubNotAvailable() =
    @DisableFlags(FLAG_GLANCEABLE_HUB_V2)
    fun testTransitionToLockscreen_onWake_canDream_glanceableHubNotAvailable() =
        kosmos.runTest {
            whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(true)
            setCommunalAvailable(false)
@@ -201,7 +201,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
        }

    @Test
    @DisableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR, FLAG_SCENE_CONTAINER)
    @DisableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR, FLAG_SCENE_CONTAINER, FLAG_GLANCEABLE_HUB_V2)
    fun testTransitionToGlanceableHub_onWakeup_ifAvailable() =
        kosmos.runTest {
            setCommunalAvailable(true)
@@ -226,9 +226,7 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
    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)
@@ -240,14 +238,12 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
        }

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

            // Device turns on.
            powerInteractor.setAwakeForTest()
@@ -261,6 +257,20 @@ class FromDozingTransitionInteractorTest(flags: FlagsParameterization?) : SysuiT
                .startedTransition(from = KeyguardState.DOZING, to = KeyguardState.OCCLUDED)
        }

    @Test
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR, FLAG_GLANCEABLE_HUB_V2)
    fun testTransitionToLockscreen_onWake_glanceableHubAvailable_glanceableHubV2Enabled() =
        kosmos.runTest {
            whenever(dreamManager.canStartDreaming(anyBoolean())).thenReturn(false)
            setCommunalAvailable(true)
            powerInteractor.setAwakeForTest()

            // Even if communal is available (and we can't dream), in hub_v2 we should transition to
            // LOCKSCREEN when waking up due to power button press.
            assertThat(transitionRepository)
                .startedTransition(from = KeyguardState.DOZING, to = KeyguardState.LOCKSCREEN)
        }

    @Test
    @EnableFlags(FLAG_KEYGUARD_WM_STATE_REFACTOR)
    fun testTransitionToOccluded_onWakeup_whenOccludingActivityOnTop() =
+1 −1
Original line number Diff line number Diff line
@@ -198,7 +198,7 @@ class FromDreamingTransitionInteractorTest(flags: FlagsParameterization?) : Sysu
        }

    @Test
    @DisableFlags(Flags.FLAG_SCENE_CONTAINER)
    @DisableFlags(Flags.FLAG_SCENE_CONTAINER, FLAG_GLANCEABLE_HUB_V2)
    fun testTransitionToGlanceableHubOnWake() =
        kosmos.runTest {
            transitionRepository.sendTransitionSteps(
+10 −35
Original line number Diff line number Diff line
@@ -34,9 +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 as sampleCombine
import com.android.systemui.util.kotlin.sample
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlinx.coroutines.CoroutineDispatcher
@@ -114,18 +114,10 @@ constructor(
    }

    @SuppressLint("MissingPermission")
    private fun shouldTransitionToCommunal(
        shouldShowCommunal: Boolean,
        isCommunalAvailable: Boolean,
        wakefulness: WakefulnessModel,
    ) =
        if (communalSettingsInteractor.isV2FlagEnabled()) {
            shouldShowCommunal &&
                !wakefulness.isAwakeFromMotionOrLift() &&
                !keyguardInteractor.isKeyguardOccluded.value
        } else {
            isCommunalAvailable && dreamManager.canStartDreaming(false)
        }
    private fun shouldTransitionToCommunal(isCommunalAvailable: Boolean) =
        !communalSettingsInteractor.isV2FlagEnabled() &&
            isCommunalAvailable &&
            dreamManager.canStartDreaming(false)

    @OptIn(FlowPreview::class)
    @SuppressLint("MissingPermission")
@@ -150,11 +142,8 @@ constructor(
            powerInteractor.detailedWakefulness
                .debounce(50L)
                .filterRelevantKeyguardStateAnd { wakefulness -> wakefulness.isAwake() }
                .sampleCombine(
                    communalInteractor.isCommunalAvailable,
                    communalSettingsInteractor.autoOpenEnabled,
                )
                .collect { (detailedWakefulness, isCommunalAvailable, shouldShowCommunal) ->
                .sample(communalInteractor.isCommunalAvailable, ::Pair)
                .collect { (_, isCommunalAvailable) ->
                    val isKeyguardOccludedLegacy = keyguardInteractor.isKeyguardOccluded.value
                    val primaryBouncerShowing = keyguardInteractor.primaryBouncerShowing.value

@@ -178,13 +167,7 @@ constructor(
                        }
                    } else if (isKeyguardOccludedLegacy) {
                        startTransitionTo(KeyguardState.OCCLUDED)
                    } else if (
                        shouldTransitionToCommunal(
                            shouldShowCommunal,
                            isCommunalAvailable,
                            detailedWakefulness,
                        )
                    ) {
                    } else if (shouldTransitionToCommunal(isCommunalAvailable)) {
                        if (!SceneContainerFlag.isEnabled) {
                            transitionToGlanceableHub()
                        }
@@ -209,7 +192,6 @@ constructor(
            powerInteractor.detailedWakefulness
                .filterRelevantKeyguardStateAnd { it.isAwake() }
                .sampleCombine(
                    communalSettingsInteractor.autoOpenEnabled,
                    communalInteractor.isCommunalAvailable,
                    keyguardInteractor.biometricUnlockState,
                    wakeToGoneInteractor.canWakeDirectlyToGone,
@@ -217,8 +199,7 @@ constructor(
                )
                .collect {
                    (
                        detailedWakefulness,
                        shouldShowCommunal,
                        _,
                        isCommunalAvailable,
                        biometricUnlockState,
                        canWakeDirectlyToGone,
@@ -244,13 +225,7 @@ constructor(
                                    ownerReason = "waking from dozing",
                                )
                            }
                        } else if (
                            shouldTransitionToCommunal(
                                shouldShowCommunal,
                                isCommunalAvailable,
                                detailedWakefulness,
                            )
                        ) {
                        } else if (shouldTransitionToCommunal(isCommunalAvailable)) {
                            if (!SceneContainerFlag.isEnabled) {
                                transitionToGlanceableHub()
                            }
+14 −30
Original line number Diff line number Diff line
@@ -108,25 +108,10 @@ constructor(
    @OptIn(FlowPreview::class)
    @SuppressLint("MissingPermission")
    private fun listenForDreamingToGlanceableHubFromPowerButton() {
        if (communalSettingsInteractor.isV2FlagEnabled()) return
        if (!communalSettingsInteractor.isCommunalFlagEnabled()) return
        if (SceneContainerFlag.isEnabled) return
        scope.launch {
            if (communalSettingsInteractor.isV2FlagEnabled()) {
                powerInteractor.isAwake
                    .debounce(50L)
                    .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
                    .sample(communalSettingsInteractor.autoOpenEnabled)
                    .collect { shouldShowCommunal ->
                        if (shouldShowCommunal) {
                            // This case handles tapping the power button to transition through
                            // dream -> off -> hub.
                            communalSceneInteractor.snapToScene(
                                newScene = CommunalScenes.Communal,
                                loggingReason = "from dreaming to hub",
                            )
                        }
                    }
            } else {
            powerInteractor.isAwake
                .debounce(50L)
                .filterRelevantKeyguardStateAnd { isAwake -> isAwake }
@@ -143,7 +128,6 @@ constructor(
                }
        }
    }
    }

    private fun listenForDreamingToPrimaryBouncer() {
        // TODO(b/336576536): Check if adaptation for scene framework is needed