Loading core/java/android/app/INotificationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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); Loading services/core/java/com/android/server/notification/NotificationManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -2285,6 +2285,12 @@ public class NotificationManagerService extends SystemService { return mRankingHelper.getDeletedChannelCount(pkg, uid); } @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) { Loading services/core/java/com/android/server/notification/RankingHelper.java +23 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"); } Loading Loading @@ -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. */ Loading @@ -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 Loading Loading @@ -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); } } Loading services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +19 −1 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -1105,6 +1105,24 @@ public class RankingHelperTest extends UiServiceTestCase { assertEquals(0, mHelper.getDeletedChannelCount("pkg2", UID2)); } @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}; Loading Loading
core/java/android/app/INotificationManager.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +6 −0 Original line number Diff line number Diff line Loading @@ -2285,6 +2285,12 @@ public class NotificationManagerService extends SystemService { return mRankingHelper.getDeletedChannelCount(pkg, uid); } @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) { Loading
services/core/java/com/android/server/notification/RankingHelper.java +23 −4 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"); } Loading Loading @@ -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. */ Loading @@ -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 Loading Loading @@ -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); } } Loading
services/tests/uiservicestests/src/com/android/server/notification/RankingHelperTest.java +19 −1 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -1105,6 +1105,24 @@ public class RankingHelperTest extends UiServiceTestCase { assertEquals(0, mHelper.getDeletedChannelCount("pkg2", UID2)); } @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}; Loading