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 @AnyThread
fun start() = bgExecutor.execute { fun start() = bgExecutor.execute {
localMediaManager.registerCallback(this) if (!started) {
localMediaManager.startScan() localMediaManager.registerCallback(this)
muteAwaitConnectionManager?.startListening() localMediaManager.startScan()
playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN muteAwaitConnectionManager?.startListening()
controller?.registerCallback(this) playbackType = controller?.playbackInfo?.playbackType ?: PLAYBACK_TYPE_UNKNOWN
updateCurrent() controller?.registerCallback(this)
started = true updateCurrent()
configurationController.addCallback(configListener) started = true
configurationController.addCallback(configListener)
}
} }
@AnyThread @AnyThread
fun stop() = bgExecutor.execute { fun stop() = bgExecutor.execute {
started = false if (started) {
controller?.unregisterCallback(this) started = false
localMediaManager.stopScan() controller?.unregisterCallback(this)
localMediaManager.unregisterCallback(this) localMediaManager.stopScan()
muteAwaitConnectionManager?.stopListening() localMediaManager.unregisterCallback(this)
configurationController.removeCallback(configListener) muteAwaitConnectionManager?.stopListening()
configurationController.removeCallback(configListener)
}
} }
fun dump(pw: PrintWriter) { fun dump(pw: PrintWriter) {