Merge "Ignore implicit high priority for 'hide silent notifs on lockscreen'" into udc-dev

This commit is contained in:
TreeHugger Robot
2023-06-16 23:12:25 +00:00
committed by Android (Google) Code Review
4 changed files with 60 additions and 21 deletions

View File

@@ -63,10 +63,27 @@ public class HighPriorityProvider {
* - has a media session associated with it * - has a media session associated with it
* - has messaging style * - has messaging style
* *
* A GroupEntry is considered high priority if its representativeEntry (summary) or children are * A GroupEntry is considered high priority if its representativeEntry (summary) or any of its
* high priority * children are high priority.
*/ */
public boolean isHighPriority(@Nullable ListEntry entry) { public boolean isHighPriority(@Nullable ListEntry entry) {
return isHighPriority(entry, /* allowImplicit = */ true);
}
/**
* @return true if the ListEntry is explicitly high priority, else false
*
* A NotificationEntry is considered explicitly high priority if has importance greater than or
* equal to IMPORTANCE_DEFAULT.
*
* A GroupEntry is considered explicitly high priority if its representativeEntry (summary) or
* any of its children are explicitly high priority.
*/
public boolean isExplicitlyHighPriority(@Nullable ListEntry entry) {
return isHighPriority(entry, /* allowImplicit= */ false);
}
private boolean isHighPriority(@Nullable ListEntry entry, boolean allowImplicit) {
if (entry == null) { if (entry == null) {
return false; return false;
} }
@@ -77,8 +94,8 @@ public class HighPriorityProvider {
} }
return notifEntry.getRanking().getImportance() >= NotificationManager.IMPORTANCE_DEFAULT return notifEntry.getRanking().getImportance() >= NotificationManager.IMPORTANCE_DEFAULT
|| hasHighPriorityCharacteristics(notifEntry) || (allowImplicit && hasHighPriorityCharacteristics(notifEntry))
|| hasHighPriorityChild(entry); || hasHighPriorityChild(entry, allowImplicit);
} }
/** /**
@@ -112,7 +129,7 @@ public class HighPriorityProvider {
>= NotificationManager.IMPORTANCE_DEFAULT); >= NotificationManager.IMPORTANCE_DEFAULT);
} }
private boolean hasHighPriorityChild(ListEntry entry) { private boolean hasHighPriorityChild(ListEntry entry, boolean allowImplicit) {
if (entry instanceof NotificationEntry if (entry instanceof NotificationEntry
&& !mGroupMembershipManager.isGroupSummary((NotificationEntry) entry)) { && !mGroupMembershipManager.isGroupSummary((NotificationEntry) entry)) {
return false; return false;
@@ -121,7 +138,7 @@ public class HighPriorityProvider {
List<NotificationEntry> children = mGroupMembershipManager.getChildren(entry); List<NotificationEntry> children = mGroupMembershipManager.getChildren(entry);
if (children != null) { if (children != null) {
for (NotificationEntry child : children) { for (NotificationEntry child : children) {
if (child != entry && isHighPriority(child)) { if (child != entry && isHighPriority(child, allowImplicit)) {
return true; return true;
} }
} }

View File

@@ -180,8 +180,8 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
} }
private fun shouldHideIfEntrySilent(entry: ListEntry): Boolean = when { private fun shouldHideIfEntrySilent(entry: ListEntry): Boolean = when {
// Show if high priority (not hidden) // Show if explicitly high priority (not hidden)
highPriorityProvider.isHighPriority(entry) -> false highPriorityProvider.isExplicitlyHighPriority(entry) -> false
// Ambient notifications are hidden always from lock screen // Ambient notifications are hidden always from lock screen
entry.representativeEntry?.isAmbient == true -> true entry.representativeEntry?.isAmbient == true -> true
// [Now notification is silent] // [Now notification is silent]

View File

@@ -92,8 +92,9 @@ public class HighPriorityProviderTest extends SysuiTestCase {
.getPeopleNotificationType(entry)) .getPeopleNotificationType(entry))
.thenReturn(TYPE_PERSON); .thenReturn(TYPE_PERSON);
// THEN it has high priority // THEN it has high priority BUT it has low explicit priority.
assertTrue(mHighPriorityProvider.isHighPriority(entry)); assertTrue(mHighPriorityProvider.isHighPriority(entry));
assertFalse(mHighPriorityProvider.isExplicitlyHighPriority(entry));
} }
@Test @Test
@@ -115,7 +116,7 @@ public class HighPriorityProviderTest extends SysuiTestCase {
@Test @Test
public void lowImportanceConversation() { public void lowImportanceConversation() {
// GIVEN notification is high importance and is a people notification // GIVEN notification is low importance and is a people notification
final Notification notification = new Notification.Builder(mContext, "test") final Notification notification = new Notification.Builder(mContext, "test")
.build(); .build();
final NotificationEntry entry = new NotificationEntryBuilder() final NotificationEntry entry = new NotificationEntryBuilder()
@@ -162,8 +163,9 @@ public class HighPriorityProviderTest extends SysuiTestCase {
.getPeopleNotificationType(entry)) .getPeopleNotificationType(entry))
.thenReturn(TYPE_NON_PERSON); .thenReturn(TYPE_NON_PERSON);
// THEN it has high priority // THEN it has high priority but low explicit priority
assertTrue(mHighPriorityProvider.isHighPriority(entry)); assertTrue(mHighPriorityProvider.isHighPriority(entry));
assertFalse(mHighPriorityProvider.isExplicitlyHighPriority(entry));
} }
@Test @Test

View File

@@ -257,7 +257,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
.setParent(parent) .setParent(parent)
.build(); .build();
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
} }
@@ -270,7 +270,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
.setUser(new UserHandle(NOTIF_USER_ID)) .setUser(new UserHandle(NOTIF_USER_ID))
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
.build(); .build();
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
} }
@@ -292,7 +292,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
.setParent(parent) .setParent(parent)
.build(); .build();
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
} }
@@ -309,7 +309,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
mEntry = new NotificationEntryBuilder() mEntry = new NotificationEntryBuilder()
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
.build(); .build();
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
// THEN filter out the entry // THEN filter out the entry
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
@@ -328,7 +328,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
mEntry = new NotificationEntryBuilder() mEntry = new NotificationEntryBuilder()
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
.build(); .build();
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(false);
// THEN do not filter out the entry // THEN do not filter out the entry
assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
@@ -345,7 +345,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
.setUser(new UserHandle(NOTIF_USER_ID)) .setUser(new UserHandle(NOTIF_USER_ID))
.setImportance(IMPORTANCE_LOW) .setImportance(IMPORTANCE_LOW)
.build(); .build();
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
// WhHEN the show silent notifs on lockscreen setting is unset // WhHEN the show silent notifs on lockscreen setting is unset
assertNull(mFakeSettings.getString(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS)); assertNull(mFakeSettings.getString(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS));
@@ -460,12 +460,32 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
.setKey(mEntry.getKey()) .setKey(mEntry.getKey())
.setImportance(IMPORTANCE_MIN) .setImportance(IMPORTANCE_MIN)
.build()); .build());
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(false);
// THEN filter out the entry // THEN filter out the entry
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry)); assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
} }
@Test
public void highPriorityCharacteristicsIgnored() {
// GIVEN an 'unfiltered-keyguard-showing' state with silent notifications hidden
setupUnfilteredState(mEntry);
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, true);
mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false);
// WHEN the notification doesn't exceed the threshold to show on the lockscreen, but does
// have the "high priority characteristics" that would promote it to high priority
mEntry.setRanking(new RankingBuilder()
.setKey(mEntry.getKey())
.setImportance(IMPORTANCE_MIN)
.build());
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(true);
when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(false);
// THEN filter out the entry anyway, because the user explicitly asked us to hide it
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
}
@Test @Test
public void notificationVisibilityPublic() { public void notificationVisibilityPublic() {
// GIVEN a VISIBILITY_PUBLIC notification // GIVEN a VISIBILITY_PUBLIC notification
@@ -538,14 +558,14 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
// 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); mFakeSettings.putBool(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, false);
when(mHighPriorityProvider.isHighPriority(parent)).thenReturn(true); when(mHighPriorityProvider.isExplicitlyHighPriority(parent)).thenReturn(true);
// THEN filter out the entry regardless of parent // THEN filter out the entry regardless of parent
assertTrue( assertTrue(
mKeyguardNotificationVisibilityProvider.shouldHideNotification(entryWithParent)); mKeyguardNotificationVisibilityProvider.shouldHideNotification(entryWithParent));
// WHEN its parent doesn't exceed threshold to show on lockscreen // WHEN its parent doesn't exceed threshold to show on lockscreen
when(mHighPriorityProvider.isHighPriority(parent)).thenReturn(false); when(mHighPriorityProvider.isExplicitlyHighPriority(parent)).thenReturn(false);
modifyEntry(parent.getSummary(), builder -> builder modifyEntry(parent.getSummary(), builder -> builder
.setImportance(IMPORTANCE_MIN) .setImportance(IMPORTANCE_MIN)
.done()); .done());
@@ -591,7 +611,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
// notification doesn't have a summary // notification doesn't have a summary
// notification is high priority, so it shouldn't be filtered // notification is high priority, so it shouldn't be filtered
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(true); when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(true);
} }
@SysUISingleton @SysUISingleton