Change BuildConfig field to a VectorFeature.

This commit is contained in:
Benoit Marty 2022-06-02 12:29:55 +02:00 committed by Benoit Marty
parent 80d42f0963
commit 18b49068c1
8 changed files with 35 additions and 15 deletions

View File

@ -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

View File

@ -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
),
)
)
}

View File

@ -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")
}

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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()

View File

@ -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
}

View File

@ -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<VectorPreference>(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(