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

Commit 53bda7c2 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Notif] Use correct content descriptions for RON chips & call chips.

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

Test: Verify call chip content description is "{app name} notification:
Ongoing call. {time}"
Test: Verify notif chip content description is "{app name} notification:
Ongoing. {chip text}"
Test: Verify screen recording chip content description is "Screen
recording" (or "Screen casting" or "Screen sharing"), {time}"
Test: Verify all the above with chips_modernization flag OFF and ON

Change-Id: I0608dc680af24027c1f2947da550f98f2587423d
parent e69156bf
Loading
Loading
Loading
Loading
+44 −12
Original line number Diff line number Diff line
@@ -24,9 +24,9 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.Expandable
import com.android.systemui.common.shared.model.ContentDescription.Companion.loadContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.plugins.activityStarter
import com.android.systemui.res.R
@@ -47,6 +47,7 @@ import com.android.systemui.statusbar.phone.ongoingcall.StatusBarChipsModernizat
import com.android.systemui.statusbar.phone.ongoingcall.data.repository.ongoingCallRepository
import com.android.systemui.statusbar.phone.ongoingcall.shared.model.OngoingCallModel
import com.android.systemui.statusbar.phone.ongoingcall.shared.model.inCallModel
import com.android.systemui.testKosmos
import com.android.systemui.util.time.fakeSystemClock
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
@@ -60,7 +61,7 @@ import org.mockito.kotlin.whenever
@SmallTest
@RunWith(AndroidJUnit4::class)
class CallChipViewModelTest : SysuiTestCase() {
    private val kosmos = Kosmos()
    private val kosmos = testKosmos()
    private val notificationListRepository = kosmos.activeNotificationListRepository
    private val testScope = kosmos.testScope
    private val repo = kosmos.ongoingCallRepository
@@ -162,25 +163,34 @@ class CallChipViewModelTest : SysuiTestCase() {

    @Test
    @DisableFlags(StatusBarConnectedDisplays.FLAG_NAME)
    fun chip_zeroStartTime_cdFlagOff_iconIsNotifIcon() =
    fun chip_zeroStartTime_cdFlagOff_iconIsNotifIcon_withContentDescription() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chip)

            val notifIcon = createStatusBarIconViewOrNull()
            repo.setOngoingCallState(inCallModel(startTimeMs = 0, notificationIcon = notifIcon))
            repo.setOngoingCallState(
                inCallModel(
                    startTimeMs = 0,
                    notificationIcon = notifIcon,
                    appName = "Fake app name",
                )
            )

            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isInstanceOf(OngoingActivityChipModel.ChipIcon.StatusBarView::class.java)
            val actualIcon =
                (((latest as OngoingActivityChipModel.Shown).icon)
                        as OngoingActivityChipModel.ChipIcon.StatusBarView)
                    .impl
            assertThat(actualIcon).isEqualTo(notifIcon)
                (latest as OngoingActivityChipModel.Shown).icon
                    as OngoingActivityChipModel.ChipIcon.StatusBarView
            assertThat(actualIcon.impl).isEqualTo(notifIcon)
            assertThat(actualIcon.contentDescription.loadContentDescription(context))
                .contains("Ongoing call")
            assertThat(actualIcon.contentDescription.loadContentDescription(context))
                .contains("Fake app name")
        }

    @Test
    @EnableFlags(StatusBarConnectedDisplays.FLAG_NAME)
    fun chip_zeroStartTime_cdFlagOn_iconIsNotifKeyIcon() =
    fun chip_zeroStartTime_cdFlagOn_iconIsNotifKeyIcon_withContentDescription() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chip)

