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

Commit dbc97877 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[SB][Notifs] Only show 1 notif chip per-package, regardless of UID" into main

parents c59b7d21 f46fba37
Loading
Loading
Loading
Loading
+7 −24
Original line number Diff line number Diff line
@@ -296,7 +296,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

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

@@ -322,8 +322,8 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                )
            )

            // Notif added later takes priority
            assertThat(latest!!.map { it.key }).containsExactly("notif2", "notif1").inOrder()
            // Notif added later takes priority and is the only one
            assertThat(latest!!.map { it.key }).containsExactly("notif2").inOrder()
        }

    @Test
@@ -362,7 +362,6 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

            val uid = 3
            fakeSystemClock.setCurrentTimeMillis(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
@@ -385,7 +384,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                )
            )

            // Notif added later takes priority
            // Notif added later takes priority and is the only one
            assertThat(latest!!.map { it.key }).containsExactly("notif2").inOrder()
        }

@@ -434,7 +433,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "secondPackage.2",
                    packageName = "secondPackage",
                    uid = 2,
                    uid = 20,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("secondPackage.2").build(),
                )
@@ -445,31 +444,15 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                activeNotificationModel(
                    key = "secondPackage.3",
                    packageName = "secondPackage",
                    uid = 2,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent = PromotedNotificationContentBuilder("secondPackage.3").build(),
                )
            )

            fakeSystemClock.advanceTime(1000)
            activeNotificationListRepository.addNotif(
                activeNotificationModel(
                    key = "secondPackage.andDifferentUid",
                    packageName = "secondPackage",
                    uid = 200,
                    statusBarChipIcon = createStatusBarIconViewOrNull(),
                    promotedContent =
                        PromotedNotificationContentBuilder("secondPackage.andDifferentUid").build(),
                    promotedContent = PromotedNotificationContentBuilder("secondPackage.3").build(),
                )
            )

            // Notifs added later take priority
            assertThat(latest!!.map { it.key })
                .containsExactly(
                    "secondPackage.andDifferentUid",
                    "secondPackage.3",
                    "firstPackage.2",
                )
                .containsExactly("secondPackage.3", "firstPackage.2")
                .inOrder()
        }

+0 −1
Original line number Diff line number Diff line
@@ -145,7 +145,6 @@ constructor(
            key = key,
            appName = appName,
            packageName = packageName,
            uid = uid,
            statusBarChipIconView = statusBarChipIconView,
            promotedContent = promotedContent,
            creationTime = creationTime,
+0 −2
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@ data class NotificationChipModel(
    val appName: String,
    /** The notifying app's package name. */
    val packageName: String,
    /** The notifying app's [packageName]'s uid. */
    val uid: Int,
    val statusBarChipIconView: StatusBarIconView?,
    val promotedContent: PromotedNotificationContentModels,
    /** The time when the notification first appeared as promoted. */
+5 −5
Original line number Diff line number Diff line
@@ -64,15 +64,15 @@ constructor(
     */
    private val notificationChipsWithPrunedContent: Flow<List<PrunedNotificationChipModel>> =
        notifChipsInteractor.allNotificationChips
            .map { chips -> chips.filterByPackagePerUser().map { it.toPrunedModel() } }
            .map { chips -> chips.filterByPackage().map { it.toPrunedModel() } }
            .distinctUntilChanged()

    /**
     * Filters all the chips down to just the most important chip per package per user so we don't
     * show multiple chips for the same app.
     * Filters all the chips down to just the most important chip per package so we don't show
     * multiple chips for the same app.
     */
    private fun List<NotificationChipModel>.filterByPackagePerUser(): List<NotificationChipModel> {
        return this.groupBy { Pair(it.packageName, it.uid) }.map { (_, chips) -> chips[0] }
    private fun List<NotificationChipModel>.filterByPackage(): List<NotificationChipModel> {
        return this.groupBy { it.packageName }.map { (_, chips) -> chips[0] }
    }

    private fun NotificationChipModel.toPrunedModel(): PrunedNotificationChipModel {