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

Commit 906b8537 authored by Felipe Leme's avatar Felipe Leme
Browse files

Uses Pattern instead of String for new Autofill Save API.

Test: CtsAutoFillServiceTestCases pass
Bug: 62534917

Change-Id: Ic285838465c2aa55e4935cdd8f00c551faa6a972
parent 7fc29dd9
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -36961,8 +36961,8 @@ package android.service.autofill {
  }
  public static class CharSequenceTransformation.Builder {
    ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
    ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation build();
  }
@@ -37058,8 +37058,8 @@ package android.service.autofill {
  }
  public static class ImageTransformation.Builder {
    ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, int);
    method public android.service.autofill.ImageTransformation.Builder addOption(java.lang.String, int);
    ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, int);
    method public android.service.autofill.ImageTransformation.Builder addOption(java.util.regex.Pattern, int);
    method public android.service.autofill.ImageTransformation build();
  }
@@ -37111,7 +37111,7 @@ package android.service.autofill {
  }
  public final class SimpleRegexValidator implements android.os.Parcelable android.service.autofill.Validator {
    ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.lang.String);
    ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.util.regex.Pattern);
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.autofill.SimpleRegexValidator> CREATOR;
+5 −5
Original line number Diff line number Diff line
@@ -40145,8 +40145,8 @@ package android.service.autofill {
  }
  public static class CharSequenceTransformation.Builder {
    ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
    ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation build();
  }
@@ -40242,8 +40242,8 @@ package android.service.autofill {
  }
  public static class ImageTransformation.Builder {
    ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, int);
    method public android.service.autofill.ImageTransformation.Builder addOption(java.lang.String, int);
    ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, int);
    method public android.service.autofill.ImageTransformation.Builder addOption(java.util.regex.Pattern, int);
    method public android.service.autofill.ImageTransformation build();
  }
@@ -40295,7 +40295,7 @@ package android.service.autofill {
  }
  public final class SimpleRegexValidator implements android.os.Parcelable android.service.autofill.Validator {
    ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.lang.String);
    ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.util.regex.Pattern);
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
    field public static final android.os.Parcelable.Creator<android.service.autofill.SimpleRegexValidator> CREATOR;
+5 −5
Original line number Diff line number Diff line
@@ -37126,8 +37126,8 @@ package android.service.autofill {
  }
  public static class CharSequenceTransformation.Builder {
    ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.lang.String, java.lang.String);
    ctor public CharSequenceTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation.Builder addField(android.view.autofill.AutofillId, java.util.regex.Pattern, java.lang.String);
    method public android.service.autofill.CharSequenceTransformation build();
  }
@@ -37224,8 +37224,8 @@ package android.service.autofill {
  }
  public static class ImageTransformation.Builder {
    ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.lang.String, int);
    method public android.service.autofill.ImageTransformation.Builder addOption(java.lang.String, int);
    ctor public ImageTransformation.Builder(android.view.autofill.AutofillId, java.util.regex.Pattern, int);
    method public android.service.autofill.ImageTransformation.Builder addOption(java.util.regex.Pattern, int);
    method public android.service.autofill.ImageTransformation build();
  }
@@ -37278,7 +37278,7 @@ package android.service.autofill {
  }
  public final class SimpleRegexValidator implements android.os.Parcelable android.service.autofill.Validator {
    ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.lang.String);
    ctor public SimpleRegexValidator(android.view.autofill.AutofillId, java.util.regex.Pattern);
    method public int describeContents();
    method public boolean isValid(android.service.autofill.ValueFinder);
    method public void writeToParcel(android.os.Parcel, int);
