From 8693397395938c3cff578cee80e2cdccb94ba2c5 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 25 Apr 2022 19:55:21 -0400 Subject: [PATCH 1/5] Add missing hasVideo attribute in some methods --- .../main/java/io/wazo/callkeep/Constants.java | 1 + .../io/wazo/callkeep/RNCallKeepModule.java | 21 ++++++++++++++++--- index.js | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/io/wazo/callkeep/Constants.java b/android/src/main/java/io/wazo/callkeep/Constants.java index f48c7ae0..923d2ec9 100644 --- a/android/src/main/java/io/wazo/callkeep/Constants.java +++ b/android/src/main/java/io/wazo/callkeep/Constants.java @@ -22,6 +22,7 @@ public class Constants { public static final String EXTRA_CALL_NUMBER_SCHEMA = "EXTRA_CALL_NUMBER_SCHEMA"; 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"; // 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 141f6fb2..e151639f 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -82,6 +82,7 @@ import static io.wazo.callkeep.Constants.EXTRA_CALLER_NAME; 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.ACTION_END_CALL; import static io.wazo.callkeep.Constants.ACTION_ANSWER_CALL; import static io.wazo.callkeep.Constants.ACTION_MUTE_CALL; @@ -179,7 +180,7 @@ public void reportNewIncomingCall(String uuid, String number, String callerName, Log.d(TAG, "[RNCallKeepModule] reportNewIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName); // @TODO: handle video - this.displayIncomingCall(uuid, number, callerName); + this.displayIncomingCall(uuid, number, callerName, hasVideo); // Send event to JS WritableMap args = Arguments.createMap(); @@ -308,12 +309,17 @@ public void unregisterEvents() { @ReactMethod public void displayIncomingCall(String uuid, String number, String callerName) { + this.displayIncomingCall(uuid, number, callerName, false); + } + + @ReactMethod + public void displayIncomingCall(String uuid, String number, String callerName, boolean hasVideo) { if (!isConnectionServiceAvailable() || !hasPhoneAccount()) { Log.w(TAG, "[RNCallKeepModule] displayIncomingCall ignored due to no ConnectionService or no phone account"); return; } - Log.d(TAG, "[RNCallKeepModule] displayIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName); + Log.d(TAG, "[RNCallKeepModule] displayIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName + ", hasVideo: " + hasVideo); Bundle extras = new Bundle(); Uri uri = Uri.fromParts(PhoneAccount.SCHEME_TEL, number, null); @@ -321,6 +327,7 @@ public void displayIncomingCall(String uuid, String number, String callerName) { extras.putParcelable(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, uri); extras.putString(EXTRA_CALLER_NAME, callerName); extras.putString(EXTRA_CALL_UUID, uuid); + extras.putString(EXTRA_HAS_VIDEO, String.valueOf(hasVideo)); telecomManager.addNewIncomingCall(handle, extras); } @@ -344,6 +351,11 @@ public void answerIncomingCall(String uuid) { @ReactMethod public void startCall(String uuid, String number, String callerName) { + this.startCall(uuid, number, callerName, false); + } + + @ReactMethod + public void startCall(String uuid, String number, String callerName, boolean hasVideo) { Log.d(TAG, "[RNCallKeepModule] startCall called, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName); if (!isConnectionServiceAvailable() || !hasPhoneAccount() || !hasPermissions() || number == null) { @@ -358,6 +370,7 @@ public void startCall(String uuid, String number, String callerName) { callExtras.putString(EXTRA_CALLER_NAME, callerName); callExtras.putString(EXTRA_CALL_UUID, uuid); callExtras.putString(EXTRA_CALL_NUMBER, number); + callExtras.putString(EXTRA_HAS_VIDEO, String.valueOf(hasVideo)); extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, handle); extras.putParcelable(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, callExtras); @@ -1067,7 +1080,7 @@ public void onReceive(Context context, Intent intent) { WritableMap args = Arguments.createMap(); HashMap attributeMap = (HashMap)intent.getSerializableExtra("attributeMap"); - Log.d(TAG, "[RNCallKeepModule][onReceive] :" + intent.getAction()); + Log.d(TAG, "[RNCallKeepModule][onReceive] " + intent.getAction()); switch (intent.getAction()) { case ACTION_END_CALL: @@ -1076,6 +1089,7 @@ public void onReceive(Context context, Intent intent) { break; case ACTION_ANSWER_CALL: args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID)); + args.putBoolean("withVideo", Boolean.valueOf(attributeMap.get(EXTRA_HAS_VIDEO))); sendEventToJS("RNCallKeepPerformAnswerCallAction", args); break; case ACTION_HOLD_CALL: @@ -1119,6 +1133,7 @@ public void onReceive(Context context, Intent intent) { args.putString("handle", attributeMap.get(EXTRA_CALL_NUMBER)); args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID)); args.putString("name", attributeMap.get(EXTRA_CALLER_NAME)); + args.putString("hasVideo", attributeMap.get(EXTRA_HAS_VIDEO)); sendEventToJS("RNCallKeepShowIncomingCallUi", args); break; case ACTION_WAKE_APP: diff --git a/index.js b/index.js index 3e1df0f0..96a31647 100644 --- a/index.js +++ b/index.js @@ -88,7 +88,7 @@ class RNCallKeep { options = null ) => { if (!isIOS) { - RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName); + RNCallKeepModule.displayIncomingCall(uuid, handle, localizedCallerName, hasVideo); return; } @@ -117,7 +117,7 @@ class RNCallKeep { startCall = (uuid, handle, contactIdentifier, handleType = 'number', hasVideo = false) => { if (!isIOS) { - RNCallKeepModule.startCall(uuid, handle, contactIdentifier); + RNCallKeepModule.startCall(uuid, handle, contactIdentifier, hasVideo); return; } From 1c6f1dbc347b597016ba477d026a1fb1b220aa02 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 25 Apr 2022 19:55:51 -0400 Subject: [PATCH 2/5] Fix missing break in VoiceBroadcastReceiver --- android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index e151639f..f65b2c50 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -1159,6 +1159,7 @@ public void onReceive(Context context, Intent intent) { args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID)); args.putString("name", attributeMap.get(EXTRA_CALLER_NAME)); sendEventToJS("RNCallKeepOnIncomingConnectionFailed", args); + break; case ACTION_DID_CHANGE_AUDIO_ROUTE: args.putString("handle", attributeMap.get(EXTRA_CALL_NUMBER)); args.putString("callUUID", attributeMap.get(EXTRA_CALL_UUID)); From 15008eec0b3507a80f1423bd8ea4a88c32f1bd7c Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Mon, 25 Apr 2022 19:56:14 -0400 Subject: [PATCH 3/5] Do not check for phone account in self managed mode --- .../src/main/java/io/wazo/callkeep/RNCallKeepModule.java | 8 ++++++++ .../java/io/wazo/callkeep/VoiceConnectionService.java | 3 +++ 2 files changed, 11 insertions(+) diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index f65b2c50..18e6ce9c 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -996,6 +996,14 @@ private Boolean hasPermissions() { } private boolean hasPhoneAccount() { + if (telecomManager == null) { + this.initializeTelecomManager(); + } + + if (isSelfManaged()) { + return true; + } + return isConnectionServiceAvailable() && telecomManager != null && hasPermissions() && telecomManager.getPhoneAccount(handle) != null && telecomManager.getPhoneAccount(handle).isEnabled(); diff --git a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java index 7895eb80..29d288a1 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -460,6 +460,9 @@ public void onConference(Connection connection1, Connection connection2) { @Override public void onCreateIncomingConnectionFailed(PhoneAccountHandle connectionManagerPhoneAccount, ConnectionRequest request) { + super.onCreateIncomingConnectionFailed(connectionManagerPhoneAccount, request); + Log.w(TAG, "[VoiceConnectionService] onCreateIncomingConnectionFailed: " + request); + Bundle extras = request.getExtras(); HashMap extrasMap = this.bundleToMap(extras); From d55d3262e0a8f452fa7467fa1c3f0552b83b3aea Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Thu, 28 Apr 2022 08:37:24 -0400 Subject: [PATCH 4/5] Fetch setting when loading RNCallkeepModule to retrieve selfManaged mode --- android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java | 1 + 1 file changed, 1 insertion(+) diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 18e6ce9c..8092c511 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -152,6 +152,7 @@ private RNCallKeepModule(ReactApplicationContext reactContext) { this.reactContext = reactContext; delayedEvents = new WritableNativeArray(); this.registerReceiver(); + this.fetchStoredSettings(reactContext); } private boolean isSelfManaged() { From 2ba0c6c43d4a344c6befcc12981674531e2ca6d1 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Thu, 28 Apr 2022 08:37:39 -0400 Subject: [PATCH 5/5] Add missing hasVideo attribute --- android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java | 2 +- .../src/main/java/io/wazo/callkeep/VoiceConnectionService.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java index 8092c511..2a2524e2 100644 --- a/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java +++ b/android/src/main/java/io/wazo/callkeep/RNCallKeepModule.java @@ -179,7 +179,6 @@ public ReactApplicationContext getContext() { public void reportNewIncomingCall(String uuid, String number, String callerName, boolean hasVideo, String payload) { Log.d(TAG, "[RNCallKeepModule] reportNewIncomingCall, uuid: " + uuid + ", number: " + number + ", callerName: " + callerName); - // @TODO: handle video this.displayIncomingCall(uuid, number, callerName, hasVideo); @@ -188,6 +187,7 @@ public void reportNewIncomingCall(String uuid, String number, String callerName, args.putString("handle", number); args.putString("callUUID", uuid); args.putString("name", callerName); + args.putString("hasVideo", hasVideo); if (payload != null) { args.putString("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 29d288a1..47200be5 100644 --- a/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java +++ b/android/src/main/java/io/wazo/callkeep/VoiceConnectionService.java @@ -389,6 +389,9 @@ private Boolean canMakeOutgoingCall() { private Connection createConnection(ConnectionRequest request) { Bundle extras = request.getExtras(); + if (request.getAddress() == null) { + return null; + } HashMap extrasMap = this.bundleToMap(extras); String callerNumber = request.getAddress().toString();