summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mady Mellor <madym@google.com> 2020-01-23 16:19:16 -0800
committer Mady Mellor <madym@google.com> 2020-01-23 17:43:23 -0800
commit05610cf0ff4d4723fec025fd857c8c6c1a1c47ad (patch)
treee11b252c3178efc7a6177e881fffb4845537a6ed
parentba5a5356407631c761fcf0bf67fc986588c9b33b (diff)
Bubbles / notifs / shortcuts: if the id's don't match throw an error
It'd be weird if developers could specify different shortcut id's for the bubble and the notification, so let's throw if they don't match. Test: atest NotificationTest (needs the CTS CL) Bug: 144352570 Bug: 138116133 Change-Id: I31106be6b278a2e599b100adf143bcfba8a9786d
-rw-r--r--core/java/android/app/Notification.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 3c4e861d55f8..1c85087f90cd 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -3534,8 +3534,16 @@ public class Notification implements Parcelable
* This field will be ignored by Launchers that don't support badging, don't show
* notification content, or don't show {@link android.content.pm.ShortcutManager shortcuts}.
*
+ * If this notification has {@link BubbleMetadata} attached that was created with
+ * {@link BubbleMetadata.Builder#createShortcutBubble(String)} a check will be performed
+ * to ensure the shortcutId supplied to bubble metadata matches the shortcutId set here,
+ * if one was set. If the shortcutId's were specified but do not match, an exception
+ * is thrown.
+ *
* @param shortcutId the {@link ShortcutInfo#getId() id} of the shortcut this notification
* supersedes
+ *
+ * @see BubbleMetadata.Builder#createShortcutBubble(String)
*/
@NonNull
public Builder setShortcutId(String shortcutId) {
@@ -5865,9 +5873,29 @@ public class Notification implements Parcelable
/**
* Combine all of the options that have been set and return a new {@link Notification}
* object.
+ *
+ * If this notification has {@link BubbleMetadata} attached that was created with
+ * {@link BubbleMetadata.Builder#createShortcutBubble(String)} a check will be performed
+ * to ensure the shortcutId supplied to bubble metadata matches the shortcutId set on the
+ * notification builder, if one was set. If the shortcutId's were specified but do not
+ * match, an exception is thrown here.
+ *
+ * @see BubbleMetadata.Builder#createShortcutBubble(String)
+ * @see #setShortcutId(String)
*/
@NonNull
public Notification build() {
+ // Check shortcut id matches
+ if (mN.mShortcutId != null
+ && mN.mBubbleMetadata != null
+ && mN.mBubbleMetadata.getShortcutId() != null
+ && !mN.mShortcutId.equals(mN.mBubbleMetadata.getShortcutId())) {
+ throw new IllegalArgumentException(
+ "Notification and BubbleMetadata shortcut id's don't match,"
+ + " notification: " + mN.mShortcutId
+ + " vs bubble: " + mN.mBubbleMetadata.getShortcutId());
+ }
+
// first, add any extras from the calling code
if (mUserExtras != null) {
mN.extras = getAllExtras();