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

Commit 3a0b5536 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Re-tapping notif chip hides the HUN.

Tapping on a notification status bar chip shows the notification as a
HUN. Re-tapping on the chip should hide the HUN.

Fixes: 385728177
Bug: 364653005
Flag: com.android.systemui.status_bar_notification_chips

Test: atest HeadsUpCoordinatorTest

Test: Have status bar notif chip, tap it -> verify HUN shows up. Tap
chip again while HUN is showing -> verify HUN disappears.
Test: Have status bar notif chip, tap it -> verify HUN shows up. Let it
time out. Tap status bar notif chip again -> verify HUN appears again.
Test: Have two 2 chips, tap one chip, then the other chip -> verify
other chip's HUN appears

Change-Id: Id593f946bf7a4e4cdf1899a536af412261639b20
parent 33db676d
Loading
Loading
Loading
Loading
+31 −4
Original line number Diff line number Diff line
@@ -458,7 +458,7 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    fun showPromotedNotification_hasNotifEntry_shownAsHUN() =
    fun onPromotedNotificationChipTapped_hasNotifEntry_shownAsHUN() =
        testScope.runTest {
            whenever(notifCollection.getEntry(entry.key)).thenReturn(entry)

@@ -473,7 +473,7 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    fun showPromotedNotification_noNotifEntry_noHUN() =
    fun onPromotedNotificationChipTapped_noNotifEntry_noHUN() =
        testScope.runTest {
            whenever(notifCollection.getEntry(entry.key)).thenReturn(null)

@@ -488,7 +488,7 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    fun showPromotedNotification_shownAsHUNEvenIfEntryShouldNot() =
    fun onPromotedNotificationChipTapped_shownAsHUNEvenIfEntryShouldNot() =
        testScope.runTest {
            whenever(notifCollection.getEntry(entry.key)).thenReturn(entry)

@@ -511,7 +511,7 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    fun showPromotedNotification_atSameTimeAsOnAdded_promotedShownAsHUN() =
    fun onPromotedNotificationChipTapped_atSameTimeAsOnAdded_promotedShownAsHUN() =
        testScope.runTest {
            // First, the promoted notification appears as not heads up
            val promotedEntry = NotificationEntryBuilder().setPkg("promotedPackage").build()
@@ -547,6 +547,33 @@ class HeadsUpCoordinatorTest : SysuiTestCase() {
            verify(headsUpManager, never()).showNotification(eq(entry), any())
        }

    @Test
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    fun onPromotedNotificationChipTapped_chipTappedTwice_hunHiddenOnSecondTap() =
        testScope.runTest {
            whenever(notifCollection.getEntry(entry.key)).thenReturn(entry)

            // WHEN chip tapped first
            statusBarNotificationChipsInteractor.onPromotedNotificationChipTapped(entry.key)
            executor.advanceClockToLast()
            executor.runAllReady()
            beforeFinalizeFilterListener.onBeforeFinalizeFilter(listOf(entry))

            // THEN HUN is shown
            finishBind(entry)
            verify(headsUpManager).showNotification(entry, isPinnedByUser = true)
            addHUN(entry)

            // WHEN chip is tapped again
            statusBarNotificationChipsInteractor.onPromotedNotificationChipTapped(entry.key)
            executor.advanceClockToLast()
            executor.runAllReady()
            beforeFinalizeFilterListener.onBeforeFinalizeFilter(listOf(entry))

            // THEN HUN is hidden
            verify(headsUpManager).removeNotification(eq(entry.key), eq(false), any())
        }

    @Test
    fun testTransferIsolatedChildAlert_withGroupAlertSummary() {
        setShouldHeadsUp(groupSummary)
+16 −9
Original line number Diff line number Diff line
@@ -112,20 +112,20 @@ constructor(
        if (StatusBarNotifChips.isEnabled) {
            applicationScope.launch {
                statusBarNotificationChipsInteractor.promotedNotificationChipTapEvent.collect {
                    showPromotedNotificationHeadsUp(it)
                    onPromotedNotificationChipTapEvent(it)
                }
            }
        }
    }

    /**
     * Shows the promoted notification with the given [key] as heads-up.
     * Updates the heads-up state based on which promoted notification with the given [key] was
     * tapped.
     *
     * Must be run on the main thread.
     */
    private fun showPromotedNotificationHeadsUp(key: String) {
    private fun onPromotedNotificationChipTapEvent(key: String) {
        StatusBarNotifChips.assertInNewMode()
        mLogger.logShowPromotedNotificationHeadsUp(key)

        val entry = notifCollection.getEntry(key)
        if (entry == null) {
@@ -135,22 +135,29 @@ constructor(
        // TODO(b/364653005): Validate that the given key indeed matches a promoted notification,
        // not just any notification.

        val isCurrentlyHeadsUp = mHeadsUpManager.isHeadsUpEntry(entry.key)
        val posted =
            PostedEntry(
                entry,
                wasAdded = false,
                wasUpdated = false,
                // Force-set this notification to show heads-up.
                shouldHeadsUpEver = true,
                shouldHeadsUpAgain = true,
                // We want the chip to act as a toggle, so if the chip's notification is currently
                // showing as heads up, then we should stop showing it.
                shouldHeadsUpEver = !isCurrentlyHeadsUp,
                shouldHeadsUpAgain = !isCurrentlyHeadsUp,
                isPinnedByUser = true,
                isHeadsUpEntry = mHeadsUpManager.isHeadsUpEntry(entry.key),
                isHeadsUpEntry = isCurrentlyHeadsUp,
                isBinding = isEntryBinding(entry),
            )
        if (isCurrentlyHeadsUp) {
            mLogger.logHidePromotedNotificationHeadsUp(key)
        } else {
            mLogger.logShowPromotedNotificationHeadsUp(key)
        }

        mExecutor.execute {
            mPostedEntries[entry.key] = posted
            mNotifPromoter.invalidateList("showPromotedNotificationHeadsUp: ${entry.logKey}")
            mNotifPromoter.invalidateList("onPromotedNotificationChipTapEvent: ${entry.logKey}")
        }
    }

+9 −0
Original line number Diff line number Diff line
@@ -148,6 +148,15 @@ class HeadsUpCoordinatorLogger(private val buffer: LogBuffer, private val verbos
        )
    }

    fun logHidePromotedNotificationHeadsUp(key: String) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            { str1 = key },
            { "requesting promoted entry to hide heads up: $str1" },
        )
    }

    fun logPromotedNotificationForHeadsUpNotFound(key: String) {
        buffer.log(
            TAG,