diff options
3 files changed, 60 insertions, 0 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 7ca56990f2d0..4b5d52f0a8de 100755 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -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; @@ -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); @@ -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); } @@ -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(); + } + } } } @@ -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; diff --git a/services/core/java/com/android/server/notification/SnoozeHelper.java b/services/core/java/com/android/server/notification/SnoozeHelper.java index 017698943fc9..8f5676b31594 100644 --- a/services/core/java/com/android/server/notification/SnoozeHelper.java +++ b/services/core/java/com/android/server/notification/SnoozeHelper.java @@ -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); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java index 51b9c176a245..47f15b8df076 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/SnoozeHelperTest.java @@ -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; @@ -486,6 +487,29 @@ public class SnoozeHelperTest extends UiServiceTestCase { } @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); NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM); |