From 7bffb411dff93c6012fad332d182554288c75793 Mon Sep 17 00:00:00 2001 From: William Xiao Date: Wed, 13 Mar 2024 16:35:04 -0700 Subject: Fix keyguard elements showing during dream->hub transition. There is a bug currently where if the shade is swiped down over the dream, we reset keyguard alpha back to 1 when the shade is closed. This is causing the keyguard to be visible when we transition away from the dream and into the hub. This fix only sets the alpha on the keyguard when opening/closing the shade if the lockscreen is visible. That prevents setting the alpha when in other states, such as dreaming or glanceable hub. Bug: 325102385 Test: atest KeyguardRootViewModelTest Flag: ACONFIG com.android.systemui.communal_hub TEAMFOOD Change-Id: I9c22dde36ab02b6fbb9aaba276639d5f27128e41 --- .../ui/viewmodel/KeyguardRootViewModelTest.kt | 42 ++++++++++++++++++++++ .../keyguard/ui/viewmodel/KeyguardRootViewModel.kt | 36 ++++++++++++++----- 2 files changed, 70 insertions(+), 8 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 979d50463a04..49a4abc0f126 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 @@ -329,6 +329,48 @@ class KeyguardRootViewModelTest : SysuiTestCase() { assertThat(alpha).isEqualTo(0f) } + @Test + fun alpha_shadeClosedOverLockscreen_isOne() = + testScope.runTest { + val alpha by collectLastValue(underTest.alpha(viewState)) + + // Transition to the lockscreen. + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.AOD, + to = KeyguardState.LOCKSCREEN, + testScope, + ) + + // Open the shade. + shadeRepository.setQsExpansion(1f) + assertThat(alpha).isEqualTo(0f) + + // Close the shade, alpha returns to 1. + shadeRepository.setQsExpansion(0f) + assertThat(alpha).isEqualTo(1f) + } + + @Test + fun alpha_shadeClosedOverDream_isZero() = + testScope.runTest { + val alpha by collectLastValue(underTest.alpha(viewState)) + + // Transition to dreaming. + keyguardTransitionRepository.sendTransitionSteps( + from = KeyguardState.LOCKSCREEN, + to = KeyguardState.DREAMING, + testScope, + ) + + // Open the shade. + shadeRepository.setQsExpansion(1f) + assertThat(alpha).isEqualTo(0f) + + // Close the shade, alpha is still 0 since we're not on the lockscreen. + shadeRepository.setQsExpansion(0f) + assertThat(alpha).isEqualTo(0f) + } + @Test fun alpha_idleOnOccluded_isZero() = testScope.runTest { 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 5ca9215ce199..41cc1d620820 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 @@ -56,6 +56,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.combineTransform import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filterNotNull @@ -125,13 +126,36 @@ constructor( .onStart { emit(false) } .distinctUntilChanged() - private val alphaOnShadeExpansion: Flow = + private val isOnLockscreen: Flow = combine( + keyguardTransitionInteractor.isFinishedInState(LOCKSCREEN).onStart { emit(false) }, + keyguardTransitionInteractor + .isInTransitionWhere { from, to -> from == LOCKSCREEN || to == LOCKSCREEN } + .onStart { emit(false) } + ) { onLockscreen, transitioningToOrFromLockscreen -> + onLockscreen || transitioningToOrFromLockscreen + } + .distinctUntilChanged() + + private val alphaOnShadeExpansion: Flow = + combineTransform( + isOnLockscreen, shadeInteractor.qsExpansion, shadeInteractor.shadeExpansion, - ) { qsExpansion, shadeExpansion -> + ) { isOnLockscreen, qsExpansion, shadeExpansion -> // Fade out quickly as the shade expands - 1f - MathUtils.constrainedMap(0f, 1f, 0f, 0.2f, max(qsExpansion, shadeExpansion)) + if (isOnLockscreen) { + val alpha = + 1f - + MathUtils.constrainedMap( + /* rangeMin = */ 0f, + /* rangeMax = */ 1f, + /* valueMin = */ 0f, + /* valueMax = */ 0.2f, + /* value = */ max(qsExpansion, shadeExpansion) + ) + emit(alpha) + } } .distinctUntilChanged() @@ -235,11 +259,7 @@ constructor( burnInJob?.cancel() burnInJob = - scope.launch { - aodBurnInViewModel.movement(params).collect { - burnInModel.value = it - } - } + scope.launch { aodBurnInViewModel.movement(params).collect { burnInModel.value = it } } } val scale: Flow = -- cgit v1.2.3-59-g8ed1b