Fix createBitmap exception at high density
createBitmap at high density will cause parcelling exception.
We carete big icon with smaller size.
The width/Height of expected icon
set to minimum of rightIconSize() and icon size.
Bug: 253559604
Test:
- Tested on device, it can pass the following test case.
1. CtsLegacyNotification30TestCases
2. android.app.notification.legacy30.cts.
3. NotificationTemplateApi30Test
#testPromoteBigPicture_withBigLargeIcon
Change-Id: Ib9304b34a4784179c08b76c4fc806244f2dcaf2e
diff --git a/tests/app/src/android/app/cts/NotificationTemplateTest.kt b/tests/app/src/android/app/cts/NotificationTemplateTest.kt
index cf9d092..ff8bf56 100644
--- a/tests/app/src/android/app/cts/NotificationTemplateTest.kt
+++ b/tests/app/src/android/app/cts/NotificationTemplateTest.kt
@@ -424,7 +424,9 @@
return
}
val picture = createBitmap(40, 30)
- val bigIcon = createBitmap(rightIconSize(), rightIconSize() * 3 / 4)
+ val inputWidth = 400
+ val inputHeight = 300
+ val bigIcon = createBitmap(inputWidth, inputHeight)
val builder = Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_media_play)
.setContentTitle("Title")
@@ -433,6 +435,10 @@
.bigLargeIcon(bigIcon)
.showBigPictureWhenCollapsed(true)
)
+
+ val expectedIconWidth = minOf(rightIconSize(), inputWidth)
+ val expectedIconHeight = minOf(rightIconSize() * inputHeight / inputWidth, inputHeight)
+
checkIconView(builder.createContentView()) { iconView ->
assertThat(iconView.visibility).isEqualTo(View.VISIBLE)
assertThat(iconView.width.toFloat())
@@ -446,8 +452,8 @@
assertThat(iconView.width.toFloat())
.isWithin(1f)
.of((iconView.height * 4 / 3).toFloat())
- assertThat(iconView.drawable.intrinsicWidth).isEqualTo(rightIconSize())
- assertThat(iconView.drawable.intrinsicHeight).isEqualTo(rightIconSize() * 3 / 4)
+ assertThat(iconView.drawable.intrinsicWidth).isEqualTo(expectedIconWidth)
+ assertThat(iconView.drawable.intrinsicHeight).isEqualTo(expectedIconHeight)
}
assertThat(builder.build().extras.getParcelable<Bitmap>(Notification.EXTRA_PICTURE)
!!.sameAs(picture)).isTrue()
diff --git a/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/NotificationTemplateApi30Test.kt b/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/NotificationTemplateApi30Test.kt
index b0cd8cb..29638bd 100644
--- a/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/NotificationTemplateApi30Test.kt
+++ b/tests/tests/notificationlegacy/notificationlegacy30/src/android/app/notification/legacy30/cts/NotificationTemplateApi30Test.kt
@@ -168,7 +168,9 @@
return
}
val picture = createBitmap(40, 30)
- val bigIcon = createBitmap(rightIconSize(), rightIconSize() * 3 / 4)
+ val inputWidth = 400
+ val inputHeight = 300
+ val bigIcon = createBitmap(inputWidth, inputHeight)
val builder = Notification.Builder(mContext, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_media_play)
.setContentTitle("Title")
@@ -177,6 +179,10 @@
.bigLargeIcon(bigIcon)
.showBigPictureWhenCollapsed(true)
)
+
+ val expectedIconWidth = minOf(rightIconSize(), inputWidth)
+ val expectedIconHeight = minOf(rightIconSize() * inputHeight / inputWidth, inputHeight)
+
// the promoted big picture is shown with enlarged aspect ratio
checkIconView(builder.createContentView()) { iconView ->
assertThat(iconView.visibility).isEqualTo(View.VISIBLE)
@@ -190,8 +196,8 @@
checkIconView(builder.createBigContentView()) { iconView ->
assertThat(iconView.visibility).isEqualTo(View.VISIBLE)
assertThat(iconView.width).isEqualTo(iconView.height)
- assertThat(iconView.drawable.intrinsicWidth).isEqualTo(rightIconSize())
- assertThat(iconView.drawable.intrinsicHeight).isEqualTo(rightIconSize() * 3 / 4)
+ assertThat(iconView.drawable.intrinsicWidth).isEqualTo(expectedIconWidth)
+ assertThat(iconView.drawable.intrinsicHeight).isEqualTo(expectedIconHeight)
}
}