[RN] Make AudioMode more resilient on Android

Some devices may give an error stating that INTERACT_ACROSS_USERS_FULL
permission is neeced. This permission can only be achieved by signing the
application with the same key as the system, which is never going to happen so
deal with it by catching any exceptions setting the mode may cause and failing
as gracefully as we can.

Ref:
http://stackoverflow.com/questions/34172575/audiomanager-setmode-securityexception-on-huawei-android-4
This commit is contained in:
Saúl Ibarra Corretgé 2017-04-19 12:29:52 +02:00 committed by Lyubo Marinov
parent 0c16842e0d
commit 5d50792a56
1 changed files with 13 additions and 2 deletions

View File

@ -188,13 +188,24 @@ public class AudioModeModule extends ReactContextBaseJavaModule {
Runnable r = new Runnable() {
@Override
public void run() {
if (updateAudioRoute(mode)) {
boolean success;
try {
success = updateAudioRoute(mode);
} catch (Throwable e) {
success = false;
Log.e(
TAG,
"Failed to update audio route for mode: " + mode,
e);
}
if (success) {
AudioModeModule.this.mode = mode;
promise.resolve(null);
} else {
promise.reject(
"setMode",
"Failed to set the requested audio mode");
"Failed to set audio mode to " + mode);
}
}
};