Browse Source

Pin : clean remaining pin code attempts

pull/1642/head
ganfra 11 months ago
parent
commit
3c5bff0927
  1. 6
      features/lockscreen/impl/src/main/kotlin/io/element/android/features/lockscreen/impl/pin/storage/PreferencesPinCodeStore.kt

6
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 { override suspend fun getRemainingPinCodeAttemptsNumber(): Int {
return context.dataStore.data.map { preferences -> return context.dataStore.data.map { preferences ->
preferences[remainingAttemptsKey] ?: 0 preferences.getRemainingPinCodeAttemptsNumber()
}.first() }.first()
} }
override suspend fun onWrongPin() { override suspend fun onWrongPin() {
context.dataStore.edit { preferences -> context.dataStore.edit { preferences ->
val current = preferences[remainingAttemptsKey] ?: 0 val current = preferences.getRemainingPinCodeAttemptsNumber()
val remaining = (current - 1).coerceAtLeast(0) val remaining = (current - 1).coerceAtLeast(0)
preferences[remainingAttemptsKey] = remaining preferences[remainingAttemptsKey] = remaining
} }
@ -86,4 +86,6 @@ class PreferencesPinCodeStore @Inject constructor(
preferences[pinCodeKey] != null preferences[pinCodeKey] != null
}.first() }.first()
} }
private fun Preferences.getRemainingPinCodeAttemptsNumber() = this[remainingAttemptsKey] ?: LockScreenConfig.MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT
} }

Loading…
Cancel
Save