From 6d00b4b014698fe8f27fea676d0b252db16da607 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Tue, 2 Jul 2024 15:50:35 +0100 Subject: [PATCH] Read task size info from RecentsView directly - Automatically determine the Overivew component to use the correct RecentsViewContainer - Also added log on both pre-computed taskSize and newly calculated task size Bug: 336660988 Test: presubmit Flag: TEST_ONLY Change-Id: Ic0adfba35af513e731007241416fc85760135f07 --- .../quickstep/OverviewComponentObserver.java | 9 +++ .../QuickstepTestInformationHandler.java | 71 +++++++++++-------- .../testing/TestInformationHandler.java | 2 +- .../testing/shared/TestProtocol.java | 6 +- .../android/launcher3/tapl/BaseOverview.java | 12 ++-- .../tapl/LauncherInstrumentation.java | 12 ++-- .../android/launcher3/tapl/OverviewTask.java | 4 +- 7 files changed, 68 insertions(+), 48 deletions(-) diff --git a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java index d82426f907..ca19480b07 100644 --- a/quickstep/src/com/android/quickstep/OverviewComponentObserver.java +++ b/quickstep/src/com/android/quickstep/OverviewComponentObserver.java @@ -274,6 +274,15 @@ public final class OverviewComponentObserver { return mActivityInterface; } + /** + * Get the current container control helper for managing interactions to the overview activity. + * + * @return the current container control helper + */ + public BaseContainerInterface getContainerInterface() { + return mActivityInterface; + } + public void dump(PrintWriter pw) { pw.println("OverviewComponentObserver:"); pw.println(" isDefaultHome=" + mIsDefaultHome); diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java index 1ac45fb060..b290f83e1b 100644 --- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -7,6 +7,7 @@ import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import android.app.Activity; import android.content.Context; import android.content.res.Resources; +import android.graphics.PointF; import android.graphics.Rect; import android.os.Bundle; import android.util.Log; @@ -22,6 +23,7 @@ import com.android.quickstep.util.GroupTask; import com.android.quickstep.util.LayoutUtils; import com.android.quickstep.util.TISBindHelper; import com.android.quickstep.views.RecentsView; +import com.android.quickstep.views.RecentsViewContainer; import java.util.ArrayList; import java.util.concurrent.CountDownLatch; @@ -79,39 +81,39 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { return response; } - case TestProtocol.REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET: { + case TestProtocol.REQUEST_GET_OVERVIEW_TASK_SIZE: { + Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "== REQUEST_GET_OVERVIEW_TASK_SIZE =="); + Rect gridSize = new Rect(); + LauncherActivityInterface.INSTANCE.calculateGridSize(mDeviceProfile, mContext, + gridSize); + Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "gridSize: " + gridSize); + PointF taskDimension = new PointF(); + LauncherActivityInterface.getTaskDimension(mContext, mDeviceProfile, taskDimension); Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, - "=== REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET ==="); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "isTablet: " + mDeviceProfile.isTablet); - if (!mDeviceProfile.isTablet) { - return null; - } - Rect focusedTaskRect = new Rect(); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "widthPx: " + mDeviceProfile.widthPx); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "heightPx: " + mDeviceProfile.heightPx); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "insets: " + mDeviceProfile.getInsets()); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "overviewTaskThumbnailTopMarginPx: " - + mDeviceProfile.overviewTaskThumbnailTopMarginPx); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "overviewActionsClaimedSpace: " - + mDeviceProfile.getOverviewActionsClaimedSpace()); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, - "overviewGridSideMargin: " + mDeviceProfile.overviewGridSideMargin); + "taskbarHeight: " + mDeviceProfile.taskbarHeight); + Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "taskDimension: " + taskDimension); + Rect taskSize = new Rect(); LauncherActivityInterface.INSTANCE.calculateTaskSize(mContext, mDeviceProfile, - focusedTaskRect, RecentsPagedOrientationHandler.PORTRAIT); - Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "focusedTaskRect: " + focusedTaskRect); - response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, focusedTaskRect.height()); - return response; + taskSize, RecentsPagedOrientationHandler.PORTRAIT); + Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "calculateTaskSize: " + taskSize); + return getUIProperty(Bundle::putParcelable, + recentsViewContainer -> { + Rect lastComputedTaskSize = + recentsViewContainer.>getOverviewPanel() + .getLastComputedTaskSize(); + Log.d(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, + "lastComputedTaskSize: " + lastComputedTaskSize); + return lastComputedTaskSize; + }, + this::getRecentsViewContainer); } - case TestProtocol.REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET: { - if (!mDeviceProfile.isTablet) { - return null; - } - Rect gridTaskRect = new Rect(); - LauncherActivityInterface.INSTANCE.calculateGridTaskSize(mContext, mDeviceProfile, - gridTaskRect, RecentsPagedOrientationHandler.PORTRAIT); - response.putParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD, gridTaskRect); - return response; + case TestProtocol.REQUEST_GET_OVERVIEW_GRID_TASK_SIZE: { + return getUIProperty(Bundle::putParcelable, + recentsViewContainer -> + recentsViewContainer.>getOverviewPanel() + .getLastComputedGridTaskSize(), + this::getRecentsViewContainer); } case TestProtocol.REQUEST_GET_OVERVIEW_PAGE_SPACING: { @@ -236,6 +238,17 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { } } + private RecentsViewContainer getRecentsViewContainer() { + RecentsAnimationDeviceState rads = new RecentsAnimationDeviceState(mContext); + OverviewComponentObserver observer = new OverviewComponentObserver(mContext, rads); + try { + return observer.getContainerInterface().getCreatedContainer(); + } finally { + observer.onDestroy(); + rads.destroy(); + } + } + @Override protected boolean isLauncherInitialized() { return super.isLauncherInitialized() && TouchInteractionService.isInitialized(); diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index db2a6e0a8b..6d9b891e53 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -501,7 +501,7 @@ public class TestInformationHandler implements ResourceBasedOverride { /** * Returns the result by getting a generic property on UI thread */ - private static Bundle getUIProperty( + protected static Bundle getUIProperty( BundleSetter bundleSetter, Function provider, Supplier targetSupplier) { return getFromExecutorSync(MAIN_EXECUTOR, () -> { S target = targetSupplier.get(); diff --git a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java index 8b774fe065..a20b0f171b 100644 --- a/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java +++ b/tests/multivalentTests/shared/com/android/launcher3/testing/shared/TestProtocol.java @@ -148,10 +148,8 @@ public final class TestProtocol { public static final String REQUEST_HOTSEAT_CELL_CENTER = "hotseat-cell-center"; - public static final String REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET = - "get-focused-task-height-for-tablet"; - public static final String REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET = - "get-grid-task-size-rect-for-tablet"; + public static final String REQUEST_GET_OVERVIEW_TASK_SIZE = "get-overivew-task-size"; + public static final String REQUEST_GET_OVERVIEW_GRID_TASK_SIZE = "get-overivew-grid-task-size"; public static final String REQUEST_GET_OVERVIEW_PAGE_SPACING = "get-overview-page-spacing"; public static final String REQUEST_GET_OVERVIEW_CURRENT_PAGE_INDEX = "get-overview-current-page-index"; diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java index cf6b02af22..ac145b7318 100644 --- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java @@ -280,7 +280,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { if (mLauncher.isTablet()) { mLauncher.assertTrue("current task is not grid height", getCurrentTask().getVisibleHeight() == mLauncher - .getGridTaskRectForTablet().height()); + .getOverviewGridTaskSize().height()); } mLauncher.assertTrue("Current task not scrolled off screen", !getCurrentTask().equals(task)); @@ -356,7 +356,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final List taskViews = getTasks(); mLauncher.assertNotEquals("Unable to find a task", 0, taskViews.size()); - final int gridTaskWidth = mLauncher.getGridTaskRectForTablet().width(); + final int gridTaskWidth = mLauncher.getOverviewGridTaskSize().width(); return taskViews.stream().filter(t -> t.getVisibleBounds().width() == gridTaskWidth).map( t -> new OverviewTask(mLauncher, t, this)).collect(Collectors.toList()); @@ -531,12 +531,12 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { throw new IllegalStateException("Must be run on tablet device."); } final List taskViews = getTasks(); - if (taskViews.size() == 0) { + if (taskViews.isEmpty()) { return null; } - int focusedTaskHeight = mLauncher.getFocusedTaskHeightForTablet(); - testLogD(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, - "getFocusedTaskForTablet: " + focusedTaskHeight); + Rect focusTaskSize = mLauncher.getOverviewTaskSize(); + testLogD(OVERVIEW_FOCUS_TASK_HEIGHT_MISMATCH, "focusTaskSize: " + focusTaskSize); + int focusedTaskHeight = focusTaskSize.height(); for (UiObject2 task : taskViews) { OverviewTask overviewTask = new OverviewTask(mLauncher, task, this); diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index a87406286b..d3c423e30e 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -428,14 +428,14 @@ public final class LauncherInstrumentation { .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); } - int getFocusedTaskHeightForTablet() { - return getTestInfo(TestProtocol.REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET).getInt( - TestProtocol.TEST_INFO_RESPONSE_FIELD); + Rect getOverviewTaskSize() { + return getTestInfo(TestProtocol.REQUEST_GET_OVERVIEW_TASK_SIZE) + .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD, Rect.class); } - Rect getGridTaskRectForTablet() { - return ((Rect) getTestInfo(TestProtocol.REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET) - .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD)); + Rect getOverviewGridTaskSize() { + return getTestInfo(TestProtocol.REQUEST_GET_OVERVIEW_GRID_TASK_SIZE) + .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD, Rect.class); } int getOverviewPageSpacing() { diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index 7a8ab492b5..ab48a211ca 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -156,8 +156,8 @@ public final class OverviewTask { return; } - boolean taskWasFocused = mLauncher.isTablet() && getVisibleHeight() == mLauncher - .getFocusedTaskHeightForTablet(); + boolean taskWasFocused = mLauncher.isTablet() + && getVisibleHeight() == mLauncher.getOverviewTaskSize().height(); List originalTasksCenterX = getCurrentTasksCenterXList().stream().sorted().toList(); boolean isClearAllVisibleBeforeDismiss = mOverview.isClearAllVisible();