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

Commit 24602011 authored by Beverly's avatar Beverly
Browse files

Only consider notification launches from keyguard in KeyguardSurfaceBehindInteractor

To avoid showing the keyguard unnecessarily when launching a
notification intent from the keyguard GONE state.

Test: with keyguard_wm_state_refactor flag enabled, tap a notification
with an intent when the keyguard isn't showing (ie: shade over the
launcher). Observe that StatusBarKeyguardViewManager#show never gets
called (requires manually logging since something else, when flexiglass
isn't enabled, gates the keyguard from actually showing).
Test: atest KeyguardSurfaceBehindInteractorTest
Bug: 308819693
Flag: ACONFIG com.android.systemui.keyguard_wm_state_refactor DEVELOPMENT

Change-Id: I5e103f5c3235dee06522828e56acaa73d86b9b29
parent 2adb2e4f
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()
        }
}