Use ACTION_SCROLL to scroll TAPL workspace objects
A slow UI thread can cause the first ACTION_DOWN motion event to be handled as a long click before the pointer can be moved for a swipe. Directly using ACTION_SCROLL instead of the usualy ACTION_DOWN/MOVE/UP flow that is sensitive to lag.
Flag: N/A
Bug: 315379864
Test: TaplWorkspaceTest, TaplTwoPanelWorkspaceTest
Change-Id: Ib7fa8c88c953a55b8923ce6a104b5c205c129173
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 91ef472..6c1a02f 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -21,6 +21,7 @@
import static android.content.pm.PackageManager.MATCH_ALL;
import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;
import static android.view.KeyEvent.ACTION_DOWN;
+import static android.view.MotionEvent.ACTION_SCROLL;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.MotionEvent.AXIS_GESTURE_SWIPE_FINGER_COUNT;
@@ -1702,6 +1703,16 @@
"scrolling");
}
+ void pointerScroll(float pointerX, float pointerY, Direction direction) {
+ executeAndWaitForLauncherEvent(
+ () -> injectEvent(getPointerMotionEvent(
+ ACTION_SCROLL, pointerX, pointerY, direction)),
+ event -> TestProtocol.SCROLL_FINISHED_MESSAGE.equals(event.getClassName()),
+ () -> "Didn't receive a scroll end message: " + direction + " scroll from ("
+ + pointerX + ", " + pointerY + ")",
+ "scrolling");
+ }
+
// Inject a swipe gesture. Inject exactly 'steps' motion points, incrementing event time by a
// fixed interval each time.
public void linearGesture(int startX, int startY, int endX, int endY, int steps,
@@ -1765,6 +1776,41 @@
return getContext().getResources();
}
+ private static MotionEvent getPointerMotionEvent(
+ int action, float x, float y, Direction direction) {
+ MotionEvent.PointerCoords[] coordinates = new MotionEvent.PointerCoords[1];
+ coordinates[0] = new MotionEvent.PointerCoords();
+ coordinates[0].x = x;
+ coordinates[0].y = y;
+ boolean isVertical = direction == Direction.UP || direction == Direction.DOWN;
+ boolean isForward = direction == Direction.RIGHT || direction == Direction.DOWN;
+ coordinates[0].setAxisValue(
+ isVertical ? MotionEvent.AXIS_VSCROLL : MotionEvent.AXIS_HSCROLL,
+ isForward ? 1f : -1f);
+
+ MotionEvent.PointerProperties[] properties = new MotionEvent.PointerProperties[1];
+ properties[0] = new MotionEvent.PointerProperties();
+ properties[0].id = 0;
+ properties[0].toolType = MotionEvent.TOOL_TYPE_MOUSE;
+
+ final long downTime = SystemClock.uptimeMillis();
+ return MotionEvent.obtain(
+ downTime,
+ downTime,
+ action,
+ /* pointerCount= */ 1,
+ properties,
+ coordinates,
+ /* metaState= */ 0,
+ /* buttonState= */ 0,
+ /* xPrecision= */ 1f,
+ /* yPrecision= */ 1f,
+ /* deviceId= */ 0,
+ /* edgeFlags= */ 0,
+ InputDevice.SOURCE_CLASS_POINTER,
+ /* flags= */ 0);
+ }
+
private static MotionEvent getTrackpadMotionEvent(long downTime, long eventTime,
int action, float x, float y, int pointerCount, TrackpadGestureType gestureType) {
MotionEvent.PointerProperties[] pointerProperties =
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index f8fa00c..1b0e59c 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -695,10 +695,9 @@
*/
public void flingForward() {
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
- final UiObject2 workspace = verifyActiveContainer();
- mLauncher.scroll(workspace, Direction.RIGHT,
- new Rect(0, 0, mLauncher.getEdgeSensitivityWidth() + 1, 0),
- FLING_STEPS, false);
+ Rect workspaceBounds = mLauncher.getVisibleBounds(verifyActiveContainer());
+ mLauncher.pointerScroll(
+ workspaceBounds.centerX(), workspaceBounds.centerY(), Direction.RIGHT);
verifyActiveContainer();
}
}
@@ -709,10 +708,9 @@
*/
public void flingBackward() {
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
- final UiObject2 workspace = verifyActiveContainer();
- mLauncher.scroll(workspace, Direction.LEFT,
- new Rect(mLauncher.getEdgeSensitivityWidth() + 1, 0, 0, 0),
- FLING_STEPS, false);
+ Rect workspaceBounds = mLauncher.getVisibleBounds(verifyActiveContainer());
+ mLauncher.pointerScroll(
+ workspaceBounds.centerX(), workspaceBounds.centerY(), Direction.LEFT);
verifyActiveContainer();
}
}