diff --git a/src/cheogram/AndroidManifest.xml b/src/cheogram/AndroidManifest.xml
index 62396bed1af27fcdcac16db152115fbd362223ec..956e892fe1b1768858702f10c6c8aac4617bc18d 100644
--- a/src/cheogram/AndroidManifest.xml
+++ b/src/cheogram/AndroidManifest.xml
@@ -3,7 +3,18 @@
xmlns:tools="http://schemas.android.com/tools"
package="eu.siacs.conversations">
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java
index 56e1ec02edcadbbd668ddab332764c5853ba33a0..555e35dceab3cdedc2bda5dfcb369d9609f45c0e 100644
--- a/src/main/java/eu/siacs/conversations/entities/Contact.java
+++ b/src/main/java/eu/siacs/conversations/entities/Contact.java
@@ -1,9 +1,14 @@
package eu.siacs.conversations.entities;
+import android.content.ComponentName;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
+import android.os.Bundle;
+import android.telecom.PhoneAccount;
+import android.telecom.PhoneAccountHandle;
+import android.telecom.TelecomManager;
import android.text.TextUtils;
import androidx.annotation.NonNull;
@@ -559,6 +564,38 @@ public class Contact implements ListItem, Blockable {
return changed;
}
+ protected String phoneAccountLabel() {
+ return account.getJid().asBareJid().toString() +
+ "/" + getJid().asBareJid().toString();
+ }
+
+ protected PhoneAccountHandle phoneAccountHandle() {
+ ComponentName componentName = new ComponentName(
+ "com.cheogram.android",
+ "com.cheogram.android.ConnectionService"
+ );
+ return new PhoneAccountHandle(componentName, phoneAccountLabel());
+ }
+
+ // This Contact is a gateway to use for voice calls, register it with OS
+ public void registerAsPhoneAccount(Context ctx) {
+ TelecomManager telecomManager = ctx.getSystemService(TelecomManager.class);
+
+ PhoneAccount phoneAccount = PhoneAccount.builder(
+ phoneAccountHandle(), phoneAccountLabel()
+ ).setCapabilities(
+ PhoneAccount.CAPABILITY_CALL_PROVIDER
+ ).build();
+
+ telecomManager.registerPhoneAccount(phoneAccount);
+ }
+
+ // Unregister any associated PSTN gateway integration
+ public void unregisterAsPhoneAccount(Context ctx) {
+ TelecomManager telecomManager = ctx.getSystemService(TelecomManager.class);
+ telecomManager.unregisterPhoneAccount(phoneAccountHandle());
+ }
+
public static int getOption(Class extends AbstractPhoneContact> clazz) {
if (clazz == JabberIdContact.class) {
return Options.SYNCED_VIA_ADDRESSBOOK;
diff --git a/src/main/java/eu/siacs/conversations/entities/Presences.java b/src/main/java/eu/siacs/conversations/entities/Presences.java
index 04d378cc2602e9fd47b1da60d9a9fdf3433114c6..4753e2138f7e4949a00d2180e2253f5434c2a78f 100644
--- a/src/main/java/eu/siacs/conversations/entities/Presences.java
+++ b/src/main/java/eu/siacs/conversations/entities/Presences.java
@@ -149,6 +149,22 @@ public class Presences {
return false;
}
+ public boolean anyIdentity(final String category, final String type) {
+ synchronized (this.presences) {
+ if (this.presences.size() == 0) {
+ // https://github.com/iNPUTmice/Conversations/issues/4230
+ return false;
+ }
+ for (Presence presence : this.presences.values()) {
+ ServiceDiscoveryResult disco = presence.getServiceDiscoveryResult();
+ if (disco != null && disco.hasIdentity(category, type)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
public Pair