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

Commit 7c2e5bb7 authored by Nikita Dubrovsky's avatar Nikita Dubrovsky
Browse files

Remove AUTOFILL_TYPE_RICH_CONTENT and related code

This reverts the autofill API changes made in ag/9884022 (only the
autofill-related changes in that CL, not the rest). This is because
non-text content in autofill is now handled via a separate code path
rather than via an autofill type (the new pipe for rich content was
added in ag/12642608).

Bug: 168837034
Test: Manual (image suggestions in augmented autofill)
Test: atest FrameworksCoreTests:AutofillValueTest
Test: atest CtsWidgetTestCases:TextViewOnReceiveContentTest
Change-Id: I261148646d21474ea10662a3e6a5d8b0ba6708f4
parent b4766c20
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -47911,7 +47911,6 @@ package android.view {
    field public static final int AUTOFILL_TYPE_DATE = 4; // 0x4
    field public static final int AUTOFILL_TYPE_LIST = 3; // 0x3
    field public static final int AUTOFILL_TYPE_NONE = 0; // 0x0
    field public static final int AUTOFILL_TYPE_RICH_CONTENT = 5; // 0x5
    field public static final int AUTOFILL_TYPE_TEXT = 1; // 0x1
    field public static final int AUTOFILL_TYPE_TOGGLE = 2; // 0x2
    field public static final int DRAG_FLAG_GLOBAL = 256; // 0x100
@@ -50184,17 +50183,14 @@ package android.view.autofill {
    method public int describeContents();
    method public static android.view.autofill.AutofillValue forDate(long);
    method public static android.view.autofill.AutofillValue forList(int);
    method @NonNull public static android.view.autofill.AutofillValue forRichContent(@NonNull android.content.ClipData);
    method public static android.view.autofill.AutofillValue forText(@Nullable CharSequence);
    method public static android.view.autofill.AutofillValue forToggle(boolean);
    method public long getDateValue();
    method public int getListValue();
    method @NonNull public android.content.ClipData getRichContentValue();
    method @NonNull public CharSequence getTextValue();
    method public boolean getToggleValue();
    method public boolean isDate();
    method public boolean isList();
    method public boolean isRichContent();
    method public boolean isText();
    method public boolean isToggle();
    method public void writeToParcel(android.os.Parcel, int);
+0 −12
Original line number Diff line number Diff line
@@ -1274,7 +1274,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            AUTOFILL_TYPE_TOGGLE,
            AUTOFILL_TYPE_LIST,
            AUTOFILL_TYPE_DATE,
            AUTOFILL_TYPE_RICH_CONTENT
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface AutofillType {}
@@ -1338,17 +1337,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    public static final int AUTOFILL_TYPE_DATE = 4;
    /**
     * Autofill type for a field that can accept rich content (text, images, etc).
     *
     * <p>{@link AutofillValue} instances for autofilling a {@link View} can be obtained through
     * {@link AutofillValue#forRichContent(ClipData)}, and the values passed to
     * autofill a {@link View} can be fetched through {@link AutofillValue#getRichContentValue()}.
     *
     * @see #getAutofillType()
     */
    public static final int AUTOFILL_TYPE_RICH_CONTENT = 5;
    /** @hide */
    @IntDef(prefix = { "IMPORTANT_FOR_AUTOFILL_" }, value = {
+0 −45
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.view.autofill;

import static android.view.View.AUTOFILL_TYPE_DATE;
import static android.view.View.AUTOFILL_TYPE_LIST;
import static android.view.View.AUTOFILL_TYPE_RICH_CONTENT;
import static android.view.View.AUTOFILL_TYPE_TEXT;
import static android.view.View.AUTOFILL_TYPE_TOGGLE;
import static android.view.autofill.Helper.sDebug;
@@ -26,7 +25,6 @@ import static android.view.autofill.Helper.sVerbose;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.ClipData;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
@@ -141,28 +139,6 @@ public final class AutofillValue implements Parcelable {
        return mType == AUTOFILL_TYPE_DATE;
    }

    /**
     * Gets the value to autofill a field that accepts rich content (text, images, etc).
     *
     * <p>See {@link View#AUTOFILL_TYPE_RICH_CONTENT} for more info.</p>
     *
     * @throws IllegalStateException if the value is not a content value
     */
    public @NonNull ClipData getRichContentValue() {
        Preconditions.checkState(isRichContent(),
                "value must be a rich content value, not type=%d", mType);
        return (ClipData) mValue;
    }

    /**
     * Checks if this is a rich content value (represented by {@link ClipData}).
     *
     * <p>See {@link View#AUTOFILL_TYPE_RICH_CONTENT} for more info.</p>
     */
    public boolean isRichContent() {
        return mType == AUTOFILL_TYPE_RICH_CONTENT;
    }

    /**
     * Used to define whether a field is empty so it's not sent to service on save.
     *
@@ -208,10 +184,6 @@ public final class AutofillValue implements Parcelable {
                .append(", value=");
        if (isText()) {
            Helper.appendRedacted(string, (CharSequence) mValue);
        } else if (isRichContent()) {
            string.append("{");
            getRichContentValue().getDescription().toShortStringTypesOnly(string);
            string.append("}");
        } else {
            string.append(mValue);
        }
@@ -244,9 +216,6 @@ public final class AutofillValue implements Parcelable {
            case AUTOFILL_TYPE_DATE:
                parcel.writeLong((Long) mValue);
                break;
            case AUTOFILL_TYPE_RICH_CONTENT:
                ((ClipData) mValue).writeToParcel(parcel, flags);
                break;
        }
    }

@@ -267,9 +236,6 @@ public final class AutofillValue implements Parcelable {
            case AUTOFILL_TYPE_DATE:
                mValue = parcel.readLong();
                break;
            case AUTOFILL_TYPE_RICH_CONTENT:
                mValue = ClipData.CREATOR.createFromParcel(parcel);
                break;
            default:
                throw new IllegalArgumentException("type=" + mType + " not valid");
        }
@@ -337,15 +303,4 @@ public final class AutofillValue implements Parcelable {
    public static AutofillValue forDate(long value) {
        return new AutofillValue(AUTOFILL_TYPE_DATE, value);
    }

    /**
     * Creates a new {@link AutofillValue} to autofill a {@link View} that accepts rich content
     * (text, images, etc).
     *
     * <p>See {@link View#AUTOFILL_TYPE_RICH_CONTENT} for more info.
     */
    public static @NonNull AutofillValue forRichContent(@NonNull ClipData value) {
        Objects.requireNonNull(value.getDescription(), "clip description must not be null");
        return new AutofillValue(AUTOFILL_TYPE_RICH_CONTENT, value);
    }
}
+2 −6
Original line number Diff line number Diff line
@@ -11862,16 +11862,12 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            Log.w(LOG_TAG, "cannot autofill non-editable TextView: " + this);
            return;
        }
        final ClipData clip;
        if (value.isRichContent()) {
            clip = value.getRichContentValue();
        } else if (value.isText()) {
            clip = ClipData.newPlainText("", value.getTextValue());
        } else {
        if (!value.isText()) {
            Log.w(LOG_TAG, "value of type " + value.describeContents()
                    + " cannot be autofilled into " + this);
            return;
        }
        final ClipData clip = ClipData.newPlainText("", value.getTextValue());
        final ContentInfo payload = new ContentInfo.Builder(clip, SOURCE_AUTOFILL).build();
        performReceiveContent(payload);
    }
+0 −17
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package android.view.autofill;

import static com.google.common.truth.Truth.assertThat;

import android.content.ClipData;
import android.os.Parcel;

import org.junit.Test;
@@ -39,20 +38,4 @@ public class AutofillValueTest {
        assertThat(result.isText()).isTrue();
        assertThat(result.getTextValue()).isEqualTo("hello");
    }

    @Test
    public void testWriteToParcel_richContent() throws Exception {
        ClipData clip = ClipData.newPlainText("my label", "hello");
        AutofillValue value = AutofillValue.forRichContent(clip);
        Parcel parcel = Parcel.obtain();
        value.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        AutofillValue result = AutofillValue.CREATOR.createFromParcel(parcel);
        assertThat(result.isRichContent()).isTrue();
        ClipData resultClip = result.getRichContentValue();
        assertThat(resultClip.getDescription().getLabel()).isEqualTo("my label");
        assertThat(resultClip.getItemAt(0).getText()).isEqualTo("hello");
        assertThat(resultClip.getDescription().getMimeType(0)).isEqualTo("text/plain");
    }
}