Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt +6 −11 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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 Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleNotificationIdentifier.kt +19 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 } } Loading @@ -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 Loading @@ -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) = Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManagerTest.kt +51 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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")) Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManager.kt +6 −11 Original line number Diff line number Diff line Loading @@ -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" Loading Loading @@ -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 Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/people/PeopleNotificationIdentifier.kt +19 −5 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 } } Loading @@ -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 Loading @@ -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) = Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/collection/NotificationRankingManagerTest.kt +51 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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")) Loading