From 0c3a209d479469666722e40a786f6a552ae0228e Mon Sep 17 00:00:00 2001 From: Rami Jarrar Date: Fri, 14 Apr 2023 16:43:37 +1000 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 #646. - Upgrade gradle to maximum compatible version (3.6.4) to satisfy new minimum (3.2.0). - Replace use of deprecated API methods and constants. - Increase android minSdk version to 27 (to use Activity.setShowWhenLocked/setTurnScreenOn). --- android/build.gradle | 4 ++-- .../io/wazo/callkeep/RNCallKeepModule.java | 20 +++++++++++-------- .../wazo/callkeep/VoiceConnectionService.java | 3 ++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 5a9971bf..9281aec1 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' } } @@ -19,7 +19,7 @@ android { compileSdkVersion safeExtGet('compileSdkVersion', 28) defaultConfig { - minSdkVersion safeExtGet('minSdkVersion', 23) + minSdkVersion safeExtGet('minSdkVersion', 27) targetSdkVersion safeExtGet('targetSdkVersion', 28) versionCode 1 versionName "1.0" diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 82b173dc..1b096c73 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -376,7 +376,9 @@ public void startCall(String uuid, String number, String callerName, boolean has Log.d(TAG, "[RNCallKeepModule] startCall, uuid: " + uuid); - telecomManager.placeCall(uri, extras); + try { + telecomManager.placeCall(uri, extras); + } catch (SecurityException ignored) {} } @ReactMethod @@ -394,7 +396,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(); Log.d(TAG, "[RNCallKeepModule] endCall executed, uuid: " + uuid); @@ -535,7 +537,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); } @@ -910,11 +916,9 @@ public void backToForeground() { 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); - + focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.setShowWhenLocked(true); + activity.setTurnScreenOn(true); getReactApplicationContext().startActivity(focusIntent); } } diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java index f53c0521..dec44ab6 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -25,6 +25,7 @@ import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Activity; +import android.app.Service; import android.content.res.Resources; import android.content.Intent; import android.content.Context; @@ -353,7 +354,7 @@ private void stopForegroundService() { } try { - stopForeground(FOREGROUND_SERVICE_TYPE_MICROPHONE); + stopForeground(Service.STOP_FOREGROUND_REMOVE); } catch (Exception e) { Log.w(TAG, "[VoiceConnectionService] can't stop foreground service :" + e.toString()); }