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

Commit 4f362f4e authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Remove ActiveNotificationModel.isPromoted; use content field

Now that `ActiveNotificationModel.promotedContent` is being filled in,
we can use that field's null/not-null status to determine `isPromoted`.

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

Test: Trigger RON -> verify chip still shows up
Test: atest NotifChipsViewModelTest ActiveNotificationsInteractorTest
Change-Id: I235bbac7c80bbccf83bca0707505d3f1ab910a63
parent 9789ec82
Loading
Loading
Loading
Loading
+17 −14
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.systemui.statusbar.chips.notification.shared.StatusBarNotifCh
import com.android.systemui.statusbar.notification.data.model.activeNotificationModel
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.shared.ActiveNotificationModel
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -60,7 +61,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -90,7 +91,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = null,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -110,7 +111,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = icon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -133,17 +134,17 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif1",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif1").build(),
                    ),
                    activeNotificationModel(
                        key = "notif2",
                        statusBarChipIcon = secondIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif2").build(),
                    ),
                    activeNotificationModel(
                        key = "notif3",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        isPromoted = false,
                        promotedContent = null,
                    ),
                )
            )
@@ -170,7 +171,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -183,7 +184,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = secondIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -196,7 +197,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = thirdIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -216,7 +217,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock(),
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -228,7 +229,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock(),
                        isPromoted = false,
                        promotedContent = null,
                    )
                )
            )
@@ -239,7 +240,7 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock(),
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -260,7 +261,8 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif|uid1",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("notif|uid1").build(),
                    )
                )
            )
@@ -274,7 +276,8 @@ class StatusBarNotificationChipsInteractorTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif|uid2",
                        statusBarChipIcon = secondIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("notif|uid2").build(),
                    )
                )
            )
+8 −6
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import com.android.systemui.statusbar.chips.ui.model.OngoingActivityChipModel
import com.android.systemui.statusbar.notification.data.model.activeNotificationModel
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.shared.ActiveNotificationModel
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -75,7 +76,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = null,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -94,7 +95,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = icon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -117,17 +118,17 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif1",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif1").build(),
                    ),
                    activeNotificationModel(
                        key = "notif2",
                        statusBarChipIcon = secondIcon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif2").build(),
                    ),
                    activeNotificationModel(
                        key = "notif3",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        isPromoted = false,
                        promotedContent = null,
                    ),
                )
            )
@@ -151,7 +152,8 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "clickTest",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("clickTest").build(),
                    )
                )
            )
+17 −9
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import com.android.systemui.statusbar.commandline.commandRegistry
import com.android.systemui.statusbar.notification.data.model.activeNotificationModel
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.shared.ActiveNotificationModel
import com.android.systemui.statusbar.phone.SystemUIDialog
import com.android.systemui.statusbar.phone.ongoingcall.data.repository.ongoingCallRepository
@@ -307,7 +308,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = icon,
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
@@ -328,12 +329,14 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "firstNotif",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("firstNotif").build(),
                    ),
                    activeNotificationModel(
                        key = "secondNotif",
                        statusBarChipIcon = secondIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("secondNotif").build(),
                    ),
                )
            )
@@ -355,17 +358,20 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "firstNotif",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("firstNotif").build(),
                    ),
                    activeNotificationModel(
                        key = "secondNotif",
                        statusBarChipIcon = secondIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("secondNotif").build(),
                    ),
                    activeNotificationModel(
                        key = "thirdNotif",
                        statusBarChipIcon = thirdIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("thirdNotif").build(),
                    ),
                )
            )
@@ -386,12 +392,14 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "firstNotif",
                        statusBarChipIcon = firstIcon,
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("firstNotif").build(),
                    ),
                    activeNotificationModel(
                        key = "secondNotif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        isPromoted = true,
                        promotedContent =
                            PromotedNotificationContentModel.Builder("secondNotif").build(),
                    ),
                )
            )
@@ -412,7 +420,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                    activeNotificationModel(
                        key = "notif",
                        statusBarChipIcon = mock<StatusBarIconView>(),
                        isPromoted = true,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
                )
            )
+22 −9
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.statusbar.notification.data.model.activeNotification
import com.android.systemui.statusbar.notification.data.repository.ActiveNotificationsStore
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.data.repository.setActiveNotifs
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.shared.CallType
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
@@ -169,8 +170,12 @@ class ActiveNotificationsInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.promotedOngoingNotifications)

            val promoted1 = activeNotificationModel(key = "notif1", isPromoted = true)
            val notPromoted2 = activeNotificationModel(key = "notif2", isPromoted = false)
            val promoted1 =
                activeNotificationModel(
                    key = "notif1",
                    promotedContent = PromotedNotificationContentModel.Builder("notif1").build(),
                )
            val notPromoted2 = activeNotificationModel(key = "notif2", promotedContent = null)

            activeNotificationListRepository.activeNotifications.value =
                ActiveNotificationsStore.Builder()
