Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/KeyguardNotificationVisibilityProvider.kt +16 −10 Original line number Diff line number Diff line Loading @@ -164,12 +164,23 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( !lockscreenUserManager.shouldShowLockscreenNotifications() -> true // User settings do not allow this notification on the lockscreen, so hide it. userSettingsDisallowNotification(entry) -> true // if entry is silent, apply custom logic to see if should hide shouldHideIfEntrySilent(entry) -> true else -> false } private fun shouldHideIfEntrySilent(entry: ListEntry): Boolean = when { // Show if high priority (not hidden) highPriorityProvider.isHighPriority(entry) -> false // Ambient notifications are hidden always from lock screen entry.representativeEntry?.isAmbient == true -> true // [Now notification is silent] // Hide regardless of parent priority if user wants silent notifs hidden hideSilentNotificationsOnLockscreen -> true // Parent priority is high enough to be shown on the lockscreen, do not hide. entry.parent?.let(::priorityExceedsLockscreenShowingThreshold) == true -> false // Entry priority is high enough to be shown on the lockscreen, do not hide. priorityExceedsLockscreenShowingThreshold(entry) -> false // Priority is too low, hide. else -> true entry.parent?.let(::shouldHideIfEntrySilent) == false -> false // Show when silent notifications are allowed on lockscreen else -> false } private fun userSettingsDisallowNotification(entry: NotificationEntry): Boolean { Loading @@ -193,11 +204,6 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( } } private fun priorityExceedsLockscreenShowingThreshold(entry: ListEntry): Boolean = when { hideSilentNotificationsOnLockscreen -> highPriorityProvider.isHighPriority(entry) else -> entry.representativeEntry?.ranking?.isAmbient == false } private fun readShowSilentNotificationSetting() { val showSilentNotifs = secureSettings.getBoolForUser(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/KeyguardNotificationVisibilityProviderTest.java +38 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.argThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; Loading Loading @@ -227,6 +228,41 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { verify(listener).accept(anyString()); } @Test public void hideSilentNotificationsPerUserSettingWithHighPriorityParent() { when(mKeyguardStateController.isShowing()).thenReturn(true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); GroupEntry parent = new GroupEntryBuilder() .setKey("parent") .addChild(mEntry) .setSummary(new NotificationEntryBuilder() .setUser(new UserHandle(NOTIF_USER_ID)) .setImportance(IMPORTANCE_LOW) .build()) .build(); mEntry = new NotificationEntryBuilder() .setUser(new UserHandle(NOTIF_USER_ID)) .setImportance(IMPORTANCE_LOW) .setParent(parent) .build(); when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); } @Test public void hideSilentNotificationsPerUserSetting() { when(mKeyguardStateController.isShowing()).thenReturn(true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); mEntry = new NotificationEntryBuilder() .setUser(new UserHandle(NOTIF_USER_ID)) .setImportance(IMPORTANCE_LOW) .build(); when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); } @Test public void notifyListeners_onSettingChange_zenMode() { when(mKeyguardStateController.isShowing()).thenReturn(true); Loading Loading @@ -384,8 +420,8 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); when(mHighPriorityProvider.isHighPriority(parent)).thenReturn(true); // THEN don't filter out the entry assertFalse( // THEN filter out the entry regardless of parent assertTrue( mKeyguardNotificationVisibilityProvider.shouldHideNotification(entryWithParent)); // WHEN its parent doesn't exceed threshold to show on lockscreen Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/KeyguardNotificationVisibilityProvider.kt +16 −10 Original line number Diff line number Diff line Loading @@ -164,12 +164,23 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( !lockscreenUserManager.shouldShowLockscreenNotifications() -> true // User settings do not allow this notification on the lockscreen, so hide it. userSettingsDisallowNotification(entry) -> true // if entry is silent, apply custom logic to see if should hide shouldHideIfEntrySilent(entry) -> true else -> false } private fun shouldHideIfEntrySilent(entry: ListEntry): Boolean = when { // Show if high priority (not hidden) highPriorityProvider.isHighPriority(entry) -> false // Ambient notifications are hidden always from lock screen entry.representativeEntry?.isAmbient == true -> true // [Now notification is silent] // Hide regardless of parent priority if user wants silent notifs hidden hideSilentNotificationsOnLockscreen -> true // Parent priority is high enough to be shown on the lockscreen, do not hide. entry.parent?.let(::priorityExceedsLockscreenShowingThreshold) == true -> false // Entry priority is high enough to be shown on the lockscreen, do not hide. priorityExceedsLockscreenShowingThreshold(entry) -> false // Priority is too low, hide. else -> true entry.parent?.let(::shouldHideIfEntrySilent) == false -> false // Show when silent notifications are allowed on lockscreen else -> false } private fun userSettingsDisallowNotification(entry: NotificationEntry): Boolean { Loading @@ -193,11 +204,6 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( } } private fun priorityExceedsLockscreenShowingThreshold(entry: ListEntry): Boolean = when { hideSilentNotificationsOnLockscreen -> highPriorityProvider.isHighPriority(entry) else -> entry.representativeEntry?.ranking?.isAmbient == false } private fun readShowSilentNotificationSetting() { val showSilentNotifs = secureSettings.getBoolForUser(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/interruption/KeyguardNotificationVisibilityProviderTest.java +38 −2 Original line number Diff line number Diff line Loading @@ -27,6 +27,7 @@ import static com.android.systemui.util.mockito.KotlinMockitoHelpersKt.argThat; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; Loading Loading @@ -227,6 +228,41 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { verify(listener).accept(anyString()); } @Test public void hideSilentNotificationsPerUserSettingWithHighPriorityParent() { when(mKeyguardStateController.isShowing()).thenReturn(true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); GroupEntry parent = new GroupEntryBuilder() .setKey("parent") .addChild(mEntry) .setSummary(new NotificationEntryBuilder() .setUser(new UserHandle(NOTIF_USER_ID)) .setImportance(IMPORTANCE_LOW) .build()) .build(); mEntry = new NotificationEntryBuilder() .setUser(new UserHandle(NOTIF_USER_ID)) .setImportance(IMPORTANCE_LOW) .setParent(parent) .build(); when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); } @Test public void hideSilentNotificationsPerUserSetting() { when(mKeyguardStateController.isShowing()).thenReturn(true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); mEntry = new NotificationEntryBuilder() .setUser(new UserHandle(NOTIF_USER_ID)) .setImportance(IMPORTANCE_LOW) .build(); when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); } @Test public void notifyListeners_onSettingChange_zenMode() { when(mKeyguardStateController.isShowing()).thenReturn(true); Loading Loading @@ -384,8 +420,8 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); when(mHighPriorityProvider.isHighPriority(parent)).thenReturn(true); // THEN don't filter out the entry assertFalse( // THEN filter out the entry regardless of parent assertTrue( mKeyguardNotificationVisibilityProvider.shouldHideNotification(entryWithParent)); // WHEN its parent doesn't exceed threshold to show on lockscreen Loading