From a04dc6e4ad6512912129604213ad7b077a816cd7 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Wed, 7 Feb 2024 15:02:06 +0100 Subject: [PATCH] show warning when call integration accounts exceed 10 --- .../CallIntegrationConnectionService.java | 32 +++++++++++++++++-- src/main/res/values/strings.xml | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java b/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java index 013a3964a..0455d4d6e 100644 --- a/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/CallIntegrationConnectionService.java @@ -211,6 +211,25 @@ public class CallIntegrationConnectionService extends ConnectionService { } public static void registerPhoneAccount(final Context context, final Account account) { + try { + registerPhoneAccountOrThrow(context, account); + } catch (final IllegalArgumentException e) { + Toast.makeText(context, R.string.call_integration_not_available, Toast.LENGTH_LONG) + .show(); + } + } + + public static void registerPhoneAccountOrThrow(final Context context, final Account account) { + final var handle = getHandle(context, account); + final var telecomManager = context.getSystemService(TelecomManager.class); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + if (telecomManager.getOwnSelfManagedPhoneAccounts().contains(handle)) { + Log.d( + Config.LOGTAG, + "a phone account for " + account.getJid().asBareJid() + " already exists"); + return; + } + } final var builder = PhoneAccount.builder(getHandle(context, account), account.getJid().asBareJid()); builder.setSupportedUriSchemes(Collections.singletonList("xmpp")); @@ -220,14 +239,21 @@ public class CallIntegrationConnectionService extends ConnectionService { | PhoneAccount.CAPABILITY_SUPPORTS_VIDEO_CALLING); } final var phoneAccount = builder.build(); - - context.getSystemService(TelecomManager.class).registerPhoneAccount(phoneAccount); + telecomManager.registerPhoneAccount(phoneAccount); } public static void registerPhoneAccounts( final Context context, final Collection accounts) { for (final Account account : accounts) { - registerPhoneAccount(context, account); + try { + registerPhoneAccountOrThrow(context, account); + } catch (final IllegalArgumentException e) { + Log.w( + Config.LOGTAG, + "could not register phone account for " + account.getJid().asBareJid(), + e); + return; + } } } diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index f47731d06..4f67b8a95 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1027,4 +1027,5 @@ Report spam and block spammer Privacy policy Contact list integration is not available + Call integration not available!