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

Commit 7bffb411 authored by William Xiao's avatar William Xiao
Browse files

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
parent 253a041a
Loading
Loading
Loading
Loading
+42 −0
Original line number Original line Diff line number Diff line
@@ -329,6 +329,48 @@ class KeyguardRootViewModelTest : SysuiTestCase() {
            assertThat(alpha).isEqualTo(0f)
            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
    @Test
    fun alpha_idleOnOccluded_isZero() =
    fun alpha_idleOnOccluded_isZero() =
        testScope.runTest {
        testScope.runTest {
+28 −8
Original line number Original line Diff line number Diff line
@@ -56,6 +56,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combineTransform
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.filterNotNull
@@ -125,13 +126,36 @@ constructor(
            .onStart { emit(false) }
            .onStart { emit(false) }
            .distinctUntilChanged()
            .distinctUntilChanged()


    private val alphaOnShadeExpansion: Flow<Float> =
    private val isOnLockscreen: Flow<Boolean> =
        combine(
        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.qsExpansion,
                shadeInteractor.shadeExpansion,
                shadeInteractor.shadeExpansion,
            ) { qsExpansion, shadeExpansion ->
            ) { isOnLockscreen, qsExpansion, shadeExpansion ->
                // Fade out quickly as the shade expands
                // 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()
            .distinctUntilChanged()


@@ -235,11 +259,7 @@ constructor(
        burnInJob?.cancel()
        burnInJob?.cancel()


        burnInJob =
        burnInJob =
            scope.launch {
            scope.launch { aodBurnInViewModel.movement(params).collect { burnInModel.value = it } }
                aodBurnInViewModel.movement(params).collect {
                    burnInModel.value = it
                }
            }
    }
    }


    val scale: Flow<BurnInScaleViewModel> =
    val scale: Flow<BurnInScaleViewModel> =