diff options
| author | Beth Thibodeau <ethibodeau@google.com> | 2021-11-12 17:12:19 -0500 |
|---|---|---|
| committer | Beth Thibodeau <ethibodeau@google.com> | 2021-11-17 11:18:35 -0500 |
| commit | e91aa6cb7d70e095c59f9bbd96efe42efbb7e243 (patch) | |
| tree | 75472f662bccdda46d2645c194c0ac0d5f3228f8 /core/java/android | |
| parent | 2ab2685ccaf91de0711faa816dfb9e1b2cc40701 (diff) | |
Check media session token type
When checking whether a notification has a media session, make sure that
the value in the extra is the correct type.
In addition, moves this check inside of
Notification#isMediaNotification for consistency - existing usages either
already checked both or will not be impacted, given that valid MediaStyle
notifications are now shown in the media carousel instead of with other
notifications in the shade.
Fixes: 205570941
Test: atest
Test: manual, repro case in bug
Change-Id: I5d0134d2ce81e9e6a2ed16748f84252bf765a1c9
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/app/Notification.java | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 61b1abe25ca2..9605cbdb48c6 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -6793,7 +6793,7 @@ public class Notification implements Parcelable // We show these sorts of notifications immediately in the absence of // any explicit app declaration - if (isMediaNotification() || hasMediaSession() + if (isMediaNotification() || CATEGORY_CALL.equals(category) || CATEGORY_NAVIGATION.equals(category) || (actions != null && actions.length > 0)) { @@ -6813,14 +6813,6 @@ public class Notification implements Parcelable } /** - * @return whether this notification has a media session attached - * @hide - */ - public boolean hasMediaSession() { - return extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null; - } - - /** * @return the style class of this notification * @hide */ @@ -6863,18 +6855,20 @@ public class Notification implements Parcelable } /** - * @return true if this is a media notification + * @return true if this is a media style notification with a media session * * @hide */ public boolean isMediaNotification() { Class<? extends Style> style = getNotificationStyle(); - if (MediaStyle.class.equals(style)) { - return true; - } else if (DecoratedMediaCustomViewStyle.class.equals(style)) { - return true; - } - return false; + boolean isMediaStyle = (MediaStyle.class.equals(style) + || DecoratedMediaCustomViewStyle.class.equals(style)); + + boolean hasMediaSession = (extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null + && extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) + instanceof MediaSession.Token); + + return isMediaStyle && hasMediaSession; } /** |