@@ -189,11 +199,22 @@ class CallChipViewModelTest : SysuiTestCase() {
                    startTimeMs = 0,
                    notificationIcon = createStatusBarIconViewOrNull(),
                    notificationKey = "notifKey",
                    appName = "Fake app name",
                )
            )

            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon("notifKey"))
                .isInstanceOf(
                    OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon::class.java
                )
            val actualIcon =
                (latest as OngoingActivityChipModel.Shown).icon
                    as OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon
            assertThat(actualIcon.notificationKey).isEqualTo("notifKey")
            assertThat(actualIcon.contentDescription.loadContentDescription(context))
                .contains("Ongoing call")
            assertThat(actualIcon.contentDescription.loadContentDescription(context))
                .contains("Fake app name")
        }

    @Test
@@ -216,7 +237,7 @@ class CallChipViewModelTest : SysuiTestCase() {

    @Test
    @EnableFlags(StatusBarConnectedDisplays.FLAG_NAME)
    fun chip_notifIconFlagOn_butNullNotifIcon_iconNotifKey() =
    fun chip_notifIconFlagOn_butNullNotifIcon_cdFlagOn_iconIsNotifKeyIcon_withContentDescription() =
        testScope.runTest {
            val latest by collectLastValue(underTest.chip)

@@ -225,11 +246,22 @@ class CallChipViewModelTest : SysuiTestCase() {
                    startTimeMs = 1000,
                    notificationIcon = null,
                    notificationKey = "notifKey",
                    appName = "Fake app name",
                )
            )

            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon("notifKey"))
                .isInstanceOf(
                    OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon::class.java
                )
            val actualIcon =
                (latest as OngoingActivityChipModel.Shown).icon
                    as OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon
            assertThat(actualIcon.notificationKey).isEqualTo("notifKey")
            assertThat(actualIcon.contentDescription.loadContentDescription(context))
                .contains("Ongoing call")
            assertThat(actualIcon.contentDescription.loadContentDescription(context))
                .contains("Fake app name")
        }

    @Test
+5 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
            val startingNotif =
                activeNotificationModel(
                    key = "notif1",
                    appName = "Fake Name",
                    statusBarChipIcon = icon,
                    promotedContent = PROMOTED_CONTENT,
                )
@@ -58,6 +59,7 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
            val latest by collectLastValue(underTest.notificationChip)

            assertThat(latest!!.key).isEqualTo("notif1")
            assertThat(latest!!.appName).isEqualTo("Fake Name")
            assertThat(latest!!.statusBarChipIconView).isEqualTo(icon)
            assertThat(latest!!.promotedContent).isEqualTo(PROMOTED_CONTENT)
        }
