From 19132b16ce4cd26a48d867dbed7f73fa08f3dec0 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 27 Jun 2023 16:26:48 -0500 Subject: [PATCH] Requires permission CALL_PHONE --- .../ui/ConversationFragment.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 50f001711..812a5edd9 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -29,6 +29,7 @@ import android.os.storage.StorageManager; import android.os.SystemClock; import android.preference.PreferenceManager; import android.provider.MediaStore; +import android.telecom.TelecomManager; import android.text.Editable; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -1898,6 +1899,27 @@ public class ConversationFragment extends XmppFragment } } + private boolean placeCallWithSystem(Contact gateway) { + if (Build.VERSION.SDK_INT < 23) return false; + + if (!activity.getPreferences().getBoolean("dialler_integration_incoming", true)) return false; + + Bundle callInfo = new Bundle(); + callInfo.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, gateway.phoneAccountHandle()); + TelecomManager telecomManager = activity.getSystemService(TelecomManager.class); + + try { + telecomManager.placeCall(Uri.parse("tel:" + conversation.getContact().getJid().getLocal()), callInfo); + } catch (SecurityException e) { + // If the account is not registered or enabled, it could result in a security exception + // Just fall back to the built-in UI in this case. + Log.w("WUT", e); + return false; + } + + return true; + } + private void triggerRtpSession(final String action) { if (activity.xmppConnectionService.getJingleConnectionManager().isBusy() != null) { Toast.makeText(getActivity(), R.string.only_one_call_at_a_time, Toast.LENGTH_LONG) @@ -1905,6 +1927,14 @@ public class ConversationFragment extends XmppFragment return; } final Contact contact = conversation.getContact(); + + if (action == RtpSessionActivity.ACTION_MAKE_VOICE_CALL) { + Contact gateway = contact.getAccount().getRoster().getContact(contact.getJid().getDomain()); + if (gateway.getPresences().anyIdentity("gateway", "pstn")) { + if (placeCallWithSystem(gateway)) return; + } + } + if (contact.getPresences().anySupport(Namespace.JINGLE_MESSAGE)) { triggerRtpSession(contact.getAccount(), contact.getJid().asBareJid(), action); } else { -- 2.45.2