diff options
4 files changed, 49 insertions, 5 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index ddd065692ea2..5067e19f1ce4 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -73,6 +73,7 @@ interface INotificationManager ParceledListSlice getNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted); int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted); int getDeletedChannelCount(String pkg, int uid); + int getBlockedChannelCount(String pkg, int uid); void deleteNotificationChannelGroup(String pkg, String channelGroupId); NotificationChannelGroup getNotificationChannelGroup(String pkg, String channelGroupId); ParceledListSlice getNotificationChannelGroups(String pkg); diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index f31ca0a2fa09..899d271019f3 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -2286,6 +2286,12 @@ public class NotificationManagerService extends SystemService { } @Override + public int getBlockedChannelCount(String pkg, int uid) { + enforceSystemOrSystemUI("getBlockedChannelCount"); + return mRankingHelper.getBlockedChannelCount(pkg, uid); + } + + @Override public ParceledListSlice<NotificationChannelGroup> getNotificationChannelGroupsForPackage( String pkg, int uid, boolean includeDeleted) { checkCallerIsSystem(); diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index 98d5c9a59f6b..43d393a237ca 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -15,6 +15,8 @@ */ package com.android.server.notification; +import static android.app.NotificationManager.IMPORTANCE_NONE; + import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; import com.android.internal.logging.MetricsLogger; @@ -619,7 +621,7 @@ public class RankingHelper implements RankingConfig { updateConfig(); return; } - if (channel.getImportance() < NotificationManager.IMPORTANCE_NONE + if (channel.getImportance() < IMPORTANCE_NONE || channel.getImportance() > NotificationManager.IMPORTANCE_MAX) { throw new IllegalArgumentException("Invalid importance level"); } @@ -959,6 +961,23 @@ public class RankingHelper implements RankingConfig { return deletedCount; } + public int getBlockedChannelCount(String pkg, int uid) { + Preconditions.checkNotNull(pkg); + int blockedCount = 0; + Record r = getRecord(pkg, uid); + if (r == null) { + return blockedCount; + } + int N = r.channels.size(); + for (int i = 0; i < N; i++) { + final NotificationChannel nc = r.channels.valueAt(i); + if (!nc.isDeleted() && IMPORTANCE_NONE == nc.getImportance()) { + blockedCount++; + } + } + return blockedCount; + } + /** * Sets importance. */ @@ -969,12 +988,12 @@ public class RankingHelper implements RankingConfig { } public void setEnabled(String packageName, int uid, boolean enabled) { - boolean wasEnabled = getImportance(packageName, uid) != NotificationManager.IMPORTANCE_NONE; + boolean wasEnabled = getImportance(packageName, uid) != IMPORTANCE_NONE; if (wasEnabled == enabled) { return; } setImportance(packageName, uid, - enabled ? DEFAULT_IMPORTANCE : NotificationManager.IMPORTANCE_NONE); + enabled ? DEFAULT_IMPORTANCE : IMPORTANCE_NONE); } @VisibleForTesting @@ -1199,7 +1218,7 @@ public class RankingHelper implements RankingConfig { ArrayMap<Integer, String> packageBans = new ArrayMap<>(N); for (int i = 0; i < N; i++) { final Record r = mRecords.valueAt(i); - if (r.importance == NotificationManager.IMPORTANCE_NONE) { + if (r.importance == IMPORTANCE_NONE) { packageBans.put(r.uid, r.pkg); } } diff --git a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java index 0815876e5915..54ed1e6f84b7 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java @@ -1093,7 +1093,7 @@ public class RankingHelperTest extends UiServiceTestCase { NotificationChannel channel2 = new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH); NotificationChannel channel3 = - new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH); + new NotificationChannel("id5", "a", NotificationManager.IMPORTANCE_HIGH); mHelper.createNotificationChannel(PKG, UID, channel, true, false); mHelper.createNotificationChannel(PKG, UID, channel2, true, false); mHelper.createNotificationChannel(PKG, UID, channel3, true, false); @@ -1106,6 +1106,24 @@ public class RankingHelperTest extends UiServiceTestCase { } @Test + public void testGetBlockedChannelCount() throws Exception { + NotificationChannel channel = + new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + NotificationChannel channel2 = + new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_NONE); + NotificationChannel channel3 = + new NotificationChannel("id5", "a", NotificationManager.IMPORTANCE_NONE); + mHelper.createNotificationChannel(PKG, UID, channel, true, false); + mHelper.createNotificationChannel(PKG, UID, channel2, true, false); + mHelper.createNotificationChannel(PKG, UID, channel3, true, false); + + mHelper.deleteNotificationChannel(PKG, UID, channel3.getId()); + + assertEquals(1, mHelper.getBlockedChannelCount(PKG, UID)); + assertEquals(0, mHelper.getBlockedChannelCount("pkg2", UID2)); + } + + @Test public void testCreateDeletedChannel() throws Exception { long[] vibration = new long[]{100, 67, 145, 156}; NotificationChannel channel = |