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,6 +188,7 @@ class MediaDeviceManager @Inject constructor(
@AnyThread @AnyThread
fun start() = bgExecutor.execute { fun start() = bgExecutor.execute {
if (!started) {
localMediaManager.registerCallback(this) localMediaManager.registerCallback(this)
localMediaManager.startScan() localMediaManager.startScan()
muteAwaitConnectionManager?.startListening() muteAwaitConnectionManager?.startListening()
@@ -197,9 +198,11 @@ class MediaDeviceManager @Inject constructor(
started = true started = true
configurationController.addCallback(configListener) configurationController.addCallback(configListener)
} }
}
@AnyThread @AnyThread
fun stop() = bgExecutor.execute { fun stop() = bgExecutor.execute {
if (started) {
started = false started = false
controller?.unregisterCallback(this) controller?.unregisterCallback(this)
localMediaManager.stopScan() localMediaManager.stopScan()
@@ -207,6 +210,7 @@ class MediaDeviceManager @Inject constructor(
muteAwaitConnectionManager?.stopListening() muteAwaitConnectionManager?.stopListening()
configurationController.removeCallback(configListener) configurationController.removeCallback(configListener)
} }
}
fun dump(pw: PrintWriter) { fun dump(pw: PrintWriter) {
val routingSession = controller?.let { val routingSession = controller?.let {