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

Commit a575bf96 authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Ensure lockscreen alpha of 0f on fast swipes to bouncer" into main

parents 746eee68 32f283e5
Loading
Loading
Loading
Loading
+50 −0
Original line number Diff line number Diff line
@@ -456,6 +456,56 @@ class KeyguardRootViewModelTest(flags: FlagsParameterization) : SysuiTestCase()
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    fun alpha_shadeExpansionIgnoredWhenTransitioningAwayFromLockscreen() =
        testScope.runTest {
            val alpha by collectLastValue(underTest.alpha(viewState))

            keyguardTransitionRepository.sendTransitionSteps(
                from = KeyguardState.AOD,
                to = KeyguardState.LOCKSCREEN,
                testScope,
            )

            shadeTestUtil.setQsExpansion(0f)
            assertThat(alpha).isEqualTo(1f)

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
                    TransitionStep(
                        from = KeyguardState.LOCKSCREEN,
                        to = KeyguardState.PRIMARY_BOUNCER,
                        transitionState = TransitionState.STARTED,
                        value = 0f,
                    ),
                    TransitionStep(
                        from = KeyguardState.LOCKSCREEN,
                        to = KeyguardState.PRIMARY_BOUNCER,
                        transitionState = TransitionState.RUNNING,
                        value = 0.8f,
                    ),
                ),
                testScope,
            )
            val priorAlpha = alpha
            shadeTestUtil.setQsExpansion(0.5f)
            assertThat(alpha).isEqualTo(priorAlpha)

            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
                    TransitionStep(
                        from = KeyguardState.LOCKSCREEN,
                        to = KeyguardState.PRIMARY_BOUNCER,
                        transitionState = TransitionState.FINISHED,
                        value = 1f,
                    )
                ),
                testScope,
            )
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    fun alphaFromShadeExpansion_doesNotEmitWhenTransitionRunning() =
+23 −16
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.flags.BrokenWithSceneContainer
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.Flags
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.flags.fakeFeatureFlagsClassic
@@ -44,7 +45,7 @@ import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.testKosmos
import com.google.common.collect.Range
import com.google.common.truth.Truth
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.test.runCurrent
@@ -101,20 +102,30 @@ class LockscreenToPrimaryBouncerTransitionViewModelTest(flags: FlagsParameteriza

            // immediately 0f
            repository.sendTransitionStep(step(0f, TransitionState.STARTED))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(0f)
            assertThat(actual).isEqualTo(0f)

            repository.sendTransitionStep(step(.2f))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(0f)
            assertThat(actual).isEqualTo(0f)

            repository.sendTransitionStep(step(0.8f))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(0f)
            assertThat(actual).isEqualTo(0f)

            repository.sendTransitionStep(step(1f, TransitionState.FINISHED))
            assertThat(actual).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    fun lockscreenAlphaEndsWithZero() =
        testScope.runTest {
            val alpha by collectLastValue(underTest.lockscreenAlpha)

            repository.sendTransitionStep(step(0f, TransitionState.STARTED))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(0f)

            // Jump right to the end and validate the value
            repository.sendTransitionStep(step(1f, TransitionState.FINISHED))
            assertThat(alpha).isEqualTo(0f)
        }

    @Test
@@ -138,21 +149,17 @@ class LockscreenToPrimaryBouncerTransitionViewModelTest(flags: FlagsParameteriza
            runCurrent()
            // fade out
            repository.sendTransitionStep(step(0f, TransitionState.STARTED))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(1f)
            assertThat(actual).isEqualTo(1f)

            repository.sendTransitionStep(step(.1f))
            runCurrent()
            Truth.assertThat(actual).isIn(Range.open(.1f, .9f))
            assertThat(actual).isIn(Range.open(.1f, .9f))

            // alpha is 1f before the full transition starts ending
            repository.sendTransitionStep(step(0.8f))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(0f)
            assertThat(actual).isEqualTo(0f)

            repository.sendTransitionStep(step(1f, TransitionState.FINISHED))
            runCurrent()
            Truth.assertThat(actual).isEqualTo(0f)
            assertThat(actual).isEqualTo(0f)
        }

    @Test
+11 −29
Original line number Diff line number Diff line
@@ -31,10 +31,8 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInterac
import com.android.systemui.keyguard.domain.interactor.PulseExpansionInteractor
import com.android.systemui.keyguard.shared.model.Edge
import com.android.systemui.keyguard.shared.model.KeyguardState.AOD
import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.LOCKSCREEN
import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
import com.android.systemui.keyguard.shared.model.KeyguardState.OFF
import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
import com.android.systemui.keyguard.shared.model.TransitionState.RUNNING
@@ -165,43 +163,27 @@ constructor(
            .onStart { emit(false) }
            .distinctUntilChanged()

    private val isOnLockscreen: Flow<Boolean> =
    private val isOnOrGoingToLockscreen: Flow<Boolean> =
        combine(
                keyguardTransitionInteractor.isFinishedIn(LOCKSCREEN).onStart { emit(false) },
                anyOf(
                keyguardTransitionInteractor.transitionValue(LOCKSCREEN).map { it == 1f },
                keyguardTransitionInteractor.isInTransition(Edge.create(to = LOCKSCREEN)),
                    keyguardTransitionInteractor.isInTransition(Edge.create(from = LOCKSCREEN)),
                ),
            ) { onLockscreen, transitioningToOrFromLockscreen ->
                onLockscreen || transitioningToOrFromLockscreen
            ) { onLockscreen, transitioningToLockscreen ->
                onLockscreen || transitioningToLockscreen
            }
            .distinctUntilChanged()

    private val alphaOnShadeExpansion: Flow<Float> =
        combineTransform(
                anyOf(
                    keyguardTransitionInteractor.isInTransition(
                        edge = Edge.create(from = LOCKSCREEN, to = Scenes.Gone),
                        edgeWithoutSceneContainer = Edge.create(from = LOCKSCREEN, to = GONE),
                    ),
                keyguardTransitionInteractor.isInTransition(
                    edge = Edge.create(from = Overlays.Bouncer, to = LOCKSCREEN),
                        edgeWithoutSceneContainer =
                            Edge.create(from = PRIMARY_BOUNCER, to = LOCKSCREEN),
                    ),
                    keyguardTransitionInteractor.isInTransition(
                        Edge.create(from = LOCKSCREEN, to = DREAMING)
                    ),
                    keyguardTransitionInteractor.isInTransition(
                        Edge.create(from = LOCKSCREEN, to = OCCLUDED)
                    ),
                    edgeWithoutSceneContainer = Edge.create(from = PRIMARY_BOUNCER, to = LOCKSCREEN),
                ),
                isOnLockscreen,
                isOnOrGoingToLockscreen,
                shadeInteractor.qsExpansion,
                shadeInteractor.shadeExpansion,
            ) { disabledTransitionRunning, isOnLockscreen, qsExpansion, shadeExpansion ->
            ) { disabledTransitionRunning, isOnOrGoingToLockscreen, qsExpansion, shadeExpansion ->
                // Fade out quickly as the shade expands
                if (isOnLockscreen && !disabledTransitionRunning) {
                if (isOnOrGoingToLockscreen && !disabledTransitionRunning) {
                    val alpha =
                        1f -
                            MathUtils.constrainedMap(
+3 −0
Original line number Diff line number Diff line
@@ -66,6 +66,9 @@ constructor(
        transitionAnimation.sharedFlow(
            duration = FromLockscreenTransitionInteractor.TO_PRIMARY_BOUNCER_DURATION,
            onStep = alphaForAnimationStep,
            // Rapid swipes to bouncer, and may end up skipping intermediate values that would've
            // caused a complete fade out of lockscreen elements. Ensure it goes to 0f.
            onFinish = { 0f },
        )

    val lockscreenAlpha: Flow<Float> = shortcutsAlpha