Use structural equality for A11yNodeInfo#mChildNodeIds

This reintroduces I508df9e4346e304b8ae56cc38b17e9a940d941f1
with the addition of missing nullchecks

A11yNodeInfo#writeToParcel relied on LongArray#equals to avoid
storing it if it's the default value, but because the equality
is be by reference, it would store it every time.
This fixes that.

Test: a11y cts
Change-Id: I8fadffb2508d819ae9a9db8c4298e8941a349627
Fixes: 72460870
This commit is contained in:
Eugene Susla
2018-02-08 15:14:06 -08:00
parent aa2c46cc81
commit 9669e3af65
2 changed files with 20 additions and 2 deletions

View File

@@ -16,11 +16,15 @@
package android.util;
import android.annotation.Nullable;
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Preconditions;
import java.util.Arrays;
import libcore.util.EmptyArray;
import java.util.Arrays;
/**
* Implements a growing array of long primitives.
*
@@ -216,4 +220,18 @@ public class LongArray implements Cloneable {
throw new ArrayIndexOutOfBoundsException(mSize, index);
}
}
/**
* Test if each element of {@code a} equals corresponding element from {@code b}
*/
public static boolean elementsEqual(@Nullable LongArray a, @Nullable LongArray b) {
if (a == null || b == null) return a == b;
if (a.mSize != b.mSize) return false;
for (int i = 0; i < a.mSize; i++) {
if (a.get(i) != b.get(i)) {
return false;
}
}
return true;
}
}

View File

@@ -3194,7 +3194,7 @@ public class AccessibilityNodeInfo implements Parcelable {
fieldIndex++;
if (mConnectionId != DEFAULT.mConnectionId) nonDefaultFields |= bitAt(fieldIndex);
fieldIndex++;
if (!Objects.equals(mChildNodeIds, DEFAULT.mChildNodeIds)) {
if (!LongArray.elementsEqual(mChildNodeIds, DEFAULT.mChildNodeIds)) {
nonDefaultFields |= bitAt(fieldIndex);
}
fieldIndex++;