From c857eb219d9c279a3add865f69a0ce9db95ed69c Mon Sep 17 00:00:00 2001 From: Rami Jarrar Date: Tue, 31 Oct 2023 17:51:20 +1100 Subject: [PATCH] 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+ --- android/build.gradle | 2 +- .../io/wazo/callkeep/RNCallKeepModule.java | 31 +++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 5a9971bf..736bb8e8 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -5,7 +5,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.0.1' + classpath 'com.android.tools.build:gradle:3.6.4' } } diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 3e90e349..c2208482 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -514,7 +514,9 @@ public void startCall(String uuid, String number, String callerName, boolean has Log.d(TAG, "[RNCallKeepModule] startCall, uuid: " + uuid); this.listenToNativeCallsState(); - telecomManager.placeCall(uri, extras); + try { + telecomManager.placeCall(uri, extras); + } catch (SecurityException ignored) {} } @ReactMethod @@ -532,7 +534,7 @@ public void endCall(String uuid) { } Context context = this.getAppContext(); AudioManager audioManager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE); - audioManager.setMode(0); + audioManager.setMode(AudioManager.MODE_NORMAL); conn.onDisconnect(); this.stopListenToNativeCallsState(); this.hasActiveCall = false; @@ -675,7 +677,11 @@ public void checkDefaultPhoneAccount(Promise promise) { } boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT; - boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null; + + boolean hasDefaultAccount = false; + try { + hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null; + } catch (SecurityException ignored) {} promise.resolve(!hasSim || hasDefaultAccount); } @@ -1080,14 +1086,21 @@ public void backToForeground() { if (isOpened) { focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); activity.startActivity(focusIntent); - } else { - focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK + - WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + - WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD + - WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); + return; + } - getReactApplicationContext().startActivity(focusIntent); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) { + focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.setShowWhenLocked(true); + activity.setTurnScreenOn(true); + } else { + focusIntent.addFlags( + Intent.FLAG_ACTIVITY_NEW_TASK + + WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED + + WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); } + + getReactApplicationContext().startActivity(focusIntent); } public static void onRequestPermissionsResult(int requestCode, String[] grantedPermissions, int[] grantResults) {