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

Commit 2ff8ced2 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Don't show `when` in chip if automatic promotion is enabled.

Automatically promoted notification will likely just set their `when`
time to the current time, which would cause the chip to always show
"now". We don't want teamfooders to get that experience because it won't
happen in prod, so just don't show any time if we're automatically
promoting notifications.

Bug: 364653005
Flag: com.android.systemui.status_bar_notification_chips
Flag: com.android.systemui.promote_notifications_automatically
Test: Send notif that's auto promoted -> verify time doesn't show
Change-Id: I5acd88fc244c68240210880681b0bbf43d31309c
parent 7177560e
Loading
Loading
Loading
Loading
+46 −0
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package com.android.systemui.statusbar.chips.notification.ui.viewmodel

import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.view.View
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.Flags.FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
@@ -71,6 +73,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
    }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_noNotifs_empty() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -81,6 +84,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_notifMissingStatusBarChipIconView_empty() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -99,6 +103,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_onePromotedNotif_statusBarIconViewMatches() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -122,6 +127,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarConnectedDisplays.FLAG_NAME)
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_onePromotedNotif_connectedDisplaysFlagEnabled_statusBarIconMatches() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -145,6 +151,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_onePromotedNotif_colorMatches() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -175,6 +182,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_onlyForPromotedNotifs() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -208,6 +216,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarConnectedDisplays.FLAG_NAME)
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_connectedDisplaysFlagEnabled_onlyForPromotedNotifs() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -242,6 +251,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_hasShortCriticalText_usesTextInsteadOfTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -272,6 +282,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_noTime_isIconOnly() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -294,6 +305,36 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @EnableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_basicTime_hiddenIfAutomaticallyPromoted() =
        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.IconOnly::class.java)
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_basicTime_isShortTimeDelta() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -322,6 +363,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_countUpTime_isTimer() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -349,6 +391,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_countDownTime_isTimer() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -376,6 +419,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_noHeadsUp_showsTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -407,6 +451,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_hasHeadsUpByUser_onlyShowsIcon() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
@@ -442,6 +487,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_clickingChipNotifiesInteractor() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.statusbar.chips.notification.ui.viewmodel

import android.view.View
import com.android.systemui.Flags
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.statusbar.chips.notification.domain.interactor.StatusBarNotificationChipsInteractor
@@ -99,6 +100,17 @@ constructor(
            )
        }

        if (Flags.promoteNotificationsAutomatically()) {
            // 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)
        }

        if (this.promotedContent.time == null) {
            return OngoingActivityChipModel.Shown.IconOnly(icon, colors, onClickListener)
        }