@@ -189,9 +194,9 @@ class ActiveNotificationsInteractorTest : SysuiTestCase() {

            activeNotificationListRepository.activeNotifications.value =
                ActiveNotificationsStore.Builder()
                    .apply { activeNotificationModel(key = "notif1", isPromoted = false) }
                    .apply { activeNotificationModel(key = "notif2", isPromoted = false) }
                    .apply { activeNotificationModel(key = "notif3", isPromoted = false) }
                    .apply { activeNotificationModel(key = "notif1", promotedContent = null) }
                    .apply { activeNotificationModel(key = "notif2", promotedContent = null) }
                    .apply { activeNotificationModel(key = "notif3", promotedContent = null) }
                    .build()

            assertThat(latest!!).isEmpty()
@@ -203,10 +208,18 @@ class ActiveNotificationsInteractorTest : SysuiTestCase() {
        testScope.runTest {
            val latest by collectLastValue(underTest.promotedOngoingNotifications)

            val promoted1 = activeNotificationModel(key = "notif1", isPromoted = true)
            val notPromoted2 = activeNotificationModel(key = "notif2", isPromoted = false)
            val notPromoted3 = activeNotificationModel(key = "notif3", isPromoted = false)
            val promoted4 = activeNotificationModel(key = "notif4", isPromoted = true)
            val promoted1 =
                activeNotificationModel(
                    key = "notif1",
                    promotedContent = PromotedNotificationContentModel.Builder("notif1").build(),
                )
            val notPromoted2 = activeNotificationModel(key = "notif2", promotedContent = null)
            val notPromoted3 = activeNotificationModel(key = "notif3", promotedContent = null)
            val promoted4 =
                activeNotificationModel(
                    key = "notif4",
                    promotedContent = PromotedNotificationContentModel.Builder("notif4").build(),
                )

            activeNotificationListRepository.activeNotifications.value =
                ActiveNotificationsStore.Builder()
+13 −16
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@
package com.android.systemui.statusbar.notification.domain.interactor

import android.app.Notification
import android.app.Notification.FLAG_PROMOTED_ONGOING
import android.platform.test.annotations.EnableFlags
import android.service.notification.StatusBarNotification
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -29,7 +28,7 @@ import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.promoted.PromotedNotificationUi
import com.android.systemui.statusbar.notification.promoted.promotedNotificationsProvider
import com.android.systemui.statusbar.notification.promoted.shared.model.PromotedNotificationContentModel
import com.android.systemui.statusbar.notification.shared.byKey
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
@@ -48,11 +47,7 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {
    private val notifsRepository = kosmos.activeNotificationListRepository
    private val notifsInteractor = kosmos.activeNotificationsInteractor
    private val underTest =
        RenderNotificationListInteractor(
            notifsRepository,
            sectionStyleProvider = mock(),
            promotedNotificationsProvider = kosmos.promotedNotificationsProvider,
        )
        RenderNotificationListInteractor(notifsRepository, sectionStyleProvider = mock())

    @Test
    fun setRenderedList_preservesOrdering() =
@@ -127,12 +122,16 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    fun setRenderList_setsPromotionStatus() =
    fun setRenderList_setsPromotionContent() =
        testScope.runTest {
            val actual by collectLastValue(notifsInteractor.topLevelRepresentativeNotifications)

            val notPromoted1 = mockNotificationEntry("key1", flag = null)
            val promoted2 = mockNotificationEntry("key2", flag = FLAG_PROMOTED_ONGOING)
            val notPromoted1 = mockNotificationEntry("key1", promotedContent = null)
            val promoted2 =
                mockNotificationEntry(
                    "key2",
                    promotedContent = PromotedNotificationContentModel.Builder("key2").build(),
                )

            underTest.setRenderedList(listOf(notPromoted1, promoted2))

@@ -140,22 +139,19 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {

            val first = actual!![0]
            assertThat(first.key).isEqualTo("key1")
            assertThat(first.isPromoted).isFalse()
            assertThat(first.promotedContent).isNull()

            val second = actual!![1]
            assertThat(second.key).isEqualTo("key2")
            assertThat(second.isPromoted).isTrue()
            assertThat(second.promotedContent).isNotNull()
        }

    private fun mockNotificationEntry(
        key: String,
        rank: Int = 0,
        flag: Int? = null,
        promotedContent: PromotedNotificationContentModel? = null,
    ): NotificationEntry {
        val nBuilder = Notification.Builder(context, "a")
        if (flag != null) {
            nBuilder.setFlag(flag, true)
        }
        val notification = nBuilder.build()

        val mockSbn =
@@ -169,6 +165,7 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {
            whenever(this.representativeEntry).thenReturn(this)
            whenever(this.ranking).thenReturn(RankingBuilder().setRank(rank).build())
            whenever(this.sbn).thenReturn(mockSbn)
            whenever(this.promotedNotificationContentModel).thenReturn(promotedContent)
        }
    }
}
Loading