Merge "Changed the virtual ids on ContentCapture to be long."
This commit is contained in:
committed by
Android (Google) Code Review
commit
e0b050e1c3
@@ -8218,10 +8218,10 @@ public class Activity extends ContextThemeWrapper
|
||||
final AutofillId autofillId = autofillIds[i];
|
||||
final View view = autofillClientFindViewByAutofillIdTraversal(autofillId);
|
||||
if (view != null) {
|
||||
if (!autofillId.isVirtual()) {
|
||||
if (!autofillId.isVirtualInt()) {
|
||||
visible[i] = view.isVisibleToUser();
|
||||
} else {
|
||||
visible[i] = view.isVisibleToUserForAutofill(autofillId.getVirtualChildId());
|
||||
visible[i] = view.isVisibleToUserForAutofill(autofillId.getVirtualChildIntId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -894,7 +894,7 @@ public class AssistStructure implements Parcelable {
|
||||
}
|
||||
if (mAutofillId != null) {
|
||||
autofillFlags |= AUTOFILL_FLAGS_HAS_AUTOFILL_VIEW_ID;
|
||||
if (mAutofillId.isVirtual()) {
|
||||
if (mAutofillId.isVirtualInt()) {
|
||||
autofillFlags |= AUTOFILL_FLAGS_HAS_AUTOFILL_VIRTUAL_VIEW_ID;
|
||||
}
|
||||
}
|
||||
@@ -961,8 +961,9 @@ public class AssistStructure implements Parcelable {
|
||||
if ((autofillFlags & AUTOFILL_FLAGS_HAS_AUTOFILL_VIEW_ID) != 0) {
|
||||
out.writeInt(mAutofillId.getViewId());
|
||||
if ((autofillFlags & AUTOFILL_FLAGS_HAS_AUTOFILL_VIRTUAL_VIEW_ID) != 0) {
|
||||
out.writeInt(mAutofillId.getVirtualChildId());
|
||||
out.writeInt(mAutofillId.getVirtualChildIntId());
|
||||
}
|
||||
// TODO(b/113593220): write session id as well
|
||||
}
|
||||
if ((autofillFlags & AUTOFILL_FLAGS_HAS_AUTOFILL_TYPE) != 0) {
|
||||
out.writeInt(mAutofillType);
|
||||
|
||||
@@ -8203,10 +8203,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* {@link ContentCaptureSession#notifyViewDisappeared(AutofillId)}, and
|
||||
* {@link ContentCaptureSession#notifyViewTextChanged(AutofillId, CharSequence, int)}
|
||||
* respectively. The structure for the a child must be created using
|
||||
* {@link ContentCaptureSession#newVirtualViewStructure(AutofillId, int)}, and the
|
||||
* {@link ContentCaptureSession#newVirtualViewStructure(AutofillId, long)}, and the
|
||||
* {@code autofillId} for a child can be obtained either through
|
||||
* {@code childStructure.getAutofillId()} or
|
||||
* {@link ContentCaptureSession#newAutofillId(AutofillId, int)}.
|
||||
* {@link ContentCaptureSession#newAutofillId(AutofillId, long)}.
|
||||
*
|
||||
* <p><b>Note: </b>the following methods of the {@code structure} will be ignored:
|
||||
* <ul>
|
||||
@@ -8608,7 +8608,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
if (isAttachedToWindow()) {
|
||||
throw new IllegalStateException("Cannot set autofill id when view is attached");
|
||||
}
|
||||
if (id != null && id.isVirtual()) {
|
||||
if (id != null && !id.isNonVirtual()) {
|
||||
throw new IllegalStateException("Cannot set autofill id assigned to virtual views");
|
||||
}
|
||||
if (id == null && (mPrivateFlags3 & PFLAG3_AUTOFILLID_EXPLICITLY_SET) == 0) {
|
||||
|
||||
@@ -29,12 +29,14 @@ public final class AutofillId implements Parcelable {
|
||||
/** @hide */
|
||||
public static final int NO_SESSION = 0;
|
||||
|
||||
private static final int FLAG_IS_VIRTUAL = 0x1;
|
||||
private static final int FLAG_HAS_SESSION = 0x2;
|
||||
private static final int FLAG_IS_VIRTUAL_INT = 0x1;
|
||||
private static final int FLAG_IS_VIRTUAL_LONG = 0x2;
|
||||
private static final int FLAG_HAS_SESSION = 0x4;
|
||||
|
||||
private final int mViewId;
|
||||
private final int mFlags;
|
||||
private final int mVirtualId;
|
||||
private final int mVirtualIntId;
|
||||
private final long mVirtualLongId;
|
||||
private final int mSessionId;
|
||||
|
||||
/** @hide */
|
||||
@@ -46,40 +48,89 @@ public final class AutofillId implements Parcelable {
|
||||
/** @hide */
|
||||
@TestApi
|
||||
public AutofillId(@NonNull AutofillId parent, int virtualChildId) {
|
||||
this(FLAG_IS_VIRTUAL, parent.mViewId, virtualChildId, NO_SESSION);
|
||||
this(FLAG_IS_VIRTUAL_INT, parent.mViewId, virtualChildId, NO_SESSION);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public AutofillId(int parentId, int virtualChildId) {
|
||||
this(FLAG_IS_VIRTUAL, parentId, virtualChildId, NO_SESSION);
|
||||
this(FLAG_IS_VIRTUAL_INT, parentId, virtualChildId, NO_SESSION);
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public AutofillId(@NonNull AutofillId parent, int virtualChildId, int sessionId) {
|
||||
this(FLAG_IS_VIRTUAL | FLAG_HAS_SESSION, parent.mViewId, virtualChildId, sessionId);
|
||||
public AutofillId(@NonNull AutofillId parent, long virtualChildId, int sessionId) {
|
||||
this(FLAG_IS_VIRTUAL_LONG | FLAG_HAS_SESSION, parent.mViewId, virtualChildId, sessionId);
|
||||
}
|
||||
|
||||
private AutofillId(int flags, int parentId, int virtualChildId, int sessionId) {
|
||||
private AutofillId(int flags, int parentId, long virtualChildId, int sessionId) {
|
||||
mFlags = flags;
|
||||
mViewId = parentId;
|
||||
mVirtualId = virtualChildId;
|
||||
mVirtualIntId = ((flags & FLAG_IS_VIRTUAL_INT) != 0) ? (int) virtualChildId : View.NO_ID;
|
||||
mVirtualLongId = ((flags & FLAG_IS_VIRTUAL_LONG) != 0) ? virtualChildId : View.NO_ID;
|
||||
mSessionId = sessionId;
|
||||
}
|
||||
|
||||
|
||||
/** @hide */
|
||||
public int getViewId() {
|
||||
return mViewId;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public int getVirtualChildId() {
|
||||
return mVirtualId;
|
||||
/**
|
||||
* Gets the virtual child id.
|
||||
*
|
||||
* <p>Should only be used on subsystems where such id is represented by an {@code int}
|
||||
* (Assist and Autofill).
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public int getVirtualChildIntId() {
|
||||
return mVirtualIntId;
|
||||
}
|
||||
|
||||
/** @hide */
|
||||
public boolean isVirtual() {
|
||||
return (mFlags & FLAG_IS_VIRTUAL) != 0;
|
||||
/**
|
||||
* Gets the virtual child id.
|
||||
*
|
||||
* <p>Should only be used on subsystems where such id is represented by a {@code long}
|
||||
* (ContentCapture).
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public long getVirtualChildLongId() {
|
||||
return mVirtualLongId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this node represents a virtual child, whose id is represented by an
|
||||
* {@code int}.
|
||||
*
|
||||
* <p>Should only be used on subsystems where such id is represented by an {@code int}
|
||||
* (Assist and Autofill).
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean isVirtualInt() {
|
||||
return (mFlags & FLAG_IS_VIRTUAL_INT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this node represents a virtual child, whose id is represented by an
|
||||
* {@code long}.
|
||||
*
|
||||
* <p>Should only be used on subsystems where such id is represented by a {@code long}
|
||||
* (ContentCapture).
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean isVirtualLong() {
|
||||
return (mFlags & FLAG_IS_VIRTUAL_LONG) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether this node represents a non-virtual child.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public boolean isNonVirtual() {
|
||||
return !isVirtualInt() && !isVirtualLong();
|
||||
}
|
||||
|
||||
private boolean hasSession() {
|
||||
@@ -100,7 +151,8 @@ public final class AutofillId implements Parcelable {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + mViewId;
|
||||
result = prime * result + mVirtualId;
|
||||
result = prime * result + mVirtualIntId;
|
||||
result = prime * result + (int) (mVirtualLongId ^ (mVirtualLongId >>> 32));
|
||||
result = prime * result + mSessionId;
|
||||
return result;
|
||||
}
|
||||
@@ -112,7 +164,8 @@ public final class AutofillId implements Parcelable {
|
||||
if (getClass() != obj.getClass()) return false;
|
||||
final AutofillId other = (AutofillId) obj;
|
||||
if (mViewId != other.mViewId) return false;
|
||||
if (mVirtualId != other.mVirtualId) return false;
|
||||
if (mVirtualIntId != other.mVirtualIntId) return false;
|
||||
if (mVirtualLongId != other.mVirtualLongId) return false;
|
||||
if (mSessionId != other.mSessionId) return false;
|
||||
return true;
|
||||
}
|
||||
@@ -120,9 +173,12 @@ public final class AutofillId implements Parcelable {
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder().append(mViewId);
|
||||
if (isVirtual()) {
|
||||
builder.append(':').append(mVirtualId);
|
||||
if (isVirtualInt()) {
|
||||
builder.append(':').append(mVirtualIntId);
|
||||
} else if (isVirtualLong()) {
|
||||
builder.append(':').append(mVirtualLongId);
|
||||
}
|
||||
|
||||
if (hasSession()) {
|
||||
builder.append('@').append(mSessionId);
|
||||
}
|
||||
@@ -138,12 +194,14 @@ public final class AutofillId implements Parcelable {
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
parcel.writeInt(mViewId);
|
||||
parcel.writeInt(mFlags);
|
||||
if (isVirtual()) {
|
||||
parcel.writeInt(mVirtualId);
|
||||
}
|
||||
if (hasSession()) {
|
||||
parcel.writeInt(mSessionId);
|
||||
}
|
||||
if (isVirtualInt()) {
|
||||
parcel.writeInt(mVirtualIntId);
|
||||
} else if (isVirtualLong()) {
|
||||
parcel.writeLong(mVirtualLongId);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<AutofillId> CREATOR =
|
||||
@@ -152,9 +210,14 @@ public final class AutofillId implements Parcelable {
|
||||
public AutofillId createFromParcel(Parcel source) {
|
||||
final int viewId = source.readInt();
|
||||
final int flags = source.readInt();
|
||||
final int virtualId = (flags & FLAG_IS_VIRTUAL) != 0 ? source.readInt() : View.NO_ID;
|
||||
final int sessionId = (flags & FLAG_HAS_SESSION) != 0 ? source.readInt() : NO_SESSION;
|
||||
return new AutofillId(flags, viewId, virtualId, sessionId);
|
||||
if ((flags & FLAG_IS_VIRTUAL_INT) != 0) {
|
||||
return new AutofillId(flags, viewId, source.readInt(), sessionId);
|
||||
}
|
||||
if ((flags & FLAG_IS_VIRTUAL_LONG) != 0) {
|
||||
return new AutofillId(flags, viewId, source.readLong(), sessionId);
|
||||
}
|
||||
return new AutofillId(flags, viewId, View.NO_ID, sessionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1769,8 +1769,8 @@ public final class AutofillManager {
|
||||
}
|
||||
|
||||
if (callback != null) {
|
||||
if (id.isVirtual()) {
|
||||
callback.onAutofillEvent(anchor, id.getVirtualChildId(),
|
||||
if (id.isVirtualInt()) {
|
||||
callback.onAutofillEvent(anchor, id.getVirtualChildIntId(),
|
||||
AutofillCallback.EVENT_INPUT_SHOWN);
|
||||
} else {
|
||||
callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_SHOWN);
|
||||
@@ -1896,7 +1896,7 @@ public final class AutofillManager {
|
||||
failedIds.add(id);
|
||||
continue;
|
||||
}
|
||||
if (id.isVirtual()) {
|
||||
if (id.isVirtualInt()) {
|
||||
if (virtualValues == null) {
|
||||
// Most likely there will be just one view with virtual children.
|
||||
virtualValues = new ArrayMap<>(1);
|
||||
@@ -1907,7 +1907,7 @@ public final class AutofillManager {
|
||||
valuesByParent = new SparseArray<>(5);
|
||||
virtualValues.put(view, valuesByParent);
|
||||
}
|
||||
valuesByParent.put(id.getVirtualChildId(), value);
|
||||
valuesByParent.put(id.getVirtualChildIntId(), value);
|
||||
} else {
|
||||
// Mark the view as to be autofilled with 'value'
|
||||
if (mLastAutofilledData == null) {
|
||||
@@ -2142,8 +2142,8 @@ public final class AutofillManager {
|
||||
}
|
||||
|
||||
if (callback != null) {
|
||||
if (id.isVirtual()) {
|
||||
callback.onAutofillEvent(anchor, id.getVirtualChildId(),
|
||||
if (id.isVirtualInt()) {
|
||||
callback.onAutofillEvent(anchor, id.getVirtualChildIntId(),
|
||||
AutofillCallback.EVENT_INPUT_HIDDEN);
|
||||
} else {
|
||||
callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_HIDDEN);
|
||||
@@ -2169,8 +2169,8 @@ public final class AutofillManager {
|
||||
}
|
||||
|
||||
if (callback != null) {
|
||||
if (id.isVirtual()) {
|
||||
callback.onAutofillEvent(anchor, id.getVirtualChildId(),
|
||||
if (id.isVirtualInt()) {
|
||||
callback.onAutofillEvent(anchor, id.getVirtualChildIntId(),
|
||||
AutofillCallback.EVENT_INPUT_UNAVAILABLE);
|
||||
} else {
|
||||
callback.onAutofillEvent(anchor, AutofillCallback.EVENT_INPUT_UNAVAILABLE);
|
||||
|
||||
@@ -352,14 +352,14 @@ public abstract class ContentCaptureSession implements AutoCloseable {
|
||||
* @throws IllegalArgumentException if {@code virtualIds} is empty
|
||||
*/
|
||||
public final void notifyViewsDisappeared(@NonNull AutofillId hostId,
|
||||
@NonNull int[] virtualIds) {
|
||||
Preconditions.checkArgument(!hostId.isVirtual(), "parent cannot be virtual");
|
||||
@NonNull long[] virtualIds) {
|
||||
Preconditions.checkArgument(hostId.isNonVirtual(), "parent cannot be virtual");
|
||||
Preconditions.checkArgument(!ArrayUtils.isEmpty(virtualIds), "virtual ids cannot be empty");
|
||||
if (!isContentCaptureEnabled()) return;
|
||||
|
||||
// TODO(b/123036895): use a internalNotifyViewsDisappeared that optimizes how the event is
|
||||
// parcelized
|
||||
for (int id : virtualIds) {
|
||||
for (long id : virtualIds) {
|
||||
internalNotifyViewDisappeared(new AutofillId(hostId, id, getIdAsInt()));
|
||||
}
|
||||
}
|
||||
@@ -405,9 +405,9 @@ public abstract class ContentCaptureSession implements AutoCloseable {
|
||||
*
|
||||
* @throws IllegalArgumentException if the {@code parentId} is a virtual child id.
|
||||
*/
|
||||
public @NonNull AutofillId newAutofillId(@NonNull AutofillId parentId, int virtualChildId) {
|
||||
public @NonNull AutofillId newAutofillId(@NonNull AutofillId parentId, long virtualChildId) {
|
||||
Preconditions.checkNotNull(parentId);
|
||||
Preconditions.checkArgument(!parentId.isVirtual(), "virtual ids cannot have children");
|
||||
Preconditions.checkArgument(parentId.isNonVirtual(), "virtual ids cannot have children");
|
||||
return new AutofillId(parentId, virtualChildId, getIdAsInt());
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ public abstract class ContentCaptureSession implements AutoCloseable {
|
||||
*/
|
||||
@NonNull
|
||||
public final ViewStructure newVirtualViewStructure(@NonNull AutofillId parentId,
|
||||
int virtualId) {
|
||||
long virtualId) {
|
||||
return new ViewNode.ViewStructureImpl(parentId, virtualId, getIdAsInt());
|
||||
}
|
||||
|
||||
|
||||
@@ -617,7 +617,7 @@ public final class ViewNode extends AssistStructure.ViewNode {
|
||||
}
|
||||
|
||||
@VisibleForTesting // Must be public to be accessed from FrameworkCoreTests' apk.
|
||||
public ViewStructureImpl(@NonNull AutofillId parentId, int virtualId, int sessionId) {
|
||||
public ViewStructureImpl(@NonNull AutofillId parentId, long virtualId, int sessionId) {
|
||||
mNode.mParentAutofillId = Preconditions.checkNotNull(parentId);
|
||||
mNode.mAutofillId = new AutofillId(parentId, virtualId, sessionId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user