Merge "Include notif suppression in canShowBadge" into rvc-dev am: 3314f72c9e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11727210

Change-Id: I19b788e97a0303843c195c8aecfd1ac1eab124af
This commit is contained in:
Lyn Han
2020-06-04 23:33:52 +00:00
committed by Automerger Merge Worker
2 changed files with 54 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
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
@@ -61,6 +62,10 @@ public class BadgeExtractor implements NotificationSignalExtractor {
record.setShowBadge(false); record.setShowBadge(false);
} }
Notification.BubbleMetadata metadata = record.getNotification().getBubbleMetadata();
if (metadata != null && metadata.isNotificationSuppressed()) {
record.setShowBadge(false);
}
return null; return null;
} }

View File

@@ -29,6 +29,10 @@ import android.app.ActivityManager;
import android.app.Notification; import android.app.Notification;
import android.app.Notification.Builder; import android.app.Notification.Builder;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.drawable.Icon;
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;
@@ -79,6 +83,37 @@ public class BadgeExtractorTest extends UiServiceTestCase {
return r; return r;
} }
private NotificationRecord getNotificationRecordWithBubble(boolean suppressNotif) {
NotificationChannel channel = new NotificationChannel("a", "a", IMPORTANCE_UNSPECIFIED);
channel.setShowBadge(/* showBadge */ true);
when(mConfig.getNotificationChannel(mPkg, mUid, "a", false)).thenReturn(channel);
Notification.BubbleMetadata metadata = new Notification.BubbleMetadata.Builder(
PendingIntent.getActivity(mContext, 0, new Intent(), 0),
Icon.createWithResource("", 0)).build();
int flags = metadata.getFlags();
if (suppressNotif) {
flags |= Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION;
} else {
flags &= ~Notification.BubbleMetadata.FLAG_SUPPRESS_NOTIFICATION;
}
metadata.setFlags(flags);
final Builder builder = new Builder(getContext())
.setContentTitle("foo")
.setSmallIcon(android.R.drawable.sym_def_app_icon)
.setPriority(Notification.PRIORITY_HIGH)
.setDefaults(Notification.DEFAULT_SOUND)
.setBubbleMetadata(metadata);
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
// //
@@ -153,6 +188,20 @@ public class BadgeExtractorTest extends UiServiceTestCase {
assertFalse(r.canShowBadge()); assertFalse(r.canShowBadge());
} }
@Test
public void testHideNotifOverridesYes() throws Exception {
BadgeExtractor extractor = new BadgeExtractor();
extractor.setConfig(mConfig);
when(mConfig.badgingEnabled(mUser)).thenReturn(true);
when(mConfig.canShowBadge(mPkg, mUid)).thenReturn(true);
NotificationRecord r = getNotificationRecordWithBubble(/* suppressNotif */ true);
extractor.process(r);
assertFalse(r.canShowBadge());
}
@Test @Test
public void testDndOverridesYes() { public void testDndOverridesYes() {
BadgeExtractor extractor = new BadgeExtractor(); BadgeExtractor extractor = new BadgeExtractor();