+14 −17
Original line number Diff line number Diff line
@@ -44,15 +44,17 @@ import java.util.regex.Pattern;
 * be:
 *
 * <pre class="prettyprint">
 * new CharSequenceTransformation.Builder(ccNumberId, "^.*(\\d\\d\\d\\d)$", "...$1").build();
 * new CharSequenceTransformation
 *     .Builder(ccNumberId, Pattern.compile("^.*(\\d\\d\\d\\d)$"), "...$1")
 *     .build();
 * </pre>
 *
 * <p>But a transformation that generates a {@code Exp: MM / YYYY} credit expiration date from two
 * fields (month and year) would be:
 *
 * <pre class="prettyprint">
 * new CharSequenceTransformation.Builder(ccExpMonthId, "^(\\d\\d)$", "Exp: $1")
 *   .addField(ccExpYearId, "^(\\d\\d\\d\\d)$", " / $1");
 * new CharSequenceTransformation.Builder(ccExpMonthId, Pattern.compile("^(\\d\\d)$"), "Exp: $1")
 *   .addField(ccExpYearId, Pattern.compile("^(\\d\\d\\d\\d)$"), " / $1");
 * </pre>
 */
public final class CharSequenceTransformation extends InternalTransformation implements
@@ -107,12 +109,11 @@ public final class CharSequenceTransformation extends InternalTransformation imp
         *
         * @param id id of the screen field.
         * @param regex regular expression with groups (delimited by {@code (} and {@code (}) that
         * are used to substitute parts of the value. The pattern will be {@link Pattern#compile
         * compiled} without setting any flags.
         * are used to substitute parts of the value.
         * @param subst the string that substitutes the matched regex, using {@code $} for
         * group substitution ({@code $1} for 1st group match, {@code $2} for 2nd, etc).
         */
        public Builder(@NonNull AutofillId id, @NonNull String regex, @NonNull String subst) {
        public Builder(@NonNull AutofillId id, @NonNull Pattern regex, @NonNull String subst) {
            addField(id, regex, subst);
        }

@@ -121,24 +122,20 @@ public final class CharSequenceTransformation extends InternalTransformation imp
         *
         * @param id id of the screen field.
         * @param regex regular expression with groups (delimited by {@code (} and {@code (}) that
         * are used to substitute parts of the value. The pattern will be {@link Pattern#compile
         * compiled} without setting any flags.
         * are used to substitute parts of the value.
         * @param subst the string that substitutes the matched regex, using {@code $} for
         * group substitution ({@code $1} for 1st group match, {@code $2} for 2nd, etc).
         *
         * @return this builder.
         */
        public Builder addField(@NonNull AutofillId id, @NonNull String regex,
        public Builder addField(@NonNull AutofillId id, @NonNull Pattern regex,
                @NonNull String subst) {
            throwIfDestroyed();
            Preconditions.checkNotNull(id);
            Preconditions.checkNotNull(regex);
            Preconditions.checkNotNull(subst);

            // Check if the regex is valid
            Pattern pattern = Pattern.compile(regex);

            mFields.put(id, new Pair<>(pattern, subst));
            mFields.put(id, new Pair<>(regex, subst));
            return this;
        }

@@ -178,17 +175,17 @@ public final class CharSequenceTransformation extends InternalTransformation imp
    public void writeToParcel(Parcel parcel, int flags) {
        final int size = mFields.size();
        final AutofillId[] ids = new AutofillId[size];
        final String[] regexs = new String[size];
        final Pattern[] regexs = new Pattern[size];
        final String[] substs = new String[size];
        Pair<Pattern, String> pair;
        for (int i = 0; i < size; i++) {
            ids[i] = mFields.keyAt(i);
            pair = mFields.valueAt(i);
            regexs[i] = pair.first.pattern();
            regexs[i] = pair.first;
            substs[i] = pair.second;
        }
        parcel.writeParcelableArray(ids, flags);
        parcel.writeStringArray(regexs);
        parcel.writeSerializable(regexs);
        parcel.writeStringArray(substs);
    }

@@ -197,7 +194,7 @@ public final class CharSequenceTransformation extends InternalTransformation imp
        @Override
        public CharSequenceTransformation createFromParcel(Parcel parcel) {
            final AutofillId[] ids = parcel.readParcelableArray(null, AutofillId.class);
            final String[] regexs = parcel.createStringArray();
            final Pattern[] regexs = (Pattern[]) parcel.readSerializable();
            final String[] substs = parcel.createStringArray();

            // Always go through the builder to ensure the data ingested by
+14 −21
Original line number Diff line number Diff line
@@ -42,9 +42,10 @@ import java.util.regex.Pattern;
 * <p>Typically used to display credit card logos. Example:
 *
 * <pre class="prettyprint">
 *   new ImageTransformation.Builder(ccNumberId, "^4815.*$", R.drawable.ic_credit_card_logo1)
 *     .addOption("^1623.*$", R.drawable.ic_credit_card_logo2)
 *     .addOption("^42.*$", R.drawable.ic_credit_card_logo3)
 *   new ImageTransformation.Builder(ccNumberId, Pattern.compile("^4815.*$"),
 *                                   R.drawable.ic_credit_card_logo1)
 *     .addOption(Pattern.compile("^1623.*$"), R.drawable.ic_credit_card_logo2)
 *     .addOption(Pattern.compile("^42.*$"), R.drawable.ic_credit_card_logo3)
 *     .build();
 * </pre>
 *
@@ -105,12 +106,11 @@ public final class ImageTransformation extends InternalTransformation implements
         *
         * @param id id of the screen field that will be used to evaluate whether the image should
         * be used.
         * @param regex regular expression defining what should be matched to use this image. The
         * pattern will be {@link Pattern#compile compiled} without setting any flags.
         * @param regex regular expression defining what should be matched to use this image.
         * @param resId resource id of the image (in the autofill service's package). The
         * {@link RemoteViews presentation} must contain a {@link ImageView} child with that id.
         */
        public Builder(@NonNull AutofillId id, @NonNull String regex, @DrawableRes int resId) {
        public Builder(@NonNull AutofillId id, @NonNull Pattern regex, @DrawableRes int resId) {
            mId = Preconditions.checkNotNull(id);

            addOption(regex, resId);
@@ -119,34 +119,27 @@ public final class ImageTransformation extends InternalTransformation implements
        /**
         * Adds an option to replace the child view with a different image when the regex matches.
         *
         * @param regex regular expression defining what should be matched to use this image. The
         * pattern will be {@link Pattern#compile compiled} without setting any flags.
         * @param regex regular expression defining what should be matched to use this image.
         * @param resId resource id of the image (in the autofill service's package). The
         * {@link RemoteViews presentation} must contain a {@link ImageView} child with that id.
         *
         * @return this build
         */
        public Builder addOption(@NonNull String regex, @DrawableRes int resId) {
        public Builder addOption(@NonNull Pattern regex, @DrawableRes int resId) {
            throwIfDestroyed();

            Preconditions.checkNotNull(regex);
            Preconditions.checkArgument(resId != 0);

            // Check regex
            Pattern pattern = Pattern.compile(regex);

            mOptions.add(new Pair<>(pattern, resId));
            mOptions.add(new Pair<>(regex, resId));
            return this;
        }

        /**
         * Creates a new {@link ImageTransformation} instance.
         *
         * @throws IllegalStateException if no call to {@link #addOption(String, int)} was made.
         */
        public ImageTransformation build() {
            throwIfDestroyed();
            Preconditions.checkState(mOptions != null && !mOptions.isEmpty(),
                    "Must add at least one option");
            mDestroyed = true;
            return new ImageTransformation(this);
        }
@@ -178,14 +171,14 @@ public final class ImageTransformation extends InternalTransformation implements
        parcel.writeParcelable(mId, flags);

        final int size = mOptions.size();
        final String[] regexs = new String[size];
        final Pattern[] regexs = new Pattern[size];
        final int[] resIds = new int[size];
        for (int i = 0; i < size; i++) {
            Pair<Pattern, Integer> regex = mOptions.get(i);
            regexs[i] = regex.first.pattern();
            regexs[i] = regex.first;
            resIds[i] = regex.second;
        }
        parcel.writeStringArray(regexs);
        parcel.writeSerializable(regexs);
        parcel.writeIntArray(resIds);
    }

@@ -195,7 +188,7 @@ public final class ImageTransformation extends InternalTransformation implements
        public ImageTransformation createFromParcel(Parcel parcel) {
            final AutofillId id = parcel.readParcelable(null);

            final String[] regexs = parcel.createStringArray();
            final Pattern[] regexs = (Pattern[]) parcel.readSerializable();
            final int[] resIds = parcel.createIntArray();

            // Always go through the builder to ensure the data ingested by the system obeys the
Loading