diff --git a/tangem-sdk-android/src/main/java/com/tangem/sdk/authentication/AndroidAuthenticationManager.kt b/tangem-sdk-android/src/main/java/com/tangem/sdk/authentication/AndroidAuthenticationManager.kt index e22a2a17..a6e3c511 100644 --- a/tangem-sdk-android/src/main/java/com/tangem/sdk/authentication/AndroidAuthenticationManager.kt +++ b/tangem-sdk-android/src/main/java/com/tangem/sdk/authentication/AndroidAuthenticationManager.kt @@ -5,6 +5,7 @@ import androidx.annotation.RequiresApi import androidx.biometric.BiometricPrompt import androidx.fragment.app.FragmentActivity import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import com.tangem.Log @@ -29,7 +30,8 @@ import androidx.biometric.BiometricManager as SystemBiometricManager internal class AndroidAuthenticationManager( private val activity: FragmentActivity, ) : AuthenticationManager, - DefaultLifecycleObserver { + DefaultLifecycleObserver, + LifecycleOwner by activity { private val biometricPromptInfo by lazy { BiometricPrompt.PromptInfo.Builder() @@ -62,8 +64,11 @@ internal class AndroidAuthenticationManager( } override suspend fun authenticate() { + if (lifecycle.currentState != Lifecycle.State.RESUMED) return + if (authenticationMutex.isLocked) { Log.warning { "$TAG - A user authentication has already been launched" } + return } authenticationMutex.withLock { @@ -194,6 +199,8 @@ internal class AndroidAuthenticationManager( Log.warning { """ $TAG - Biometric authentication error + |- Code: $errorCode + |- Message: $errString |- Cause: $error """.trimIndent() } diff --git a/tangem-sdk-core/src/main/java/com/tangem/common/authentication/AuthenticationManager.kt b/tangem-sdk-core/src/main/java/com/tangem/common/authentication/AuthenticationManager.kt index b6c4f412..b45b9eac 100644 --- a/tangem-sdk-core/src/main/java/com/tangem/common/authentication/AuthenticationManager.kt +++ b/tangem-sdk-core/src/main/java/com/tangem/common/authentication/AuthenticationManager.kt @@ -24,6 +24,8 @@ interface AuthenticationManager { * this might trigger biometric prompts or other authentication mechanisms. * * @throws TangemSdkError.AuthenticationUnavailable if authentication is unavailable. + * @throws TangemSdkError.UserCanceledAuthentication if the user cancels the authentication process. + * @throws TangemSdkError.AuthenticationFailed if authentication fails for any other reason. */ suspend fun authenticate() }