Loading proto/src/metrics_constants/metrics_constants.proto +1 −1 Original line number Diff line number Diff line Loading @@ -3684,7 +3684,7 @@ message MetricsEvent { ACTION_SETTINGS_TILE_CLICK = 830; // OPEN: Notification unsnoozed. CLOSE: Notification snoozed. UPDATE: snoozed notification // updated // updated. TYPE_DISMISS: snoozing canceled due to data being cleared on package // CATEGORY: NOTIFICATION // OS: O NOTIFICATION_SNOOZED = 831; Loading services/core/java/com/android/server/notification/NotificationManagerService.java +3 −0 Original line number Diff line number Diff line Loading @@ -2641,6 +2641,9 @@ public class NotificationManagerService extends SystemService { // Zen mConditionProviders.onPackagesChanged(true, packages, uids); // Snoozing mSnoozeHelper.clearData(UserHandle.getUserId(uid), packageName); // Reset notification preferences if (!fromApp) { mPreferencesHelper.onPackagesChanged( Loading services/core/java/com/android/server/notification/SnoozeHelper.java +25 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.notification; import android.annotation.NonNull; import android.app.AlarmManager; import android.app.Notification; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; Loading Loading @@ -163,7 +164,6 @@ public class SnoozeHelper { mSnoozedNotifications.get(userId).get(pkg); if (recordsForPkg != null) { final Set<Map.Entry<String, NotificationRecord>> records = recordsForPkg.entrySet(); String key = null; for (Map.Entry<String, NotificationRecord> record : records) { final StatusBarNotification sbn = record.getValue().sbn; if (Objects.equals(sbn.getTag(), tag) && sbn.getId() == id) { Loading Loading @@ -305,6 +305,30 @@ public class SnoozeHelper { } } protected void clearData(int userId, String pkg) { ArrayMap<String, ArrayMap<String, NotificationRecord>> records = mSnoozedNotifications.get(userId); if (records == null) { return; } ArrayMap<String, NotificationRecord> pkgRecords = records.get(pkg); if (pkgRecords == null) { return; } for (int i = pkgRecords.size() - 1; i >= 0; i--) { final NotificationRecord r = pkgRecords.removeAt(i); if (r != null) { mPackages.remove(r.getKey()); mUsers.remove(r.getKey()); final PendingIntent pi = createPendingIntent(pkg, r.getKey(), userId); mAm.cancel(pi); MetricsLogger.action(r.getLogMaker() .setCategory(MetricsProto.MetricsEvent.NOTIFICATION_SNOOZED) .setType(MetricsProto.MetricsEvent.TYPE_DISMISS)); } } } private PendingIntent createPendingIntent(String pkg, String key, int userId) { return PendingIntent.getBroadcast(mContext, REQUEST_CODE_REPOST, Loading services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java +53 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,59 @@ public class SnoozeHelperTest extends UiServiceTestCase { assertEquals(1, mSnoozeHelper.getSnoozed(UserHandle.USER_SYSTEM, "pkg").size()); } @Test public void testClearData() { // snooze 2 from same package NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); mSnoozeHelper.snooze(r, 1000); mSnoozeHelper.snooze(r2, 1000); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); // clear data mSnoozeHelper.clearData(UserHandle.USER_SYSTEM, "pkg"); // nothing snoozed; alarms canceled assertFalse(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertFalse(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); // twice for initial snooze, twice for canceling the snooze verify(mAm, times(4)).cancel(any(PendingIntent.class)); } @Test public void testClearData_otherRecordsUntouched() { // 2 packages, 2 users NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.ALL); NotificationRecord r3 = getNotificationRecord("pkg2", 3, "three", UserHandle.SYSTEM); mSnoozeHelper.snooze(r, 1000); mSnoozeHelper.snooze(r2, 1000); mSnoozeHelper.snooze(r3, 1000); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_ALL, r2.sbn.getPackageName(), r2.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey())); // clear data mSnoozeHelper.clearData(UserHandle.USER_SYSTEM, "pkg"); assertFalse(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_ALL, r2.sbn.getPackageName(), r2.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey())); // once for each initial snooze, once for canceling one snooze verify(mAm, times(4)).cancel(any(PendingIntent.class)); } private NotificationRecord getNotificationRecord(String pkg, int id, String tag, UserHandle user, String groupKey, boolean groupSummary) { Notification n = new Notification.Builder(getContext(), TEST_CHANNEL_ID) Loading Loading
proto/src/metrics_constants/metrics_constants.proto +1 −1 Original line number Diff line number Diff line Loading @@ -3684,7 +3684,7 @@ message MetricsEvent { ACTION_SETTINGS_TILE_CLICK = 830; // OPEN: Notification unsnoozed. CLOSE: Notification snoozed. UPDATE: snoozed notification // updated // updated. TYPE_DISMISS: snoozing canceled due to data being cleared on package // CATEGORY: NOTIFICATION // OS: O NOTIFICATION_SNOOZED = 831; Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +3 −0 Original line number Diff line number Diff line Loading @@ -2641,6 +2641,9 @@ public class NotificationManagerService extends SystemService { // Zen mConditionProviders.onPackagesChanged(true, packages, uids); // Snoozing mSnoozeHelper.clearData(UserHandle.getUserId(uid), packageName); // Reset notification preferences if (!fromApp) { mPreferencesHelper.onPackagesChanged( Loading
services/core/java/com/android/server/notification/SnoozeHelper.java +25 −1 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.server.notification; import android.annotation.NonNull; import android.app.AlarmManager; import android.app.Notification; import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; Loading Loading @@ -163,7 +164,6 @@ public class SnoozeHelper { mSnoozedNotifications.get(userId).get(pkg); if (recordsForPkg != null) { final Set<Map.Entry<String, NotificationRecord>> records = recordsForPkg.entrySet(); String key = null; for (Map.Entry<String, NotificationRecord> record : records) { final StatusBarNotification sbn = record.getValue().sbn; if (Objects.equals(sbn.getTag(), tag) && sbn.getId() == id) { Loading Loading @@ -305,6 +305,30 @@ public class SnoozeHelper { } } protected void clearData(int userId, String pkg) { ArrayMap<String, ArrayMap<String, NotificationRecord>> records = mSnoozedNotifications.get(userId); if (records == null) { return; } ArrayMap<String, NotificationRecord> pkgRecords = records.get(pkg); if (pkgRecords == null) { return; } for (int i = pkgRecords.size() - 1; i >= 0; i--) { final NotificationRecord r = pkgRecords.removeAt(i); if (r != null) { mPackages.remove(r.getKey()); mUsers.remove(r.getKey()); final PendingIntent pi = createPendingIntent(pkg, r.getKey(), userId); mAm.cancel(pi); MetricsLogger.action(r.getLogMaker() .setCategory(MetricsProto.MetricsEvent.NOTIFICATION_SNOOZED) .setType(MetricsProto.MetricsEvent.TYPE_DISMISS)); } } } private PendingIntent createPendingIntent(String pkg, String key, int userId) { return PendingIntent.getBroadcast(mContext, REQUEST_CODE_REPOST, Loading
services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java +53 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,59 @@ public class SnoozeHelperTest extends UiServiceTestCase { assertEquals(1, mSnoozeHelper.getSnoozed(UserHandle.USER_SYSTEM, "pkg").size()); } @Test public void testClearData() { // snooze 2 from same package NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); mSnoozeHelper.snooze(r, 1000); mSnoozeHelper.snooze(r2, 1000); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); // clear data mSnoozeHelper.clearData(UserHandle.USER_SYSTEM, "pkg"); // nothing snoozed; alarms canceled assertFalse(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertFalse(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey())); // twice for initial snooze, twice for canceling the snooze verify(mAm, times(4)).cancel(any(PendingIntent.class)); } @Test public void testClearData_otherRecordsUntouched() { // 2 packages, 2 users NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.ALL); NotificationRecord r3 = getNotificationRecord("pkg2", 3, "three", UserHandle.SYSTEM); mSnoozeHelper.snooze(r, 1000); mSnoozeHelper.snooze(r2, 1000); mSnoozeHelper.snooze(r3, 1000); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_ALL, r2.sbn.getPackageName(), r2.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey())); // clear data mSnoozeHelper.clearData(UserHandle.USER_SYSTEM, "pkg"); assertFalse(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_ALL, r2.sbn.getPackageName(), r2.getKey())); assertTrue(mSnoozeHelper.isSnoozed( UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey())); // once for each initial snooze, once for canceling one snooze verify(mAm, times(4)).cancel(any(PendingIntent.class)); } private NotificationRecord getNotificationRecord(String pkg, int id, String tag, UserHandle user, String groupKey, boolean groupSummary) { Notification n = new Notification.Builder(getContext(), TEST_CHANNEL_ID) Loading