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

Commit 24fd1b3f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes I3bc2a4f3,I43d2c6cf into main

* changes:
  [SB][Notif] Show shortCriticalText in notification chip if available.
  [SB][Notif] Use PromotedNotificationContentModel.time for chip time.
parents 84e03f80 80e1b6b1
Loading
Loading
Loading
Loading
+5 −25
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.chips.notification.domain.model.NotificationChipModel
import com.android.systemui.statusbar.core.StatusBarConnectedDisplays
import com.android.systemui.statusbar.notification.data.model.activeNotificationModel
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
@@ -50,7 +49,6 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "notif1",
                    statusBarChipIcon = icon,
                    whenTime = 5432,
                    promotedContent = PROMOTED_CONTENT,
                )

@@ -60,7 +58,7 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {

            assertThat(latest!!.key).isEqualTo("notif1")
            assertThat(latest!!.statusBarChipIconView).isEqualTo(icon)
            assertThat(latest!!.whenTime).isEqualTo(5432)
            assertThat(latest!!.promotedContent).isEqualTo(PROMOTED_CONTENT)
        }

    @Test
@@ -83,14 +81,12 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "notif1",
                    statusBarChipIcon = newIconView,
                    whenTime = 6543,
                    promotedContent = PROMOTED_CONTENT,
                )
            )

            assertThat(latest!!.key).isEqualTo("notif1")
            assertThat(latest!!.statusBarChipIconView).isEqualTo(newIconView)
            assertThat(latest!!.whenTime).isEqualTo(6543)
        }

    @Test
@@ -174,22 +170,14 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif1",
                        statusBarChipIcon = null,
                        whenTime = 123L,
                        promotedContent = PROMOTED_CONTENT,
                    )
                )

            val latest by collectLastValue(underTest.notificationChip)

            assertThat(latest)
                .isEqualTo(
                    NotificationChipModel(
                        "notif1",
                        statusBarChipIconView = null,
                        whenTime = 123L,
                        promotedContent = PROMOTED_CONTENT,
                    )
                )
            assertThat(latest).isNotNull()
            assertThat(latest!!.key).isEqualTo("notif1")
        }

    @Test
@@ -234,20 +222,12 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "notif1",
                    statusBarChipIcon = null,
                    whenTime = 123L,
                    promotedContent = PROMOTED_CONTENT,
                )
            )

            assertThat(latest)
                .isEqualTo(
                    NotificationChipModel(
                        key = "notif1",
                        statusBarChipIconView = null,
                        whenTime = 123L,
                        promotedContent = PROMOTED_CONTENT,
                    )
                )
            assertThat(latest).isNotNull()
            assertThat(latest!!.key).isEqualTo("notif1")
        }

    @Test
+156 −8
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {

            assertThat(latest).hasSize(1)
            val chip = latest!![0]
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
            assertThat(chip.icon).isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarView(icon))
        }

@@ -139,7 +139,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {

            assertThat(latest).hasSize(1)
            val chip = latest!![0]
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
            assertThat(chip.icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon(notifKey))
        }
@@ -241,16 +241,159 @@ class NotifChipsViewModelTest : SysuiTestCase() {
            assertIsNotifKey(latest!![1], secondKey)
        }

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

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.shortCriticalText = "Arrived"
                    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.Text::class.java)
            assertThat((latest!![0] as OngoingActivityChipModel.Shown.Text).text)
                .isEqualTo("Arrived")
        }

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

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply { this.time = null }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )

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

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

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    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
    fun chips_countUpTime_isTimer() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

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

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

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

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

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

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

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.BasicTime,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )
@@ -267,12 +410,21 @@ class NotifChipsViewModelTest : SysuiTestCase() {
    fun chips_hasHeadsUpByUser_onlyShowsIcon() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val promotedContentBuilder =
                PromotedNotificationContentModel.Builder("notif").apply {
                    this.time =
                        PromotedNotificationContentModel.When(
                            time = 6543L,
                            mode = PromotedNotificationContentModel.When.Mode.BasicTime,
                        )
                }
            setNotifs(
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                        promotedContent = promotedContentBuilder.build(),
                    )
                )
            )
