From c4fd115209e5735f4bc5fb8e779b54c78e1fcca0 Mon Sep 17 00:00:00 2001 From: S1m Date: Mon, 15 Nov 2021 20:21:01 +0100 Subject: [PATCH] Add a BuildConfig to allow external unifiedpush distrib Change-Id: I5435c02dab05f84dd5dd99507afd1075f357e76d --- vector/build.gradle | 2 ++ .../im/vector/app/core/pushers/UPHelper.kt | 6 ++++++ ...rSettingsNotificationPreferenceFragment.kt | 21 ++++++++++++------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/vector/build.gradle b/vector/build.gradle index a1d5a47bae..a10aad350f 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -274,6 +274,7 @@ android { resValue "bool", "isGplay", "true" buildConfigField "boolean", "ALLOW_FCM_USE", "true" + buildConfigField "boolean", "ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB", "true" buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"G\"" buildConfigField "String", "FLAVOR_DESCRIPTION", "\"GooglePlay\"" } @@ -285,6 +286,7 @@ android { resValue "bool", "isGplay", "false" buildConfigField "boolean", "ALLOW_FCM_USE", "false" + buildConfigField "boolean", "ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB", "true" buildConfigField "String", "SHORT_FLAVOR_DESCRIPTION", "\"F\"" buildConfigField "String", "FLAVOR_DESCRIPTION", "\"FDroid\"" } diff --git a/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt index f00a3ee9d8..80d529ae33 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UPHelper.kt @@ -21,6 +21,7 @@ import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.core.content.edit import com.google.android.material.dialog.MaterialAlertDialogBuilder +import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.di.DefaultSharedPreferences import im.vector.app.features.settings.VectorPreferences @@ -86,6 +87,11 @@ object UPHelper { fun registerUnifiedPush(context: Context, forceShowSelection: Boolean = false, onDoneRunnable: Runnable? = null) { val up = Registration() + if (!BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { + up.saveDistributor(context, context.packageName) + up.registerApp(context) + return + } if (forceShowSelection) { // Un-register first up.unregisterApp(context) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt index 16c2881653..b6db1cce3a 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt @@ -31,6 +31,7 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.map import androidx.preference.Preference import androidx.preference.SwitchPreference +import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.extensions.registerStartForActivityResult @@ -141,17 +142,21 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( } findPreference(SETTINGS_UNIFIED_PUSH_RE_REGISTER)?.let { - it.onPreferenceClickListener = Preference.OnPreferenceClickListener { - lifecycleScope.launch { - updateEnabledForDevice(false) - UPHelper.registerUnifiedPush(requireContext(), forceShowSelection = true) { - lifecycleScope.launch { - updateEnabledForDevice(true) + if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { + it.onPreferenceClickListener = Preference.OnPreferenceClickListener { + lifecycleScope.launch { + updateEnabledForDevice(false) + UPHelper.registerUnifiedPush(requireContext(), forceShowSelection = true) { + lifecycleScope.launch { + updateEnabledForDevice(true) + } + Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() }, 500) } - Handler(Looper.getMainLooper()).postDelayed({ refreshBackgroundSyncPrefs() }, 500) } + true } - true + } else { + it.isVisible = false } }