Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/KeyguardNotificationVisibilityProvider.kt +10 −5 Original line number Diff line number Diff line Loading @@ -107,8 +107,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( if (uri == showSilentNotifsUri) { readShowSilentNotificationSetting() } if (statusBarStateController.getCurrentOrUpcomingState() == StatusBarState.KEYGUARD) { if (isLockedOrLocking) { notifyStateChanged("Settings $uri changed") } } Loading @@ -134,14 +133,16 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( // register (maybe) public mode changed callbacks: statusBarStateController.addCallback(object : StatusBarStateController.StateListener { override fun onStateChanged(newState: Int) { notifyStateChanged("onStatusBarStateChanged") } override fun onUpcomingStateChanged(state: Int) { notifyStateChanged("onStatusBarUpcomingStateChanged") } }) broadcastDispatcher.registerReceiver(object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { if (statusBarStateController.getCurrentOrUpcomingState() == StatusBarState.KEYGUARD) { if (isLockedOrLocking) { // maybe public mode changed notifyStateChanged(intent.action!!) } Loading @@ -163,7 +164,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( override fun shouldHideNotification(entry: NotificationEntry): Boolean = when { // Keyguard state doesn't matter if the keyguard is not showing. statusBarStateController.getCurrentOrUpcomingState() != StatusBarState.KEYGUARD -> false !isLockedOrLocking -> false // Notifications not allowed on the lockscreen, always hide. !lockscreenUserManager.shouldShowLockscreenNotifications() -> true // User settings do not allow this notification on the lockscreen, so hide it. Loading Loading @@ -208,6 +209,10 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( } } private val isLockedOrLocking get() = keyguardStateController.isShowing || statusBarStateController.currentOrUpcomingState == StatusBarState.KEYGUARD 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 +54 −2 Original line number Diff line number Diff line Loading @@ -173,7 +173,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { } @Test public void notifyListeners_onStatusBarStateChanged() { public void notifyListeners_onStatusBarUpcomingStateChanged() { ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor = ArgumentCaptor.forClass(StatusBarStateController.StateListener.class); verify(mStatusBarStateController).addCallback(callbackCaptor.capture()); Loading @@ -187,6 +187,21 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { verify(listener).accept(anyString()); } @Test public void notifyListeners_onStatusBarStateChanged() { ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor = ArgumentCaptor.forClass(StatusBarStateController.StateListener.class); verify(mStatusBarStateController).addCallback(callbackCaptor.capture()); StatusBarStateController.StateListener callback = callbackCaptor.getValue(); Consumer<String> listener = mock(Consumer.class); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); callback.onStateChanged(0); verify(listener).accept(anyString()); } @Test public void notifyListeners_onReceiveUserSwitchBroadcast() { ArgumentCaptor<BroadcastReceiver> callbackCaptor = Loading Loading @@ -254,7 +269,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { } @Test public void hideSilentNotificationsPerUserSetting() { public void keyguardShowing_hideSilentNotifications_perUserSetting() { when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); Loading @@ -266,6 +281,41 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); } @Test public void keyguardShowing_hideSilentNotifications_perUserSetting_withHighPriorityParent() { 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(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); Loading Loading @@ -301,6 +351,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { public void keyguardNotShowing() { // GIVEN the lockscreen isn't showing setupUnfilteredState(mEntry); when(mKeyguardStateController.isShowing()).thenReturn(false); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(SHADE); // THEN don't filter out the entry Loading Loading @@ -443,6 +494,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { */ private void setupUnfilteredState(NotificationEntry entry) { // keyguard is showing when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); // show notifications on the lockscreen Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/interruption/KeyguardNotificationVisibilityProvider.kt +10 −5 Original line number Diff line number Diff line Loading @@ -107,8 +107,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( if (uri == showSilentNotifsUri) { readShowSilentNotificationSetting() } if (statusBarStateController.getCurrentOrUpcomingState() == StatusBarState.KEYGUARD) { if (isLockedOrLocking) { notifyStateChanged("Settings $uri changed") } } Loading @@ -134,14 +133,16 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( // register (maybe) public mode changed callbacks: statusBarStateController.addCallback(object : StatusBarStateController.StateListener { override fun onStateChanged(newState: Int) { notifyStateChanged("onStatusBarStateChanged") } override fun onUpcomingStateChanged(state: Int) { notifyStateChanged("onStatusBarUpcomingStateChanged") } }) broadcastDispatcher.registerReceiver(object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { if (statusBarStateController.getCurrentOrUpcomingState() == StatusBarState.KEYGUARD) { if (isLockedOrLocking) { // maybe public mode changed notifyStateChanged(intent.action!!) } Loading @@ -163,7 +164,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( override fun shouldHideNotification(entry: NotificationEntry): Boolean = when { // Keyguard state doesn't matter if the keyguard is not showing. statusBarStateController.getCurrentOrUpcomingState() != StatusBarState.KEYGUARD -> false !isLockedOrLocking -> false // Notifications not allowed on the lockscreen, always hide. !lockscreenUserManager.shouldShowLockscreenNotifications() -> true // User settings do not allow this notification on the lockscreen, so hide it. Loading Loading @@ -208,6 +209,10 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor( } } private val isLockedOrLocking get() = keyguardStateController.isShowing || statusBarStateController.currentOrUpcomingState == StatusBarState.KEYGUARD 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 +54 −2 Original line number Diff line number Diff line Loading @@ -173,7 +173,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { } @Test public void notifyListeners_onStatusBarStateChanged() { public void notifyListeners_onStatusBarUpcomingStateChanged() { ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor = ArgumentCaptor.forClass(StatusBarStateController.StateListener.class); verify(mStatusBarStateController).addCallback(callbackCaptor.capture()); Loading @@ -187,6 +187,21 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { verify(listener).accept(anyString()); } @Test public void notifyListeners_onStatusBarStateChanged() { ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor = ArgumentCaptor.forClass(StatusBarStateController.StateListener.class); verify(mStatusBarStateController).addCallback(callbackCaptor.capture()); StatusBarStateController.StateListener callback = callbackCaptor.getValue(); Consumer<String> listener = mock(Consumer.class); mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener); callback.onStateChanged(0); verify(listener).accept(anyString()); } @Test public void notifyListeners_onReceiveUserSwitchBroadcast() { ArgumentCaptor<BroadcastReceiver> callbackCaptor = Loading Loading @@ -254,7 +269,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { } @Test public void hideSilentNotificationsPerUserSetting() { public void keyguardShowing_hideSilentNotifications_perUserSetting() { when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); Loading @@ -266,6 +281,41 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); } @Test public void keyguardShowing_hideSilentNotifications_perUserSetting_withHighPriorityParent() { 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(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); Loading Loading @@ -301,6 +351,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { public void keyguardNotShowing() { // GIVEN the lockscreen isn't showing setupUnfilteredState(mEntry); when(mKeyguardStateController.isShowing()).thenReturn(false); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(SHADE); // THEN don't filter out the entry Loading Loading @@ -443,6 +494,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase { */ private void setupUnfilteredState(NotificationEntry entry) { // keyguard is showing when(mKeyguardStateController.isShowing()).thenReturn(true); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); // show notifications on the lockscreen Loading