Merge "Changed the virtual ids on ContentCapture to be long."
This commit is contained in:
committed by
Android (Google) Code Review
commit
e0b050e1c3
@@ -52637,12 +52637,12 @@ package android.view.contentcapture {
|
||||
method @NonNull public final android.view.contentcapture.ContentCaptureSession createContentCaptureSession(@NonNull android.view.contentcapture.ContentCaptureContext);
|
||||
method public final void destroy();
|
||||
method public final android.view.contentcapture.ContentCaptureSessionId getContentCaptureSessionId();
|
||||
method @NonNull public android.view.autofill.AutofillId newAutofillId(@NonNull android.view.autofill.AutofillId, int);
|
||||
method @NonNull public final android.view.ViewStructure newVirtualViewStructure(@NonNull android.view.autofill.AutofillId, int);
|
||||
method @NonNull public android.view.autofill.AutofillId newAutofillId(@NonNull android.view.autofill.AutofillId, long);
|
||||
method @NonNull public final android.view.ViewStructure newVirtualViewStructure(@NonNull android.view.autofill.AutofillId, long);
|
||||
method public final void notifyViewAppeared(@NonNull android.view.ViewStructure);
|
||||
method public final void notifyViewDisappeared(@NonNull android.view.autofill.AutofillId);
|
||||
method public final void notifyViewTextChanged(@NonNull android.view.autofill.AutofillId, @Nullable CharSequence, int);
|
||||
method public final void notifyViewsDisappeared(@NonNull android.view.autofill.AutofillId, @NonNull int[]);
|
||||
method public final void notifyViewsDisappeared(@NonNull android.view.autofill.AutofillId, @NonNull long[]);
|
||||
}
|
||||
|
||||
public final class ContentCaptureSessionId implements android.os.Parcelable {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -34,26 +34,57 @@ public class AutofillIdTest {
|
||||
public void testNonVirtual() {
|
||||
final AutofillId id = new AutofillId(42);
|
||||
assertThat(id.getViewId()).isEqualTo(42);
|
||||
assertThat(id.isVirtual()).isFalse();
|
||||
assertThat(id.getVirtualChildId()).isEqualTo(View.NO_ID);
|
||||
assertThat(id.isNonVirtual()).isTrue();
|
||||
assertThat(id.isVirtualInt()).isFalse();
|
||||
assertThat(id.isVirtualLong()).isFalse();
|
||||
assertThat(id.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(id.getVirtualChildLongId()).isEqualTo(View.NO_ID);
|
||||
|
||||
final AutofillId clone = cloneThroughParcel(id);
|
||||
assertThat(clone.getViewId()).isEqualTo(42);
|
||||
assertThat(clone.isVirtual()).isFalse();
|
||||
assertThat(clone.getVirtualChildId()).isEqualTo(View.NO_ID);
|
||||
assertThat(clone.isNonVirtual()).isTrue();
|
||||
assertThat(clone.isVirtualInt()).isFalse();
|
||||
assertThat(clone.isVirtualLong()).isFalse();
|
||||
assertThat(clone.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(clone.getVirtualChildLongId()).isEqualTo(View.NO_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVirtual() {
|
||||
public void testVirtual_int() {
|
||||
final AutofillId id = new AutofillId(42, 108);
|
||||
assertThat(id.getViewId()).isEqualTo(42);
|
||||
assertThat(id.isVirtual()).isTrue();
|
||||
assertThat(id.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(id.isVirtualInt()).isTrue();
|
||||
assertThat(id.isVirtualLong()).isFalse();
|
||||
assertThat(id.isNonVirtual()).isFalse();
|
||||
assertThat(id.getVirtualChildIntId()).isEqualTo(108);
|
||||
assertThat(id.getVirtualChildLongId()).isEqualTo(View.NO_ID);
|
||||
|
||||
final AutofillId clone = cloneThroughParcel(id);
|
||||
assertThat(clone.getViewId()).isEqualTo(42);
|
||||
assertThat(clone.isVirtual()).isTrue();
|
||||
assertThat(clone.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(clone.isVirtualLong()).isFalse();
|
||||
assertThat(clone.isVirtualInt()).isTrue();
|
||||
assertThat(clone.isNonVirtual()).isFalse();
|
||||
assertThat(clone.getVirtualChildIntId()).isEqualTo(108);
|
||||
assertThat(clone.getVirtualChildLongId()).isEqualTo(View.NO_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVirtual_long() {
|
||||
final AutofillId id = new AutofillId(new AutofillId(42), 4815162342L, 108);
|
||||
assertThat(id.getViewId()).isEqualTo(42);
|
||||
assertThat(id.isVirtualLong()).isTrue();
|
||||
assertThat(id.isVirtualInt()).isFalse();
|
||||
assertThat(id.isNonVirtual()).isFalse();
|
||||
assertThat(id.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(id.getVirtualChildLongId()).isEqualTo(4815162342L);
|
||||
|
||||
final AutofillId clone = cloneThroughParcel(id);
|
||||
assertThat(clone.getViewId()).isEqualTo(42);
|
||||
assertThat(clone.isVirtualLong()).isTrue();
|
||||
assertThat(clone.isVirtualInt()).isFalse();
|
||||
assertThat(clone.isNonVirtual()).isFalse();
|
||||
assertThat(clone.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(clone.getVirtualChildLongId()).isEqualTo(4815162342L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -62,27 +93,33 @@ public class AutofillIdTest {
|
||||
|
||||
final AutofillId id = new AutofillId(new AutofillId(42), 108);
|
||||
assertThat(id.getViewId()).isEqualTo(42);
|
||||
assertThat(id.isVirtual()).isTrue();
|
||||
assertThat(id.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(id.isVirtualInt()).isTrue();
|
||||
assertThat(id.getVirtualChildIntId()).isEqualTo(108);
|
||||
|
||||
final AutofillId clone = cloneThroughParcel(id);
|
||||
assertThat(clone.getViewId()).isEqualTo(42);
|
||||
assertThat(clone.isVirtual()).isTrue();
|
||||
assertThat(clone.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(clone.isVirtualInt()).isTrue();
|
||||
assertThat(clone.getVirtualChildIntId()).isEqualTo(108);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVirtual_withSession() {
|
||||
final AutofillId id = new AutofillId(new AutofillId(42), 108, 666);
|
||||
final AutofillId id = new AutofillId(new AutofillId(42), 108L, 666);
|
||||
assertThat(id.getViewId()).isEqualTo(42);
|
||||
assertThat(id.isVirtual()).isTrue();
|
||||
assertThat(id.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(id.isVirtualLong()).isTrue();
|
||||
assertThat(id.isVirtualInt()).isFalse();
|
||||
assertThat(id.isNonVirtual()).isFalse();
|
||||
assertThat(id.getVirtualChildLongId()).isEqualTo(108L);
|
||||
assertThat(id.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(id.getSessionId()).isEqualTo(666);
|
||||
|
||||
final AutofillId clone = cloneThroughParcel(id);
|
||||
assertThat(clone.getViewId()).isEqualTo(42);
|
||||
assertThat(clone.isVirtual()).isTrue();
|
||||
assertThat(clone.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(clone.isVirtualLong()).isTrue();
|
||||
assertThat(clone.isVirtualInt()).isFalse();
|
||||
assertThat(clone.isNonVirtual()).isFalse();
|
||||
assertThat(clone.getVirtualChildLongId()).isEqualTo(108L);
|
||||
assertThat(clone.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(clone.getSessionId()).isEqualTo(666);
|
||||
}
|
||||
|
||||
@@ -118,13 +155,14 @@ public class AutofillIdTest {
|
||||
assertThat(virtualIdDifferentParent).isNotEqualTo(virtualIdDifferentChild);
|
||||
assertThat(virtualIdDifferentChild).isNotEqualTo(virtualIdDifferentParent);
|
||||
|
||||
final AutofillId virtualIdDifferentSession = new AutofillId(new AutofillId(42), 1, 108);
|
||||
final AutofillId virtualIdDifferentSession = new AutofillId(new AutofillId(42), 1L, 108);
|
||||
assertThat(virtualIdDifferentSession).isNotEqualTo(virtualId);
|
||||
assertThat(virtualId).isNotEqualTo(virtualIdDifferentSession);
|
||||
assertThat(virtualIdDifferentSession).isNotEqualTo(realId);
|
||||
assertThat(realId).isNotEqualTo(virtualIdDifferentSession);
|
||||
|
||||
final AutofillId sameVirtualIdDifferentSession = new AutofillId(new AutofillId(42), 1, 108);
|
||||
final AutofillId sameVirtualIdDifferentSession =
|
||||
new AutofillId(new AutofillId(42), 1L, 108);
|
||||
assertThat(sameVirtualIdDifferentSession).isEqualTo(virtualIdDifferentSession);
|
||||
assertThat(virtualIdDifferentSession).isEqualTo(sameVirtualIdDifferentSession);
|
||||
assertThat(sameVirtualIdDifferentSession.hashCode())
|
||||
|
||||
@@ -48,17 +48,18 @@ public class ContentCaptureSessionTest {
|
||||
|
||||
@Test
|
||||
public void testNewAutofillId_invalid() {
|
||||
assertThrows(NullPointerException.class, () -> mSession1.newAutofillId(null, 42));
|
||||
assertThrows(NullPointerException.class, () -> mSession1.newAutofillId(null, 42L));
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> mSession1.newAutofillId(new AutofillId(42, 42), 42));
|
||||
() -> mSession1.newAutofillId(new AutofillId(42, 42), 42L));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewAutofillId_valid() {
|
||||
final AutofillId parentId = new AutofillId(42);
|
||||
final AutofillId childId = mSession1.newAutofillId(parentId, 108);
|
||||
final AutofillId childId = mSession1.newAutofillId(parentId, 108L);
|
||||
assertThat(childId.getViewId()).isEqualTo(42);
|
||||
assertThat(childId.getVirtualChildId()).isEqualTo(108);
|
||||
assertThat(childId.getVirtualChildLongId()).isEqualTo(108L);
|
||||
assertThat(childId.getVirtualChildIntId()).isEqualTo(View.NO_ID);
|
||||
assertThat(childId.getSessionId()).isEqualTo(mSession1.getIdAsInt());
|
||||
}
|
||||
|
||||
@@ -66,8 +67,8 @@ public class ContentCaptureSessionTest {
|
||||
public void testNewAutofillId_differentSessions() {
|
||||
assertThat(mSession1.getIdAsInt()).isNotSameAs(mSession2.getIdAsInt()); //sanity check
|
||||
final AutofillId parentId = new AutofillId(42);
|
||||
final AutofillId childId1 = mSession1.newAutofillId(parentId, 108);
|
||||
final AutofillId childId2 = mSession2.newAutofillId(parentId, 108);
|
||||
final AutofillId childId1 = mSession1.newAutofillId(parentId, 108L);
|
||||
final AutofillId childId2 = mSession2.newAutofillId(parentId, 108L);
|
||||
assertThat(childId1).isNotEqualTo(childId2);
|
||||
assertThat(childId2).isNotEqualTo(childId1);
|
||||
}
|
||||
@@ -91,9 +92,9 @@ public class ContentCaptureSessionTest {
|
||||
@Test
|
||||
public void testNewVirtualViewStructure() {
|
||||
final AutofillId parentId = new AutofillId(42);
|
||||
final ViewStructure structure = mSession1.newVirtualViewStructure(parentId, 108);
|
||||
final ViewStructure structure = mSession1.newVirtualViewStructure(parentId, 108L);
|
||||
assertThat(structure).isNotNull();
|
||||
final AutofillId childId = mSession1.newAutofillId(parentId, 108);
|
||||
final AutofillId childId = mSession1.newAutofillId(parentId, 108L);
|
||||
assertThat(structure.getAutofillId()).isEqualTo(childId);
|
||||
}
|
||||
|
||||
@@ -101,16 +102,16 @@ public class ContentCaptureSessionTest {
|
||||
public void testNotifyViewsDisappeared_invalid() {
|
||||
// Null parent
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> mSession1.notifyViewsDisappeared(null, new int[] {42}));
|
||||
() -> mSession1.notifyViewsDisappeared(null, new long[] {42}));
|
||||
// Null child
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> mSession1.notifyViewsDisappeared(new AutofillId(42), null));
|
||||
// Empty child
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> mSession1.notifyViewsDisappeared(new AutofillId(42), new int[] {}));
|
||||
() -> mSession1.notifyViewsDisappeared(new AutofillId(42), new long[] {}));
|
||||
// Virtual parent
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> mSession1.notifyViewsDisappeared(new AutofillId(42, 108), new int[] {666}));
|
||||
() -> mSession1.notifyViewsDisappeared(new AutofillId(42, 108), new long[] {666}));
|
||||
}
|
||||
|
||||
// Cannot use @Spy because we need to pass the session id on constructor
|
||||
|
||||
Reference in New Issue
Block a user