Bug 1531833 - Add a Java method that enables and disable all that is needed to do audio communication with an earpiece. r=snorp

Differential Revision: https://phabricator.services.mozilla.com/D21735

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Paul Adenot 2019-04-16 15:42:28 +00:00
parent 90034d42cc
commit 2867cb1c22

View File

@ -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();