Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if new finger was added?

I have an app with fingerprint authentication. It has been working fine till Android 8 was released. So the problem is that when I enroll new fingerprints there is no KeyPermanentlyInvalidatedException. So it happens only on Android 8, lower API's are fine with that and I can check if new fingerprint was added by this exception. How could I check new fingerprint in Android 8? Google sample App - FingerprintDialog - also has same problem. It does not see changes in enrolling new fingerprint. Opened google issue: https://issuetracker.google.com/issues/65578763

like image 931
Vlad Melnikov Avatar asked Sep 12 '17 17:09

Vlad Melnikov


1 Answers

i got good news. i finally cracked it.

I can get all finger id in integers.

private void getFingerprintInfo(Context context) 
{
    try {
        FingerprintManager fingerprintManager = (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
        Method method = FingerprintManager.class.getDeclaredMethod("getEnrolledFingerprints");
        Object obj = method.invoke(fingerprintManager);

        if (obj != null) {
            Class<?> clazz = Class.forName("android.hardware.fingerprint.Fingerprint");
            Method getFingerId = clazz.getDeclaredMethod("getFingerId");

            for (int i = 0; i < ((List) obj).size(); i++)
            {
                Object item = ((List) obj).get(i);
                if(item != null)
                {
                    System.out.println("fkie4. fingerId: " + getFingerId.invoke(item));
                }
            }
        }
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | ClassNotFoundException e) {
        e.printStackTrace();
    }
}

please refer to this: https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/hardware/fingerprint/Fingerprint.java

there is a public method getFingerId( ), but it is not available for us to call because it has "@UnsupportedAppUsage".

so you need to use reflection to call the method. after you get a list of fingerprint id, you can encrypt them and store in sharedPreference.

Finger id is the id of the fingerprints stored in setting

After you get all finger ids, you can determine if user has added/deleted a fingerprint.

No need to count on the KeyPermanentlyInvalidatedException. It is not thrown in Android 8.0

Good luck!!!...

don't believe google did such a poor job

like image 143
Frankie Mak Avatar answered Oct 08 '22 20:10

Frankie Mak