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

Commit 441859af authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge "Remove notification content from icon a11y" into main

parents c4e48028 e55a350c
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.statusbar;

import static android.app.Notification.CATEGORY_CALL;

import static com.google.common.truth.Truth.assertThat;

import static junit.framework.Assert.assertEquals;
@@ -196,6 +198,19 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // no crash, good
    }

    @Test
    public void testContentDescForNotification_noNotifContent() {
        Notification n = new Notification.Builder(mContext, "test")
                .setSmallIcon(0)
                .setContentTitle("hello")
                .setCategory(CATEGORY_CALL)
                .build();
        assertThat(NotificationContentDescription.contentDescForNotification(mContext, n)
                .toString()).startsWith("com.android.systemui.tests notification");
        assertThat(NotificationContentDescription.contentDescForNotification(mContext, n)
                .toString()).doesNotContain("hello");
    }

    @Test
    @EnableFlags({Flags.FLAG_MODES_UI, Flags.FLAG_MODES_UI_ICONS})
    public void setIcon_withPreloaded_usesPreloaded() {
+1 −23
Original line number Diff line number Diff line
@@ -34,31 +34,9 @@ class NotificationContentDescriptionTest : SysuiTestCase() {
    private val TICKER = "this is a ticker"

    @Test
    fun notificationWithAllDifferentFields_descriptionIsTitle() {
    fun notificationWithAllDifferentFields_descriptionIsAppName() {
        val n = createNotification(TITLE, TEXT, TICKER)
        val description = contentDescForNotification(context, n)
        assertThat(description).isEqualTo(createDescriptionText(n, TITLE))
    }

    @Test
    fun notificationWithAllDifferentFields_titleMatchesAppName_descriptionIsText() {
        val n = createNotification(getTestAppName(), TEXT, TICKER)
        val description = contentDescForNotification(context, n)
        assertThat(description).isEqualTo(createDescriptionText(n, TEXT))
    }

    @Test
    fun notificationWithAllDifferentFields_titleMatchesAppNameNoText_descriptionIsTicker() {
        val n = createNotification(getTestAppName(), null, TICKER)
        val description = contentDescForNotification(context, n)
        assertThat(description).isEqualTo(createDescriptionText(n, TICKER))
    }

    @Test
    fun notificationWithAllDifferentFields_titleMatchesAppNameNoTextNoTicker_descriptionEmpty() {
        val appName = getTestAppName()
        val n = createNotification(appName, null, null)
        val description = contentDescForNotification(context, n)
        assertThat(description).isEqualTo(createDescriptionText(n, ""))
    }

+1 −10
Original line number Diff line number Diff line
@@ -28,14 +28,5 @@ import com.android.systemui.res.R
@MainThread
fun contentDescForNotification(c: Context, n: Notification): CharSequence {
    val appName = n.loadHeaderAppName(c) ?: ""
    val title = n.extras?.getCharSequence(Notification.EXTRA_TITLE)
    val text = n.extras?.getCharSequence(Notification.EXTRA_TEXT)
    val ticker = n.tickerText

    // Some apps just put the app name into the title
    val titleOrText = if (TextUtils.equals(title, appName)) text else title
    val desc =
        if (!TextUtils.isEmpty(titleOrText)) titleOrText
        else if (!TextUtils.isEmpty(ticker)) ticker else ""
    return c.getString(R.string.accessibility_desc_notification_icon, appName, desc)
    return c.getString(R.string.accessibility_desc_notification_icon, appName, "")
}