diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index 5ab767ba9676a..896f56c9f4d9f 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -66,6 +66,7 @@ interface INotificationManager ParceledListSlice getNotificationChannels(String pkg); ParceledListSlice getNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted); int getNumNotificationChannelsForPackage(String pkg, int uid, boolean includeDeleted); + int getDeletedChannelCount(String pkg, int uid); // TODO: Remove this when callers have been migrated to the equivalent // INotificationListener method. diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index be8aaf02db41f..7285a4c0e9c7d 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -1697,6 +1697,12 @@ public class NotificationManagerService extends SystemService { .getList().size(); } + @Override + public int getDeletedChannelCount(String pkg, int uid) { + enforceSystemOrSystemUI("getDeletedChannelCount"); + return mRankingHelper.getDeletedChannelCount(pkg, uid); + } + @Override public ParceledListSlice getNotificationChannelGroupsForPackage( String pkg, int uid, boolean includeDeleted) { diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java index bc39006c69f33..e239164d65689 100644 --- a/services/core/java/com/android/server/notification/RankingHelper.java +++ b/services/core/java/com/android/server/notification/RankingHelper.java @@ -766,6 +766,23 @@ public class RankingHelper implements RankingConfig { return new ParceledListSlice<>(channels); } + public int getDeletedChannelCount(String pkg, int uid) { + Preconditions.checkNotNull(pkg); + int deletedCount = 0; + Record r = getRecord(pkg, uid); + if (r == null) { + return deletedCount; + } + int N = r.channels.size(); + for (int i = 0; i < N; i++) { + final NotificationChannel nc = r.channels.valueAt(i); + if (nc.isDeleted()) { + deletedCount++; + } + } + return deletedCount; + } + /** * Sets importance. */ diff --git a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java index c420f40409a24..b538453dc93d9 100644 --- a/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java +++ b/services/tests/notification/src/com/android/server/notification/RankingHelperTest.java @@ -722,6 +722,25 @@ public class RankingHelperTest { } } + @Test + public void testGetDeletedChannelCount() throws Exception { + NotificationChannel channel = + new NotificationChannel("id2", "name2", IMPORTANCE_LOW); + NotificationChannel channel2 = + new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH); + NotificationChannel channel3 = + new NotificationChannel("id4", "a", NotificationManager.IMPORTANCE_HIGH); + mHelper.createNotificationChannel(pkg, uid, channel, true); + mHelper.createNotificationChannel(pkg, uid, channel2, true); + mHelper.createNotificationChannel(pkg, uid, channel3, true); + + mHelper.deleteNotificationChannel(pkg, uid, channel.getId()); + mHelper.deleteNotificationChannel(pkg, uid, channel3.getId()); + + assertEquals(2, mHelper.getDeletedChannelCount(pkg, uid)); + assertEquals(0, mHelper.getDeletedChannelCount(pkg2, uid2)); + } + @Test public void testUpdateDeletedChannels() throws Exception { NotificationChannel channel =