@@ -70,6 +72,7 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
                factory.create(
                    activeNotificationModel(
                        key = "notif1",
                        appName = "Fake Name",
                        statusBarChipIcon = originalIconView,
                        promotedContent = PROMOTED_CONTENT,
                    ),
@@ -82,12 +85,14 @@ class SingleNotificationChipInteractorTest : SysuiTestCase() {
            underTest.setNotification(
                activeNotificationModel(
                    key = "notif1",
                    appName = "New Name",
                    statusBarChipIcon = newIconView,
                    promotedContent = PROMOTED_CONTENT,
                )
            )

            assertThat(latest!!.key).isEqualTo("notif1")
            assertThat(latest!!.appName).isEqualTo("New Name")
            assertThat(latest!!.statusBarChipIconView).isEqualTo(newIconView)
        }

+46 −15
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

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

import android.content.Context
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.view.View
@@ -23,6 +24,7 @@ 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.common.shared.model.ContentDescription.Companion.loadContentDescription
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.kosmos.collectLastValue
@@ -125,7 +127,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {

    @Test
    @DisableFlags(FLAG_PROMOTE_NOTIFICATIONS_AUTOMATICALLY)
    fun chips_onePromotedNotif_statusBarIconViewMatches() =
    fun chips_onePromotedNotif_connectedDisplaysFlagDisabled_statusBarIconViewMatches() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.chips)

@@ -134,6 +136,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                listOf(
                    activeNotificationModel(
                        key = "notif",
                        appName = "Fake App Name",
                        statusBarChipIcon = icon,
                        promotedContent = PromotedNotificationContentModel.Builder("notif").build(),
                    )
@@ -142,7 +145,13 @@ class NotifChipsViewModelTest : SysuiTestCase() {

            assertThat(latest).hasSize(1)
            val chip = latest!![0]
            assertIsNotifChip(chip, icon, "notif")
            assertIsNotifChip(
                chip,
                context,
                icon,
                expectedNotificationKey = "notif",
                expectedContentDescriptionSubstrings = listOf("Ongoing", "Fake App Name"),
            )
        }

    @Test
@@ -157,6 +166,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
                listOf(
                    activeNotificationModel(
                        key = notifKey,
                        appName = "Fake App Name",
                        statusBarChipIcon = null,
                        promotedContent = PromotedNotificationContentModel.Builder(notifKey).build(),
                    )
@@ -165,9 +175,13 @@ class NotifChipsViewModelTest : SysuiTestCase() {

            assertThat(latest).hasSize(1)
            val chip = latest!![0]
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown::class.java)
            assertThat(chip.icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon(notifKey))
            assertIsNotifChip(
                chip,
                context,
                expectedIcon = null,
                expectedNotificationKey = "notif",
                expectedContentDescriptionSubstrings = listOf("Ongoing", "Fake App Name"),
            )
        }

    @Test
@@ -230,8 +244,8 @@ class NotifChipsViewModelTest : SysuiTestCase() {
            )

            assertThat(latest).hasSize(2)
            assertIsNotifChip(latest!![0], firstIcon, "notif1")
            assertIsNotifChip(latest!![1], secondIcon, "notif2")
            assertIsNotifChip(latest!![0], context, firstIcon, "notif1")
            assertIsNotifChip(latest!![1], context, secondIcon, "notif2")
        }

    @Test
@@ -590,7 +604,7 @@ class NotifChipsViewModelTest : SysuiTestCase() {
            // THEN the "notif" chip keeps showing time
            val chip = latest!![0]
            assertThat(chip).isInstanceOf(OngoingActivityChipModel.Shown.ShortTimeDelta::class.java)
            assertIsNotifChip(chip, icon, "notif")
            assertIsNotifChip(chip, context, icon, "notif")
        }

    @Test
@@ -705,24 +719,41 @@ class NotifChipsViewModelTest : SysuiTestCase() {
    companion object {
        fun assertIsNotifChip(
            latest: OngoingActivityChipModel?,
            context: Context,
            expectedIcon: StatusBarIconView?,
            notificationKey: String,
            expectedNotificationKey: String,
            expectedContentDescriptionSubstrings: List<String> = emptyList(),
        ) {
            val shown = latest as OngoingActivityChipModel.Shown
            if (StatusBarConnectedDisplays.isEnabled) {
                assertThat(shown.icon)
                    .isEqualTo(
                        OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon(notificationKey)
                    .isInstanceOf(
                        OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon::class.java
                    )
                val icon = shown.icon as OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon

                assertThat(icon.notificationKey).isEqualTo(expectedNotificationKey)
                expectedContentDescriptionSubstrings.forEach {
                    assertThat(icon.contentDescription.loadContentDescription(context)).contains(it)
                }
            } else {
                assertThat(latest.icon)
                    .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarView(expectedIcon!!))
                assertThat(shown.icon)
                    .isInstanceOf(OngoingActivityChipModel.ChipIcon.StatusBarView::class.java)
                val icon = shown.icon as OngoingActivityChipModel.ChipIcon.StatusBarView
                assertThat(icon.impl).isEqualTo(expectedIcon!!)
                expectedContentDescriptionSubstrings.forEach {
                    assertThat(icon.contentDescription.loadContentDescription(context)).contains(it)
                }
            }
        }

        fun assertIsNotifKey(latest: OngoingActivityChipModel?, expectedKey: String) {
            assertThat((latest as OngoingActivityChipModel.Shown).icon)
                .isEqualTo(OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon(expectedKey))
            assertThat(
                    ((latest as OngoingActivityChipModel.Shown).icon
                            as OngoingActivityChipModel.ChipIcon.StatusBarNotificationIcon)
                        .notificationKey
                )
                .isEqualTo(expectedKey)
        }
    }
}
+12 −12
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                )
            )

            assertIsNotifChip(latest!!.primary, icon, "notif")
            assertIsNotifChip(latest!!.primary, context, icon, "notif")
            assertThat(latest!!.secondary).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)
        }

