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

Commit 9ce824ca authored by William Xiao's avatar William Xiao Committed by Android (Google) Code Review
Browse files

Merge "Fix keyguard elements showing during dream->hub transition." into main

parents 7ae1ed6d 7bffb411
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -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 {
+28 −8
Original line number Diff line number Diff line
@@ -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> =