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

Commit 18eb0668 authored by Beverly Tai's avatar Beverly Tai Committed by Android (Google) Code Review
Browse files

Merge "Only consider notification launches from keyguard in...

Merge "Only consider notification launches from keyguard in KeyguardSurfaceBehindInteractor" into main
parents 4b4854d2 24602011
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -23,12 +23,14 @@ import com.android.systemui.keyguard.domain.interactor.WindowManagerLockscreenVi
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardSurfaceBehindModel
import com.android.systemui.statusbar.notification.domain.interactor.NotificationLaunchAnimationInteractor
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.kotlin.toPx
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map

/**
 * Distance over which the surface behind the keyguard is animated in during a Y-translation
@@ -95,6 +97,14 @@ constructor(
            }
            .distinctUntilChanged()

    /**
     * Whether a notification launch animation is running when we're not already in the GONE state.
     */
    private val isNotificationLaunchAnimationRunningOnKeyguard =
        notificationLaunchInteractor.isLaunchAnimationRunning
            .sample(transitionInteractor.finishedKeyguardState)
            .map { it != KeyguardState.GONE }

    /**
     * Whether we're animating the surface, or a notification launch animation is running (which
     * means we're going to animate the surface, even if animators aren't yet running).
@@ -102,7 +112,7 @@ constructor(
    val isAnimatingSurface =
        combine(
            repository.isAnimatingSurface,
            notificationLaunchInteractor.isLaunchAnimationRunning
            isNotificationLaunchAnimationRunningOnKeyguard,
        ) { animatingSurface, animatingLaunch ->
            animatingSurface || animatingLaunch
        }
+47 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.keyguard.domain.interactor
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
@@ -227,4 +228,50 @@ class KeyguardSurfaceBehindInteractorTest : SysuiTestCase() {
                { it == KeyguardSurfaceBehindModel(alpha = 0f) },
            )
        }

    @Test
    fun notificationLaunchFromLockscreen_isAnimatingSurfaceTrue() =
        testScope.runTest {
            val isAnimatingSurface by collectLastValue(underTest.isAnimatingSurface)
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.GONE,
                    to = KeyguardState.LOCKSCREEN,
                    transitionState = TransitionState.STARTED,
                )
            )
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.GONE,
                    to = KeyguardState.LOCKSCREEN,
                    transitionState = TransitionState.FINISHED,
                )
            )
            kosmos.notificationLaunchAnimationInteractor.setIsLaunchAnimationRunning(true)
            runCurrent()
            assertThat(isAnimatingSurface).isTrue()
        }

    @Test
    fun notificationLaunchFromGone_isAnimatingSurfaceFalse() =
        testScope.runTest {
            val isAnimatingSurface by collectLastValue(underTest.isAnimatingSurface)
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                    transitionState = TransitionState.STARTED,
                )
            )
            transitionRepository.sendTransitionStep(
                TransitionStep(
                    from = KeyguardState.LOCKSCREEN,
                    to = KeyguardState.GONE,
                    transitionState = TransitionState.FINISHED,
                )
            )
            kosmos.notificationLaunchAnimationInteractor.setIsLaunchAnimationRunning(true)
            runCurrent()
            assertThat(isAnimatingSurface).isFalse()
        }
}