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

android: remove legacy support #241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 0 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,4 @@ dependencies {
implementation 'com.facebook.react:react-native:+'
// androidx:biometric now supports fingerprint back to Android v23
implementation "androidx.biometric:biometric:1.1.0"

// retain fingerprintScanner lib for compat with Android v16-23 device-specific drivers (Samsung & MeiZu)
// 1.2.3 is the minimum version compatible with androidx.
// See https://github.com/uccmawei/FingerprintIdentify/issues/74
// (translation https://translate.google.com/translate?sl=zh-CN&tl=en&u=https://github.com/uccmawei/FingerprintIdentify/issues/74)
implementation "com.github.uccmawei:fingerprintidentify:${safeExtGet("fingerprintidentify", "1.2.6")}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.bridge.UiThreadUtil;

// for Samsung/MeiZu compat, Android v16-23
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
import com.wei.android.lib.fingerprintidentify.FingerprintIdentify;
import com.wei.android.lib.fingerprintidentify.base.BaseFingerprint.ExceptionListener;
import com.wei.android.lib.fingerprintidentify.base.BaseFingerprint.IdentifyListener;


@ReactModule(name="ReactNativeFingerprintScanner")
public class ReactNativeFingerprintScannerModule
extends ReactContextBaseJavaModule
Expand All @@ -39,9 +32,6 @@ public class ReactNativeFingerprintScannerModule
private final ReactApplicationContext mReactContext;
private BiometricPrompt biometricPrompt;

// for Samsung/MeiZu compat, Android v16-23
private FingerprintIdentify mFingerprintIdentify;

public ReactNativeFingerprintScannerModule(ReactApplicationContext reactContext) {
super(reactContext);
mReactContext = reactContext;
Expand Down Expand Up @@ -194,8 +184,10 @@ private String getSensorError() {

@ReactMethod
public void authenticate(String title, String subtitle, String description, String cancelButton, final Promise promise) {
if (requiresLegacyAuthentication()) {
legacyAuthenticate(promise);
if (false) {
promise.reject("legacy not supported", TYPE_BIOMETRICS);
ReactNativeFingerprintScannerModule.this.release();
return;
}
else {
final String errorName = getSensorError();
Expand All @@ -211,11 +203,6 @@ public void authenticate(String title, String subtitle, String description, Stri

@ReactMethod
public synchronized void release() {
if (requiresLegacyAuthentication()) {
getFingerprintIdentify().cancelIdentify();
mFingerprintIdentify = null;
}

// consistent across legacy and current API
if (biometricPrompt != null) {
biometricPrompt.cancelAuthentication(); // if release called from eg React
Expand All @@ -226,16 +213,6 @@ public synchronized void release() {

@ReactMethod
public void isSensorAvailable(final Promise promise) {
if (requiresLegacyAuthentication()) {
String errorMessage = legacyGetErrorMessage();
if (errorMessage != null) {
promise.reject(errorMessage, TYPE_FINGERPRINT_LEGACY);
} else {
promise.resolve(TYPE_FINGERPRINT_LEGACY);
}
return;
}

// current API
String errorName = getSensorError();
if (errorName != null) {
Expand All @@ -244,83 +221,4 @@ public void isSensorAvailable(final Promise promise) {
promise.resolve(TYPE_BIOMETRICS);
}
}


// for Samsung/MeiZu compat, Android v16-23
private FingerprintIdentify getFingerprintIdentify() {
if (mFingerprintIdentify != null) {
return mFingerprintIdentify;
}
mReactContext.addLifecycleEventListener(this);
mFingerprintIdentify = new FingerprintIdentify(mReactContext);
mFingerprintIdentify.setSupportAndroidL(true);
mFingerprintIdentify.setExceptionListener(
new ExceptionListener() {
@Override
public void onCatchException(Throwable exception) {
mReactContext.removeLifecycleEventListener(ReactNativeFingerprintScannerModule.this);
}
}
);
mFingerprintIdentify.init();
return mFingerprintIdentify;
}

private String legacyGetErrorMessage() {
if (!getFingerprintIdentify().isHardwareEnable()) {
return "FingerprintScannerNotSupported";
} else if (!getFingerprintIdentify().isRegisteredFingerprint()) {
return "FingerprintScannerNotEnrolled";
} else if (!getFingerprintIdentify().isFingerprintEnable()) {
return "FingerprintScannerNotAvailable";
}

return null;
}


private void legacyAuthenticate(final Promise promise) {
final String errorMessage = legacyGetErrorMessage();
if (errorMessage != null) {
promise.reject(errorMessage, TYPE_FINGERPRINT_LEGACY);
ReactNativeFingerprintScannerModule.this.release();
return;
}

getFingerprintIdentify().resumeIdentify();
getFingerprintIdentify().startIdentify(MAX_AVAILABLE_TIMES, new IdentifyListener() {
@Override
public void onSucceed() {
promise.resolve(true);
}

@Override
public void onNotMatch(int availableTimes) {
if (availableTimes <= 0) {
mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "DeviceLocked");

} else {
mReactContext.getJSModule(RCTDeviceEventEmitter.class)
.emit("FINGERPRINT_SCANNER_AUTHENTICATION", "AuthenticationNotMatch");
}
}

@Override
public void onFailed(boolean isDeviceLocked) {
if(isDeviceLocked){
promise.reject("AuthenticationFailed", "DeviceLocked");
} else {
promise.reject("AuthenticationFailed", TYPE_FINGERPRINT_LEGACY);
}
ReactNativeFingerprintScannerModule.this.release();
}

@Override
public void onStartFailedByDeviceLocked() {
// the first start failed because the device was locked temporarily
promise.reject("AuthenticationFailed", "DeviceLocked");
}
});
}
}