From 3c5bff092721f2fda16e05bf917a38e604938295 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 25 Oct 2023 16:54:34 +0200 Subject: [PATCH] Pin : clean remaining pin code attempts --- .../lockscreen/impl/pin/storage/PreferencesPinCodeStore.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/storage/PreferencesPinCodeStore.kt b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/storage/PreferencesPinCodeStore.kt index 2bf9225a2c..04f849e117 100644 --- a/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/storage/PreferencesPinCodeStore.kt +++ b/features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/storage/PreferencesPinCodeStore.kt @@ -45,13 +45,13 @@ class PreferencesPinCodeStore @Inject constructor( override suspend fun getRemainingPinCodeAttemptsNumber(): Int { return context.dataStore.data.map { preferences -> - preferences[remainingAttemptsKey] ?: 0 + preferences.getRemainingPinCodeAttemptsNumber() }.first() } override suspend fun onWrongPin() { context.dataStore.edit { preferences -> - val current = preferences[remainingAttemptsKey] ?: 0 + val current = preferences.getRemainingPinCodeAttemptsNumber() val remaining = (current - 1).coerceAtLeast(0) preferences[remainingAttemptsKey] = remaining } @@ -86,4 +86,6 @@ class PreferencesPinCodeStore @Inject constructor( preferences[pinCodeKey] != null }.first() } + + private fun Preferences.getRemainingPinCodeAttemptsNumber() = this[remainingAttemptsKey] ?: LockScreenConfig.MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT }