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

Commit ac8b3d3f authored by burakov's avatar burakov
Browse files

[flexiglass] Don't dim screen or go to sleep while typing a password.

Fix: 306518856
Test: Manually verified by typing a long password, waiting ~4 seconds
 after each character typed, and observing that the screen is not
 dimmed. The same verification was done for PIN bouncer as well.
Test: Added new unit tests.
Test: Existing unit tests still pass.
Flag: ACONFIG com.android.systemui.scene_container DEVELOPMENT
Change-Id: Icabae81246217741a9fc4e5b409c4c6c55f49eff
parent f5adf3e9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -66,7 +66,7 @@ internal fun PasswordBouncer(
    LaunchedEffect(Unit) {
        // When the UI comes up, request focus on the TextField to bring up the software keyboard.
        focusRequester.requestFocus()
        // Also, report that the UI is shown to let the view-model runs some logic.
        // Also, report that the UI is shown to let the view-model run some logic.
        viewModel.onShown()
    }

+3 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.classifier.FalsingClassifier
import com.android.systemui.classifier.domain.interactor.FalsingInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.res.R
import com.android.systemui.scene.shared.flag.SceneContainerFlags
import com.android.systemui.util.kotlin.pairwise
@@ -52,6 +53,7 @@ constructor(
    private val authenticationInteractor: AuthenticationInteractor,
    flags: SceneContainerFlags,
    private val falsingInteractor: FalsingInteractor,
    private val powerInteractor: PowerInteractor,
) {

    /** The user-facing message to show in the bouncer. */
@@ -124,6 +126,7 @@ constructor(
     * user's pocket or by the user's face while holding their device up to their ear.
     */
    fun onIntentionalUserInput() {
        powerInteractor.onUserTouch()
        falsingInteractor.updateFalseConfidence(FalsingClassifier.Result.passed(0.6))
    }

+32 −25
Original line number Diff line number Diff line
@@ -27,10 +27,10 @@ import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.statusbar.phone.ScreenOffAnimationController
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import javax.inject.Inject

/** Hosts business logic for interacting with the power system. */
@SysUISingleton
@@ -59,17 +59,27 @@ constructor(
     * Whether we're awake (screen is on and responding to user touch) or asleep (screen is off, or
     * on AOD).
     */
    val isAwake = repository.wakefulness
    val isAwake =
        repository.wakefulness
            .map { it.isAwake() }
            .distinctUntilChanged(checkEquivalentUnlessEmitDuplicatesUnderTest)

    /**
     * Helper flow in case "isAsleep" reads better than "!isAwake".
     */
    /** Helper flow in case "isAsleep" reads better than "!isAwake". */
    val isAsleep = isAwake.map { !it }

    val screenPowerState = repository.screenPowerState

    /**
     * Notifies the power interactor that a user touch happened.
     *
     * @param noChangeLights If true, does not cause the keyboard backlight to turn on because of
     *   this event. This is set when the power key is pressed. We want the device to stay on while
     *   the button is down, but we're about to turn off the screen so we don't want the keyboard
     *   backlight to turn on again. Otherwise the lights flash on and then off and it looks weird.
     */
    fun onUserTouch(noChangeLights: Boolean = false) =
        repository.userTouch(noChangeLights = noChangeLights)

    /**
     * Wakes up the device if the device was dozing.
     *
@@ -92,9 +102,7 @@ constructor(
     */
    fun wakeUpForFullScreenIntent() {
        if (repository.wakefulness.value.isAsleep() || statusBarStateController.isDozing) {
            repository.wakeUp(
                    why = FSI_WAKE_WHY,
                    wakeReason = PowerManager.WAKE_REASON_APPLICATION)
            repository.wakeUp(why = FSI_WAKE_WHY, wakeReason = PowerManager.WAKE_REASON_APPLICATION)
        }
    }

@@ -258,8 +266,7 @@ constructor(
         */
        @JvmOverloads
        fun PowerInteractor.setAsleepForTest(
                @PowerManager.GoToSleepReason sleepReason: Int =
                        PowerManager.GO_TO_SLEEP_REASON_MIN,
            @PowerManager.GoToSleepReason sleepReason: Int = PowerManager.GO_TO_SLEEP_REASON_MIN,
            forceEmit: Boolean = false,
        ) {
            emitDuplicateWakefulnessValue = forceEmit
+3 −3
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.systemui.scene.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.power.data.repository.PowerRepository
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.scene.data.repository.SceneContainerRepository
import com.android.systemui.scene.shared.logger.SceneLogger
import com.android.systemui.scene.shared.model.ObservableTransitionState
@@ -48,7 +48,7 @@ class SceneInteractor
constructor(
    @Application private val applicationScope: CoroutineScope,
    private val repository: SceneContainerRepository,
    private val powerRepository: PowerRepository,
    private val powerInteractor: PowerInteractor,
    private val logger: SceneLogger,
) {

@@ -202,7 +202,7 @@ constructor(

    /** Handles a user input event. */
    fun onUserInput() {
        powerRepository.userTouch()
        powerInteractor.onUserTouch()
    }

    /**
+8 −0
Original line number Diff line number Diff line
@@ -291,6 +291,14 @@ class BouncerInteractorTest : SysuiTestCase() {
            assertThat(imeHiddenEvent).isNotNull()
        }

    @Test
    fun intentionalUserInputEvent_registersTouchEvent() =
        testScope.runTest {
            assertThat(utils.powerRepository.userTouchRegistered).isFalse()
            underTest.onIntentionalUserInput()
            assertThat(utils.powerRepository.userTouchRegistered).isTrue()
        }

    private fun assertTryAgainMessage(
        message: String?,
        time: Int,
Loading