diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSource.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSource.kt index 4d5dab6a8..ec3851980 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSource.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSource.kt @@ -92,4 +92,14 @@ interface SettingsDiskSource { * Stores the given [isPullToRefreshEnabled] for the given [userId]. */ fun storePullToRefreshEnabled(userId: String, isPullToRefreshEnabled: Boolean?) + + /** + * Gets the value determining if inline autofill is enabled for the given [userId]. + */ + fun getInlineAutofillEnabled(userId: String): Boolean? + + /** + * Stores the given [isInlineAutofillEnabled] value for the given [userId]. + */ + fun storeInlineAutofillEnabled(userId: String, isInlineAutofillEnabled: Boolean?) } diff --git a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceImpl.kt b/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceImpl.kt index a158ba039..bd4b4338d 100644 --- a/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceImpl.kt +++ b/app/src/main/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceImpl.kt @@ -13,6 +13,7 @@ import kotlinx.coroutines.flow.onSubscription 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 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" @@ -84,6 +85,8 @@ class SettingsDiskSourceImpl( override fun clearData(userId: String) { storeVaultTimeoutInMinutes(userId = userId, vaultTimeoutInMinutes = null) storeVaultTimeoutAction(userId = userId, vaultTimeoutAction = null) + storePullToRefreshEnabled(userId = userId, isPullToRefreshEnabled = null) + storeInlineAutofillEnabled(userId = userId, isInlineAutofillEnabled = null) } override fun getVaultTimeoutInMinutes(userId: String): Int? = @@ -136,6 +139,19 @@ class SettingsDiskSourceImpl( getMutablePullToRefreshEnabledFlowMap(userId = userId).tryEmit(isPullToRefreshEnabled) } + override fun getInlineAutofillEnabled(userId: String): Boolean? = + getBoolean(key = "${INLINE_AUTOFILL_ENABLED_KEY}_$userId") + + override fun storeInlineAutofillEnabled( + userId: String, + isInlineAutofillEnabled: Boolean?, + ) { + putBoolean( + key = "${INLINE_AUTOFILL_ENABLED_KEY}_$userId", + value = isInlineAutofillEnabled, + ) + } + private fun getMutableVaultTimeoutActionFlow( userId: String, ): MutableSharedFlow = diff --git a/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceTest.kt index fa14da21b..317eded2b 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/SettingsDiskSourceTest.kt @@ -70,11 +70,21 @@ class SettingsDiskSourceTest { userId = userId, vaultTimeoutAction = VaultTimeoutAction.LOCK, ) + settingsDiskSource.storePullToRefreshEnabled( + userId = userId, + isPullToRefreshEnabled = true, + ) + settingsDiskSource.storeInlineAutofillEnabled( + userId = userId, + isInlineAutofillEnabled = true, + ) settingsDiskSource.clearData(userId = userId) assertNull(settingsDiskSource.getVaultTimeoutInMinutes(userId = userId)) assertNull(settingsDiskSource.getVaultTimeoutAction(userId = userId)) + assertNull(settingsDiskSource.getPullToRefreshEnabled(userId = userId)) + assertNull(settingsDiskSource.getInlineAutofillEnabled(userId = userId)) } @Test @@ -329,7 +339,7 @@ class SettingsDiskSourceTest { } @Test - fun `storePullToRefreshEnabled when values are present should pull from SharedPreferences`() { + fun `getPullToRefreshEnabled when values are present should pull from SharedPreferences`() { val pullToRefreshBaseKey = "bwPreferencesStorage:syncOnRefresh" val mockUserId = "mockUserId" val pullToRefreshKey = "${pullToRefreshBaseKey}_$mockUserId" @@ -341,7 +351,7 @@ class SettingsDiskSourceTest { } @Test - fun `storePullToRefreshEnabled when values are absent should return null`() { + fun `getPullToRefreshEnabled when values are absent should return null`() { val mockUserId = "mockUserId" assertNull(settingsDiskSource.getPullToRefreshEnabled(userId = mockUserId)) } @@ -388,4 +398,47 @@ class SettingsDiskSourceTest { ) assertFalse(fakeSharedPreferences.contains(pullToRefreshKey)) } + + @Test + fun `getInlineAutofillEnabled when values are present should pull from SharedPreferences`() { + val inlineAutofillEnabledBaseKey = "bwPreferencesStorage:inlineAutofillEnabled" + val mockUserId = "mockUserId" + val inlineAutofillEnabledKey = "${inlineAutofillEnabledBaseKey}_$mockUserId" + fakeSharedPreferences + .edit { + putBoolean(inlineAutofillEnabledKey, true) + } + assertEquals(true, settingsDiskSource.getInlineAutofillEnabled(userId = mockUserId)) + } + + @Test + fun `getInlineAutofillEnabled when values are absent should return null`() { + val mockUserId = "mockUserId" + assertNull(settingsDiskSource.getInlineAutofillEnabled(userId = mockUserId)) + } + + @Test + fun `storeInlineAutofillEnabled for non-null values should update SharedPreferences`() { + val inlineAutofillEnabledBaseKey = "bwPreferencesStorage:inlineAutofillEnabled" + val mockUserId = "mockUserId" + val inlineAutofillEnabledKey = "${inlineAutofillEnabledBaseKey}_$mockUserId" + settingsDiskSource.storeInlineAutofillEnabled( + userId = mockUserId, + isInlineAutofillEnabled = true, + ) + assertTrue(fakeSharedPreferences.getBoolean(inlineAutofillEnabledKey, false)) + } + + @Test + fun `storeInlineAutofillEnabled for null values should clear SharedPreferences`() { + val inlineAutofillEnabledBaseKey = "bwPreferencesStorage:inlineAutofillEnabled" + val mockUserId = "mockUserId" + val inlineAutofillEnabledKey = "${inlineAutofillEnabledBaseKey}_$mockUserId" + fakeSharedPreferences.edit { putBoolean(inlineAutofillEnabledKey, false) } + settingsDiskSource.storeInlineAutofillEnabled( + userId = mockUserId, + isInlineAutofillEnabled = null, + ) + assertFalse(fakeSharedPreferences.contains(inlineAutofillEnabledKey)) + } } diff --git a/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/util/FakeSettingsDiskSource.kt b/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/util/FakeSettingsDiskSource.kt index 769b0815c..844f7d0f8 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/util/FakeSettingsDiskSource.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/platform/datasource/disk/util/FakeSettingsDiskSource.kt @@ -34,6 +34,7 @@ class FakeSettingsDiskSource : SettingsDiskSource { private val storedVaultTimeoutInMinutes = mutableMapOf() private val storedPullToRefreshEnabled = mutableMapOf() + private val storedInlineAutofillEnabled = mutableMapOf() private var storedIsIconLoadingDisabled: Boolean? = null @@ -66,6 +67,8 @@ class FakeSettingsDiskSource : SettingsDiskSource { override fun clearData(userId: String) { storedVaultTimeoutActions.remove(userId) storedVaultTimeoutInMinutes.remove(userId) + storedPullToRefreshEnabled.remove(userId) + storedInlineAutofillEnabled.remove(userId) mutableVaultTimeoutActionsFlowMap.remove(userId) mutableVaultTimeoutInMinutesFlowMap.remove(userId) @@ -113,6 +116,16 @@ class FakeSettingsDiskSource : SettingsDiskSource { getMutablePullToRefreshEnabledFlow(userId = userId).tryEmit(isPullToRefreshEnabled) } + override fun getInlineAutofillEnabled(userId: String): Boolean? = + storedInlineAutofillEnabled[userId] + + override fun storeInlineAutofillEnabled( + userId: String, + isInlineAutofillEnabled: Boolean?, + ) { + storedInlineAutofillEnabled[userId] = isInlineAutofillEnabled + } + //region Private helper functions private fun getMutableVaultTimeoutActionsFlow(