diff options
| author | 2025-03-10 09:12:26 -0700 | |
|---|---|---|
| committer | 2025-03-10 09:12:26 -0700 | |
| commit | a575bf96e38b7fa54f8814a0ffa42330ce53caa5 (patch) | |
| tree | 53ffb6b1dbbaae514dad328a025eee5d5799f50f | |
| parent | 746eee689fc07c5dfa5905eae05c11a79cac6c09 (diff) | |
| parent | 32f283e529d8a98de69789d64ec1d5bbd250c51a (diff) | |
Merge "Ensure lockscreen alpha of 0f on fast swipes to bouncer" into main
4 files changed, 87 insertions, 45 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt index 83bee7c66d31..fe213a6ebbf0 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt @@ -458,6 +458,56 @@ class KeyguardRootViewModelTest(flags: FlagsParameterization) : SysuiTestCase() @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() = testScope.runTest { keyguardTransitionRepository.sendTransitionSteps( diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModelTest.kt index 91cb1ff266c9..9c168298b9a5 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModelTest.kt @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt index 6d8a943d3e28..830afeac7b96 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt @@ -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.isInTransition(Edge.create(to = LOCKSCREEN)), - keyguardTransitionInteractor.isInTransition(Edge.create(from = LOCKSCREEN)), - ), - ) { onLockscreen, transitioningToOrFromLockscreen -> - onLockscreen || transitioningToOrFromLockscreen + keyguardTransitionInteractor.transitionValue(LOCKSCREEN).map { it == 1f }, + keyguardTransitionInteractor.isInTransition(Edge.create(to = LOCKSCREEN)), + ) { 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) - ), + keyguardTransitionInteractor.isInTransition( + edge = Edge.create(from = Overlays.Bouncer, to = LOCKSCREEN), + 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( diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt index 3758afa61ed4..9312bca04994 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/LockscreenToPrimaryBouncerTransitionViewModel.kt @@ -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 |