From 3725f698e461ce9ac5e0572a3b60684a3da51f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Thu, 26 Nov 2020 15:11:45 +0100 Subject: [PATCH] fix(android) reset audio route after audio focus was lost Looks like audio devices must be re-set after focus was lost and regained. Otherwise some devices (tested on a Samsung Galaxy S9) are in a weird state where the second microphone is not used when speakerphone is on. --- .../meet/sdk/AudioDeviceHandlerGeneric.java | 4 ++-- .../org/jitsi/meet/sdk/AudioModeModule.java | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerGeneric.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerGeneric.java index 383ff704c1..8e155698fe 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerGeneric.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioDeviceHandlerGeneric.java @@ -63,7 +63,7 @@ class AudioDeviceHandlerGeneric implements private AudioManager audioManager; /** - * {@link Runnable} for running audio device detection the main thread. + * {@link Runnable} for running audio device detection in the audio thread. * This is only used on Android >= M. */ private final Runnable onAudioDeviceChangeRunner = new Runnable() { @@ -145,7 +145,7 @@ class AudioDeviceHandlerGeneric implements // Some other application potentially stole our audio focus // temporarily. Restore our mode. if (audioFocusLost) { - module.updateAudioRoute(); + module.resetAudioRoute(); } audioFocusLost = false; break; diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java index 8cbecd71d6..9cd59cfab7 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/AudioModeModule.java @@ -256,7 +256,7 @@ class AudioModeModule extends ReactContextBaseJavaModule { if (mode != -1) { JitsiMeetLogger.i(TAG + " User selected device set to: " + device); userSelectedDevice = device; - updateAudioRoute(mode); + updateAudioRoute(mode, false); } } }); @@ -282,7 +282,7 @@ class AudioModeModule extends ReactContextBaseJavaModule { boolean success; try { - success = updateAudioRoute(mode); + success = updateAudioRoute(mode, false); } catch (Throwable e) { success = false; JitsiMeetLogger.e(e, TAG + " Failed to update audio route for mode: " + mode); @@ -321,7 +321,7 @@ class AudioModeModule extends ReactContextBaseJavaModule { * @return {@code true} if the audio route was updated successfully; * {@code false}, otherwise. */ - private boolean updateAudioRoute(int mode) { + private boolean updateAudioRoute(int mode, boolean force) { JitsiMeetLogger.i(TAG + " Update audio route for mode: " + mode); if (!audioDeviceHandler.setMode(mode)) { @@ -356,7 +356,7 @@ class AudioModeModule extends ReactContextBaseJavaModule { // If the previously selected device and the current default one // match, do nothing. - if (selectedDevice != null && selectedDevice.equals(audioDevice)) { + if (!force && selectedDevice != null && selectedDevice.equals(audioDevice)) { return true; } @@ -421,7 +421,16 @@ class AudioModeModule extends ReactContextBaseJavaModule { */ void updateAudioRoute() { if (mode != -1) { - updateAudioRoute(mode); + updateAudioRoute(mode, false); + } + } + + /** + * Re-sets the current audio route. Needed when focus is lost and regained. + */ + void resetAudioRoute() { + if (mode != -1) { + updateAudioRoute(mode, true); } }