Don't recycle the same node twice And fix a bug where the node may not be recycled in findNodeOrAncestor() Bug: 159949186 Test: manual Change-Id: Ic4d6327242429567d75639b51e42c44d59bd294c
diff --git a/src/com/android/car/rotary/RotaryService.java b/src/com/android/car/rotary/RotaryService.java index 2251c7c..3756f75 100644 --- a/src/com/android/car/rotary/RotaryService.java +++ b/src/com/android/car/rotary/RotaryService.java
@@ -1264,9 +1264,15 @@ L.d("Exit direct manipulation mode since there is no focused node"); } - Utils.recycleNode(mPreviousFocusedNode); - mPreviousFocusedNode = copyNode(mFocusedNode); - Utils.recycleNode(mFocusedNode); + // Recycle mPreviousFocusedNode only when it's not the same with focusedNode. + if (mPreviousFocusedNode != focusedNode) { + Utils.recycleNode(mPreviousFocusedNode); + } else { + // TODO(b/159949186) + L.e("mPreviousFocusedNode shouldn't be the same with focusedNode " + focusedNode); + } + + mPreviousFocusedNode = mFocusedNode; mFocusedNode = copyNode(focusedNode); // Set mScrollableContainer to the scrollable container which contains mFocusedNode, if any.
diff --git a/src/com/android/car/rotary/TreeTraverser.java b/src/com/android/car/rotary/TreeTraverser.java index 0ea04b2..9be79a2 100644 --- a/src/com/android/car/rotary/TreeTraverser.java +++ b/src/com/android/car/rotary/TreeTraverser.java
@@ -65,6 +65,7 @@ currentNode.recycle(); currentNode = parentNode; } + Utils.recycleNode(currentNode); return null; }