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

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

Changed Dataset.setValue() methods to allow filtering with authentication.

The Dataset.setValue() methods were created before Datasets supported
RemoteViews as presentation. As such, the service always had to provide a
value for the dataset fields, and the value could not be used for filtering
(otherwise the user could "guess" what that authenticaed values were).

But once Dataset required RemoteViews for presentation, the field values were
not used anymore when the dataset required authentication (in fact, the
setValue() methods accepted null for the value), so now we can always use the
field values for filtering.

Test: atest CtsAutoFillServiceTestCases
Fixes: 69458842

Change-Id: Ia58af8bb946f31c3806c28570b2445870d7ccf0c
parent 601d2200
Loading
Loading
Loading
Loading
+19 −2
Original line number Diff line number Diff line
@@ -303,6 +303,10 @@ public final class Dataset implements Parcelable {
         * in the constructor in a dataset that is meant to be shown to the user, the autofill UI
         * for this field will not be displayed.
         *
         * <p><b>Note:</b> On Android {@link android.os.Build.VERSION_CODES#P} and
         * higher, datasets that require authentication can be also be filtered by passing a
         * {@link AutofillValue#forText(CharSequence) text value} as the {@code value} parameter.
         *
         * @param id id returned by {@link
         *         android.app.assist.AssistStructure.ViewNode#getAutofillId()}.
         * @param value value to be autofilled. Pass {@code null} if you do not have the value
@@ -320,6 +324,10 @@ public final class Dataset implements Parcelable {
         * Sets the value of a field, using a custom {@link RemoteViews presentation} to
         * visualize it.
         *
         * <p><b>Note:</b> On Android {@link android.os.Build.VERSION_CODES#P} and
         * higher, datasets that require authentication can be also be filtered by passing a
         * {@link AutofillValue#forText(CharSequence) text value} as the  {@code value} parameter.
         *
         * @param id id returned by {@link
         *         android.app.assist.AssistStructure.ViewNode#getAutofillId()}.
         * @param value the value to be autofilled. Pass {@code null} if you do not have the value
@@ -340,12 +348,16 @@ public final class Dataset implements Parcelable {
        /**
         * Sets the value of a field using an <a href="#Filtering">explicit filter</a>.
         *
         * <p>This method is typically used when the dataset is authenticated and the service
         * <p>This method is typically used when the dataset requires authentication and the service
         * does not know its value but wants to hide the dataset after the user enters a minimum
         * number of characters. For example, if the dataset represents a credit card number and the
         * service does not want to show the "Tap to authenticate" message until the user tapped
         * 4 digits, in which case the filter would be {@code Pattern.compile("\\d.{4,}")}.
         *
         * <p><b>Note:</b> If the dataset requires authentication but the service knows its text
         * value it's easier to filter by calling {@link #setValue(AutofillId, AutofillValue)} and
         * use the value to filter.
         *
         * @param id id returned by {@link
         *         android.app.assist.AssistStructure.ViewNode#getAutofillId()}.
         * @param value the value to be autofilled. Pass {@code null} if you do not have the value
@@ -371,12 +383,16 @@ public final class Dataset implements Parcelable {
         * Sets the value of a field, using a custom {@link RemoteViews presentation} to
         * visualize it and a <a href="#Filtering">explicit filter</a>.
         *
         * <p>This method is typically used when the dataset is authenticated and the service
         * <p>This method is typically used when the dataset requires authentication and the service
         * does not know its value but wants to hide the dataset after the user enters a minimum
         * number of characters. For example, if the dataset represents a credit card number and the
         * service does not want to show the "Tap to authenticate" message until the user tapped
         * 4 digits, in which case the filter would be {@code Pattern.compile("\\d.{4,}")}.
         *
         * <p><b>Note:</b> If the dataset requires authentication but the service knows its text
         * value it's easier to filter by calling
         * {@link #setValue(AutofillId, AutofillValue, RemoteViews)} and using the value to filter.
         *
         * @param id id returned by {@link
         *         android.app.assist.AssistStructure.ViewNode#getAutofillId()}.
         * @param value the value to be autofilled. Pass {@code null} if you do not have the value
@@ -405,6 +421,7 @@ public final class Dataset implements Parcelable {
                if (existingIdx >= 0) {
                    mFieldValues.set(existingIdx, value);
                    mFieldPresentations.set(existingIdx, presentation);
                    mFieldFilters.set(existingIdx, filter);
                    return;
                }
            } else {
+1 −3
Original line number Diff line number Diff line
@@ -176,9 +176,7 @@ final class FillUi {
                    String valueText = null;
                    if (filter == null) {
                        final AutofillValue value = dataset.getFieldValues().get(index);
                        // If the dataset needs auth - don't add its text to allow guessing
                        // its content based on how filtering behaves.
                        if (value != null && value.isText() && dataset.getAuthentication() == null) {
                        if (value != null && value.isText()) {
                            valueText = value.getTextValue().toString().toLowerCase();
                        }
                    }