From 3c0cffa9601f2fe635a9078b43af9cfcb9924b40 Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Wed, 16 Nov 2022 09:24:44 +0100 Subject: [PATCH 1/9] More options --- .../rnbiometrics/ReactNativeBiometrics.java | 30 +++++++++++++++++-- index.ts | 24 ++++++++++----- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index 624ecd9..156ec90 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -54,13 +54,39 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { boolean allowDeviceCredentials = params.getBoolean("allowDeviceCredentials"); ReactApplicationContext reactApplicationContext = getReactApplicationContext(); BiometricManager biometricManager = BiometricManager.from(reactApplicationContext); - int canAuthenticate = biometricManager.canAuthenticate(getAllowedAuthenticators(allowDeviceCredentials)); + int canAuthenticate = biometricManager.canAuthenticate(getAllowedAuthenticators(false)); if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) { WritableMap resultMap = new WritableNativeMap(); resultMap.putBoolean("available", true); resultMap.putString("biometryType", "Biometrics"); promise.resolve(resultMap); + } else if (allowDeviceCredentials) { + int canAuthenticateCredentials = biometricManager.canAuthenticate(getAllowedAuthenticators(allowDeviceCredentials)); + + if (canAuthenticateCredentials == BiometricManager.BIOMETRIC_SUCCESS) { + WritableMap resultMap = new WritableNativeMap(); + resultMap.putBoolean("available", true); + resultMap.putString("biometryType", "Credentials"); + promise.resolve(resultMap); + } else { + WritableMap resultMap = new WritableNativeMap(); + resultMap.putBoolean("available", false); + + switch (canAuthenticateCredentials) { + case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: + resultMap.putString("error", "BIOMETRIC_ERROR_NO_HARDWARE"); + break; + case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE: + resultMap.putString("error", "BIOMETRIC_ERROR_HW_UNAVAILABLE"); + break; + case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: + resultMap.putString("error", "BIOMETRIC_ERROR_NONE_ENROLLED"); + break; + } + + promise.resolve(resultMap); + } } else { WritableMap resultMap = new WritableNativeMap(); resultMap.putBoolean("available", false); @@ -77,7 +103,7 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { break; } - promise.resolve(resultMap); + promise.resolve(resultMap); } } else { WritableMap resultMap = new WritableNativeMap(); diff --git a/index.ts b/index.ts index ef8f260..58a9cb6 100644 --- a/index.ts +++ b/index.ts @@ -5,12 +5,16 @@ const { ReactNativeBiometrics: bridge } = NativeModules /** * Type alias for possible biometry types */ -export type BiometryType = 'TouchID' | 'FaceID' | 'Biometrics' +export type BiometryType = 'TouchID' | 'FaceID' | 'Biometrics' | 'Credentials' interface RNBiometricsOptions { allowDeviceCredentials?: boolean } +interface isSensorAvailable { + allowDeviceCredentials?: boolean +} + interface IsSensorAvailableResult { available: boolean biometryType?: BiometryType @@ -45,6 +49,7 @@ interface SimplePromptOptions { promptMessage: string fallbackPromptMessage?: string cancelButtonText?: string + allowDeviceCredentials?: boolean } interface SimplePromptResult { @@ -64,20 +69,22 @@ export const FaceID = 'FaceID' * Enum for generic biometrics (this is the only value available on android) */ export const Biometrics = 'Biometrics' +export const Credentials = 'Credentials' export const BiometryTypes = { TouchID, FaceID, - Biometrics + Biometrics, + Credentials } export module ReactNativeBiometricsLegacy { /** - * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID + * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID | Credentials * @returns {Promise} Promise that resolves to an object with details about biometrics available */ - export function isSensorAvailable(): Promise { - return new ReactNativeBiometrics().isSensorAvailable() + export function isSensorAvailable(params: isSensorAvailable): Promise { + return new ReactNativeBiometrics().isSensorAvailable(params) } /** @@ -127,6 +134,7 @@ export module ReactNativeBiometricsLegacy { * @param {Object} simplePromptOptions * @param {string} simplePromptOptions.promptMessage * @param {string} simplePromptOptions.fallbackPromptMessage + * @param {boolean} simplePromptOptions.allowDeviceCredentials * @returns {Promise} Promise that resolves an object with details about the biometrics result */ export function simplePrompt(simplePromptOptions: SimplePromptOptions): Promise { @@ -150,9 +158,9 @@ export default class ReactNativeBiometrics { * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID * @returns {Promise} Promise that resolves to an object with details about biometrics available */ - isSensorAvailable(): Promise { + isSensorAvailable(params?: isSensorAvailable): Promise { return bridge.isSensorAvailable({ - allowDeviceCredentials: this.allowDeviceCredentials + allowDeviceCredentials: params?.allowDeviceCredentials ?? this.allowDeviceCredentials }) } @@ -217,7 +225,7 @@ export default class ReactNativeBiometrics { simplePromptOptions.fallbackPromptMessage = simplePromptOptions.fallbackPromptMessage ?? 'Use Passcode' return bridge.simplePrompt({ - allowDeviceCredentials: this.allowDeviceCredentials, + allowDeviceCredentials: simplePromptOptions.allowDeviceCredentials ?? this.allowDeviceCredentials, ...simplePromptOptions }) } From 7c376f90fecb2a623748a763fc67ee590120f714 Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Thu, 1 Dec 2022 09:39:18 +0100 Subject: [PATCH 2/9] Fetch enabled biometric feature from package --- .../rnbiometrics/ReactNativeBiometrics.java | 21 +++++++++++++++++++ index.ts | 14 ++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index 156ec90..ac3121e 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -1,5 +1,7 @@ package com.rnbiometrics; +import android.content.Context; +import android.content.pm.PackageManager; import android.os.Build; import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyProperties; @@ -54,12 +56,27 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { boolean allowDeviceCredentials = params.getBoolean("allowDeviceCredentials"); ReactApplicationContext reactApplicationContext = getReactApplicationContext(); BiometricManager biometricManager = BiometricManager.from(reactApplicationContext); + PackageManager packageManager = reactApplicationContext.getPackageManager(); int canAuthenticate = biometricManager.canAuthenticate(getAllowedAuthenticators(false)); if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) { WritableMap resultMap = new WritableNativeMap(); resultMap.putBoolean("available", true); resultMap.putString("biometryType", "Biometrics"); + + if (packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) == true) { + resultMap.putString("biometryType", "Fingerprint"); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if (packageManager.hasSystemFeature(PackageManager.FEATURE_FACE) == true) { + resultMap.putString("biometryType", "Face"); + } + if (packageManager.hasSystemFeature(PackageManager.FEATURE_IRIS) == true) { + resultMap.putString("biometryType", "Iris"); + } + } + promise.resolve(resultMap); } else if (allowDeviceCredentials) { int canAuthenticateCredentials = biometricManager.canAuthenticate(getAllowedAuthenticators(allowDeviceCredentials)); @@ -151,6 +168,10 @@ private boolean isCurrentSDKMarshmallowOrLater() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; } + private boolean isCurrentSDKSnowConeOrLater() { + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; + } + @ReactMethod public void deleteKeys(Promise promise) { if (doesBiometricKeyExist()) { diff --git a/index.ts b/index.ts index 58a9cb6..79c8eed 100644 --- a/index.ts +++ b/index.ts @@ -5,7 +5,9 @@ const { ReactNativeBiometrics: bridge } = NativeModules /** * Type alias for possible biometry types */ -export type BiometryType = 'TouchID' | 'FaceID' | 'Biometrics' | 'Credentials' +export type BiometryTypeIOS = 'TouchID' | 'FaceID' +export type BiometryTypeAndroid ='Fingerprint' | 'Face' | 'Iris'| 'Biometrics' | 'Credentials' +export type BiometryType = BiometryTypeIOS | BiometryTypeAndroid interface RNBiometricsOptions { allowDeviceCredentials?: boolean @@ -68,6 +70,9 @@ export const FaceID = 'FaceID' /** * Enum for generic biometrics (this is the only value available on android) */ +export const Fingerprint = 'Fingerprint' +export const Face = 'Face' +export const Iris = 'Iris' export const Biometrics = 'Biometrics' export const Credentials = 'Credentials' @@ -75,6 +80,9 @@ export const BiometryTypes = { TouchID, FaceID, Biometrics, + Fingerprint, + Face, + Iris, Credentials } @@ -83,7 +91,7 @@ export module ReactNativeBiometricsLegacy { * Returns promise that resolves to an object with object.biometryType = Biometrics | TouchID | FaceID | Credentials * @returns {Promise} Promise that resolves to an object with details about biometrics available */ - export function isSensorAvailable(params: isSensorAvailable): Promise { + export function isSensorAvailable(params: isSensorAvailable): Promise { return new ReactNativeBiometrics().isSensorAvailable(params) } @@ -225,7 +233,7 @@ export default class ReactNativeBiometrics { simplePromptOptions.fallbackPromptMessage = simplePromptOptions.fallbackPromptMessage ?? 'Use Passcode' return bridge.simplePrompt({ - allowDeviceCredentials: simplePromptOptions.allowDeviceCredentials ?? this.allowDeviceCredentials, + allowDeviceCredentials: simplePromptOptions.allowDeviceCredentials ?? this.allowDeviceCredentials, ...simplePromptOptions }) } From f5fe0c022b29153274f9f39be4c0fc7a68ad6b6e Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Thu, 1 Dec 2022 12:54:51 +0100 Subject: [PATCH 3/9] fix spaces --- .../src/main/java/com/rnbiometrics/ReactNativeBiometrics.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index ac3121e..6262553 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -67,7 +67,7 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { if (packageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT) == true) { resultMap.putString("biometryType", "Fingerprint"); } - + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { if (packageManager.hasSystemFeature(PackageManager.FEATURE_FACE) == true) { resultMap.putString("biometryType", "Face"); @@ -120,7 +120,7 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { break; } - promise.resolve(resultMap); + promise.resolve(resultMap); } } else { WritableMap resultMap = new WritableNativeMap(); From 856f0076baf72e5859eacea1d34af65d9810cec8 Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Mon, 5 Dec 2022 13:10:27 +0100 Subject: [PATCH 4/9] Update for iOS --- ios/ReactNativeBiometrics.m | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ios/ReactNativeBiometrics.m b/ios/ReactNativeBiometrics.m index 03ec388..8849bca 100644 --- a/ios/ReactNativeBiometrics.m +++ b/ios/ReactNativeBiometrics.m @@ -16,14 +16,10 @@ @implementation ReactNativeBiometrics RCT_EXPORT_METHOD(isSensorAvailable: (NSDictionary *)params resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { LAContext *context = [[LAContext alloc] init]; NSError *la_error = nil; + NSError *la_errorWithCredentials = nil; BOOL allowDeviceCredentials = [RCTConvert BOOL:params[@"allowDeviceCredentials"]]; - LAPolicy laPolicy = LAPolicyDeviceOwnerAuthenticationWithBiometrics; - if (allowDeviceCredentials == TRUE) { - laPolicy = LAPolicyDeviceOwnerAuthentication; - } - - BOOL canEvaluatePolicy = [context canEvaluatePolicy:laPolicy error:&la_error]; + BOOL canEvaluatePolicy = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&la_error]; if (canEvaluatePolicy) { NSString *biometryType = [self getBiometryType:context]; @@ -34,13 +30,23 @@ @implementation ReactNativeBiometrics resolve(result); } else { - NSString *errorMessage = [NSString stringWithFormat:@"%@", la_error]; - NSDictionary *result = @{ - @"available": @(NO), - @"error": errorMessage - }; + if (allowDeviceCredentials == TRUE) { + BOOL canEvaluatePolicy = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&la_errorWithCredentials]; + NSString *biometryType = [self getBiometryType:context]; + NSDictionary *result = @{ + @"available": @(YES), + @"biometryType": "Credentials" + }; - resolve(result); + resolve(result); + } else { + NSString *errorMessage = [NSString stringWithFormat:@"%@", la_error]; + NSDictionary *result = @{ + @"available": @(NO), + @"error": errorMessage + }; + + resolve(result); } } From 18089c3de3c55342c440b2f7365acad377f80e87 Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Mon, 5 Dec 2022 14:00:36 +0100 Subject: [PATCH 5/9] Fix issues --- ios/ReactNativeBiometrics.m | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ios/ReactNativeBiometrics.m b/ios/ReactNativeBiometrics.m index 8849bca..880337d 100644 --- a/ios/ReactNativeBiometrics.m +++ b/ios/ReactNativeBiometrics.m @@ -29,16 +29,24 @@ @implementation ReactNativeBiometrics }; resolve(result); - } else { - if (allowDeviceCredentials == TRUE) { - BOOL canEvaluatePolicy = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&la_errorWithCredentials]; - NSString *biometryType = [self getBiometryType:context]; - NSDictionary *result = @{ - @"available": @(YES), - @"biometryType": "Credentials" - }; + } else if (allowDeviceCredentials == TRUE) { + BOOL canEvaluatePolicyWithCredentials = [context canEvaluatePolicy:LAPolicyDeviceOwnerAuthentication error:&la_errorWithCredentials]; + if(canEvaluatePolicyWithCredentials == TRUE) { + NSDictionary *result = @{ + @"available": @(YES), + @"biometryType": @"Credentials" + }; - resolve(result); + resolve(result); + } else { + NSString *errorMessage = [NSString stringWithFormat:@"%@", la_errorWithCredentials]; + NSDictionary *result = @{ + @"available": @(NO), + @"error": errorMessage + }; + + resolve(result); + } } else { NSString *errorMessage = [NSString stringWithFormat:@"%@", la_error]; NSDictionary *result = @{ From 41fba98e3edaeffaa149c4235bbc04614b0f9ce1 Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Wed, 7 Dec 2022 14:33:02 +0100 Subject: [PATCH 6/9] Remove weak types Android --- .../main/java/com/rnbiometrics/ReactNativeBiometrics.java | 8 -------- index.ts | 8 ++------ 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index 6262553..c718a47 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -68,14 +68,6 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { resultMap.putString("biometryType", "Fingerprint"); } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - if (packageManager.hasSystemFeature(PackageManager.FEATURE_FACE) == true) { - resultMap.putString("biometryType", "Face"); - } - if (packageManager.hasSystemFeature(PackageManager.FEATURE_IRIS) == true) { - resultMap.putString("biometryType", "Iris"); - } - } promise.resolve(resultMap); } else if (allowDeviceCredentials) { diff --git a/index.ts b/index.ts index 79c8eed..2fd2f13 100644 --- a/index.ts +++ b/index.ts @@ -6,7 +6,7 @@ const { ReactNativeBiometrics: bridge } = NativeModules * Type alias for possible biometry types */ export type BiometryTypeIOS = 'TouchID' | 'FaceID' -export type BiometryTypeAndroid ='Fingerprint' | 'Face' | 'Iris'| 'Biometrics' | 'Credentials' +export type BiometryTypeAndroid ='Fingerprint' | 'Biometrics' | 'Credentials' export type BiometryType = BiometryTypeIOS | BiometryTypeAndroid interface RNBiometricsOptions { @@ -70,10 +70,8 @@ export const FaceID = 'FaceID' /** * Enum for generic biometrics (this is the only value available on android) */ -export const Fingerprint = 'Fingerprint' -export const Face = 'Face' -export const Iris = 'Iris' export const Biometrics = 'Biometrics' +export const Fingerprint = 'Fingerprint' export const Credentials = 'Credentials' export const BiometryTypes = { @@ -81,8 +79,6 @@ export const BiometryTypes = { FaceID, Biometrics, Fingerprint, - Face, - Iris, Credentials } From b8686431f0e5329538c154050212e11a7051ad58 Mon Sep 17 00:00:00 2001 From: jensdev Date: Thu, 15 Dec 2022 11:26:40 +0100 Subject: [PATCH 7/9] Update android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java Co-authored-by: Tyler Cook --- .../src/main/java/com/rnbiometrics/ReactNativeBiometrics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index c718a47..4952684 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -71,7 +71,7 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { promise.resolve(resultMap); } else if (allowDeviceCredentials) { - int canAuthenticateCredentials = biometricManager.canAuthenticate(getAllowedAuthenticators(allowDeviceCredentials)); + int canAuthenticateCredentials = biometricManager.canAuthenticate(getAllowedAuthenticators(true)); if (canAuthenticateCredentials == BiometricManager.BIOMETRIC_SUCCESS) { WritableMap resultMap = new WritableNativeMap(); From e4ec33dd3cae62463c72739c19d38c3140a3c7ce Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Thu, 15 Dec 2022 11:27:05 +0100 Subject: [PATCH 8/9] Remove isCurrentSDKSnowConeOrLater --- .../src/main/java/com/rnbiometrics/ReactNativeBiometrics.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index c718a47..f170f45 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -160,10 +160,6 @@ private boolean isCurrentSDKMarshmallowOrLater() { return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M; } - private boolean isCurrentSDKSnowConeOrLater() { - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; - } - @ReactMethod public void deleteKeys(Promise promise) { if (doesBiometricKeyExist()) { From 4c8e12c89664ddbf84993c364aa97ea27aafc44b Mon Sep 17 00:00:00 2001 From: Jens Verbeken Date: Thu, 15 Dec 2022 12:07:16 +0100 Subject: [PATCH 9/9] Refactor error message --- .../rnbiometrics/ReactNativeBiometrics.java | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java index aa6ad0a..8164b49 100644 --- a/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java +++ b/android/src/main/java/com/rnbiometrics/ReactNativeBiometrics.java @@ -68,7 +68,6 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { resultMap.putString("biometryType", "Fingerprint"); } - promise.resolve(resultMap); } else if (allowDeviceCredentials) { int canAuthenticateCredentials = biometricManager.canAuthenticate(getAllowedAuthenticators(true)); @@ -77,40 +76,19 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { WritableMap resultMap = new WritableNativeMap(); resultMap.putBoolean("available", true); resultMap.putString("biometryType", "Credentials"); + promise.resolve(resultMap); } else { WritableMap resultMap = new WritableNativeMap(); resultMap.putBoolean("available", false); - - switch (canAuthenticateCredentials) { - case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: - resultMap.putString("error", "BIOMETRIC_ERROR_NO_HARDWARE"); - break; - case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE: - resultMap.putString("error", "BIOMETRIC_ERROR_HW_UNAVAILABLE"); - break; - case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: - resultMap.putString("error", "BIOMETRIC_ERROR_NONE_ENROLLED"); - break; - } + resultMap.putString("error", parseError(canAuthenticateCredentials)); promise.resolve(resultMap); } } else { WritableMap resultMap = new WritableNativeMap(); resultMap.putBoolean("available", false); - - switch (canAuthenticate) { - case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: - resultMap.putString("error", "BIOMETRIC_ERROR_NO_HARDWARE"); - break; - case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE: - resultMap.putString("error", "BIOMETRIC_ERROR_HW_UNAVAILABLE"); - break; - case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: - resultMap.putString("error", "BIOMETRIC_ERROR_NONE_ENROLLED"); - break; - } + resultMap.putString("error", parseError(canAuthenticate)); promise.resolve(resultMap); } @@ -121,10 +99,29 @@ public void isSensorAvailable(final ReadableMap params, final Promise promise) { promise.resolve(resultMap); } } catch (Exception e) { - promise.reject("Error detecting biometrics availability: " + e.getMessage(), "Error detecting biometrics availability: " + e.getMessage()); + promise.reject("Error detecting biometrics availability: " + e.getMessage(), + "Error detecting biometrics availability: " + e.getMessage()); } } + private String parseError(final int authenticationResult) { + String message = ""; + + switch (authenticationResult) { + case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE: + message = "BIOMETRIC_ERROR_NO_HARDWARE"; + break; + case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE: + message = "BIOMETRIC_ERROR_HW_UNAVAILABLE"; + break; + case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED: + message = "BIOMETRIC_ERROR_NONE_ENROLLED"; + break; + } + + return message; + } + @ReactMethod public void createKeys(final ReadableMap params, Promise promise) { try {