Loading packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModel.kt +17 −4 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn /** Models UI state and handles user input for the shade scene. */ Loading @@ -39,14 +39,22 @@ constructor( ) { /** The key of the scene we should switch to when swiping up. */ val upDestinationSceneKey: StateFlow<SceneKey> = authenticationInteractor.isUnlocked .map { isUnlocked -> upDestinationSceneKey(isUnlocked = isUnlocked) } combine( authenticationInteractor.isUnlocked, authenticationInteractor.canSwipeToDismiss, ) { isUnlocked, canSwipeToDismiss -> upDestinationSceneKey( isUnlocked = isUnlocked, canSwipeToDismiss = canSwipeToDismiss, ) } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = upDestinationSceneKey( isUnlocked = authenticationInteractor.isUnlocked.value, canSwipeToDismiss = authenticationInteractor.canSwipeToDismiss.value, ), ) Loading @@ -57,7 +65,12 @@ constructor( private fun upDestinationSceneKey( isUnlocked: Boolean, canSwipeToDismiss: Boolean, ): SceneKey { return if (isUnlocked) SceneKey.Gone else SceneKey.Lockscreen return when { canSwipeToDismiss -> SceneKey.Lockscreen isUnlocked -> SceneKey.Gone else -> SceneKey.Lockscreen } } } packages/SystemUI/tests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt +47 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.systemui.scene.shared.model.SceneKey import com.android.systemui.scene.shared.model.SceneModel import com.android.systemui.scene.ui.viewmodel.SceneContainerViewModel import com.android.systemui.settings.FakeDisplayTracker import com.android.systemui.shade.ui.viewmodel.ShadeSceneViewModel import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage Loading Loading @@ -120,6 +121,13 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { bouncerInteractor = bouncerInteractor, ) private val shadeSceneViewModel = ShadeSceneViewModel( applicationScope = testScope.backgroundScope, authenticationInteractor = authenticationInteractor, bouncerInteractor = bouncerInteractor, ) private val keyguardRepository = utils.keyguardRepository() private val keyguardInteractor = utils.keyguardInteractor( Loading Loading @@ -196,7 +204,44 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { assertThat(upDestinationSceneKey).isEqualTo(SceneKey.Gone) emulateUserDrivenTransition( to = upDestinationSceneKey, expectedVisible = false, ) } @Test fun swipeUpOnShadeScene_withAuthMethodSwipe_lockscreenNotDismissed_goesToLockscreen() = testScope.runTest { val upDestinationSceneKey by collectLastValue(shadeSceneViewModel.upDestinationSceneKey) setAuthMethod(DomainLayerAuthenticationMethodModel.Swipe) assertCurrentScene(SceneKey.Lockscreen) // Emulate a user swipe to the shade scene. emulateUserDrivenTransition(to = SceneKey.Shade) assertCurrentScene(SceneKey.Shade) assertThat(upDestinationSceneKey).isEqualTo(SceneKey.Lockscreen) emulateUserDrivenTransition( to = upDestinationSceneKey, ) } @Test fun swipeUpOnShadeScene_withAuthMethodSwipe_lockscreenDismissed_goesToGone() = testScope.runTest { val upDestinationSceneKey by collectLastValue(shadeSceneViewModel.upDestinationSceneKey) setAuthMethod(DomainLayerAuthenticationMethodModel.Swipe) assertCurrentScene(SceneKey.Lockscreen) // Emulate a user swipe to dismiss the lockscreen. emulateUserDrivenTransition(to = SceneKey.Gone) assertCurrentScene(SceneKey.Gone) // Emulate a user swipe to the shade scene. emulateUserDrivenTransition(to = SceneKey.Shade) assertCurrentScene(SceneKey.Shade) assertThat(upDestinationSceneKey).isEqualTo(SceneKey.Gone) emulateUserDrivenTransition( to = upDestinationSceneKey, ) } Loading Loading @@ -379,12 +424,9 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { * catching up with the requested scene change (see [emulateUiSceneTransition]). * * @param to The scene to transition to. * @param expectedVisible Whether [SceneContainerViewModel.isVisible] should be set at the end * of the UI transition. */ private fun TestScope.emulateUserDrivenTransition( to: SceneKey?, expectedVisible: Boolean = true, ) { checkNotNull(to) Loading @@ -392,7 +434,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { assertThat(sceneContainerViewModel.currentScene.value.key).isEqualTo(to) emulateUiSceneTransition( expectedVisible = expectedVisible, expectedVisible = to != SceneKey.Gone, ) } Loading packages/SystemUI/tests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModelTest.kt +25 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ class ShadeSceneViewModelTest : SysuiTestCase() { private val authenticationInteractor = utils.authenticationInteractor( repository = utils.authenticationRepository(), sceneInteractor = sceneInteractor, ) private val underTest = Loading Loading @@ -75,6 +76,30 @@ class ShadeSceneViewModelTest : SysuiTestCase() { assertThat(upTransitionSceneKey).isEqualTo(SceneKey.Gone) } @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() = testScope.runTest { val upTransitionSceneKey by collectLastValue(underTest.upDestinationSceneKey) utils.authenticationRepository.setLockscreenEnabled(true) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.None) sceneInteractor.changeScene(SceneModel(SceneKey.Lockscreen), "reason") sceneInteractor.onSceneChanged(SceneModel(SceneKey.Lockscreen), "reason") assertThat(upTransitionSceneKey).isEqualTo(SceneKey.Lockscreen) } @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() = testScope.runTest { val upTransitionSceneKey by collectLastValue(underTest.upDestinationSceneKey) utils.authenticationRepository.setLockscreenEnabled(true) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.None) sceneInteractor.changeScene(SceneModel(SceneKey.Gone), "reason") sceneInteractor.onSceneChanged(SceneModel(SceneKey.Gone), "reason") assertThat(upTransitionSceneKey).isEqualTo(SceneKey.Gone) } @Test fun onContentClicked_deviceUnlocked_switchesToGone() = testScope.runTest { Loading Loading
packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModel.kt +17 −4 Original line number Diff line number Diff line Loading @@ -25,7 +25,7 @@ import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.stateIn /** Models UI state and handles user input for the shade scene. */ Loading @@ -39,14 +39,22 @@ constructor( ) { /** The key of the scene we should switch to when swiping up. */ val upDestinationSceneKey: StateFlow<SceneKey> = authenticationInteractor.isUnlocked .map { isUnlocked -> upDestinationSceneKey(isUnlocked = isUnlocked) } combine( authenticationInteractor.isUnlocked, authenticationInteractor.canSwipeToDismiss, ) { isUnlocked, canSwipeToDismiss -> upDestinationSceneKey( isUnlocked = isUnlocked, canSwipeToDismiss = canSwipeToDismiss, ) } .stateIn( scope = applicationScope, started = SharingStarted.WhileSubscribed(), initialValue = upDestinationSceneKey( isUnlocked = authenticationInteractor.isUnlocked.value, canSwipeToDismiss = authenticationInteractor.canSwipeToDismiss.value, ), ) Loading @@ -57,7 +65,12 @@ constructor( private fun upDestinationSceneKey( isUnlocked: Boolean, canSwipeToDismiss: Boolean, ): SceneKey { return if (isUnlocked) SceneKey.Gone else SceneKey.Lockscreen return when { canSwipeToDismiss -> SceneKey.Lockscreen isUnlocked -> SceneKey.Gone else -> SceneKey.Lockscreen } } }
packages/SystemUI/tests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt +47 −5 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ import com.android.systemui.scene.shared.model.SceneKey import com.android.systemui.scene.shared.model.SceneModel import com.android.systemui.scene.ui.viewmodel.SceneContainerViewModel import com.android.systemui.settings.FakeDisplayTracker import com.android.systemui.shade.ui.viewmodel.ShadeSceneViewModel import com.android.systemui.util.mockito.mock import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage Loading Loading @@ -120,6 +121,13 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { bouncerInteractor = bouncerInteractor, ) private val shadeSceneViewModel = ShadeSceneViewModel( applicationScope = testScope.backgroundScope, authenticationInteractor = authenticationInteractor, bouncerInteractor = bouncerInteractor, ) private val keyguardRepository = utils.keyguardRepository() private val keyguardInteractor = utils.keyguardInteractor( Loading Loading @@ -196,7 +204,44 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { assertThat(upDestinationSceneKey).isEqualTo(SceneKey.Gone) emulateUserDrivenTransition( to = upDestinationSceneKey, expectedVisible = false, ) } @Test fun swipeUpOnShadeScene_withAuthMethodSwipe_lockscreenNotDismissed_goesToLockscreen() = testScope.runTest { val upDestinationSceneKey by collectLastValue(shadeSceneViewModel.upDestinationSceneKey) setAuthMethod(DomainLayerAuthenticationMethodModel.Swipe) assertCurrentScene(SceneKey.Lockscreen) // Emulate a user swipe to the shade scene. emulateUserDrivenTransition(to = SceneKey.Shade) assertCurrentScene(SceneKey.Shade) assertThat(upDestinationSceneKey).isEqualTo(SceneKey.Lockscreen) emulateUserDrivenTransition( to = upDestinationSceneKey, ) } @Test fun swipeUpOnShadeScene_withAuthMethodSwipe_lockscreenDismissed_goesToGone() = testScope.runTest { val upDestinationSceneKey by collectLastValue(shadeSceneViewModel.upDestinationSceneKey) setAuthMethod(DomainLayerAuthenticationMethodModel.Swipe) assertCurrentScene(SceneKey.Lockscreen) // Emulate a user swipe to dismiss the lockscreen. emulateUserDrivenTransition(to = SceneKey.Gone) assertCurrentScene(SceneKey.Gone) // Emulate a user swipe to the shade scene. emulateUserDrivenTransition(to = SceneKey.Shade) assertCurrentScene(SceneKey.Shade) assertThat(upDestinationSceneKey).isEqualTo(SceneKey.Gone) emulateUserDrivenTransition( to = upDestinationSceneKey, ) } Loading Loading @@ -379,12 +424,9 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { * catching up with the requested scene change (see [emulateUiSceneTransition]). * * @param to The scene to transition to. * @param expectedVisible Whether [SceneContainerViewModel.isVisible] should be set at the end * of the UI transition. */ private fun TestScope.emulateUserDrivenTransition( to: SceneKey?, expectedVisible: Boolean = true, ) { checkNotNull(to) Loading @@ -392,7 +434,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { assertThat(sceneContainerViewModel.currentScene.value.key).isEqualTo(to) emulateUiSceneTransition( expectedVisible = expectedVisible, expectedVisible = to != SceneKey.Gone, ) } Loading
packages/SystemUI/tests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModelTest.kt +25 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ class ShadeSceneViewModelTest : SysuiTestCase() { private val authenticationInteractor = utils.authenticationInteractor( repository = utils.authenticationRepository(), sceneInteractor = sceneInteractor, ) private val underTest = Loading Loading @@ -75,6 +76,30 @@ class ShadeSceneViewModelTest : SysuiTestCase() { assertThat(upTransitionSceneKey).isEqualTo(SceneKey.Gone) } @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() = testScope.runTest { val upTransitionSceneKey by collectLastValue(underTest.upDestinationSceneKey) utils.authenticationRepository.setLockscreenEnabled(true) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.None) sceneInteractor.changeScene(SceneModel(SceneKey.Lockscreen), "reason") sceneInteractor.onSceneChanged(SceneModel(SceneKey.Lockscreen), "reason") assertThat(upTransitionSceneKey).isEqualTo(SceneKey.Lockscreen) } @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() = testScope.runTest { val upTransitionSceneKey by collectLastValue(underTest.upDestinationSceneKey) utils.authenticationRepository.setLockscreenEnabled(true) utils.authenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.None) sceneInteractor.changeScene(SceneModel(SceneKey.Gone), "reason") sceneInteractor.onSceneChanged(SceneModel(SceneKey.Gone), "reason") assertThat(upTransitionSceneKey).isEqualTo(SceneKey.Gone) } @Test fun onContentClicked_deviceUnlocked_switchesToGone() = testScope.runTest { Loading