@@ -324,15 +476,11 @@ class NotifChipsViewModelTest : SysuiTestCase() {

    companion object {
        fun assertIsNotifChip(latest: OngoingActivityChipModel?, expectedIcon: StatusBarIconView) {
            assertThat(latest)
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarView(expectedIcon))
        }

        fun assertIsNotifKey(latest: OngoingActivityChipModel?, expectedKey: String) {
            assertThat(latest)
                .isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon(expectedKey))
        }
+48 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ class PromotedNotificationContentExtractorTest : SysuiTestCase() {
                    setSubText(TEST_SUB_TEXT)
                    setContentTitle(TEST_CONTENT_TITLE)
                    setContentText(TEST_CONTENT_TEXT)
                    setShortCriticalText(TEST_SHORT_CRITICAL_TEXT)
                }
                .also { provider.promotedEntries.add(it) }

@@ -112,6 +113,52 @@ class PromotedNotificationContentExtractorTest : SysuiTestCase() {
        assertThat(content?.text).isEqualTo(TEST_CONTENT_TEXT)
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    @DisableFlags(android.app.Flags.FLAG_API_RICH_ONGOING)
    fun extractContent_apiFlagOff_shortCriticalTextNotExtracted() {
        val entry =
            createEntry { setShortCriticalText(TEST_SHORT_CRITICAL_TEXT) }
                .also { provider.promotedEntries.add(it) }

        val content = extractContent(entry)

        assertThat(content).isNotNull()
        assertThat(content?.text).isNull()
    }

    @Test
    @EnableFlags(
        PromotedNotificationUi.FLAG_NAME,
        StatusBarNotifChips.FLAG_NAME,
        android.app.Flags.FLAG_API_RICH_ONGOING,
    )
    fun extractContent_apiFlagOn_shortCriticalTextExtracted() {
        val entry =
            createEntry { setShortCriticalText(TEST_SHORT_CRITICAL_TEXT) }
                .also { provider.promotedEntries.add(it) }

        val content = extractContent(entry)

        assertThat(content).isNotNull()
        assertThat(content?.shortCriticalText).isEqualTo(TEST_SHORT_CRITICAL_TEXT)
    }

    @Test
    @EnableFlags(
        PromotedNotificationUi.FLAG_NAME,
        StatusBarNotifChips.FLAG_NAME,
        android.app.Flags.FLAG_API_RICH_ONGOING,
    )
    fun extractContent_noShortCriticalTextSet_textIsNull() {
        val entry = createEntry {}.also { provider.promotedEntries.add(it) }

        val content = extractContent(entry)

        assertThat(content).isNotNull()
        assertThat(content?.shortCriticalText).isNull()
    }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME, StatusBarNotifChips.FLAG_NAME)
    fun extractContent_fromBigPictureStyle() {
@@ -201,6 +248,7 @@ class PromotedNotificationContentExtractorTest : SysuiTestCase() {
        private const val TEST_SUB_TEXT = "sub text"
        private const val TEST_CONTENT_TITLE = "content title"
        private const val TEST_CONTENT_TEXT = "content text"
        private const val TEST_SHORT_CRITICAL_TEXT = "short"

        private const val TEST_PERSON_NAME = "person name"
        private const val TEST_PERSON_KEY = "person key"
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ constructor(
            }
        }

        return NotificationChipModel(key, statusBarChipIconView, whenTime, promotedContent)
        return NotificationChipModel(key, statusBarChipIconView, promotedContent)
    }

    @AssistedFactory
+0 −2
Original line number Diff line number Diff line
@@ -23,7 +23,5 @@ import com.android.systemui.statusbar.notification.promoted.shared.model.Promote
data class NotificationChipModel(
    val key: String,
    val statusBarChipIconView: StatusBarIconView?,
    // TODO(b/364653005): Use [PromotedNotificationContentModel.time] instead of a custom field.
    val whenTime: Long,
    val promotedContent: PromotedNotificationContentModel,
)
Loading