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

Commit c2090f44 authored by William Xiao's avatar William Xiao
Browse files

Fix transition when pressing power button from hub gesture

This CL makes the hub snap immediately to blank when the devices goes
to sleep. For a single power press, this happens after the screen is
off so there's no visual issue. With a double power press that's slow
enough to not trigger camera, the device ends up on the lock screen as
expected.

Prior to this change, the KTF transition wouldn't finish until the hub
STL became idle, leaving the device in DOZING but with messed up UI.

Bug: 431931326
Fixed: 431931326
Test: atest KeyguardTransitionScenariosTest
      manually verified on device, see bug for video
Flag: com.android.systemui.communal_power_transition_fix
Change-Id: I3c7e116bf1a9efc8309893492cf162fc3e4a6e1f
parent 1e3e76ae
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1196,6 +1196,16 @@ flag {
  }
}

flag {
  name: "communal_power_transition_fix"
  namespace: "systemui"
  description: "Flags a minor bug fix for pressing power button on the hub"
  bug: "431931326"
  metadata {
    purpose: PURPOSE_BUGFIX
  }
}

flag {
  name: "dream_transition_fixes"
  namespace: "systemui"
+18 −3
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@ import com.android.systemui.Flags.FLAG_GLANCEABLE_HUB_V2
import com.android.systemui.Flags.glanceableHubV2
import com.android.systemui.SysuiTestCase
import com.android.systemui.bouncer.data.repository.fakeKeyguardBouncerRepository
import com.android.systemui.communal.data.repository.communalSceneRepository
import com.android.systemui.communal.data.repository.fakeCommunalSceneRepositorySpy
import com.android.systemui.communal.domain.interactor.CommunalSceneTransitionInteractor
import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSceneTransitionInteractor
@@ -54,6 +56,8 @@ import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.keyguard.util.KeyguardTransitionRepositorySpySubject.Companion.assertThat
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
@@ -77,7 +81,11 @@ import org.mockito.ArgumentMatchers.anyInt
import org.mockito.Mock
import org.mockito.Mockito.clearInvocations
import org.mockito.Mockito.reset
import org.mockito.Mockito.verify
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.eq
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@@ -91,6 +99,7 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
    private val kosmos =
        testKosmos().apply {
            this.keyguardTransitionRepository = fakeKeyguardTransitionRepositorySpy
            this.communalSceneRepository = fakeCommunalSceneRepositorySpy
        }
    private val testScope = kosmos.testScope

@@ -1448,7 +1457,7 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
    @Test
    @DisableSceneContainer
    fun glanceableHubToDozing_communalKtfRefactor() =
        testScope.runTest {
        kosmos.runTest {
            // GIVEN a prior transition has run to GLANCEABLE_HUB
            communalSceneInteractor.changeScene(CommunalScenes.Communal, "test")
            runCurrent()
@@ -1465,8 +1474,14 @@ class KeyguardTransitionScenariosTest(flags: FlagsParameterization?) : SysuiTest
                    to = KeyguardState.DOZING,
                    animatorAssertion = { it.isNull() },
                )
            if (Flags.communalPowerTransitionFix()) {
                verify(communalSceneRepository)
                    .instantlyTransitionTo(eq(CommunalScenes.Blank), any())
            } else {
                verify(communalSceneRepository).changeScene(eq(CommunalScenes.Blank), anyOrNull())
            }

            coroutineContext.cancelChildren()
            testScope.coroutineContext.cancelChildren()
        }

    @Test
+16 −5
Original line number Diff line number Diff line
@@ -127,6 +127,16 @@ constructor(
            powerInteractor.isAsleep
                .filterRelevantKeyguardStateAnd { isAsleep -> isAsleep }
                .collect {
                    if (Flags.communalPowerTransitionFix()) {
                        // Snap to blank immediately when asleep so that KTF can transition
                        // correctly if the power button is pressed quickly in succession, ex.
                        // pressing twice should end up on lock screen.
                        communalSceneInteractor.snapToScene(
                            newScene = CommunalScenes.Blank,
                            loggingReason = "hub to sleep",
                            keyguardState = keyguardInteractor.asleepKeyguardState.value,
                        )
                    } else {
                        communalSceneInteractor.changeScene(
                            newScene = CommunalScenes.Blank,
                            loggingReason = "hub to sleep",
@@ -135,6 +145,7 @@ constructor(
                    }
                }
        }
    }

    private fun listenForHubToDreaming() {
        if (!communalSettingsInteractor.isV2FlagEnabled()) {
+3 −1
Original line number Diff line number Diff line
@@ -19,10 +19,12 @@ package com.android.systemui.communal.data.repository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.applicationCoroutineScope
import org.mockito.kotlin.spy

var Kosmos.fakeCommunalSceneRepository by Fixture {
    FakeCommunalSceneRepository(applicationScope = applicationCoroutineScope)
}
var Kosmos.fakeCommunalSceneRepositorySpy by Fixture { spy(fakeCommunalSceneRepository) }

val Kosmos.communalSceneRepository by
var Kosmos.communalSceneRepository by
    Fixture<CommunalSceneRepository> { fakeCommunalSceneRepository }