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

Commit 9df88782 authored by Matt Pietal's avatar Matt Pietal
Browse files

Upstream keyguard animation flow optimizations

This divides transition flows into separate MutableSharedFlow
per Edge, and also supports (any)->KeyguardState as well as
KeyguardState->(any). This should greatly reduce the number
of continuations as flows will now only get emits directly
for transitions they care about.

Test: atest SystemUITests && perfetto
Bug: 326719188
Flag: N/A
Change-Id: I37402933cd4a45141686e1521fe78d16d6746786
parent 815b9743
Loading
Loading
Loading
Loading
+64 −62
Original line number Diff line number Diff line
@@ -55,9 +55,10 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
    val testScope = kosmos.testScope

    @Test
    fun transitionCollectorsReceivesOnlyAppropriateEvents() = runTest {
        val lockscreenToAodSteps by collectValues(underTest.lockscreenToAodTransition)
        val aodToLockscreenSteps by collectValues(underTest.aodToLockscreenTransition)
    fun transitionCollectorsReceivesOnlyAppropriateEvents() =
        testScope.runTest {
            val lockscreenToAodSteps by collectValues(underTest.transition(LOCKSCREEN, AOD))
            val aodToLockscreenSteps by collectValues(underTest.transition(AOD, LOCKSCREEN))

            val steps = mutableListOf<TransitionStep>()
            steps.add(TransitionStep(AOD, GONE, 0f, STARTED))
@@ -187,9 +188,9 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
        }

    @Test
    fun finishedKeyguardTransitionStepTests() = runTest {
    fun finishedKeyguardTransitionStepTests() =
        testScope.runTest {
            val finishedSteps by collectValues(underTest.finishedKeyguardTransitionStep)

            val steps = mutableListOf<TransitionStep>()

            steps.add(TransitionStep(LOCKSCREEN, AOD, 0f, STARTED))
@@ -211,7 +212,8 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
        }

    @Test
    fun startedKeyguardTransitionStepTests() = runTest {
    fun startedKeyguardTransitionStepTests() =
        testScope.runTest {
            val startedSteps by collectValues(underTest.startedKeyguardTransitionStep)

            val steps = mutableListOf<TransitionStep>()
+2 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyguard.ui

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.app.animation.Interpolators.EMPHASIZED_ACCELERATE
import com.android.systemui.SysuiTestCase
@@ -35,10 +36,9 @@ import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@SmallTest
@RunWith(JUnit4::class)
@RunWith(AndroidJUnit4::class)
class KeyguardTransitionAnimationFlowTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
+10 −9
Original line number Diff line number Diff line
@@ -641,7 +641,6 @@ class ShadeInteractorImplTest : SysuiTestCase() {
                )
            )
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            runCurrent()
            assertThat(isShadeTouchable).isFalse()
        }

@@ -668,13 +667,17 @@ class ShadeInteractorImplTest : SysuiTestCase() {
                )
            )
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            runCurrent()
            assertThat(isShadeTouchable).isTrue()
        }

    @Test
    fun isShadeTouchable_isFalse_whenStartingToSleepAndNotControlScreenOff() =
        testScope.runTest {
            whenever(dozeParameters.shouldControlScreenOff()).thenReturn(false)
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            // Assert the default condition is true
            assertThat(isShadeTouchable).isTrue()

            powerRepository.updateWakefulness(
                rawState = WakefulnessState.STARTING_TO_SLEEP,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
@@ -688,15 +691,17 @@ class ShadeInteractorImplTest : SysuiTestCase() {
                    transitionState = TransitionState.STARTED,
                )
            )
            whenever(dozeParameters.shouldControlScreenOff()).thenReturn(false)
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            runCurrent()
            assertThat(isShadeTouchable).isFalse()
        }

    @Test
    fun isShadeTouchable_isTrue_whenStartingToSleepAndControlScreenOff() =
        testScope.runTest {
            whenever(dozeParameters.shouldControlScreenOff()).thenReturn(true)
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            // Assert the default condition is true
            assertThat(isShadeTouchable).isTrue()

            powerRepository.updateWakefulness(
                rawState = WakefulnessState.STARTING_TO_SLEEP,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
@@ -710,9 +715,6 @@ class ShadeInteractorImplTest : SysuiTestCase() {
                    transitionState = TransitionState.STARTED,
                )
            )
            whenever(dozeParameters.shouldControlScreenOff()).thenReturn(true)
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            runCurrent()
            assertThat(isShadeTouchable).isTrue()
        }

@@ -730,7 +732,6 @@ class ShadeInteractorImplTest : SysuiTestCase() {
                )
            )
            val isShadeTouchable by collectLastValue(underTest.isShadeTouchable)
            runCurrent()
            assertThat(isShadeTouchable).isTrue()
        }
}
+2 −1
Original line number Diff line number Diff line
@@ -295,7 +295,8 @@ constructor(
    }

    private fun listenForSchedulingWatchdog() {
        keyguardTransitionInteractor.anyStateToGoneTransition
        keyguardTransitionInteractor
            .transition(from = null, to = KeyguardState.GONE)
            .filter { it.transitionState == TransitionState.FINISHED }
            .onEach {
                // We deliberately want to run this in background because scheduleWatchdog does
+2 −1
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dump.DumpManager
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.ui.viewmodel.DreamingToGlanceableHubTransitionViewModel
import com.android.systemui.keyguard.ui.viewmodel.DreamingToLockscreenTransitionViewModel
@@ -97,7 +98,7 @@ constructor(
            .distinctUntilChanged()

    val transitionEnded =
        keyguardTransitionInteractor.fromDreamingTransition.filter { step ->
        keyguardTransitionInteractor.transition(from = DREAMING, to = null).filter { step ->
            step.transitionState == TransitionState.FINISHED ||
                step.transitionState == TransitionState.CANCELED
        }
Loading