Merge "Revert "Fix a11y cache correctness bug"" into pi-dev

This commit is contained in:
Qasid Sadiq
2019-02-22 23:43:54 +00:00
committed by Android (Google) Code Review
2 changed files with 3 additions and 31 deletions

View File

@@ -418,28 +418,20 @@ public class AccessibilityCache {
* *
* @param nodes The nodes in the hosting window. * @param nodes The nodes in the hosting window.
* @param rootNodeId The id of the root to evict. * @param rootNodeId The id of the root to evict.
*
* @return {@code true} if the cache was cleared
*/ */
private boolean clearSubTreeRecursiveLocked(LongSparseArray<AccessibilityNodeInfo> nodes, private void clearSubTreeRecursiveLocked(LongSparseArray<AccessibilityNodeInfo> nodes,
long rootNodeId) { long rootNodeId) {
AccessibilityNodeInfo current = nodes.get(rootNodeId); AccessibilityNodeInfo current = nodes.get(rootNodeId);
if (current == null) { if (current == null) {
// The node isn't in the cache, but its descendents might be. return;
clear();
return true;
} }
nodes.remove(rootNodeId); nodes.remove(rootNodeId);
final int childCount = current.getChildCount(); final int childCount = current.getChildCount();
for (int i = 0; i < childCount; i++) { for (int i = 0; i < childCount; i++) {
final long childNodeId = current.getChildId(i); final long childNodeId = current.getChildId(i);
if (clearSubTreeRecursiveLocked(nodes, childNodeId)) { clearSubTreeRecursiveLocked(nodes, childNodeId);
current.recycle();
return true;
}
} }
current.recycle(); current.recycle();
return false;
} }
/** /**

View File

@@ -299,26 +299,6 @@ public class AccessibilityCacheTest {
} }
} }
@Test
public void subTreeChangeEventFromUncachedNode_clearsNodeInCache() {
AccessibilityNodeInfo nodeInfo = getNodeWithA11yAndWindowId(CHILD_VIEW_ID, WINDOW_ID_1);
long id = nodeInfo.getSourceNodeId();
mAccessibilityCache.add(nodeInfo);
nodeInfo.recycle();
AccessibilityEvent event = AccessibilityEvent
.obtain(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
event.setContentChangeTypes(AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE);
event.setSource(getMockViewWithA11yAndWindowIds(PARENT_VIEW_ID, WINDOW_ID_1));
mAccessibilityCache.onAccessibilityEvent(event);
AccessibilityNodeInfo shouldBeNull = mAccessibilityCache.getNode(WINDOW_ID_1, id);
if (shouldBeNull != null) {
shouldBeNull.recycle();
}
assertNull(shouldBeNull);
}
@Test @Test
public void scrollEvent_clearsNodeAndChild() { public void scrollEvent_clearsNodeAndChild() {
AccessibilityEvent event = AccessibilityEvent AccessibilityEvent event = AccessibilityEvent