1
0
mirror of https://github.com/danog/termux-api.git synced 2024-11-30 04:19:20 +01:00

Update to BiometricManager

This commit is contained in:
Daniil Gentili 2020-09-30 19:50:03 +02:00
parent 67954de363
commit f9041daf6b
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
3 changed files with 15 additions and 39 deletions

View File

@ -1,12 +1,12 @@
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId "com.termux.api"
minSdkVersion 24
targetSdkVersion 28
targetSdkVersion 29
versionCode 44
versionName "0.44"
}
@ -38,9 +38,9 @@ android {
}
dependencies {
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.biometric:biometric:1.0.0-alpha04'
implementation "androidx.media:media:1.1.0"
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.biometric:biometric:1.0.1'
implementation "androidx.media:media:1.2.0"
}
task versionName {

View File

@ -12,8 +12,8 @@ import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricConstants;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.hardware.fingerprint.FingerprintManagerCompat;
import androidx.fragment.app.FragmentActivity;
import com.termux.api.util.ResultReturner;
@ -71,7 +71,7 @@ public class FingerprintAPI {
resetFingerprintResult();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
FingerprintManagerCompat fingerprintManagerCompat = FingerprintManagerCompat.from(context);
BiometricManager fingerprintManagerCompat = BiometricManager.from(context);
// make sure we have a valid fingerprint sensor before attempting to launch Fingerprint activity
if (validateFingerprintSensor(context, fingerprintManagerCompat)) {
Intent fingerprintIntent = new Intent(context, FingerprintActivity.class);
@ -120,16 +120,21 @@ public class FingerprintAPI {
* Ensure that we have a fingerprint sensor and that the user has already enrolled fingerprints
*/
@TargetApi(Build.VERSION_CODES.M)
protected static boolean validateFingerprintSensor(Context context, FingerprintManagerCompat fingerprintManagerCompat) {
protected static boolean validateFingerprintSensor(Context context, BiometricManager biometricManager) {
boolean result = true;
if (!fingerprintManagerCompat.isHardwareDetected()) {
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
Toast.makeText(context, "No fingerprint scanner found!", Toast.LENGTH_SHORT).show();
appendFingerprintError(ERROR_NO_HARDWARE);
result = false;
}
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE) {
Toast.makeText(context, "No fingerprint scanner available!", Toast.LENGTH_SHORT).show();
appendFingerprintError(ERROR_NO_HARDWARE);
result = false;
}
if (!fingerprintManagerCompat.hasEnrolledFingerprints()) {
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) {
Toast.makeText(context, "No fingerprints enrolled", Toast.LENGTH_SHORT).show();
appendFingerprintError(ERROR_NO_ENROLLED_FINGERPRINTS);
result = false;

View File

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:gravity="center"
android:layout_height="match_parent">
<TextView
android:id="@+id/grant_permission_description"
android:layout_marginLeft="32dp"
android:layout_marginRight="32dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="24dp"
android:text="@string/grant_permission"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onOkButton"/>
</LinearLayout>
</LinearLayout>