Guard MediaDeviceManager.Entry against successive stop calls

This is a cherrypick of commit 543dd362fe.

It's non obvious from the code that an entry will be stopped
only once. The start() protection is added for simmetry.

Bug: 232812007
Test: Manual behavioral test.
Test: atest MediaDeviceManagerTest MediaDataCombineLatestTest
Change-Id: Icb4573d30790b4055b67eff57c495ceb6c3ae61b
Merged-In: Icb4573d30790b4055b67eff57c495ceb6c3ae61b
This commit is contained in:
Santiago Seifert
2022-07-12 15:00:26 +00:00
parent 9958359ced
commit ae173fef18

View File

@@ -188,24 +188,28 @@ class MediaDeviceManager @Inject constructor(
@AnyThread
fun start() = bgExecutor.execute {
localMediaManager.registerCallback(this)
localMediaManager.startScan()
muteAwaitConnectionManager?.startListening()
playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
controller?.registerCallback(this)
updateCurrent()
started = true
configurationController.addCallback(configListener)
if (!started) {
localMediaManager.registerCallback(this)
localMediaManager.startScan()
muteAwaitConnectionManager?.startListening()
playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
controller?.registerCallback(this)
updateCurrent()
started = true
configurationController.addCallback(configListener)
}
}
@AnyThread
fun stop() = bgExecutor.execute {
started = false
controller?.unregisterCallback(this)
localMediaManager.stopScan()
localMediaManager.unregisterCallback(this)
muteAwaitConnectionManager?.stopListening()
configurationController.removeCallback(configListener)
if (started) {
started = false
controller?.unregisterCallback(this)
localMediaManager.stopScan()
localMediaManager.unregisterCallback(this)
muteAwaitConnectionManager?.stopListening()
configurationController.removeCallback(configListener)
}
}
fun dump(pw: PrintWriter) {