Uprank colorized FSNs

Fixes: 151834960
Test: manual
Change-Id: I9408b9a500f3ae4989c16a4951c1783840f3ac42
This commit is contained in:
Steve Elliott
2020-05-20 08:36:35 -04:00
parent f7b6901230
commit 421c529782
2 changed files with 76 additions and 20 deletions

View File

@@ -74,11 +74,14 @@ open class NotificationRankingManager @Inject constructor(
val aRank = a.ranking.rank
val bRank = b.ranking.rank
val aIsFsn = a.isColorizedForegroundService()
val bIsFsn = b.isColorizedForegroundService()
val aPersonType = a.getPeopleNotificationType()
val bPersonType = b.getPeopleNotificationType()
val aMedia = isImportantMedia(a)
val bMedia = isImportantMedia(b)
val aMedia = a.isImportantMedia()
val bMedia = b.isImportantMedia()
val aSystemMax = a.isSystemMax()
val bSystemMax = b.isSystemMax()
@@ -92,7 +95,7 @@ open class NotificationRankingManager @Inject constructor(
aHeadsUp != bHeadsUp -> if (aHeadsUp) -1 else 1
// Provide consistent ranking with headsUpManager
aHeadsUp -> headsUpManager.compare(a, b)
aIsFsn != bIsFsn -> if (aIsFsn) -1 else 1
usePeopleFiltering && aPersonType != bPersonType ->
peopleNotificationIdentifier.compareTo(aPersonType, bPersonType)
// Upsort current media notification.
@@ -106,11 +109,6 @@ open class NotificationRankingManager @Inject constructor(
}
}
private fun isImportantMedia(entry: NotificationEntry): Boolean {
val importance = entry.ranking.importance
return entry.key == mediaManager.mediaNotificationKey && importance > IMPORTANCE_MIN
}
fun updateRanking(
newRankingMap: RankingMap?,
entries: Collection<NotificationEntry>,
@@ -153,15 +151,12 @@ open class NotificationRankingManager @Inject constructor(
@PriorityBucket
private fun getBucketForEntry(entry: NotificationEntry): Int {
val isHeadsUp = entry.isRowHeadsUp
val isMedia = isImportantMedia(entry)
val isMedia = entry.isImportantMedia()
val isSystemMax = entry.isSystemMax()
return when {
entry.sbn.notification.isForegroundService && entry.sbn.notification.isColorized ->
BUCKET_FOREGROUND_SERVICE
usePeopleFiltering && entry.getPeopleNotificationType() != TYPE_NON_PERSON ->
BUCKET_PEOPLE
isHeadsUp || isMedia || isSystemMax || entry.isHighPriority() ->
BUCKET_ALERTING
entry.isColorizedForegroundService() -> BUCKET_FOREGROUND_SERVICE
usePeopleFiltering && entry.isConversation() -> BUCKET_PEOPLE
isHeadsUp || isMedia || isSystemMax || entry.isHighPriority() -> BUCKET_ALERTING
else -> BUCKET_SILENT
}
}
@@ -190,6 +185,11 @@ open class NotificationRankingManager @Inject constructor(
}
}
private fun NotificationEntry.isImportantMedia() =
key == mediaManager.mediaNotificationKey && ranking.importance > IMPORTANCE_MIN
private fun NotificationEntry.isConversation() = getPeopleNotificationType() != TYPE_NON_PERSON
private fun NotificationEntry.getPeopleNotificationType() =
peopleNotificationIdentifier.getPeopleNotificationType(sbn, ranking)
@@ -198,10 +198,12 @@ open class NotificationRankingManager @Inject constructor(
}
// Convenience functions
private fun NotificationEntry.isSystemMax(): Boolean {
return importance >= IMPORTANCE_HIGH && sbn.isSystemNotification()
}
private fun NotificationEntry.isSystemMax() =
importance >= IMPORTANCE_HIGH && sbn.isSystemNotification()
private fun StatusBarNotification.isSystemNotification(): Boolean {
return "android" == packageName || "com.android.systemui" == packageName
private fun StatusBarNotification.isSystemNotification() =
"android" == packageName || "com.android.systemui" == packageName
private fun NotificationEntry.isColorizedForegroundService() = sbn.notification.run {
isForegroundService && isColorized && importance > IMPORTANCE_MIN
}

View File

@@ -38,9 +38,11 @@ import com.android.systemui.statusbar.notification.people.PeopleNotificationIden
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.stack.BUCKET_ALERTING
import com.android.systemui.statusbar.notification.stack.BUCKET_FOREGROUND_SERVICE
import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT
import com.android.systemui.statusbar.phone.NotificationGroupManager
import com.android.systemui.statusbar.policy.HeadsUpManager
import com.google.common.truth.Truth.assertThat
import dagger.Lazy
import junit.framework.Assert.assertEquals
import org.junit.Before
@@ -353,6 +355,58 @@ class NotificationRankingManagerTest : SysuiTestCase() {
assertEquals(false, e.hasFinishedInitialization())
}
@Test
fun testSort_colorizedForegroundService() {
whenever(sectionsManager.isFilteringEnabled()).thenReturn(true)
val a = NotificationEntryBuilder()
.setImportance(IMPORTANCE_HIGH)
.setPkg("pkg")
.setOpPkg("pkg")
.setTag("tag")
.setNotification(
Notification.Builder(mContext, "test")
.build())
.setChannel(NotificationChannel("test", "", IMPORTANCE_DEFAULT))
.setUser(mContext.getUser())
.setOverrideGroupKey("")
.build()
val b = NotificationEntryBuilder()
.setImportance(IMPORTANCE_DEFAULT) // high priority
.setPkg("pkg2")
.setOpPkg("pkg2")
.setTag("tag")
.setNotification(mock(Notification::class.java).also { notif ->
whenever(notif.isForegroundService).thenReturn(true)
whenever(notif.isColorized).thenReturn(true)
})
.setChannel(NotificationChannel("test", "", IMPORTANCE_DEFAULT))
.setUser(mContext.getUser())
.setOverrideGroupKey("")
.build()
val cN = Notification.Builder(mContext, "test")
.setStyle(Notification.MessagingStyle(""))
.build()
val c = NotificationEntryBuilder()
.setImportance(IMPORTANCE_HIGH)
.setPkg("pkg")
.setOpPkg("pkg")
.setTag("tag")
.setNotification(cN)
.setChannel(NotificationChannel("test", "", IMPORTANCE_DEFAULT))
.setUser(mContext.user)
.setOverrideGroupKey("")
.build()
whenever(personNotificationIdentifier.getPeopleNotificationType(a.sbn, a.ranking))
.thenReturn(TYPE_IMPORTANT_PERSON)
assertThat(rankingManager.updateRanking(null, listOf(a, b, c), "test"))
.containsExactly(b, c, a)
assertThat(b.bucket).isEqualTo(BUCKET_FOREGROUND_SERVICE)
}
internal class TestableNotificationRankingManager(
mediaManager: Lazy<NotificationMediaManager>,
groupManager: NotificationGroupManager,