diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index fca115e259..f9f3487dde 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -5824,19 +5824,19 @@ public abstract class RecentsView< @Override public void addChildrenForAccessibility(ArrayList outChildren) { - // Add children in reverse order - for (int i = getChildCount() - 1; i >= 0; --i) { - outChildren.add(getChildAt(i)); - } + outChildren.addAll(getAccessibilityChildren()); + } + + public List getAccessibilityChildren() { + return mUtils.getAccessibilityChildren(); } @Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { super.onInitializeAccessibilityNodeInfo(info); final AccessibilityNodeInfo.CollectionInfo - collectionInfo = AccessibilityNodeInfo.CollectionInfo.obtain( - 1, getTaskViewCount(), false, - AccessibilityNodeInfo.CollectionInfo.SELECTION_MODE_NONE); + collectionInfo = new AccessibilityNodeInfo.CollectionInfo( + 1, getAccessibilityChildren().size(), false); info.setCollectionInfo(collectionInfo); } @@ -5845,14 +5845,12 @@ public abstract class RecentsView< super.onInitializeAccessibilityEvent(event); event.setScrollable(hasTaskViews()); - // TODO(b/379942019): Revisit the logic below to make sure it does not rely on the - // `taskViewCount` to update the indices or make it indices free. - final int taskViewCount = getTaskViewCount(); if (event.getEventType() == AccessibilityEvent.TYPE_VIEW_SCROLLED) { + final List accessibilityChildren = getAccessibilityChildren(); final int[] visibleTasks = getVisibleChildrenRange(); - event.setFromIndex(taskViewCount - visibleTasks[1]); - event.setToIndex(taskViewCount - visibleTasks[0]); - event.setItemCount(taskViewCount); + event.setFromIndex(accessibilityChildren.indexOf(getChildAt(visibleTasks[1]))); + event.setToIndex(accessibilityChildren.indexOf(getChildAt(visibleTasks[0]))); + event.setItemCount(accessibilityChildren.size()); } } diff --git a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt index 6eeffdabe2..ccf22ced8a 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt +++ b/quickstep/src/com/android/quickstep/views/RecentsViewUtils.kt @@ -16,6 +16,8 @@ package com.android.quickstep.views +import android.view.View +import androidx.core.view.children import com.android.launcher3.Flags.enableLargeDesktopWindowingTile import com.android.quickstep.util.GroupTask import com.android.quickstep.views.RecentsView.RUNNING_TASK_ATTACH_ALPHA @@ -94,6 +96,12 @@ class RecentsViewUtils(private val recentsView: RecentsView<*, *>) { /** Returns the last TaskView that should be displayed as a large tile. */ fun getLastLargeTaskView(): TaskView? = recentsView.taskViews.lastOrNull { it.isLargeTile } + /** + * Gets the list of accessibility children. Currently all the children of RecentsViews are + * added, and in the reverse order to the list. + */ + fun getAccessibilityChildren(): List = recentsView.children.toList().reversed() + @JvmOverloads /** Returns the first [TaskView], with some tasks possibly hidden in the carousel. */ fun getFirstTaskViewInCarousel( diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index 084ea4bd5a..0dbad70874 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -658,10 +658,10 @@ constructor( recentsView?.let { collectionItemInfo = - AccessibilityNodeInfo.CollectionItemInfo.obtain( + AccessibilityNodeInfo.CollectionItemInfo( 0, 1, - it.taskViewCount - it.indexOfChild(this@TaskView) - 1, + it.getAccessibilityChildren().indexOf(this@TaskView), 1, false, )