diff options
3 files changed, 89 insertions, 9 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModel.kt b/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModel.kt index 87abc9208d45..8edc26d01d71 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModel.kt @@ -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. */ @@ -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, ), ) @@ -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 + } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt index 8caf6dc3e28a..53c04ccbdb38 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/scene/SceneFrameworkIntegrationTest.kt @@ -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 @@ -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( @@ -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, ) } @@ -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) @@ -392,7 +434,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() { assertThat(sceneContainerViewModel.currentScene.value.key).isEqualTo(to) emulateUiSceneTransition( - expectedVisible = expectedVisible, + expectedVisible = to != SceneKey.Gone, ) } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModelTest.kt index 7443097a2628..69b952542c29 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneViewModelTest.kt @@ -42,6 +42,7 @@ class ShadeSceneViewModelTest : SysuiTestCase() { private val authenticationInteractor = utils.authenticationInteractor( repository = utils.authenticationRepository(), + sceneInteractor = sceneInteractor, ) private val underTest = @@ -76,6 +77,30 @@ class ShadeSceneViewModelTest : SysuiTestCase() { } @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 { val currentScene by collectLastValue(sceneInteractor.desiredScene) |