Merge "Requery silent notifs lockscreen setting on change" into tm-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9711658113
@@ -77,6 +77,8 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
|||||||
private val secureSettings: SecureSettings,
|
private val secureSettings: SecureSettings,
|
||||||
private val globalSettings: GlobalSettings
|
private val globalSettings: GlobalSettings
|
||||||
) : CoreStartable(context), KeyguardNotificationVisibilityProvider {
|
) : CoreStartable(context), KeyguardNotificationVisibilityProvider {
|
||||||
|
private val showSilentNotifsUri =
|
||||||
|
secureSettings.getUriFor(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS)
|
||||||
private val onStateChangedListeners = ListenerSet<Consumer<String>>()
|
private val onStateChangedListeners = ListenerSet<Consumer<String>>()
|
||||||
private var hideSilentNotificationsOnLockscreen: Boolean = false
|
private var hideSilentNotificationsOnLockscreen: Boolean = false
|
||||||
|
|
||||||
@@ -100,6 +102,9 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
|||||||
// register lockscreen settings changed callbacks:
|
// register lockscreen settings changed callbacks:
|
||||||
val settingsObserver: ContentObserver = object : ContentObserver(handler) {
|
val settingsObserver: ContentObserver = object : ContentObserver(handler) {
|
||||||
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
override fun onChange(selfChange: Boolean, uri: Uri?) {
|
||||||
|
if (uri == showSilentNotifsUri) {
|
||||||
|
readShowSilentNotificationSetting()
|
||||||
|
}
|
||||||
if (keyguardStateController.isShowing) {
|
if (keyguardStateController.isShowing) {
|
||||||
notifyStateChanged("Settings $uri changed")
|
notifyStateChanged("Settings $uri changed")
|
||||||
}
|
}
|
||||||
@@ -152,62 +157,50 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
|||||||
onStateChangedListeners.forEach { it.accept(reason) }
|
onStateChangedListeners.forEach { it.accept(reason) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun shouldHideNotification(entry: NotificationEntry): Boolean {
|
override fun shouldHideNotification(entry: NotificationEntry): Boolean = when {
|
||||||
val sbn = entry.sbn
|
// Keyguard state doesn't matter if the keyguard is not showing.
|
||||||
// FILTER OUT the notification when the keyguard is showing and...
|
!keyguardStateController.isShowing -> false
|
||||||
if (keyguardStateController.isShowing) {
|
// Notifications not allowed on the lockscreen, always hide.
|
||||||
// ... user settings or the device policy manager doesn't allow lockscreen
|
!lockscreenUserManager.shouldShowLockscreenNotifications() -> true
|
||||||
// notifications;
|
// User settings do not allow this notification on the lockscreen, so hide it.
|
||||||
if (!lockscreenUserManager.shouldShowLockscreenNotifications()) {
|
userSettingsDisallowNotification(entry) -> true
|
||||||
return true
|
// Parent priority is high enough to be shown on the lockscreen, do not hide.
|
||||||
}
|
entry.parent?.let(::priorityExceedsLockscreenShowingThreshold) == true -> false
|
||||||
val currUserId: Int = lockscreenUserManager.currentUserId
|
// Entry priority is high enough to be shown on the lockscreen, do not hide.
|
||||||
val notifUserId =
|
priorityExceedsLockscreenShowingThreshold(entry) -> false
|
||||||
if (sbn.user.identifier == UserHandle.USER_ALL) currUserId
|
// Priority is too low, hide.
|
||||||
else sbn.user.identifier
|
else -> true
|
||||||
|
|
||||||
// ... user is in lockdown
|
|
||||||
if (keyguardUpdateMonitor.isUserInLockdown(currUserId) ||
|
|
||||||
keyguardUpdateMonitor.isUserInLockdown(notifUserId)) {
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... device is in public mode and the user's settings doesn't allow
|
private fun userSettingsDisallowNotification(entry: NotificationEntry): Boolean {
|
||||||
// notifications to show in public mode
|
fun disallowForUser(user: Int) = when {
|
||||||
if (lockscreenUserManager.isLockscreenPublicMode(currUserId) ||
|
// user is in lockdown, always disallow
|
||||||
lockscreenUserManager.isLockscreenPublicMode(notifUserId)) {
|
keyguardUpdateMonitor.isUserInLockdown(user) -> true
|
||||||
if (entry.ranking.lockscreenVisibilityOverride == Notification.VISIBILITY_SECRET) {
|
// device isn't public, no need to check public-related settings, so allow
|
||||||
return true
|
!lockscreenUserManager.isLockscreenPublicMode(user) -> false
|
||||||
|
// entry is meant to be secret on the lockscreen, disallow
|
||||||
|
entry.ranking.lockscreenVisibilityOverride == Notification.VISIBILITY_SECRET -> true
|
||||||
|
// disallow if user disallows notifications in public
|
||||||
|
else -> !lockscreenUserManager.userAllowsNotificationsInPublic(user)
|
||||||
}
|
}
|
||||||
if (!lockscreenUserManager.userAllowsNotificationsInPublic(currUserId) ||
|
val currentUser = lockscreenUserManager.currentUserId
|
||||||
!lockscreenUserManager.userAllowsNotificationsInPublic(
|
val notifUser = entry.sbn.user.identifier
|
||||||
notifUserId)) {
|
return when {
|
||||||
return true
|
disallowForUser(currentUser) -> true
|
||||||
|
notifUser == UserHandle.USER_ALL -> false
|
||||||
|
notifUser == currentUser -> false
|
||||||
|
else -> disallowForUser(notifUser)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... neither this notification nor its group have high enough priority
|
private fun priorityExceedsLockscreenShowingThreshold(entry: ListEntry): Boolean = when {
|
||||||
// to be shown on the lockscreen
|
|
||||||
if (entry.parent != null) {
|
|
||||||
val parent = entry.parent
|
|
||||||
if (priorityExceedsLockscreenShowingThreshold(parent)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return !priorityExceedsLockscreenShowingThreshold(entry)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun priorityExceedsLockscreenShowingThreshold(entry: ListEntry?): Boolean =
|
|
||||||
when {
|
|
||||||
entry == null -> false
|
|
||||||
hideSilentNotificationsOnLockscreen -> highPriorityProvider.isHighPriority(entry)
|
hideSilentNotificationsOnLockscreen -> highPriorityProvider.isHighPriority(entry)
|
||||||
else -> entry.representativeEntry?.ranking?.isAmbient == false
|
else -> entry.representativeEntry?.ranking?.isAmbient == false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun readShowSilentNotificationSetting() {
|
private fun readShowSilentNotificationSetting() {
|
||||||
hideSilentNotificationsOnLockscreen =
|
val showSilentNotifs =
|
||||||
secureSettings.getBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, true)
|
secureSettings.getBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, true)
|
||||||
|
hideSilentNotificationsOnLockscreen = !showSilentNotifs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.notification.interruption;
|
|||||||
import static android.app.Notification.VISIBILITY_PUBLIC;
|
import static android.app.Notification.VISIBILITY_PUBLIC;
|
||||||
import static android.app.Notification.VISIBILITY_SECRET;
|
import static android.app.Notification.VISIBILITY_SECRET;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
import static android.app.NotificationManager.IMPORTANCE_HIGH;
|
||||||
|
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||||
import static android.app.NotificationManager.IMPORTANCE_MIN;
|
import static android.app.NotificationManager.IMPORTANCE_MIN;
|
||||||
|
|
||||||
import static com.android.systemui.statusbar.notification.collection.EntryUtilKt.modifyEntry;
|
import static com.android.systemui.statusbar.notification.collection.EntryUtilKt.modifyEntry;
|
||||||
@@ -209,7 +210,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
|||||||
Consumer<String> listener = mock(Consumer.class);
|
Consumer<String> listener = mock(Consumer.class);
|
||||||
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
||||||
|
|
||||||
mFakeSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 1);
|
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true);
|
||||||
|
|
||||||
verify(listener).accept(anyString());
|
verify(listener).accept(anyString());
|
||||||
}
|
}
|
||||||
@@ -220,7 +221,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
|||||||
Consumer<String> listener = mock(Consumer.class);
|
Consumer<String> listener = mock(Consumer.class);
|
||||||
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
||||||
|
|
||||||
mFakeSettings.putInt(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1);
|
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, true);
|
||||||
|
|
||||||
verify(listener).accept(anyString());
|
verify(listener).accept(anyString());
|
||||||
}
|
}
|
||||||
@@ -231,7 +232,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
|||||||
Consumer<String> listener = mock(Consumer.class);
|
Consumer<String> listener = mock(Consumer.class);
|
||||||
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
||||||
|
|
||||||
mFakeSettings.putInt(Settings.Global.ZEN_MODE, 1);
|
mFakeSettings.putBool(Settings.Global.ZEN_MODE, true);
|
||||||
|
|
||||||
verify(listener).accept(anyString());
|
verify(listener).accept(anyString());
|
||||||
}
|
}
|
||||||
@@ -242,7 +243,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
|||||||
Consumer<String> listener = mock(Consumer.class);
|
Consumer<String> listener = mock(Consumer.class);
|
||||||
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
mKeyguardNotificationVisibilityProvider.addOnStateChangedListener(listener);
|
||||||
|
|
||||||
mFakeSettings.putInt(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
|
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, true);
|
||||||
|
|
||||||
verify(listener).accept(anyString());
|
verify(listener).accept(anyString());
|
||||||
}
|
}
|
||||||
@@ -337,6 +338,25 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
|||||||
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void showSilentOnLockscreenSetting() {
|
||||||
|
// GIVEN an 'unfiltered-keyguard-showing' state
|
||||||
|
setupUnfilteredState(mEntry);
|
||||||
|
|
||||||
|
// WHEN the notification is not high priority and not ambient
|
||||||
|
mEntry.setRanking(new RankingBuilder()
|
||||||
|
.setKey(mEntry.getKey())
|
||||||
|
.setImportance(IMPORTANCE_LOW)
|
||||||
|
.build());
|
||||||
|
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(false);
|
||||||
|
|
||||||
|
// WHEN the show silent notifs on lockscreen setting is true
|
||||||
|
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, true);
|
||||||
|
|
||||||
|
// THEN do not filter out the entry
|
||||||
|
assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void summaryExceedsThresholdToShow() {
|
public void summaryExceedsThresholdToShow() {
|
||||||
// GIVEN the notification doesn't exceed the threshold to show on the lockscreen
|
// GIVEN the notification doesn't exceed the threshold to show on the lockscreen
|
||||||
@@ -360,6 +380,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
|||||||
.build());
|
.build());
|
||||||
|
|
||||||
// WHEN its parent does exceed threshold tot show on the lockscreen
|
// WHEN its parent does exceed threshold tot show on the lockscreen
|
||||||
|
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false);
|
||||||
when(mHighPriorityProvider.isHighPriority(parent)).thenReturn(true);
|
when(mHighPriorityProvider.isHighPriority(parent)).thenReturn(true);
|
||||||
|
|
||||||
// THEN don't filter out the entry
|
// THEN don't filter out the entry
|
||||||
|
|||||||
Reference in New Issue
Block a user