Skip to content

Commit

Permalink
AND-6182 [Biometrics] Improved AuthenticationManager
Browse files Browse the repository at this point in the history
  • Loading branch information
iiiburnyiii committed Feb 29, 2024
1 parent 2aff144 commit 8ebad3c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -194,6 +199,8 @@ internal class AndroidAuthenticationManager(
Log.warning {
"""
$TAG - Biometric authentication error
|- Code: $errorCode
|- Message: $errString
|- Cause: $error
""".trimIndent()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

0 comments on commit 8ebad3c

Please # to comment.