From eb049d0b47d9ef81500c957b431042e2fb26f291 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 23 Jan 2020 12:01:01 -0800 Subject: [PATCH] Bubble API: add support for URI based icons I would ultimately like to restrict icons to be TYPE_URI_ADAPTIVE_BITMAP, however, that would break existing app behaviour. Let's log a warning and hope that we can change it to be one of the URI based icons in the future. Test: atest NotificationManagerTest Bug: 138943209 Bug: 144352570 Change-Id: I044f035571fcaa817b19d8ff330fb22b4addf970 --- core/java/android/app/Notification.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 1af275fedd74c..b346e8f20feb4 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -17,6 +17,8 @@ package android.app; import static android.annotation.Dimension.DP; +import static android.graphics.drawable.Icon.TYPE_URI; +import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP; import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast; @@ -2504,6 +2506,14 @@ public class Notification implements Parcelable } } } + + if (mBubbleMetadata != null && mBubbleMetadata.getBubbleIcon() != null) { + final Icon icon = mBubbleMetadata.getBubbleIcon(); + final int iconType = icon.getType(); + if (iconType == TYPE_URI_ADAPTIVE_BITMAP || iconType == TYPE_URI) { + visitor.accept(icon.getUri()); + } + } } /** @@ -8900,6 +8910,12 @@ public class Notification implements Parcelable if (icon == null) { throw new IllegalArgumentException("Bubbles require non-null icon"); } + if (icon.getType() != TYPE_URI_ADAPTIVE_BITMAP + && icon.getType() != TYPE_URI) { + Log.w(TAG, "Bubbles work best with icons of TYPE_URI or " + + "TYPE_URI_ADAPTIVE_BITMAP. " + + "In the future, using an icon of this type will be required."); + } mShortcutId = null; mPendingIntent = intent; mIcon = icon;