Skip to content

Commit

Permalink
Merge pull request #16 from icerockdev/#13-android-cancel-biometric-d…
Browse files Browse the repository at this point in the history
…ialog-fix

#13 fix handling of android biometric dialog cancelling
  • Loading branch information
Alex009 authored Apr 11, 2023
2 parents 8e5fd0d + b86e9de commit 622136c
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 407 deletions.
17 changes: 0 additions & 17 deletions biometry-build-logic/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions biometry-build-logic/src/main/kotlin/detekt-convention.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

17 changes: 7 additions & 10 deletions biometry/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
*/

plugins {
id("multiplatform-library-convention")
id("kotlin-parcelize")
id("dev.icerock.mobile.multiplatform.android-manifest")
id("publication-convention")
id("dev.icerock.moko.gradle.multiplatform.mobile")
id("dev.icerock.moko.gradle.publication")
id("dev.icerock.moko.gradle.stub.javadoc")
id("dev.icerock.moko.gradle.detekt")
}

group = "dev.icerock.moko"
version = libs.versions.mokoBiometryVersion.get()

dependencies {
"androidMainImplementation"(libs.appCompat)
"androidMainImplementation"(libs.biometric)
androidMainImplementation(libs.appCompat)
androidMainImplementation(libs.biometric)

commonMainImplementation(libs.mokoResources)
commonMainApi(libs.mokoResources)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package dev.icerock.moko.biometry

import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.os.Build
import androidx.biometric.BiometricConstants
Expand Down Expand Up @@ -45,11 +46,11 @@ actual class BiometryAuthenticator actual constructor() {

actual suspend fun checkBiometryAuthentication(
requestReason: StringDesc,
failureButtonText: StringDesc): Boolean {
failureButtonText: StringDesc
): Boolean {

val fragmentManager =
fragmentManager
?: throw IllegalStateException("can't check biometry without active window")
val fragmentManager = fragmentManager
?: error("can't check biometry without active window")

val currentFragment: Fragment? = fragmentManager.findFragmentByTag(BIOMETRY_RESOLVER_FRAGMENT_TAG)
val resolverFragment: ResolverFragment = if (currentFragment != null) {
Expand Down Expand Up @@ -89,7 +90,7 @@ actual class BiometryAuthenticator actual constructor() {
return false
}
return _packageManager?.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
?: throw IllegalStateException("can't check touch id enabled without packageManager")
?: error("can't check touch id enabled without packageManager")
}

/**
Expand Down Expand Up @@ -132,26 +133,27 @@ actual class BiometryAuthenticator actual constructor() {

biometricPrompt = BiometricPrompt(this, executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int,
errString: CharSequence) {
@SuppressLint("RestrictedApi")
override fun onAuthenticationError(
errorCode: Int,
errString: CharSequence
) {
super.onAuthenticationError(errorCode, errString)
if (errorCode == BiometricConstants.ERROR_NEGATIVE_BUTTON) {
callback.invoke(Result.failure(Exception(errorCode.toString())))
if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON ||
errorCode == BiometricPrompt.ERROR_USER_CANCELED
) {
callback.invoke(Result.success(false))
} else {
callback.invoke(Result.failure(Exception(errString.toString())))
}
}

override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult) {
result: BiometricPrompt.AuthenticationResult
) {
super.onAuthenticationSucceeded(result)
callback.invoke(Result.success(true))
}

override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
callback.invoke(Result.success(false))
}
}
)

Expand All @@ -173,5 +175,4 @@ actual class BiometryAuthenticator actual constructor() {
companion object {
private const val BIOMETRY_RESOLVER_FRAGMENT_TAG = "BiometryControllerResolver"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ expect class BiometryAuthenticator() {
* Performs user authentication using biometrics-fingerprint/face scan-returns the result of the scan
*
* @param requestReason - Text describing the reason for confirmation via biometrics
* @param failureButtonText - Text of the button to go to the backup verification method in case of unsuccessful biometrics recognition
* @param failureButtonText - Text of the button to go to the backup verification method in
* case of unsuccessful biometrics recognition
*
* @throws Exception if authentication failed
*
Expand Down
Loading

0 comments on commit 622136c

Please sign in to comment.