Skip to content

Commit cee288a

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 #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 cc308ce commit cee288a

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

android/build.gradle

+1-1
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

+21-9
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,9 @@ public void startCall(String uuid, String number, String callerName, boolean has
512512

513513
Log.d(TAG, "[RNCallKeepModule] startCall, uuid: " + uuid);
514514
this.listenToNativeCallsState();
515-
telecomManager.placeCall(uri, extras);
515+
try {
516+
telecomManager.placeCall(uri, extras);
517+
} catch (SecurityException ignored) {}
516518
}
517519

518520
@ReactMethod
@@ -530,7 +532,7 @@ public void endCall(String uuid) {
530532
}
531533
Context context = this.getAppContext();
532534
AudioManager audioManager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
533-
audioManager.setMode(0);
535+
audioManager.setMode(AudioManager.MODE_NORMAL);
534536
conn.onDisconnect();
535537
this.stopListenToNativeCallsState();
536538
this.hasActiveCall = false;
@@ -673,7 +675,11 @@ public void checkDefaultPhoneAccount(Promise promise) {
673675
}
674676

675677
boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT;
676-
boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
678+
679+
boolean hasDefaultAccount = false;
680+
try {
681+
hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
682+
} catch (SecurityException ignored) {}
677683

678684
promise.resolve(!hasSim || hasDefaultAccount);
679685
}
@@ -1078,14 +1084,20 @@ public void backToForeground() {
10781084
if (isOpened) {
10791085
focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
10801086
activity.startActivity(focusIntent);
1081-
} else {
1082-
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
1083-
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
1084-
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
1085-
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
1087+
return;
1088+
}
10861089

1087-
getReactApplicationContext().startActivity(focusIntent);
1090+
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
1091+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
1092+
activity.setShowWhenLocked(true);
1093+
activity.setTurnScreenOn(true);
1094+
} else {
1095+
activity.getWindow().addFlags(
1096+
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
1097+
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
10881098
}
1099+
1100+
getReactApplicationContext().startActivity(focusIntent);
10891101
}
10901102

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

0 commit comments

Comments
 (0)