diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java index f7528225f6..cfd330d2ad 100644 --- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -2,6 +2,7 @@ package com.android.quickstep; import android.app.Activity; import android.content.Context; +import android.graphics.Rect; import android.os.Bundle; import com.android.launcher3.LauncherState; @@ -58,6 +59,17 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { FeatureFlags.ENABLE_OVERVIEW_SHARE.get()); return response; } + + case TestProtocol.REQUEST_GET_FOCUSED_TASK_WIDTH_FOR_TABLET: { + if (!mDeviceProfile.isTablet) { + return null; + } + Rect focusedTaskRect = new Rect(); + LauncherActivityInterface.INSTANCE.calculateTaskSize(mContext, mDeviceProfile, + focusedTaskRect); + response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, focusedTaskRect.width()); + return response; + } } return super.call(method, arg); diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 232acd925c..304e76aac6 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -102,6 +102,8 @@ public final class TestProtocol { public static final String REQUEST_GET_ACTIVITIES_CREATED_COUNT = "get-activities-created-count"; public static final String REQUEST_GET_ACTIVITIES = "get-activities"; + public static final String REQUEST_GET_FOCUSED_TASK_WIDTH_FOR_TABLET = + "get-focused-task-width-for-tablet"; public static Long sForcePauseTimeout; public static final String REQUEST_SET_FORCE_PAUSE_TIMEOUT = "set-force-pause-timeout"; diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java index 588b6b8f07..7137c00b55 100644 --- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java @@ -35,6 +35,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { BaseOverview(LauncherInstrumentation launcher) { super(launcher); verifyActiveContainer(); + verifyActionsViewVisibility(); } @Override @@ -59,7 +60,11 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int leftMargin = mLauncher.getTargetInsets().left; mLauncher.scroll( overview, Direction.LEFT, new Rect(leftMargin + 1, 0, 0, 0), 20, false); - verifyActiveContainer(); + try (LauncherInstrumentation.Closable c2 = + mLauncher.addContextLayer("flung forwards")) { + verifyActiveContainer(); + verifyActionsViewVisibility(); + } } } @@ -95,7 +100,11 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int rightMargin = mLauncher.getTargetInsets().right; mLauncher.scroll( overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false); - verifyActiveContainer(); + try (LauncherInstrumentation.Closable c2 = + mLauncher.addContextLayer("flung backwards")) { + verifyActiveContainer(); + verifyActionsViewVisibility(); + } } } @@ -150,4 +159,55 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { return new OverviewActions(overviewActions, mLauncher); } } + + /* TODO(b/197630182): Once b/188790554 is fixed, remove instanceof check. Currently, when + swiping from app to overview in Fallback Recents, taskbar remains and no action buttons + are visible, so we are only testing Overview for now, not BaseOverview. */ + private void verifyActionsViewVisibility() { + if (!(this instanceof Overview)) { + return; + } + try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to assert overview actions view visibility")) { + if (mLauncher.isTablet() && !isOverviewSnappedToFocusedTask()) { + mLauncher.waitUntilLauncherObjectGone("action_buttons"); + } else { + mLauncher.waitForLauncherObject("action_buttons"); + } + } + } + + /** + * Returns if focused task is currently snapped task in overview. + */ + private boolean isOverviewSnappedToFocusedTask() { + if (!mLauncher.isTablet()) { + // Focused task only exists in tablet's grid-overview + return false; + } + UiObject2 focusedTask = getFocusedTask(); + if (focusedTask == null) { + return false; + } + return Math.abs( + focusedTask.getVisibleBounds().exactCenterX() - mLauncher.getExactScreenCenterX()) + < 1; + } + + /** + * Returns Overview focused task if it exists. + */ + private UiObject2 getFocusedTask() { + final List taskViews = getTasks(); + if (taskViews.size() == 0) { + return null; + } + int focusedTaskWidth = mLauncher.getFocusedTaskWidth(); + for (UiObject2 task : taskViews) { + if (task.getVisibleBounds().width() == focusedTaskWidth) { + return task; + } + } + return null; + } } \ No newline at end of file diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 69c97c5a65..3e73c12fb0 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -321,6 +321,15 @@ public final class LauncherInstrumentation { .getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD); } + int getFocusedTaskWidth() { + return getTestInfo(TestProtocol.REQUEST_GET_FOCUSED_TASK_WIDTH_FOR_TABLET).getInt( + TestProtocol.TEST_INFO_RESPONSE_FIELD); + } + + float getExactScreenCenterX() { + return getRealDisplaySize().x / 2f; + } + private void setForcePauseTimeout(long timeout) { getTestInfo(TestProtocol.REQUEST_SET_FORCE_PAUSE_TIMEOUT, Long.toString(timeout)); } diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java index 4d673a8cde..0d06be373b 100644 --- a/tests/tapl/com/android/launcher3/tapl/Overview.java +++ b/tests/tapl/com/android/launcher3/tapl/Overview.java @@ -30,7 +30,6 @@ public final class Overview extends BaseOverview { Overview(LauncherInstrumentation launcher) { super(launcher); - verifyActiveContainer(); } @Override