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

Commit f26fe171 authored by Hao Dong's avatar Hao Dong Committed by Android (Google) Code Review
Browse files

Merge "Add a new constructor of CryptoObject()." into main

parents 75373f9a a4e91441
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18971,6 +18971,7 @@ 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);
    ctor @FlaggedApi("android.hardware.biometrics.get_op_id_crypto_object") public BiometricPrompt.CryptoObject(long);
    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();
+50 −1
Original line number Diff line number Diff line
@@ -944,14 +944,29 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     * @see Builder#setAllowedAuthenticators(int)
     */
    public static final class CryptoObject extends android.hardware.biometrics.CryptoObject {
        /**
         * Create from a {@link Signature} object.
         *
         * @param signature a {@link Signature} object.
         */
        public CryptoObject(@NonNull Signature signature) {
            super(signature);
        }

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

        /**
         * Create from a {@link Mac} object.
         *
         * @param mac a {@link Mac} object.
         */
        public CryptoObject(@NonNull Mac mac) {
            super(mac);
        }
@@ -967,15 +982,36 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            super(credential);
        }

        /**
         * Create from a {@link PresentationSession} object.
         *
         * @param session a {@link PresentationSession} object.
         */
        public CryptoObject(@NonNull PresentationSession session) {
            super(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) {
            super(keyAgreement);
        }

        /**
         * Create from an operation handle.
         * @see CryptoObject#getOperationHandle()
         *
         * @param operationHandle the operation handle associated with this object.
         */
        @FlaggedApi(FLAG_GET_OP_ID_CRYPTO_OBJECT)
        public CryptoObject(long operationHandle) {
            super(operationHandle);
        }

        /**
         * Get {@link Signature} object.
         * @return {@link Signature} object or null if this doesn't contain one.
@@ -1028,7 +1064,20 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        }

        /**
         * Get the operation handle associated with this object or 0 if none.
         * Returns the {@code operationHandle} associated with this object or 0 if none.
         * The {@code operationHandle} is the underlying identifier associated with
         * the {@code CryptoObject}.
         *
         * <p> The {@code operationHandle} can be used to reconstruct a {@code CryptoObject}
         * instance. This is useful for any cross-process communication as the {@code CryptoObject}
         * class is not {@link android.os.Parcelable}. Hence, if the {@code CryptoObject} is
         * constructed in one process, and needs to be propagated to another process,
         * before calling the
         * {@link BiometricPrompt#authenticate(CryptoObject, CancellationSignal, Executor,
         * AuthenticationCallback)} API in the second process, the recommendation is to retrieve the
         * {@code operationHandle} using this API, and then reconstruct the
         * {@code CryptoObject}using the constructor that takes in an {@code operationHandle}, and
         * pass that in to the {@code authenticate} API mentioned above.
         */
        @FlaggedApi(FLAG_GET_OP_ID_CRYPTO_OBJECT)
        public long getOperationHandle() {
+6 −0
Original line number Diff line number Diff line
@@ -97,6 +97,10 @@ public class CryptoObject {
        mCrypto = keyAgreement;
    }

    public CryptoObject(long operationHandle) {
        mCrypto = operationHandle;
    }

    /**
     * Get {@link Signature} object.
     * @return {@link Signature} object or null if this doesn't contain one.
@@ -157,6 +161,8 @@ public class CryptoObject {
    public long getOpId() {
        if (mCrypto == null) {
            return 0;
        } else if (mCrypto instanceof Long) {
            return (long) mCrypto;
        } else if (mCrypto instanceof IdentityCredential) {
            return ((IdentityCredential) mCrypto).getCredstoreOperationHandle();
        } else if (mCrypto instanceof PresentationSession) {