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

Commit 319b59a5 authored by Reema Bajwa's avatar Reema Bajwa
Browse files

Add hidden authenticationExtras field to Dataset class

This is needed to add context from the credentialAutofillService
including the final request and other data that the credential provider
may have set. For traditional autofill flows, this will always be null.

Bug:300981001
Test: Built locally & deployed
Unit tests to be added through b/303677885

Change-Id: I49ab64b55ad5a62aa30a6961436263389ea0eb07
parent ee20263f
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.service.autofill;

import static android.view.autofill.Helper.sDebug;

import android.annotation.Hide;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -26,6 +27,7 @@ import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.ClipData;
import android.content.IntentSender;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArrayMap;
@@ -187,6 +189,9 @@ public final class Dataset implements Parcelable {
    @Nullable private final InlinePresentation mInlinePresentation;
    @Nullable private final InlinePresentation mInlineTooltipPresentation;
    private final IntentSender mAuthentication;

    @Nullable private final Bundle mAuthenticationExtras;

    @Nullable String mId;

    /**
@@ -224,6 +229,7 @@ public final class Dataset implements Parcelable {
        mInlinePresentation = inlinePresentation;
        mInlineTooltipPresentation = inlineTooltipPresentation;
        mAuthentication = authentication;
        mAuthenticationExtras = null;
        mId = id;
    }

@@ -246,6 +252,7 @@ public final class Dataset implements Parcelable {
        mInlinePresentation = dataset.mInlinePresentation;
        mInlineTooltipPresentation = dataset.mInlineTooltipPresentation;
        mAuthentication = dataset.mAuthentication;
        mAuthenticationExtras = dataset.mAuthenticationExtras;
        mId = dataset.mId;
        mAutofillDatatypes = dataset.mAutofillDatatypes;
    }
@@ -264,6 +271,7 @@ public final class Dataset implements Parcelable {
        mInlinePresentation = builder.mInlinePresentation;
        mInlineTooltipPresentation = builder.mInlineTooltipPresentation;
        mAuthentication = builder.mAuthentication;
        mAuthenticationExtras = builder.mAuthenticationExtras;
        mId = builder.mId;
        mAutofillDatatypes = builder.mAutofillDatatypes;
    }
@@ -344,6 +352,12 @@ public final class Dataset implements Parcelable {
        return mAuthentication;
    }

    /** @hide */
    @Hide
    public @Nullable Bundle getAuthenticationExtras() {
        return mAuthenticationExtras;
    }

    /** @hide */
    @TestApi
    public boolean isEmpty() {
@@ -401,6 +415,9 @@ public final class Dataset implements Parcelable {
        if (mAuthentication != null) {
            builder.append(", hasAuthentication");
        }
        if (mAuthenticationExtras != null) {
            builder.append(", hasAuthenticationExtras");
        }
        if (mAutofillDatatypes != null) {
            builder.append(", autofillDatatypes=").append(mAutofillDatatypes);
        }
@@ -454,6 +471,8 @@ public final class Dataset implements Parcelable {
        @Nullable private InlinePresentation mInlinePresentation;
        @Nullable private InlinePresentation mInlineTooltipPresentation;
        private IntentSender mAuthentication;

        private Bundle mAuthenticationExtras;
        private boolean mDestroyed;
        @Nullable private String mId;

@@ -623,6 +642,25 @@ public final class Dataset implements Parcelable {
            return this;
        }

        /**
         * Sets extras to be associated with the {@code authentication} intent sender, to be
         * set on the intent that is fired through the intent sender.
         *
         * Autofill providers can set any extras they wish to receive directly on the intent
         * that is used to create the {@code authentication}. This is an internal API, to be
         * used by the platform to associate data with a given dataset. These extras will be
         * merged with the {@code clientState} and sent as part of the fill in intent when
         * the {@code authentication} intentSender is invoked.
         *
         * @hide
         */
        @Hide
        public @NonNull Builder setAuthenticationExtras(@Nullable Bundle authenticationExtra) {
            throwIfDestroyed();
            mAuthenticationExtras = authenticationExtra;
            return this;
        }

        /**
         * Sets the id for the dataset so its usage can be tracked.
         *
+6 −0
Original line number Diff line number Diff line
@@ -276,6 +276,12 @@ public final class AutofillManager {
    public static final String EXTRA_CLIENT_STATE =
            "android.view.autofill.extra.CLIENT_STATE";

    /**
     * @hide
     */
    public static final String EXTRA_AUTH_STATE =
            "android.view.autofill.extra.AUTH_STATE";

    /**
     * Intent extra: the {@link android.view.inputmethod.InlineSuggestionsRequest} in the
     * autofill request.
+8 −3
Original line number Diff line number Diff line
@@ -2437,7 +2437,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
                        + id + " destroyed");
                return;
            }
            fillInIntent = createAuthFillInIntentLocked(requestId, extras);
            fillInIntent = createAuthFillInIntentLocked(requestId, extras, /* authExtras= */ null);
            if (fillInIntent == null) {
                forceRemoveFromServiceLocked();
                return;
@@ -5557,7 +5557,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
            mPresentationStatsEventLogger.maybeSetAuthenticationType(
                AUTHENTICATION_TYPE_DATASET_AUTHENTICATION);
            setViewStatesLocked(null, dataset, ViewState.STATE_WAITING_DATASET_AUTH, false);
            final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState);
            final Intent fillInIntent = createAuthFillInIntentLocked(requestId, mClientState,
                    dataset.getAuthenticationExtras());
            if (fillInIntent == null) {
                forceRemoveFromServiceLocked();
                return;
@@ -5573,7 +5574,8 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
    // TODO: this should never be null, but we got at least one occurrence, probably due to a race.
    @GuardedBy("mLock")
    @Nullable
    private Intent createAuthFillInIntentLocked(int requestId, Bundle extras) {
    private Intent createAuthFillInIntentLocked(int requestId, Bundle extras,
            @Nullable Bundle authExtras) {
        final Intent fillInIntent = new Intent();

        final FillContext context = getFillContextByRequestIdLocked(requestId);
@@ -5590,6 +5592,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState
        }
        fillInIntent.putExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE, context.getStructure());
        fillInIntent.putExtra(AutofillManager.EXTRA_CLIENT_STATE, extras);
        if (authExtras != null) {
            fillInIntent.putExtra(AutofillManager.EXTRA_AUTH_STATE, authExtras);
        }
        return fillInIntent;
    }