FFs can now be toggled in release builds too (#3101)

- Removed `StaticFeatureFlagProvider`.
- Always provide `PreferencesFeatureFlagProvider`.
- For the default values of feature flags, use a lambda with a `BuildMeta` parameter so we can customize the return value based on its data.
This commit is contained in:
Jorge Martin Espinosa 2024-07-02 18:06:42 +02:00 committed by GitHub
parent d846113fdf
commit e9e7d4d0c4
19 changed files with 118 additions and 118 deletions

View file

@ -23,6 +23,8 @@ android {
dependencies {
api(projects.libraries.featureflag.api)
implementation(projects.libraries.core)
implementation(projects.libraries.matrix.test)
implementation(libs.coroutines.core)
}
}

View file

@ -16,19 +16,19 @@
package io.element.android.libraries.featureflag.test
import io.element.android.libraries.core.meta.BuildMeta
import io.element.android.libraries.featureflag.api.Feature
import io.element.android.libraries.featureflag.api.FeatureFlagService
import io.element.android.libraries.matrix.test.core.aBuildMeta
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
class FakeFeatureFlagService(
initialState: Map<String, Boolean> = emptyMap()
initialState: Map<String, Boolean> = emptyMap(),
private val buildMeta: BuildMeta = aBuildMeta(),
) : FeatureFlagService {
private val enabledFeatures = initialState
.map {
it.key to MutableStateFlow(it.value)
}
.toMap()
.mapValues { MutableStateFlow(it.value) }
.toMutableMap()
override suspend fun setFeatureEnabled(feature: Feature, enabled: Boolean): Boolean {
@ -38,6 +38,6 @@ class FakeFeatureFlagService(
}
override fun isFeatureEnabledFlow(feature: Feature): Flow<Boolean> {
return enabledFeatures.getOrPut(feature.key) { MutableStateFlow(feature.defaultValue) }
return enabledFeatures.getOrPut(feature.key) { MutableStateFlow(feature.defaultValue(buildMeta)) }
}
}