Merge "Ignore implicit high priority for 'hide silent notifs on lockscreen'" into udc-dev am: 72ccb6ee54
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23690408 Change-Id: I3b07c73aacad09dbb2f7c3e4d8b9c6bf23e2ae35 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -63,10 +63,27 @@ public class HighPriorityProvider {
|
||||
* - has a media session associated with it
|
||||
* - has messaging style
|
||||
*
|
||||
* A GroupEntry is considered high priority if its representativeEntry (summary) or children are
|
||||
* high priority
|
||||
* A GroupEntry is considered high priority if its representativeEntry (summary) or any of its
|
||||
* children are high priority.
|
||||
*/
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
@@ -77,8 +94,8 @@ public class HighPriorityProvider {
|
||||
}
|
||||
|
||||
return notifEntry.getRanking().getImportance() >= NotificationManager.IMPORTANCE_DEFAULT
|
||||
|| hasHighPriorityCharacteristics(notifEntry)
|
||||
|| hasHighPriorityChild(entry);
|
||||
|| (allowImplicit && hasHighPriorityCharacteristics(notifEntry))
|
||||
|| hasHighPriorityChild(entry, allowImplicit);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +129,7 @@ public class HighPriorityProvider {
|
||||
>= NotificationManager.IMPORTANCE_DEFAULT);
|
||||
}
|
||||
|
||||
private boolean hasHighPriorityChild(ListEntry entry) {
|
||||
private boolean hasHighPriorityChild(ListEntry entry, boolean allowImplicit) {
|
||||
if (entry instanceof NotificationEntry
|
||||
&& !mGroupMembershipManager.isGroupSummary((NotificationEntry) entry)) {
|
||||
return false;
|
||||
@@ -121,7 +138,7 @@ public class HighPriorityProvider {
|
||||
List<NotificationEntry> children = mGroupMembershipManager.getChildren(entry);
|
||||
if (children != null) {
|
||||
for (NotificationEntry child : children) {
|
||||
if (child != entry && isHighPriority(child)) {
|
||||
if (child != entry && isHighPriority(child, allowImplicit)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,8 +180,8 @@ private class KeyguardNotificationVisibilityProviderImpl @Inject constructor(
|
||||
}
|
||||
|
||||
private fun shouldHideIfEntrySilent(entry: ListEntry): Boolean = when {
|
||||
// Show if high priority (not hidden)
|
||||
highPriorityProvider.isHighPriority(entry) -> false
|
||||
// Show if explicitly high priority (not hidden)
|
||||
highPriorityProvider.isExplicitlyHighPriority(entry) -> false
|
||||
// Ambient notifications are hidden always from lock screen
|
||||
entry.representativeEntry?.isAmbient == true -> true
|
||||
// [Now notification is silent]
|
||||
|
||||
@@ -92,8 +92,9 @@ public class HighPriorityProviderTest extends SysuiTestCase {
|
||||
.getPeopleNotificationType(entry))
|
||||
.thenReturn(TYPE_PERSON);
|
||||
|
||||
// THEN it has high priority
|
||||
// THEN it has high priority BUT it has low explicit priority.
|
||||
assertTrue(mHighPriorityProvider.isHighPriority(entry));
|
||||
assertFalse(mHighPriorityProvider.isExplicitlyHighPriority(entry));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,7 +116,7 @@ public class HighPriorityProviderTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
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")
|
||||
.build();
|
||||
final NotificationEntry entry = new NotificationEntryBuilder()
|
||||
@@ -162,8 +163,9 @@ public class HighPriorityProviderTest extends SysuiTestCase {
|
||||
.getPeopleNotificationType(entry))
|
||||
.thenReturn(TYPE_NON_PERSON);
|
||||
|
||||
// THEN it has high priority
|
||||
// THEN it has high priority but low explicit priority
|
||||
assertTrue(mHighPriorityProvider.isHighPriority(entry));
|
||||
assertFalse(mHighPriorityProvider.isExplicitlyHighPriority(entry));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -257,7 +257,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
.setImportance(IMPORTANCE_LOW)
|
||||
.setParent(parent)
|
||||
.build();
|
||||
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
|
||||
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
.setUser(new UserHandle(NOTIF_USER_ID))
|
||||
.setImportance(IMPORTANCE_LOW)
|
||||
.build();
|
||||
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
|
||||
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
.setImportance(IMPORTANCE_LOW)
|
||||
.setParent(parent)
|
||||
.build();
|
||||
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
|
||||
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
mEntry = new NotificationEntryBuilder()
|
||||
.setImportance(IMPORTANCE_LOW)
|
||||
.build();
|
||||
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
|
||||
|
||||
// THEN filter out the entry
|
||||
assertTrue(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||
@@ -328,7 +328,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
mEntry = new NotificationEntryBuilder()
|
||||
.setImportance(IMPORTANCE_LOW)
|
||||
.build();
|
||||
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(false);
|
||||
|
||||
// THEN do not filter out the entry
|
||||
assertFalse(mKeyguardNotificationVisibilityProvider.shouldHideNotification(mEntry));
|
||||
@@ -345,7 +345,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
.setUser(new UserHandle(NOTIF_USER_ID))
|
||||
.setImportance(IMPORTANCE_LOW)
|
||||
.build();
|
||||
when(mHighPriorityProvider.isHighPriority(any())).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(any())).thenReturn(false);
|
||||
|
||||
// WhHEN the show silent notifs on lockscreen setting is unset
|
||||
assertNull(mFakeSettings.getString(Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS));
|
||||
@@ -460,12 +460,32 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
.setKey(mEntry.getKey())
|
||||
.setImportance(IMPORTANCE_MIN)
|
||||
.build());
|
||||
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(false);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(false);
|
||||
|
||||
// THEN filter out the entry
|
||||
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
|
||||
public void notificationVisibilityPublic() {
|
||||
// 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
|
||||
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
|
||||
assertTrue(
|
||||
mKeyguardNotificationVisibilityProvider.shouldHideNotification(entryWithParent));
|
||||
|
||||
// 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
|
||||
.setImportance(IMPORTANCE_MIN)
|
||||
.done());
|
||||
@@ -591,7 +611,7 @@ public class KeyguardNotificationVisibilityProviderTest extends SysuiTestCase {
|
||||
// notification doesn't have a summary
|
||||
|
||||
// notification is high priority, so it shouldn't be filtered
|
||||
when(mHighPriorityProvider.isHighPriority(mEntry)).thenReturn(true);
|
||||
when(mHighPriorityProvider.isExplicitlyHighPriority(mEntry)).thenReturn(true);
|
||||
}
|
||||
|
||||
@SysUISingleton
|
||||
|
||||
Reference in New Issue
Block a user