From 83560973551ec714f44cee6e0e27a6f2e365e104 Mon Sep 17 00:00:00 2001 From: S-Sebb <72104181+S-Sebb@users.noreply.github.com> Date: Sun, 22 Nov 2026 18:00:44 +0000 Subject: [PATCH] fix(android): set the audio mode when manageAudioFocus is false --- .changes/android-audio-mode-without-focus | 1 + .../kotlin/io/livekit/plugin/LKAudioSwitchManager.kt | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 .changes/android-audio-mode-without-focus diff --git a/.changes/android-audio-mode-without-focus b/.changes/android-audio-mode-without-focus new file mode 100644 index 000000000..7fdb379d2 --- /dev/null +++ b/.changes/android-audio-mode-without-focus @@ -0,0 +1 @@ +patch type="fixed" "Android: the audio mode is set when manageAudioFocus is false, so calls keep the communication mode without taking audio focus. Apps that pass manageAudioFocus: false without an audioMode now get the default inCommunication mode." diff --git a/android/src/main/kotlin/io/livekit/plugin/LKAudioSwitchManager.kt b/android/src/main/kotlin/io/livekit/plugin/LKAudioSwitchManager.kt index 37f928df0..6023775d7 100644 --- a/android/src/main/kotlin/io/livekit/plugin/LKAudioSwitchManager.kt +++ b/android/src/main/kotlin/io/livekit/plugin/LKAudioSwitchManager.kt @@ -92,6 +92,7 @@ internal class LKAudioSwitchManager(private val context: Context) { if (isActive && sessionConfigChanged) { switch.deactivate() switch.activate() + setModeWithoutFocus(sessionConfig) applySpeakerRouting(switch, speakerRouting) } } @@ -119,6 +120,7 @@ internal class LKAudioSwitchManager(private val context: Context) { val switch = audioSwitch ?: createSwitch(sessionConfig, speakerRouting).also { audioSwitch = it } if (!isActive) { switch.activate() + setModeWithoutFocus(sessionConfig) applySpeakerRouting(switch, speakerRouting) isActive = true } @@ -184,6 +186,16 @@ internal class LKAudioSwitchManager(private val context: Context) { return switch } + // audioswitch sets the audio mode only as it takes audio focus, so a session without focus + // would stay in MODE_NORMAL, without the call mode that echo cancelling and routing need. Set + // it here instead; deactivate() still restores the mode activate() saved. + private fun setModeWithoutFocus(sessionConfig: SessionConfig) { + if (!sessionConfig.manageAudioFocus) { + val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager + audioManager.mode = sessionConfig.audioMode + } + } + private fun applyConfiguration(switch: AbstractAudioSwitch, sessionConfig: SessionConfig) { switch.manageAudioFocus = sessionConfig.manageAudioFocus switch.audioMode = sessionConfig.audioMode