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

Commit b214d151 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

[flexiglass] Immediately locks device when sleep button is pressed.

Bug: 378708150
Test: manually verified that hitting the sleep button (using "adb shell
input keyevent 223") immediately locks the device even if the "lock
after screen timeout" setting is not set to "immediately"
Test: added a unit test
Test: atest
PlatformScenarioTests:android.platform.test.scenario.sysui.notification.LockscreenSilentNotificationVisibility#goToLockscreen_silentShown_showAlertingNotification
-- --abi arm64-v8a
Flag: com.android.systemui.scene_container

Change-Id: Ia7cc37cf65d9f6b720e56baf1ef9ab84d6331875
parent 31986fe9
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -582,6 +582,27 @@ class DeviceUnlockedInteractorTest : SysuiTestCase() {
            assertThat(isUnlocked).isFalse()
        }

    @Test
    fun deviceUnlockStatus_isResetToFalse_whenDeviceGoesToSleep_fromSleepButton() =
        testScope.runTest {
            setLockAfterScreenTimeout(5000)
            kosmos.fakeAuthenticationRepository.powerButtonInstantlyLocks = false
            val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus)

            kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus(
                SuccessFingerprintAuthenticationStatus(0, true)
            )
            runCurrent()
            assertThat(deviceUnlockStatus?.isUnlocked).isTrue()

            kosmos.powerInteractor.setAsleepForTest(
                sleepReason = PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON
            )
            runCurrent()

            assertThat(deviceUnlockStatus?.isUnlocked).isFalse()
        }

    private fun TestScope.unlockDevice() {
        val deviceUnlockStatus by collectLastValue(underTest.deviceUnlockStatus)

+3 −1
Original line number Diff line number Diff line
@@ -233,10 +233,12 @@ constructor(
                    .map { (isAsleep, lastSleepReason) ->
                        if (isAsleep) {
                            if (
                                lastSleepReason == WakeSleepReason.POWER_BUTTON &&
                                (lastSleepReason == WakeSleepReason.POWER_BUTTON) &&
                                    authenticationInteractor.getPowerButtonInstantlyLocks()
                            ) {
                                LockImmediately("locked instantly from power button")
                            } else if (lastSleepReason == WakeSleepReason.SLEEP_BUTTON) {
                                LockImmediately("locked instantly from sleep button")
                            } else {
                                LockWithDelay("entering sleep")
                            }
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ enum class WakeSleepReason(
    /** The physical power button was pressed to wake up or sleep the device. */
    POWER_BUTTON(isTouch = false, PowerManager.WAKE_REASON_POWER_BUTTON),

    /** The sleep button was pressed to sleep the device. */
    SLEEP_BUTTON(isTouch = false, PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON),

    /** The user has tapped or double tapped to wake the screen. */
    TAP(isTouch = true, PowerManager.WAKE_REASON_TAP),

@@ -78,6 +81,7 @@ enum class WakeSleepReason(
        fun fromPowerManagerSleepReason(reason: Int): WakeSleepReason {
            return when (reason) {
                PowerManager.GO_TO_SLEEP_REASON_POWER_BUTTON -> POWER_BUTTON
                PowerManager.GO_TO_SLEEP_REASON_SLEEP_BUTTON -> SLEEP_BUTTON
                PowerManager.GO_TO_SLEEP_REASON_TIMEOUT -> TIMEOUT
                PowerManager.GO_TO_SLEEP_REASON_DEVICE_FOLD -> FOLD
                else -> OTHER