Skip to content

Commit

Permalink
Remove unused lastDatabaseSchemeChangeInstant from settings disk sour…
Browse files Browse the repository at this point in the history
…ce (#4374)
  • Loading branch information
david-livefront authored Nov 25, 2024
1 parent cce9bef commit 05aa52b
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ interface SettingsDiskSource {
*/
val hasUserLoggedInOrCreatedAccountFlow: Flow<Boolean?>

/**
* The instant when the last database scheme change was applied. `null` if no scheme changes
* have been applied yet.
*/
var lastDatabaseSchemeChangeInstant: Instant?

/**
* Emits updates that track [lastDatabaseSchemeChangeInstant].
*/
val lastDatabaseSchemeChangeInstantFlow: Flow<Instant?>

/**
* Clears all the settings data for the given user.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ private const val HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY = "hasUserLoggedI
private const val SHOW_AUTOFILL_SETTING_BADGE = "showAutofillSettingBadge"
private const val SHOW_UNLOCK_SETTING_BADGE = "showUnlockSettingBadge"
private const val SHOW_IMPORT_LOGINS_SETTING_BADGE = "showImportLoginsSettingBadge"
private const val LAST_SCHEME_CHANGE_INSTANT = "lastDatabaseSchemeChangeInstant"
private const val IS_VAULT_REGISTERED_FOR_EXPORT = "isVaultRegisteredForExport"

/**
Expand Down Expand Up @@ -76,8 +75,6 @@ class SettingsDiskSourceImpl(

private val mutableHasUserLoggedInOrCreatedAccountFlow = bufferedMutableSharedFlow<Boolean?>()

private val mutableLastDatabaseSchemeChangeInstantFlow = bufferedMutableSharedFlow<Instant?>()

private val mutableScreenCaptureAllowedFlowMap =
mutableMapOf<String, MutableSharedFlow<Boolean?>>()

Expand Down Expand Up @@ -162,17 +159,6 @@ class SettingsDiskSourceImpl(
get() = mutableHasUserLoggedInOrCreatedAccountFlow
.onSubscription { emit(getBoolean(HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY)) }

override var lastDatabaseSchemeChangeInstant: Instant?
get() = getLong(LAST_SCHEME_CHANGE_INSTANT)?.let { Instant.ofEpochMilli(it) }
set(value) {
putLong(LAST_SCHEME_CHANGE_INSTANT, value?.toEpochMilli())
mutableLastDatabaseSchemeChangeInstantFlow.tryEmit(value)
}

override val lastDatabaseSchemeChangeInstantFlow: Flow<Instant?>
get() = mutableLastDatabaseSchemeChangeInstantFlow
.onSubscription { emit(lastDatabaseSchemeChangeInstant) }

override fun clearData(userId: String) {
storeVaultTimeoutInMinutes(userId = userId, vaultTimeoutInMinutes = null)
storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1117,55 +1117,6 @@ class SettingsDiskSourceTest {
}
}

@Test
fun `lastDatabaseSchemeChangeInstant should pull from SharedPreferences`() {
val schemeChangeKey = "bwPreferencesStorage:lastDatabaseSchemeChangeInstant"
val expected: Long = Instant.now().toEpochMilli()

fakeSharedPreferences
.edit {
remove(schemeChangeKey)
}
assertEquals(0, fakeSharedPreferences.getLong(schemeChangeKey, 0))
assertNull(settingsDiskSource.lastDatabaseSchemeChangeInstant)

// Updating the shared preferences should update disk source.
fakeSharedPreferences
.edit {
putLong(
schemeChangeKey,
expected,
)
}
val actual = settingsDiskSource.lastDatabaseSchemeChangeInstant
assertEquals(
expected,
actual?.toEpochMilli(),
)
}

@Test
fun `setting lastDatabaseSchemeChangeInstant should update SharedPreferences`() {
val schemeChangeKey = "bwPreferencesStorage:lastDatabaseSchemeChangeInstant"
val schemeChangeInstant = Instant.now()

// Setting to null should update disk source
settingsDiskSource.lastDatabaseSchemeChangeInstant = null
assertEquals(0, fakeSharedPreferences.getLong(schemeChangeKey, 0))
assertNull(settingsDiskSource.lastDatabaseSchemeChangeInstant)

// Setting to value should update disk source
settingsDiskSource.lastDatabaseSchemeChangeInstant = schemeChangeInstant
val actual = fakeSharedPreferences.getLong(
schemeChangeKey,
0,
)
assertEquals(
schemeChangeInstant.toEpochMilli(),
actual,
)
}

@Test
fun `getShowImportLoginsSettingBadge should pull from shared preferences`() {
val mockUserId = "mockUserId"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ class FakeSettingsDiskSource : SettingsDiskSource {
private val mutableScreenCaptureAllowedFlowMap =
mutableMapOf<String, MutableSharedFlow<Boolean?>>()

private val mutableLastDatabaseSchemeChangeInstant =
bufferedMutableSharedFlow<Instant?>()

private var storedAppTheme: AppTheme = AppTheme.DEFAULT
private val storedLastSyncTime = mutableMapOf<String, Instant?>()
private val storedVaultTimeoutActions = mutableMapOf<String, VaultTimeoutAction?>()
Expand All @@ -67,7 +64,6 @@ class FakeSettingsDiskSource : SettingsDiskSource {
private val userShowAutoFillBadge = mutableMapOf<String, Boolean?>()
private val userShowUnlockBadge = mutableMapOf<String, Boolean?>()
private val userShowImportLoginsBadge = mutableMapOf<String, Boolean?>()
private var storedLastDatabaseSchemeChangeInstant: Instant? = null
private val vaultRegisteredForExport = mutableMapOf<String, Boolean?>()

private val mutableShowAutoFillSettingBadgeFlowMap =
Expand Down Expand Up @@ -144,17 +140,6 @@ class FakeSettingsDiskSource : SettingsDiskSource {
emit(hasUserLoggedInOrCreatedAccount)
}

override var lastDatabaseSchemeChangeInstant: Instant?
get() = storedLastDatabaseSchemeChangeInstant
set(value) {
storedLastDatabaseSchemeChangeInstant = value
}

override val lastDatabaseSchemeChangeInstantFlow: Flow<Instant?>
get() = mutableLastDatabaseSchemeChangeInstant.onSubscription {
emit(lastDatabaseSchemeChangeInstant)
}

override fun getAccountBiometricIntegrityValidity(
userId: String,
systemBioIntegrityState: String,
Expand Down

0 comments on commit 05aa52b

Please sign in to comment.