mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +03:00
PM-14414 hides autofill card for all users if autofill service is enabled. (#4297)
This commit is contained in:
parent
1e0e4831b8
commit
072c3a992c
3 changed files with 83 additions and 4 deletions
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.data.platform.manager
|
||||||
|
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||||
import com.x8bit.bitwarden.data.auth.repository.util.activeUserIdChangesFlow
|
import com.x8bit.bitwarden.data.auth.repository.util.activeUserIdChangesFlow
|
||||||
|
import com.x8bit.bitwarden.data.autofill.manager.AutofillEnabledManager
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
||||||
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
import com.x8bit.bitwarden.data.platform.manager.dispatcher.DispatcherManager
|
||||||
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
|
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
|
||||||
|
@ -30,6 +31,7 @@ class FirstTimeActionManagerImpl @Inject constructor(
|
||||||
private val settingsDiskSource: SettingsDiskSource,
|
private val settingsDiskSource: SettingsDiskSource,
|
||||||
private val vaultDiskSource: VaultDiskSource,
|
private val vaultDiskSource: VaultDiskSource,
|
||||||
private val featureFlagManager: FeatureFlagManager,
|
private val featureFlagManager: FeatureFlagManager,
|
||||||
|
private val autofillEnabledManager: AutofillEnabledManager,
|
||||||
) : FirstTimeActionManager {
|
) : FirstTimeActionManager {
|
||||||
|
|
||||||
private val unconfinedScope = CoroutineScope(dispatcherManager.unconfined)
|
private val unconfinedScope = CoroutineScope(dispatcherManager.unconfined)
|
||||||
|
@ -78,7 +80,7 @@ class FirstTimeActionManagerImpl @Inject constructor(
|
||||||
.filterNotNull()
|
.filterNotNull()
|
||||||
.flatMapLatest {
|
.flatMapLatest {
|
||||||
// Can be expanded to support multiple autofill settings
|
// Can be expanded to support multiple autofill settings
|
||||||
settingsDiskSource.getShowAutoFillSettingBadgeFlow(userId = it)
|
getShowAutofillSettingBadgeFlowInternal(userId = it)
|
||||||
.map { showAutofillBadge ->
|
.map { showAutofillBadge ->
|
||||||
listOfNotNull(showAutofillBadge)
|
listOfNotNull(showAutofillBadge)
|
||||||
}
|
}
|
||||||
|
@ -128,7 +130,7 @@ class FirstTimeActionManagerImpl @Inject constructor(
|
||||||
listOf(
|
listOf(
|
||||||
getShowImportLoginsFlowInternal(userId = activeUserId),
|
getShowImportLoginsFlowInternal(userId = activeUserId),
|
||||||
settingsDiskSource.getShowUnlockSettingBadgeFlow(userId = activeUserId),
|
settingsDiskSource.getShowUnlockSettingBadgeFlow(userId = activeUserId),
|
||||||
settingsDiskSource.getShowAutoFillSettingBadgeFlow(userId = activeUserId),
|
getShowAutofillSettingBadgeFlowInternal(userId = activeUserId),
|
||||||
getShowImportLoginsSettingBadgeFlowInternal(userId = activeUserId),
|
getShowImportLoginsSettingBadgeFlowInternal(userId = activeUserId),
|
||||||
),
|
),
|
||||||
) {
|
) {
|
||||||
|
@ -165,7 +167,7 @@ class FirstTimeActionManagerImpl @Inject constructor(
|
||||||
FirstTimeState(
|
FirstTimeState(
|
||||||
showImportLoginsCard = authDiskSource.getShowImportLogins(it),
|
showImportLoginsCard = authDiskSource.getShowImportLogins(it),
|
||||||
showSetupUnlockCard = settingsDiskSource.getShowUnlockSettingBadge(it),
|
showSetupUnlockCard = settingsDiskSource.getShowUnlockSettingBadge(it),
|
||||||
showSetupAutofillCard = settingsDiskSource.getShowAutoFillSettingBadge(it),
|
showSetupAutofillCard = getShowAutofillSettingBadgeInternal(it),
|
||||||
showImportLoginsCardInSettings = settingsDiskSource
|
showImportLoginsCardInSettings = settingsDiskSource
|
||||||
.getShowImportLoginsSettingBadge(it),
|
.getShowImportLoginsSettingBadge(it),
|
||||||
)
|
)
|
||||||
|
@ -236,4 +238,23 @@ class FirstTimeActionManagerImpl @Inject constructor(
|
||||||
showImportLogins ?: false && ciphers.isEmpty()
|
showImportLogins ?: false && ciphers.isEmpty()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal implementation to get a flow of the showAutofill value which takes
|
||||||
|
* into account if autofill is already enabled globally.
|
||||||
|
*/
|
||||||
|
private fun getShowAutofillSettingBadgeFlowInternal(userId: String): Flow<Boolean> {
|
||||||
|
return settingsDiskSource
|
||||||
|
.getShowAutoFillSettingBadgeFlow(userId)
|
||||||
|
.combine(
|
||||||
|
autofillEnabledManager.isAutofillEnabledStateFlow,
|
||||||
|
) { showAutofill, autofillEnabled ->
|
||||||
|
showAutofill ?: false && !autofillEnabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getShowAutofillSettingBadgeInternal(userId: String): Boolean {
|
||||||
|
return settingsDiskSource.getShowAutoFillSettingBadge(userId) ?: false &&
|
||||||
|
!autofillEnabledManager.isAutofillEnabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import androidx.core.content.getSystemService
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
import com.x8bit.bitwarden.data.auth.datasource.disk.AuthDiskSource
|
||||||
import com.x8bit.bitwarden.data.auth.manager.AddTotpItemFromAuthenticatorManager
|
import com.x8bit.bitwarden.data.auth.manager.AddTotpItemFromAuthenticatorManager
|
||||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||||
|
import com.x8bit.bitwarden.data.autofill.manager.AutofillEnabledManager
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.EventDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.EventDiskSource
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.PushDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.PushDiskSource
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.SettingsDiskSource
|
||||||
|
@ -293,12 +294,14 @@ object PlatformManagerModule {
|
||||||
vaultDiskSource: VaultDiskSource,
|
vaultDiskSource: VaultDiskSource,
|
||||||
dispatcherManager: DispatcherManager,
|
dispatcherManager: DispatcherManager,
|
||||||
featureFlagManager: FeatureFlagManager,
|
featureFlagManager: FeatureFlagManager,
|
||||||
|
autofillEnabledManager: AutofillEnabledManager,
|
||||||
): FirstTimeActionManager = FirstTimeActionManagerImpl(
|
): FirstTimeActionManager = FirstTimeActionManagerImpl(
|
||||||
authDiskSource = authDiskSource,
|
authDiskSource = authDiskSource,
|
||||||
settingsDiskSource = settingsDiskSource,
|
settingsDiskSource = settingsDiskSource,
|
||||||
vaultDiskSource = vaultDiskSource,
|
vaultDiskSource = vaultDiskSource,
|
||||||
dispatcherManager = dispatcherManager,
|
dispatcherManager = dispatcherManager,
|
||||||
featureFlagManager = featureFlagManager,
|
featureFlagManager = featureFlagManager,
|
||||||
|
autofillEnabledManager = autofillEnabledManager,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|
|
@ -8,6 +8,7 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.util.FakeAuthDiskSource
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.KdfTypeJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.KdfTypeJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.TrustedDeviceUserDecryptionOptionsJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.TrustedDeviceUserDecryptionOptionsJson
|
||||||
import com.x8bit.bitwarden.data.auth.datasource.network.model.UserDecryptionOptionsJson
|
import com.x8bit.bitwarden.data.auth.datasource.network.model.UserDecryptionOptionsJson
|
||||||
|
import com.x8bit.bitwarden.data.autofill.manager.AutofillEnabledManager
|
||||||
import com.x8bit.bitwarden.data.platform.base.FakeDispatcherManager
|
import com.x8bit.bitwarden.data.platform.base.FakeDispatcherManager
|
||||||
import com.x8bit.bitwarden.data.platform.datasource.disk.util.FakeSettingsDiskSource
|
import com.x8bit.bitwarden.data.platform.datasource.disk.util.FakeSettingsDiskSource
|
||||||
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
|
import com.x8bit.bitwarden.data.platform.manager.model.FirstTimeState
|
||||||
|
@ -37,17 +38,24 @@ class FirstTimeActionManagerTest {
|
||||||
every { getFeatureFlagFlow(FlagKey.ImportLoginsFlow) } returns mutableImportLoginsFlow
|
every { getFeatureFlagFlow(FlagKey.ImportLoginsFlow) } returns mutableImportLoginsFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val mutableAutofillEnabledFlow = MutableStateFlow(false)
|
||||||
|
private val autofillEnabledManager = mockk<AutofillEnabledManager> {
|
||||||
|
every { isAutofillEnabledStateFlow } returns mutableAutofillEnabledFlow
|
||||||
|
every { isAutofillEnabled } returns false
|
||||||
|
}
|
||||||
|
|
||||||
private val firstTimeActionManager = FirstTimeActionManagerImpl(
|
private val firstTimeActionManager = FirstTimeActionManagerImpl(
|
||||||
authDiskSource = fakeAuthDiskSource,
|
authDiskSource = fakeAuthDiskSource,
|
||||||
settingsDiskSource = fakeSettingsDiskSource,
|
settingsDiskSource = fakeSettingsDiskSource,
|
||||||
vaultDiskSource = vaultDiskSource,
|
vaultDiskSource = vaultDiskSource,
|
||||||
featureFlagManager = featureFlagManager,
|
featureFlagManager = featureFlagManager,
|
||||||
dispatcherManager = FakeDispatcherManager(),
|
dispatcherManager = FakeDispatcherManager(),
|
||||||
|
autofillEnabledManager = autofillEnabledManager,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Suppress("MaxLineLength")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
fun `allAutoFillSettingsBadgeCountFlow should emit the value of flags set to true and update when changed`() =
|
fun `allAutoFillSettingsBadgeCountFlow should emit the value of flags set to true and update when saved value is changed or autofill enabled state changes`() =
|
||||||
runTest {
|
runTest {
|
||||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||||
firstTimeActionManager.allAutofillSettingsBadgeCountFlow.test {
|
firstTimeActionManager.allAutofillSettingsBadgeCountFlow.test {
|
||||||
|
@ -62,6 +70,13 @@ class FirstTimeActionManagerTest {
|
||||||
showBadge = false,
|
showBadge = false,
|
||||||
)
|
)
|
||||||
assertEquals(0, awaitItem())
|
assertEquals(0, awaitItem())
|
||||||
|
fakeSettingsDiskSource.storeShowAutoFillSettingBadge(
|
||||||
|
userId = USER_ID,
|
||||||
|
showBadge = true,
|
||||||
|
)
|
||||||
|
assertEquals(1, awaitItem())
|
||||||
|
mutableAutofillEnabledFlow.update { true }
|
||||||
|
assertEquals(0, awaitItem())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,6 +255,46 @@ class FirstTimeActionManagerTest {
|
||||||
firstTimeActionManager.storeShowImportLoginsSettingsBadge(showBadge = false)
|
firstTimeActionManager.storeShowImportLoginsSettingsBadge(showBadge = false)
|
||||||
assertFalse(fakeSettingsDiskSource.getShowImportLoginsSettingBadge(userId = USER_ID)!!)
|
assertFalse(fakeSettingsDiskSource.getShowImportLoginsSettingBadge(userId = USER_ID)!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `show autofill badge when autofill is already enabled should be false`() {
|
||||||
|
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||||
|
every { autofillEnabledManager.isAutofillEnabled } returns true
|
||||||
|
assertFalse(firstTimeActionManager.currentOrDefaultUserFirstTimeState.showSetupAutofillCard)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `first time state flow should update when autofill is enabled`() = runTest {
|
||||||
|
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||||
|
|
||||||
|
firstTimeActionManager.firstTimeStateFlow.test {
|
||||||
|
assertEquals(
|
||||||
|
FirstTimeState(
|
||||||
|
showImportLoginsCard = true,
|
||||||
|
),
|
||||||
|
awaitItem(),
|
||||||
|
)
|
||||||
|
fakeSettingsDiskSource.storeShowAutoFillSettingBadge(
|
||||||
|
userId = MOCK_USER_STATE.activeUserId,
|
||||||
|
showBadge = true,
|
||||||
|
)
|
||||||
|
assertEquals(
|
||||||
|
FirstTimeState(
|
||||||
|
showImportLoginsCard = true,
|
||||||
|
showSetupAutofillCard = true,
|
||||||
|
),
|
||||||
|
awaitItem(),
|
||||||
|
)
|
||||||
|
mutableAutofillEnabledFlow.update { true }
|
||||||
|
assertEquals(
|
||||||
|
FirstTimeState(
|
||||||
|
showImportLoginsCard = true,
|
||||||
|
showSetupAutofillCard = false,
|
||||||
|
),
|
||||||
|
awaitItem(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val USER_ID: String = "userId"
|
private const val USER_ID: String = "userId"
|
||||||
|
|
Loading…
Reference in a new issue