From 2e58b462094d380d1777901c417785400763ba54 Mon Sep 17 00:00:00 2001 From: Justin Weir Date: Sat, 30 Apr 2022 00:00:02 +0000 Subject: [PATCH] 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 --- .../systemui/media/MediaCarouselController.kt | 21 +++++++++---------- .../media/MediaCarouselControllerTest.kt | 13 ++++++++---- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt index 38128bfb70e70..3483bc39b9438 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt @@ -926,17 +926,16 @@ internal object MediaPlayerData { val isSsReactivated: Boolean = false ) - private val comparator = - compareByDescending { 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 { + 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(comparator) private val mediaData: MutableMap = mutableMapOf() diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaCarouselControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaCarouselControllerTest.kt index 1522ee8cd6d5c..0d917e3b19a87 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaCarouselControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaCarouselControllerTest.kt @@ -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