Skip to content

Commit 0c3a209

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). - Replace use of deprecated API methods and constants. - Increase android minSdk version to 27 (to use Activity.setShowWhenLocked/setTurnScreenOn).
1 parent 534ea32 commit 0c3a209

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

android/build.gradle

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

@@ -19,7 +19,7 @@ android {
1919
compileSdkVersion safeExtGet('compileSdkVersion', 28)
2020

2121
defaultConfig {
22-
minSdkVersion safeExtGet('minSdkVersion', 23)
22+
minSdkVersion safeExtGet('minSdkVersion', 27)
2323
targetSdkVersion safeExtGet('targetSdkVersion', 28)
2424
versionCode 1
2525
versionName "1.0"

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

+12-8
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ public void startCall(String uuid, String number, String callerName, boolean has
376376

377377
Log.d(TAG, "[RNCallKeepModule] startCall, uuid: " + uuid);
378378

379-
telecomManager.placeCall(uri, extras);
379+
try {
380+
telecomManager.placeCall(uri, extras);
381+
} catch (SecurityException ignored) {}
380382
}
381383

382384
@ReactMethod
@@ -394,7 +396,7 @@ public void endCall(String uuid) {
394396
}
395397
Context context = this.getAppContext();
396398
AudioManager audioManager = (AudioManager) context.getSystemService(context.AUDIO_SERVICE);
397-
audioManager.setMode(0);
399+
audioManager.setMode(AudioManager.MODE_NORMAL);
398400
conn.onDisconnect();
399401

400402
Log.d(TAG, "[RNCallKeepModule] endCall executed, uuid: " + uuid);
@@ -535,7 +537,11 @@ public void checkDefaultPhoneAccount(Promise promise) {
535537
}
536538

537539
boolean hasSim = telephonyManager.getSimState() != TelephonyManager.SIM_STATE_ABSENT;
538-
boolean hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
540+
541+
boolean hasDefaultAccount = false;
542+
try {
543+
hasDefaultAccount = telecomManager.getDefaultOutgoingPhoneAccount("tel") != null;
544+
} catch (SecurityException ignored) {}
539545

540546
promise.resolve(!hasSim || hasDefaultAccount);
541547
}
@@ -910,11 +916,9 @@ public void backToForeground() {
910916
focusIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
911917
activity.startActivity(focusIntent);
912918
} else {
913-
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK +
914-
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED +
915-
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD +
916-
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
917-
919+
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
920+
activity.setShowWhenLocked(true);
921+
activity.setTurnScreenOn(true);
918922
getReactApplicationContext().startActivity(focusIntent);
919923
}
920924
}

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.app.NotificationManager;
2626
import android.app.PendingIntent;
2727
import android.app.Activity;
28+
import android.app.Service;
2829
import android.content.res.Resources;
2930
import android.content.Intent;
3031
import android.content.Context;
@@ -353,7 +354,7 @@ private void stopForegroundService() {
353354
}
354355

355356
try {
356-
stopForeground(FOREGROUND_SERVICE_TYPE_MICROPHONE);
357+
stopForeground(Service.STOP_FOREGROUND_REMOVE);
357358
} catch (Exception e) {
358359
Log.w(TAG, "[VoiceConnectionService] can't stop foreground service :" + e.toString());
359360
}

0 commit comments

Comments
 (0)