Android 连续多次按下后退按钮后,createConfirmDeviceCredentialIntent是否将解锁?

Android 连续多次按下后退按钮后,createConfirmDeviceCredentialIntent是否将解锁?,android,fingerprint,Android,Fingerprint,我最近在我的一个应用程序中实现了指纹认证。除了我在测试时发现的一个问题外,其他一切都正常工作。一些背景:我生成了一个具有以下密钥生成器参数的密钥: KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT) .setBlockModes(KeyProperties.BLOCK_MODE_CBC) .setUserAuthenticationRequir

我最近在我的一个应用程序中实现了指纹认证。除了我在测试时发现的一个问题外,其他一切都正常工作。一些背景:我生成了一个具有以下密钥生成器参数的密钥:

KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
                    .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
                    .setUserAuthenticationRequired(true)
                    .setUserAuthenticationValidityDurationSeconds(80)
                    .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
因此,用户将在80秒内保持身份验证。每当应用程序需要重新验证用户时,它都会检查密钥是否仍然有效,否则
createConfirmDeviceCredentialIntent
如果密钥超时,则会弹出一个系统屏幕,提示用户验证指纹或输入密码/pin/模式

问题:现在这个屏幕应该是不可取消的,但是如果我连续多次点击后退按钮或上箭头按钮,用户就会进入应用程序。有人有过这种经历吗

编辑: 这似乎只发生在我测试过的三星设备上,它在Nexus和Google Pixel上运行良好。 下面是正在使用的代码,它来自使用createConfirmDeviceCredentialIntent的Google示例项目。 这是检查密钥是否仍然有效的方法

 protected boolean tryEncrypt() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            try {
                mKeyStore = KeyStore.getInstance("AndroidKeyStore");
                mKeyStore.load(null);
                SecretKey secretKey = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
                mCipher = Cipher.getInstance(
                        KeyProperties.KEY_ALGORITHM_AES + "/" + KeyProperties.BLOCK_MODE_CBC + "/"
                                + KeyProperties.ENCRYPTION_PADDING_PKCS7);
                mCipher.init(Cipher.ENCRYPT_MODE, secretKey);
                mCipher.doFinal(SECRET_BYTE_ARRAY);
                return true;
            } catch (UserNotAuthenticatedException e) {
                // User is not authenticated, let's authenticate with device credentials.
                showAuthenticationScreen();
                return false;
            } catch (KeyPermanentlyInvalidatedException e) {
                return false;
            } catch (BadPaddingException | IllegalBlockSizeException | KeyStoreException |
                    CertificateException | UnrecoverableKeyException | IOException
                    | NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException e) {
                throw new RuntimeException(e);
            }
        }
        return false;
    }
以下是在密钥超时时调用的showEncryption方法:

  protected void showAuthenticationScreen() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            Intent intent = getKeyguardManager().createConfirmDeviceCredentialIntent(null, null);
            if (intent != null) {
                startActivityForResult(intent, 1);
            }
        }
    }

请共享代码,当您在应用程序中检查身份验证时,请检查上面的“我的编辑”