【问题标题】:Detect device is secured with pin lock or fingerprint lock of face lock?检测设备是用针锁或面部锁的指纹锁保护的吗?
【发布时间】:2021-04-05 01:07:38
【问题描述】:

我的应用程序包含用于登录的用户身份验证(包括密码/图案、指纹解锁),这取决于设备安全性。我正在使用生物识别管理器来检测设备是否使用 BiometricManager 支持指纹,并使用 isDeviceSecure() 检查设备是否受到保护。我需要检测移动设备在哪种模式下受到保护,无论是针/图案、带指纹的针/图案、带面部解锁的针/图案还是所有三种模式(针/图案、面部解锁、指纹)。

【问题讨论】:

标签: android android-fingerprint-api android-biometric-prompt android-biometric


【解决方案1】:

这是检测设置的锁类型的代码

将库添加到build.gradle

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

将此代码添加到您的活动中

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

我们无法检测面部类型。更多请看link

【讨论】:

  • 我已经测试了您的解决方案的工作原理,但为了设备安全,甚至禁用了指纹,我在三星 Galaxy 设备中收到“i=0(BiometricManager.BIOMETRIC_SUCCESS)”。由于设备安全性禁用指纹,指纹数据不会从设备中清除(使用 BiometricManager.from(this).canAuthenticate() 时会触发 BiometricManager.BIOMETRIC_SUCCESS)。另外,我需要设备当前的锁定模式(pin/pattern、面部解锁、指纹)。
  • 我们无法获得当前设置的特定锁类型。
  • 我遇到这种情况,如果用户从设备安全中禁用指纹,应用程序需要检测到它只询问其他身份验证模式,如 pin/pattern,而不是使用生物识别提示的指纹。
  • 来自KeyguardManager 的这种方法createConfirmDeviceCredentialIntent() 可能会对您有所帮助。尝试一下并检查返回的内容。
  • 否,无法获取所需信息。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 1970-01-01
  • 2018-08-03
  • 1970-01-01
  • 2013-12-21
相关资源
最近更新 更多