BIT-1148: Add storage for blocked autofill URIs (#657)

This commit is contained in:
Brian Yencho
2024-01-17 21:30:25 -06:00
committed by Álison Fernandes
parent a87bcd28ff
commit 840f675736
8 changed files with 163 additions and 0 deletions

View File

@@ -102,4 +102,17 @@ interface SettingsDiskSource {
* Stores the given [isInlineAutofillEnabled] value for the given [userId].
*/
fun storeInlineAutofillEnabled(userId: String, isInlineAutofillEnabled: Boolean?)
/**
* Gets a list of blocked autofill URI's for the given [userId].
*/
fun getBlockedAutofillUris(userId: String): List<String>?
/**
* Stores the list of [blockedAutofillUris] for the given [userId].
*/
fun storeBlockedAutofillUris(
userId: String,
blockedAutofillUris: List<String>?,
)
}

View File

@@ -9,11 +9,14 @@ import com.x8bit.bitwarden.ui.platform.feature.settings.appearance.model.AppThem
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.onSubscription
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
private const val APP_LANGUAGE_KEY = "$BASE_KEY:appLocale"
private const val APP_THEME_KEY = "$BASE_KEY:theme"
private const val PULL_TO_REFRESH_KEY = "$BASE_KEY:syncOnRefresh"
private const val INLINE_AUTOFILL_ENABLED_KEY = "$BASE_KEY:inlineAutofillEnabled"
private const val BLOCKED_AUTOFILL_URIS_KEY = "$BASE_KEY:autofillBlacklistedUris"
private const val VAULT_TIMEOUT_ACTION_KEY = "$BASE_KEY:vaultTimeoutAction"
private const val VAULT_TIME_IN_MINUTES_KEY = "$BASE_KEY:vaultTimeout"
private const val DISABLE_ICON_LOADING_KEY = "$BASE_KEY:disableFavicon"
@@ -24,6 +27,7 @@ private const val DISABLE_ICON_LOADING_KEY = "$BASE_KEY:disableFavicon"
@Suppress("TooManyFunctions")
class SettingsDiskSourceImpl(
val sharedPreferences: SharedPreferences,
private val json: Json,
) : BaseDiskSource(sharedPreferences = sharedPreferences),
SettingsDiskSource {
private val mutableAppThemeFlow =
@@ -87,6 +91,7 @@ class SettingsDiskSourceImpl(
storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null)
storePullToRefreshEnabled(userId = userId, isPullToRefreshEnabled = null)
storeInlineAutofillEnabled(userId = userId, isInlineAutofillEnabled = null)
storeBlockedAutofillUris(userId = userId, blockedAutofillUris = null)
}
override fun getVaultTimeoutInMinutes(userId: String): Int? =
@@ -152,6 +157,21 @@ class SettingsDiskSourceImpl(
)
}
override fun getBlockedAutofillUris(userId: String): List<String>? =
getString(key = "${BLOCKED_AUTOFILL_URIS_KEY}_$userId")?.let {
json.decodeFromString(it)
}
override fun storeBlockedAutofillUris(
userId: String,
blockedAutofillUris: List<String>?,
) {
putString(
key = "${BLOCKED_AUTOFILL_URIS_KEY}_$userId",
value = blockedAutofillUris?.let { json.encodeToString(it) },
)
}
private fun getMutableVaultTimeoutActionFlow(
userId: String,
): MutableSharedFlow<VaultTimeoutAction?> =

View File

@@ -46,8 +46,10 @@ object PlatformDiskModule {
@Singleton
fun provideSettingsDiskSource(
@UnencryptedPreferences sharedPreferences: SharedPreferences,
json: Json,
): SettingsDiskSource =
SettingsDiskSourceImpl(
sharedPreferences = sharedPreferences,
json = json,
)
}

View File

@@ -57,6 +57,11 @@ interface SettingsRepository {
*/
var isInlineAutofillEnabled: Boolean
/**
* A list of blocked autofill URI's for the current user.
*/
var blockedAutofillUris: List<String>
/**
* Sets default values for various settings for the given [userId] if necessary. This is
* typically used when logging into a new account.

View File

@@ -109,6 +109,18 @@ class SettingsRepositoryImpl(
)
}
override var blockedAutofillUris: List<String>
get() = activeUserId
?.let { settingsDiskSource.getBlockedAutofillUris(userId = it) }
?: emptyList()
set(value) {
val userId = activeUserId ?: return
settingsDiskSource.storeBlockedAutofillUris(
userId = userId,
blockedAutofillUris = value,
)
}
override fun setDefaultsIfNecessary(userId: String) {
// Set Vault Settings defaults
if (!isVaultTimeoutActionSet(userId = userId)) {