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

[local-authentication] added supported authentication type estimate with package manager #8431

Merged
merged 6 commits into from May 22, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/expo-local-authentication/CHANGELOG.md
Expand Up @@ -9,3 +9,5 @@
- Added support for `promptMessage`, `cancelLabel` and `disableDeviceFallback` on Android. ([#8219](https://github.com/expo/expo/pull/8219) by [@diegolmello](https://github.com/diegolmello))

### 🐛 Bug fixes

- Added estimate of supported authentication types for Android ([#8431](https://github.com/expo/expo/pull/8431) by [@bycedric](https://github.com/bycedric))
byCedric marked this conversation as resolved.
Show resolved Hide resolved
Expand Up @@ -5,6 +5,7 @@
import android.app.Activity;
import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import androidx.core.os.CancellationSignal;
Expand All @@ -28,13 +29,15 @@

public class LocalAuthenticationModule extends ExportedModule {
private final BiometricManager mBiometricManager;
private final PackageManager mPackageManager;
private CancellationSignal mCancellationSignal;
private Promise mPromise;
private boolean mIsAuthenticating = false;
private ModuleRegistry mModuleRegistry;
private UIManager mUIManager;

private static final int AUTHENTICATION_TYPE_FINGERPRINT = 1;
private static final int AUTHENTICATION_TYPE_FACIAL_RECOGNITION = 2;

private final BiometricPrompt.AuthenticationCallback mAuthenticationCallback =
new BiometricPrompt.AuthenticationCallback () {
Expand All @@ -61,6 +64,7 @@ public LocalAuthenticationModule(Context context) {
super(context);

mBiometricManager = BiometricManager.from(context);
mPackageManager = context.getPackageManager();
}

@Override
Expand All @@ -78,9 +82,16 @@ public void onCreate(ModuleRegistry moduleRegistry) {
public void supportedAuthenticationTypesAsync(final Promise promise) {
int result = mBiometricManager.canAuthenticate();
List<Integer> results = new ArrayList<>();
if (result != BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
if (result == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
promise.resolve(results);
return;
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
results.add(AUTHENTICATION_TYPE_FINGERPRINT);
}
if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)) {
results.add(AUTHENTICATION_TYPE_FACIAL_RECOGNITION);
}
promise.resolve(results);
}

Expand Down