Skip to content

Commit

Permalink
Merge pull request #365 from tangem/bugfix/AND-6643_fix_biometric_crash
Browse files Browse the repository at this point in the history
AND-6643 [Biometrics] Fixed a crash that occurred when checking biometrics availability
  • Loading branch information
iiiburnyiii authored Apr 3, 2024
2 parents 217eb96 + 4dc97b0 commit 1757709
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
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

0 comments on commit 1757709

Please # to comment.