Merge "Don't show badge for media style notifications" into rvc-dev am: e0034ad1c5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11923800 Change-Id: I166a7bbaa6450431209cd5b9cf4875f64a3378e0
This commit is contained in:
@@ -17,9 +17,9 @@ package com.android.server.notification;
|
|||||||
|
|
||||||
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
|
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
import android.app.Notification;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether a badge should be shown for this notification
|
* Determines whether a badge should be shown for this notification
|
||||||
@@ -66,6 +66,17 @@ public class BadgeExtractor implements NotificationSignalExtractor {
|
|||||||
if (metadata != null && metadata.isNotificationSuppressed()) {
|
if (metadata != null && metadata.isNotificationSuppressed()) {
|
||||||
record.setShowBadge(false);
|
record.setShowBadge(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mConfig.isMediaNotificationFilteringEnabled()) {
|
||||||
|
final Notification notif = record.getNotification();
|
||||||
|
if (notif.hasMediaSession()) {
|
||||||
|
Class<? extends Notification.Style> notifStyle = notif.getNotificationStyle();
|
||||||
|
if (Notification.DecoratedMediaCustomViewStyle.class.equals(notifStyle)
|
||||||
|
|| Notification.MediaStyle.class.equals(notifStyle)) {
|
||||||
|
record.setShowBadge(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1621,7 +1621,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
= Settings.Global.getUriFor(Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE);
|
= Settings.Global.getUriFor(Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE);
|
||||||
private final Uri NOTIFICATION_HISTORY_ENABLED
|
private final Uri NOTIFICATION_HISTORY_ENABLED
|
||||||
= Settings.Secure.getUriFor(Settings.Secure.NOTIFICATION_HISTORY_ENABLED);
|
= Settings.Secure.getUriFor(Settings.Secure.NOTIFICATION_HISTORY_ENABLED);
|
||||||
|
private final Uri NOTIFICATION_SHOW_MEDIA_ON_QUICK_SETTINGS_URI
|
||||||
|
= Settings.Global.getUriFor(Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS);
|
||||||
|
|
||||||
SettingsObserver(Handler handler) {
|
SettingsObserver(Handler handler) {
|
||||||
super(handler);
|
super(handler);
|
||||||
@@ -1639,6 +1640,8 @@ public class NotificationManagerService extends SystemService {
|
|||||||
false, this, UserHandle.USER_ALL);
|
false, this, UserHandle.USER_ALL);
|
||||||
resolver.registerContentObserver(NOTIFICATION_HISTORY_ENABLED,
|
resolver.registerContentObserver(NOTIFICATION_HISTORY_ENABLED,
|
||||||
false, this, UserHandle.USER_ALL);
|
false, this, UserHandle.USER_ALL);
|
||||||
|
resolver.registerContentObserver(NOTIFICATION_SHOW_MEDIA_ON_QUICK_SETTINGS_URI,
|
||||||
|
false, this, UserHandle.USER_ALL);
|
||||||
update(null);
|
update(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1675,6 +1678,9 @@ public class NotificationManagerService extends SystemService {
|
|||||||
Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0) == 1);
|
Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0) == 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (uri == null || NOTIFICATION_SHOW_MEDIA_ON_QUICK_SETTINGS_URI.equals(uri)) {
|
||||||
|
mPreferencesHelper.updateMediaNotificationFilteringEnabled();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ public class PreferencesHelper implements RankingConfig {
|
|||||||
static final boolean DEFAULT_GLOBAL_ALLOW_BUBBLE = true;
|
static final boolean DEFAULT_GLOBAL_ALLOW_BUBBLE = true;
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int DEFAULT_BUBBLE_PREFERENCE = BUBBLE_PREFERENCE_NONE;
|
static final int DEFAULT_BUBBLE_PREFERENCE = BUBBLE_PREFERENCE_NONE;
|
||||||
|
static final boolean DEFAULT_MEDIA_NOTIFICATION_FILTERING = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default value for what fields are user locked. See {@link LockableAppFields} for all lockable
|
* Default value for what fields are user locked. See {@link LockableAppFields} for all lockable
|
||||||
@@ -165,6 +166,7 @@ public class PreferencesHelper implements RankingConfig {
|
|||||||
|
|
||||||
private SparseBooleanArray mBadgingEnabled;
|
private SparseBooleanArray mBadgingEnabled;
|
||||||
private boolean mBubblesEnabledGlobally = DEFAULT_GLOBAL_ALLOW_BUBBLE;
|
private boolean mBubblesEnabledGlobally = DEFAULT_GLOBAL_ALLOW_BUBBLE;
|
||||||
|
private boolean mIsMediaNotificationFilteringEnabled = DEFAULT_MEDIA_NOTIFICATION_FILTERING;
|
||||||
private boolean mAreChannelsBypassingDnd;
|
private boolean mAreChannelsBypassingDnd;
|
||||||
private boolean mHideSilentStatusBarIcons = DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS;
|
private boolean mHideSilentStatusBarIcons = DEFAULT_HIDE_SILENT_STATUS_BAR_ICONS;
|
||||||
|
|
||||||
@@ -184,6 +186,7 @@ public class PreferencesHelper implements RankingConfig {
|
|||||||
|
|
||||||
updateBadgingEnabled();
|
updateBadgingEnabled();
|
||||||
updateBubblesEnabled();
|
updateBubblesEnabled();
|
||||||
|
updateMediaNotificationFilteringEnabled();
|
||||||
syncChannelsBypassingDnd(mContext.getUserId());
|
syncChannelsBypassingDnd(mContext.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2289,6 +2292,21 @@ public class PreferencesHelper implements RankingConfig {
|
|||||||
return mBubblesEnabledGlobally;
|
return mBubblesEnabledGlobally;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Requests check of the feature setting for showing media notifications in quick settings. */
|
||||||
|
public void updateMediaNotificationFilteringEnabled() {
|
||||||
|
final boolean newValue = Settings.Global.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1) > 0;
|
||||||
|
if (newValue != mIsMediaNotificationFilteringEnabled) {
|
||||||
|
mIsMediaNotificationFilteringEnabled = newValue;
|
||||||
|
updateConfig();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns true if the setting is enabled for showing media notifications in quick settings. */
|
||||||
|
public boolean isMediaNotificationFilteringEnabled() {
|
||||||
|
return mIsMediaNotificationFilteringEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
public void updateBadgingEnabled() {
|
public void updateBadgingEnabled() {
|
||||||
if (mBadgingEnabled == null) {
|
if (mBadgingEnabled == null) {
|
||||||
mBadgingEnabled = new SparseBooleanArray();
|
mBadgingEnabled = new SparseBooleanArray();
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ public interface RankingConfig {
|
|||||||
boolean badgingEnabled(UserHandle userHandle);
|
boolean badgingEnabled(UserHandle userHandle);
|
||||||
int getBubblePreference(String packageName, int uid);
|
int getBubblePreference(String packageName, int uid);
|
||||||
boolean bubblesEnabled();
|
boolean bubblesEnabled();
|
||||||
|
/** Returns true when feature is enabled that shows media notifications in quick settings. */
|
||||||
|
boolean isMediaNotificationFilteringEnabled();
|
||||||
boolean isGroupBlocked(String packageName, int uid, String groupId);
|
boolean isGroupBlocked(String packageName, int uid, String groupId);
|
||||||
|
|
||||||
Collection<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
|
Collection<NotificationChannelGroup> getNotificationChannelGroups(String pkg,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import android.app.NotificationChannel;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
|
import android.media.session.MediaSession;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
@@ -114,6 +114,31 @@ public class BadgeExtractorTest extends UiServiceTestCase {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private NotificationRecord getNotificationRecordWithMedia(boolean excludeSession) {
|
||||||
|
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_UNSPECIFIED);
|
||||||
|
channel.setShowBadge(/* showBadge */ true);
|
||||||
|
when(mConfig.getNotificationChannel(mPkg, mUid, "a", false)).thenReturn(channel);
|
||||||
|
|
||||||
|
Notification.MediaStyle style = new Notification.MediaStyle();
|
||||||
|
if (!excludeSession) {
|
||||||
|
MediaSession session = new MediaSession(getContext(), "BadgeExtractorTestSession");
|
||||||
|
style.setMediaSession(session.getSessionToken());
|
||||||
|
}
|
||||||
|
|
||||||
|
final Builder builder = new Builder(getContext())
|
||||||
|
.setContentTitle("foo")
|
||||||
|
.setSmallIcon(android.R.drawable.sym_def_app_icon)
|
||||||
|
.setPriority(Notification.PRIORITY_HIGH)
|
||||||
|
.setDefaults(Notification.DEFAULT_SOUND)
|
||||||
|
.setStyle(style);
|
||||||
|
|
||||||
|
Notification n = builder.build();
|
||||||
|
StatusBarNotification sbn = new StatusBarNotification(mPkg, mPkg, mId, mTag, mUid,
|
||||||
|
mPid, n, mUser, null, System.currentTimeMillis());
|
||||||
|
NotificationRecord r = new NotificationRecord(getContext(), sbn, channel);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Tests
|
// Tests
|
||||||
//
|
//
|
||||||
@@ -202,6 +227,66 @@ public class BadgeExtractorTest extends UiServiceTestCase {
|
|||||||
assertFalse(r.canShowBadge());
|
assertFalse(r.canShowBadge());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHideMediaNotifOverridesYes() throws Exception {
|
||||||
|
BadgeExtractor extractor = new BadgeExtractor();
|
||||||
|
extractor.setConfig(mConfig);
|
||||||
|
when(mConfig.badgingEnabled(mUser)).thenReturn(true);
|
||||||
|
when(mConfig.canShowBadge(mPkg, mUid)).thenReturn(true);
|
||||||
|
|
||||||
|
when(mConfig.isMediaNotificationFilteringEnabled()).thenReturn(true);
|
||||||
|
NotificationRecord r = getNotificationRecordWithMedia(/* excludeSession */ false);
|
||||||
|
|
||||||
|
extractor.process(r);
|
||||||
|
|
||||||
|
assertFalse(r.canShowBadge());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHideMediaNotifDisabledOverridesNo() throws Exception {
|
||||||
|
BadgeExtractor extractor = new BadgeExtractor();
|
||||||
|
extractor.setConfig(mConfig);
|
||||||
|
when(mConfig.badgingEnabled(mUser)).thenReturn(true);
|
||||||
|
when(mConfig.canShowBadge(mPkg, mUid)).thenReturn(true);
|
||||||
|
|
||||||
|
when(mConfig.isMediaNotificationFilteringEnabled()).thenReturn(false);
|
||||||
|
NotificationRecord r = getNotificationRecordWithMedia(/* excludeSession */ false);
|
||||||
|
|
||||||
|
extractor.process(r);
|
||||||
|
|
||||||
|
assertTrue(r.canShowBadge());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHideMediaNotifNoSessionOverridesNo() throws Exception {
|
||||||
|
BadgeExtractor extractor = new BadgeExtractor();
|
||||||
|
extractor.setConfig(mConfig);
|
||||||
|
when(mConfig.badgingEnabled(mUser)).thenReturn(true);
|
||||||
|
when(mConfig.canShowBadge(mPkg, mUid)).thenReturn(true);
|
||||||
|
|
||||||
|
when(mConfig.isMediaNotificationFilteringEnabled()).thenReturn(true);
|
||||||
|
NotificationRecord r = getNotificationRecordWithMedia(/* excludeSession */ true);
|
||||||
|
|
||||||
|
extractor.process(r);
|
||||||
|
|
||||||
|
assertTrue(r.canShowBadge());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHideMediaNotifNotMediaStyleOverridesNo() throws Exception {
|
||||||
|
BadgeExtractor extractor = new BadgeExtractor();
|
||||||
|
extractor.setConfig(mConfig);
|
||||||
|
when(mConfig.badgingEnabled(mUser)).thenReturn(true);
|
||||||
|
when(mConfig.canShowBadge(mPkg, mUid)).thenReturn(true);
|
||||||
|
|
||||||
|
when(mConfig.isMediaNotificationFilteringEnabled()).thenReturn(true);
|
||||||
|
NotificationRecord r = getNotificationRecord(true, IMPORTANCE_UNSPECIFIED);
|
||||||
|
|
||||||
|
extractor.process(r);
|
||||||
|
|
||||||
|
assertTrue(r.canShowBadge());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDndOverridesYes() {
|
public void testDndOverridesYes() {
|
||||||
BadgeExtractor extractor = new BadgeExtractor();
|
BadgeExtractor extractor = new BadgeExtractor();
|
||||||
|
|||||||
@@ -2124,6 +2124,22 @@ public class PreferencesHelperTest extends UiServiceTestCase {
|
|||||||
assertFalse(mHelper.bubblesEnabled());
|
assertFalse(mHelper.bubblesEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowQSMediaOverrideTrue() {
|
||||||
|
Global.putInt(getContext().getContentResolver(),
|
||||||
|
Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 1);
|
||||||
|
mHelper.updateMediaNotificationFilteringEnabled(); // would be called by settings observer
|
||||||
|
assertTrue(mHelper.isMediaNotificationFilteringEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testShowQSMediaOverrideFalse() {
|
||||||
|
Global.putInt(getContext().getContentResolver(),
|
||||||
|
Global.SHOW_MEDIA_ON_QUICK_SETTINGS, 0);
|
||||||
|
mHelper.updateMediaNotificationFilteringEnabled(); // would be called by settings observer
|
||||||
|
assertFalse(mHelper.isMediaNotificationFilteringEnabled());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnLocaleChanged_updatesDefaultChannels() throws Exception {
|
public void testOnLocaleChanged_updatesDefaultChannels() throws Exception {
|
||||||
String newLabel = "bananas!";
|
String newLabel = "bananas!";
|
||||||
|
|||||||
Reference in New Issue
Block a user