[PM-10622] Handle the skip unlock step in the onboarding, storing when the user selects to do so. (#3928)

This commit is contained in:
Dave Severns 2024-09-20 15:25:01 -04:00 committed by GitHub
parent 8fe637d207
commit 05d6c2f61e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 108 additions and 3 deletions

View file

@ -270,4 +270,16 @@ interface SettingsDiskSource {
* enable autofill in onboarding.
*/
fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean?)
/**
* Gets whether or not the given [userId] has signalled they want to enable unlock options
* later, during onboarding.
*/
fun getShowUnlockSettingBadge(userId: String): Boolean?
/**
* Stores the given value for whether or not the given [userId] has signalled they want to
* set up unlock options later, during onboarding.
*/
fun storeShowUnlockSettingBadge(userId: String, showBadge: Boolean?)
}

View file

@ -34,6 +34,7 @@ private const val CLEAR_CLIPBOARD_INTERVAL_KEY = "clearClipboard"
private const val INITIAL_AUTOFILL_DIALOG_SHOWN = "addSitePromptShown"
private const val HAS_USER_LOGGED_IN_OR_CREATED_AN_ACCOUNT_KEY = "hasUserLoggedInOrCreatedAccount"
private const val SHOW_AUTOFILL_SETTING_BADGE = "showAutofillSettingBadge"
private const val SHOW_UNLOCK_SETTING_BADGE = "showUnlockSettingBadge"
/**
* Primary implementation of [SettingsDiskSource].
@ -407,4 +408,15 @@ class SettingsDiskSourceImpl(
key = SHOW_AUTOFILL_SETTING_BADGE.appendIdentifier(userId),
value = showBadge,
)
override fun getShowUnlockSettingBadge(userId: String): Boolean? =
getBoolean(
key = SHOW_UNLOCK_SETTING_BADGE.appendIdentifier(userId),
)
override fun storeShowUnlockSettingBadge(userId: String, showBadge: Boolean?) =
putBoolean(
key = SHOW_UNLOCK_SETTING_BADGE.appendIdentifier(userId),
value = showBadge,
)
}

View file

@ -256,14 +256,26 @@ interface SettingsRepository {
fun storeUserHasLoggedInValue(userId: String)
/**
* Gets whether or not the given [userId] has signalled they want to enable autofill in
* onboarding.
* Gets whether or not the given [userId] has signalled they want to enable autofill
* later, during onboarding.
*/
fun getShowAutoFillSettingBadge(userId: String): Boolean
/**
* Stores the given value for whether or not the given [userId] has signalled they want to
* enable autofill in onboarding.
* enable autofill later, during onboarding.
*/
fun storeShowAutoFillSettingBadge(userId: String, showBadge: Boolean)
/**
* Gets whether or not the given [userId] has signalled they want to enable unlock options
* later, during onboarding.
*/
fun getShowUnlockSettingBadge(userId: String): Boolean
/**
* Stores the given value for whether or not the given [userId] has signalled they want to
* set up unlock options later, during onboarding.
*/
fun storeShowUnlockSettingBadge(userId: String, showBadge: Boolean)
}

View file

