From 98f6e69f32dfdfd3fbc17dd977858d354a4bc27e Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Tue, 29 Jan 2019 16:31:56 -0500 Subject: [PATCH] Don't recommend downranking _HIGH notifications Test: atest Change-Id: Iede3988e97e9205d64c67d26e10c84db0a550158 Fixes: 123586747 --- .../services/notification/NotificationCategorizer.java | 6 +++++- .../notification/NotificationCategorizerTest.java | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/ExtServices/src/android/ext/services/notification/NotificationCategorizer.java b/packages/ExtServices/src/android/ext/services/notification/NotificationCategorizer.java index 1f4ba0150dc16..7ba0f7ac1d30b 100644 --- a/packages/ExtServices/src/android/ext/services/notification/NotificationCategorizer.java +++ b/packages/ExtServices/src/android/ext/services/notification/NotificationCategorizer.java @@ -45,12 +45,13 @@ public class NotificationCategorizer { protected static final int CATEGORY_PEOPLE = 4; protected static final int CATEGORY_ALARM = 5; protected static final int CATEGORY_CALL = 6; + protected static final int CATEGORY_HIGH = 7; /** @hide */ @IntDef(prefix = { "CATEGORY_" }, value = { CATEGORY_MIN, CATEGORY_EVERYTHING_ELSE, CATEGORY_ONGOING, CATEGORY_CALL, CATEGORY_SYSTEM_LOW, CATEGORY_EVENT, CATEGORY_REMINDER, CATEGORY_SYSTEM, - CATEGORY_PEOPLE, CATEGORY_ALARM + CATEGORY_PEOPLE, CATEGORY_ALARM, CATEGORY_HIGH }) @Retention(RetentionPolicy.SOURCE) public @interface Category {} @@ -96,6 +97,9 @@ public class NotificationCategorizer { return CATEGORY_SYSTEM_LOW; } } + if (entry.getChannel().getImportance() == IMPORTANCE_HIGH) { + return CATEGORY_HIGH; + } if (entry.isOngoing()) { return CATEGORY_ONGOING; } diff --git a/packages/ExtServices/tests/src/android/ext/services/notification/NotificationCategorizerTest.java b/packages/ExtServices/tests/src/android/ext/services/notification/NotificationCategorizerTest.java index c37392f032607..12908e619a3c2 100644 --- a/packages/ExtServices/tests/src/android/ext/services/notification/NotificationCategorizerTest.java +++ b/packages/ExtServices/tests/src/android/ext/services/notification/NotificationCategorizerTest.java @@ -84,6 +84,16 @@ public class NotificationCategorizerTest { assertTrue(nc.shouldSilence(NotificationCategorizer.CATEGORY_MIN)); } + @Test + public void testHigh() { + NotificationCategorizer nc = new NotificationCategorizer(); + + when(mEntry.getChannel()).thenReturn(new NotificationChannel("", "", IMPORTANCE_HIGH)); + + assertEquals(NotificationCategorizer.CATEGORY_HIGH, nc.getCategory(mEntry)); + assertFalse(nc.shouldSilence(NotificationCategorizer.CATEGORY_HIGH)); + } + @Test public void testOngoingCategory() { NotificationCategorizer nc = new NotificationCategorizer();