@@ -339,8 +339,8 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                )
            )

            assertIsNotifChip(latest!!.primary, firstIcon, "firstNotif")
            assertIsNotifChip(latest!!.secondary, secondIcon, "secondNotif")
            assertIsNotifChip(latest!!.primary, context, firstIcon, "firstNotif")
            assertIsNotifChip(latest!!.secondary, context, secondIcon, "secondNotif")
        }

    @Test
@@ -374,8 +374,8 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
                )
            )

            assertIsNotifChip(latest!!.primary, firstIcon, "firstNotif")
            assertIsNotifChip(latest!!.secondary, secondIcon, "secondNotif")
            assertIsNotifChip(latest!!.primary, context, firstIcon, "firstNotif")
            assertIsNotifChip(latest!!.secondary, context, secondIcon, "secondNotif")
        }

    @Test
@@ -407,7 +407,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            )

            assertIsCallChip(latest!!.primary, callNotificationKey)
            assertIsNotifChip(latest!!.secondary, firstIcon, "firstNotif")
            assertIsNotifChip(latest!!.secondary, context, firstIcon, "firstNotif")
        }

    @Test
@@ -456,7 +456,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.primaryChip)

            assertIsNotifChip(latest, notifIcon, "notif")
            assertIsNotifChip(latest, context, notifIcon, "notif")

            // WHEN the higher priority call chip is added
            callRepo.setOngoingCallState(
@@ -527,7 +527,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            callRepo.setOngoingCallState(OngoingCallModel.NoCall)

            // THEN the lower priority notif is used
            assertIsNotifChip(latest, notifIcon, "notif")
            assertIsNotifChip(latest, context, notifIcon, "notif")
        }

    @Test
@@ -552,7 +552,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            val latest by collectLastValue(underTest.chips)

            assertIsNotifChip(latest!!.primary, notifIcon, "notif")
            assertIsNotifChip(latest!!.primary, context, notifIcon, "notif")
            assertThat(latest!!.secondary).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)

            // WHEN the higher priority call chip is added
@@ -563,7 +563,7 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {
            // THEN the higher priority call chip is used as primary and notif is demoted to
            // secondary
            assertIsCallChip(latest!!.primary, callNotificationKey)
            assertIsNotifChip(latest!!.secondary, notifIcon, "notif")
            assertIsNotifChip(latest!!.secondary, context, notifIcon, "notif")

            // WHEN the higher priority media projection chip is added
            mediaProjectionState.value =
@@ -590,13 +590,13 @@ class OngoingActivityChipsWithNotifsViewModelTest : SysuiTestCase() {

            // THEN media projection and notif remain
            assertIsShareToAppChip(latest!!.primary)
            assertIsNotifChip(latest!!.secondary, notifIcon, "notif")
            assertIsNotifChip(latest!!.secondary, context, notifIcon, "notif")

            // WHEN media projection is dropped
            mediaProjectionState.value = MediaProjectionState.NotProjecting

            // THEN notif is promoted to primary
            assertIsNotifChip(latest!!.primary, notifIcon, "notif")
            assertIsNotifChip(latest!!.primary, context, notifIcon, "notif")
            assertThat(latest!!.secondary).isInstanceOf(OngoingActivityChipModel.Hidden::class.java)
        }

+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {
    private val notifsRepository = kosmos.activeNotificationListRepository
    private val notifsInteractor = kosmos.activeNotificationsInteractor
    private val underTest =
        RenderNotificationListInteractor(notifsRepository, sectionStyleProvider = mock())
        RenderNotificationListInteractor(notifsRepository, sectionStyleProvider = mock(), context)

    @Test
    fun setRenderedList_preservesOrdering() =
Loading