diff --git a/Android.bp b/Android.bp index 7c78ba844e..f5a38b4e6f 100644 --- a/Android.bp +++ b/Android.bp @@ -36,6 +36,7 @@ android_library { "tests/tapl/**/*.java", "src/com/android/launcher3/ResourceUtils.java", "src/com/android/launcher3/testing/TestProtocol.java", + "src/com/android/launcher3/testing/*Request.java", ], resource_dirs: [ ], manifest: "tests/tapl/AndroidManifest.xml", diff --git a/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java b/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java index 0f61d149d0..02206c0dc9 100644 --- a/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java +++ b/ext_tests/src/com/android/launcher3/testing/DebugTestInformationHandler.java @@ -27,6 +27,7 @@ import android.system.Os; import android.view.View; import androidx.annotation.Keep; +import androidx.annotation.Nullable; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherSettings; @@ -124,7 +125,7 @@ public class DebugTestInformationHandler extends TestInformationHandler { } @Override - public Bundle call(String method, String arg) { + public Bundle call(String method, String arg, @Nullable Bundle extras) { final Bundle response = new Bundle(); switch (method) { case TestProtocol.REQUEST_APP_LIST_FREEZE_FLAGS: { @@ -219,7 +220,7 @@ public class DebugTestInformationHandler extends TestInformationHandler { } default: - return super.call(method, arg); + return super.call(method, arg, extras); } } } diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java index ae2583b515..4c570f1d95 100644 --- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -5,6 +5,8 @@ import android.content.Context; import android.graphics.Rect; import android.os.Bundle; +import androidx.annotation.Nullable; + import com.android.launcher3.LauncherState; import com.android.launcher3.testing.TestInformationHandler; import com.android.launcher3.testing.TestProtocol; @@ -21,7 +23,7 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { } @Override - public Bundle call(String method, String arg) { + public Bundle call(String method, String arg, @Nullable Bundle extras) { final Bundle response = new Bundle(); switch (method) { case TestProtocol.REQUEST_ALL_APPS_TO_OVERVIEW_SWIPE_HEIGHT: { @@ -82,7 +84,7 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { } } - return super.call(method, arg); + return super.call(method, arg, extras); } @Override diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 8ebfd62b69..2eae99ae90 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -23,16 +23,23 @@ import android.app.Activity; import android.content.Context; import android.content.res.Resources; import android.graphics.Insets; +import android.graphics.Point; +import android.graphics.Rect; import android.os.Build; import android.os.Bundle; import android.view.WindowInsets; +import androidx.annotation.Nullable; + +import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherState; import com.android.launcher3.R; +import com.android.launcher3.Workspace; +import com.android.launcher3.dragndrop.DragLayer; import com.android.launcher3.util.ResourceBasedOverride; import com.android.launcher3.widget.picker.WidgetsFullSheet; @@ -62,12 +69,18 @@ public class TestInformationHandler implements ResourceBasedOverride { mLauncherAppState = LauncherAppState.getInstanceNoCreate(); } - public Bundle call(String method) { - return call(method, /*arg=*/ null); - } - - public Bundle call(String method, String arg) { + /** + * handle a request and return result Bundle. + * + * @param method request name. + * @param arg optional single string argument. + * @param extra extra request payload. + */ + public Bundle call(String method, String arg, @Nullable Bundle extra) { final Bundle response = new Bundle(); + if (extra != null && extra.getClassLoader() == null) { + extra.setClassLoader(getClass().getClassLoader()); + } switch (method) { case TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT: { return getLauncherUIProperty(Bundle::putInt, l -> { @@ -163,11 +176,48 @@ public class TestInformationHandler implements ResourceBasedOverride { .forceAllowRotationForTesting(Boolean.parseBoolean(arg))); return null; + case TestProtocol.REQUEST_WORKSPACE_CELL_LAYOUT_SIZE: + return getLauncherUIProperty(Bundle::putIntArray, launcher -> { + final Workspace workspace = launcher.getWorkspace(); + final int screenId = workspace.getScreenIdForPageIndex( + workspace.getCurrentPage()); + final CellLayout cellLayout = workspace.getScreenWithId(screenId); + return new int[]{cellLayout.getCountX(), cellLayout.getCountY()}; + }); + + case TestProtocol.REQUEST_WORKSPACE_CELL_CENTER: + final WorkspaceCellCenterRequest request = extra.getParcelable( + TestProtocol.TEST_INFO_REQUEST_FIELD); + return getLauncherUIProperty(Bundle::putParcelable, launcher -> { + final Workspace workspace = launcher.getWorkspace(); + // TODO(b/216387249): allow caller selecting different pages. + CellLayout cellLayout = (CellLayout) workspace.getPageAt( + workspace.getCurrentPage()); + final Rect cellRect = getDescendantRectRelativeToDragLayerForCell(launcher, + cellLayout, request.cellX, request.cellY, request.spanX, request.spanY); + return new Point(cellRect.centerX(), cellRect.centerY()); + }); + default: return null; } } + private static Rect getDescendantRectRelativeToDragLayerForCell(Launcher launcher, + CellLayout cellLayout, int cellX, int cellY, int spanX, int spanY) { + final DragLayer dragLayer = launcher.getDragLayer(); + final Rect target = new Rect(); + + cellLayout.cellToRect(cellX, cellY, spanX, spanY, target); + int[] leftTop = {target.left, target.top}; + int[] rightBottom = {target.right, target.bottom}; + dragLayer.getDescendantCoordRelativeToSelf(cellLayout, leftTop); + dragLayer.getDescendantCoordRelativeToSelf(cellLayout, rightBottom); + + target.set(leftTop[0], leftTop[1], rightBottom[0], rightBottom[1]); + return target; + } + protected boolean isLauncherInitialized() { return Launcher.ACTIVITY_TRACKER.getCreatedActivity() == null || LauncherAppState.getInstance(mContext).getModel().isModelLoaded(); diff --git a/src/com/android/launcher3/testing/TestInformationProvider.java b/src/com/android/launcher3/testing/TestInformationProvider.java index 4f2619cc84..bcc7c2de4e 100644 --- a/src/com/android/launcher3/testing/TestInformationProvider.java +++ b/src/com/android/launcher3/testing/TestInformationProvider.java @@ -60,7 +60,7 @@ public class TestInformationProvider extends ContentProvider { if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { TestInformationHandler handler = TestInformationHandler.newInstance(getContext()); handler.init(getContext()); - return handler.call(method, arg); + return handler.call(method, arg, extras); } return null; } diff --git a/src/com/android/launcher3/testing/TestInformationRequest.java b/src/com/android/launcher3/testing/TestInformationRequest.java new file mode 100644 index 0000000000..272ae56a30 --- /dev/null +++ b/src/com/android/launcher3/testing/TestInformationRequest.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2021 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.launcher3.testing; + +import android.os.Parcelable; + +/** + * A Request sent to TestInformationHandler can implement this interface to carry more information. + */ +public interface TestInformationRequest extends Parcelable { + /** + * The name for handler to dispatch request. + */ + String getRequestName(); +} diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 7c6ad9fe59..5156f56b77 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -68,6 +68,7 @@ public final class TestProtocol { } } + public static final String TEST_INFO_REQUEST_FIELD = "request"; public static final String TEST_INFO_RESPONSE_FIELD = "response"; public static final String REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT = @@ -104,6 +105,10 @@ 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_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; + public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-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 = diff --git a/src/com/android/launcher3/testing/WorkspaceCellCenterRequest.java b/src/com/android/launcher3/testing/WorkspaceCellCenterRequest.java new file mode 100644 index 0000000000..71ab09f3f2 --- /dev/null +++ b/src/com/android/launcher3/testing/WorkspaceCellCenterRequest.java @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2022 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.launcher3.testing; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Request object for querying a workspace cell region in Rect. + */ +public class WorkspaceCellCenterRequest implements TestInformationRequest { + public final int cellX; + public final int cellY; + public final int spanX; + public final int spanY; + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(cellX); + dest.writeInt(cellY); + dest.writeInt(spanX); + dest.writeInt(spanY); + } + + public static final Parcelable.Creator CREATOR = + new Parcelable.Creator() { + + @Override + public WorkspaceCellCenterRequest createFromParcel(Parcel source) { + return new WorkspaceCellCenterRequest(source); + } + + @Override + public WorkspaceCellCenterRequest[] newArray(int size) { + return new WorkspaceCellCenterRequest[size]; + } + }; + + private WorkspaceCellCenterRequest(int cellX, int cellY, int spanX, int spanY) { + this.cellX = cellX; + this.cellY = cellY; + this.spanX = spanX; + this.spanY = spanY; + } + + private WorkspaceCellCenterRequest(Parcel in) { + this(in.readInt(), in.readInt(), in.readInt(), in.readInt()); + } + + /** + * Create a builder for WorkspaceCellRectRequest. + * + * @return WorkspaceCellRectRequest builder. + */ + public static WorkspaceCellCenterRequest.Builder builder() { + return new WorkspaceCellCenterRequest.Builder(); + } + + @Override + public String getRequestName() { + return TestProtocol.REQUEST_WORKSPACE_CELL_CENTER; + } + + /** + * WorkspaceCellRectRequest Builder. + */ + public static final class Builder { + private int mCellX; + private int mCellY; + private int mSpanX; + private int mSpanY; + + private Builder() { + this.mCellX = 0; + this.mCellY = 0; + this.mSpanX = 1; + this.mSpanY = 1; + } + + /** + * Set X coordinate of upper left corner expressed as a cell position + */ + public WorkspaceCellCenterRequest.Builder setCellX(int x) { + this.mCellX = x; + return this; + } + + /** + * Set Y coordinate of upper left corner expressed as a cell position + */ + public WorkspaceCellCenterRequest.Builder setCellY(int y) { + this.mCellY = y; + return this; + } + + /** + * Set span Width in cells + */ + public WorkspaceCellCenterRequest.Builder setSpanX(int x) { + this.mSpanX = x; + return this; + } + + /** + * Set span Height in cells + */ + public WorkspaceCellCenterRequest.Builder setSpanY(int y) { + this.mCellY = y; + return this; + } + + /** + * build the WorkspaceCellRectRequest. + */ + public WorkspaceCellCenterRequest build() { + return new WorkspaceCellCenterRequest(mCellX, mCellY, mSpanX, mSpanY); + } + } +} diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 4b4f1d9abc..2035da1de9 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -24,6 +24,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import android.graphics.Point; + import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; @@ -368,8 +370,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { AllApps allApps = mLauncher.getWorkspace().switchToAllApps(); allApps.freeze(); try { - appIcon = allApps.getAppIcon(name); - appIcon.dragToWorkspace(false, false); + allApps.getAppIcon(name).dragToWorkspace(false, false); } finally { allApps.unfreeze(); } @@ -431,7 +432,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { @PortraitLandscape public void testDeleteFromWorkspace() throws Exception { // test delete both built-in apps and user-installed app from workspace - for (String appName : new String[] {"Gmail", "Play Store", APP_NAME}) { + for (String appName : new String[]{"Gmail", "Play Store", APP_NAME}) { final AppIcon appIcon = createShortcutIfNotExist(appName); Workspace workspace = mLauncher.getWorkspace().deleteAppIcon(appIcon); assertNull(appName + " app was found after being deleted from workspace", @@ -481,7 +482,39 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } } + @Test + @PortraitLandscape + public void testDragAppIconToWorkspaceCell() throws Exception { + final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions(); + + Point[] targets = { + new Point(0, 1), + new Point(0, dimensions.y - 2), + new Point(dimensions.x - 1, 1), + new Point(dimensions.x - 1, dimensions.y - 2), + new Point(dimensions.x / 2, dimensions.y / 2) + }; + + for (Point target : targets) { + final AllApps allApps = mLauncher.getWorkspace().switchToAllApps(); + allApps.freeze(); + try { + allApps.getAppIcon(APP_NAME).dragToWorkspace(target.x, target.y); + } finally { + allApps.unfreeze(); + } + // Reset the workspace for the next shortcut creation. + initialize(this); + } + + // test to move a shortcut to other cell. + final AppIcon launcherTestAppIcon = createShortcutIfNotExist(APP_NAME); + for (Point target : targets) { + launcherTestAppIcon.dragToWorkspace(target.x, target.y); + } + } + public static String getAppPackageName() { return getInstrumentation().getContext().getPackageName(); } -} \ No newline at end of file +} diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index c1b022017a..800322b1fa 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -51,8 +51,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { // Wait for the recycler to populate. mLauncher.waitForObjectInContainer(appListRecycler, By.clazz(TextView.class)); verifyNotFrozen("All apps freeze flags upon opening all apps"); - mIconHeight = mLauncher.getTestInfo( - TestProtocol.REQUEST_ICON_HEIGHT) + mIconHeight = mLauncher.getTestInfo(TestProtocol.REQUEST_ICON_HEIGHT) .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); } @@ -211,7 +210,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { private int getAllAppsScroll() { return mLauncher.getTestInfo( - TestProtocol.REQUEST_APPS_LIST_SCROLL_Y) + TestProtocol.REQUEST_APPS_LIST_SCROLL_Y) .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); } diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index 8fa9e12e8e..50611d7225 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -27,6 +27,7 @@ import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.TestProtocol; +import java.util.function.Supplier; import java.util.regex.Pattern; /** @@ -34,8 +35,11 @@ import java.util.regex.Pattern; */ public abstract class AppIcon extends Launchable implements FolderDragTarget { + private final String mAppName; + AppIcon(LauncherInstrumentation launcher, UiObject2 icon) { super(launcher, icon); + mAppName = icon.getText(); } static BySelector getAppIconSelector(String appName, LauncherInstrumentation launcher) { @@ -138,4 +142,31 @@ public abstract class AppIcon extends Launchable implements FolderDragTarget { ); } } + + /** + * Drag an object to the given cell in workspace. The target cell must be empty. + * + * @param cellX zero based column number, starting from the left of the screen. + * @param cellY zero based row number, starting from the top of the screen. + */ + public AppIcon dragToWorkspace(int cellX, int cellY) { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + String.format("want to drag the icon to cell(%d, %d)", cellX, cellY)) + ) { + final Supplier dest = () -> Workspace.getCellCenter(mLauncher, cellX, cellY); + Workspace.dragIconToWorkspace(mLauncher, this, dest, true, getLongPressIndicator(), + () -> addExpectedEventsForLongClick(), null); + try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) { + WorkspaceAppIcon appIcon = + (WorkspaceAppIcon) mLauncher.getWorkspace().getWorkspaceAppIcon(mAppName); + mLauncher.assertTrue( + String.format( + "The %s icon should be in the cell (%d, %d).", mAppName, cellX, + cellY), + appIcon.isInCell(cellX, cellY)); + return appIcon; + } + } + } } \ 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 5511770b10..5287b826ce 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -66,6 +66,7 @@ import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import com.android.launcher3.ResourceUtils; +import com.android.launcher3.testing.TestInformationRequest; import com.android.launcher3.testing.TestProtocol; import com.android.systemui.shared.system.ContextUtils; import com.android.systemui.shared.system.QuickStepContract; @@ -301,9 +302,13 @@ public final class LauncherInstrumentation { } Bundle getTestInfo(String request, String arg) { + return getTestInfo(request, arg, null); + } + + Bundle getTestInfo(String request, String arg, Bundle extra) { try (ContentProviderClient client = getContext().getContentResolver() .acquireContentProviderClient(mTestProviderUri)) { - return client.call(request, arg, null); + return client.call(request, arg, extra); } catch (DeadObjectException e) { fail("Launcher crashed"); return null; @@ -312,6 +317,12 @@ public final class LauncherInstrumentation { } } + Bundle getTestInfo(TestInformationRequest request) { + Bundle extra = new Bundle(); + extra.putParcelable(TestProtocol.TEST_INFO_REQUEST_FIELD, request); + return getTestInfo(request.getRequestName(), null, extra); + } + Insets getTargetInsets() { return getTestInfo(TestProtocol.REQUEST_TARGET_INSETS) .getParcelable(TestProtocol.TEST_INFO_RESPONSE_FIELD); @@ -1757,4 +1768,4 @@ public final class LauncherInstrumentation { return ResourceUtils.getBoolByName( "config_supportsRoundedCornersOnWindows", resources, false); } -} \ No newline at end of file +} diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 16987e97cc..1947da30a7 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -41,6 +41,7 @@ import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import com.android.launcher3.testing.TestProtocol; +import com.android.launcher3.testing.WorkspaceCellCenterRequest; import java.util.List; import java.util.function.Supplier; @@ -88,7 +89,7 @@ public final class Workspace extends Home { final int windowCornerRadius = (int) Math.ceil(mLauncher.getWindowCornerRadius()); final int startY = deviceHeight - Math.max(bottomGestureMargin, windowCornerRadius) - 1; final int swipeHeight = mLauncher.getTestInfo( - TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT) + TestProtocol.REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT) .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); LauncherInstrumentation.log( "switchToAllApps: deviceHeight = " + deviceHeight + ", startY = " + startY @@ -180,8 +181,8 @@ public final class Workspace extends Home { * * @param appIcon - icon to drag. * @param pageDelta - how many pages should the icon be dragged from the current page. - * It can be a negative value. currentPage + pageDelta should be greater - * than or equal to 0. + * It can be a negative value. currentPage + pageDelta should be greater + * than or equal to 0. */ public void dragIcon(AppIcon appIcon, int pageDelta) { if (mHotseat.getVisibleBounds().height() > mHotseat.getVisibleBounds().width()) { @@ -266,8 +267,9 @@ public final class Workspace extends Home { /** * Uninstall the appIcon by dragging it to the 'uninstall' drop point of the drop_target_bar. * - * @param launcher the root TAPL instrumentation object of {@link LauncherInstrumentation} type. - * @param appIcon to be uninstalled. + * @param launcher the root TAPL instrumentation object of {@link + * LauncherInstrumentation} type. + * @param appIcon to be uninstalled. * @param expectLongClickEvents the runnable to be executed to verify expected longclick event. * @return validated workspace after the existing appIcon being uninstalled. */ @@ -304,6 +306,23 @@ public final class Workspace extends Home { } } + /** + * Get cell layout's grids size. The return point's x and y values are the cell counts in X and + * Y directions respectively, not the values in pixels. + */ + public Point getIconGridDimensions() { + int[] countXY = mLauncher.getTestInfo( + TestProtocol.REQUEST_WORKSPACE_CELL_LAYOUT_SIZE).getIntArray( + TestProtocol.TEST_INFO_RESPONSE_FIELD); + return new Point(countXY[0], countXY[1]); + } + + static Point getCellCenter(LauncherInstrumentation launcher, int cellX, int cellY) { + return launcher.getTestInfo(WorkspaceCellCenterRequest.builder().setCellX( + cellX).setCellY(cellY).build()).getParcelable( + TestProtocol.TEST_INFO_RESPONSE_FIELD); + } + /** * Finds folder icons in the current workspace. * diff --git a/tests/tapl/com/android/launcher3/tapl/WorkspaceAppIcon.java b/tests/tapl/com/android/launcher3/tapl/WorkspaceAppIcon.java index 5f4e4695ef..0523a63dcc 100644 --- a/tests/tapl/com/android/launcher3/tapl/WorkspaceAppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/WorkspaceAppIcon.java @@ -16,6 +16,8 @@ package com.android.launcher3.tapl; +import android.graphics.Point; + import androidx.test.uiautomator.UiObject2; import java.util.regex.Pattern; @@ -33,4 +35,9 @@ final class WorkspaceAppIcon extends AppIcon { protected Pattern getLongClickEvent() { return Workspace.LONG_CLICK_EVENT; } + + boolean isInCell(int cellX, int cellY) { + final Point center = Workspace.getCellCenter(mLauncher, cellX, cellY); + return mObject.getParent().getVisibleBounds().contains(center.x, center.y); + } }