mirror of
https://github.com/status-im/react-native-keychain.git
synced 2025-02-17 15:47:29 +00:00
Add Android support for getSupportedBiometryType
This commit is contained in:
parent
3247375911
commit
c3990b0c09
@ -133,6 +133,7 @@ Get what type of hardware biometry support the device has. Resolves to a `Keycha
|
||||
|-----|-------------|
|
||||
|**`TOUCH_ID`**|Device supports authentication with Touch ID.|
|
||||
|**`FACE_ID`**|Device supports authentication with Face ID.|
|
||||
|**`FINGERPRINT`**|Device supports authentication with Android Fingerprint.|
|
||||
|
||||
## Manual Installation
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.oblador.keychain">
|
||||
|
||||
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
|
||||
</manifest>
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.oblador.keychain;
|
||||
|
||||
import android.os.Build;
|
||||
import android.content.Context;
|
||||
import android.app.KeyguardManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
|
||||
public class DeviceAvailability {
|
||||
public static boolean isFingerprintAuthAvailable(Context context) {
|
||||
FingerprintManager fingerprintManager =
|
||||
(FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
|
||||
return android.os.Build.VERSION.SDK_INT >= 23 &&
|
||||
fingerprintManager.isHardwareDetected() &&
|
||||
fingerprintManager.hasEnrolledFingerprints();
|
||||
}
|
||||
|
||||
public static boolean isSecure(Context context) {
|
||||
KeyguardManager keyguardManager =
|
||||
(KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
|
||||
return android.os.Build.VERSION.SDK_INT >= 23 && keyguardManager.isDeviceSecure();
|
||||
}
|
||||
}
|
@ -20,6 +20,7 @@ import com.oblador.keychain.cipherStorage.CipherStorageKeystoreAESCBC;
|
||||
import com.oblador.keychain.exceptions.CryptoFailedException;
|
||||
import com.oblador.keychain.exceptions.EmptyParameterException;
|
||||
import com.oblador.keychain.exceptions.KeyStoreAccessException;
|
||||
import com.oblador.keychain.DeviceAvailability;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -29,7 +30,9 @@ public class KeychainModule extends ReactContextBaseJavaModule {
|
||||
public static final String E_EMPTY_PARAMETERS = "E_EMPTY_PARAMETERS";
|
||||
public static final String E_CRYPTO_FAILED = "E_CRYPTO_FAILED";
|
||||
public static final String E_KEYSTORE_ACCESS_ERROR = "E_KEYSTORE_ACCESS_ERROR";
|
||||
public static final String E_SUPPORTED_BIOMETRY_ERROR = "E_SUPPORTED_BIOMETRY_ERROR";
|
||||
public static final String KEYCHAIN_MODULE = "RNKeychainManager";
|
||||
public static final String FINGERPRINT_SUPPORTED_NAME = "Fingerprint";
|
||||
public static final String EMPTY_STRING = "";
|
||||
|
||||
private final Map<String, CipherStorage> cipherStorageMap = new HashMap<>();
|
||||
@ -161,6 +164,21 @@ public class KeychainModule extends ReactContextBaseJavaModule {
|
||||
resetGenericPasswordForOptions(server, promise);
|
||||
}
|
||||
|
||||
@ReactMethod
|
||||
public void getSupportedBiometryType(Promise promise) {
|
||||
try {
|
||||
boolean fingerprintAuthAvailable = isFingerprintAuthAvailable();
|
||||
if (fingerprintAuthAvailable) {
|
||||
promise.resolve(FINGERPRINT_SUPPORTED_NAME);
|
||||
} else {
|
||||
promise.resolve(null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(KEYCHAIN_MODULE, e.getMessage());
|
||||
promise.reject(E_SUPPORTED_BIOMETRY_ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
// The "Current" CipherStorage is the cipherStorage with the highest API level that is lower than or equal to the current API level
|
||||
private CipherStorage getCipherStorageForCurrentAPILevel() throws CryptoFailedException {
|
||||
int currentAPILevel = Build.VERSION.SDK_INT;
|
||||
@ -184,6 +202,10 @@ public class KeychainModule extends ReactContextBaseJavaModule {
|
||||
return cipherStorageMap.get(cipherStorageName);
|
||||
}
|
||||
|
||||
private boolean isFingerprintAuthAvailable() {
|
||||
return DeviceAvailability.isFingerprintAuthAvailable(getCurrentActivity());
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private String getDefaultServiceIfNull(String service) {
|
||||
return service == null ? EMPTY_STRING : service;
|
||||
|
Loading…
x
Reference in New Issue
Block a user