Skip to content

Commit deaf0bb

Browse files
committed
Fix android build errors with RN 0.71
- Add redundant handling for missing permission exceptions. Existing checks work but do not satisfy lint, so this is the only way to resolve react-native-webrtc#646 - Upgrade gradle to maximum compatible version (3.6.4) to satisfy new minimum (3.2.0) - Use AudioManager.MODE_NORMAL constant explicitly (instead of the equivalent value of "0" currently being used) to satisfy lint - Replace deprecated WindowManager.LayoutParams constants with Activity API methods when using Android SDK v27+
1 parent 7f7ff14 commit deaf0bb

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.0.1'
8+
classpath 'com.android.tools.build:gradle:3.6.4'
99
}
1010
}
1111

android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,9 @@ public void startCall(String uuid, String number, String callerName, boolean has
514514

515515
Log.d(TAG, "[RNCallKeepModule] startCall, uuid: " + uuid);
516516
this.listenToNativeCallsState();
517-
telecomManager.placeCall(uri, extras);
517+
try {
518+
telecomManager.placeCall(uri, extras);
519+
} catch (SecurityException ignored) {}
518520
}
519521

520522
@ReactMethod
@@ -532,7 +534,7 @@ public void endCall(String uuid) {
532534
}
533535
Context context = this.getAppContext();
534536
AudioManager audioManager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
535-
audioManager.setMode(0);
537+
audioManager.setMode(AudioManager.MODE_NORMAL);
536538
conn.onDisconnect();
537539
this.stopListenToNativeCallsState();
538540
this.hasActiveCall = false;
@@ -675,7 +677,11 @@ public void checkDefaultPhoneAccount(Promise promise) {
675677
}
676678

677679
boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT;
678-
boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
680+
681+
boolean hasDefaultAccount = false;
682+
try {
683+
hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
684+
} catch (SecurityException ignored) {}
679685

680686
promise.resolve(!hasSim || hasDefaultAccount);
681687
}
@@ -1080,14 +1086,20 @@ public void backToForeground() {
10801086
if (isOpened) {
10811087
focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
10821088
activity.startActivity(focusIntent);
1083-
} else {
1084-
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
1085-
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
1086-
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
1087-
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
1089+
return;
1090+
}
10881091

1089-
getReactApplicationContext().startActivity(focusIntent);
1092+
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1093+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
1094+
activity.setShowWhenLocked(true);
1095+
activity.setTurnScreenOn(true);
1096+
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O_MR1) {
1097+
focusIntent.addFlags(
1098+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
1099+
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
10901100
}
1101+
1102+
getReactApplicationContext().startActivity(focusIntent);
10911103
}
10921104

10931105
public static void onRequestPermissionsResult(int requestCode, String[] grantedPermissions, int[] grantResults) {

0 commit comments

Comments
 (0)