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

Commit c928d999 authored by Ioana Alexandru's avatar Ioana Alexandru Committed by Android (Google) Code Review
Browse files

Merge "Remove recoverBuilder use from test" into main

parents 882ec9a6 de1feb16
Loading
Loading
Loading
Loading
+3 −16
Original line number Diff line number Diff line
@@ -62,36 +62,23 @@ class NotificationContentDescriptionTest : SysuiTestCase() {
        assertThat(description).isEqualTo(createDescriptionText(n, ""))
    }

    @Test
    fun nullNotification_descriptionIsAppName() {
        val description = contentDescForNotification(context, null)
        assertThat(description).isEqualTo(createDescriptionText(null, ""))
    }

    private fun createNotification(
        title: String? = null,
        text: String? = null,
        ticker: String? = null
    ): Notification =
        Notification.Builder(context)
        Notification.Builder(context, "channel")
            .setContentTitle(title)
            .setContentText(text)
            .setTicker(ticker)
            .build()

    private fun getTestAppName(): String {
        return getAppName(createNotification("", "", ""))
    }

    private fun getAppName(n: Notification?) =
        n?.let {
            val builder = Notification.Builder.recoverBuilder(context, it)
            builder.loadHeaderAppName()
        return createNotification("", "", "").loadHeaderAppName(mContext)
    }
            ?: ""

    private fun createDescriptionText(n: Notification?, desc: String?): String {
        val appName = getAppName(n)
        val appName = n?.loadHeaderAppName(mContext)
        return context.getString(R.string.accessibility_desc_notification_icon, appName, desc)
    }
}
+5 −5
Original line number Diff line number Diff line
@@ -26,11 +26,11 @@ import com.android.systemui.res.R

/** Returns accessibility content description for a given notification. */
@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
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
+17 −11
Original line number Diff line number Diff line
@@ -52,8 +52,8 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.res.R;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.notification.NotificationContentDescription;

import org.junit.Before;
@@ -153,7 +153,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        Icon icon = Icon.createWithBitmap(bitmap);
        StatusBarIcon largeIcon = new StatusBarIcon(UserHandle.ALL, "mockPackage",
                icon, 0, 0, "");
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        mIconView.getIcon(largeIcon);
        // no crash? good

@@ -196,7 +196,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 60x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, dpIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 50x50. When put the drawable into iconView whose
        // layout size is 60x150, the drawable size would not be constrained and thus keep 50x50
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 50);
@@ -215,7 +215,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 60x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, dpIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 50x100. When put the drawable into iconView whose
        // layout size is 60x150, the drawable size would not be constrained and thus keep 50x100
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 100);
@@ -235,7 +235,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 60x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, dpIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 100x50. When put the drawable into iconView whose
        // layout size is 60x150, the drawable size would be constrained to 60x30
        setIconDrawableWithSize(/* width= */ 100, /* height= */ 50);
@@ -257,7 +257,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 40x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 50x50. When put the drawable into iconView whose
        // layout size is 40x150, the drawable size would be constrained to 40x40
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 50);
@@ -283,7 +283,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 40x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 70x70. When put the drawable into iconView whose
        // layout size is 40x150, the drawable size would be constrained to 40x40
        setIconDrawableWithSize(/* width= */ 70, /* height= */ 70);
@@ -310,7 +310,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 40x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 50x100. When put the drawable into iconView whose
        // layout size is 40x150, the drawable size would be constrained to 40x80
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 100);
@@ -334,7 +334,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 80x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 50x50. When put the drawable into iconView whose
        // layout size is 80x150, the drawable size would not be constrained and thus keep 50x50
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 50);
@@ -357,7 +357,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 80x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 50x100. When put the drawable into iconView whose
        // layout size is 80x150, the drawable size would not be constrained and thus keep 50x100
        setIconDrawableWithSize(/* width= */ 50, /* height= */ 100);
@@ -381,7 +381,7 @@ public class StatusBarIconViewTest extends SysuiTestCase {
        // the icon view layout size would be 80x150
        //   (the height is always 150 due to TEST_STATUS_BAR_HEIGHT)
        setUpIconView(dpIconSize, dpDrawingSize, spIconSize);
        mIconView.setNotification(mock(StatusBarNotification.class));
        mIconView.setNotification(getMockSbn());
        // the raw drawable size is 100x50. When put the drawable into iconView whose
        // layout size is 80x150, the drawable size would not be constrained and thus keep 80x40
        setIconDrawableWithSize(/* width= */ 100, /* height= */ 50);
@@ -397,6 +397,12 @@ public class StatusBarIconViewTest extends SysuiTestCase {
                mIconView.getIconScale(), 0.01f);
    }

    private static StatusBarNotification getMockSbn() {
        StatusBarNotification sbn = mock(StatusBarNotification.class);
        when(sbn.getNotification()).thenReturn(mock(Notification.class));
        return sbn;
    }

    /**
     * Setup iconView dimens for testing. The result icon view layout width would
     * be spIconSize and height would be 150.