Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/NotificationContentDescriptionTest.kt +3 −16 Original line number Diff line number Diff line Loading @@ -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) } } packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationContentDescription.kt +5 −5 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +17 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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. Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/NotificationContentDescriptionTest.kt +3 −16 Original line number Diff line number Diff line Loading @@ -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) } }
packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationContentDescription.kt +5 −5 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/StatusBarIconViewTest.java +17 −11 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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 Loading Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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); Loading @@ -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. Loading