From bf91f0b8ce0ebb4c597cae7d8da0fc6fd4323cce Mon Sep 17 00:00:00 2001 From: Santiago Seifert Date: Thu, 20 Apr 2023 11:34:31 +0000 Subject: [PATCH] Update current device when volume control id changes The volume control id determines the routing session info associated to the media session. This means when transferring remote to remote, the check before this changewon't detect the playback transfer, as it only checks for REMOTE <-> LOCAL. With this check, we will update the current media device whenever the media session advertises its association with a different routing session info. Bug: 269985505 Test: atest MediaDeviceManagerTest Change-Id: Ifdbec9e6353602fd9e1774f3aa8d97363f8e506d --- .../controls/pipeline/MediaDeviceManager.kt | 11 +++++++++- .../pipeline/MediaDeviceManagerTest.kt | 21 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDeviceManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDeviceManager.kt index 120704c0582ab..3fc3ad682bc73 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDeviceManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDeviceManager.kt @@ -154,6 +154,7 @@ constructor( get() = controller?.sessionToken private var started = false private var playbackType = PLAYBACK_TYPE_UNKNOWN + private var playbackVolumeControlId: String? = null private var current: MediaDeviceData? = null set(value) { val sameWithoutIcon = value != null && value.equalsWithoutIcon(field) @@ -181,6 +182,7 @@ constructor( localMediaManager.startScan() muteAwaitConnectionManager?.startListening() playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN + playbackVolumeControlId = controller?.playbackInfo?.volumeControlId controller?.registerCallback(this) updateCurrent() started = true @@ -209,6 +211,8 @@ constructor( println(" current device is ${current?.name}") val type = controller?.playbackInfo?.playbackType println(" PlaybackType=$type (1 for local, 2 for remote) cached=$playbackType") + val volumeControlId = controller?.playbackInfo?.volumeControlId + println(" volumeControlId=$volumeControlId cached= $playbackVolumeControlId") println(" routingSession=$routingSession") println(" selectedRoutes=$selectedRoutes") } @@ -217,10 +221,15 @@ constructor( @WorkerThread override fun onAudioInfoChanged(info: MediaController.PlaybackInfo?) { val newPlaybackType = info?.playbackType ?: PLAYBACK_TYPE_UNKNOWN - if (newPlaybackType == playbackType) { + val newPlaybackVolumeControlId = info?.volumeControlId + if ( + newPlaybackType == playbackType && + newPlaybackVolumeControlId == playbackVolumeControlId + ) { return } playbackType = newPlaybackType + playbackVolumeControlId = newPlaybackVolumeControlId updateCurrent() } diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDeviceManagerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDeviceManagerTest.kt index a45e9d9fcacf6..0c57e7b825865 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDeviceManagerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/pipeline/MediaDeviceManagerTest.kt @@ -468,7 +468,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() { } @Test - fun audioInfoChanged() { + fun audioInfoPlaybackTypeChanged() { whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_LOCAL) whenever(controller.getPlaybackInfo()).thenReturn(playbackInfo) // GIVEN a controller with local playback type @@ -485,6 +485,25 @@ public class MediaDeviceManagerTest : SysuiTestCase() { verify(mr2).getRoutingSessionForMediaController(eq(controller)) } + @Test + fun audioInfoVolumeControlIdChanged() { + whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_LOCAL) + whenever(playbackInfo.getVolumeControlId()).thenReturn(null) + whenever(controller.getPlaybackInfo()).thenReturn(playbackInfo) + // GIVEN a controller with local playback type + manager.onMediaDataLoaded(KEY, null, mediaData) + fakeBgExecutor.runAllReady() + fakeFgExecutor.runAllReady() + reset(mr2) + // WHEN onAudioInfoChanged fires with a volume control id change + whenever(playbackInfo.getVolumeControlId()).thenReturn("placeholder id") + val captor = ArgumentCaptor.forClass(MediaController.Callback::class.java) + verify(controller).registerCallback(captor.capture()) + captor.value.onAudioInfoChanged(playbackInfo) + // THEN the route is checked + verify(mr2).getRoutingSessionForMediaController(eq(controller)) + } + @Test fun audioInfoHasntChanged() { whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)