From 376e308a10cd3a79993cab2c1912f6617e659ae1 Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 24 Apr 2020 12:06:27 -0400 Subject: [PATCH] Check importance to determine if notif sounds If the user has a setting to not show silent notifications on the lockscreen, then all notifications that don't make noise from all notification sections aside from the media section should hide. For example, silent notifications categorized in BUCKET_PEOPLE. Test: atest NotificationLockscreenUserManagerTest Fixes: 152934785 Change-Id: I98c0f0d0ac17463f92cc0228903d13ab226c5c1a --- ...NotificationLockscreenUserManagerImpl.java | 7 +++- ...NotificationLockscreenUserManagerTest.java | 41 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index 12298817d5a67..bce95a6f7829c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -19,11 +19,13 @@ import static android.app.Notification.VISIBILITY_SECRET; import static android.app.admin.DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED; import static com.android.systemui.DejankUtils.whitelistIpcs; +import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_MEDIA_CONTROLS; import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT; import android.app.ActivityManager; import android.app.KeyguardManager; import android.app.Notification; +import android.app.NotificationManager; import android.app.admin.DevicePolicyManager; import android.content.BroadcastReceiver; import android.content.Context; @@ -351,7 +353,10 @@ public class NotificationLockscreenUserManagerImpl implements boolean exceedsPriorityThreshold; if (NotificationUtils.useNewInterruptionModel(mContext) && hideSilentNotificationsOnLockscreen()) { - exceedsPriorityThreshold = entry.getBucket() != BUCKET_SILENT; + exceedsPriorityThreshold = + entry.getBucket() == BUCKET_MEDIA_CONTROLS + || (entry.getBucket() != BUCKET_SILENT + && entry.getImportance() >= NotificationManager.IMPORTANCE_DEFAULT); } else { exceedsPriorityThreshold = !entry.getRanking().isAmbient(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java index c6d57e6df0283..5838ae4aec675 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java @@ -20,6 +20,8 @@ import static android.app.NotificationManager.IMPORTANCE_LOW; import static android.content.Intent.ACTION_USER_SWITCHED; import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL; +import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_MEDIA_CONTROLS; +import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE; import static com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT; import static junit.framework.Assert.assertFalse; @@ -233,6 +235,45 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(entry)); } + @Test + public void testShowSilentNotificationsPeopleBucket_settingSaysHide() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); + Settings.Secure.putInt(mContext.getContentResolver(), + NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0); + + final Notification notification = mock(Notification.class); + when(notification.isForegroundService()).thenReturn(true); + NotificationEntry entry = new NotificationEntryBuilder() + .setImportance(IMPORTANCE_LOW) + .setNotification(notification) + .build(); + entry.setBucket(BUCKET_PEOPLE); + assertFalse(mLockscreenUserManager.shouldShowOnKeyguard(entry)); + } + + @Test + public void testShowSilentNotificationsMediaBucket_settingSaysHide() { + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1); + Settings.Secure.putInt(mContext.getContentResolver(), + NOTIFICATION_NEW_INTERRUPTION_MODEL, 1); + Settings.Secure.putInt(mContext.getContentResolver(), + Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0); + + final Notification notification = mock(Notification.class); + when(notification.isForegroundService()).thenReturn(true); + NotificationEntry entry = new NotificationEntryBuilder() + .setImportance(IMPORTANCE_LOW) + .setNotification(notification) + .build(); + entry.setBucket(BUCKET_MEDIA_CONTROLS); + // always show media controls, even if they're silent + assertTrue(mLockscreenUserManager.shouldShowOnKeyguard(entry)); + } + private class TestNotificationLockscreenUserManager extends NotificationLockscreenUserManagerImpl { public TestNotificationLockscreenUserManager(Context context) {