fix(audio): clear audioSwitch synchronously in AudioSwitchHandler.stop() (#967)
Audio output could get stuck on the earpiece (very low volume) after a disconnect() + connect() on a reused Room on Android 12+ (CommDeviceAudioSwitch). stop() nulled `audioSwitch` inside the posted teardown runnable while tearing down handler/thread synchronously. Because the field was not volatile and the write happened off the lock on the handler thread, a fast subsequent start() could read a stale (already-stopped) switch and skip re-creation via the `if (audioSwitch == null)` guard. With no new switch created, activate() never re-ran, so the routing cleared by the prior deactivate()'s clearCommunicationDevice() was never re-asserted and playout stayed on the earpiece until the next connect. Clear `audioSwitch` synchronously under the lock and mark it @Volatile so start() reliably observes the teardown and re-creates the switch. The switch's stop() is still posted to its handler thread, since AbstractAudioSwitch is not threadsafe. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Y
YashJainSC committed
b6bc06eb3742aac72b5e37ac79bd486fd59fb5df
Parent: 0c12e90
Committed by GitHub <noreply@github.com>
on 6/17/2026, 9:20:36 AM