Merge "Include notif suppression in canShowBadge" into rvc-dev
This commit is contained in:
@@ -19,6 +19,7 @@ import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_BADGE;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Slog;
|
||||
import android.app.Notification;
|
||||
|
||||
/**
|
||||
* Determines whether a badge should be shown for this notification
|
||||
@@ -61,6 +62,10 @@ public class BadgeExtractor implements NotificationSignalExtractor {
|
||||
record.setShowBadge(false);
|
||||
}
|
||||
|
||||
Notification.BubbleMetadata metadata = record.getNotification().getBubbleMetadata();
|
||||
if (metadata != null && metadata.isNotificationSuppressed()) {
|
||||
record.setShowBadge(false);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,10 @@ import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.app.Notification.Builder;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Icon;
|
||||
|
||||
import android.os.UserHandle;
|
||||
import android.service.notification.StatusBarNotification;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
@@ -79,6 +83,37 @@ public class BadgeExtractorTest extends UiServiceTestCase {
|
||||
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
|
||||
//
|
||||
@@ -153,6 +188,20 @@ public class BadgeExtractorTest extends UiServiceTestCase {
|
||||
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
|
||||
public void testDndOverridesYes() {
|
||||
BadgeExtractor extractor = new BadgeExtractor();
|
||||
|
||||
Reference in New Issue
Block a user