mirror of https://github.com/M66B/FairEmail.git
Check if biometrics sensor available
This commit is contained in:
parent
0998f408b0
commit
ec87b383e8
|
@ -201,13 +201,14 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
}
|
||||
}));
|
||||
|
||||
menus.add(new NavMenuItem(R.drawable.baseline_fingerprint_24, R.string.title_setup_authentication, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawerLayout.closeDrawer(drawerContainer);
|
||||
onMenuBiometrics();
|
||||
}
|
||||
}));
|
||||
if (Helper.canAuthenticate(this))
|
||||
menus.add(new NavMenuItem(R.drawable.baseline_fingerprint_24, R.string.title_setup_authentication, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
drawerLayout.closeDrawer(drawerContainer);
|
||||
onMenuBiometrics();
|
||||
}
|
||||
}));
|
||||
|
||||
menus.add(new NavMenuItem(R.drawable.baseline_person_24, R.string.menu_contacts, new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -19,6 +19,7 @@ package eu.faircode.email;
|
|||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
|
@ -32,7 +33,10 @@ import android.content.res.TypedArray;
|
|||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Matrix;
|
||||
import android.hardware.biometrics.BiometricManager;
|
||||
import android.hardware.fingerprint.FingerprintManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Parcel;
|
||||
|
@ -653,6 +657,19 @@ public class Helper {
|
|||
return Objects.equals(signed, expected);
|
||||
}
|
||||
|
||||
static boolean canAuthenticate(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
return false;
|
||||
else if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) {
|
||||
FingerprintManager fpm = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
|
||||
return (fpm != null && fpm.isHardwareDetected() && fpm.hasEnrolledFingerprints());
|
||||
} else {
|
||||
@SuppressLint("WrongConstant")
|
||||
BiometricManager bm = (BiometricManager) context.getSystemService(Context.BIOMETRIC_SERVICE);
|
||||
return (bm != null && bm.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean hasAuthentication(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getBoolean("biometrics", false);
|
||||
|
|
Loading…
Reference in New Issue