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
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user