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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
a0cc8a8
commit 5f109b5
Showing
19 changed files
with
575 additions
and
126 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
19 changes: 19 additions & 0 deletions
19
...om/bitwarden/authenticator/data/platform/datasource/disk/FeatureFlagOverrideDiskSource.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,19 @@ | ||
package com.bitwarden.authenticator.data.platform.datasource.disk | ||
|
||
import com.bitwarden.authenticator.data.platform.manager.model.FlagKey | ||
|
||
/** | ||
* Disk data source for saved feature flag overrides. | ||
*/ | ||
interface FeatureFlagOverrideDiskSource { | ||
|
||
/** | ||
* Save a feature flag [FlagKey] to disk. | ||
*/ | ||
fun <T : Any> saveFeatureFlag(key: FlagKey<T>, value: T) | ||
|
||
/** | ||
* Get a feature flag value based on the associated [FlagKey] from disk. | ||
*/ | ||
fun <T : Any> getFeatureFlag(key: FlagKey<T>): T? | ||
} |
37 changes: 37 additions & 0 deletions
37
...itwarden/authenticator/data/platform/datasource/disk/FeatureFlagOverrideDiskSourceImpl.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.datasource.disk | ||
|
||
import android.content.SharedPreferences | ||
import com.bitwarden.authenticator.data.platform.manager.model.FlagKey | ||
|
||
/** | ||
* Default implementation of the [FeatureFlagOverrideDiskSource] | ||
*/ | ||
class FeatureFlagOverrideDiskSourceImpl( | ||
sharedPreferences: SharedPreferences, | ||
) : FeatureFlagOverrideDiskSource, BaseDiskSource(sharedPreferences) { | ||
|
||
override fun <T : Any> saveFeatureFlag(key: FlagKey<T>, value: T) { | ||
when (key.defaultValue) { | ||
is Boolean -> putBoolean(key.keyName, value as Boolean) | ||
is String -> putString(key.keyName, value as String) | ||
is Int -> putInt(key.keyName, value as Int) | ||
else -> Unit | ||
} | ||
} | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
override fun <T : Any> getFeatureFlag(key: FlagKey<T>): T? { | ||
return try { | ||
when (key.defaultValue) { | ||
is Boolean -> getBoolean(key.keyName) as? T | ||
is String -> getString(key.keyName) as? T | ||
is Int -> getInt(key.keyName) as? T | ||
else -> null | ||
} | ||
} catch (castException: ClassCastException) { | ||
null | ||
} catch (numberFormatException: NumberFormatException) { | ||
null | ||
} | ||
} | ||
} |
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
40 changes: 27 additions & 13 deletions
40
...c/main/kotlin/com/bitwarden/authenticator/data/platform/manager/FeatureFlagManagerImpl.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
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
48 changes: 0 additions & 48 deletions
48
app/src/main/kotlin/com/bitwarden/authenticator/data/platform/manager/model/FeatureFlag.kt
This file was deleted.
Oops, something went wrong.
80 changes: 80 additions & 0 deletions
80
app/src/main/kotlin/com/bitwarden/authenticator/data/platform/manager/model/FlagKey.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,80 @@ | ||
package com.bitwarden.authenticator.data.platform.manager.model | ||
|
||
/** | ||
* Class to hold feature flag keys. | ||
*/ | ||
sealed class FlagKey<out T : Any> { | ||
/** | ||
* The string value of the given key. This must match the network value. | ||
*/ | ||
abstract val keyName: String | ||
|
||
/** | ||
* The value to be used if the flags value cannot be determined or is not remotely configured. | ||
*/ | ||
abstract val defaultValue: T | ||
|
||
/** | ||
* Indicates if the flag should respect the network value or not. | ||
*/ | ||
abstract val isRemotelyConfigured: Boolean | ||
|
||
@Suppress("UndocumentedPublicClass") | ||
companion object { | ||
/** | ||
* List of all flag keys to consider | ||
*/ | ||
val activeFlags: List<FlagKey<*>> by lazy { | ||
listOf( | ||
BitwardenAuthenticationEnabled, | ||
PasswordManagerSync, | ||
) | ||
} | ||
} | ||
|
||
/** | ||
* Indicates the state of Bitwarden authentication. | ||
*/ | ||
data object BitwardenAuthenticationEnabled : FlagKey<Boolean>() { | ||
override val keyName: String = "bitwarden-authentication-enabled" | ||
override val defaultValue: Boolean = false | ||
override val isRemotelyConfigured: Boolean = false | ||
} | ||
|
||
/** | ||
* Indicates whether syncing with the main Bitwarden password manager app should be enabled.. | ||
*/ | ||
data object PasswordManagerSync : FlagKey<Boolean>() { | ||
override val keyName: String = "enable-password-manager-sync-android" | ||
override val defaultValue: Boolean = false | ||
override val isRemotelyConfigured: Boolean = true | ||
} | ||
|
||
/** | ||
* Data object holding the key for a [Boolean] flag to be used in tests. | ||
*/ | ||
data object DummyBoolean : FlagKey<Boolean>() { | ||
override val keyName: String = "dummy-boolean" | ||
override val defaultValue: Boolean = false | ||
override val isRemotelyConfigured: Boolean = true | ||
} | ||
|
||
/** | ||
* Data object holding the key for an [Int] flag to be used in tests. | ||
*/ | ||
data class DummyInt( | ||
override val isRemotelyConfigured: Boolean = true, | ||
) : FlagKey<Int>() { | ||
override val keyName: String = "dummy-int" | ||
override val defaultValue: Int = Int.MIN_VALUE | ||
} | ||
|
||
/** | ||
* Data object holding the key for a [String] flag to be used in tests. | ||
*/ | ||
data object DummyString : FlagKey<String>() { | ||
override val keyName: String = "dummy-string" | ||
override val defaultValue: String = "defaultValue" | ||
override val isRemotelyConfigured: Boolean = true | ||
} | ||
} |
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.