diff options
2 files changed, 88 insertions, 51 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt index 20ee393e8dac..bd233f80b47b 100644 --- a/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt +++ b/packages/SystemUI/src/com/android/systemui/scene/domain/startable/SceneContainerStartable.kt @@ -18,6 +18,7 @@ package com.android.systemui.scene.domain.startable import com.android.systemui.CoreStartable import com.android.systemui.authentication.domain.interactor.AuthenticationInteractor +import com.android.systemui.authentication.domain.model.AuthenticationMethodModel import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.DisplayId @@ -135,22 +136,27 @@ constructor( applicationScope.launch { keyguardInteractor.wakefulnessModel - .map { it.state == WakefulnessState.ASLEEP } + .map { wakefulnessModel -> wakefulnessModel.state } .distinctUntilChanged() - .collect { isAsleep -> - if (isAsleep) { - // When the device goes to sleep, reset the current scene. - val isUnlocked = authenticationInteractor.isUnlocked.value - val (targetSceneKey, loggingReason) = - if (isUnlocked) { - SceneKey.Gone to "device is asleep while unlocked" - } else { - SceneKey.Lockscreen to "device is asleep while locked" + .collect { wakefulnessState -> + when (wakefulnessState) { + WakefulnessState.STARTING_TO_SLEEP -> { + switchToScene( + targetSceneKey = SceneKey.Lockscreen, + loggingReason = "device is asleep", + ) + } + WakefulnessState.STARTING_TO_WAKE -> { + val authMethod = authenticationInteractor.getAuthenticationMethod() + if (authMethod == AuthenticationMethodModel.None) { + switchToScene( + targetSceneKey = SceneKey.Gone, + loggingReason = + "device is starting to wake up while auth method is None", + ) } - switchToScene( - targetSceneKey = targetSceneKey, - loggingReason = loggingReason, - ) + } + else -> Unit } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt index 6be19b99dd3b..bec0b77e6480 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/startable/SceneContainerStartableTest.kt @@ -21,6 +21,7 @@ package com.android.systemui.scene.domain.startable import android.view.Display import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase +import com.android.systemui.authentication.data.model.AuthenticationMethodModel import com.android.systemui.coroutines.collectLastValue import com.android.systemui.flags.Flags import com.android.systemui.keyguard.shared.model.WakeSleepReason @@ -245,93 +246,110 @@ class SceneContainerStartableTest : SysuiTestCase() { } @Test - fun switchToGoneWhenDeviceSleepsUnlocked_featureEnabled() = + fun switchToLockscreenWhenDeviceSleepsLocked_featureEnabled() = testScope.runTest { val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key }) prepareState( isFeatureEnabled = true, - isDeviceUnlocked = true, + isDeviceUnlocked = false, initialSceneKey = SceneKey.Shade, ) assertThat(currentSceneKey).isEqualTo(SceneKey.Shade) underTest.start() - keyguardRepository.setWakefulnessModel(ASLEEP) + keyguardRepository.setWakefulnessModel(STARTING_TO_SLEEP) - assertThat(currentSceneKey).isEqualTo(SceneKey.Gone) + assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) } @Test - fun switchToGoneWhenDeviceSleepsUnlocked_featureDisabled() = + fun switchToLockscreenWhenDeviceSleepsLocked_featureDisabled() = testScope.runTest { val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key }) prepareState( isFeatureEnabled = false, - isDeviceUnlocked = true, + isDeviceUnlocked = false, initialSceneKey = SceneKey.Shade, ) assertThat(currentSceneKey).isEqualTo(SceneKey.Shade) underTest.start() - keyguardRepository.setWakefulnessModel(ASLEEP) + keyguardRepository.setWakefulnessModel(STARTING_TO_SLEEP) assertThat(currentSceneKey).isEqualTo(SceneKey.Shade) } @Test - fun switchToLockscreenWhenDeviceSleepsLocked_featureEnabled() = + fun hydrateSystemUiState() = + testScope.runTest { + underTest.start() + runCurrent() + clearInvocations(sysUiState) + + listOf( + SceneKey.Gone, + SceneKey.Lockscreen, + SceneKey.Bouncer, + SceneKey.Shade, + SceneKey.QuickSettings, + ) + .forEachIndexed { index, sceneKey -> + sceneInteractor.setCurrentScene(SceneModel(sceneKey), "reason") + runCurrent() + + verify(sysUiState, times(index + 1)).commitUpdate(Display.DEFAULT_DISPLAY) + } + } + + @Test + fun switchToGoneWhenDeviceStartsToWakeUp_authMethodNone_featureEnabled() = testScope.runTest { val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key }) prepareState( isFeatureEnabled = true, - isDeviceUnlocked = false, - initialSceneKey = SceneKey.Shade, + initialSceneKey = SceneKey.Lockscreen, + authenticationMethod = AuthenticationMethodModel.None, ) - assertThat(currentSceneKey).isEqualTo(SceneKey.Shade) + assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) underTest.start() - keyguardRepository.setWakefulnessModel(ASLEEP) + keyguardRepository.setWakefulnessModel(STARTING_TO_WAKE) - assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) + assertThat(currentSceneKey).isEqualTo(SceneKey.Gone) } @Test - fun switchToLockscreenWhenDeviceSleepsLocked_featureDisabled() = + fun switchToGoneWhenDeviceStartsToWakeUp_authMethodNotNone_featureEnabled() = testScope.runTest { val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key }) prepareState( - isFeatureEnabled = false, - isDeviceUnlocked = false, - initialSceneKey = SceneKey.Shade, + isFeatureEnabled = true, + initialSceneKey = SceneKey.Lockscreen, + authenticationMethod = AuthenticationMethodModel.Pin, ) - assertThat(currentSceneKey).isEqualTo(SceneKey.Shade) + assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) underTest.start() - keyguardRepository.setWakefulnessModel(ASLEEP) + keyguardRepository.setWakefulnessModel(STARTING_TO_WAKE) - assertThat(currentSceneKey).isEqualTo(SceneKey.Shade) + assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) } @Test - fun hydrateSystemUiState() = + fun switchToGoneWhenDeviceStartsToWakeUp_authMethodNone_featureDisabled() = testScope.runTest { + val currentSceneKey by collectLastValue(sceneInteractor.currentScene.map { it.key }) + prepareState( + isFeatureEnabled = false, + initialSceneKey = SceneKey.Lockscreen, + authenticationMethod = AuthenticationMethodModel.None, + ) + assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) underTest.start() - runCurrent() - clearInvocations(sysUiState) - listOf( - SceneKey.Gone, - SceneKey.Lockscreen, - SceneKey.Bouncer, - SceneKey.Shade, - SceneKey.QuickSettings, - ) - .forEachIndexed { index, sceneKey -> - sceneInteractor.setCurrentScene(SceneModel(sceneKey), "reason") - runCurrent() + keyguardRepository.setWakefulnessModel(STARTING_TO_WAKE) - verify(sysUiState, times(index + 1)).commitUpdate(Display.DEFAULT_DISPLAY) - } + assertThat(currentSceneKey).isEqualTo(SceneKey.Lockscreen) } private fun prepareState( @@ -339,17 +357,30 @@ class SceneContainerStartableTest : SysuiTestCase() { isDeviceUnlocked: Boolean = false, isBypassEnabled: Boolean = false, initialSceneKey: SceneKey? = null, + authenticationMethod: AuthenticationMethodModel? = null, ) { featureFlags.set(Flags.SCENE_CONTAINER, isFeatureEnabled) authenticationRepository.setUnlocked(isDeviceUnlocked) keyguardRepository.setBypassEnabled(isBypassEnabled) initialSceneKey?.let { sceneInteractor.setCurrentScene(SceneModel(it), "reason") } + authenticationMethod?.let { + authenticationRepository.setAuthenticationMethod(authenticationMethod) + authenticationRepository.setLockscreenEnabled( + authenticationMethod != AuthenticationMethodModel.None + ) + } } companion object { - private val ASLEEP = + private val STARTING_TO_SLEEP = + WakefulnessModel( + state = WakefulnessState.STARTING_TO_SLEEP, + lastWakeReason = WakeSleepReason.POWER_BUTTON, + lastSleepReason = WakeSleepReason.POWER_BUTTON + ) + private val STARTING_TO_WAKE = WakefulnessModel( - state = WakefulnessState.ASLEEP, + state = WakefulnessState.STARTING_TO_WAKE, lastWakeReason = WakeSleepReason.POWER_BUTTON, lastSleepReason = WakeSleepReason.POWER_BUTTON ) |