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

Commit 37cf60dd authored by Haoran Zhang's avatar Haoran Zhang
Browse files

[Autofill-Credman] Adding a pending intent field in fill response.

The proxy service can set this intent field in fill response so
framework would start the intent and display the credential selector UI.

Bug: b/319521495
Test: atest CtsAutofillServiceTestCases
Change-Id: Id6da629587047f52a7282cc9a6ee8a38b236fe47
parent efeea2a7
Loading
Loading
Loading
Loading
+35 −2
Original line number Original line Diff line number Diff line
@@ -28,6 +28,7 @@ import android.annotation.StringRes;
import android.annotation.SuppressLint;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.annotation.TestApi;
import android.app.Activity;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.content.IntentSender;
import android.content.IntentSender;
import android.content.pm.ParceledListSlice;
import android.content.pm.ParceledListSlice;
@@ -116,6 +117,7 @@ public final class FillResponse implements Parcelable {
    private final boolean mShowFillDialogIcon;
    private final boolean mShowFillDialogIcon;
    private final boolean mShowSaveDialogIcon;
    private final boolean mShowSaveDialogIcon;
    private final @Nullable FieldClassification[] mDetectedFieldTypes;
    private final @Nullable FieldClassification[] mDetectedFieldTypes;
    private final @Nullable PendingIntent mDialogPendingIntent;


    /**
    /**
    * Creates a shollow copy of the provided FillResponse.
    * Creates a shollow copy of the provided FillResponse.
@@ -150,7 +152,8 @@ public final class FillResponse implements Parcelable {
                r.mServiceDisplayNameResourceId,
                r.mServiceDisplayNameResourceId,
                r.mShowFillDialogIcon,
                r.mShowFillDialogIcon,
                r.mShowSaveDialogIcon,
                r.mShowSaveDialogIcon,
                r.mDetectedFieldTypes);
                r.mDetectedFieldTypes,
                r.mDialogPendingIntent);
    }
    }


    private FillResponse(ParceledListSlice<Dataset> datasets, SaveInfo saveInfo, Bundle clientState,
    private FillResponse(ParceledListSlice<Dataset> datasets, SaveInfo saveInfo, Bundle clientState,
@@ -163,7 +166,7 @@ public final class FillResponse implements Parcelable {
            int[] cancelIds, boolean supportsInlineSuggestions, int iconResourceId,
            int[] cancelIds, boolean supportsInlineSuggestions, int iconResourceId,
            int serviceDisplayNameResourceId, boolean showFillDialogIcon,
            int serviceDisplayNameResourceId, boolean showFillDialogIcon,
            boolean showSaveDialogIcon,
            boolean showSaveDialogIcon,
            FieldClassification[] detectedFieldTypes) {
            FieldClassification[] detectedFieldTypes, PendingIntent dialogPendingIntent) {
        mDatasets = datasets;
        mDatasets = datasets;
        mSaveInfo = saveInfo;
        mSaveInfo = saveInfo;
        mClientState = clientState;
        mClientState = clientState;
@@ -190,6 +193,7 @@ public final class FillResponse implements Parcelable {
        mShowFillDialogIcon = showFillDialogIcon;
        mShowFillDialogIcon = showFillDialogIcon;
        mShowSaveDialogIcon = showSaveDialogIcon;
        mShowSaveDialogIcon = showSaveDialogIcon;
        mDetectedFieldTypes = detectedFieldTypes;
        mDetectedFieldTypes = detectedFieldTypes;
        mDialogPendingIntent = dialogPendingIntent;
    }
    }


    private FillResponse(@NonNull Builder builder) {
    private FillResponse(@NonNull Builder builder) {
@@ -219,6 +223,7 @@ public final class FillResponse implements Parcelable {
        mShowFillDialogIcon = builder.mShowFillDialogIcon;
        mShowFillDialogIcon = builder.mShowFillDialogIcon;
        mShowSaveDialogIcon = builder.mShowSaveDialogIcon;
        mShowSaveDialogIcon = builder.mShowSaveDialogIcon;
        mDetectedFieldTypes = builder.mDetectedFieldTypes;
        mDetectedFieldTypes = builder.mDetectedFieldTypes;
        mDialogPendingIntent = builder.mDialogPendingIntent;
    }
    }


    /** @hide */
    /** @hide */
@@ -399,6 +404,7 @@ public final class FillResponse implements Parcelable {
        private boolean mShowFillDialogIcon = true;
        private boolean mShowFillDialogIcon = true;
        private boolean mShowSaveDialogIcon = true;
        private boolean mShowSaveDialogIcon = true;
        private FieldClassification[] mDetectedFieldTypes;
        private FieldClassification[] mDetectedFieldTypes;
        private PendingIntent mDialogPendingIntent;


        /**
        /**
         * Adds a new {@link FieldClassification} to this response, to
         * Adds a new {@link FieldClassification} to this response, to
@@ -1078,6 +1084,24 @@ public final class FillResponse implements Parcelable {
            return this;
            return this;
        }
        }


        /**
         * Sets credential dialog pending intent. Framework will use the intent to launch the
         * selector UI. A replacement for previous fill bottom sheet.
         *
         * @throws IllegalStateException if {@link #build()} was already called.
         * @throws NullPointerException if {@code pendingIntent} is {@code null}.
         *
         * @hide
         */
        @NonNull
        public Builder setDialogPendingIntent(@NonNull PendingIntent pendingIntent) {
            throwIfDestroyed();
            Preconditions.checkNotNull(pendingIntent,
                    "can't pass a null object to setDialogPendingIntent");
            mDialogPendingIntent = pendingIntent;
            return this;
        }

        /**
        /**
         * Builds a new {@link FillResponse} instance.
         * Builds a new {@link FillResponse} instance.
         *
         *
@@ -1187,6 +1211,9 @@ public final class FillResponse implements Parcelable {
        if (mAuthentication != null) {
        if (mAuthentication != null) {
            builder.append(", hasAuthentication");
            builder.append(", hasAuthentication");
        }
        }
        if (mDialogPendingIntent != null) {
            builder.append(", hasDialogPendingIntent");
        }
        if (mAuthenticationIds != null) {
        if (mAuthenticationIds != null) {
            builder.append(", authenticationIds=").append(Arrays.toString(mAuthenticationIds));
            builder.append(", authenticationIds=").append(Arrays.toString(mAuthenticationIds));
        }
        }
@@ -1232,6 +1259,7 @@ public final class FillResponse implements Parcelable {
        parcel.writeParcelable(mInlineTooltipPresentation, flags);
        parcel.writeParcelable(mInlineTooltipPresentation, flags);
        parcel.writeParcelable(mDialogPresentation, flags);
        parcel.writeParcelable(mDialogPresentation, flags);
        parcel.writeParcelable(mDialogHeader, flags);
        parcel.writeParcelable(mDialogHeader, flags);
        parcel.writeParcelable(mDialogPendingIntent, flags);
        parcel.writeParcelableArray(mFillDialogTriggerIds, flags);
        parcel.writeParcelableArray(mFillDialogTriggerIds, flags);
        parcel.writeParcelable(mHeader, flags);
        parcel.writeParcelable(mHeader, flags);
        parcel.writeParcelable(mFooter, flags);
        parcel.writeParcelable(mFooter, flags);
@@ -1282,6 +1310,11 @@ public final class FillResponse implements Parcelable {
            if (dialogHeader != null) {
            if (dialogHeader != null) {
                builder.setDialogHeader(dialogHeader);
                builder.setDialogHeader(dialogHeader);
            }
            }
            final PendingIntent dialogPendingIntent = parcel.readParcelable(null,
                    PendingIntent.class);
            if (dialogPendingIntent != null) {
                builder.setDialogPendingIntent(dialogPendingIntent);
            }
            final AutofillId[] triggerIds = parcel.readParcelableArray(null, AutofillId.class);
            final AutofillId[] triggerIds = parcel.readParcelableArray(null, AutofillId.class);
            if (triggerIds != null) {
            if (triggerIds != null) {
                builder.setFillDialogTriggerIds(triggerIds);
                builder.setFillDialogTriggerIds(triggerIds);