From 1b2029725f5819ff2109c96daa6d9162b4cb22e8 Mon Sep 17 00:00:00 2001 From: JunZhang Date: Thu, 4 Jun 2020 10:19:01 +0800 Subject: [PATCH] fix fingerprint issue (#23) --- .../main/java/com/cobo/cold/Utilities.java | 4 +-- .../cobo/cold/fingerprint/FingerprintKit.java | 7 +++-- .../setting/MainPreferenceFragment.java | 30 ++++++++++--------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/com/cobo/cold/Utilities.java b/app/src/main/java/com/cobo/cold/Utilities.java index dede7c3..de22877 100644 --- a/app/src/main/java/com/cobo/cold/Utilities.java +++ b/app/src/main/java/com/cobo/cold/Utilities.java @@ -201,8 +201,8 @@ public class Utilities { return Settings.System.getString(context.getContentResolver(), FINGERPRINT_PASSWORD); } - public static void setFingerprintPassword(Context context, String pwd) { - Settings.System.putString(context.getContentResolver(), FINGERPRINT_PASSWORD, pwd); + public static boolean setFingerprintPassword(Context context, String pwd) { + return Settings.System.putString(context.getContentResolver(), FINGERPRINT_PASSWORD, pwd); } public static void setAttackDetected(Context context) { diff --git a/app/src/main/java/com/cobo/cold/fingerprint/FingerprintKit.java b/app/src/main/java/com/cobo/cold/fingerprint/FingerprintKit.java index 4e7f9fc..a12f68f 100644 --- a/app/src/main/java/com/cobo/cold/fingerprint/FingerprintKit.java +++ b/app/src/main/java/com/cobo/cold/fingerprint/FingerprintKit.java @@ -66,9 +66,10 @@ public class FingerprintKit { fp = (FingerprintManager) mContext.getSystemService(FINGERPRINT_SERVICE); if (!lockPatternUtils.isLockPasswordEnabled(mUserId)) { String password = HashUtil.generateRandomPassword(20); - lockPatternUtils.saveLockPassword(password, null, - DevicePolicyManager.PASSWORD_QUALITY_NUMERIC, mUserId); - Utilities.setFingerprintPassword(mContext, password); + if (Utilities.setFingerprintPassword(mContext, password)) { + lockPatternUtils.saveLockPassword(password, null, + DevicePolicyManager.PASSWORD_QUALITY_NUMERIC, mUserId); + } } } diff --git a/app/src/main/java/com/cobo/cold/ui/fragment/setting/MainPreferenceFragment.java b/app/src/main/java/com/cobo/cold/ui/fragment/setting/MainPreferenceFragment.java index 061a519..e5ae82e 100644 --- a/app/src/main/java/com/cobo/cold/ui/fragment/setting/MainPreferenceFragment.java +++ b/app/src/main/java/com/cobo/cold/ui/fragment/setting/MainPreferenceFragment.java @@ -23,6 +23,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.graphics.Color; import android.hardware.fingerprint.Fingerprint; +import android.hardware.fingerprint.FingerprintManager; import android.os.Bundle; import android.os.Looper; import android.view.Gravity; @@ -64,6 +65,7 @@ import java.util.Locale; import java.util.Objects; import java.util.concurrent.Executors; +import static android.content.Context.FINGERPRINT_SERVICE; import static com.cobo.cold.Utilities.IS_SETUP_VAULT; import static com.cobo.cold.Utilities.SHARED_PREFERENCES_KEY; import static com.cobo.cold.ui.fragment.Constants.KEY_NAV_ID; @@ -361,20 +363,20 @@ public class MainPreferenceFragment extends PreferenceFragmentCompat { } public static void removeAllFingerprint(AppCompatActivity activity) { - if (!FingerprintKit.isHardwareDetected(activity)) { - return; - } - FingerprintKit fpKit = new FingerprintKit(activity); - if (FingerprintKit.isHardwareDetected(activity)) { - List fingerprints = fpKit.getEnrolledFingerprints(); - fingerprints.forEach(f -> { - fpKit.removeFingerprint(f, null); - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - }); + FingerprintManager fm = (FingerprintManager) activity.getSystemService(FINGERPRINT_SERVICE); + if (fm.isHardwareDetected() && fm.hasEnrolledFingerprints()) { + FingerprintKit fpKit = new FingerprintKit(activity); + if (FingerprintKit.isHardwareDetected(activity)) { + List fingerprints = fpKit.getEnrolledFingerprints(); + fingerprints.forEach(f -> { + fpKit.removeFingerprint(f, null); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }); + } } }