android - 检查指纹是否已在三星手机中注册时出现 SecurityException

标签 android lockscreen securityexception android-fingerprint-api

我在我的应用程序中使用带指纹的锁屏。虽然它可以与其他具有指纹传感器的手机无缝协作,但三星用户正面临一些 SecurityException,正如我在我的谷歌控制台报告中看到的那样。报告如下:

java.lang.RuntimeException: 

at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3319)

at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:3415)

at android.app.ActivityThread.access$1100 (ActivityThread.java:229)

at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1821)

at android.os.Handler.dispatchMessage (Handler.java:102)

at android.os.Looper.loop (Looper.java:148)

 at android.app.ActivityThread.main (ActivityThread.java:7406)

at java.lang.reflect.Method.invoke (Native Method)

at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)

at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)

Caused by: java.lang.SecurityException: 

at android.os.Parcel.readException (Parcel.java:1621)

at android.os.Parcel.readException (Parcel.java:1574)

at android.hardware.fingerprint.IFingerprintService$Stub$Proxy.hasEnrolledFingerprints (IFingerprintService.java:503)

at android.hardware.fingerprint.FingerprintManager.hasEnrolledFingerprints (FingerprintManager.java:776)

at com.example.ark.access.LockScreen.setUpFingerPrint (LockScreen.java:252)

at com.example.ark.access.LockScreen.onCreate (LockScreen.java:67)

at android.app.Activity.performCreate (Activity.java:6904)

at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1136)

at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:3266)

这是我的文件中检查指纹的部分:

    private void setUpFingerPrint(ImageView white,ImageView black)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        //Get an instance of KeyguardManager and FingerprintManager//
        KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
        FingerprintManager fingerprintManager = (FingerprintManager) getSystemService(FINGERPRINT_SERVICE);


        //Check whether the device has a fingerprint sensor//
        if (!fingerprintManager.isHardwareDetected()) {
            // If a fingerprint sensor isn’t available, then inform the user that they’ll be unable to use your app’s fingerprint functionality//
            //Toast.makeText(this, R.string.noFingerPrint, Toast.LENGTH_SHORT).show();
            white.setVisibility(View.GONE);
            black.setVisibility(View.GONE);
        }
        //Check whether the user has granted your app the USE_FINGERPRINT permission//
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.USE_FINGERPRINT) != PackageManager.PERMISSION_GRANTED) {
            // If your app doesn't have this permission, then display the following text//
            Toast.makeText(this, R.string.noFingerPrintPermission, Toast.LENGTH_SHORT).show();
        }

        //Check that the user has registered at least one fingerprint//
        if (!fingerprintManager.hasEnrolledFingerprints()) {
            // If the user hasn’t configured any fingerprints, then display the following message//
            Toast.makeText(this, R.string.noFingerPrintRegistered, Toast.LENGTH_SHORT).show();
        }

        //Check that the lockscreen is secured//
        if (!keyguardManager.isKeyguardSecure()) {
            // If the user hasn’t secured their lockscreen with a PIN password or pattern, then display the following text//
            Toast.makeText(this, R.string.lockScreenNotConfigured, Toast.LENGTH_SHORT).show();
        }
        else {
            try {
                generateKey();
            } catch (FingerprintException e) {
                e.printStackTrace();
            }

            if (initCipher()) {
                //If the cipher is initialized successfully, then create a CryptoObject instance//
                FingerprintManager.CryptoObject cryptoObject = new FingerprintManager.CryptoObject(cipher);

                // Here, I’m referencing the FingerprintHandler class that we’ll create in the next section. This class will be responsible
                // for starting the authentication process (via the startAuth method) and processing the authentication process events//
                int k = getIntent().getIntExtra("Mode", 0);
                FingerprintHandler helper = new FingerprintHandler(this,k,white,black);
                helper.startAuth(fingerprintManager, cryptoObject);
            }
        }
    }
    else
    {
        white.setVisibility(View.GONE);
        black.setVisibility(View.GONE);
    }
}

第 252 行是检查 fingerprintmanager.hasEnrolledFingerprints()

我很难搞清楚,因为我没有三星手机可以测试。到目前为止,它已经发生在 Galaxy J7 和 Grand Prime Plus 中。

最佳答案

不确定您是否曾经为此找到解决方案,作为一种解决方法,我只是将我们的调用包装在权限检查中。

inline val Activity.fingerprintManager: FingerprintManagerCompat?
  get() = (
    if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.USE_FINGERPRINT) == PackageManager.PERMISSION_GRANTED) {
      FingerprintManagerCompat.from(this)
    } else { null }
  )

关于android - 检查指纹是否已在三星手机中注册时出现 SecurityException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48542621/

相关文章:

android - 安全警报: Your app contains embedded private keys or keystore files

android - 可绘制的图像但仍然出现错误

android - 防止状态栏扩展

android - 如何在 RecycleViewer 中更改 Canvas?

android - 区分 RemoteControlClient 和 Headset

ios - iOS中基于位置的锁屏应用程序建议是自动生成的吗?

Android:java.lang.SecurityException:权限拒绝:启动 Intent

android - 拦截语音识别

javascript - 在单页上应用 Touch Swipe,用于动态加载数据的页面?