Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5ab03d2c authored by Reema Bajwa's avatar Reema Bajwa
Browse files

Pass crypto object to biometric prompt

Bug: 333596088
Test: Built & deployed locally

Change-Id: Idd93ffbfd5531d85eff680f728062910fc7da369
parent 4487bc7f
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context
import android.graphics.Bitmap
import android.hardware.biometrics.BiometricManager
import android.hardware.biometrics.BiometricPrompt
import android.hardware.biometrics.CryptoObject
import android.os.CancellationSignal
import android.util.Log
import androidx.core.content.ContextCompat.getMainExecutor
@@ -220,13 +221,24 @@ private fun runBiometricFlow(
    val executor = getMainExecutor(context)

    try {
        val cryptoOpId = getCryptoOpId(biometricDisplayInfo)
        if (cryptoOpId != null) {
            biometricPrompt.authenticate(
                    BiometricPrompt.CryptoObject(cryptoOpId.toLong()),
                    cancellationSignal, executor, callback)
        } else {
            biometricPrompt.authenticate(cancellationSignal, executor, callback)
        }
    } catch (e: IllegalArgumentException) {
        Log.w(TAG, "Calling the biometric prompt API failed with: /n${e.localizedMessage}\n")
        onBiometricFailureFallback(biometricFlowType)
    }
}

private fun getCryptoOpId(biometricDisplayInfo: BiometricDisplayInfo): Int? {
    return biometricDisplayInfo.biometricRequestInfo.opId
}

/**
 * Sets up the biometric prompt with the UI specific bits.
 * // TODO(b/333445112) : Pass in opId once dependency is confirmed via CryptoObject