From e277fec4660166ff552fe1e0bb7a05c950df3954 Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 31 Mar 2020 19:06:41 -0700 Subject: [PATCH] Events checking for long press events Also fixing duplicate long press events resulting from both framework and Launcher own detection reporting long presses. Change-Id: Ib46de5bd60850f1c5578992c8c1172ddbc0961f3 --- .../launcher3/touch/ItemLongClickListener.java | 5 +++++ .../launcher3/touch/WorkspaceTouchListener.java | 3 +++ src/com/android/launcher3/widget/BaseWidgetSheet.java | 4 ++++ tests/tapl/com/android/launcher3/tapl/AppIcon.java | 8 +++++++- .../com/android/launcher3/tapl/AppIconMenuItem.java | 4 ++++ tests/tapl/com/android/launcher3/tapl/Launchable.java | 5 ++++- .../launcher3/tapl/LauncherInstrumentation.java | 4 +++- tests/tapl/com/android/launcher3/tapl/Widget.java | 11 +++++++++++ tests/tapl/com/android/launcher3/tapl/Workspace.java | 8 ++++++-- 9 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/touch/ItemLongClickListener.java b/src/com/android/launcher3/touch/ItemLongClickListener.java index ba1bfa597b..8537bdfab8 100644 --- a/src/com/android/launcher3/touch/ItemLongClickListener.java +++ b/src/com/android/launcher3/touch/ItemLongClickListener.java @@ -33,6 +33,8 @@ import com.android.launcher3.Launcher; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.folder.Folder; +import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; /** * Class to handle long-clicks on workspace items and start drag as a result. @@ -46,6 +48,7 @@ public class ItemLongClickListener { ItemLongClickListener::onAllAppsItemLongClick; private static boolean onWorkspaceItemLongClick(View v) { + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onWorkspaceItemLongClick"); Launcher launcher = Launcher.getLauncher(v.getContext()); if (!canStartDrag(launcher)) return false; if (!launcher.isInState(NORMAL) && !launcher.isInState(OVERVIEW)) return false; @@ -75,6 +78,8 @@ public class ItemLongClickListener { } private static boolean onAllAppsItemLongClick(View v) { + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "onAllAppsItemLongClick"); + v.cancelLongPress(); Launcher launcher = Launcher.getLauncher(v.getContext()); if (!canStartDrag(launcher)) return false; // When we have exited all apps or are in transition, disregard long clicks diff --git a/src/com/android/launcher3/touch/WorkspaceTouchListener.java b/src/com/android/launcher3/touch/WorkspaceTouchListener.java index 310d598b25..da631bd293 100644 --- a/src/com/android/launcher3/touch/WorkspaceTouchListener.java +++ b/src/com/android/launcher3/touch/WorkspaceTouchListener.java @@ -38,6 +38,8 @@ import com.android.launcher3.DeviceProfile; import com.android.launcher3.Launcher; import com.android.launcher3.Workspace; import com.android.launcher3.dragndrop.DragLayer; +import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.views.OptionsPopupView; import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; @@ -165,6 +167,7 @@ public class WorkspaceTouchListener extends GestureDetector.SimpleOnGestureListe @Override public void onLongPress(MotionEvent event) { + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Workspace.longPress"); if (mLongPressState == STATE_REQUESTED) { if (canHandleLongPress()) { mLongPressState = STATE_PENDING_PARENT_INFORM; diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index 73a061594f..23c2160848 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -33,6 +33,8 @@ import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.dragndrop.DragOptions; import com.android.launcher3.popup.PopupDataProvider; +import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.ItemLongClickListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; @@ -92,6 +94,8 @@ abstract class BaseWidgetSheet extends AbstractSlideInView @Override public boolean onLongClick(View v) { + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Widgets.onLongClick"); + v.cancelLongPress(); if (!ItemLongClickListener.canStartDrag(mLauncher)) return false; if (v instanceof WidgetCell) { diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index 8932291f94..bdfd563943 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -32,6 +32,7 @@ import java.util.regex.Pattern; public final class AppIcon extends Launchable { private static final Pattern START_EVENT = Pattern.compile("start:"); + private static final Pattern LONG_CLICK_EVENT = Pattern.compile("onAllAppsItemLongClick"); AppIcon(LauncherInstrumentation launcher, UiObject2 icon) { super(launcher, icon); @@ -47,10 +48,15 @@ public final class AppIcon extends Launchable { public AppIconMenu openMenu() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { return new AppIconMenu(mLauncher, mLauncher.clickAndGet( - mObject, "deep_shortcuts_container")); + mObject, "deep_shortcuts_container", LONG_CLICK_EVENT)); } } + @Override + protected void addExpectedEventsForLongClick() { + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT); + } + @Override protected String getLongPressIndicator() { return "deep_shortcuts_container"; diff --git a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java index f8dd89c60c..37a7b91c62 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java @@ -40,6 +40,10 @@ public class AppIconMenuItem extends Launchable { return mObject.getText(); } + @Override + protected void addExpectedEventsForLongClick() { + } + @Override protected String getLongPressIndicator() { return "drop_target_bar"; diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index d1a1254eed..2177032e6e 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -92,9 +92,12 @@ abstract class Launchable { : launchableCenter.x + width / 2, displaySize.y / 2), getLongPressIndicator(), - startsActivity); + startsActivity, + () -> addExpectedEventsForLongClick()); } } + protected abstract void addExpectedEventsForLongClick(); + protected abstract String getLongPressIndicator(); } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index d171a695a7..fbf85080e8 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -1173,10 +1173,12 @@ public final class LauncherInstrumentation { } @NonNull - UiObject2 clickAndGet(@NonNull final UiObject2 target, @NonNull String resName) { + UiObject2 clickAndGet( + @NonNull final UiObject2 target, @NonNull String resName, Pattern longClickEvent) { final Point targetCenter = target.getVisibleCenter(); final long downTime = SystemClock.uptimeMillis(); sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, targetCenter, GestureScope.INSIDE); + expectEvent(TestProtocol.SEQUENCE_MAIN, longClickEvent); final UiObject2 result = waitForLauncherObject(resName); sendPointer(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, targetCenter, GestureScope.INSIDE); diff --git a/tests/tapl/com/android/launcher3/tapl/Widget.java b/tests/tapl/com/android/launcher3/tapl/Widget.java index a658f16deb..53ef796c90 100644 --- a/tests/tapl/com/android/launcher3/tapl/Widget.java +++ b/tests/tapl/com/android/launcher3/tapl/Widget.java @@ -18,11 +18,17 @@ package com.android.launcher3.tapl; import androidx.test.uiautomator.UiObject2; +import com.android.launcher3.testing.TestProtocol; + +import java.util.regex.Pattern; + /** * Widget in workspace or a widget list. */ public final class Widget extends Launchable { + private static final Pattern LONG_CLICK_EVENT = Pattern.compile("Widgets.onLongClick"); + Widget(LauncherInstrumentation launcher, UiObject2 icon) { super(launcher, icon); } @@ -35,4 +41,9 @@ public final class Widget extends Launchable { @Override protected void expectActivityStartEvents() { } + + @Override + protected void addExpectedEventsForLongClick() { + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT); + } } diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 9ef64767e6..86aafc21f4 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -52,6 +52,7 @@ public final class Workspace extends Home { static final Pattern EVENT_CTRL_W_UP = Pattern.compile( "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_W" + ".*?metaState=META_CTRL_ON"); + private static final Pattern LONG_CLICK_EVENT = Pattern.compile("onWorkspaceItemLongClick"); private final UiObject2 mHotseat; @@ -178,7 +179,9 @@ public final class Workspace extends Home { new Point(mLauncher.getDevice().getDisplayWidth(), workspace.getVisibleBounds().centerY()), "deep_shortcuts_container", - false); + false, + () -> mLauncher.expectEvent( + TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT)); verifyActiveContainer(); } } @@ -199,7 +202,7 @@ public final class Workspace extends Home { static void dragIconToWorkspace( LauncherInstrumentation launcher, Launchable launchable, Point dest, - String longPressIndicator, boolean startsActivity) { + String longPressIndicator, boolean startsActivity, Runnable expectLongClickEvents) { LauncherInstrumentation.log("dragIconToWorkspace: begin"); final Point launchableCenter = launchable.getObject().getVisibleCenter(); final long downTime = SystemClock.uptimeMillis(); @@ -208,6 +211,7 @@ public final class Workspace extends Home { launcher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, launchableCenter, LauncherInstrumentation.GestureScope.INSIDE); LauncherInstrumentation.log("dragIconToWorkspace: sent down"); + expectLongClickEvents.run(); launcher.waitForLauncherObject(longPressIndicator); LauncherInstrumentation.log("dragIconToWorkspace: indicator"); launcher.movePointer(launchableCenter, dest, 10, downTime, true,