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

Commit f6643f6b authored by burakov's avatar burakov Committed by Danny Burakov
Browse files

[flexiglass] Ensure Flexiglass touch events keep the device awake.

Fix: 295535216
Test: Added unit tests.
Test: Manually tested on device by dragging down the shade on the
      lockscreen for more than 10 seconds without the screen dimming.
Change-Id: Ifc1eadc4f6bcc962a0fcc57cd31724104275c96b
parent 8792597c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.motionEventSpy
import com.android.compose.animation.scene.Back
import com.android.compose.animation.scene.ObservableTransitionState as SceneTransitionObservableTransitionState
import com.android.compose.animation.scene.SceneKey as SceneTransitionSceneKey
@@ -56,6 +58,7 @@ import kotlinx.coroutines.flow.map
 *   must have entries in this map.
 * @param modifier A modifier.
 */
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun SceneContainer(
    viewModel: SceneContainerViewModel,
@@ -79,7 +82,7 @@ fun SceneContainer(
        onChangeScene = viewModel::onSceneChanged,
        transitions = SceneContainerTransitions,
        state = state,
        modifier = modifier.fillMaxSize(),
        modifier = modifier.fillMaxSize().motionEventSpy { viewModel.onUserInput() },
    ) {
        sceneByKey.forEach { (sceneKey, composableScene) ->
            scene(
+11 −0
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ interface PowerRepository {

    /** Wakes up the device. */
    fun wakeUp(why: String, @PowerManager.WakeReason wakeReason: Int)

    /** Notifies the power repository that a user touch happened. */
    fun userTouch()
}

@SysUISingleton
@@ -83,6 +86,14 @@ constructor(
        )
    }

    override fun userTouch() {
        manager.userActivity(
            systemClock.uptimeMillis(),
            PowerManager.USER_ACTIVITY_EVENT_TOUCH,
            /* flags= */ 0,
        )
    }

    companion object {
        private const val TAG = "PowerRepository"
    }
+7 −0
Original line number Diff line number Diff line
@@ -18,6 +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.scene.data.repository.SceneContainerRepository
import com.android.systemui.scene.shared.logger.SceneLogger
import com.android.systemui.scene.shared.model.ObservableTransitionState
@@ -44,6 +45,7 @@ class SceneInteractor
constructor(
    @Application applicationScope: CoroutineScope,
    private val repository: SceneContainerRepository,
    private val powerRepository: PowerRepository,
    private val logger: SceneLogger,
) {

@@ -153,6 +155,11 @@ constructor(
        repository.setTransitionState(transitionState)
    }

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

    /**
     * Notifies that the UI has transitioned sufficiently to the given scene.
     *
+5 −0
Original line number Diff line number Diff line
@@ -63,6 +63,11 @@ constructor(
        interactor.setTransitionState(transitionState)
    }

    /** Handles an event representing user input. */
    fun onUserInput() {
        interactor.onUserInput()
    }

    companion object {
        private const val SCENE_TRANSITION_LOGGING_REASON = "user input"
    }
+17 −0
Original line number Diff line number Diff line
@@ -193,6 +193,23 @@ class PowerRepositoryImplTest : SysuiTestCase() {
        assertThat(reasonCaptor.value).contains(context.applicationContext.packageName)
    }

    @Test
    fun userActivity_notifiesPowerManager() {
        systemClock.setUptimeMillis(345000)

        underTest.userTouch()

        val flagsCaptor = argumentCaptor<Int>()
        verify(manager)
            .userActivity(
                eq(345000L),
                eq(PowerManager.USER_ACTIVITY_EVENT_TOUCH),
                capture(flagsCaptor)
            )
        assertThat(flagsCaptor.value).isNotEqualTo(PowerManager.USER_ACTIVITY_FLAG_NO_CHANGE_LIGHTS)
        assertThat(flagsCaptor.value).isNotEqualTo(PowerManager.USER_ACTIVITY_FLAG_INDIRECT)
    }

    private fun verifyRegistered() {
        // We must verify with all arguments, even those that are optional because they have default
        // values because Mockito is forcing us to. Once we can use mockito-kotlin, we should be
Loading