Add clearData calls DiskSources (#603)

This commit is contained in:
Brian Yencho
2024-01-14 08:19:11 -06:00
committed by Álison Fernandes
parent 67d7b7a9f5
commit f1b9ded3e3
12 changed files with 161 additions and 12 deletions

View File

@@ -31,6 +31,13 @@ interface AuthDiskSource {
*/
val userStateFlow: Flow<UserStateJson?>
/**
* Clears all the settings data for the given user.
*
* Note that this does not include any data saved in the [userState].
*/
fun clearData(userId: String)
/**
* Retrieves the "last active time" for the given [userId], in milliseconds.
*

View File

@@ -67,6 +67,17 @@ class AuthDiskSourceImpl(
get() = mutableUserStateFlow
.onSubscription { emit(userState) }
private val mutableUserStateFlow = bufferedMutableSharedFlow<UserStateJson?>(replay = 1)
override fun clearData(userId: String) {
storeLastActiveTimeMillis(userId = userId, lastActiveTimeMillis = null)
storeUserKey(userId = userId, userKey = null)
storeUserAutoUnlockKey(userId = userId, userAutoUnlockKey = null)
storePrivateKey(userId = userId, privateKey = null)
storeOrganizationKeys(userId = userId, organizationKeys = null)
storeOrganizations(userId = userId, organizations = null)
}
override fun getLastActiveTimeMillis(userId: String): Long? =
getLong(key = "${LAST_ACTIVE_TIME_KEY}_$userId")
@@ -80,8 +91,6 @@ class AuthDiskSourceImpl(
)
}
private val mutableUserStateFlow = bufferedMutableSharedFlow<UserStateJson?>(replay = 1)
override fun getUserKey(userId: String): String? =
getString(key = "${MASTER_KEY_ENCRYPTION_USER_KEY}_$userId")

View File

@@ -13,6 +13,11 @@ interface SettingsDiskSource {
*/
var appLanguage: AppLanguage?
/**
* Clears all the settings data for the given user.
*/
fun clearData(userId: String)
/**
* Gets the current vault timeout (in minutes) for the given [userId] (or `null` if the vault
* should never time out).

View File

@@ -39,6 +39,11 @@ class SettingsDiskSourceImpl(
)
}
override fun clearData(userId: String) {
storeVaultTimeoutInMinutes(userId = userId, vaultTimeoutInMinutes = null)
storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null)
}
override fun getVaultTimeoutInMinutes(userId: String): Int? =
getInt(key = "${VAULT_TIME_IN_MINUTES_KEY}_$userId")

View File

@@ -59,16 +59,7 @@ class SettingsRepositoryImpl(
}
override fun clearData(userId: String) {
settingsDiskSource.apply {
storeVaultTimeoutInMinutes(
userId = userId,
vaultTimeoutInMinutes = null,
)
storeVaultTimeoutAction(
userId = userId,
vaultTimeoutAction = null,
)
}
settingsDiskSource.clearData(userId = userId)
}
override fun setDefaultsIfNecessary(userId: String) {

View File

@@ -7,6 +7,10 @@ import com.x8bit.bitwarden.data.tools.generator.repository.model.UsernameGenerat
* Primary access point for disk information related to generation.
*/
interface GeneratorDiskSource {
/**
* Clears all the settings data for the given user.
*/
fun clearData(userId: String)
/**
* Retrieves a user's passcode generation options using a [userId].

View File

@@ -19,6 +19,11 @@ class GeneratorDiskSourceImpl(
) : BaseDiskSource(sharedPreferences),
GeneratorDiskSource {
override fun clearData(userId: String) {
storePasscodeGenerationOptions(userId = userId, options = null)
storeUsernameGenerationOptions(userId = userId, options = null)
}
override fun getPasscodeGenerationOptions(userId: String): PasscodeGenerationOptions? {
val key = getPasswordGenerationOptionsKey(userId)
return getString(key)?.let { json.decodeFromString(it) }