Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt +42 −0 Original line number Diff line number Diff line Loading @@ -347,6 +347,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 { Loading packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt +28 −8 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading Loading @@ -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> = Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModelTest.kt +42 −0 Original line number Diff line number Diff line Loading @@ -347,6 +347,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 { Loading
packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardRootViewModel.kt +28 −8 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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() Loading Loading @@ -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> = Loading