summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/java/android/app/Notification.java12
-rw-r--r--core/res/res/values/dimens.xml4
-rw-r--r--core/res/res/values/symbols.xml2
-rw-r--r--core/tests/coretests/src/android/app/NotificationTest.java17
4 files changed, 35 insertions, 0 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 779552f1bbed..d57c288165d5 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -6712,6 +6712,18 @@ public class Notification implements Parcelable
return;
}
boolean isLowRam = ActivityManager.isLowRamDeviceStatic();
+
+ if (mSmallIcon != null
+ // Only bitmap icons can be downscaled.
+ && (mSmallIcon.getType() == Icon.TYPE_BITMAP
+ || mSmallIcon.getType() == Icon.TYPE_ADAPTIVE_BITMAP)) {
+ Resources resources = context.getResources();
+ int maxSize = resources.getDimensionPixelSize(
+ isLowRam ? R.dimen.notification_small_icon_size_low_ram
+ : R.dimen.notification_small_icon_size);
+ mSmallIcon.scaleDownIfNecessary(maxSize, maxSize);
+ }
+
if (mLargeIcon != null || largeIcon != null) {
Resources resources = context.getResources();
Class<? extends Style> style = getNotificationStyle();
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 3f08e4b9d9ad..d374b74aa947 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -755,6 +755,8 @@
<dimen name="item_touch_helper_swipe_escape_velocity">120dp</dimen>
<dimen name="item_touch_helper_swipe_escape_max_velocity">800dp</dimen>
+ <!-- The maximum size of the small notification icon. -->
+ <dimen name="notification_small_icon_size">48dp</dimen>
<!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. This value is determined by the maximum notification height -->
<dimen name="notification_custom_view_max_image_height">284dp</dimen>
<!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. This value is determined a maximum notification width -->
@@ -779,6 +781,8 @@
<!-- The alpha of a disabled notification button -->
<item type="dimen" format="float" name="notification_action_disabled_alpha">0.5</item>
+ <!-- The maximum size of the small notification icon on low memory devices. -->
+ <dimen name="notification_small_icon_size_low_ram">@dimen/notification_small_icon_size</dimen>
<!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. -->
<dimen name="notification_custom_view_max_image_height_low_ram">208dp</dimen>
<!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. -->
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 3ce6b6ce539b..6ae2829124b7 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3561,6 +3561,7 @@
<java-symbol type="style" name="Theme.DeviceDefault.Autofill.Save" />
<java-symbol type="style" name="Theme.DeviceDefault.Light.Autofill.Save" />
+ <java-symbol type="dimen" name="notification_small_icon_size"/>
<java-symbol type="dimen" name="notification_big_picture_max_height"/>
<java-symbol type="dimen" name="notification_big_picture_max_width"/>
<java-symbol type="dimen" name="notification_right_icon_size"/>
@@ -3569,6 +3570,7 @@
<java-symbol type="dimen" name="notification_custom_view_max_image_height"/>
<java-symbol type="dimen" name="notification_custom_view_max_image_width"/>
+ <java-symbol type="dimen" name="notification_small_icon_size_low_ram"/>
<java-symbol type="dimen" name="notification_big_picture_max_height_low_ram"/>
<java-symbol type="dimen" name="notification_big_picture_max_width_low_ram"/>
<java-symbol type="dimen" name="notification_right_icon_size_low_ram"/>
diff --git a/core/tests/coretests/src/android/app/NotificationTest.java b/core/tests/coretests/src/android/app/NotificationTest.java
index 37cf514e92ea..e6d23643e8c0 100644
--- a/core/tests/coretests/src/android/app/NotificationTest.java
+++ b/core/tests/coretests/src/android/app/NotificationTest.java
@@ -39,6 +39,7 @@ import android.content.Intent;
import android.content.LocusId;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
+import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.Icon;
@@ -504,6 +505,22 @@ public class NotificationTest {
}
@Test
+ public void testBuild_ensureSmallIconIsNotTooBig_resizesIcon() {
+ Icon hugeIcon = Icon.createWithBitmap(
+ Bitmap.createBitmap(3000, 3000, Bitmap.Config.ARGB_8888));
+ Notification notification = new Notification.Builder(mContext, "Channel").setSmallIcon(
+ hugeIcon).build();
+
+ Bitmap smallNotificationIcon = notification.getSmallIcon().getBitmap();
+ assertThat(smallNotificationIcon.getWidth()).isEqualTo(
+ mContext.getResources().getDimensionPixelSize(
+ R.dimen.notification_small_icon_size));
+ assertThat(smallNotificationIcon.getHeight()).isEqualTo(
+ mContext.getResources().getDimensionPixelSize(
+ R.dimen.notification_small_icon_size));
+ }
+
+ @Test
public void testColors_ensureColors_dayMode_producesValidPalette() {
Notification.Colors c = new Notification.Colors();
boolean colorized = false;