Added MediaData.active to the media carousel comparator

Active apps should be prioritized above media recommendations in the media carousel based on go/media-teamfood-test.

Bug: 209148780
Test: augmented the sort test to fail without this change and pass with it
Change-Id: I556f45b423920a625418870355703ff167efaffd
This commit is contained in:
Justin Weir
2022-04-30 00:00:02 +00:00
parent fe8cf73739
commit 2e58b46209
2 changed files with 19 additions and 15 deletions

View File

@@ -926,17 +926,16 @@ internal object MediaPlayerData {
val isSsReactivated: Boolean = false
)
private val comparator =
compareByDescending<MediaSortKey> { it.data.isPlaying == true &&
it.data.playbackLocation == MediaData.PLAYBACK_LOCAL }
.thenByDescending { it.data.isPlaying == true &&
it.data.playbackLocation == MediaData.PLAYBACK_CAST_LOCAL
}
.thenByDescending { if (shouldPrioritizeSs) it.isSsMediaRec else !it.isSsMediaRec }
.thenByDescending { !it.data.resumption }
.thenByDescending { it.data.playbackLocation != MediaData.PLAYBACK_CAST_REMOTE }
.thenByDescending { it.updateTime }
.thenByDescending { it.data.notificationKey }
private val comparator = compareByDescending<MediaSortKey> {
it.data.isPlaying == true && it.data.playbackLocation == MediaData.PLAYBACK_LOCAL }
.thenByDescending {
it.data.isPlaying == true && it.data.playbackLocation == MediaData.PLAYBACK_CAST_LOCAL }
.thenByDescending { it.data.active }
.thenByDescending { shouldPrioritizeSs == it.isSsMediaRec }
.thenByDescending { !it.data.resumption }
.thenByDescending { it.data.playbackLocation != MediaData.PLAYBACK_CAST_REMOTE }
.thenByDescending { it.updateTime }
.thenByDescending { it.data.notificationKey }
private val mediaPlayers = TreeMap<MediaSortKey, MediaControlPanel>(comparator)
private val mediaData: MutableMap<String, MediaSortKey> = mutableMapOf()

View File

@@ -122,6 +122,11 @@ class MediaCarouselControllerTest : SysuiTestCase() {
playbackLocation = MediaData.PLAYBACK_CAST_REMOTE, resumption = false),
5000L)
val active = Triple("active",
DATA.copy(active = true, isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL, resumption = true),
250L)
val resume1 = Triple("resume 1",
DATA.copy(active = false, isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL, resumption = true),
@@ -140,7 +145,7 @@ class MediaCarouselControllerTest : SysuiTestCase() {
// Resume controls, by last active
val expected = listOf(playingLocal, playingCast, pausedCast, pausedLocal, playingRcn,
pausedRcn, resume2, resume1)
pausedRcn, active, resume2, resume1)
expected.forEach {
clock.setCurrentTimeMillis(it.third)
@@ -173,9 +178,9 @@ class MediaCarouselControllerTest : SysuiTestCase() {
MediaPlayerData.addMediaRecommendation(SMARTSPACE_KEY, EMPTY_SMARTSPACE_MEDIA_DATA, panel,
false, clock)
// Then it should be shown at the end of the carousel
val size = MediaPlayerData.playerKeys().size
assertTrue(MediaPlayerData.playerKeys().elementAt(size - 1).isSsMediaRec)
// Then it should be shown at the end of the carousel's active entries
val idx = MediaPlayerData.playerKeys().count { it.data.active } - 1
assertTrue(MediaPlayerData.playerKeys().elementAt(idx).isSsMediaRec)
}
@Test