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

Commit d6f7c8f2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Prevent user actions from changing to Gone when locked" into main

parents f61612ae 17d99dc2
Loading
Loading
Loading
Loading
+30 −1
Original line number Diff line number Diff line
@@ -25,8 +25,12 @@ import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.DefaultEdgeDetector
import com.android.systemui.SysuiTestCase
import com.android.systemui.classifier.fakeFalsingManager
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.currentValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
@@ -139,7 +143,7 @@ class SceneContainerViewModelTest : SysuiTestCase() {
            assertThat(currentScene).isEqualTo(Scenes.Lockscreen)

            sceneContainerConfig.sceneKeys
                .filter { it != currentScene }
                .filter { it != currentScene && it != Scenes.Gone }
                .forEach { toScene ->
                    assertWithMessage("Scene $toScene incorrectly protected when allowed")
                        .that(underTest.canChangeScene(toScene = toScene))
@@ -208,6 +212,31 @@ class SceneContainerViewModelTest : SysuiTestCase() {
                }
        }

    @Test
    fun canChangeScene_toGone_whenLocked_returnsFalse() =
        kosmos.runTest {
            assertThat(currentValue(deviceUnlockedInteractor.deviceUnlockStatus).isUnlocked)
                .isFalse()
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isNotEqualTo(Scenes.Gone)

            assertThat(underTest.canChangeScene(toScene = Scenes.Gone)).isFalse()
        }

    @Test
    fun canChangeScene_toGone_whenUnlocked_returnsTrue() =
        kosmos.runTest {
            fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            assertThat(currentValue(deviceUnlockedInteractor.deviceUnlockStatus).isUnlocked)
                .isTrue()
            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isNotEqualTo(Scenes.Gone)

            assertThat(underTest.canChangeScene(toScene = Scenes.Gone)).isTrue()
        }

    @Test
    fun canShowOrReplaceOverlay_whenAllowed_showingWhileOnGone_returnsTrue() =
        kosmos.runTest {
+34 −18
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.compose.animation.scene.UserAction
import com.android.compose.animation.scene.UserActionResult
import com.android.systemui.classifier.Classifier
import com.android.systemui.classifier.domain.interactor.FalsingInteractor
import com.android.systemui.deviceentry.domain.interactor.DeviceUnlockedInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.ui.viewmodel.AodBurnInViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel
@@ -63,6 +64,7 @@ class SceneContainerViewModel
@AssistedInject
constructor(
    private val sceneInteractor: SceneInteractor,
    private val deviceUnlockedInteractor: DeviceUnlockedInteractor,
    private val falsingInteractor: FalsingInteractor,
    private val powerInteractor: PowerInteractor,
    private val onBootTransitionInteractor: OnBootTransitionInteractor,
@@ -222,25 +224,39 @@ constructor(
     * it being a false touch.
     */
    fun canChangeScene(toScene: SceneKey): Boolean {
        return isInteractionAllowedByFalsing(toScene).also { sceneChangeAllowed ->
            if (sceneChangeAllowed) {
                // A scene change is guaranteed; log it.
                logger.logSceneChanged(
        if (
            toScene == Scenes.Gone && !deviceUnlockedInteractor.deviceUnlockStatus.value.isUnlocked
        ) {
            logger.logSceneChangeRejection(
                from = currentScene.value,
                to = toScene,
                    sceneState = null,
                    reason = "user interaction",
                    isInstant = false,
                originalChangeReason = null,
                rejectionReason = "Device not unlocked",
            )
            } else {

            return false
        }

        if (!isInteractionAllowedByFalsing(toScene)) {
            logger.logSceneChangeRejection(
                from = currentScene.value,
                to = toScene,
                originalChangeReason = null,
                rejectionReason = "Falsing: false touch detected",
            )

            return false
        }
        }

        // A scene change is guaranteed; log it.
        logger.logSceneChanged(
            from = currentScene.value,
            to = toScene,
            sceneState = null,
            reason = "user interaction",
            isInstant = false,
        )
        return true
    }

    /**
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ package com.android.systemui.scene
import android.view.View
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.systemui.classifier.domain.interactor.falsingInteractor
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.haptics.msdl.msdlPlayer
import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.keyguard.ui.viewmodel.aodBurnInViewModel
@@ -94,6 +95,7 @@ val Kosmos.sceneContainerViewModelFactory by Fixture {
        ): SceneContainerViewModel =
            SceneContainerViewModel(
                sceneInteractor = sceneInteractor,
                deviceUnlockedInteractor = deviceUnlockedInteractor,
                falsingInteractor = falsingInteractor,
                powerInteractor = powerInteractor,
                shadeModeInteractor = shadeModeInteractor,