Merge "Fix flaky important people sort test" into rvc-dev am: 8faccab86e
Change-Id: I29478a576e3dcd8c8246b0cff495b1eaaa8c1751
This commit is contained in:
@@ -58,7 +58,7 @@ open class NotificationRankingManager @Inject constructor(
|
|||||||
private val headsUpManager: HeadsUpManager,
|
private val headsUpManager: HeadsUpManager,
|
||||||
private val notifFilter: NotificationFilter,
|
private val notifFilter: NotificationFilter,
|
||||||
private val logger: NotificationEntryManagerLogger,
|
private val logger: NotificationEntryManagerLogger,
|
||||||
sectionsFeatureManager: NotificationSectionsFeatureManager,
|
private val sectionsFeatureManager: NotificationSectionsFeatureManager,
|
||||||
private val peopleNotificationIdentifier: PeopleNotificationIdentifier,
|
private val peopleNotificationIdentifier: PeopleNotificationIdentifier,
|
||||||
private val highPriorityProvider: HighPriorityProvider
|
private val highPriorityProvider: HighPriorityProvider
|
||||||
) {
|
) {
|
||||||
@@ -68,7 +68,8 @@ open class NotificationRankingManager @Inject constructor(
|
|||||||
private val mediaManager by lazy {
|
private val mediaManager by lazy {
|
||||||
mediaManagerLazy.get()
|
mediaManagerLazy.get()
|
||||||
}
|
}
|
||||||
private val usePeopleFiltering: Boolean = sectionsFeatureManager.isFilteringEnabled()
|
private val usePeopleFiltering: Boolean
|
||||||
|
get() = sectionsFeatureManager.isFilteringEnabled()
|
||||||
private val rankingComparator: Comparator<NotificationEntry> = Comparator { a, b ->
|
private val rankingComparator: Comparator<NotificationEntry> = Comparator { a, b ->
|
||||||
val na = a.sbn
|
val na = a.sbn
|
||||||
val nb = b.sbn
|
val nb = b.sbn
|
||||||
@@ -123,36 +124,31 @@ open class NotificationRankingManager @Inject constructor(
|
|||||||
entries: Collection<NotificationEntry>,
|
entries: Collection<NotificationEntry>,
|
||||||
reason: String
|
reason: String
|
||||||
): List<NotificationEntry> {
|
): List<NotificationEntry> {
|
||||||
val eSeq = entries.asSequence()
|
|
||||||
|
|
||||||
// TODO: may not be ideal to guard on null here, but this code is implementing exactly what
|
// TODO: may not be ideal to guard on null here, but this code is implementing exactly what
|
||||||
// NotificationData used to do
|
// NotificationData used to do
|
||||||
if (newRankingMap != null) {
|
if (newRankingMap != null) {
|
||||||
rankingMap = newRankingMap
|
rankingMap = newRankingMap
|
||||||
updateRankingForEntries(eSeq)
|
updateRankingForEntries(entries)
|
||||||
}
|
}
|
||||||
|
return synchronized(this) {
|
||||||
val filtered: Sequence<NotificationEntry>
|
filterAndSortLocked(entries, reason)
|
||||||
synchronized(this) {
|
|
||||||
filtered = filterAndSortLocked(eSeq, reason)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return filtered.toList()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Uses the [rankingComparator] to sort notifications which aren't filtered */
|
/** Uses the [rankingComparator] to sort notifications which aren't filtered */
|
||||||
private fun filterAndSortLocked(
|
private fun filterAndSortLocked(
|
||||||
entries: Sequence<NotificationEntry>,
|
entries: Collection<NotificationEntry>,
|
||||||
reason: String
|
reason: String
|
||||||
): Sequence<NotificationEntry> {
|
): List<NotificationEntry> {
|
||||||
logger.logFilterAndSort(reason)
|
logger.logFilterAndSort(reason)
|
||||||
|
val filtered = entries.asSequence()
|
||||||
return entries.filter { !notifFilter.shouldFilterOut(it) }
|
.filterNot(notifFilter::shouldFilterOut)
|
||||||
.sortedWith(rankingComparator)
|
.sortedWith(rankingComparator)
|
||||||
.map {
|
.toList()
|
||||||
assignBucketForEntry(it)
|
for (entry in filtered) {
|
||||||
it
|
assignBucketForEntry(entry)
|
||||||
}
|
}
|
||||||
|
return filtered
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun assignBucketForEntry(entry: NotificationEntry) {
|
private fun assignBucketForEntry(entry: NotificationEntry) {
|
||||||
@@ -179,13 +175,13 @@ open class NotificationRankingManager @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateRankingForEntries(entries: Sequence<NotificationEntry>) {
|
private fun updateRankingForEntries(entries: Iterable<NotificationEntry>) {
|
||||||
rankingMap?.let { rankingMap ->
|
rankingMap?.let { rankingMap ->
|
||||||
synchronized(entries) {
|
synchronized(entries) {
|
||||||
entries.forEach { entry ->
|
for (entry in entries) {
|
||||||
val newRanking = Ranking()
|
val newRanking = Ranking()
|
||||||
if (!rankingMap.getRanking(entry.key, newRanking)) {
|
if (!rankingMap.getRanking(entry.key, newRanking)) {
|
||||||
return@forEach
|
continue
|
||||||
}
|
}
|
||||||
entry.ranking = newRanking
|
entry.ranking = newRanking
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user