diff --git a/vector/build.gradle b/vector/build.gradle index c0112a2934..82f43c6ac4 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -165,10 +165,6 @@ android { buildConfigField "Boolean", "enableLocationSharing", "true" buildConfigField "String", "mapTilerKey", "\"fU3vlMsMn4Jb6dnEIFsx\"" - // Set to false to prevent usage of UnifiedPush. For Gplay variant it means that only FCM will be used, - // And for F-Droid variant, it means that only background polling will be available to the user. - buildConfigField "boolean", "ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB", "true" - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" // Keep abiFilter for the universalApk diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt index aa4df5e308..248d9d232b 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt @@ -65,6 +65,11 @@ class DebugFeaturesStateFactory @Inject constructor( key = DebugFeatureKeys.onboardingCombinedLogin, factory = VectorFeatures::isOnboardingCombinedLoginEnabled ), + createBooleanFeature( + label = "Allow external UnifiedPush distributors", + key = DebugFeatureKeys.allowExternalUnifiedPushDistributors, + factory = VectorFeatures::allowExternalUnifiedPushDistributors + ), ) ) } diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt index f36b1a804a..919cc6635e 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt @@ -60,6 +60,9 @@ class DebugVectorFeatures( override fun isOnboardingCombinedLoginEnabled(): Boolean = read(DebugFeatureKeys.onboardingCombinedLogin) ?: vectorFeatures.isOnboardingCombinedLoginEnabled() + override fun allowExternalUnifiedPushDistributors(): Boolean = read(DebugFeatureKeys.allowExternalUnifiedPushDistributors) + ?: vectorFeatures.allowExternalUnifiedPushDistributors() + override fun isScreenSharingEnabled(): Boolean = read(DebugFeatureKeys.screenSharing) ?: vectorFeatures.isScreenSharingEnabled() @@ -117,6 +120,7 @@ object DebugFeatureKeys { val onboardingPersonalize = booleanPreferencesKey("onboarding-personalize") val onboardingCombinedRegister = booleanPreferencesKey("onboarding-combined-register") val onboardingCombinedLogin = booleanPreferencesKey("onboarding-combined-login") + val allowExternalUnifiedPushDistributors = booleanPreferencesKey("allow-external-unified-push-distributors") val liveLocationSharing = booleanPreferencesKey("live-location-sharing") val screenSharing = booleanPreferencesKey("screen-sharing") } diff --git a/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt index b049edaf9a..5873b4308f 100644 --- a/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/fdroid/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt @@ -16,11 +16,11 @@ package im.vector.app.push.fcm import androidx.fragment.app.Fragment -import im.vector.app.BuildConfig import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.fdroid.features.settings.troubleshoot.TestAutoStartBoot import im.vector.app.fdroid.features.settings.troubleshoot.TestBackgroundRestrictions import im.vector.app.fdroid.features.settings.troubleshoot.TestBatteryOptimization +import im.vector.app.features.VectorFeatures import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.app.features.settings.troubleshoot.TestAccountSettings import im.vector.app.features.settings.troubleshoot.TestAvailableUnifiedPushDistributors @@ -50,7 +50,8 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( private val testAutoStartBoot: TestAutoStartBoot, private val testBackgroundRestrictions: TestBackgroundRestrictions, private val testBatteryOptimization: TestBatteryOptimization, - private val testNotification: TestNotification + private val testNotification: TestNotification, + private val vectorFeatures: VectorFeatures, ) { fun create(fragment: Fragment): NotificationTroubleshootTestManager { @@ -59,7 +60,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( mgr.addTest(testAccountSettings) mgr.addTest(testDeviceSettings) mgr.addTest(testPushRulesSettings) - if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { + if (vectorFeatures.allowExternalUnifiedPushDistributors()) { mgr.addTest(testAvailableUnifiedPushDistributors) mgr.addTest(testCurrentUnifiedPushDistributor) } diff --git a/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt b/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt index 767078b0d6..b3425c778b 100644 --- a/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt +++ b/vector/src/gplay/java/im/vector/app/push/fcm/NotificationTroubleshootTestManagerFactory.kt @@ -16,8 +16,8 @@ package im.vector.app.push.fcm import androidx.fragment.app.Fragment -import im.vector.app.BuildConfig import im.vector.app.core.pushers.UnifiedPushHelper +import im.vector.app.features.VectorFeatures import im.vector.app.features.settings.troubleshoot.NotificationTroubleshootTestManager import im.vector.app.features.settings.troubleshoot.TestAccountSettings import im.vector.app.features.settings.troubleshoot.TestAvailableUnifiedPushDistributors @@ -50,7 +50,8 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( private val testAvailableUnifiedPushDistributors: TestAvailableUnifiedPushDistributors, private val testEndpointAsTokenRegistration: TestEndpointAsTokenRegistration, private val testPushFromPushGateway: TestPushFromPushGateway, - private val testNotification: TestNotification + private val testNotification: TestNotification, + private val vectorFeatures: VectorFeatures, ) { fun create(fragment: Fragment): NotificationTroubleshootTestManager { @@ -59,7 +60,7 @@ class NotificationTroubleshootTestManagerFactory @Inject constructor( mgr.addTest(testAccountSettings) mgr.addTest(testDeviceSettings) mgr.addTest(testPushRulesSettings) - if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { + if (vectorFeatures.allowExternalUnifiedPushDistributors()) { mgr.addTest(testAvailableUnifiedPushDistributors) mgr.addTest(testCurrentUnifiedPushDistributor) } diff --git a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt index 1f712fa1e0..f2d2e802c4 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/UnifiedPushHelper.kt @@ -22,9 +22,9 @@ import androidx.fragment.app.FragmentActivity import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.squareup.moshi.Json import com.squareup.moshi.JsonClass -import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.resources.StringProvider +import im.vector.app.features.VectorFeatures import im.vector.app.features.settings.BackgroundSyncMode import im.vector.app.features.settings.VectorPreferences import im.vector.app.push.fcm.FcmHelper @@ -43,6 +43,7 @@ class UnifiedPushHelper @Inject constructor( private val stringProvider: StringProvider, private val vectorPreferences: VectorPreferences, private val matrix: Matrix, + private val vectorFeatures: VectorFeatures, ) { private val up = UnifiedPush @@ -75,7 +76,7 @@ class UnifiedPushHelper @Inject constructor( pushersManager: PushersManager? = null, onDoneRunnable: Runnable? = null ) { - if (!BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { + if (!vectorFeatures.allowExternalUnifiedPushDistributors()) { up.saveDistributor(context, context.packageName) up.registerApp(context) onDoneRunnable?.run() diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index 6a7a0865de..85b04dfbdc 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -27,6 +27,7 @@ interface VectorFeatures { fun isOnboardingPersonalizeEnabled(): Boolean fun isOnboardingCombinedRegisterEnabled(): Boolean fun isOnboardingCombinedLoginEnabled(): Boolean + fun allowExternalUnifiedPushDistributors(): Boolean fun isScreenSharingEnabled(): Boolean enum class OnboardingVariant { @@ -44,5 +45,15 @@ class DefaultVectorFeatures : VectorFeatures { override fun isOnboardingPersonalizeEnabled() = false override fun isOnboardingCombinedRegisterEnabled() = false override fun isOnboardingCombinedLoginEnabled() = false + + /** + * Return false to prevent usage of external UnifiedPush distributors. + * - For Gplay variant it means that only FCM will be used; + * - For F-Droid variant, it means that only background polling will be available to the user. + * Return true to allow any available external UnifiedPush distributor to be chosen by the user. + * - For Gplay variant it means that FCM will be used by default, but user can choose another UnifiedPush distributor; + * - For F-Droid variant, it means that background polling will be used by default, but user can choose another UnifiedPush distributor. + */ + override fun allowExternalUnifiedPushDistributors(): Boolean = true override fun isScreenSharingEnabled(): Boolean = true } 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 f8feb57c72..658dffab12 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 @@ -30,7 +30,6 @@ 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 @@ -44,6 +43,7 @@ import im.vector.app.core.services.GuardServiceStarter import im.vector.app.core.utils.combineLatest import im.vector.app.core.utils.isIgnoringBatteryOptimizations import im.vector.app.core.utils.requestDisablingBatteryOptimization +import im.vector.app.features.VectorFeatures import im.vector.app.features.analytics.plan.MobileScreen import im.vector.app.features.notifications.NotificationUtils import im.vector.app.features.settings.BackgroundSyncMode @@ -67,7 +67,8 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( private val pushersManager: PushersManager, private val activeSessionHolder: ActiveSessionHolder, private val vectorPreferences: VectorPreferences, - private val guardServiceStarter: GuardServiceStarter + private val guardServiceStarter: GuardServiceStarter, + private val vectorFeatures: VectorFeatures, ) : VectorSettingsBaseFragment(), BackgroundSyncModeChooserDialog.InteractionListener { @@ -147,7 +148,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( } findPreference(VectorPreferences.SETTINGS_UNIFIED_PUSH_RE_REGISTER_KEY)?.let { - if (BuildConfig.ALLOW_EXTERNAL_UNIFIEDPUSH_DISTRIB) { + if (vectorFeatures.allowExternalUnifiedPushDistributors()) { it.summary = unifiedPushHelper.getCurrentDistributorName() it.onPreferenceClickListener = Preference.OnPreferenceClickListener { unifiedPushHelper.reRegister(