Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 442bc73f authored by Santiago Seifert's avatar Santiago Seifert Committed by Automerger Merge Worker
Browse files

Merge "Update current device when volume control id changes" into udc-dev am: 2f63277b

parents 3533b1bc 2f63277b
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -154,6 +154,7 @@ constructor(
            get() = controller?.sessionToken
            get() = controller?.sessionToken
        private var started = false
        private var started = false
        private var playbackType = PLAYBACK_TYPE_UNKNOWN
        private var playbackType = PLAYBACK_TYPE_UNKNOWN
        private var playbackVolumeControlId: String? = null
        private var current: MediaDeviceData? = null
        private var current: MediaDeviceData? = null
            set(value) {
            set(value) {
                val sameWithoutIcon = value != null && value.equalsWithoutIcon(field)
                val sameWithoutIcon = value != null && value.equalsWithoutIcon(field)
@@ -181,6 +182,7 @@ constructor(
                    localMediaManager.startScan()
                    localMediaManager.startScan()
                    muteAwaitConnectionManager?.startListening()
                    muteAwaitConnectionManager?.startListening()
                    playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
                    playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
                    playbackVolumeControlId = controller?.playbackInfo?.volumeControlId
                    controller?.registerCallback(this)
                    controller?.registerCallback(this)
                    updateCurrent()
                    updateCurrent()
                    started = true
                    started = true
@@ -209,6 +211,8 @@ constructor(
                println("    current device is ${current?.name}")
                println("    current device is ${current?.name}")
                val type = controller?.playbackInfo?.playbackType
                val type = controller?.playbackInfo?.playbackType
                println("    PlaybackType=$type (1 for local, 2 for remote) cached=$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("    routingSession=$routingSession")
                println("    selectedRoutes=$selectedRoutes")
                println("    selectedRoutes=$selectedRoutes")
            }
            }
@@ -217,10 +221,15 @@ constructor(
        @WorkerThread
        @WorkerThread
        override fun onAudioInfoChanged(info: MediaController.PlaybackInfo?) {
        override fun onAudioInfoChanged(info: MediaController.PlaybackInfo?) {
            val newPlaybackType = info?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
            val newPlaybackType = info?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
            if (newPlaybackType == playbackType) {
            val newPlaybackVolumeControlId = info?.volumeControlId
            if (
                newPlaybackType == playbackType &&
                    newPlaybackVolumeControlId == playbackVolumeControlId
            ) {
                return
                return
            }
            }
            playbackType = newPlaybackType
            playbackType = newPlaybackType
            playbackVolumeControlId = newPlaybackVolumeControlId
            updateCurrent()
            updateCurrent()
        }
        }


+20 −1
Original line number Original line Diff line number Diff line
@@ -468,7 +468,7 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
    }
    }


    @Test
    @Test
    fun audioInfoChanged() {
    fun audioInfoPlaybackTypeChanged() {
        whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_LOCAL)
        whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_LOCAL)
        whenever(controller.getPlaybackInfo()).thenReturn(playbackInfo)
        whenever(controller.getPlaybackInfo()).thenReturn(playbackInfo)
        // GIVEN a controller with local playback type
        // GIVEN a controller with local playback type
@@ -485,6 +485,25 @@ public class MediaDeviceManagerTest : SysuiTestCase() {
        verify(mr2).getRoutingSessionForMediaController(eq(controller))
        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
    @Test
    fun audioInfoHasntChanged() {
    fun audioInfoHasntChanged() {
        whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)
        whenever(playbackInfo.getPlaybackType()).thenReturn(PlaybackInfo.PLAYBACK_TYPE_REMOTE)