diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml
index 03c7426cd..b987209ec 100644
--- a/src/main/AndroidManifest.xml
+++ b/src/main/AndroidManifest.xml
@@ -40,6 +40,7 @@
+
@@ -400,6 +401,15 @@
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize">
+
+
+
+
+
+
= Build.VERSION_CODES.TIRAMISU) {
+ if (telecomManager.getOwnSelfManagedPhoneAccounts().contains(handle)) {
+ Log.d(TAG, "a phone account for " + accountId + " already exists");
+ return;
+ }
+ }
+ final PhoneAccount.Builder builder =
+ PhoneAccount.builder(getHandle(context, accountId), accountId+"");
+ builder.setSupportedUriSchemes(Collections.singletonList("dc"));
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ builder.setCapabilities(
+ PhoneAccount.CAPABILITY_SELF_MANAGED
+ | PhoneAccount.CAPABILITY_SUPPORTS_VIDEO_CALLING);
+ }
+ final PhoneAccount phoneAccount = builder.build();
+ telecomManager.registerPhoneAccount(phoneAccount);
+ }
+
+ public static void placeCall(Context context, int accountId, int chatId) {
+ final Bundle extras = new Bundle();
+ extras.putParcelable(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, getHandle(context, accountId));
+ final Bundle outgoingCallExtras = new Bundle();
+ outgoingCallExtras.putInt(EXTRA_ACCOUNT_ID, accountId);
+ outgoingCallExtras.putInt(EXTRA_CHAT_ID, chatId);
+ extras.putBundle(TelecomManager.EXTRA_OUTGOING_CALL_EXTRAS, outgoingCallExtras);
+
+ final Uri address = Uri.parse("tel:0");
+ try {
+ context.getSystemService(TelecomManager.class).placeCall(address, extras);
+ } catch (final SecurityException e) {
+ Log.e(TAG, "call integration not available", e);
+ Toast.makeText(context, "call integration not available", Toast.LENGTH_LONG).show();
+ }
+ }
+
+ public static void addNewIncomingCall(final Context context, int accId, int chatId, int callId, String payload) {
+ final PhoneAccountHandle phoneAccountHandle = getHandle(context, accId);
+ final Bundle bundle = new Bundle();
+ bundle.putString(TelecomManager.EXTRA_INCOMING_CALL_ADDRESS, chatId+"");
+ final Bundle extras = new Bundle();
+ extras.putInt(EXTRA_CALL_ID, callId);
+ extras.putString(EXTRA_CALL_PAYLOAD, payload);
+ bundle.putBundle(TelecomManager.EXTRA_INCOMING_CALL_EXTRAS, extras);
+
+ try {
+ context.getSystemService(TelecomManager.class).addNewIncomingCall(phoneAccountHandle, bundle);
+ } catch (final SecurityException e) {
+ Log.e(TAG, "call integration not available", e);
+ Toast.makeText(context, "call integration not available", Toast.LENGTH_LONG).show();
+ }
+ }
+
+}
diff --git a/src/main/java/org/thoughtcrime/securesms/videochat/VideochatUtil.java b/src/main/java/org/thoughtcrime/securesms/videochat/VideochatUtil.java
index 00778f577..1c1784eb3 100644
--- a/src/main/java/org/thoughtcrime/securesms/videochat/VideochatUtil.java
+++ b/src/main/java/org/thoughtcrime/securesms/videochat/VideochatUtil.java
@@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.videochat;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
+import android.os.Build;
import androidx.appcompat.app.AlertDialog;
@@ -57,16 +58,28 @@ public class VideochatUtil {
public static void joinCall(Activity activity, int callId, String payload) {
DcContext dcContext = DcHelper.getContext(activity);
DcMsg dcMsg = dcContext.getMsg(callId);
+ int accId = dcContext.getAccountId();
+ int chatId = dcMsg.getChatId();
String hash = "#offer=" + payload;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ CallIntegrationService.addNewIncomingCall(activity, accId, chatId, callId, payload);
+ }
openCall(activity, dcMsg.getChatId(), callId, hash);
}
private static void openCall(Activity activity, int chatId, int callId, String hash) {
+ DcContext dcContext = DcHelper.getContext(activity);
+ int accId = dcContext.getAccountId();
+
Permissions.with(activity)
.request(Manifest.permission.CAMERA, Manifest.permission.RECORD_AUDIO)
.ifNecessary()
.withPermanentDenialDialog(activity.getString(R.string.perm_explain_access_to_camera_denied))
.onAllGranted(() -> {
+ if ("#call".equals(hash) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ CallIntegrationService.registerPhoneAccount(activity, accId);
+ CallIntegrationService.placeCall(activity, accId, chatId);
+ }
Intent intent = new Intent(activity, VideochatActivity.class);
intent.setAction(Intent.ACTION_VIEW);
intent.putExtra(VideochatActivity.EXTRA_CHAT_ID, chatId);