Merge "Update current device when volume control id changes" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
2f63277b7f
@@ -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