5

My application contains user authentication for login(includes pin/pattern, fingerprint unlock) which depends on device security. I am using Biometric manager to detect whether device has fingerprint support using BiometricManager and also checking whether device is secured using isDeviceSecure(). I am in need to detect in which mode mobile device is secured whether pin/pattern with, pin/pattern with fingerprint, pin/pattern with face unlock or all the three modes(pin/pattern, face unlock, fingerprint).

Zoe
  • 27,060
  • 21
  • 118
  • 148
Prasanth
  • 51
  • 6
  • maybe you will get an answer from here https://stackoverflow.com/questions/34409969/how-to-check-device-compatibility-for-finger-print-authentication-in-android – Priyanka Dec 28 '20 at 08:15
  • @Priyankagb The solution provided is to check whether fingerprint is enrolled or not. I need to check in which mode the device is secured. – Prasanth Dec 29 '20 at 15:03

1 Answers1

2

here is the code to detect what lock type is set

add lib to build.gradle

implementation 'androidx.biometric:biometric:1.0.0-beta01'

and this code to your activity

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
boolean keyguardSecure = keyguardManager.isKeyguardSecure();
Log.e("---", "checkSecurityTypes: keyguardLocked - " + keyguardSecure);//true = pin/pattern

int i = BiometricManager.from(this).canAuthenticate();
Log.e("---", "checkSecurityTypes: " + i);//true 0 = pin/pattern with finger print

switch (i) {
    case BiometricManager.BIOMETRIC_SUCCESS:
        Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
        Log.e("MY_APP_TAG", "No biometric features available on this device.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
        Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
        // Prompts the user to create credentials that your app accepts.
        break;
}

if (i == 0 && keyguardSecure) {
    //fingerprint is always with pin/pattern/password
    Log.e("---", "checkSecurityTypes: fingerprint is set with pin/pattern");
} else if (keyguardSecure) {
    //true if pin/pattern/password is set
    Log.e("---", "checkSecurityTypes: pin/pattern is set");
}

we can't detect face type. for more see this link

Priyanka
  • 3,369
  • 1
  • 10
  • 33
  • I have tested your solution its working but even the fingerprint is disabled for device security, I am receiving "i=0(BiometricManager.BIOMETRIC_SUCCESS)" in samsung galaxy device. As disabling fingerprint as device security, Fingerprint data not cleared from device(BiometricManager.BIOMETRIC_SUCCESS is triggered when using BiometricManager.from(this).canAuthenticate()). Also, I need the device current lock mode(pin/pattern, face unlock, fingerprint). – Prasanth Jan 04 '21 at 05:06
  • 1
    We can't get a specific lock type which one is currently set up. – Priyanka Jan 04 '21 at 05:41
  • I am having the scenario, If user disables fingerprint from the device security, App needs to detect it ask only other mode of authentication like pin/pattern instead of fingerprint using biometric prompt. – Prasanth Jan 04 '21 at 07:02
  • this method `createConfirmDeviceCredentialIntent()` from `KeyguardManager` might help you. try it and check what is returning. – Priyanka Jan 04 '21 at 07:23
  • No, Can't able to get the required information. – Prasanth Jan 06 '21 at 06:07