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

Commit d55b16e7 authored by Adam He's avatar Adam He
Browse files

Implement AssistStructure.ViewNode.getHintIdEntry().

Bug: 135134274
Test: atest CtsAutoFillServiceTestCases
Test: atest android.contentcaptureservice.cts.unit.ViewNodeTest
Change-Id: I7154cf97a5236ad975bd774c29b30e055cfca8bd
parent 63bc5be9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -7165,6 +7165,7 @@ package android.app.assist {
    method public android.os.Bundle getExtras();
    method public int getHeight();
    method public String getHint();
    method @Nullable public String getHintIdEntry();
    method @Nullable public android.view.ViewStructure.HtmlInfo getHtmlInfo();
    method public int getId();
    method public String getIdEntry();
@@ -51426,6 +51427,7 @@ package android.view {
    method public abstract void setFocusable(boolean);
    method public abstract void setFocused(boolean);
    method public abstract void setHint(CharSequence);
    method public void setHintIdEntry(@NonNull String);
    method public abstract void setHtmlInfo(@NonNull android.view.ViewStructure.HtmlInfo);
    method public abstract void setId(int, String, String, String);
    method public void setImportantForAutofill(int);
+40 −12
Original line number Diff line number Diff line
@@ -641,6 +641,7 @@ public class AssistStructure implements Parcelable {
        int mMaxEms = -1;
        int mMaxLength = -1;
        @Nullable String mTextIdEntry;
        @Nullable String mHintIdEntry;
        @AutofillImportance int mImportantForAutofill;

        // POJO used to override some autofill-related values when the node is parcelized.
@@ -688,18 +689,19 @@ public class AssistStructure implements Parcelable {
        static final int FLAGS_HAS_LOCALE_LIST = 0x00010000;
        static final int FLAGS_ALL_CONTROL = 0xfff00000;

        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_VIEW_ID =         0x001;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_VIRTUAL_VIEW_ID = 0x002;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_VALUE =           0x004;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_TYPE =            0x008;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_HINTS =           0x010;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_OPTIONS =         0x020;
        static final int AUTOFILL_FLAGS_HAS_HTML_INFO =                0x040;
        static final int AUTOFILL_FLAGS_HAS_TEXT_ID_ENTRY =            0x080;
        static final int AUTOFILL_FLAGS_HAS_MIN_TEXT_EMS =             0x100;
        static final int AUTOFILL_FLAGS_HAS_MAX_TEXT_EMS =             0x200;
        static final int AUTOFILL_FLAGS_HAS_MAX_TEXT_LENGTH =          0x400;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_SESSION_ID =      0x800;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_VIEW_ID =         0x0001;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_VIRTUAL_VIEW_ID = 0x0002;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_VALUE =           0x0004;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_TYPE =            0x0008;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_HINTS =           0x0010;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_OPTIONS =         0x0020;
        static final int AUTOFILL_FLAGS_HAS_HTML_INFO =                0x0040;
        static final int AUTOFILL_FLAGS_HAS_TEXT_ID_ENTRY =            0x0080;
        static final int AUTOFILL_FLAGS_HAS_MIN_TEXT_EMS =             0x0100;
        static final int AUTOFILL_FLAGS_HAS_MAX_TEXT_EMS =             0x0200;
        static final int AUTOFILL_FLAGS_HAS_MAX_TEXT_LENGTH =          0x0400;
        static final int AUTOFILL_FLAGS_HAS_AUTOFILL_SESSION_ID =      0x0800;
        static final int AUTOFILL_FLAGS_HAS_HINT_ID_ENTRY =            0x1000;

        int mFlags;
        int mAutofillFlags;
@@ -786,6 +788,9 @@ public class AssistStructure implements Parcelable {
                if ((autofillFlags & AUTOFILL_FLAGS_HAS_TEXT_ID_ENTRY) != 0) {
                    mTextIdEntry = preader.readString();
                }
                if ((autofillFlags & AUTOFILL_FLAGS_HAS_HINT_ID_ENTRY) != 0) {
                    mHintIdEntry = preader.readString();
                }
            }
            if ((flags&FLAGS_HAS_LARGE_COORDS) != 0) {
                mX = in.readInt();
@@ -934,6 +939,9 @@ public class AssistStructure implements Parcelable {
            if (mTextIdEntry != null) {
                autofillFlags |= AUTOFILL_FLAGS_HAS_TEXT_ID_ENTRY;
            }
            if (mHintIdEntry != null) {
                autofillFlags |= AUTOFILL_FLAGS_HAS_HINT_ID_ENTRY;
            }

            pwriter.writeString(mClassName);

@@ -1011,6 +1019,9 @@ public class AssistStructure implements Parcelable {
                if ((autofillFlags & AUTOFILL_FLAGS_HAS_TEXT_ID_ENTRY) != 0) {
                    pwriter.writeString(mTextIdEntry);
                }
                if ((autofillFlags & AUTOFILL_FLAGS_HAS_HINT_ID_ENTRY) != 0) {
                    pwriter.writeString(mHintIdEntry);
                }
            }
            if ((flags&FLAGS_HAS_LARGE_COORDS) != 0) {
                out.writeInt(mX);
@@ -1585,6 +1596,17 @@ public class AssistStructure implements Parcelable {
            return mText != null ? mText.mHint : null;
        }

        /**
         * Gets the identifier used to set the hint associated with this view.
         *
         * <p>It's only relevant when the {@link AssistStructure} is used for autofill purposes,
         * not for assist purposes.
         */
        @Nullable
        public String getHintIdEntry() {
            return mHintIdEntry;
        }

        /**
         * Return a Bundle containing optional vendor-specific extension information.
         */
@@ -1852,6 +1874,11 @@ public class AssistStructure implements Parcelable {
            getNodeText().mHint = hint != null ? hint.toString() : null;
        }

        @Override
        public void setHintIdEntry(@NonNull String entryName) {
            mNode.mHintIdEntry = Preconditions.checkNotNull(entryName);
        }

        @Override
        public CharSequence getText() {
            return mNode.mText != null ? mNode.mText.mText : null;
@@ -2266,6 +2293,7 @@ public class AssistStructure implements Parcelable {
        String hint = node.getHint();
        if (hint != null) {
            Log.i(TAG, prefix + "  Hint: " + hint);
            Log.i(TAG, prefix + "  Resource id: " + node.getHintIdEntry());
        }
        Bundle extras = node.getExtras();
        if (extras != null) {
+1 −1
Original line number Diff line number Diff line
@@ -8486,7 +8486,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     * </ul>
     *
     * <p>It's also recommended to set the following properties - the more properties the structure
     * has, the higher the changes of an {@link android.service.autofill.AutofillService} properly
     * has, the higher the chances of an {@link android.service.autofill.AutofillService} properly
     * using the structure:
     *
     * <ul>
+10 −0
Original line number Diff line number Diff line
@@ -227,6 +227,16 @@ public abstract class ViewStructure {
     */
    public abstract void setHint(CharSequence hint);

    /**
     * Sets the identifier used to set the hint associated with this view.
     *
     * <p>Should only be set when the node is used for autofill purposes - it will be ignored
     * when used for Assist.
     */
    public void setHintIdEntry(@NonNull String entryName) {
        Preconditions.checkNotNull(entryName);
    }

    /**
     * Retrieve the last {@link #setText(CharSequence)}.
     */
+22 −1
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ public final class ViewNode extends AssistStructure.ViewNode {
    private static final long FLAGS_HAS_AUTOFILL_VALUE = 1L << 32;
    private static final long FLAGS_HAS_AUTOFILL_HINTS = 1L << 33;
    private static final long FLAGS_HAS_AUTOFILL_OPTIONS = 1L << 34;
    private static final long FLAGS_HAS_HINT_ID_ENTRY = 1L << 35;

    /** Flags used to optimize what's written to the parcel */
    private long mFlags;
@@ -108,6 +109,7 @@ public final class ViewNode extends AssistStructure.ViewNode {
    private int mMaxEms = -1;
    private int mMaxLength = -1;
    private String mTextIdEntry;
    private String mHintIdEntry;
    private @View.AutofillType int mAutofillType = View.AUTOFILL_TYPE_NONE;
    private String[] mAutofillHints;
    private AutofillValue mAutofillValue;
@@ -195,6 +197,9 @@ public final class ViewNode extends AssistStructure.ViewNode {
        if ((nodeFlags & FLAGS_HAS_AUTOFILL_OPTIONS) != 0) {
            mAutofillOptions = parcel.readCharSequenceArray();
        }
        if ((nodeFlags & FLAGS_HAS_HINT_ID_ENTRY) != 0) {
            mHintIdEntry = parcel.readString();
        }
    }

    /**
@@ -351,6 +356,11 @@ public final class ViewNode extends AssistStructure.ViewNode {
        return mText != null ? mText.mHint : null;
    }

    @Override
    public String getHintIdEntry() {
        return mHintIdEntry;
    }

    @Override
    public int getTextSelectionStart() {
        return mText != null ? mText.mTextSelectionStart : -1;
@@ -512,6 +522,9 @@ public final class ViewNode extends AssistStructure.ViewNode {
        if (mAutofillOptions != null) {
            nodeFlags |= FLAGS_HAS_AUTOFILL_OPTIONS;
        }
        if (mHintIdEntry != null) {
            nodeFlags |= FLAGS_HAS_HINT_ID_ENTRY;
        }
        parcel.writeLong(nodeFlags);

        if ((nodeFlags & FLAGS_HAS_AUTOFILL_ID) != 0) {
@@ -585,6 +598,9 @@ public final class ViewNode extends AssistStructure.ViewNode {
        if ((nodeFlags & FLAGS_HAS_AUTOFILL_OPTIONS) != 0) {
            parcel.writeCharSequenceArray(mAutofillOptions);
        }
        if ((nodeFlags & FLAGS_HAS_HINT_ID_ENTRY) != 0) {
            parcel.writeString(mHintIdEntry);
        }
    }

    /** @hide */
@@ -783,7 +799,7 @@ public final class ViewNode extends AssistStructure.ViewNode {
        }

        @Override
        public void setTextIdEntry(String entryName) {
        public void setTextIdEntry(@NonNull String entryName) {
            mNode.mTextIdEntry = Preconditions.checkNotNull(entryName);
        }

@@ -792,6 +808,11 @@ public final class ViewNode extends AssistStructure.ViewNode {
            getNodeText().mHint = hint != null ? hint.toString() : null;
        }

        @Override
        public void setHintIdEntry(String entryName) {
            mNode.mHintIdEntry = Preconditions.checkNotNull(entryName);
        }

        @Override
        public CharSequence getText() {
            return mNode.getText();
Loading