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

Commit 638f31cc authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Only hide `when` in chip if notif was automatically promoted

Bug: 364653005
Flag: com.android.systemui.promote_notifications_automatically
Flag: com.android.systemui.status_bar_notification_chips
Test: Trigger normally promoted notif -> verify it shows `when` time
Test: Trigger automatically promoted notif -> verify it doesn't show
`when` time
Test: atest NotifChipsViewModelTest

Change-Id: Ie84f082436c17e12b29e9f7a37bdaf4bae3c61a8
parent c0c0957a
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -306,12 +306,13 @@ class NotifChipsViewModelTest : SysuiTestCase() {

    @Test
    @EnableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_basicTime_hiddenIfAutomaticallyPromoted() =
    fun chips_basicTime_timeHiddenIfAutomaticallyPromoted() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.wasPromotedAutomatically = true
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
@@ -333,6 +334,36 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                .isInstanceOf(OngoingActivityChipModel.Shown.IconOnly::class.java)
        }

    @Test
    @EnableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_basicTime_timeShownIfNotAutomaticallyPromoted() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.wasPromotedAutomatically = false
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.BasicTime,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )

            assertThat(latest).hasSize(1)
            assertThat(latest!![0])
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_basicTime_isShortTimeDelta() =
+21 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
import com.android.systemui.statusbar.notification.promoted.AutomaticPromotionCoordinator.Companion.EXTRA_WAS_AUTOMATICALLY_PROMOTED
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel.Style
import com.android.systemui.testKosmos
@@ -108,6 +109,26 @@ class PromotedNotificationContentExtractorImplTest : SysuiTestCase() {
        assertThat(content?.text).isEqualTo(TEST_CONTENT_TEXT)
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_wasPromotedAutomatically_false() {
        val entry = createEntry { extras.putBoolean(EXTRA_WAS_AUTOMATICALLY_PROMOTED, false) }

        val content = extractContent(entry)

        assertThat(content!!.wasPromotedAutomatically).isFalse()
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_wasPromotedAutomatically_true() {
        val entry = createEntry { extras.putBoolean(EXTRA_WAS_AUTOMATICALLY_PROMOTED, true) }

        val content = extractContent(entry)

        assertThat(content!!.wasPromotedAutomatically).isTrue()
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    @DisableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
+4 −4
Original line number Diff line number Diff line
@@ -100,14 +100,14 @@ constructor(
            )
        }

        if (Flags.promoteNotificationsAutomatically()) {
        if (
            Flags.promoteNotificationsAutomatically() &&
                this.promotedContent.wasPromotedAutomatically
        ) {
            // When we're promoting notifications automatically, the `when` time set on the
            // notification will likely just be set to the current time, which would cause the chip
            // to always show "now". We don't want early testers to get that experience since it's
            // not what will happen at launch, so just don't show any time.
            // TODO(b/364653005): Only ignore the `when` time if the notification was
            //  *automatically* promoted (as opposed to being legitimately promoted by the
            // criteria). We'll need to track that status somehow.
            return OngoingActivityChipModel.Shown.IconOnly(icon, colors, onClickListener)
        }

+10 −1
Original line number Diff line number Diff line
@@ -22,7 +22,16 @@ import com.android.systemui.statusbar.notification.collection.coordinator.dagger
import javax.inject.Inject

/** A coordinator that may automatically promote certain notifications. */
interface AutomaticPromotionCoordinator : Coordinator
interface AutomaticPromotionCoordinator : Coordinator {
    companion object {
        /**
         * An extra that should be set on notifications that were automatically promoted. Used in
         * case we want to disable certain features for only automatically promoted notifications
         * (but not normally promoted notifications).
         */
        const val EXTRA_WAS_AUTOMATICALLY_PROMOTED = "android.wasAutomaticallyPromoted"
    }
}

/** A default implementation of [AutomaticPromotionCoordinator] that doesn't promote anything. */
@CoordinatorScope
+6 −8
Original line number Diff line number Diff line
@@ -24,14 +24,14 @@ import android.app.Notification.EXTRA_CHRONOMETER_COUNT_DOWN
import android.app.Notification.EXTRA_SUB_TEXT
import android.app.Notification.EXTRA_TEXT
import android.app.Notification.EXTRA_TITLE
import android.app.Notification.FLAG_PROMOTED_ONGOING
import android.app.Notification.ProgressStyle
import android.content.Context
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifChips
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.promoted.AutomaticPromotionCoordinator.Companion.EXTRA_WAS_AUTOMATICALLY_PROMOTED
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel.Companion.isPromotedForStatusBarChip
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel.Style
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel.When
import javax.inject.Inject
@@ -65,12 +65,8 @@ constructor(
            return null
        }

        // Notification.isPromotedOngoing checks the ui_rich_ongoing flag, but we want the status
        // bar chip to be ready before all the features behind the ui_rich_ongoing flag are ready.
        val isPromotedForStatusBarChip =
            StatusBarNotifChips.isEnabled && (notification.flags and FLAG_PROMOTED_ONGOING) != 0
        val isPromoted = notification.isPromotedOngoing() || isPromotedForStatusBarChip
        if (!isPromoted) {
        // The status bar chips rely on this extractor, so take them into account for promotion.
        if (!isPromotedForStatusBarChip(notification)) {
            logger.logExtractionSkipped(entry, "isPromotedOngoing returned false")
            return null
        }
@@ -80,6 +76,8 @@ constructor(
        // TODO: Pitch a fit if style is unsupported or mandatory fields are missing once
        // FLAG_PROMOTED_ONGOING is set reliably and we're not testing status bar chips.

        contentBuilder.wasPromotedAutomatically =
            notification.extras.getBoolean(EXTRA_WAS_AUTOMATICALLY_PROMOTED, false)
        contentBuilder.skeletonSmallIcon = entry.icons.aodIcon?.sourceIcon
        contentBuilder.appName = notification.loadHeaderAppName(context)
        contentBuilder.subText = notification.subText()
Loading