Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

AND-6265 Add biometric logging level #356

Merged
merged 1 commit into from
Mar 4, 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 @@ -64,10 +64,12 @@ internal class AndroidAuthenticationManager(
override suspend fun authenticate() {
if (authenticationMutex.isLocked) {
Log.warning { "$TAG - A user authentication has already been launched" }
Log.biometric { "A user authentication has already been launched" }
}

authenticationMutex.withLock {
Log.debug { "$TAG - Trying to authenticate a user" }
Log.biometric { "Try to authenticate a user" }

val canAuthenticate = canAuthenticateInternal.filterNotNull().first()
if (canAuthenticate) {
Expand All @@ -76,6 +78,7 @@ internal class AndroidAuthenticationManager(
}
} else {
Log.warning { "$TAG - Unable to authenticate the user as the biometrics feature is unavailable" }
Log.biometric { "Unable to authenticate the user as the biometrics feature is unavailable" }

throw TangemSdkError.AuthenticationUnavailable()
}
Expand Down Expand Up @@ -110,6 +113,7 @@ internal class AndroidAuthenticationManager(
when (biometricManager.canAuthenticate(AUTHENTICATORS)) {
SystemBiometricManager.BIOMETRIC_SUCCESS -> {
Log.debug { "$TAG - Biometric features are available" }
Log.biometric { "Biometric features are available" }
continuation.resume(
BiometricsAvailability(
available = true,
Expand All @@ -120,6 +124,7 @@ internal class AndroidAuthenticationManager(

SystemBiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
Log.debug { "$TAG - No biometric features enrolled" }
Log.biometric { "No biometric features enrolled" }
continuation.resume(
BiometricsAvailability(
available = false,
Expand All @@ -129,6 +134,7 @@ internal class AndroidAuthenticationManager(
}
SystemBiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> {
Log.debug { "$TAG - No biometric features available on this device" }
Log.biometric { "No biometric features available on this device" }
continuation.resume(
BiometricsAvailability(
available = false,
Expand All @@ -138,6 +144,7 @@ internal class AndroidAuthenticationManager(
}
SystemBiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE -> {
Log.debug { "$TAG - Biometric features are currently unavailable" }
Log.biometric { "Biometric features are currently unavailable" }
continuation.resume(
BiometricsAvailability(
available = false,
Expand All @@ -147,6 +154,7 @@ internal class AndroidAuthenticationManager(
}
SystemBiometricManager.BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED -> {
Log.debug { "$TAG - Biometric features are currently unavailable, security update required" }
Log.biometric { "Biometric features are currently unavailable, security update required" }
continuation.resume(
BiometricsAvailability(
available = false,
Expand All @@ -156,6 +164,7 @@ internal class AndroidAuthenticationManager(
}
SystemBiometricManager.BIOMETRIC_STATUS_UNKNOWN -> {
Log.debug { "$TAG - Biometric features are in unknown status" }
Log.biometric { "Biometric features are in unknown status" }
continuation.resume(
BiometricsAvailability(
available = false,
Expand All @@ -165,6 +174,7 @@ internal class AndroidAuthenticationManager(
}
SystemBiometricManager.BIOMETRIC_ERROR_UNSUPPORTED -> {
Log.debug { "$TAG - Biometric features are unsupported" }
Log.biometric { "Biometric features are unsupported" }
continuation.resume(
BiometricsAvailability(
available = false,
Expand Down Expand Up @@ -197,17 +207,20 @@ internal class AndroidAuthenticationManager(
|- Cause: $error
""".trimIndent()
}
Log.biometric { "Biometric authentication error:\n$error" }

result(BiometricAuthenticationResult.Failure(error))
}

override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
Log.debug { "$TAG - Biometric authentication succeed" }
Log.biometric { "Biometric authentication succeed" }
result(BiometricAuthenticationResult.Success(result))
}

override fun onAuthenticationFailed() {
Log.warning { "$TAG - Biometric authentication failed" }
Log.biometric { "Biometric authentication failed" }
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions tangem-sdk-core/src/main/java/com/tangem/Log.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ object Log {
logInternal(message, Level.Info)
}

fun biometric(message: () -> String) {
logInternal(message, Level.Biometric)
}

private fun logInternal(message: () -> String, level: Level) {
if (loggers.isEmpty()) return

Expand Down Expand Up @@ -92,6 +96,7 @@ object Log {
Apdu(""),
Nfc("NFCReader: "),
Tlv(""),
Biometric("Biometric: "),
}

enum class Config(val levels: List<Level>) {
Expand Down
Loading