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

Commit b72f012c authored by Felipe Leme's avatar Felipe Leme
Browse files

Added customization to SaveInfo.

Bug: 35727295
Test: CtsAutoFillServiceTestCases pass
Test: m update-api

Change-Id: I7eba36b6ab8181ae1cdbd10b0879927b9f9cf086
parent 81926e39
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -36391,16 +36391,17 @@ package android.service.autofill {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.autofill.SaveInfo> CREATOR;
    field public static final int SAVE_UI_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_UI_TYPE_CREDENTIALS = 1; // 0x1
    field public static final int SAVE_UI_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_UI_TYPE_PAYMENT = 3; // 0x3
    field public static final int SAVE_DATA_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_DATA_TYPE_CREDIT_CARD = 3; // 0x3
    field public static final int SAVE_DATA_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_DATA_TYPE_PASSWORD = 1; // 0x1
  }
  public static final class SaveInfo.Builder {
    ctor public SaveInfo.Builder(int);
    method public android.service.autofill.SaveInfo.Builder addSavableIds(android.view.autofill.AutoFillId...);
    method public android.service.autofill.SaveInfo build();
    method public android.service.autofill.SaveInfo.Builder setDescription(java.lang.CharSequence);
  }
}
+5 −4
Original line number Diff line number Diff line
@@ -39311,16 +39311,17 @@ package android.service.autofill {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.autofill.SaveInfo> CREATOR;
    field public static final int SAVE_UI_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_UI_TYPE_CREDENTIALS = 1; // 0x1
    field public static final int SAVE_UI_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_UI_TYPE_PAYMENT = 3; // 0x3
    field public static final int SAVE_DATA_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_DATA_TYPE_CREDIT_CARD = 3; // 0x3
    field public static final int SAVE_DATA_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_DATA_TYPE_PASSWORD = 1; // 0x1
  }
  public static final class SaveInfo.Builder {
    ctor public SaveInfo.Builder(int);
    method public android.service.autofill.SaveInfo.Builder addSavableIds(android.view.autofill.AutoFillId...);
    method public android.service.autofill.SaveInfo build();
    method public android.service.autofill.SaveInfo.Builder setDescription(java.lang.CharSequence);
  }
}
+5 −4
Original line number Diff line number Diff line
@@ -36530,16 +36530,17 @@ package android.service.autofill {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.autofill.SaveInfo> CREATOR;
    field public static final int SAVE_UI_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_UI_TYPE_CREDENTIALS = 1; // 0x1
    field public static final int SAVE_UI_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_UI_TYPE_PAYMENT = 3; // 0x3
    field public static final int SAVE_DATA_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_DATA_TYPE_CREDIT_CARD = 3; // 0x3
    field public static final int SAVE_DATA_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_DATA_TYPE_PASSWORD = 1; // 0x1
  }
  public static final class SaveInfo.Builder {
    ctor public SaveInfo.Builder(int);
    method public android.service.autofill.SaveInfo.Builder addSavableIds(android.view.autofill.AutoFillId...);
    method public android.service.autofill.SaveInfo build();
    method public android.service.autofill.SaveInfo.Builder setDescription(java.lang.CharSequence);
  }
}
+2 −2
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ public final class FillResponse implements Parcelable {
            // Handle the the case where service didn't call setSavableIds() because it would
            // contain just the ids from the datasets.
            if (saveInfo == null && mDatasets != null) {
                saveInfo = new SaveInfo.Builder(SaveInfo.SAVE_UI_TYPE_GENERIC).build();
                saveInfo = new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_GENERIC).build();
            }
            if (saveInfo != null) {
                saveInfo.addSavableIds(mDatasets);
@@ -324,7 +324,7 @@ public final class FillResponse implements Parcelable {
                throw new IllegalStateException("setSaveInfo() already called");
            }
            if (mSaveInfoBuilder == null) {
                mSaveInfoBuilder = new SaveInfo.Builder(SaveInfo.SAVE_UI_TYPE_GENERIC);
                mSaveInfoBuilder = new SaveInfo.Builder(SaveInfo.SAVE_DATA_TYPE_GENERIC);
            }
            mSaveInfoBuilder.addSavableIds(ids);

+51 −24
Original line number Diff line number Diff line
@@ -52,43 +52,44 @@ public final class SaveInfo implements Parcelable {
     * Type used on when the service can save the contents of an activity, but cannot describe what
     * the content is for.
     */
    public static final int SAVE_UI_TYPE_GENERIC = 0;
    public static final int SAVE_DATA_TYPE_GENERIC = 0;

    /**
     * Type used when the {@link FillResponse} represents user credentials (such as username and
     * password).
     * Type used when the {@link FillResponse} represents user credentials that have a password.
     */
    public static final int SAVE_UI_TYPE_CREDENTIALS = 1;
    public static final int SAVE_DATA_TYPE_PASSWORD = 1;


    /**
     * Type used on when the {@link FillResponse} represents a physical address (such as street,
     * city, state, etc).
     */
    public static final int SAVE_UI_TYPE_ADDRESS = 2;
    public static final int SAVE_DATA_TYPE_ADDRESS = 2;

    /**
     * Type used when the {@link FillResponse} represents a payment (such as credit card number
     * and expiration date).
     * Type used when the {@link FillResponse} represents a credit card.
     */
    public static final int SAVE_UI_TYPE_PAYMENT = 3;
    public static final int SAVE_DATA_TYPE_CREDIT_CARD = 3;

    private final @SaveUiType int mType;
    private final @SaveDataType int mType;
    private ArraySet<AutoFillId> mSavableIds;
    private final CharSequence mDescription;

    /** @hide */
    @IntDef({
        SAVE_UI_TYPE_GENERIC,
        SAVE_UI_TYPE_CREDENTIALS,
        SAVE_UI_TYPE_ADDRESS,
        SAVE_UI_TYPE_PAYMENT
        SAVE_DATA_TYPE_GENERIC,
        SAVE_DATA_TYPE_PASSWORD,
        SAVE_DATA_TYPE_ADDRESS,
        SAVE_DATA_TYPE_CREDIT_CARD
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface SaveUiType {
    public @interface SaveDataType {
    }

    private SaveInfo(Builder builder) {
        mType = builder.mType;
        mSavableIds = builder.mSavableIds;
        mDescription = builder.mDescription;
    }

    /** @hide */
@@ -96,6 +97,16 @@ public final class SaveInfo implements Parcelable {
        return mSavableIds;
    }

    /** @hide */
    public int getType() {
        return mType;
    }

    /** @hide */
    public CharSequence getDescription() {
        return mDescription;
    }

    /** @hide */
    public void addSavableIds(@Nullable ArrayList<Dataset> datasets) {
        if (datasets != null) {
@@ -120,27 +131,28 @@ public final class SaveInfo implements Parcelable {
     */
    public static final class Builder {

        private final @SaveUiType int mType;
        private final @SaveDataType int mType;
        private ArraySet<AutoFillId> mSavableIds;
        private CharSequence mDescription;
        private boolean mDestroyed;

        /**
         * Creates a new builder.
         *
         * @param type the type of information the associated {@link FillResponse} represents. Must
         * be {@link SaveInfo#SAVE_UI_TYPE_GENERIC}, {@link SaveInfo#SAVE_UI_TYPE_CREDENTIALS},
         * {@link SaveInfo#SAVE_UI_TYPE_ADDRESS}, or {@link SaveInfo#SAVE_UI_TYPE_PAYMENT};
         * otherwise it will assume {@link SaveInfo#SAVE_UI_TYPE_GENERIC}.
         * be {@link SaveInfo#SAVE_DATA_TYPE_GENERIC}, {@link SaveInfo#SAVE_DATA_TYPE_PASSWORD},
         * {@link SaveInfo#SAVE_DATA_TYPE_ADDRESS}, or {@link SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD};
         * otherwise it will assume {@link SaveInfo#SAVE_DATA_TYPE_GENERIC}.
         */
        public Builder(@SaveUiType int type) {
        public Builder(@SaveDataType int type) {
            switch (type) {
                case SAVE_UI_TYPE_CREDENTIALS:
                case SAVE_UI_TYPE_ADDRESS:
                case SAVE_UI_TYPE_PAYMENT:
                case SAVE_DATA_TYPE_PASSWORD:
                case SAVE_DATA_TYPE_ADDRESS:
                case SAVE_DATA_TYPE_CREDIT_CARD:
                    mType = type;
                    break;
                default:
                    mType = SAVE_UI_TYPE_GENERIC;
                    mType = SAVE_DATA_TYPE_GENERIC;
            }
        }

@@ -168,6 +180,20 @@ public final class SaveInfo implements Parcelable {
            return this;
        }

        /**
         * Sets an optional description to be shown in the UI when the user is asked to save.
         *
         * <p>Typically, it describes how the data will be stored by the service, so it can help
         * users to decide whether they can trust the service to save their data.
         *
         * @param description a succint description.
         * @return This Builder.
         */
        public @NonNull Builder setDescription(@Nullable CharSequence description) {
            mDescription = description;
            return this;
        }

        /**
         * Builds a new {@link SaveInfo} instance.
         */
@@ -210,6 +236,7 @@ public final class SaveInfo implements Parcelable {
    public void writeToParcel(Parcel parcel, int flags) {
        parcel.writeInt(mType);
        parcel.writeTypedArraySet(mSavableIds, flags);
        parcel.writeCharSequence(mDescription);
    }

    public static final Parcelable.Creator<SaveInfo> CREATOR = new Parcelable.Creator<SaveInfo>() {
@@ -224,7 +251,7 @@ public final class SaveInfo implements Parcelable {
            for (int i = 0; i < savableIdsCount; i++) {
                builder.addSavableIds(savableIds.valueAt(i));
            }

            builder.setDescription(parcel.readCharSequence());
            return builder.build();
        }

Loading