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

Commit 42d4afcd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Enhances the title and the positive button style on the save UI"

parents b61d30d4 7d1a44ec
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -41368,11 +41368,16 @@ package android.service.autofill {
    field public static final int FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE = 1; // 0x1
    field public static final int NEGATIVE_BUTTON_STYLE_CANCEL = 0; // 0x0
    field public static final int NEGATIVE_BUTTON_STYLE_REJECT = 1; // 0x1
    field public static final int POSITIVE_BUTTON_STYLE_CONTINUE = 1; // 0x1
    field public static final int POSITIVE_BUTTON_STYLE_SAVE = 0; // 0x0
    field public static final int SAVE_DATA_TYPE_ADDRESS = 2; // 0x2
    field public static final int SAVE_DATA_TYPE_CREDIT_CARD = 4; // 0x4
    field public static final int SAVE_DATA_TYPE_DEBIT_CARD = 32; // 0x20
    field public static final int SAVE_DATA_TYPE_EMAIL_ADDRESS = 16; // 0x10
    field public static final int SAVE_DATA_TYPE_GENERIC = 0; // 0x0
    field public static final int SAVE_DATA_TYPE_GENERIC_CARD = 128; // 0x80
    field public static final int SAVE_DATA_TYPE_PASSWORD = 1; // 0x1
    field public static final int SAVE_DATA_TYPE_PAYMENT_CARD = 64; // 0x40
    field public static final int SAVE_DATA_TYPE_USERNAME = 8; // 0x8
  }
@@ -41386,6 +41391,7 @@ package android.service.autofill {
    method @NonNull public android.service.autofill.SaveInfo.Builder setFlags(int);
    method @NonNull public android.service.autofill.SaveInfo.Builder setNegativeAction(int, @Nullable android.content.IntentSender);
    method @NonNull public android.service.autofill.SaveInfo.Builder setOptionalIds(@NonNull android.view.autofill.AutofillId[]);
    method @NonNull public android.service.autofill.SaveInfo.Builder setPositiveAction(int);
    method @NonNull public android.service.autofill.SaveInfo.Builder setTriggerId(@NonNull android.view.autofill.AutofillId);
    method @NonNull public android.service.autofill.SaveInfo.Builder setValidator(@NonNull android.service.autofill.Validator);
  }
