Skip to content

Commit

Permalink
Fix android build errors with RN 0.71
Browse files Browse the repository at this point in the history
- 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+
  • Loading branch information
ramijarrar committed Oct 31, 2023
1 parent cc308ce commit cee288a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.6.4'
}
}

Expand Down
30 changes: 21 additions & 9 deletions android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,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
Expand All @@ -530,7 +532,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;
Expand Down Expand Up @@ -673,7 +675,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);
}
Expand Down Expand Up @@ -1078,14 +1084,20 @@ 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);
focusIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
activity.setShowWhenLocked(true);
activity.setTurnScreenOn(true);
} else {
activity.getWindow().addFlags(
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) {
Expand Down

0 comments on commit cee288a

Please sign in to comment.