Loading core/java/android/app/Notification.java +10 −16 Original line number Diff line number Diff line Loading @@ -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)) { Loading @@ -6812,14 +6812,6 @@ public class Notification implements Parcelable return FOREGROUND_SERVICE_DEFERRED == mFgsDeferBehavior; } /** * @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 Loading Loading @@ -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; } /** Loading core/tests/coretests/src/android/app/NotificationTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.drawable.Icon; import android.os.Build; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.text.Spannable; Loading Loading @@ -545,6 +546,29 @@ public class NotificationTest { validateColorizedPaletteForColor(Color.BLACK); } @Test public void testIsMediaNotification_nullSession_returnsFalse() { // Null media session Notification.MediaStyle mediaStyle = new Notification.MediaStyle(); Notification notification = new Notification.Builder(mContext, "test id") .setStyle(mediaStyle) .build(); assertFalse(notification.isMediaNotification()); } @Test public void testIsMediaNotification_invalidSession_returnsFalse() { // Extra was set manually to an invalid type Bundle extras = new Bundle(); extras.putParcelable(Notification.EXTRA_MEDIA_SESSION, new Intent()); Notification.MediaStyle mediaStyle = new Notification.MediaStyle(); Notification notification = new Notification.Builder(mContext, "test id") .setStyle(mediaStyle) .addExtras(extras) .build(); assertFalse(notification.isMediaNotification()); } public void validateColorizedPaletteForColor(int rawColor) { Notification.Colors cDay = new Notification.Colors(); Notification.Colors cNight = new Notification.Colors(); Loading packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt +1 −9 Original line number Diff line number Diff line Loading @@ -85,15 +85,7 @@ internal val EMPTY_SMARTSPACE_MEDIA_DATA = SmartspaceMediaData("INVALID", false, "INVALID", null, emptyList(), null, 0) fun isMediaNotification(sbn: StatusBarNotification): Boolean { if (!sbn.notification.hasMediaSession()) { return false } val notificationStyle = sbn.notification.notificationStyle if (Notification.DecoratedMediaCustomViewStyle::class.java.equals(notificationStyle) || Notification.MediaStyle::class.java.equals(notificationStyle)) { return true } return false return sbn.notification.isMediaNotification() } /** Loading packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +1 −1 Original line number Diff line number Diff line Loading @@ -242,7 +242,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback { for (NotificationEntry entry : mNotificationEntryManager.getActiveNotificationsForCurrentUser()) { final Notification notification = entry.getSbn().getNotification(); if (notification.hasMediaSession() if (notification.isMediaNotification() && TextUtils.equals(entry.getSbn().getPackageName(), mPackageName)) { final Icon icon = notification.getLargeIcon(); if (icon == null) { Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -460,7 +460,8 @@ public class NotificationMediaManager implements Dumpable { NotificationEntry mediaNotification = null; MediaController controller = null; for (NotificationEntry entry : allNotifications) { if (entry.isMediaNotification()) { Notification notif = entry.getSbn().getNotification(); if (notif.isMediaNotification()) { final MediaSession.Token token = entry.getSbn().getNotification().extras.getParcelable( Notification.EXTRA_MEDIA_SESSION); Loading Loading
core/java/android/app/Notification.java +10 −16 Original line number Diff line number Diff line Loading @@ -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)) { Loading @@ -6812,14 +6812,6 @@ public class Notification implements Parcelable return FOREGROUND_SERVICE_DEFERRED == mFgsDeferBehavior; } /** * @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 Loading Loading @@ -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; } /** Loading
core/tests/coretests/src/android/app/NotificationTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.drawable.Icon; import android.os.Build; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; import android.text.Spannable; Loading Loading @@ -545,6 +546,29 @@ public class NotificationTest { validateColorizedPaletteForColor(Color.BLACK); } @Test public void testIsMediaNotification_nullSession_returnsFalse() { // Null media session Notification.MediaStyle mediaStyle = new Notification.MediaStyle(); Notification notification = new Notification.Builder(mContext, "test id") .setStyle(mediaStyle) .build(); assertFalse(notification.isMediaNotification()); } @Test public void testIsMediaNotification_invalidSession_returnsFalse() { // Extra was set manually to an invalid type Bundle extras = new Bundle(); extras.putParcelable(Notification.EXTRA_MEDIA_SESSION, new Intent()); Notification.MediaStyle mediaStyle = new Notification.MediaStyle(); Notification notification = new Notification.Builder(mContext, "test id") .setStyle(mediaStyle) .addExtras(extras) .build(); assertFalse(notification.isMediaNotification()); } public void validateColorizedPaletteForColor(int rawColor) { Notification.Colors cDay = new Notification.Colors(); Notification.Colors cNight = new Notification.Colors(); Loading
packages/SystemUI/src/com/android/systemui/media/MediaDataManager.kt +1 −9 Original line number Diff line number Diff line Loading @@ -85,15 +85,7 @@ internal val EMPTY_SMARTSPACE_MEDIA_DATA = SmartspaceMediaData("INVALID", false, "INVALID", null, emptyList(), null, 0) fun isMediaNotification(sbn: StatusBarNotification): Boolean { if (!sbn.notification.hasMediaSession()) { return false } val notificationStyle = sbn.notification.notificationStyle if (Notification.DecoratedMediaCustomViewStyle::class.java.equals(notificationStyle) || Notification.MediaStyle::class.java.equals(notificationStyle)) { return true } return false return sbn.notification.isMediaNotification() } /** Loading
packages/SystemUI/src/com/android/systemui/media/dialog/MediaOutputController.java +1 −1 Original line number Diff line number Diff line Loading @@ -242,7 +242,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback { for (NotificationEntry entry : mNotificationEntryManager.getActiveNotificationsForCurrentUser()) { final Notification notification = entry.getSbn().getNotification(); if (notification.hasMediaSession() if (notification.isMediaNotification() && TextUtils.equals(entry.getSbn().getPackageName(), mPackageName)) { final Icon icon = notification.getLargeIcon(); if (icon == null) { Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationMediaManager.java +2 −1 Original line number Diff line number Diff line Loading @@ -460,7 +460,8 @@ public class NotificationMediaManager implements Dumpable { NotificationEntry mediaNotification = null; MediaController controller = null; for (NotificationEntry entry : allNotifications) { if (entry.isMediaNotification()) { Notification notif = entry.getSbn().getNotification(); if (notif.isMediaNotification()) { final MediaSession.Token token = entry.getSbn().getNotification().extras.getParcelable( Notification.EXTRA_MEDIA_SESSION); Loading