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

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

Improve error message when expecting a non-virtual autofill id.

Bug: 122959591

Test: atest CtsContentCaptureServiceTestCases
Test: mmm frameworks/base/:doc-comment-check-docs

Change-Id: I183771036e27bc770b9f895e1afd4a30b499b1a1
parent c5689d35
Loading
Loading
Loading
Loading
+6 −6
Original line number Original line Diff line number Diff line
@@ -47,20 +47,20 @@ public final class AutofillId implements Parcelable {


    /** @hide */
    /** @hide */
    @TestApi
    @TestApi
    public AutofillId(@NonNull AutofillId parent, int virtualChildId) {
    public AutofillId(@NonNull AutofillId hostId, int virtualChildId) {
        this(FLAG_IS_VIRTUAL_INT, parent.mViewId, virtualChildId, NO_SESSION);
        this(FLAG_IS_VIRTUAL_INT, hostId.mViewId, virtualChildId, NO_SESSION);
    }
    }


    /** @hide */
    /** @hide */
    @TestApi
    @TestApi
    public AutofillId(int parentId, int virtualChildId) {
    public AutofillId(int hostId, int virtualChildId) {
        this(FLAG_IS_VIRTUAL_INT, parentId, virtualChildId, NO_SESSION);
        this(FLAG_IS_VIRTUAL_INT, hostId, virtualChildId, NO_SESSION);
    }
    }


    /** @hide */
    /** @hide */
    @TestApi
    @TestApi
    public AutofillId(@NonNull AutofillId parent, long virtualChildId, int sessionId) {
    public AutofillId(@NonNull AutofillId hostId, long virtualChildId, int sessionId) {
        this(FLAG_IS_VIRTUAL_LONG | FLAG_HAS_SESSION, parent.mViewId, virtualChildId, sessionId);
        this(FLAG_IS_VIRTUAL_LONG | FLAG_HAS_SESSION, hostId.mViewId, virtualChildId, sessionId);
    }
    }


    private AutofillId(int flags, int parentId, long virtualChildId, int sessionId) {
    private AutofillId(int flags, int parentId, long virtualChildId, int sessionId) {
+9 −8
Original line number Original line Diff line number Diff line
@@ -389,7 +389,8 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     *
     *
     * <p>Should only be called by views that handle their own virtual view hierarchy.
     * <p>Should only be called by views that handle their own virtual view hierarchy.
     *
     *
     * @param hostId id of the view hosting the virtual hierarchy.
     * @param hostId id of the non-virtual view hosting the virtual view hierarchy (it can be
     * obtained by calling {@link ViewStructure#getAutofillId()}).
     * @param virtualIds ids of the virtual children.
     * @param virtualIds ids of the virtual children.
     *
     *
     * @throws IllegalArgumentException if the {@code hostId} is an autofill id for a virtual view.
     * @throws IllegalArgumentException if the {@code hostId} is an autofill id for a virtual view.
@@ -397,7 +398,7 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     */
     */
    public final void notifyViewsDisappeared(@NonNull AutofillId hostId,
    public final void notifyViewsDisappeared(@NonNull AutofillId hostId,
            @NonNull long[] virtualIds) {
            @NonNull long[] virtualIds) {
        Preconditions.checkArgument(hostId.isNonVirtual(), "parent cannot be virtual");
        Preconditions.checkArgument(hostId.isNonVirtual(), "hostId cannot be virtual: %s", hostId);
        Preconditions.checkArgument(!ArrayUtils.isEmpty(virtualIds), "virtual ids cannot be empty");
        Preconditions.checkArgument(!ArrayUtils.isEmpty(virtualIds), "virtual ids cannot be empty");
        if (!isContentCaptureEnabled()) return;
        if (!isContentCaptureEnabled()) return;


@@ -442,18 +443,18 @@ public abstract class ContentCaptureSession implements AutoCloseable {
     * Creates a new {@link AutofillId} for a virtual child, so it can be used to uniquely identify
     * Creates a new {@link AutofillId} for a virtual child, so it can be used to uniquely identify
     * the children in the session.
     * the children in the session.
     *
     *
     * @param parentId id of the virtual view parent (it can be obtained by calling
     * @param hostId id of the non-virtual view hosting the virtual view hierarchy (it can be
     * {@link ViewStructure#getAutofillId()} on the parent).
     * obtained by calling {@link ViewStructure#getAutofillId()}).
     * @param virtualChildId id of the virtual child, relative to the parent.
     * @param virtualChildId id of the virtual child, relative to the parent.
     *
     *
     * @return if for the virtual child
     * @return if for the virtual child
     *
     *
     * @throws IllegalArgumentException if the {@code parentId} is a virtual child id.
     * @throws IllegalArgumentException if the {@code parentId} is a virtual child id.
     */
     */
    public @NonNull AutofillId newAutofillId(@NonNull AutofillId parentId, long virtualChildId) {
    public @NonNull AutofillId newAutofillId(@NonNull AutofillId hostId, long virtualChildId) {
        Preconditions.checkNotNull(parentId);
        Preconditions.checkNotNull(hostId);
        Preconditions.checkArgument(parentId.isNonVirtual(), "virtual ids cannot have children");
        Preconditions.checkArgument(hostId.isNonVirtual(), "hostId cannot be virtual: %s", hostId);
        return new AutofillId(parentId, virtualChildId, getIdAsInt());
        return new AutofillId(hostId, virtualChildId, getIdAsInt());
    }
    }


    /**
    /**