Browse Source

fix fingerprint issue (#22)

V1.2.0-release
JunZhang 5 years ago
committed by GitHub
parent
commit
d840941a99
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      app/src/main/java/com/cobo/cold/Utilities.java
  2. 7
      app/src/main/java/com/cobo/cold/fingerprint/FingerprintKit.java
  3. 30
      app/src/main/java/com/cobo/cold/ui/fragment/setting/MainPreferenceFragment.java

4
app/src/main/java/com/cobo/cold/Utilities.java

@ -213,8 +213,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) {

7
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);
}
}
}

30
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;
@ -62,6 +63,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;
@ -347,20 +349,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<Fingerprint> 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<Fingerprint> fingerprints = fpKit.getEnrolledFingerprints();
fingerprints.forEach(f -> {
fpKit.removeFingerprint(f, null);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
}
}

Loading…
Cancel
Save