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

Commit d2a2f339 authored by lyn's avatar lyn
Browse files

[Dual Shade] Fix unresponsive HUN in unlocked QS

Bug: 440059830
Flag: com.android.systemui.scene_container
Test: NotificationScrollViewModelTest
Test: tap HUN action button/reply via IME => expected animations run
Change-Id: I07ca8c06da4305b31ce33364bde6658b289293ea
parent d45521e9
Loading
Loading
Loading
Loading
+68 −1
Original line number Diff line number Diff line
@@ -25,11 +25,16 @@ import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.scene.domain.startable.sceneContainerStartable
import com.android.systemui.settings.brightness.domain.interactor.brightnessMirrorShowingInteractor
import com.android.systemui.shade.domain.interactor.disableDualShade
import com.android.systemui.shade.domain.interactor.enableDualShade
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.statusbar.notification.data.repository.UnconfinedFakeHeadsUpRowRepository
import com.android.systemui.statusbar.notification.headsup.PinnedStatus
import com.android.systemui.statusbar.notification.stack.data.repository.headsUpNotificationRepository
import com.android.systemui.statusbar.notification.stack.domain.interactor.notificationStackAppearanceInteractor
import com.android.systemui.statusbar.notification.stack.shared.model.ShadeScrimBounds
import com.android.systemui.statusbar.notification.stack.shared.model.ShadeScrimShape
@@ -37,6 +42,7 @@ import com.android.systemui.testKosmos
import com.android.systemui.util.state.SynchronouslyObservableState
import com.android.systemui.util.state.observableStateOf
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -46,9 +52,15 @@ import org.junit.runner.RunWith
@EnableSceneContainer
class NotificationScrollViewModelTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
    private val Kosmos.underTest by Kosmos.Fixture { notificationScrollViewModel }

    private val fakePinnedHun =
        UnconfinedFakeHeadsUpRowRepository(
            key = "test_hun",
            pinnedStatus = MutableStateFlow(PinnedStatus.PinnedByUser),
        )

    @Before
    fun setUp() =
        with(kosmos) {
@@ -152,4 +164,59 @@ class NotificationScrollViewModelTest : SysuiTestCase() {
            brightnessMirrorShowingInteractor.setMirrorShowing(true)
            assertThat(interactive).isFalse()
        }

    @Test
    fun interactive_whenBlurredAndHunIsPinned_isTrue() =
        kosmos.runTest {
            val interactive by collectLastValue(underTest.interactive)
            brightnessMirrorShowingInteractor.setMirrorShowing(false)

            // GIVEN the background is blurred and a HUN is pinned
            setBlur(true)
            setHunIsPinned(true)

            // THEN the notification stack is interactive (because of the HUN)
            assertThat(interactive).isTrue()
        }

    @Test
    fun interactive_whenBlurredAndNoHun_isFalse() =
        kosmos.runTest {
            val interactive by collectLastValue(underTest.interactive)
            brightnessMirrorShowingInteractor.setMirrorShowing(false)

            // GIVEN the background is blurred and no HUN is pinned
            setBlur(true)
            setHunIsPinned(false)

            // THEN the notification stack is NOT interactive
            assertThat(interactive).isFalse()
        }

    @Test
    fun interactive_whenNotBlurredAndHunIsPinned_isTrue() =
        kosmos.runTest {
            val interactive by collectLastValue(underTest.interactive)
            brightnessMirrorShowingInteractor.setMirrorShowing(false)

            // GIVEN the background is not blurred but a HUN is still pinned
            setBlur(false)
            setHunIsPinned(true)

            // THEN the notification stack is interactive
            assertThat(interactive).isTrue()
        }

    private fun Kosmos.setBlur(isBlurred: Boolean) {
        val expansion = if (isBlurred) 1f else 0f
        shadeTestUtil.setQsExpansion(expansion)
    }

    private fun Kosmos.setHunIsPinned(isPinned: Boolean) {
        if (isPinned) {
            headsUpNotificationRepository.setNotifications(listOf(fakePinnedHun))
        } else {
            headsUpNotificationRepository.setNotifications(emptyList())
        }
    }
}
+9 −3
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.domain.interactor.ShadeModeInteractor
import com.android.systemui.shade.shared.model.ShadeMode
import com.android.systemui.statusbar.domain.interactor.RemoteInputInteractor
import com.android.systemui.statusbar.notification.domain.interactor.HeadsUpNotificationInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.LockscreenDisplayConfig
import com.android.systemui.statusbar.notification.stack.domain.interactor.LockscreenNotificationDisplayConfigInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.NotificationStackAppearanceInteractor
@@ -80,6 +81,7 @@ constructor(
    shadeModeInteractor: ShadeModeInteractor,
    bouncerInteractor: BouncerInteractor,
    private val remoteInputInteractor: RemoteInputInteractor,
    private val headsUpNotificationInteractor: HeadsUpNotificationInteractor,
    sceneInteractor: SceneInteractor,
    // TODO(b/336364825) Remove Lazy when SceneContainerFlag is released -
    // while the flag is off, creating this object too early results in a crash
@@ -263,8 +265,12 @@ constructor(
     * scene container will handle touches.
     */
    val interactive: Flow<Boolean> =
        combine(blurFraction, brightnessMirrorShowing) { blurFraction, brightnessMirrorShowing ->
                blurFraction != 1f && !brightnessMirrorShowing
        combine(
            blurFraction,
            brightnessMirrorShowing,
            headsUpNotificationInteractor.hasPinnedRows,
        ) { blurFraction, brightnessMirrorShowing, hasPinnedHun ->
            (blurFraction != 1f || hasPinnedHun) && !brightnessMirrorShowing
        }
            .distinctUntilChanged()
            .dumpWhileCollecting("interactive")
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.settings.brightness.domain.interactor.brightnessMirr
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.domain.interactor.shadeModeInteractor
import com.android.systemui.statusbar.domain.interactor.remoteInputInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.headsUpNotificationInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.lockscreenNotificationDisplayConfigInteractor
import com.android.systemui.statusbar.notification.stack.domain.interactor.notificationStackAppearanceInteractor

@@ -39,6 +40,7 @@ val Kosmos.notificationScrollViewModel by Fixture {
        shadeModeInteractor = shadeModeInteractor,
        bouncerInteractor = bouncerInteractor,
        remoteInputInteractor = remoteInputInteractor,
        headsUpNotificationInteractor = headsUpNotificationInteractor,
        sceneInteractor = sceneInteractor,
        keyguardInteractor = { keyguardInteractor },
    )