diff options
| author | 2024-03-14 21:55:34 +0000 | |
|---|---|---|
| committer | 2024-03-14 21:55:34 +0000 | |
| commit | 9ce824ca823e0c9c1718f2d486b6430f4ecbe4cd (patch) | |
| tree | 000be8feaf0edfaa6f9b7753352277c16f7a26e0 | |
| parent | 7ae1ed6d04450e45ce0c4e2ecb1dada08df249e5 (diff) | |
| parent | 7bffb411dff93c6012fad332d182554288c75793 (diff) | |
Merge "Fix keyguard elements showing during dream->hub transition." into main
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 6e15c51e8782..fc604aa5a1d2 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 @@ -348,6 +348,48 @@ class KeyguardRootViewModelTest : SysuiTestCase() {          }      @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 {              val alpha by collectLastValue(underTest.alpha(viewState)) 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<Float> = +    private val isOnLockscreen: Flow<Boolean> =          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<Float> = +        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<BurnInScaleViewModel> =  |