From 1b63bdec1229c6c49f9984d80c5dfe9985cb5fa2 Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 12 Jul 2023 12:11:01 -0400 Subject: [PATCH] Control CDS compat mode with it's own remote config. --- .../contacts/sync/ContactDiscovery.kt | 6 +++--- .../securesms/util/FeatureFlags.java | 21 +++++++++++++++++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/ContactDiscovery.kt b/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/ContactDiscovery.kt index 853f3cc1a0..75483c7cf1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/ContactDiscovery.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/contacts/sync/ContactDiscovery.kt @@ -66,7 +66,7 @@ object ContactDiscovery { context = context, descriptor = "refresh-all", refresh = { - ContactDiscoveryRefreshV2.refreshAll(context, useCompat = !FeatureFlags.phoneNumberPrivacy()) + ContactDiscoveryRefreshV2.refreshAll(context, useCompat = FeatureFlags.cdsCompatMode()) }, removeSystemContactLinksIfMissing = true, notifyOfNewUsers = notifyOfNewUsers @@ -83,7 +83,7 @@ object ContactDiscovery { context = context, descriptor = "refresh-multiple", refresh = { - ContactDiscoveryRefreshV2.refresh(context, recipients, useCompat = !FeatureFlags.phoneNumberPrivacy()) + ContactDiscoveryRefreshV2.refresh(context, recipients, useCompat = FeatureFlags.cdsCompatMode()) }, removeSystemContactLinksIfMissing = false, notifyOfNewUsers = notifyOfNewUsers @@ -99,7 +99,7 @@ object ContactDiscovery { context = context, descriptor = "refresh-single", refresh = { - ContactDiscoveryRefreshV2.refresh(context, listOf(recipient), useCompat = !FeatureFlags.phoneNumberPrivacy(), timeoutMs = timeoutMs) + ContactDiscoveryRefreshV2.refresh(context, listOf(recipient), useCompat = FeatureFlags.cdsCompatMode(), timeoutMs = timeoutMs) }, removeSystemContactLinksIfMissing = false, notifyOfNewUsers = notifyOfNewUsers diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java b/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java index e27c9e58fb..414d828c27 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/FeatureFlags.java @@ -106,6 +106,7 @@ public final class FeatureFlags { private static final String MAX_ATTACHMENT_RECEIVE_SIZE_BYTES = "global.attachments.maxReceiveBytes"; private static final String MAX_ATTACHMENT_SIZE_BYTES = "global.attachments.maxBytes"; private static final String SVR2_KILLSWITCH = "android.svr2.killSwitch"; + private static final String CDS_COMPAT_MODE = "global.cds.return_acis_without_uaks"; /** * We will only store remote values for flags in this set. If you want a flag to be controllable @@ -163,7 +164,8 @@ public final class FeatureFlags { MAX_ATTACHMENT_RECEIVE_SIZE_BYTES, MAX_ATTACHMENT_SIZE_BYTES, AD_HOC_CALLING, - SVR2_KILLSWITCH + SVR2_KILLSWITCH, + CDS_COMPAT_MODE ); @VisibleForTesting @@ -227,7 +229,8 @@ public final class FeatureFlags { MAX_ATTACHMENT_COUNT, MAX_ATTACHMENT_RECEIVE_SIZE_BYTES, MAX_ATTACHMENT_SIZE_BYTES, - SVR2_KILLSWITCH + SVR2_KILLSWITCH, + CDS_COMPAT_MODE ); /** @@ -584,6 +587,11 @@ public final class FeatureFlags { return getLong(MAX_ATTACHMENT_SIZE_BYTES, ByteUnit.MEGABYTES.toBytes(100)); } + /** True if you should use CDS in compat mode (i.e. request ACI's even if you don't know the access key), otherwise false. */ + public static boolean cdsCompatMode() { + return getBoolean(CDS_COMPAT_MODE, true); + } + /** Only for rendering debug info. */ public static synchronized @NonNull Map getMemoryValues() { return new TreeMap<>(REMOTE_VALUES); @@ -754,6 +762,15 @@ public final class FeatureFlags { Object remote = REMOTE_VALUES.get(key); if (remote instanceof Boolean) { return (boolean) remote; + } else if (remote instanceof String) { + String stringValue = ((String) remote).toLowerCase(); + if (stringValue.equals("true")) { + return true; + } else if (stringValue.equals("false")) { + return false; + } else { + Log.w(TAG, "Expected a boolean for key '" + key + "', but got something else (" + stringValue + ")! Falling back to the default."); + } } else if (remote != null) { Log.w(TAG, "Expected a boolean for key '" + key + "', but got something else! Falling back to the default."); }