Loading services/core/java/com/android/server/notification/NotificationManagerService.java +22 −0 Original line number Diff line number Diff line Loading @@ -244,6 +244,7 @@ import android.os.WorkSource; import android.permission.PermissionManager; import android.provider.DeviceConfig; import android.provider.Settings; import android.provider.Settings.Secure; import android.service.notification.Adjustment; import android.service.notification.Condition; import android.service.notification.ConversationChannelWrapper; Loading Loading @@ -2008,6 +2009,8 @@ public class NotificationManagerService extends SystemService { Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); private final Uri LOCK_SCREEN_SHOW_NOTIFICATIONS = Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); private final Uri SHOW_NOTIFICATION_SNOOZE = Settings.Secure.getUriFor(Settings.Secure.SHOW_NOTIFICATION_SNOOZE); SettingsObserver(Handler handler) { super(handler); Loading @@ -2034,6 +2037,10 @@ public class NotificationManagerService extends SystemService { false, this, UserHandle.USER_ALL); resolver.registerContentObserver(LOCK_SCREEN_SHOW_NOTIFICATIONS, false, this, UserHandle.USER_ALL); resolver.registerContentObserver(SHOW_NOTIFICATION_SNOOZE, false, this, UserHandle.USER_ALL); update(null); } Loading Loading @@ -2083,6 +2090,14 @@ public class NotificationManagerService extends SystemService { if (uri == null || LOCK_SCREEN_SHOW_NOTIFICATIONS.equals(uri)) { mPreferencesHelper.updateLockScreenShowNotifications(); } if (SHOW_NOTIFICATION_SNOOZE.equals(uri)) { final boolean snoozeEnabled = Settings.Secure.getIntForUser(resolver, Secure.SHOW_NOTIFICATION_SNOOZE, 0, UserHandle.USER_CURRENT) != 0; if (!snoozeEnabled) { unsnoozeAll(); } } } } Loading Loading @@ -7792,6 +7807,13 @@ public class NotificationManagerService extends SystemService { } } private void unsnoozeAll() { synchronized (mNotificationLock) { mSnoozeHelper.repostAll(mUserProfiles.getCurrentProfileIds()); handleSavePolicyFile(); } } protected class CancelNotificationRunnable implements Runnable { private final int mCallingUid; private final int mCallingPid; Loading services/core/java/com/android/server/notification/SnoozeHelper.java +14 −0 Original line number Diff line number Diff line Loading @@ -296,6 +296,20 @@ public final class SnoozeHelper { } } /** * Unsnooze & repost all snoozed notifications for userId and its profiles */ protected void repostAll(IntArray userIds) { synchronized (mLock) { List<NotificationRecord> snoozedNotifications = getSnoozed(); for (NotificationRecord r : snoozedNotifications) { if (userIds.binarySearch(r.getUserId()) >= 0) { repost(r.getKey(), r.getUserId(), false); } } } } protected void repost(String key, boolean muteOnReturn) { synchronized (mLock) { final NotificationRecord r = mSnoozedNotifications.get(key); Loading services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.notification; import static com.android.server.notification.SnoozeHelper.CONCURRENT_SNOOZE_LIMIT; import static com.android.server.notification.SnoozeHelper.EXTRA_KEY; import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; Loading Loading @@ -485,6 +486,29 @@ public class SnoozeHelperTest extends UiServiceTestCase { verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r, true); } @Test public void testRepostAll() throws Exception { final int profileId = 11; final int otherUserId = 2; IntArray userIds = new IntArray(); userIds.add(UserHandle.USER_SYSTEM); userIds.add(profileId); NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); NotificationRecord r3 = getNotificationRecord("pkg", 3, "three", UserHandle.of(profileId)); NotificationRecord r4 = getNotificationRecord("pkg", 4, "four", UserHandle.of(otherUserId)); mSnoozeHelper.snooze(r, 1000); mSnoozeHelper.snooze(r2, 1000); mSnoozeHelper.snooze(r3, 1000); mSnoozeHelper.snooze(r4, 1000); mSnoozeHelper.repostAll(userIds); verify(mCallback, times(3)).repost(anyInt(), any(), anyBoolean()); // All notifications were reposted, except the one for otherUserId assertThat(mSnoozeHelper.getSnoozed()).containsExactly(r4); } @Test public void testGetSnoozedBy() throws Exception { NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); Loading Loading
services/core/java/com/android/server/notification/NotificationManagerService.java +22 −0 Original line number Diff line number Diff line Loading @@ -244,6 +244,7 @@ import android.os.WorkSource; import android.permission.PermissionManager; import android.provider.DeviceConfig; import android.provider.Settings; import android.provider.Settings.Secure; import android.service.notification.Adjustment; import android.service.notification.Condition; import android.service.notification.ConversationChannelWrapper; Loading Loading @@ -2008,6 +2009,8 @@ public class NotificationManagerService extends SystemService { Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); private final Uri LOCK_SCREEN_SHOW_NOTIFICATIONS = Settings.Secure.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS); private final Uri SHOW_NOTIFICATION_SNOOZE = Settings.Secure.getUriFor(Settings.Secure.SHOW_NOTIFICATION_SNOOZE); SettingsObserver(Handler handler) { super(handler); Loading @@ -2034,6 +2037,10 @@ public class NotificationManagerService extends SystemService { false, this, UserHandle.USER_ALL); resolver.registerContentObserver(LOCK_SCREEN_SHOW_NOTIFICATIONS, false, this, UserHandle.USER_ALL); resolver.registerContentObserver(SHOW_NOTIFICATION_SNOOZE, false, this, UserHandle.USER_ALL); update(null); } Loading Loading @@ -2083,6 +2090,14 @@ public class NotificationManagerService extends SystemService { if (uri == null || LOCK_SCREEN_SHOW_NOTIFICATIONS.equals(uri)) { mPreferencesHelper.updateLockScreenShowNotifications(); } if (SHOW_NOTIFICATION_SNOOZE.equals(uri)) { final boolean snoozeEnabled = Settings.Secure.getIntForUser(resolver, Secure.SHOW_NOTIFICATION_SNOOZE, 0, UserHandle.USER_CURRENT) != 0; if (!snoozeEnabled) { unsnoozeAll(); } } } } Loading Loading @@ -7792,6 +7807,13 @@ public class NotificationManagerService extends SystemService { } } private void unsnoozeAll() { synchronized (mNotificationLock) { mSnoozeHelper.repostAll(mUserProfiles.getCurrentProfileIds()); handleSavePolicyFile(); } } protected class CancelNotificationRunnable implements Runnable { private final int mCallingUid; private final int mCallingPid; Loading
services/core/java/com/android/server/notification/SnoozeHelper.java +14 −0 Original line number Diff line number Diff line Loading @@ -296,6 +296,20 @@ public final class SnoozeHelper { } } /** * Unsnooze & repost all snoozed notifications for userId and its profiles */ protected void repostAll(IntArray userIds) { synchronized (mLock) { List<NotificationRecord> snoozedNotifications = getSnoozed(); for (NotificationRecord r : snoozedNotifications) { if (userIds.binarySearch(r.getUserId()) >= 0) { repost(r.getKey(), r.getUserId(), false); } } } } protected void repost(String key, boolean muteOnReturn) { synchronized (mLock) { final NotificationRecord r = mSnoozedNotifications.get(key); Loading
services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java +24 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.server.notification; import static com.android.server.notification.SnoozeHelper.CONCURRENT_SNOOZE_LIMIT; import static com.android.server.notification.SnoozeHelper.EXTRA_KEY; import static com.google.common.truth.Truth.assertThat; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNotNull; Loading Loading @@ -485,6 +486,29 @@ public class SnoozeHelperTest extends UiServiceTestCase { verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r, true); } @Test public void testRepostAll() throws Exception { final int profileId = 11; final int otherUserId = 2; IntArray userIds = new IntArray(); userIds.add(UserHandle.USER_SYSTEM); userIds.add(profileId); NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); NotificationRecord r3 = getNotificationRecord("pkg", 3, "three", UserHandle.of(profileId)); NotificationRecord r4 = getNotificationRecord("pkg", 4, "four", UserHandle.of(otherUserId)); mSnoozeHelper.snooze(r, 1000); mSnoozeHelper.snooze(r2, 1000); mSnoozeHelper.snooze(r3, 1000); mSnoozeHelper.snooze(r4, 1000); mSnoozeHelper.repostAll(userIds); verify(mCallback, times(3)).repost(anyInt(), any(), anyBoolean()); // All notifications were reposted, except the one for otherUserId assertThat(mSnoozeHelper.getSnoozed()).containsExactly(r4); } @Test public void testGetSnoozedBy() throws Exception { NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM); Loading