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)