generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f109b5
commit f3f51cf
Showing
26 changed files
with
1,358 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...tlin/com/bitwarden/authenticator/data/platform/manager/DebugMenuFeatureFlagManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.bitwarden.authenticator.data.platform.manager | ||
|
||
import com.bitwarden.authenticator.data.platform.manager.model.FlagKey | ||
import com.bitwarden.authenticator.data.platform.repository.DebugMenuRepository | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.map | ||
|
||
/** | ||
* The [FeatureFlagManager] implementation for the debug menu. This manager uses the | ||
* values returned from the [debugMenuRepository] if they are available. otherwise it will use | ||
* the default [FeatureFlagManager]. | ||
*/ | ||
class DebugMenuFeatureFlagManagerImpl( | ||
private val defaultFeatureFlagManager: FeatureFlagManager, | ||
private val debugMenuRepository: DebugMenuRepository, | ||
) : FeatureFlagManager by defaultFeatureFlagManager { | ||
|
||
override fun <T : Any> getFeatureFlagFlow(key: FlagKey<T>): Flow<T> { | ||
return debugMenuRepository.featureFlagOverridesUpdatedFlow.map { _ -> | ||
debugMenuRepository | ||
.getFeatureFlag(key) | ||
?: defaultFeatureFlagManager.getFeatureFlag(key = key) | ||
} | ||
} | ||
|
||
override suspend fun <T : Any> getFeatureFlag(key: FlagKey<T>, forceRefresh: Boolean): T { | ||
return debugMenuRepository | ||
.getFeatureFlag(key) | ||
?: defaultFeatureFlagManager.getFeatureFlag(key = key, forceRefresh = forceRefresh) | ||
} | ||
|
||
override fun <T : Any> getFeatureFlag(key: FlagKey<T>): T { | ||
return debugMenuRepository | ||
.getFeatureFlag(key) | ||
?: defaultFeatureFlagManager.getFeatureFlag(key = key) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...c/main/kotlin/com/bitwarden/authenticator/data/platform/repository/DebugMenuRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.bitwarden.authenticator.data.platform.repository | ||
|
||
import com.bitwarden.authenticator.data.platform.manager.model.FlagKey | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
/** | ||
* Repository for accessing data required or associated with the debug menu. | ||
*/ | ||
interface DebugMenuRepository { | ||
|
||
/** | ||
* Value to determine if the debug menu is enabled. | ||
*/ | ||
val isDebugMenuEnabled: Boolean | ||
|
||
/** | ||
* Observable flow for when any of the feature flag overrides have been updated. | ||
*/ | ||
val featureFlagOverridesUpdatedFlow: Flow<Unit> | ||
|
||
/** | ||
* Update a feature flag which matches the given [key] to the given [value]. | ||
*/ | ||
fun <T : Any> updateFeatureFlag(key: FlagKey<T>, value: T) | ||
|
||
/** | ||
* Get a feature flag value based on the associated [FlagKey]. | ||
*/ | ||
fun <T : Any> getFeatureFlag(key: FlagKey<T>): T? | ||
|
||
/** | ||
* Reset all feature flag overrides to their default values or values from the network. | ||
*/ | ||
fun resetFeatureFlagOverrides() | ||
} |
45 changes: 45 additions & 0 deletions
45
...in/kotlin/com/bitwarden/authenticator/data/platform/repository/DebugMenuRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.bitwarden.authenticator.data.platform.repository | ||
|
||
import com.bitwarden.authenticator.BuildConfig | ||
import com.bitwarden.authenticator.data.platform.datasource.disk.FeatureFlagOverrideDiskSource | ||
import com.bitwarden.authenticator.data.platform.manager.getFlagValueOrDefault | ||
import com.bitwarden.authenticator.data.platform.manager.model.FlagKey | ||
import com.bitwarden.authenticator.data.platform.repository.util.bufferedMutableSharedFlow | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.onSubscription | ||
|
||
/** | ||
* Default implementation of the [DebugMenuRepository] | ||
*/ | ||
class DebugMenuRepositoryImpl( | ||
private val featureFlagOverrideDiskSource: FeatureFlagOverrideDiskSource, | ||
private val serverConfigRepository: ServerConfigRepository, | ||
) : DebugMenuRepository { | ||
|
||
private val mutableOverridesUpdatedFlow = bufferedMutableSharedFlow<Unit>(replay = 1) | ||
override val featureFlagOverridesUpdatedFlow: Flow<Unit> = mutableOverridesUpdatedFlow | ||
.onSubscription { emit(Unit) } | ||
|
||
override val isDebugMenuEnabled: Boolean | ||
get() = BuildConfig.HAS_DEBUG_MENU | ||
|
||
override fun <T : Any> updateFeatureFlag(key: FlagKey<T>, value: T) { | ||
featureFlagOverrideDiskSource.saveFeatureFlag(key = key, value = value) | ||
mutableOverridesUpdatedFlow.tryEmit(Unit) | ||
} | ||
|
||
override fun <T : Any> getFeatureFlag(key: FlagKey<T>): T? = | ||
featureFlagOverrideDiskSource.getFeatureFlag( | ||
key = key, | ||
) | ||
|
||
override fun resetFeatureFlagOverrides() { | ||
val currentServerConfig = serverConfigRepository.serverConfigStateFlow.value | ||
FlagKey.activeFlags.forEach { flagKey -> | ||
updateFeatureFlag( | ||
flagKey, | ||
currentServerConfig.getFlagValueOrDefault(flagKey), | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.