Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AND-6643 [Biometrics] Fixed a crash that occurred when checking biometrics availability #365

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ internal class AndroidAuthenticationManager(
.build()
}

private val biometricsStatus = MutableStateFlow(BiometricsStatus.UNINITIALIZED)
private val biometricsStatus = MutableStateFlow(BiometricsStatus.NOT_INITIALIZED)

override val canAuthenticate: Boolean
get() {
if (biometricsStatus.value == BiometricsStatus.UNAVAILABLE) {
if (biometricsStatus.value == BiometricsStatus.NOT_INITIALIZED) {
error("Biometrics status must be initialized before checking if biometrics can authenticate")
}

Expand All @@ -56,7 +56,7 @@ internal class AndroidAuthenticationManager(

override val needEnrollBiometrics: Boolean
get() {
if (biometricsStatus.value == BiometricsStatus.UNAVAILABLE) {
if (biometricsStatus.value == BiometricsStatus.NOT_INITIALIZED) {
error("Biometrics status must be initialized before checking if biometrics need to be enrolled")
}

Expand All @@ -74,7 +74,7 @@ internal class AndroidAuthenticationManager(
override fun onPause(owner: LifecycleOwner) {
Log.biometric { "Owner has been paused, biometrics was uninitialized" }

biometricsStatus.value = BiometricsStatus.UNINITIALIZED
biometricsStatus.value = BiometricsStatus.NOT_INITIALIZED
}

override suspend fun authenticate(
Expand Down Expand Up @@ -106,7 +106,7 @@ internal class AndroidAuthenticationManager(

throw TangemSdkError.AuthenticationUnavailable()
}
BiometricsStatus.UNINITIALIZED -> {
BiometricsStatus.NOT_INITIALIZED -> {
Log.biometric { "Awaiting for the biometrics status to be initialized" }

awaitBiometricsInititialization()
Expand Down Expand Up @@ -164,7 +164,7 @@ internal class AndroidAuthenticationManager(
)

private suspend fun awaitBiometricsInititialization() {
biometricsStatus.first { it != BiometricsStatus.UNINITIALIZED }
biometricsStatus.first { it != BiometricsStatus.NOT_INITIALIZED }
}

@Suppress("LongMethod")
Expand Down Expand Up @@ -258,7 +258,7 @@ internal class AndroidAuthenticationManager(
AUTHENTICATING,
UNAVAILABLE,
NEED_ENROLL,
UNINITIALIZED,
NOT_INITIALIZED,
}

private sealed interface BiometricAuthenticationResult {
Expand Down
6 changes: 3 additions & 3 deletions tangem-sdk-core/src/main/java/com/tangem/TangemSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1157,8 +1157,8 @@ class TangemSdk(
keystoreManager: KeystoreManager,
secureStorage: SecureStorage,
config: Config,
): UserCodeRepository? {
return if (authenticationManager.canAuthenticate &&
): UserCodeRepository? = runCatching {
if (authenticationManager.canAuthenticate &&
config.userCodeRequestPolicy is UserCodeRequestPolicy.AlwaysWithBiometrics
) {
UserCodeRepository(
Expand All @@ -1168,7 +1168,7 @@ class TangemSdk(
} else {
null
}
}
}.getOrNull()

private fun makeSession(
cardId: String? = null,
Expand Down
Loading