Merge "Check media session token type" into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
313b9e923d
@@ -6793,7 +6793,7 @@ public class Notification implements Parcelable
|
|||||||
|
|
||||||
// We show these sorts of notifications immediately in the absence of
|
// We show these sorts of notifications immediately in the absence of
|
||||||
// any explicit app declaration
|
// any explicit app declaration
|
||||||
if (isMediaNotification() || hasMediaSession()
|
if (isMediaNotification()
|
||||||
|| CATEGORY_CALL.equals(category)
|
|| CATEGORY_CALL.equals(category)
|
||||||
|| CATEGORY_NAVIGATION.equals(category)
|
|| CATEGORY_NAVIGATION.equals(category)
|
||||||
|| (actions != null && actions.length > 0)) {
|
|| (actions != null && actions.length > 0)) {
|
||||||
@@ -6812,14 +6812,6 @@ public class Notification implements Parcelable
|
|||||||
return FOREGROUND_SERVICE_DEFERRED == mFgsDeferBehavior;
|
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
|
* @return the style class of this notification
|
||||||
* @hide
|
* @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
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean isMediaNotification() {
|
public boolean isMediaNotification() {
|
||||||
Class<? extends Style> style = getNotificationStyle();
|
Class<? extends Style> style = getNotificationStyle();
|
||||||
if (MediaStyle.class.equals(style)) {
|
boolean isMediaStyle = (MediaStyle.class.equals(style)
|
||||||
return true;
|
|| DecoratedMediaCustomViewStyle.class.equals(style));
|
||||||
} else if (DecoratedMediaCustomViewStyle.class.equals(style)) {
|
|
||||||
return true;
|
boolean hasMediaSession = (extras.getParcelable(Notification.EXTRA_MEDIA_SESSION) != null
|
||||||
}
|
&& extras.getParcelable(Notification.EXTRA_MEDIA_SESSION)
|
||||||
return false;
|
instanceof MediaSession.Token);
|
||||||
|
|
||||||
|
return isMediaStyle && hasMediaSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import android.graphics.BitmapFactory;
|
|||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
@@ -545,6 +546,29 @@ public class NotificationTest {
|
|||||||
validateColorizedPaletteForColor(Color.BLACK);
|
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) {
|
public void validateColorizedPaletteForColor(int rawColor) {
|
||||||
Notification.Colors cDay = new Notification.Colors();
|
Notification.Colors cDay = new Notification.Colors();
|
||||||
Notification.Colors cNight = new Notification.Colors();
|
Notification.Colors cNight = new Notification.Colors();
|
||||||
|
|||||||
@@ -85,15 +85,7 @@ internal val EMPTY_SMARTSPACE_MEDIA_DATA = SmartspaceMediaData("INVALID", false,
|
|||||||
"INVALID", null, emptyList(), null, 0)
|
"INVALID", null, emptyList(), null, 0)
|
||||||
|
|
||||||
fun isMediaNotification(sbn: StatusBarNotification): Boolean {
|
fun isMediaNotification(sbn: StatusBarNotification): Boolean {
|
||||||
if (!sbn.notification.hasMediaSession()) {
|
return sbn.notification.isMediaNotification()
|
||||||
return false
|
|
||||||
}
|
|
||||||
val notificationStyle = sbn.notification.notificationStyle
|
|
||||||
if (Notification.DecoratedMediaCustomViewStyle::class.java.equals(notificationStyle) ||
|
|
||||||
Notification.MediaStyle::class.java.equals(notificationStyle)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ public class MediaOutputController implements LocalMediaManager.DeviceCallback {
|
|||||||
for (NotificationEntry entry
|
for (NotificationEntry entry
|
||||||
: mNotificationEntryManager.getActiveNotificationsForCurrentUser()) {
|
: mNotificationEntryManager.getActiveNotificationsForCurrentUser()) {
|
||||||
final Notification notification = entry.getSbn().getNotification();
|
final Notification notification = entry.getSbn().getNotification();
|
||||||
if (notification.hasMediaSession()
|
if (notification.isMediaNotification()
|
||||||
&& TextUtils.equals(entry.getSbn().getPackageName(), mPackageName)) {
|
&& TextUtils.equals(entry.getSbn().getPackageName(), mPackageName)) {
|
||||||
final Icon icon = notification.getLargeIcon();
|
final Icon icon = notification.getLargeIcon();
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
|
|||||||
@@ -460,7 +460,8 @@ public class NotificationMediaManager implements Dumpable {
|
|||||||
NotificationEntry mediaNotification = null;
|
NotificationEntry mediaNotification = null;
|
||||||
MediaController controller = null;
|
MediaController controller = null;
|
||||||
for (NotificationEntry entry : allNotifications) {
|
for (NotificationEntry entry : allNotifications) {
|
||||||
if (entry.isMediaNotification()) {
|
Notification notif = entry.getSbn().getNotification();
|
||||||
|
if (notif.isMediaNotification()) {
|
||||||
final MediaSession.Token token =
|
final MediaSession.Token token =
|
||||||
entry.getSbn().getNotification().extras.getParcelable(
|
entry.getSbn().getNotification().extras.getParcelable(
|
||||||
Notification.EXTRA_MEDIA_SESSION);
|
Notification.EXTRA_MEDIA_SESSION);
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ public class HighPriorityProvider {
|
|||||||
|
|
||||||
private boolean hasHighPriorityCharacteristics(NotificationEntry entry) {
|
private boolean hasHighPriorityCharacteristics(NotificationEntry entry) {
|
||||||
return !hasUserSetImportance(entry)
|
return !hasUserSetImportance(entry)
|
||||||
&& (entry.getSbn().getNotification().hasMediaSession()
|
&& (entry.getSbn().getNotification().isMediaNotification()
|
||||||
|| isPeopleNotification(entry)
|
|| isPeopleNotification(entry)
|
||||||
|| isMessagingStyle(entry));
|
|| isMessagingStyle(entry));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3182,11 +3182,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
|
|||||||
return getCurrentBottomRoundness() == 0.0f && getCurrentTopRoundness() == 0.0f;
|
return getCurrentBottomRoundness() == 0.0f && getCurrentTopRoundness() == 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: this logic can't depend on layout if we are recycling!
|
|
||||||
public boolean isMediaRow() {
|
public boolean isMediaRow() {
|
||||||
return getExpandedContentView() != null
|
return mEntry.getSbn().getNotification().isMediaNotification();
|
||||||
&& getExpandedContentView().findViewById(
|
|
||||||
com.android.internal.R.id.media_actions) != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTopLevelChild() {
|
public boolean isTopLevelChild() {
|
||||||
|
|||||||
@@ -469,7 +469,7 @@ public class MediaOutputControllerTest extends SysuiTestCase {
|
|||||||
when(entry.getSbn()).thenReturn(sbn);
|
when(entry.getSbn()).thenReturn(sbn);
|
||||||
when(sbn.getNotification()).thenReturn(notification);
|
when(sbn.getNotification()).thenReturn(notification);
|
||||||
when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
||||||
when(notification.hasMediaSession()).thenReturn(true);
|
when(notification.isMediaNotification()).thenReturn(true);
|
||||||
when(notification.getLargeIcon()).thenReturn(null);
|
when(notification.getLargeIcon()).thenReturn(null);
|
||||||
|
|
||||||
assertThat(mMediaOutputController.getNotificationIcon()).isNull();
|
assertThat(mMediaOutputController.getNotificationIcon()).isNull();
|
||||||
@@ -489,7 +489,7 @@ public class MediaOutputControllerTest extends SysuiTestCase {
|
|||||||
when(entry.getSbn()).thenReturn(sbn);
|
when(entry.getSbn()).thenReturn(sbn);
|
||||||
when(sbn.getNotification()).thenReturn(notification);
|
when(sbn.getNotification()).thenReturn(notification);
|
||||||
when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
||||||
when(notification.hasMediaSession()).thenReturn(true);
|
when(notification.isMediaNotification()).thenReturn(true);
|
||||||
when(notification.getLargeIcon()).thenReturn(icon);
|
when(notification.getLargeIcon()).thenReturn(icon);
|
||||||
|
|
||||||
assertThat(mMediaOutputController.getNotificationIcon() instanceof IconCompat).isTrue();
|
assertThat(mMediaOutputController.getNotificationIcon() instanceof IconCompat).isTrue();
|
||||||
@@ -509,7 +509,7 @@ public class MediaOutputControllerTest extends SysuiTestCase {
|
|||||||
when(entry.getSbn()).thenReturn(sbn);
|
when(entry.getSbn()).thenReturn(sbn);
|
||||||
when(sbn.getNotification()).thenReturn(notification);
|
when(sbn.getNotification()).thenReturn(notification);
|
||||||
when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
when(sbn.getPackageName()).thenReturn(TEST_PACKAGE_NAME);
|
||||||
when(notification.hasMediaSession()).thenReturn(false);
|
when(notification.isMediaNotification()).thenReturn(false);
|
||||||
when(notification.getLargeIcon()).thenReturn(icon);
|
when(notification.getLargeIcon()).thenReturn(icon);
|
||||||
|
|
||||||
assertThat(mMediaOutputController.getNotificationIcon()).isNull();
|
assertThat(mMediaOutputController.getNotificationIcon()).isNull();
|
||||||
|
|||||||
@@ -69,11 +69,8 @@ public class BadgeExtractor implements NotificationSignalExtractor {
|
|||||||
|
|
||||||
if (mConfig.isMediaNotificationFilteringEnabled()) {
|
if (mConfig.isMediaNotificationFilteringEnabled()) {
|
||||||
final Notification notif = record.getNotification();
|
final Notification notif = record.getNotification();
|
||||||
if (notif.hasMediaSession()) {
|
if (notif.isMediaNotification()) {
|
||||||
if (notif.isStyle(Notification.DecoratedMediaCustomViewStyle.class)
|
record.setShowBadge(false);
|
||||||
|| notif.isStyle(Notification.MediaStyle.class)) {
|
|
||||||
record.setShowBadge(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ public class NotificationComparator
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMediaNotification(NotificationRecord record) {
|
private boolean isMediaNotification(NotificationRecord record) {
|
||||||
return record.getNotification().hasMediaSession();
|
return record.getNotification().isMediaNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isCallCategory(NotificationRecord record) {
|
private boolean isCallCategory(NotificationRecord record) {
|
||||||
|
|||||||
Reference in New Issue
Block a user