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

Commit 1d4e1ab1 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB] Rework chip visibility & notification icon visibility with HUNs.

I noticed a few problems:
 - With StatusBarNoHunBehavior flag off, if you have a chip and then get
   a HUN then we weren't showing the HUN's notification icon because
   `isAnyChipVisible` was `true`.
 - With StatusBarNoHunBehavior flag on, then tapping the chip to show
   the HUN would hide the chip because there was a pinned HUN.

This reworks the flows to address both of these problems.

Bug: 364653005
Flag: com.android.systemui.status_bar_no_hun_behavior
Flag: com.android.systemui.status_bar_root_modernization

Test: NoHunBehavior off: Verify status bar updates to show HUN icon &
text if you have a chip AND if you don't have a chip
Test: NoHunBeahvior on: Verify status bar always shows clock & chip,
even if there's a chip HUN showing or a non-chip HUN showing

Test: atest HomeStatusBarViewModelTest
Change-Id: Ie58ebbc9ad021f9e33b1280c4cbbc4d146b31e23
parent bc85e45d
Loading
Loading
Loading
Loading
+140 −5
Original line number Diff line number Diff line
@@ -716,7 +716,8 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
        }

    @Test
    fun canShowOngoingActivityChips_statusBarNotHidden_noSecureCamera_hun_false() =
    @DisableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun canShowOngoingActivityChips_statusBarNotHidden_noSecureCamera_hunBySystem_noHunFlagOff_false() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.canShowOngoingActivityChips)

