From 55c301add099718a00e7a01298497a67e7b6fd32 Mon Sep 17 00:00:00 2001 From: minch Date: Tue, 17 Dec 2024 23:30:24 +0000 Subject: [PATCH] Migrate using TaskViewCount as the indices Do not rely on `getTaskViewCount` as the index information. - Remove the use of the deprecated function `obtain` as well. Flag: EXEMPT as no functionality changes Bug: 379942019 Test: Enabled TalkBack on Tangor and entered overview with multiple opened apps, verified the information as below: 1. The number of children pronounced by TalkBack is the number of RecentsView children. 2. Talkback starts from the leftmost visible TaskView, which matches the logic that we added the TaskView in reverse order to the accessibility children list. 3. Scrolled inside RecentsView, and checked the from and end indices of the a11 event are the same as before. Change-Id: Ib3c37422ba940aed6c124a8cc0d4732144783d45 --- .../android/quickstep/views/RecentsView.java | 24 +++++++++---------- .../quickstep/views/RecentsViewUtils.kt | 8 +++++++ .../com/android/quickstep/views/TaskView.kt | 4 ++-- 3 files changed, 21 insertions(+), 15 deletions(-) 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, )