diff --git a/README.md b/README.md index 1388a153..011d1fdc 100644 --- a/README.md +++ b/README.md @@ -198,6 +198,7 @@ To implement a self managed calling app, the following steps are necessary: - When `showIncomingCallUi` is fired, you must show an incoming call UI. This would be a high priority notification ([Android: Display time-sensitive notifications](https://developer.android.com/training/notify-user/time-sensitive)). - If the user answers the call, you call the appropriate RNCallKeep actions such as `answerCall` or `endCall` - In certain cases Android will not allow you to show an incoming call notification. In that case the 'createIncomingConnectionFailed' event is fired and you should reject the incoming SIP Invite. +- When using self managed mode, all connections created by the foreground service will be self managed. Self Managed calling apps are an advanced topic, and there are many steps involved in implementing them, but here are some things to keep in mind: - React Native Headless Tasks are a great way to execute React Native code. Remember to start up the headless task as a Foreground Service. diff --git a/android/src/main/java/io/wazo/callkeep/Constants.java b/android/src/main/java/io/wazo/callkeep/Constants.java index 5a8f7c6e..612de648 100644 --- a/android/src/main/java/io/wazo/callkeep/Constants.java +++ b/android/src/main/java/io/wazo/callkeep/Constants.java @@ -23,6 +23,7 @@ public class Constants { public static final String EXTRA_CALL_UUID = "EXTRA_CALL_UUID"; public static final String EXTRA_CALLER_NAME = "EXTRA_CALLER_NAME"; public static final String EXTRA_HAS_VIDEO = "EXTRA_HAS_VIDEO"; + public static final String EXTRA_SELF_MANAGED = "EXTRA_SELF_MANAGED"; public static final String EXTRA_PAYLOAD = "EXTRA_PAYLOAD"; // Can't use telecom.EXTRA_DISABLE_ADD_CALL ... public static final String EXTRA_DISABLE_ADD_CALL = "android.telecom.extra.DISABLE_ADD_CALL"; diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 19d43c69..87b87f09 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -83,6 +83,7 @@ import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID; import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER; import static io.wazo.callkeep.Constants.EXTRA_HAS_VIDEO; +import static io.wazo.callkeep.Constants.EXTRA_SELF_MANAGED; import static io.wazo.callkeep.Constants.EXTRA_PAYLOAD; import static io.wazo.callkeep.Constants.ACTION_END_CALL; import static io.wazo.callkeep.Constants.ACTION_ANSWER_CALL; @@ -382,6 +383,7 @@ public void startCall(String uuid, String number, String callerName, boolean has callExtras.putString(EXTRA_CALL_UUID, uuid); callExtras.putString(EXTRA_CALL_NUMBER, number); callExtras.putString(EXTRA_HAS_VIDEO, String.valueOf(hasVideo)); + callExtras.putString(EXTRA_SELF_MANAGED, String.valueOf(isSelfManaged())); if (payload != null) { callExtras.putBundle(EXTRA_PAYLOAD, payload); } diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java index f53c0521..4ee0491a 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -69,6 +69,7 @@ import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER; import static io.wazo.callkeep.Constants.EXTRA_CALL_NUMBER_SCHEMA; import static io.wazo.callkeep.Constants.EXTRA_CALL_UUID; +import static io.wazo.callkeep.Constants.EXTRA_SELF_MANAGED; import static io.wazo.callkeep.Constants.EXTRA_DISABLE_ADD_CALL; import static io.wazo.callkeep.Constants.FOREGROUND_SERVICE_TYPE_MICROPHONE; import static io.wazo.callkeep.Constants.ACTION_ON_CREATE_CONNECTION_FAILED; @@ -448,7 +449,10 @@ private Connection createConnection(ConnectionRequest request) { VoiceConnection connection = new VoiceConnection(this, extrasMap); connection.setConnectionCapabilities(Connection.CAPABILITY_MUTE | Connection.CAPABILITY_SUPPORT_HOLD); - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Boolean.parseBoolean(extras.getString(EXTRA_SELF_MANAGED))) { + Log.d(TAG, "[VoiceConnectionService] self managed is enabled in setup, so connection will be too"); + connection.setConnectionProperties(Connection.PROPERTY_SELF_MANAGED); + } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Context context = getApplicationContext(); TelecomManager telecomManager = (TelecomManager) context.getSystemService(context.TELECOM_SERVICE); PhoneAccount phoneAccount = telecomManager.getPhoneAccount(request.getAccountHandle());