Merge "Ensure notifs are filtered when device is locked" into tm-dev am: d9cefd3410

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18715241

Change-Id: I35f1e0ddb30d8c1f792efe9a1a182b553991daa7
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Steve Elliott
2022-06-04 00:11:40 +00:00
committed by Automerger Merge Worker
2 changed files with 64 additions and 7 deletions

View File

@@ -107,8 +107,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
if (uri == showSilentNotifsUri) { if (uri == showSilentNotifsUri) {
readShowSilentNotificationSetting() readShowSilentNotificationSetting()
} }
if (statusBarStateController.getCurrentOrUpcomingState() if (isLockedOrLocking) {
== StatusBarState.KEYGUARD) {
notifyStateChanged("Settings $uri changed") notifyStateChanged("Settings $uri changed")
} }
} }
@@ -134,14 +133,16 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
// register (maybe) public mode changed callbacks: // register (maybe) public mode changed callbacks:
statusBarStateController.addCallback(object : StatusBarStateController.StateListener { statusBarStateController.addCallback(object : StatusBarStateController.StateListener {
override fun onStateChanged(newState: Int) {
notifyStateChanged("onStatusBarStateChanged")
}
override fun onUpcomingStateChanged(state: Int) { override fun onUpcomingStateChanged(state: Int) {
notifyStateChanged("onStatusBarUpcomingStateChanged") notifyStateChanged("onStatusBarUpcomingStateChanged")
} }
}) })
broadcastDispatcher.registerReceiver(object : BroadcastReceiver() { broadcastDispatcher.registerReceiver(object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) { override fun onReceive(context: Context, intent: Intent) {
if (statusBarStateController.getCurrentOrUpcomingState() if (isLockedOrLocking) {
== StatusBarState.KEYGUARD) {
// maybe public mode changed // maybe public mode changed
notifyStateChanged(intent.action!!) notifyStateChanged(intent.action!!)
} }
@@ -163,7 +164,7 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
override fun shouldHideNotification(entry: NotificationEntry): Boolean = when { override fun shouldHideNotification(entry: NotificationEntry): Boolean = when {
// Keyguard state doesn't matter if the keyguard is not showing. // 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. // Notifications not allowed on the lockscreen, always hide.
!lockscreenUserManager.shouldShowLockscreenNotifications() -> true !lockscreenUserManager.shouldShowLockscreenNotifications() -> true
// User settings do not allow this notification on the lockscreen, so hide it. // User settings do not allow this notification on the lockscreen, so hide it.
@@ -208,6 +209,10 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
} }
} }
private val isLockedOrLocking get() =
keyguardStateController.isShowing ||
statusBarStateController.currentOrUpcomingState == StatusBarState.KEYGUARD
private fun readShowSilentNotificationSetting() { private fun readShowSilentNotificationSetting() {
val showSilentNotifs = val showSilentNotifs =
secureSettings.getBoolForUser(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, secureSettings.getBoolForUser(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS,

View File

@@ -173,7 +173,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
} }
@Test @Test
public void notifyListeners_onStatusBarStateChanged() { public void notifyListeners_onStatusBarUpcomingStateChanged() {
ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor = ArgumentCaptor<StatusBarStateController.StateListener> callbackCaptor =
ArgumentCaptor.forClass(StatusBarStateController.StateListener.class); ArgumentCaptor.forClass(StatusBarStateController.StateListener.class);
verify(mStatusBarStateController).addCallback(callbackCaptor.capture()); verify(mStatusBarStateController).addCallback(callbackCaptor.capture());
@@ -187,6 +187,21 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
verify(listener).accept(anyString()); 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 @Test
public void notifyListeners_onReceiveUserSwitchBroadcast() { public void notifyListeners_onReceiveUserSwitchBroadcast() {
ArgumentCaptor<BroadcastReceiver> callbackCaptor = ArgumentCaptor<BroadcastReceiver> callbackCaptor =
@@ -254,7 +269,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
} }
@Test @Test
public void hideSilentNotificationsPerUserSetting() { public void keyguardShowing_hideSilentNotifications_perUserSetting() {
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true);
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false);
@@ -266,6 +281,41 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); 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 @Test
public void notifyListeners_onSettingChange_zenMode() { public void notifyListeners_onSettingChange_zenMode() {
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
@@ -301,6 +351,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
public void keyguardNotShowing() { public void keyguardNotShowing() {
// GIVEN the lockscreen isn't showing // GIVEN the lockscreen isn't showing
setupUnfilteredState(mEntry); setupUnfilteredState(mEntry);
when(mKeyguardStateController.isShowing()).thenReturn(false);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(SHADE); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(SHADE);
// THEN don't filter out the entry // THEN don't filter out the entry
@@ -443,6 +494,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
*/ */
private void setupUnfilteredState(NotificationEntry entry) { private void setupUnfilteredState(NotificationEntry entry) {
// keyguard is showing // keyguard is showing
when(mKeyguardStateController.isShowing()).thenReturn(true);
when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD); when(mStatusBarStateController.getCurrentOrUpcomingState()).thenReturn(KEYGUARD);
// show notifications on the lockscreen // show notifications on the lockscreen