Modern Apps git

← Modern-Apps.git

library: handle biometric success without a cipher

Commit
b8a7e3f2443cdd40c09f305eb9117ce79f981812
Author
Vayun Mathur <[email protected]>
When
2026-11-19 01:54 UTC (17 days ago)
Parents
02cec4e
unlockDatabaseWithBiometrics force-unwrapped
result.cryptoObject?.cipher in onAuthenticationSucceeded.
Success via device credential can deliver no CryptoObject on
some devices, so the unlock path crashed with an NPE exactly
where the module contract says to handle the locked-out path
gracefully. A missing cipher now reports failure through
onFailure instead.

Verified: ./gradlew :library:biometric:testDebugUnitTest and
./check library/biometric pass.

Diff

library/biometric/src/main/java/com/vayunmathur/library/biometric/BiometricDatabaseHelper.kt
diff --git a/library/biometric/src/main/java/com/vayunmathur/library/biometric/BiometricDatabaseHelper.kt b/library/biometric/src/main/java/com/vayunmathur/library/biometric/BiometricDatabaseHelper.ktindex 78b354b992..16aac3241e 100644--- a/library/biometric/src/main/java/com/vayunmathur/library/biometric/BiometricDatabaseHelper.kt+++ b/library/biometric/src/main/java/com/vayunmathur/library/biometric/BiometricDatabaseHelper.kt@@ -72,7 +72,14 @@ fun unlockDatabaseWithBiometrics(     fun prompt(title: String, subtitle: String, cipher: Cipher, onCipher: (Cipher) -> String) {         val biometricPrompt = BiometricPrompt(activity, executor, object : BiometricPrompt.AuthenticationCallback() {             override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {-                onSuccess(onCipher(result.cryptoObject?.cipher!!))+                // Device-credential success can deliver no CryptoObject on some+                // devices; fail gracefully instead of crashing on a force-unwrap.+                val cipher = result.cryptoObject?.cipher+                if (cipher == null) {+                    onFailure("Device authentication didn't unlock the secure folder.")+                    return+                }+                onSuccess(onCipher(cipher))             }              override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {