Merge "Distinguish shortcut vs non shortcut convos" into rvc-dev am: a3460d1831

Change-Id: I5afb3ecab3a0cedbc25267971c879d2461f27339
This commit is contained in:
TreeHugger Robot
2020-04-27 15:14:30 +00:00
committed by Automerger Merge Worker
3 changed files with 76 additions and 16 deletions

View File

@@ -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_HEADS_UP
import com.android.systemui.statusbar.notification.stack.NotificationSectionsManager.BUCKET_PEOPLE 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.notification.stack.NotificationSectionsManager.BUCKET_SILENT
import com.android.systemui.statusbar.phone.NotificationGroupManager import com.android.systemui.statusbar.phone.NotificationGroupManager
import com.android.systemui.statusbar.policy.HeadsUpManager import com.android.systemui.statusbar.policy.HeadsUpManager
import dagger.Lazy import dagger.Lazy
import java.util.Comparator import java.util.Objects;
import java.util.Objects
import javax.inject.Inject import javax.inject.Inject
import kotlin.Comparator
private const val TAG = "NotifRankingManager" private const val TAG = "NotifRankingManager"
@@ -90,19 +91,13 @@ open class NotificationRankingManager @Inject constructor(
val aIsHighPriority = a.isHighPriority() val aIsHighPriority = a.isHighPriority()
val bIsHighPriority = b.isHighPriority() val bIsHighPriority = b.isHighPriority()
when { when {
aHeadsUp != bHeadsUp -> if (aHeadsUp) -1 else 1 aHeadsUp != bHeadsUp -> if (aHeadsUp) -1 else 1
// Provide consistent ranking with headsUpManager // Provide consistent ranking with headsUpManager
aHeadsUp -> headsUpManager.compare(a, b) aHeadsUp -> headsUpManager.compare(a, b)
usePeopleFiltering && aPersonType != bPersonType -> when (aPersonType) {
TYPE_IMPORTANT_PERSON -> -1 usePeopleFiltering && aPersonType != bPersonType ->
TYPE_PERSON -> when (bPersonType) { peopleNotificationIdentifier.compareTo(aPersonType, bPersonType)
TYPE_IMPORTANT_PERSON -> 1
else -> -1
}
else -> 1
}
// Upsort current media notification. // Upsort current media notification.
aMedia != bMedia -> if (aMedia) -1 else 1 aMedia != bMedia -> if (aMedia) -1 else 1
// Upsort PRIORITY_MAX system notifications // Upsort PRIORITY_MAX system notifications

View File

@@ -20,6 +20,7 @@ import android.annotation.IntDef
import android.service.notification.NotificationListenerService.Ranking import android.service.notification.NotificationListenerService.Ranking
import android.service.notification.StatusBarNotification import android.service.notification.StatusBarNotification
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.PeopleNotificationType 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_IMPORTANT_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_NON_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_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. * 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 * @return [TYPE_NON_PERSON] if not a people notification, [TYPE_PERSON] if it is a people
* notification, and [TYPE_IMPORTANT_PERSON] if an "important" people notification. * 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 @PeopleNotificationType
fun getPeopleNotificationType(sbn: StatusBarNotification, ranking: Ranking): Int fun getPeopleNotificationType(sbn: StatusBarNotification, ranking: Ranking): Int
fun compareTo(@PeopleNotificationType a: Int,
@PeopleNotificationType b: Int): Int
companion object { companion object {
@Retention(AnnotationRetention.SOURCE) @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 annotation class PeopleNotificationType
const val TYPE_NON_PERSON = 0 const val TYPE_NON_PERSON = 0
const val TYPE_PERSON = 1 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 * 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 * 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 private val Ranking.personTypeInfo
get() = when { get() = when {
!isConversation -> TYPE_NON_PERSON !isConversation -> TYPE_NON_PERSON
shortcutInfo == null -> TYPE_PERSON
channel?.isImportantConversation == true -> TYPE_IMPORTANT_PERSON channel?.isImportantConversation == true -> TYPE_IMPORTANT_PERSON
else -> TYPE_PERSON else -> TYPE_FULL_PERSON
} }
private fun extractPersonTypeInfo(sbn: StatusBarNotification) = private fun extractPersonTypeInfo(sbn: StatusBarNotification) =

View File

@@ -32,6 +32,7 @@ import com.android.systemui.statusbar.notification.NotificationFilter
import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager import com.android.systemui.statusbar.notification.NotificationSectionsFeatureManager
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider 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
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_IMPORTANT_PERSON
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_PERSON import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier.Companion.TYPE_PERSON
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
@@ -228,6 +229,56 @@ class NotificationRankingManagerTest : SysuiTestCase() {
whenever(personNotificationIdentifier.getPeopleNotificationType(b.sbn, b.ranking)) whenever(personNotificationIdentifier.getPeopleNotificationType(b.sbn, b.ranking))
.thenReturn(TYPE_IMPORTANT_PERSON) .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( assertEquals(
listOf(b, a), listOf(b, a),
rankingManager.updateRanking(null, listOf(a, b), "test")) rankingManager.updateRanking(null, listOf(a, b), "test"))