@ -545,6 +545,13 @@ class SettingsRepositoryImpl(
settingsDiskSource.storeShowAutoFillSettingBadge(userId, showBadge)
}
override fun getShowUnlockSettingBadge(userId: String): Boolean =
settingsDiskSource.getShowUnlockSettingBadge(userId) ?: false
override fun storeShowUnlockSettingBadge(userId: String, showBadge: Boolean) {
settingsDiskSource.storeShowUnlockSettingBadge(userId, showBadge)
}
/**
* If there isn't already one generated, generate a symmetric sync key that would be used
* for communicating via IPC.

View file

@ -95,6 +95,7 @@ class SetupUnlockViewModel @Inject constructor(
}
private fun handleSetUpLaterClick() {
settingsRepository.storeShowUnlockSettingBadge(state.userId, true)
updateOnboardingStatusToNextStep()
}

View file

@ -1053,4 +1053,28 @@ class SettingsDiskSourceTest {
assertTrue(settingsDiskSource.getShowAutoFillSettingBadge(userId = mockUserId)!!)
}
@Test
fun `storeShowUnlockSettingBadge should update SharedPreferences`() {
val mockUserId = "mockUserId"
val showUnlockSettingBadgeKey =
"bwPreferencesStorage:showUnlockSettingBadge_$mockUserId"
settingsDiskSource.storeShowUnlockSettingBadge(
userId = mockUserId,
showBadge = true,
)
assertTrue(fakeSharedPreferences.getBoolean(showUnlockSettingBadgeKey, false))
}
@Test
fun `getShowUnlockSettingBadge should pull value from shared preferences`() {
val mockUserId = "mockUserId"
val showUnlockSettingBadgeKey =
"bwPreferencesStorage:showUnlockSettingBadge_$mockUserId"
fakeSharedPreferences.edit {
putBoolean(showUnlockSettingBadgeKey, true)
}
assertTrue(settingsDiskSource.getShowUnlockSettingBadge(userId = mockUserId)!!)
}
}

View file

@ -62,6 +62,7 @@ class FakeSettingsDiskSource : SettingsDiskSource {
private val storedAccountBiometricIntegrityValidity = mutableMapOf<String, Boolean?>()
private val userSignIns = mutableMapOf<String, Boolean>()
private val userShowAutoFillBadge = mutableMapOf<String, Boolean?>()
private val userShowUnlockBadge = mutableMapOf<String, Boolean?>()
override var appLanguage: AppLanguage? = null
@ -292,6 +293,13 @@ class FakeSettingsDiskSource : SettingsDiskSource {
userShowAutoFillBadge[userId] = showBadge
}
override fun getShowUnlockSettingBadge(userId: String): Boolean? =
userShowUnlockBadge[userId]
override fun storeShowUnlockSettingBadge(userId: String, showBadge: Boolean?) {
userShowUnlockBadge[userId] = showBadge
}
private fun getMutableScreenCaptureAllowedFlow(userId: String): MutableSharedFlow<Boolean?> {
return mutableScreenCaptureAllowedFlowMap.getOrPut(userId) {
bufferedMutableSharedFlow(replay = 1)

View file

@ -1175,6 +1175,33 @@ class SettingsRepositoryTest {
fakeSettingsDiskSource.storeShowAutoFillSettingBadge(userId = userId, showBadge = true)
assertTrue(settingsRepository.getShowAutoFillSettingBadge(userId = userId))
}
@Test
fun `storeShowUnlockSettingBadge should store value of false to disk`() {
val userId = "userId"
settingsRepository.storeShowUnlockSettingBadge(userId = userId, showBadge = false)
assertFalse(fakeSettingsDiskSource.getShowUnlockSettingBadge(userId = userId)!!)
}
@Test
fun `storeShowUnlockSettingBadge should store value of true to disk`() {
val userId = "userId"
settingsRepository.storeShowUnlockSettingBadge(userId = userId, showBadge = true)
assertTrue(fakeSettingsDiskSource.getShowUnlockSettingBadge(userId = userId)!!)
}
@Test
fun `getUnlockSettingBadge get value of false if does not exist`() {
val userId = "userId"
assertFalse(settingsRepository.getShowUnlockSettingBadge(userId = userId))
}
@Test
fun `getShowUnlockSettingBadge should return the value saved to disk`() {
val userId = "userId"
fakeSettingsDiskSource.storeShowUnlockSettingBadge(userId = userId, showBadge = true)
assertTrue(settingsRepository.getShowUnlockSettingBadge(userId = userId))
}
}
private const val USER_ID: String = "userId"

View file

@ -40,6 +40,7 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
every { isUnlockWithPinEnabled } returns false
every { isUnlockWithBiometricsEnabled } returns false
every { isAutofillEnabledStateFlow } returns mutableAutofillEnabledStateFlow
every { storeShowUnlockSettingBadge(any(), any()) } just runs
}
private val biometricsEncryptionManager: BiometricsEncryptionManager = mockk {
every { getOrCreateCipher(userId = DEFAULT_USER_ID) } returns CIPHER
@ -80,6 +81,7 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
userId = DEFAULT_USER_ID,
status = OnboardingStatus.AUTOFILL_SETUP,
)
settingsRepository.storeShowUnlockSettingBadge(DEFAULT_USER_ID, true)
}
}