From 8cdfdb6c0dbdfdfa49ec5742b053dc7a4de9acd9 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 24 Apr 2020 12:03:33 -0400 Subject: [PATCH] Distinguish shortcut vs non shortcut convos Test: atest Bug: 154814754 Change-Id: If4f0e6c73db926ab1f8f1e1c9c4911784d85d8ef --- .../collection/NotificationRankingManager.kt | 17 +++---- .../people/PeopleNotificationIdentifier.kt | 24 +++++++-- .../NotificationRankingManagerTest.kt | 51 +++++++++++++++++++ 3 files changed, 76 insertions(+), 16 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt index ec17f4ed868c4..9738bcc692792 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt @@ -34,12 +34,13 @@ import com.android.systemui.statusbar.notification.stack.NotificationSectionsMan import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_HEADS_UP import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_SILENT + import com.android.systemui.statusbar.phone.NotificationGroupManager import com.android.systemui.statusbar.policy.HeadsUpManager import dagger.Lazy -import java.util.Comparator -import java.util.Objects +import java.util.Objects; import javax.inject.Inject +import kotlin.Comparator private const val TAG = "NotifRankingManager" @@ -90,19 +91,13 @@ open class NotificationRankingManager @Inject constructor( val aIsHighPriority = a.isHighPriority() val bIsHighPriority = b.isHighPriority() - when { aHeadsUp != bHeadsUp -> if (aHeadsUp) -1 else 1 // Provide consistent ranking with headsUpManager aHeadsUp -> headsUpManager.compare(a, b) - usePeopleFiltering && aPersonType != bPersonType -> when (aPersonType) { - TYPE_IMPORTANT_PERSON -> -1 - TYPE_PERSON -> when (bPersonType) { - TYPE_IMPORTANT_PERSON -> 1 - else -> -1 - } - else -> 1 - } + + usePeopleFiltering && aPersonType != bPersonType -> + peopleNotificationIdentifier.compareTo(aPersonType, bPersonType) // Upsort current media notification. aMedia != bMedia -> if (aMedia) -1 else 1 // Upsort PRIORITY_MAX system notifications diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleNotificationIdentifier.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleNotificationIdentifier.kt index 5879c15c24930..d36627fb849d8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleNotificationIdentifier.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleNotificationIdentifier.kt @@ -20,6 +20,7 @@ import android.annotation.IntDef import android.service.notification.NotificationListenerService.Ranking import android.service.notification.StatusBarNotification import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.PeopleNotificationType +import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_FULL_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_IMPORTANT_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_PERSON @@ -33,21 +34,28 @@ interface PeopleNotificationIdentifier { /** * Identifies if the given notification can be classified as a "People" notification. * - * @return [TYPE_NON_PERSON] if not a people notification, [TYPE_PERSON] if a standard people - * notification, and [TYPE_IMPORTANT_PERSON] if an "important" people notification. + * @return [TYPE_NON_PERSON] if not a people notification, [TYPE_PERSON] if it is a people + * notification that doesn't use shortcuts, [TYPE_FULL_PERSON] if it is a person notification + * that users shortcuts, and [TYPE_IMPORTANT_PERSON] if an "important" people notification + * that users shortcuts. */ @PeopleNotificationType fun getPeopleNotificationType(sbn: StatusBarNotification, ranking: Ranking): Int + fun compareTo(@PeopleNotificationType a: Int, + @PeopleNotificationType b: Int): Int + companion object { @Retention(AnnotationRetention.SOURCE) - @IntDef(prefix = ["TYPE_"], value = [TYPE_NON_PERSON, TYPE_PERSON, TYPE_IMPORTANT_PERSON]) + @IntDef(prefix = ["TYPE_"], value = [TYPE_NON_PERSON, TYPE_PERSON, TYPE_FULL_PERSON, + TYPE_IMPORTANT_PERSON]) annotation class PeopleNotificationType const val TYPE_NON_PERSON = 0 const val TYPE_PERSON = 1 - const val TYPE_IMPORTANT_PERSON = 2 + const val TYPE_FULL_PERSON = 2 + const val TYPE_IMPORTANT_PERSON = 3 } } @@ -69,6 +77,11 @@ class PeopleNotificationIdentifierImpl @Inject constructor( } } + override fun compareTo(@PeopleNotificationType a: Int, + @PeopleNotificationType b: Int): Int { + return b.compareTo(a); + } + /** * Given two [PeopleNotificationType]s, determine the upper bound. Used to constrain a * notification to a type given multiple signals, i.e. notification groups, where each child @@ -84,8 +97,9 @@ class PeopleNotificationIdentifierImpl @Inject constructor( private val Ranking.personTypeInfo get() = when { !isConversation -> TYPE_NON_PERSON + shortcutInfo == null -> TYPE_PERSON channel?.isImportantConversation == true -> TYPE_IMPORTANT_PERSON - else -> TYPE_PERSON + else -> TYPE_FULL_PERSON } private fun extractPersonTypeInfo(sbn: StatusBarNotification) = diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManagerTest.kt index a2599ecb50da4..b4cabfd1855d3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManagerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManagerTest.kt @@ -32,6 +32,7 @@ import com.android.systemui.statusbar.notification.NotificationFilter import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier +import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_FULL_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_IMPORTANT_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_PERSON import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow @@ -228,6 +229,56 @@ class NotificationRankingManagerTest : SysuiTestCase() { whenever(personNotificationIdentifier.getPeopleNotificationType(b.sbn, b.ranking)) .thenReturn(TYPE_IMPORTANT_PERSON) + whenever(personNotificationIdentifier.compareTo(TYPE_PERSON, TYPE_IMPORTANT_PERSON)) + .thenReturn(TYPE_IMPORTANT_PERSON.compareTo(TYPE_PERSON)) + whenever(personNotificationIdentifier.compareTo(TYPE_IMPORTANT_PERSON, TYPE_PERSON)) + .thenReturn(TYPE_PERSON.compareTo(TYPE_IMPORTANT_PERSON)) + + assertEquals( + listOf(b, a), + rankingManager.updateRanking(null, listOf(a, b), "test")) + } + + @Test + fun testSort_fullPeople() { + whenever(sectionsManager.isFilteringEnabled()).thenReturn(true) + val aN = Notification.Builder(mContext, "test") + .setStyle(Notification.MessagingStyle("")) + .build() + val a = NotificationEntryBuilder() + .setImportance(IMPORTANCE_HIGH) + .setPkg("pkg") + .setOpPkg("pkg") + .setTag("tag") + .setNotification(aN) + .setChannel(NotificationChannel("test", "", IMPORTANCE_DEFAULT)) + .setUser(mContext.user) + .setOverrideGroupKey("") + .build() + whenever(personNotificationIdentifier.getPeopleNotificationType(a.sbn, a.ranking)) + .thenReturn(TYPE_PERSON) + + val bN = Notification.Builder(mContext, "test") + .setStyle(Notification.MessagingStyle("")) + .build() + val b = NotificationEntryBuilder() + .setImportance(IMPORTANCE_HIGH) + .setPkg("pkg2") + .setOpPkg("pkg2") + .setTag("tag") + .setNotification(bN) + .setChannel(NotificationChannel("test", "", IMPORTANCE_DEFAULT)) + .setUser(mContext.user) + .setOverrideGroupKey("") + .build() + whenever(personNotificationIdentifier.getPeopleNotificationType(b.sbn, b.ranking)) + .thenReturn(TYPE_FULL_PERSON) + + whenever(personNotificationIdentifier.compareTo(TYPE_PERSON, TYPE_FULL_PERSON)) + .thenReturn(TYPE_FULL_PERSON.compareTo(TYPE_PERSON)) + whenever(personNotificationIdentifier.compareTo(TYPE_FULL_PERSON, TYPE_PERSON)) + .thenReturn(TYPE_PERSON.compareTo(TYPE_FULL_PERSON)) + assertEquals( listOf(b, a), rankingManager.updateRanking(null, listOf(a, b), "test"))