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

Commit 71ec7fa3 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Call] Hide call chip timer when chip is tapped.

This aligns the call chip with the notification chips.

Bug: 414830065
Flag: android.app.ui_rich_ongoing
Test: atest CallChipViewModelTest
Test: Trigger call notification then tap call chip -> verify timer
disappears. Once HUN expires, verify timer re-appears.

Change-Id: Ib9685561b36bd0ee899867b4da382f37447b8a85
parent c7bd6625
Loading
Loading
Loading
Loading
+90 −0
Original line number Diff line number Diff line
@@ -202,6 +202,96 @@ class CallChipViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
            assertThat((latest as OngoingActivityChipModel.Active).instanceId).isEqualTo(instanceId)
        }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    fun chip_inCall_noHun_chipHasTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chip)

            addOngoingCallState(startTimeMs = 4_000)

            headsUpNotificationRepository.setNotifications(emptyList())

            assertThat((latest as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
        }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    fun chip_inCall_hunPinnedBySystem_chipHasTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chip)

            addOngoingCallState()

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

            assertThat((latest as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
        }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    fun chip_inCall_hunPinnedByUser_forDifferentChip_chipHasTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chip)

            addOngoingCallState(key = "thisNotif")

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

            assertThat((latest as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
        }

    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    fun chip_inCall_hunPinnedByUser_forThisChip_chipDoesNotHaveTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chip)

            addOngoingCallState(key = "thisNotif")

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

            assertThat((latest as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.IconOnly::class.java)
        }

    @Test
    @DisableFlags(PromotedNotificationUi.FLAG_NAME)
    fun chip_inCall_hunPinnedByUser_forThisChip_butPromotedFlagOff_chipHasTime() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chip)

            addOngoingCallState(key = "thisNotif")

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

            assertThat((latest as OngoingActivityChipModel.Active).content)
                .isInstanceOf(OngoingActivityChipModel.Content.Timer::class.java)
        }

    @Test
    @EnableChipsModernization
    fun chip_twoCallNotifs_earlierIsUsed() =
+21 −11
Original line number Diff line number Diff line
@@ -228,19 +228,29 @@ constructor(
        val instanceId = state.notificationInstanceId

        // This block mimics OngoingCallController#updateChip.
        // TODO(b/414830065): If the call chip was tapped to show the notification (when
        // PromotedNotificationUi is enabled), don't show the time and show IconOnly instead.
        val content =
            if (state.startTimeMs <= 0L) {
            when {
                state.startTimeMs <= 0L -> {
                    // If the start time is invalid, don't show a timer and show just an icon.
                    // See b/192379214.
                    OngoingActivityChipModel.Content.IconOnly
            } else {
                }
                PromotedNotificationUi.isEnabled &&
                    headsUpState.isShowingHeadsUpFromChipTap(
                        notificationKey = state.notificationKey
                    ) -> {
                    // If the user tapped this chip to show the HUN, we want to just show the icon
                    // because the HUN will show the rest of the information.
                    // Similar behavior to [NotifChipsViewModel].
                    OngoingActivityChipModel.Content.IconOnly
                }
                else -> {
                    val startTimeInElapsedRealtime =
                        state.startTimeMs - systemClock.currentTimeMillis() +
                            systemClock.elapsedRealtime()
                    OngoingActivityChipModel.Content.Timer(startTimeMs = startTimeInElapsedRealtime)
                }
            }

        return OngoingActivityChipModel.Active(
            key = key,
+1 −0
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ constructor(
                isShowingHeadsUpFromChipTap -> {
                    // If the user tapped this chip to show the HUN, we want to just show the icon
                    // because the HUN will show the rest of the information.
                    // Similar behavior to [CallChipViewModel].
                    OngoingActivityChipModel.Content.IconOnly
                }
                text != null -> OngoingActivityChipModel.Content.Text(text = text)