diff options
| author | 2024-02-13 14:35:08 +0100 | |
|---|---|---|
| committer | 2024-02-15 15:14:03 +0100 | |
| commit | de1feb167b62ce684f24c496de3e48dd669a77d1 (patch) | |
| tree | e27adbd18024bf755469791f7282d089874eeded | |
| parent | 06bceb955bb0bf097e58e020cfdd4f77a912dd93 (diff) | |
Remove recoverBuilder use from test
We removed the usage of recoverBuilder in contentDescForNotification,
but left it in the test. This change removes it from the test as well,
and makes the notification passed to contentDescForNotification non-null
since there's no point in getting a description for a null notification.
I checked the callsites and this should be safe to do.
Bug: 281629927
Test: NotificationContentDescriptionTest
Flag: NONE
Change-Id: I1cea7d0163b5cd87ff3daf159cbec617b335d30d
3 files changed, 25 insertions, 32 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/NotificationContentDescriptionTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/NotificationContentDescriptionTest.kt index f67c70ce783f..12473cb46793 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/NotificationContentDescriptionTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/NotificationContentDescriptionTest.kt @@ -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("", "", "")) + return createNotification("", "", "").loadHeaderAppName(mContext) } - private fun getAppName(n: Notification?) = - n?.let { - val builder = Notification.Builder.recoverBuilder(context, it) - builder.loadHeaderAppName() - } - ?: "" - 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) } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationContentDescription.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationContentDescription.kt index 17fc5c60f74f..bdd9fd032800 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationContentDescription.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationContentDescription.kt @@ -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 diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java index f178046b665a..b6ee46ddafeb 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java @@ -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. |