Merge "Fix Tapl drag to folder issue on S5 and R3" into tm-dev

This commit is contained in:
Benno Lin
2022-03-05 03:18:26 +00:00
committed by Android (Google) Code Review
6 changed files with 59 additions and 47 deletions
@@ -33,6 +33,7 @@ import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps; import android.content.pm.LauncherApps;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.graphics.Point;
import android.os.Debug; import android.os.Debug;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
@@ -55,6 +56,8 @@ import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities; import com.android.launcher3.Utilities;
import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.statemanager.StateManager; import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.tapl.HomeAppIcon;
import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType; import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.tapl.TestHelpers;
@@ -602,4 +605,26 @@ public abstract class AbstractLauncherUiTest {
protected void onLauncherActivityClose(Launcher launcher) { protected void onLauncherActivityClose(Launcher launcher) {
} }
protected HomeAppIcon createShortcutInCenterIfNotExist(String name) {
Point dimension = mLauncher.getWorkspace().getIconGridDimensions();
return createShortcutIfNotExist(name, dimension.x / 2, dimension.y / 2);
}
protected HomeAppIcon createShortcutIfNotExist(String name, int cellX, int cellY) {
HomeAppIcon homeAppIcon = mLauncher.getWorkspace().tryGetWorkspaceAppIcon(name);
if (homeAppIcon == null) {
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
try {
allApps.getAppIcon(name).dragToWorkspace(cellX, cellY);
} finally {
allApps.unfreeze();
}
homeAppIcon = mLauncher.getWorkspace().getWorkspaceAppIcon(name);
}
return homeAppIcon;
}
} }
@@ -365,27 +365,11 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
} }
} }
private HomeAppIcon createShortcutIfNotExist(String name) {
HomeAppIcon homeAppIcon = mLauncher.getWorkspace().tryGetWorkspaceAppIcon(name);
if (homeAppIcon == null) {
HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps();
allApps.freeze();
try {
allApps.getAppIcon(name).dragToWorkspace(false, false);
} finally {
allApps.unfreeze();
}
homeAppIcon = mLauncher.getWorkspace().getWorkspaceAppIcon(name);
}
return homeAppIcon;
}
@Ignore("b/205014516")
@Test @Test
@PortraitLandscape @PortraitLandscape
public void testDragToFolder() throws Exception { public void testDragToFolder() throws Exception {
final HomeAppIcon playStoreIcon = createShortcutIfNotExist("Play Store"); final HomeAppIcon playStoreIcon = createShortcutIfNotExist("Play Store", 0, 1);
final HomeAppIcon gmailIcon = createShortcutIfNotExist("Gmail"); final HomeAppIcon gmailIcon = createShortcutIfNotExist("Gmail", 1, 1);
FolderIcon folderIcon = gmailIcon.dragToIcon(playStoreIcon); FolderIcon folderIcon = gmailIcon.dragToIcon(playStoreIcon);
@@ -399,7 +383,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
assertNull("Play Store should be moved to a folder.", assertNull("Play Store should be moved to a folder.",
workspace.tryGetWorkspaceAppIcon("Play Store")); workspace.tryGetWorkspaceAppIcon("Play Store"));
final HomeAppIcon youTubeIcon = createShortcutIfNotExist("YouTube"); final HomeAppIcon youTubeIcon = createShortcutInCenterIfNotExist("YouTube");
folderIcon = youTubeIcon.dragToIcon(folderIcon); folderIcon = youTubeIcon.dragToIcon(folderIcon);
folder = folderIcon.open(); folder = folderIcon.open();
@@ -433,8 +417,8 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
@PortraitLandscape @PortraitLandscape
public void testDeleteFromWorkspace() throws Exception { public void testDeleteFromWorkspace() throws Exception {
// test delete both built-in apps and user-installed app from workspace // 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 HomeAppIcon homeAppIcon = createShortcutIfNotExist(appName); final HomeAppIcon homeAppIcon = createShortcutInCenterIfNotExist(appName);
Workspace workspace = mLauncher.getWorkspace().deleteAppIcon(homeAppIcon); Workspace workspace = mLauncher.getWorkspace().deleteAppIcon(homeAppIcon);
assertNull(appName + " app was found after being deleted from workspace", assertNull(appName + " app was found after being deleted from workspace",
workspace.tryGetWorkspaceAppIcon(appName)); workspace.tryGetWorkspaceAppIcon(appName));
@@ -458,7 +442,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
TestUtil.installDummyApp(); TestUtil.installDummyApp();
try { try {
verifyAppUninstalledFromAllApps( verifyAppUninstalledFromAllApps(
createShortcutIfNotExist(DUMMY_APP_NAME).uninstall(), DUMMY_APP_NAME); createShortcutInCenterIfNotExist(DUMMY_APP_NAME).uninstall(), DUMMY_APP_NAME);
} finally { } finally {
TestUtil.uninstallDummyApp(); TestUtil.uninstallDummyApp();
} }
@@ -509,7 +493,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
} }
// test to move a shortcut to other cell. // test to move a shortcut to other cell.
final HomeAppIcon launcherTestAppIcon = createShortcutIfNotExist(APP_NAME); final HomeAppIcon launcherTestAppIcon = createShortcutInCenterIfNotExist(APP_NAME);
for (Point target : targets) { for (Point target : targets) {
launcherTestAppIcon.dragToWorkspace(target.x, target.y); launcherTestAppIcon.dragToWorkspace(target.x, target.y);
} }
@@ -115,7 +115,7 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W
String.format("want to drag the icon to cell(%d, %d)", cellX, cellY)) String.format("want to drag the icon to cell(%d, %d)", cellX, cellY))
) { ) {
final Supplier<Point> dest = () -> Workspace.getCellCenter(mLauncher, cellX, cellY); final Supplier<Point> dest = () -> Workspace.getCellCenter(mLauncher, cellX, cellY);
Workspace.dragIconToWorkspace(mLauncher, this, dest, true, getLongPressIndicator(), Workspace.dragIconToWorkspace(mLauncher, this, dest, getLongPressIndicator(),
() -> addExpectedEventsForLongClick(), null); () -> addExpectedEventsForLongClick(), null);
try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) { try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) {
WorkspaceAppIcon appIcon = WorkspaceAppIcon appIcon =
@@ -139,7 +139,7 @@ abstract class Launchable {
mLauncher.waitForLauncherObject(longPressIndicator); mLauncher.waitForLauncherObject(longPressIndicator);
LauncherInstrumentation.log("movePointerForStartDrag: indicator"); LauncherInstrumentation.log("movePointerForStartDrag: indicator");
mLauncher.movePointer(iconCenter, dragStartCenter, DEFAULT_DRAG_STEPS, false, mLauncher.movePointer(iconCenter, dragStartCenter, DEFAULT_DRAG_STEPS, false,
downTime, true, LauncherInstrumentation.GestureScope.INSIDE); downTime, downTime, true, LauncherInstrumentation.GestureScope.INSIDE);
} }
private int getStartDragThreshold() { private int getStartDragThreshold() {
@@ -1107,11 +1107,13 @@ public final class LauncherInstrumentation {
} }
} }
@NonNull UiObject2 waitForObjectInContainer(UiObject2 container, BySelector selector) { @NonNull
UiObject2 waitForObjectInContainer(UiObject2 container, BySelector selector) {
return waitForObjectsInContainer(container, selector).get(0); return waitForObjectsInContainer(container, selector).get(0);
} }
@NonNull List<UiObject2> waitForObjectsInContainer( @NonNull
List<UiObject2> waitForObjectsInContainer(
UiObject2 container, BySelector selector) { UiObject2 container, BySelector selector) {
try { try {
final List<UiObject2> objects = container.wait( final List<UiObject2> objects = container.wait(
@@ -1406,13 +1408,13 @@ public final class LauncherInstrumentation {
final Point end = new Point(endX, endY); final Point end = new Point(endX, endY);
sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start, gestureScope); sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start, gestureScope);
final long endTime = movePointer( final long endTime = movePointer(
start, end, steps, false, downTime, slowDown, gestureScope); start, end, steps, false, downTime, downTime, slowDown, gestureScope);
sendPointer(downTime, endTime, MotionEvent.ACTION_UP, end, gestureScope); sendPointer(downTime, endTime, MotionEvent.ACTION_UP, end, gestureScope);
} }
long movePointer(Point start, Point end, int steps, boolean isDecelerating, long movePointer(Point start, Point end, int steps, boolean isDecelerating, long downTime,
long downTime, boolean slowDown, GestureScope gestureScope) { long startTime, boolean slowDown, GestureScope gestureScope) {
long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, long endTime = movePointer(downTime, startTime, steps * GESTURE_STEP_MS,
isDecelerating, start, end, gestureScope); isDecelerating, start, end, gestureScope);
if (slowDown) { if (slowDown) {
endTime = movePointer(downTime, endTime + GESTURE_STEP_MS, 5 * GESTURE_STEP_MS, end, endTime = movePointer(downTime, endTime + GESTURE_STEP_MS, 5 * GESTURE_STEP_MS, end,
@@ -178,10 +178,10 @@ public final class Workspace extends Home {
* pageDelta: 3, the latest page that can be created is 2) the icon will be dragged onto the * pageDelta: 3, the latest page that can be created is 2) the icon will be dragged onto the
* page that can be created and is closest to the target page. * page that can be created and is closest to the target page.
* *
* @param homeAppIcon - icon to drag. * @param homeAppIcon - icon to drag.
* @param pageDelta - how many pages should the icon be dragged from the current page. * @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 * It can be a negative value. currentPage + pageDelta should be greater
* than or equal to 0. * than or equal to 0.
*/ */
public void dragIcon(HomeAppIcon homeAppIcon, int pageDelta) { public void dragIcon(HomeAppIcon homeAppIcon, int pageDelta) {
if (mHotseat.getVisibleBounds().height() > mHotseat.getVisibleBounds().width()) { if (mHotseat.getVisibleBounds().height() > mHotseat.getVisibleBounds().width()) {
@@ -246,7 +246,6 @@ public final class Workspace extends Home {
dragIconToWorkspace( dragIconToWorkspace(
mLauncher, homeAppIcon, mLauncher, homeAppIcon,
() -> getDropPointFromDropTargetBar(mLauncher, DELETE_TARGET_TEXT_ID), () -> getDropPointFromDropTargetBar(mLauncher, DELETE_TARGET_TEXT_ID),
true, /* decelerating */
homeAppIcon.getLongPressIndicator(), homeAppIcon.getLongPressIndicator(),
() -> mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), () -> mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT),
null); null);
@@ -261,8 +260,9 @@ public final class Workspace extends Home {
/** /**
* Uninstall the appIcon by dragging it to the 'uninstall' drop point of the drop_target_bar. * 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 launcher the root TAPL instrumentation object of {@link
* @param homeAppIcon to be uninstalled. * LauncherInstrumentation} type.
* @param homeAppIcon to be uninstalled.
* @param launcher the root TAPL instrumentation object of {@link * @param launcher the root TAPL instrumentation object of {@link
* LauncherInstrumentation} type. * LauncherInstrumentation} type.
* @param homeAppIcon to be uninstalled. * @param homeAppIcon to be uninstalled.
@@ -276,7 +276,6 @@ public final class Workspace extends Home {
dragIconToWorkspace( dragIconToWorkspace(
launcher, homeAppIcon, launcher, homeAppIcon,
() -> getDropPointFromDropTargetBar(launcher, UNINSTALL_TARGET_TEXT_ID), () -> getDropPointFromDropTargetBar(launcher, UNINSTALL_TARGET_TEXT_ID),
true, /* decelerating */
homeAppIcon.getLongPressIndicator(), homeAppIcon.getLongPressIndicator(),
expectLongClickEvents, expectLongClickEvents,
null); null);
@@ -353,23 +352,24 @@ public final class Workspace extends Home {
expectDropEvents = () -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, expectDropEvents = () -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN,
LauncherInstrumentation.EVENT_START); LauncherInstrumentation.EVENT_START);
} }
dragIconToWorkspace(launcher, launchable, () -> dest, false, longPressIndicator, dragIconToWorkspace(launcher, launchable, () -> dest, longPressIndicator,
expectLongClickEvents, expectDropEvents); expectLongClickEvents, expectDropEvents);
} }
/** /**
* Drag icon in workspace to else where. * Drag icon in workspace to else where and drop it immediately.
* (There is no slow down time before drop event)
* This function expects the launchable is inside the workspace and there is no drop event. * This function expects the launchable is inside the workspace and there is no drop event.
*/ */
static void dragIconToWorkspace(LauncherInstrumentation launcher, Launchable launchable, static void dragIconToWorkspace(LauncherInstrumentation launcher, Launchable launchable,
Supplier<Point> destSupplier, String longPressIndicator) { Supplier<Point> destSupplier, String longPressIndicator) {
dragIconToWorkspace(launcher, launchable, destSupplier, false, longPressIndicator, dragIconToWorkspace(launcher, launchable, destSupplier, longPressIndicator,
() -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), null); () -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), null);
} }
static void dragIconToWorkspace( static void dragIconToWorkspace(
LauncherInstrumentation launcher, Launchable launchable, Supplier<Point> dest, LauncherInstrumentation launcher, Launchable launchable, Supplier<Point> dest,
boolean isDecelerating, String longPressIndicator, Runnable expectLongClickEvents, String longPressIndicator, Runnable expectLongClickEvents,
@Nullable Runnable expectDropEvents) { @Nullable Runnable expectDropEvents) {
try (LauncherInstrumentation.Closable ignored = launcher.addContextLayer( try (LauncherInstrumentation.Closable ignored = launcher.addContextLayer(
"want to drag icon to workspace")) { "want to drag icon to workspace")) {
@@ -391,7 +391,7 @@ public final class Workspace extends Home {
Point finalDragStart = dragStart; Point finalDragStart = dragStart;
executeAndWaitForPageScroll(launcher, executeAndWaitForPageScroll(launcher,
() -> launcher.movePointer(finalDragStart, screenEdge, DEFAULT_DRAG_STEPS, () -> launcher.movePointer(finalDragStart, screenEdge, DEFAULT_DRAG_STEPS,
isDecelerating, downTime, true, true, downTime, downTime, true,
LauncherInstrumentation.GestureScope.INSIDE)); LauncherInstrumentation.GestureScope.INSIDE));
targetDest.x += displayX * (targetDest.x > 0 ? -1 : 1); targetDest.x += displayX * (targetDest.x > 0 ? -1 : 1);
dragStart = screenEdge; dragStart = screenEdge;
@@ -399,8 +399,9 @@ public final class Workspace extends Home {
// targetDest.x is now between 0 and displayX so we found the target page, // targetDest.x is now between 0 and displayX so we found the target page,
// we just have to put move the icon to the destination and drop it // we just have to put move the icon to the destination and drop it
launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, true,
downTime, true, LauncherInstrumentation.GestureScope.INSIDE); downTime, SystemClock.uptimeMillis(), false,
LauncherInstrumentation.GestureScope.INSIDE);
dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents); dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents);
} }
} }
@@ -488,4 +489,4 @@ public final class Workspace extends Home {
return widget != null ? new Widget(mLauncher, widget) : null; return widget != null ? new Widget(mLauncher, widget) : null;
} }
} }
} }