From 3359fa7f326d6aa3572fa47f2e20a1f83885921f Mon Sep 17 00:00:00 2001 From: vinayjoglekar Date: Thu, 22 Aug 2024 19:51:42 +0100 Subject: [PATCH] Fix talkback in split mode 1. Announce description of both snapshot in GroupedTaskView. 2. Announce them in correct order. After setting right content description for both the apps in split mode, announcement order was reverse. Seems that order of the node tree which android sees was wrong. Also order did not change even in RTL mode. see here https://paste.googleplex.com/6492038621298688. The correct order is manually set using addChildrenForAccessibility in GroupedTaskView. (similarly being used in RecentsView since we use reverse order for overview). Also considered RTL. See order after fix here https://paste.googleplex.com/6492038621298688 https://drive.google.com/file/d/1BA1YKkcNsovEu4us9cvq5xOdXviTR1OV/view?usp=drive_link Other alternatives tried were fixing order using android:accessibilityTraversalAfter and android:accessibilityTraversalBefore, both in layout and programatically which doesn't seem to work. Test: Manual - Using Node tree debugging of talkback developer options.(Print and filter by tag TreeDebug) BUG: 330424779 Flag: EXEMPT bugfix Change-Id: If3c360277bd951d2d2b223bab7844e078e9c7d27 --- quickstep/Android.bp | 1 + .../quickstep/views/DigitalWellBeingToast.kt | 9 ++- .../android/quickstep/views/TaskContainer.kt | 14 +++++ .../com/android/quickstep/views/TaskView.kt | 6 ++ .../quickstep/TaplOverviewIconTest.java | 36 ++--------- .../android/quickstep/TaplTestsQuickstep.java | 6 +- .../quickstep/TaplTestsSplitscreen.java | 27 +-------- .../quickstep/util/SplitScreenTestUtils.kt | 60 +++++++++++++++++++ .../android/launcher3/tapl/OverviewTask.java | 13 +++- 9 files changed, 111 insertions(+), 61 deletions(-) create mode 100644 quickstep/tests/src/com/android/quickstep/util/SplitScreenTestUtils.kt diff --git a/quickstep/Android.bp b/quickstep/Android.bp index 1b9c661387..4c724dc290 100644 --- a/quickstep/Android.bp +++ b/quickstep/Android.bp @@ -52,6 +52,7 @@ filegroup { "tests/src/com/android/quickstep/TaplOverviewIconTest.java", "tests/src/com/android/quickstep/TaplTestsQuickstep.java", "tests/src/com/android/quickstep/TaplTestsSplitscreen.java", + "tests/src/com/android/quickstep/util/SplitScreenTestUtils.kt", "tests/src/com/android/launcher3/testcomponent/ExcludeFromRecentsTestActivity.java", ], } diff --git a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.kt b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.kt index 0ab36c9d72..e340ce60ab 100644 --- a/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.kt +++ b/quickstep/src/com/android/quickstep/views/DigitalWellBeingToast.kt @@ -85,7 +85,7 @@ class DigitalWellBeingToast( private fun setNoLimit() { hasLimit = false - taskView.contentDescription = task.titleDescription + setContentDescription(appUsageLimitTimeMs = -1, appRemainingTimeMs = -1) replaceBanner(null) appRemainingTimeMs = -1 } @@ -110,9 +110,14 @@ class DigitalWellBeingToast( setOnClickListener(::openAppUsageSettings) } replaceBanner(toast) + setContentDescription(appUsageLimitTimeMs, appRemainingTimeMs) + } - taskView.contentDescription = + private fun setContentDescription(appUsageLimitTimeMs: Long, appRemainingTimeMs: Long) { + val taskContainer: TaskContainer = taskView.getTaskContainerById(task.key.id) ?: return + val contentDescription = getContentDescriptionForTask(task, appUsageLimitTimeMs, appRemainingTimeMs) + taskContainer.snapshotView.contentDescription = contentDescription } fun initialize(task: Task) { diff --git a/quickstep/src/com/android/quickstep/views/TaskContainer.kt b/quickstep/src/com/android/quickstep/views/TaskContainer.kt index af32ba2565..86f6a99be0 100644 --- a/quickstep/src/com/android/quickstep/views/TaskContainer.kt +++ b/quickstep/src/com/android/quickstep/views/TaskContainer.kt @@ -171,4 +171,18 @@ class TaskContainer( thumbnailViewDeprecated.setOverlayEnabled(enabled) } } + + fun addChildForAccessibility(outChildren: ArrayList) { + addAccessibleChildToList(iconView.asView(), outChildren) + addAccessibleChildToList(snapshotView, outChildren) + showWindowsView?.let { addAccessibleChildToList(it, outChildren) } + } + + private fun addAccessibleChildToList(view: View, outChildren: ArrayList) { + if (view.includeForAccessibility()) { + outChildren.add(view) + } else { + view.addChildrenForAccessibility(outChildren) + } + } } diff --git a/quickstep/src/com/android/quickstep/views/TaskView.kt b/quickstep/src/com/android/quickstep/views/TaskView.kt index d2cdfa2bef..139bc248c3 100644 --- a/quickstep/src/com/android/quickstep/views/TaskView.kt +++ b/quickstep/src/com/android/quickstep/views/TaskView.kt @@ -1662,6 +1662,12 @@ constructor( return thumbnailBounds.contains(x.toInt(), y.toInt()) } + override fun addChildrenForAccessibility(outChildren: ArrayList) { + (if (isLayoutRtl) taskContainers.reversed() else taskContainers).forEach { + it.addChildForAccessibility(outChildren) + } + } + companion object { private const val TAG = "TaskView" const val FLAG_UPDATE_ICON = 1 diff --git a/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java b/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java index 2087016388..9bc1c5981e 100644 --- a/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java +++ b/quickstep/tests/src/com/android/quickstep/TaplOverviewIconTest.java @@ -15,20 +15,18 @@ */ package com.android.quickstep; -import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL; -import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT; - import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import android.content.Intent; import android.platform.test.annotations.PlatinumTest; +import com.android.launcher3.tapl.Overview; import com.android.launcher3.tapl.OverviewTask.OverviewSplitTask; import com.android.launcher3.tapl.OverviewTaskMenu; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.uioverrides.QuickstepLauncher; -import com.android.launcher3.util.rule.TestStabilityRule; +import com.android.quickstep.util.SplitScreenTestUtils; import org.junit.Test; @@ -70,39 +68,17 @@ public class TaplOverviewIconTest extends AbstractLauncherUiTest LauncherState.OVERVIEW)); // overview.getCurrentTask().dismiss(); -// executeOnLauncher(launcher -> assertTrue("Grid did not rebalance after multiple dismissals", +// executeOnLauncher(launcher -> assertTrue("Grid did not rebalance after multiple +// dismissals", // (Math.abs(getTopRowTaskCountForTablet(launcher) - getBottomRowTaskCountForTablet( // launcher)) <= 1))); @@ -592,7 +593,8 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { if (overview.hasTasks()) { currentTask = overview.getCurrentTask(); assertFalse("Found ExcludeFromRecentsTestActivity after entering Overview from Home", - currentTask.containsContentDescription("ExcludeFromRecents") + currentTask.containsContentDescription( + "ExcludeFromRecents") || currentTask.containsContentDescription(null)); } else { // Presumably the test started with 0 tasks and remains that way after going home. diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java b/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java index 733ea4e2cf..daa4ec327a 100644 --- a/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java +++ b/quickstep/tests/src/com/android/quickstep/TaplTestsSplitscreen.java @@ -17,8 +17,6 @@ package com.android.quickstep; import static com.android.launcher3.config.FeatureFlags.enableSplitContextually; -import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL; -import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -33,7 +31,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import com.android.launcher3.tapl.Overview; import com.android.launcher3.tapl.Taskbar; import com.android.launcher3.tapl.TaskbarAppIcon; -import com.android.launcher3.util.rule.TestStabilityRule; +import com.android.quickstep.util.SplitScreenTestUtils; import com.android.wm.shell.Flags; import org.junit.After; @@ -110,9 +108,8 @@ public class TaplTestsSplitscreen extends AbstractQuickStepTest { assumeTrue("App pairs feature is currently not enabled, no test needed", Flags.enableAppPairs()); - createAndLaunchASplitPair(); + Overview overview = SplitScreenTestUtils.createAndLaunchASplitPairInOverview(mLauncher); - Overview overview = mLauncher.goHome().switchToOverview(); if (mLauncher.isGridOnlyOverviewEnabled() || !mLauncher.isTablet()) { assertTrue("Save app pair menu item is missing", overview.getCurrentTask() @@ -156,24 +153,4 @@ public class TaplTestsSplitscreen extends AbstractQuickStepTest { TaskbarAppIcon firstApp = taskbar.getAppIcon(firstAppName); firstApp.launchIntoSplitScreen(); } - - private void createAndLaunchASplitPair() { - clearAllRecentTasks(); - - startTestActivity(2); - startTestActivity(3); - - if (mLauncher.isTablet() && !mLauncher.isGridOnlyOverviewEnabled()) { - mLauncher.goHome().switchToOverview().getOverviewActions() - .clickSplit() - .getTestActivityTask(2) - .open(); - } else { - mLauncher.goHome().switchToOverview().getCurrentTask() - .tapMenu() - .tapSplitMenuItem() - .getCurrentTask() - .open(); - } - } } diff --git a/quickstep/tests/src/com/android/quickstep/util/SplitScreenTestUtils.kt b/quickstep/tests/src/com/android/quickstep/util/SplitScreenTestUtils.kt new file mode 100644 index 0000000000..82361aabb8 --- /dev/null +++ b/quickstep/tests/src/com/android/quickstep/util/SplitScreenTestUtils.kt @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.quickstep.util + +import androidx.test.uiautomator.By +import com.android.launcher3.tapl.LauncherInstrumentation +import com.android.launcher3.tapl.Overview +import com.android.launcher3.tapl.OverviewTask +import com.android.launcher3.ui.AbstractLauncherUiTest + +object SplitScreenTestUtils { + + /** Creates 2 tasks and makes a split mode pair. Also asserts the accessibility labels. */ + @JvmStatic + fun createAndLaunchASplitPairInOverview(launcher: LauncherInstrumentation): Overview { + clearAllRecentTasks(launcher) + + AbstractLauncherUiTest.startTestActivity(2) + AbstractLauncherUiTest.startTestActivity(3) + + val overView = launcher.goHome().switchToOverview() + if (launcher.isTablet && !launcher.isGridOnlyOverviewEnabled) { + overView.overviewActions.clickSplit().getTestActivityTask(2).open() + } else { + overView.currentTask.tapMenu().tapSplitMenuItem().currentTask.open() + } + + val overviewWithSplitPair = launcher.goHome().switchToOverview() + val currentTask = overviewWithSplitPair.currentTask + currentTask.containsContentDescription( + By.pkg(AbstractLauncherUiTest.getAppPackageName()).text("TestActivity3").toString(), + OverviewTask.OverviewSplitTask.SPLIT_TOP_OR_LEFT + ) + currentTask.containsContentDescription( + By.pkg(AbstractLauncherUiTest.getAppPackageName()).text("TestActivity2").toString(), + OverviewTask.OverviewSplitTask.SPLIT_BOTTOM_OR_RIGHT + ) + return overviewWithSplitPair + } + + private fun clearAllRecentTasks(launcher: LauncherInstrumentation) { + if (launcher.recentTasks.isNotEmpty()) { + launcher.goHome().switchToOverview().dismissAllTasks() + } + } +} diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index ab48a211ca..5433fa7e94 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -284,8 +284,9 @@ public final class OverviewTask { * * TODO(b/326565120): remove Nullable support once the bug causing it to be null is fixed. */ - public boolean containsContentDescription(@Nullable String expected) { - String actual = mTask.getContentDescription(); + public boolean containsContentDescription(@Nullable String expected, + OverviewSplitTask overviewSplitTask) { + String actual = findObjectInTask(overviewSplitTask.snapshotRes).getContentDescription(); if (actual == null && expected == null) { return true; } @@ -295,6 +296,14 @@ public final class OverviewTask { return actual.contains(expected); } + /** + * Returns whether the given String is contained in this Task's contentDescription. Also returns + * true if both Strings are null + */ + public boolean containsContentDescription(@Nullable String expected) { + return containsContentDescription(expected, DEFAULT); + } + private TaskViewType getType() { String resourceName = mTask.getResourceName(); if (resourceName.endsWith("task_view_grouped")) {