+94 −7
Original line number Diff line number Diff line
@@ -180,6 +180,23 @@ public final class SaveInfo implements Parcelable {
     */
    public static final int SAVE_DATA_TYPE_EMAIL_ADDRESS = 0x10;

    /**
     * Type used when the {@link FillResponse} represents a debit card.
     */
    public static final int SAVE_DATA_TYPE_DEBIT_CARD = 0x20;

    /**
     * Type used when the {@link FillResponse} represents a payment card except for credit and
     * debit cards.
     */
    public static final int SAVE_DATA_TYPE_PAYMENT_CARD = 0x40;

    /**
     * Type used when the {@link FillResponse} represents a card that does not a specified card or
     * cannot identify what the card is for.
     */
    public static final int SAVE_DATA_TYPE_GENERIC_CARD = 0x80;

    /**
     * Style for the negative button of the save UI to cancel the
     * save operation. In this case, the user tapping the negative
@@ -207,6 +224,30 @@ public final class SaveInfo implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    @interface NegativeButtonStyle{}

    /**
     * Style for the positive button of save UI to request the save operation.
     * In this case, the user tapping the positive button signals that they
     * agrees to save the filled content.
     */
    public static final int POSITIVE_BUTTON_STYLE_SAVE = 0;

    /**
     * Style for the positive button of save UI to have next action before the save operation.
     * This could be useful if the filled content contains sensitive personally identifiable
     * information and then requires user confirmation or verification. In this case, the user
     * tapping the positive button signals that they would complete the next required action
     * to save the filled content.
     */
    public static final int POSITIVE_BUTTON_STYLE_CONTINUE = 1;

    /** @hide */
    @IntDef(prefix = { "POSITIVE_BUTTON_STYLE_" }, value = {
            POSITIVE_BUTTON_STYLE_SAVE,
            POSITIVE_BUTTON_STYLE_CONTINUE
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface PositiveButtonStyle{}

    /** @hide */
    @IntDef(flag = true, prefix = { "SAVE_DATA_TYPE_" }, value = {
            SAVE_DATA_TYPE_GENERIC,
@@ -214,7 +255,10 @@ public final class SaveInfo implements Parcelable {
            SAVE_DATA_TYPE_ADDRESS,
            SAVE_DATA_TYPE_CREDIT_CARD,
            SAVE_DATA_TYPE_USERNAME,
            SAVE_DATA_TYPE_EMAIL_ADDRESS
            SAVE_DATA_TYPE_EMAIL_ADDRESS,
            SAVE_DATA_TYPE_DEBIT_CARD,
            SAVE_DATA_TYPE_PAYMENT_CARD,
            SAVE_DATA_TYPE_GENERIC_CARD
    })
    @Retention(RetentionPolicy.SOURCE)
    @interface SaveDataType{}
@@ -266,6 +310,7 @@ public final class SaveInfo implements Parcelable {

    private final @SaveDataType int mType;
    private final @NegativeButtonStyle int mNegativeButtonStyle;
    private final @PositiveButtonStyle int mPositiveButtonStyle;
    private final IntentSender mNegativeActionListener;
    private final AutofillId[] mRequiredIds;
    private final AutofillId[] mOptionalIds;
@@ -281,6 +326,7 @@ public final class SaveInfo implements Parcelable {
        mType = builder.mType;
        mNegativeButtonStyle = builder.mNegativeButtonStyle;
        mNegativeActionListener = builder.mNegativeActionListener;
        mPositiveButtonStyle = builder.mPositiveButtonStyle;
        mRequiredIds = builder.mRequiredIds;
        mOptionalIds = builder.mOptionalIds;
        mDescription = builder.mDescription;
@@ -312,6 +358,11 @@ public final class SaveInfo implements Parcelable {
        return mNegativeActionListener;
    }

    /** @hide */
    public @PositiveButtonStyle int getPositiveActionStyle() {
        return mPositiveButtonStyle;
    }

    /** @hide */
    public @Nullable AutofillId[] getRequiredIds() {
        return mRequiredIds;
@@ -374,6 +425,7 @@ public final class SaveInfo implements Parcelable {

        private final @SaveDataType int mType;
        private @NegativeButtonStyle int mNegativeButtonStyle = NEGATIVE_BUTTON_STYLE_CANCEL;
        private @PositiveButtonStyle int mPositiveButtonStyle = POSITIVE_BUTTON_STYLE_SAVE;
        private IntentSender mNegativeActionListener;
        private final AutofillId[] mRequiredIds;
        private AutofillId[] mOptionalIds;
@@ -394,8 +446,9 @@ public final class SaveInfo implements Parcelable {
         * can be any combination of {@link SaveInfo#SAVE_DATA_TYPE_GENERIC},
         * {@link SaveInfo#SAVE_DATA_TYPE_PASSWORD},
         * {@link SaveInfo#SAVE_DATA_TYPE_ADDRESS}, {@link SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD},
         * {@link SaveInfo#SAVE_DATA_TYPE_USERNAME}, or
         * {@link SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS}.
         * {@link SaveInfo#SAVE_DATA_TYPE_DEBIT_CARD}, {@link SaveInfo#SAVE_DATA_TYPE_PAYMENT_CARD},
         * {@link SaveInfo#SAVE_DATA_TYPE_GENERIC_CARD}, {@link SaveInfo#SAVE_DATA_TYPE_USERNAME},
         * or {@link SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS}.
         * @param requiredIds ids of all required views that will trigger a save request.
         *
         * <p>See {@link SaveInfo} for more info.
@@ -418,8 +471,9 @@ public final class SaveInfo implements Parcelable {
         * can be any combination of {@link SaveInfo#SAVE_DATA_TYPE_GENERIC},
         * {@link SaveInfo#SAVE_DATA_TYPE_PASSWORD},
         * {@link SaveInfo#SAVE_DATA_TYPE_ADDRESS}, {@link SaveInfo#SAVE_DATA_TYPE_CREDIT_CARD},
         * {@link SaveInfo#SAVE_DATA_TYPE_USERNAME}, or
         * {@link SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS}.
         * {@link SaveInfo#SAVE_DATA_TYPE_DEBIT_CARD}, {@link SaveInfo#SAVE_DATA_TYPE_PAYMENT_CARD},
         * {@link SaveInfo#SAVE_DATA_TYPE_GENERIC_CARD}, {@link SaveInfo#SAVE_DATA_TYPE_USERNAME},
         * or {@link SaveInfo#SAVE_DATA_TYPE_EMAIL_ADDRESS}.
         *
         * <p>See {@link SaveInfo} for more info.
         */
@@ -523,6 +577,8 @@ public final class SaveInfo implements Parcelable {
        public @NonNull Builder setNegativeAction(@NegativeButtonStyle int style,
                @Nullable IntentSender listener) {
            throwIfDestroyed();
            Preconditions.checkArgumentInRange(style, NEGATIVE_BUTTON_STYLE_CANCEL,
                    NEGATIVE_BUTTON_STYLE_REJECT, "style");
            if (style != NEGATIVE_BUTTON_STYLE_CANCEL
                    && style != NEGATIVE_BUTTON_STYLE_REJECT) {
                throw new IllegalArgumentException("Invalid style: " + style);
@@ -532,6 +588,33 @@ public final class SaveInfo implements Parcelable {
            return this;
        }

        /**
         * Sets the style for the positive save action.
         *
         * <p>This allows an autofill service to customize the style of the
         * positive action in the save UI. Note that selecting the positive
         * action regardless of its style would dismiss the save UI and calling
         * into the {@link AutofillService#onSaveRequest(SaveRequest, SaveCallback) save request}.
         * The service should take the next action if selecting style
         * {@link #POSITIVE_BUTTON_STYLE_CONTINUE}. The default style is
         * {@link #POSITIVE_BUTTON_STYLE_SAVE}
         *
         * @param style The action style.
         * @return This builder.
         *
         * @see #POSITIVE_BUTTON_STYLE_SAVE
         * @see #POSITIVE_BUTTON_STYLE_CONTINUE
         *
         * @throws IllegalArgumentException If the style is invalid
         */
        public @NonNull Builder setPositiveAction(@PositiveButtonStyle int style) {
            throwIfDestroyed();
            Preconditions.checkArgumentInRange(style, POSITIVE_BUTTON_STYLE_SAVE,
                    POSITIVE_BUTTON_STYLE_CONTINUE, "style");
            mPositiveButtonStyle = style;
            return this;
        }

        /**
         * Sets an object used to validate the user input - if the input is not valid, the
         * autofill save UI is not shown.
@@ -717,8 +800,10 @@ public final class SaveInfo implements Parcelable {
        final StringBuilder builder = new StringBuilder("SaveInfo: [type=")
                .append(DebugUtils.flagsToString(SaveInfo.class, "SAVE_DATA_TYPE_", mType))
                .append(", requiredIds=").append(Arrays.toString(mRequiredIds))
                .append(", style=").append(DebugUtils.flagsToString(SaveInfo.class,
                        "NEGATIVE_BUTTON_STYLE_", mNegativeButtonStyle));
                .append(", negative style=").append(DebugUtils.flagsToString(SaveInfo.class,
                        "NEGATIVE_BUTTON_STYLE_", mNegativeButtonStyle))
                .append(", positive style=").append(DebugUtils.flagsToString(SaveInfo.class,
                        "POSITIVE_BUTTON_STYLE_", mPositiveButtonStyle));
        if (mOptionalIds != null) {
            builder.append(", optionalIds=").append(Arrays.toString(mOptionalIds));
        }
@@ -763,6 +848,7 @@ public final class SaveInfo implements Parcelable {
        parcel.writeParcelableArray(mOptionalIds, flags);
        parcel.writeInt(mNegativeButtonStyle);
        parcel.writeParcelable(mNegativeActionListener, flags);
        parcel.writeInt(mPositiveButtonStyle);
        parcel.writeCharSequence(mDescription);
        parcel.writeParcelable(mCustomDescription, flags);
        parcel.writeParcelable(mValidator, flags);
@@ -794,6 +880,7 @@ public final class SaveInfo implements Parcelable {
            }

            builder.setNegativeAction(parcel.readInt(), parcel.readParcelable(null));
            builder.setPositiveAction(parcel.readInt());
            builder.setDescription(parcel.readCharSequence());
            final CustomDescription customDescripton = parcel.readParcelable(null);
            if (customDescripton != null) {
+8 −0
Original line number Diff line number Diff line
@@ -5205,6 +5205,8 @@
    <string name="autofill_save_no">No thanks</string>
    <!-- Label for the autofill update button [CHAR LIMIT=NONE] -->
    <string name="autofill_update_yes">Update</string>
    <!-- Label for the autofill continue button [CHAR LIMIT=NONE] -->
    <string name="autofill_continue_yes">Continue</string>

    <!-- Label for the type of data being saved for autofill when it represent user credentials with a password [CHAR LIMIT=NONE] -->
    <string name="autofill_save_type_password">password</string>
@@ -5212,6 +5214,12 @@
    <string name="autofill_save_type_address">address</string>
    <!-- Label for the type of data being saved for autofill when it represents a credit card [CHAR LIMIT=NONE] -->
    <string name="autofill_save_type_credit_card">credit card</string>
    <!-- Label for the type of data being saved for autofill when it represents a debit card [CHAR LIMIT=NONE] -->
    <string name="autofill_save_type_debit_card">debit card</string>
    <!-- Label for the type of data being saved for autofill when it represents a payment card [CHAR LIMIT=NONE] -->
    <string name="autofill_save_type_payment_card">payment card</string>
    <!-- Label for the type of data being saved for autofill when it represents a card that does not a specified type or cannot identify what the type is for [CHAR LIMIT=NONE] -->
    <string name="autofill_save_type_generic_card">card</string>
    <!-- Label for the type of data being saved for autofill when it represents an username [CHAR LIMIT=NONE] -->
    <string name="autofill_save_type_username">username</string>
    <!-- Label for the type of data being saved for autofill when it represents an email address [CHAR LIMIT=NONE] -->
+4 −0
Original line number Diff line number Diff line
@@ -3355,6 +3355,7 @@
  <java-symbol type="string" name="autofill_update_title_with_2types" />
  <java-symbol type="string" name="autofill_update_title_with_3types" />
  <java-symbol type="string" name="autofill_update_yes" />
  <java-symbol type="string" name="autofill_continue_yes" />
  <java-symbol type="string" name="autofill_save_accessibility_title " />
  <java-symbol type="string" name="autofill_save_title" />
  <java-symbol type="string" name="autofill_save_title_with_type" />
@@ -3365,6 +3366,9 @@
  <java-symbol type="string" name="autofill_save_type_password" />
  <java-symbol type="string" name="autofill_save_type_address" />
  <java-symbol type="string" name="autofill_save_type_credit_card" />
  <java-symbol type="string" name="autofill_save_type_debit_card" />
  <java-symbol type="string" name="autofill_save_type_payment_card" />
  <java-symbol type="string" name="autofill_save_type_generic_card" />
  <java-symbol type="string" name="autofill_save_type_username" />
  <java-symbol type="string" name="autofill_save_type_email_address" />
  <java-symbol type="drawable" name="autofill_dataset_picker_background" />
+16 −2
Original line number Diff line number Diff line
@@ -197,8 +197,20 @@ final class SaveUi {
        if ((type & SaveInfo.SAVE_DATA_TYPE_ADDRESS) != 0) {
            types.add(context.getString(R.string.autofill_save_type_address));
        }
        if ((type & SaveInfo.SAVE_DATA_TYPE_CREDIT_CARD) != 0) {

        // fallback to generic card type if set multiple types
        final int cardTypeMask = SaveInfo.SAVE_DATA_TYPE_CREDIT_CARD
                        | SaveInfo.SAVE_DATA_TYPE_DEBIT_CARD
                        | SaveInfo.SAVE_DATA_TYPE_PAYMENT_CARD;
        final int count = Integer.bitCount(type & cardTypeMask);
        if (count > 1 || (type & SaveInfo.SAVE_DATA_TYPE_GENERIC_CARD) != 0) {
            types.add(context.getString(R.string.autofill_save_type_generic_card));
        } else if ((type & SaveInfo.SAVE_DATA_TYPE_PAYMENT_CARD) != 0) {
            types.add(context.getString(R.string.autofill_save_type_payment_card));
        } else if ((type & SaveInfo.SAVE_DATA_TYPE_CREDIT_CARD) != 0) {
            types.add(context.getString(R.string.autofill_save_type_credit_card));
        } else if ((type & SaveInfo.SAVE_DATA_TYPE_DEBIT_CARD) != 0) {
            types.add(context.getString(R.string.autofill_save_type_debit_card));
        }
        if ((type & SaveInfo.SAVE_DATA_TYPE_USERNAME) != 0) {
            types.add(context.getString(R.string.autofill_save_type_username));
@@ -269,7 +281,9 @@ final class SaveUi {
        noButton.setOnClickListener((v) -> mListener.onCancel(info.getNegativeActionListener()));

        final TextView yesButton = view.findViewById(R.id.autofill_save_yes);
        if (isUpdate) {
        if (info.getPositiveActionStyle() == SaveInfo.POSITIVE_BUTTON_STYLE_CONTINUE) {
            yesButton.setText(R.string.autofill_continue_yes);
        } else if (isUpdate) {
            yesButton.setText(R.string.autofill_update_yes);
        }
        yesButton.setOnClickListener((v) -> mListener.onSave());