diff --git a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java index 8cfdf797ba06..92819317c687 100644 --- a/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java +++ b/mobile/android/geckoview/src/main/java/org/mozilla/gecko/GeckoAppShell.java @@ -1996,6 +1996,41 @@ public class GeckoAppShell { return Integer.parseInt(prop); } + static private int sPreviousAudioMode = -2; + + @WrapForJNI(calledFrom = "any") + public static void setCommunicationAudioModeOn(final boolean on) { + final AudioManager am = (AudioManager)getApplicationContext() + .getSystemService(Context.AUDIO_SERVICE); + if (am == null) { + return; + } + + if (sPreviousAudioMode == AudioManager.MODE_INVALID) { + sPreviousAudioMode = am.getMode(); + } + + try { + if (on) { + Log.e(LOGTAG, "Setting communication mode ON"); + sPreviousAudioMode = am.getMode(); + am.startBluetoothSco(); + am.setBluetoothScoOn(true); + am.setMode(AudioManager.MODE_IN_COMMUNICATION); + } else { + Log.e(LOGTAG, "Setting communication mode OFF"); + am.setMode(sPreviousAudioMode); + sPreviousAudioMode = AudioManager.MODE_INVALID; + am.stopBluetoothSco(); + am.setBluetoothScoOn(false); + } + } catch (SecurityException e) { + Log.e(LOGTAG, "could not set communication mode", e); + } + + am.setSpeakerphoneOn(!on); + } + private static String getLanguageTag(final Locale locale) { final StringBuilder out = new StringBuilder(locale.getLanguage()); final String country = locale.getCountry();