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

Commit 3266711a authored by Shaquille Johnson's avatar Shaquille Johnson
Browse files

biometric: Add nullable to api for crypto

The javadocs mention that the functions getMac(), getKeyAgreement,
getCipher() can return nullable but this isn't show in the API.
Updating these to reflect that

Bug: 304697130
Test: atest FrameworksCoreTests
Change-Id: Icda5a087775174517abca7b4d1078a6ea0719170
parent 0c175e28
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -18375,12 +18375,12 @@ package android.hardware.biometrics {
    ctor @Deprecated public BiometricPrompt.CryptoObject(@NonNull android.security.identity.IdentityCredential);
    ctor public BiometricPrompt.CryptoObject(@NonNull android.security.identity.PresentationSession);
    ctor @FlaggedApi("android.hardware.biometrics.add_key_agreement_crypto_object") public BiometricPrompt.CryptoObject(@NonNull javax.crypto.KeyAgreement);
    method public javax.crypto.Cipher getCipher();
    method @Nullable public javax.crypto.Cipher getCipher();
    method @Deprecated @Nullable public android.security.identity.IdentityCredential getIdentityCredential();
    method @FlaggedApi("android.hardware.biometrics.add_key_agreement_crypto_object") @Nullable public javax.crypto.KeyAgreement getKeyAgreement();
    method public javax.crypto.Mac getMac();
    method @Nullable public javax.crypto.Mac getMac();
    method @Nullable public android.security.identity.PresentationSession getPresentationSession();
    method public java.security.Signature getSignature();
    method @Nullable public java.security.Signature getSignature();
  }
}
+3 −3
Original line number Diff line number Diff line
@@ -786,7 +786,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
         * Get {@link Signature} object.
         * @return {@link Signature} object or null if this doesn't contain one.
         */
        public Signature getSignature() {
        public @Nullable Signature getSignature() {
            return super.getSignature();
        }

@@ -794,7 +794,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
         * Get {@link Cipher} object.
         * @return {@link Cipher} object or null if this doesn't contain one.
         */
        public Cipher getCipher() {
        public @Nullable Cipher getCipher() {
            return super.getCipher();
        }

@@ -802,7 +802,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
         * Get {@link Mac} object.
         * @return {@link Mac} object or null if this doesn't contain one.
         */
        public Mac getMac() {
        public @Nullable Mac getMac() {
            return super.getMac();
        }

+36 −8
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.hardware.biometrics.Flags.FLAG_ADD_KEY_AGREEMENT_CRYPTO_OB

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.security.identity.IdentityCredential;
import android.security.identity.PresentationSession;
import android.security.keystore2.AndroidKeyStoreProvider;
@@ -33,20 +34,35 @@ import javax.crypto.Mac;
/**
 * A wrapper class for the crypto objects supported by BiometricPrompt and FingerprintManager.
 * Currently the framework supports {@link Signature}, {@link Cipher}, {@link Mac},
 * {@link IdentityCredential}, and {@link PresentationSession} objects.
 * {@link KeyAgreement}, {@link IdentityCredential}, and {@link PresentationSession} objects.
 * @hide
 */
public class CryptoObject {
    private final Object mCrypto;

    /**
     * Create from a {@link Signature} object.
     *
     * @param signature a {@link Signature} object.
     */
    public CryptoObject(@NonNull Signature signature) {
        mCrypto = signature;
    }

    /**
     * Create from a {@link Cipher} object.
     *
     * @param cipher a {@link Cipher} object.
     */
    public CryptoObject(@NonNull Cipher cipher) {
        mCrypto = cipher;
    }

    /**
     * Create from a {@link Mac} object.
     *
     * @param mac a {@link Mac} object.
     */
    public CryptoObject(@NonNull Mac mac) {
        mCrypto = mac;
    }
@@ -62,10 +78,20 @@ public class CryptoObject {
        mCrypto = credential;
    }

    /**
     * Create from a {@link PresentationSession} object.
     *
     * @param session a {@link PresentationSession} object.
     */
    public CryptoObject(@NonNull PresentationSession session) {
        mCrypto = session;
    }

    /**
     * Create from a {@link KeyAgreement} object.
     *
     * @param keyAgreement a {@link KeyAgreement} object.
     */
    @FlaggedApi(FLAG_ADD_KEY_AGREEMENT_CRYPTO_OBJECT)
    public CryptoObject(@NonNull KeyAgreement keyAgreement) {
        mCrypto = keyAgreement;
@@ -75,7 +101,7 @@ public class CryptoObject {
     * Get {@link Signature} object.
     * @return {@link Signature} object or null if this doesn't contain one.
     */
    public Signature getSignature() {
    public @Nullable Signature getSignature() {
        return mCrypto instanceof Signature ? (Signature) mCrypto : null;
    }

@@ -83,7 +109,7 @@ public class CryptoObject {
     * Get {@link Cipher} object.
     * @return {@link Cipher} object or null if this doesn't contain one.
     */
    public Cipher getCipher() {
    public @Nullable Cipher getCipher() {
        return mCrypto instanceof Cipher ? (Cipher) mCrypto : null;
    }

@@ -91,7 +117,7 @@ public class CryptoObject {
     * Get {@link Mac} object.
     * @return {@link Mac} object or null if this doesn't contain one.
     */
    public Mac getMac() {
    public @Nullable Mac getMac() {
        return mCrypto instanceof Mac ? (Mac) mCrypto : null;
    }

@@ -101,7 +127,7 @@ public class CryptoObject {
     * @deprecated Use {@link PresentationSession} instead of {@link IdentityCredential}.
     */
    @Deprecated
    public IdentityCredential getIdentityCredential() {
    public @Nullable IdentityCredential getIdentityCredential() {
        return mCrypto instanceof IdentityCredential ? (IdentityCredential) mCrypto : null;
    }

@@ -109,16 +135,18 @@ public class CryptoObject {
     * Get {@link PresentationSession} object.
     * @return {@link PresentationSession} object or null if this doesn't contain one.
     */
    public PresentationSession getPresentationSession() {
    public @Nullable PresentationSession getPresentationSession() {
        return mCrypto instanceof PresentationSession ? (PresentationSession) mCrypto : null;
    }

    /**
     * Get {@link KeyAgreement} object.
     * Get {@link KeyAgreement} object. A key-agreement protocol is a protocol whereby
     * two or more parties can agree on a shared secret using public key cryptography.
     *
     * @return {@link KeyAgreement} object or null if this doesn't contain one.
     */
    @FlaggedApi(FLAG_ADD_KEY_AGREEMENT_CRYPTO_OBJECT)
    public KeyAgreement getKeyAgreement() {
    public @Nullable KeyAgreement getKeyAgreement() {
        return mCrypto instanceof KeyAgreement ? (KeyAgreement) mCrypto : null;
    }