Loading services/core/java/com/android/server/notification/NotificationManagerService.java +21 −2 Original line number Original line Diff line number Diff line Loading @@ -685,6 +685,21 @@ public class NotificationManagerService extends SystemService { } } } } } } // Remove notifications with the specified user & channel ID. public void removeChannelNotifications(String pkg, @UserIdInt int userId, String channelId) { for (int i = 0; i < mBuffer.size(); i++) { final Pair<StatusBarNotification, Integer> pair = mBuffer.get(i); if (pair.first != null && userId == pair.first.getNormalizedUserId() && pkg != null && pkg.equals(pair.first.getPackageName()) && pair.first.getNotification() != null && Objects.equals(channelId, pair.first.getNotification().getChannelId())) { mBuffer.remove(i); } } } } } void loadDefaultApprovedServices(int userId) { void loadDefaultApprovedServices(int userId) { Loading Loading @@ -3623,6 +3638,8 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true, cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true, callingUser, REASON_CHANNEL_REMOVED, null); callingUser, REASON_CHANNEL_REMOVED, null); mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId); mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId); // Remove from both recent notification archive and notification history mArchive.removeChannelNotifications(pkg, callingUser, channelId); mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId); mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId); mListeners.notifyNotificationChannelChanged(pkg, mListeners.notifyNotificationChannelChanged(pkg, UserHandle.getUserHandleForUid(callingUid), UserHandle.getUserHandleForUid(callingUid), Loading Loading @@ -8179,8 +8196,10 @@ public class NotificationManagerService extends SystemService { summaries.remove(r.getSbn().getPackageName()); summaries.remove(r.getSbn().getPackageName()); } } // Save it for users of getHistoricalNotifications() // Save it for users of getHistoricalNotifications(), unless the whole channel was deleted if (reason != REASON_CHANNEL_REMOVED) { mArchive.record(r.getSbn(), reason); mArchive.record(r.getSbn(), reason); } final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis(); final LogMaker logMaker = r.getItemLogMaker() final LogMaker logMaker = r.getItemLogMaker() Loading services/tests/uiservicestests/src/com/android/server/notification/ArchiveTest.java +20 −1 Original line number Original line Diff line number Diff line Loading @@ -56,7 +56,7 @@ public class ArchiveTest extends UiServiceTestCase { } } private StatusBarNotification getNotification(String pkg, int id, UserHandle user) { private StatusBarNotification getNotification(String pkg, int id, UserHandle user) { Notification n = new Notification.Builder(getContext(), "test") Notification n = new Notification.Builder(getContext(), "test" + id) .setContentTitle("A") .setContentTitle("A") .setWhen(1205) .setWhen(1205) .build(); .build(); Loading Loading @@ -140,4 +140,23 @@ public class ArchiveTest extends UiServiceTestCase { assertThat(expected).contains(sbn.getKey()); assertThat(expected).contains(sbn.getKey()); } } } } @Test public void testRemoveChannelNotifications() { List<String> expected = new ArrayList<>(); for (int i = 0; i < SIZE; i++) { StatusBarNotification sbn = getNotification("pkg", i, UserHandle.of(USER_CURRENT)); mArchive.record(sbn, REASON_CANCEL); if (i != 3) { // Will delete notification for this user in channel "test3". expected.add(sbn.getKey()); } } mArchive.removeChannelNotifications("pkg", USER_CURRENT, "test3"); List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray(SIZE, true)); assertThat(actual).hasSize(expected.size()); for (StatusBarNotification sbn : actual) { assertThat(expected).contains(sbn.getKey()); } } } } Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +21 −2 Original line number Original line Diff line number Diff line Loading @@ -685,6 +685,21 @@ public class NotificationManagerService extends SystemService { } } } } } } // Remove notifications with the specified user & channel ID. public void removeChannelNotifications(String pkg, @UserIdInt int userId, String channelId) { for (int i = 0; i < mBuffer.size(); i++) { final Pair<StatusBarNotification, Integer> pair = mBuffer.get(i); if (pair.first != null && userId == pair.first.getNormalizedUserId() && pkg != null && pkg.equals(pair.first.getPackageName()) && pair.first.getNotification() != null && Objects.equals(channelId, pair.first.getNotification().getChannelId())) { mBuffer.remove(i); } } } } } void loadDefaultApprovedServices(int userId) { void loadDefaultApprovedServices(int userId) { Loading Loading @@ -3623,6 +3638,8 @@ public class NotificationManagerService extends SystemService { cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true, cancelAllNotificationsInt(MY_UID, MY_PID, pkg, channelId, 0, 0, true, callingUser, REASON_CHANNEL_REMOVED, null); callingUser, REASON_CHANNEL_REMOVED, null); mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId); mPreferencesHelper.deleteNotificationChannel(pkg, callingUid, channelId); // Remove from both recent notification archive and notification history mArchive.removeChannelNotifications(pkg, callingUser, channelId); mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId); mHistoryManager.deleteNotificationChannel(pkg, callingUid, channelId); mListeners.notifyNotificationChannelChanged(pkg, mListeners.notifyNotificationChannelChanged(pkg, UserHandle.getUserHandleForUid(callingUid), UserHandle.getUserHandleForUid(callingUid), Loading Loading @@ -8179,8 +8196,10 @@ public class NotificationManagerService extends SystemService { summaries.remove(r.getSbn().getPackageName()); summaries.remove(r.getSbn().getPackageName()); } } // Save it for users of getHistoricalNotifications() // Save it for users of getHistoricalNotifications(), unless the whole channel was deleted if (reason != REASON_CHANNEL_REMOVED) { mArchive.record(r.getSbn(), reason); mArchive.record(r.getSbn(), reason); } final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis(); final LogMaker logMaker = r.getItemLogMaker() final LogMaker logMaker = r.getItemLogMaker() Loading
services/tests/uiservicestests/src/com/android/server/notification/ArchiveTest.java +20 −1 Original line number Original line Diff line number Diff line Loading @@ -56,7 +56,7 @@ public class ArchiveTest extends UiServiceTestCase { } } private StatusBarNotification getNotification(String pkg, int id, UserHandle user) { private StatusBarNotification getNotification(String pkg, int id, UserHandle user) { Notification n = new Notification.Builder(getContext(), "test") Notification n = new Notification.Builder(getContext(), "test" + id) .setContentTitle("A") .setContentTitle("A") .setWhen(1205) .setWhen(1205) .build(); .build(); Loading Loading @@ -140,4 +140,23 @@ public class ArchiveTest extends UiServiceTestCase { assertThat(expected).contains(sbn.getKey()); assertThat(expected).contains(sbn.getKey()); } } } } @Test public void testRemoveChannelNotifications() { List<String> expected = new ArrayList<>(); for (int i = 0; i < SIZE; i++) { StatusBarNotification sbn = getNotification("pkg", i, UserHandle.of(USER_CURRENT)); mArchive.record(sbn, REASON_CANCEL); if (i != 3) { // Will delete notification for this user in channel "test3". expected.add(sbn.getKey()); } } mArchive.removeChannelNotifications("pkg", USER_CURRENT, "test3"); List<StatusBarNotification> actual = Arrays.asList(mArchive.getArray(SIZE, true)); assertThat(actual).hasSize(expected.size()); for (StatusBarNotification sbn : actual) { assertThat(expected).contains(sbn.getKey()); } } } }