Loading core/java/android/view/accessibility/AccessibilityCache.java +11 −3 Original line number Diff line number Diff line Loading @@ -418,20 +418,28 @@ public class AccessibilityCache { * * @param nodes The nodes in the hosting window. * @param rootNodeId The id of the root to evict. * * @return {@code true} if the cache was cleared */ private void clearSubTreeRecursiveLocked(LongSparseArray<AccessibilityNodeInfo> nodes, private boolean clearSubTreeRecursiveLocked(LongSparseArray<AccessibilityNodeInfo> nodes, long rootNodeId) { AccessibilityNodeInfo current = nodes.get(rootNodeId); if (current == null) { return; // The node isn't in the cache, but its descendents might be. clear(); return true; } nodes.remove(rootNodeId); final int childCount = current.getChildCount(); for (int i = 0; i < childCount; i++) { final long childNodeId = current.getChildId(i); clearSubTreeRecursiveLocked(nodes, childNodeId); if (clearSubTreeRecursiveLocked(nodes, childNodeId)) { current.recycle(); return true; } } current.recycle(); return false; } /** Loading core/tests/coretests/src/android/view/accessibility/AccessibilityCacheTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,26 @@ 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 public void scrollEvent_clearsNodeAndChild() { AccessibilityEvent event = AccessibilityEvent Loading Loading
core/java/android/view/accessibility/AccessibilityCache.java +11 −3 Original line number Diff line number Diff line Loading @@ -418,20 +418,28 @@ public class AccessibilityCache { * * @param nodes The nodes in the hosting window. * @param rootNodeId The id of the root to evict. * * @return {@code true} if the cache was cleared */ private void clearSubTreeRecursiveLocked(LongSparseArray<AccessibilityNodeInfo> nodes, private boolean clearSubTreeRecursiveLocked(LongSparseArray<AccessibilityNodeInfo> nodes, long rootNodeId) { AccessibilityNodeInfo current = nodes.get(rootNodeId); if (current == null) { return; // The node isn't in the cache, but its descendents might be. clear(); return true; } nodes.remove(rootNodeId); final int childCount = current.getChildCount(); for (int i = 0; i < childCount; i++) { final long childNodeId = current.getChildId(i); clearSubTreeRecursiveLocked(nodes, childNodeId); if (clearSubTreeRecursiveLocked(nodes, childNodeId)) { current.recycle(); return true; } } current.recycle(); return false; } /** Loading
core/tests/coretests/src/android/view/accessibility/AccessibilityCacheTest.java +20 −0 Original line number Diff line number Diff line Loading @@ -299,6 +299,26 @@ 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 public void scrollEvent_clearsNodeAndChild() { AccessibilityEvent event = AccessibilityEvent Loading