@@ -725,13 +726,67 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedByUser),
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedBySystem),
                )
            )

            assertThat(latest).isFalse()
        }

    @Test
    @DisableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun canShowOngoingActivityChips_statusBarNotHidden_noSecureCamera_hunByUser_noHunFlagOff_true() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.canShowOngoingActivityChips)

            transitionKeyguardToGone()

            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedByUser),
                )
            )

            assertThat(latest).isTrue()
        }

    @Test
    @EnableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun canShowOngoingActivityChips_statusBarNotHidden_noSecureCamera_hunBySystem_noHunFlagOn_true() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.canShowOngoingActivityChips)

            transitionKeyguardToGone()

            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedBySystem),
                )
            )

            assertThat(latest).isTrue()
        }

    @Test
    @EnableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun canShowOngoingActivityChips_statusBarNotHidden_noSecureCamera_hunByUser_noHunFlagOn_true() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.canShowOngoingActivityChips)

            transitionKeyguardToGone()

            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedByUser),
                )
            )

            assertThat(latest).isTrue()
        }

    @Test
    fun isClockVisible_allowedByDisableFlags_visible() =
        kosmos.runTest {
@@ -892,7 +947,7 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {

    @Test
    @EnableChipsModernization
    fun isNotificationIconContainerVisible_anyChipShowing_ChipsModernizationOn() =
    fun isNotificationIconContainerVisible_anyChipShowing_chipsModernizationOn() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()
@@ -909,7 +964,7 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
    @Test
    @DisableFlags(StatusBarRootModernization.FLAG_NAME, StatusBarChipsModernization.FLAG_NAME)
    @EnableFlags(StatusBarNotifChips.FLAG_NAME)
    fun isNotificationIconContainerVisible_anyChipShowing_PromotedNotifsOn() =
    fun isNotificationIconContainerVisible_anyChipShowing_promotedNotifsOn() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()
@@ -929,7 +984,7 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
        StatusBarRootModernization.FLAG_NAME,
        StatusBarChipsModernization.FLAG_NAME,
    )
    fun isNotificationIconContainerVisible_anyChipShowing_ChipsModernizationAndPromotedNotifsOff() =
    fun isNotificationIconContainerVisible_anyChipShowing_chipsModernizationAndPromotedNotifsOff() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()
@@ -943,6 +998,86 @@ class HomeStatusBarViewModelImplTest : SysuiTestCase() {
            assertThat(latest!!.visibility).isEqualTo(View.VISIBLE)
        }

    @DisableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun isNotificationIconContainerVisible_hasChipButAlsoHun_hunBySystem_noHunFlagOff_visible() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()

            // Chip
            kosmos.screenRecordRepository.screenRecordState.value = ScreenRecordModel.Recording

            // HUN, PinnedBySystem
            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedBySystem),
                )
            )

            assertThat(latest!!.visibility).isEqualTo(View.VISIBLE)
        }

    @DisableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun isNotificationIconContainerVisible_hasChipButAlsoHun_hunByUser_noHunFlagOff_gone() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()

            // Chip
            kosmos.screenRecordRepository.screenRecordState.value = ScreenRecordModel.Recording

            // HUN, PinnedByUser
            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedByUser),
                )
            )

            assertThat(latest!!.visibility).isEqualTo(View.GONE)
        }

    @EnableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun isNotificationIconContainerVisible_hasChipButAlsoHun_hunBySystem_noHunFlagOn_gone() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()

            // Chip
            kosmos.screenRecordRepository.screenRecordState.value = ScreenRecordModel.Recording

            // HUN, PinnedBySystem
            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedBySystem),
                )
            )

            assertThat(latest!!.visibility).isEqualTo(View.GONE)
        }

    @EnableFlags(StatusBarNoHunBehavior.FLAG_NAME)
    fun isNotificationIconContainerVisible_hasChipButAlsoHun_hunByUser_noHunFlagOn_gone() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.isNotificationIconContainerVisible)
            transitionKeyguardToGone()

            // Chip
            kosmos.screenRecordRepository.screenRecordState.value = ScreenRecordModel.Recording

            // HUN, PinnedByUser
            headsUpNotificationRepository.setNotifications(
                UnconfinedFakeHeadsUpRowRepository(
                    key = "key",
                    pinnedStatus = MutableStateFlow(PinnedStatus.PinnedByUser),
                )
            )

            assertThat(latest!!.visibility).isEqualTo(View.GONE)
        }

    @Test
    fun isSystemInfoVisible_allowedByDisableFlags_visible() =
        kosmos.runTest {
+17 −12
Original line number Diff line number Diff line
@@ -369,15 +369,6 @@ constructor(
            )
            .flowOn(bgDispatcher)

    private val isAnyChipVisible =
        if (StatusBarChipsModernization.isEnabled) {
            ongoingActivityChips.map { it.active.any { chip -> !chip.isHidden } }
        } else if (StatusBarNotifChips.isEnabled) {
            ongoingActivityChipsLegacy.map { it.primary is OngoingActivityChipModel.Active }
        } else {
            primaryOngoingActivityChip.map { it is OngoingActivityChipModel.Active }
        }

    /**
     * True if we need to hide the usual start side content in order to show the heads up
     * notification info.
@@ -419,9 +410,23 @@ constructor(
        combine(
            isHomeStatusBarAllowed,
            keyguardInteractor.isSecureCameraActive,
            headsUpNotificationInteractor.statusBarHeadsUpStatus,
        ) { isHomeStatusBarAllowed, isSecureCameraActive, headsUpState ->
            isHomeStatusBarAllowed && !isSecureCameraActive && !headsUpState.isPinned
            hideStartSideContentForHeadsUp,
        ) { isHomeStatusBarAllowed, isSecureCameraActive, hideStartSideContentForHeadsUp ->
            isHomeStatusBarAllowed && !isSecureCameraActive && !hideStartSideContentForHeadsUp
        }

    private val hasOngoingActivityChips =
        if (StatusBarChipsModernization.isEnabled) {
            ongoingActivityChips.map { it.active.any { chip -> !chip.isHidden } }
        } else if (StatusBarNotifChips.isEnabled) {
            ongoingActivityChipsLegacy.map { it.primary is OngoingActivityChipModel.Active }
        } else {
            primaryOngoingActivityChip.map { it is OngoingActivityChipModel.Active }
        }

    private val isAnyChipVisible =
        combine(hasOngoingActivityChips, canShowOngoingActivityChips) { hasChips, canShowChips ->
            hasChips && canShowChips
        }

    override val isClockVisible: Flow<VisibilityModel> =