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

Commit 3340e91f authored by Matt Pietal's avatar Matt Pietal
Browse files

Shared notification container - Update isLockscreen

The flow should also include any transitions to/from LOCKSCREEN. This
will prevent flickers while moving between states, like coming back
from OCCLUDED.

Bug: 296606746
Test: atest SystemUITests:SharedNotificationContainerViewModelTest
Change-Id: I9191a096187a05c42a43674a70db85a04cf2069f
parent ad48a441
Loading
Loading
Loading
Loading
+13 −3
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart


/** View-model for the shared notification container, used by both the shade and keyguard spaces */
/** View-model for the shared notification container, used by both the shade and keyguard spaces */
class SharedNotificationContainerViewModel
class SharedNotificationContainerViewModel
@@ -45,8 +46,8 @@ constructor(
) {
) {
    private val statesForConstrainedNotifications =
    private val statesForConstrainedNotifications =
        setOf(
        setOf(
            KeyguardState.LOCKSCREEN,
            KeyguardState.AOD,
            KeyguardState.AOD,
            KeyguardState.LOCKSCREEN,
            KeyguardState.DOZING,
            KeyguardState.DOZING,
            KeyguardState.ALTERNATE_BOUNCER,
            KeyguardState.ALTERNATE_BOUNCER,
            KeyguardState.PRIMARY_BOUNCER
            KeyguardState.PRIMARY_BOUNCER
@@ -68,8 +69,17 @@ constructor(


    /** If the user is visually on one of the unoccluded lockscreen states. */
    /** If the user is visually on one of the unoccluded lockscreen states. */
    val isOnLockscreen: Flow<Boolean> =
    val isOnLockscreen: Flow<Boolean> =
        keyguardTransitionInteractor.finishedKeyguardState
        combine(
            .map { statesForConstrainedNotifications.contains(it) }
                keyguardTransitionInteractor.finishedKeyguardState.map {
                    statesForConstrainedNotifications.contains(it)
                },
                keyguardTransitionInteractor
                    .transitionValue(KeyguardState.LOCKSCREEN)
                    .onStart { emit(0f) }
                    .map { it > 0 }
            ) { constrainedNotificationState, transitioningToOrFromLockscreen ->
                constrainedNotificationState || transitioningToOrFromLockscreen
            }
            .distinctUntilChanged()
            .distinctUntilChanged()


    /** Are we purely on the keyguard without the shade/qs? */
    /** Are we purely on the keyguard without the shade/qs? */
+17 −1
Original line number Original line Diff line number Diff line
@@ -192,10 +192,26 @@ class SharedNotificationContainerViewModelTest : SysuiTestCase() {
            val isOnLockscreen by collectLastValue(underTest.isOnLockscreen)
            val isOnLockscreen by collectLastValue(underTest.isOnLockscreen)


            keyguardTransitionRepository.sendTransitionStep(
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(to = KeyguardState.GONE, transitionState = TransitionState.FINISHED)
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                    value = 1f,
                    transitionState = TransitionState.FINISHED
                )
            )
            )
            assertThat(isOnLockscreen).isFalse()
            assertThat(isOnLockscreen).isFalse()


            // While progressing from lockscreen, should still be true
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                    value = 0.8f,
                    transitionState = TransitionState.RUNNING
                )
            )
            assertThat(isOnLockscreen).isTrue()

            keyguardTransitionRepository.sendTransitionStep(
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
                TransitionStep(
                    to = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.LOCKSCREEN,