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

Commit 11ff90c0 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin Committed by Ale Nijamkin
Browse files

[flexiglass] Swipe up from shade goes to correct scene.

Fix: 295214677
Test: integration and unit tests added; work was done in TDD fashion,
the tests were added first, then the produciton code to make them pass
Test: manually verified that, with None, we still skip the lockscreen at
all times
Test: manually verified that, with Swipe, swiping up in the shade scene
goes to lockscreen if it needs to be dismissed or to gone if it's
already dismissed
Test: manually verfieid that, with PIN, swiping up in the shade scene
goes to lockscreen if the device is locked or to gone of it's already
unlocked

Change-Id: Ia174a07277fc108031f206b5daaca06a34a1c379
parent 07a2e318
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -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
        }
    }
}
+47 −5
Original line number Diff line number Diff line
@@ -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,
        )
    }

+25 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ class ShadeSceneViewModelTest : SysuiTestCase() {
    private val authenticationInteractor =
        utils.authenticationInteractor(
            repository = utils.authenticationRepository(),
            sceneInteractor = sceneInteractor,
        )

    private val underTest =
@@ -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 {