From d633c9c7da87d6eab96d72c5f6480d6e9eb27c6a Mon Sep 17 00:00:00 2001 From: vadimt Date: Wed, 22 Jan 2020 18:00:37 -0800 Subject: [PATCH] Verifying events from TouchInteractionService MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a guaranteed order in which TIS events will be registered relative to other TIS events. However, relative to the touch events arriving to the activity, TIS events can come in any order. Now the event checker verifies 2 independent ordered event sequences: from TIS, and “the rest” (Main). Change-Id: I5872e0e3b0b498050a91c67105fbe4a29411375a --- .../quickstep/TouchInteractionService.java | 8 +- .../inputconsumers/DelegateInputConsumer.java | 3 +- .../DeviceLockedInputConsumer.java | 3 +- .../OtherActivityInputConsumer.java | 3 +- .../inputconsumers/OverviewInputConsumer.java | 3 +- .../OverviewWithoutFocusInputConsumer.java | 3 +- .../com/android/quickstep/views/TaskView.java | 6 +- src/com/android/launcher3/BaseActivity.java | 5 +- .../launcher3/BaseDraggingActivity.java | 5 +- src/com/android/launcher3/Launcher.java | 8 +- .../launcher3/testing/TestLogging.java | 21 +- .../launcher3/testing/TestProtocol.java | 2 + .../launcher3/tapl/AddToHomeScreenPrompt.java | 9 + .../com/android/launcher3/tapl/AppIcon.java | 4 +- .../launcher3/tapl/AppIconMenuItem.java | 4 +- .../android/launcher3/tapl/Background.java | 8 +- .../tapl/LauncherInstrumentation.java | 194 +++++++++++++----- .../android/launcher3/tapl/OverviewTask.java | 4 +- .../com/android/launcher3/tapl/Workspace.java | 4 +- 19 files changed, 218 insertions(+), 79 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java index edaef30a8e..693f22347f 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java @@ -145,7 +145,7 @@ public class TouchInteractionService extends Service implements PluginListener ActiveGestureLog.INSTANCE.addLog("startQuickstep"); } if (mInputMonitor != null) { - TestLogging.recordEvent("pilferPointers"); + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "pilferPointers"); mInputMonitor.pilferPointers(); } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java index 6bfc3fd6b9..823b254d80 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/inputconsumers/OverviewWithoutFocusInputConsumer.java @@ -23,6 +23,7 @@ import com.android.launcher3.BaseActivity; import com.android.launcher3.BaseDraggingActivity; import com.android.launcher3.logging.StatsLogUtils; import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; import com.android.quickstep.GestureState; @@ -64,7 +65,7 @@ public class OverviewWithoutFocusInputConsumer implements InputConsumer { private void onInterceptTouch() { if (mInputMonitor != null) { - TestLogging.recordEvent("pilferPointers"); + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "pilferPointers"); mInputMonitor.pilferPointers(); } } diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java index 294bb7b564..8b7ce10b2b 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/TaskView.java @@ -58,6 +58,7 @@ import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.popup.SystemShortcut; import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction; import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Touch; @@ -334,9 +335,8 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable { Consumer resultCallback, Handler resultCallbackHandler) { if (mTask != null) { final ActivityOptions opts; - if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { - TestLogging.recordEvent("startActivityFromRecentsAsync:" + mTask); - } + TestLogging.recordEvent( + TestProtocol.SEQUENCE_MAIN, "startActivityFromRecentsAsync", mTask); if (animate) { opts = mActivity.getActivityLaunchOptions(this); if (freezeTaskList) { diff --git a/src/com/android/launcher3/BaseActivity.java b/src/com/android/launcher3/BaseActivity.java index f3c5191bbe..217a41c083 100644 --- a/src/com/android/launcher3/BaseActivity.java +++ b/src/com/android/launcher3/BaseActivity.java @@ -42,6 +42,7 @@ import com.android.launcher3.logging.StatsLogUtils.LogStateProvider; import com.android.launcher3.logging.UserEventDispatcher; import com.android.launcher3.logging.UserEventDispatcher.UserEventDelegate; import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.userevent.nano.LauncherLogProto; import com.android.launcher3.util.SystemUiController; import com.android.launcher3.util.ViewCache; @@ -330,9 +331,7 @@ public abstract class BaseActivity extends Activity return; } try { - if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { - TestLogging.recordEvent("start: shortcut: " + packageName); - } + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "start: shortcut", packageName); getSystemService(LauncherApps.class).startShortcut(packageName, id, sourceBounds, startActivityOptions, user); } catch (SecurityException | IllegalStateException e) { diff --git a/src/com/android/launcher3/BaseDraggingActivity.java b/src/com/android/launcher3/BaseDraggingActivity.java index dda38b308d..8d4af11dcc 100644 --- a/src/com/android/launcher3/BaseDraggingActivity.java +++ b/src/com/android/launcher3/BaseDraggingActivity.java @@ -37,6 +37,7 @@ import androidx.annotation.Nullable; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.model.AppLaunchTracker; import com.android.launcher3.testing.TestLogging; +import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.touch.ItemClickHandler; import com.android.launcher3.uioverrides.DisplayRotationListener; import com.android.launcher3.uioverrides.WallpaperColorInfo; @@ -167,9 +168,7 @@ public abstract class BaseDraggingActivity extends BaseActivity startShortcutIntentSafely(intent, optsBundle, item, sourceContainer); } else if (user == null || user.equals(Process.myUserHandle())) { // Could be launching some bookkeeping activity - if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { - TestLogging.recordEvent("start: activity: " + intent); - } + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "start: activity", intent); startActivity(intent, optsBundle); AppLaunchTracker.INSTANCE.get(this).onStartApp(intent.getComponent(), Process.myUserHandle(), sourceContainer); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index d2506588e1..a53805ffad 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -1778,17 +1778,13 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns, @Override public boolean dispatchKeyEvent(KeyEvent event) { - if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { - TestLogging.recordEvent("Key event: " + event); - } + TestLogging.recordEvent(TestProtocol.SEQUENCE_MAIN, "Key event", event); return (event.getKeyCode() == KeyEvent.KEYCODE_HOME) || super.dispatchKeyEvent(event); } @Override public boolean dispatchTouchEvent(MotionEvent ev) { - if (Utilities.IS_RUNNING_IN_TEST_HARNESS && ev.getAction() != MotionEvent.ACTION_MOVE) { - TestLogging.recordEvent("Touch event: " + ev); - } + TestLogging.recordMotionEvent(TestProtocol.SEQUENCE_MAIN, "Touch event", ev); return super.dispatchTouchEvent(ev); } diff --git a/src/com/android/launcher3/testing/TestLogging.java b/src/com/android/launcher3/testing/TestLogging.java index fd066c1ce1..d522d81665 100644 --- a/src/com/android/launcher3/testing/TestLogging.java +++ b/src/com/android/launcher3/testing/TestLogging.java @@ -17,13 +17,30 @@ package com.android.launcher3.testing; import android.util.Log; +import android.view.MotionEvent; import com.android.launcher3.Utilities; public final class TestLogging { - public static void recordEvent(String event) { + private static void recordEventSlow(String sequence, String event) { + Log.d(TestProtocol.TAPL_EVENTS_TAG, sequence + " / " + event); + } + + public static void recordEvent(String sequence, String event) { if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { - Log.d(TestProtocol.TAPL_EVENTS_TAG, event); + recordEventSlow(sequence, event); + } + } + + public static void recordEvent(String sequence, String message, Object parameter) { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS) { + recordEventSlow(sequence, message + ": " + parameter); + } + } + + public static void recordMotionEvent(String sequence, String message, MotionEvent event) { + if (Utilities.IS_RUNNING_IN_TEST_HARNESS && event.getAction() != MotionEvent.ACTION_MOVE) { + recordEventSlow(sequence, message + ": " + event); } } } diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 2f053c99e8..35a7f3e622 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -33,6 +33,8 @@ public final class TestProtocol { public static final int BACKGROUND_APP_STATE_ORDINAL = 6; public static final int HINT_STATE_ORDINAL = 7; public static final String TAPL_EVENTS_TAG = "TaplEvents"; + public static final String SEQUENCE_MAIN = "Main"; + public static final String SEQUENCE_TIS = "TIS"; public static String stateOrdinalToString(int ordinal) { switch (ordinal) { diff --git a/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java b/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java index afb50e06f3..468f54c0d9 100644 --- a/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java +++ b/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java @@ -21,6 +21,8 @@ import static java.util.regex.Pattern.CASE_INSENSITIVE; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; +import com.android.launcher3.testing.TestProtocol; + import java.util.regex.Pattern; public class AddToHomeScreenPrompt { @@ -38,6 +40,13 @@ public class AddToHomeScreenPrompt { public void addAutomatically() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + if (mLauncher.getNavigationModel() + != LauncherInstrumentation.NavigationModel.THREE_BUTTON) { + mLauncher.expectEvent( + TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_DOWN_TIS); + mLauncher.expectEvent( + TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_UP_TIS); + } mLauncher.waitForObjectInContainer( mWidgetCell.getParent().getParent().getParent().getParent(), By.text(ADD_AUTOMATICALLY)).click(); diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index 3f814fd1eb..8932291f94 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -22,6 +22,8 @@ import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.UiObject2; +import com.android.launcher3.testing.TestProtocol; + import java.util.regex.Pattern; /** @@ -56,6 +58,6 @@ public final class AppIcon extends Launchable { @Override protected void expectActivityStartEvents() { - mLauncher.expectEvent(START_EVENT); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, START_EVENT); } } diff --git a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java index fadfd9ff38..f8dd89c60c 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIconMenuItem.java @@ -18,6 +18,8 @@ package com.android.launcher3.tapl; import androidx.test.uiautomator.UiObject2; +import com.android.launcher3.testing.TestProtocol; + import java.util.regex.Pattern; /** @@ -45,6 +47,6 @@ public class AppIconMenuItem extends Launchable { @Override protected void expectActivityStartEvents() { - mLauncher.expectEvent(START_SHORTCUT_EVENT); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, START_SHORTCUT_EVENT); } } diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 9f29a1a826..2acab97454 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -131,7 +131,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } case THREE_BUTTON: - mLauncher.expectEvent(SQUARE_BUTTON_EVENT); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); mLauncher.runToState( () -> mLauncher.waitForSystemUiObject("recent_apps").click(), OVERVIEW_STATE_ORDINAL); @@ -195,14 +195,14 @@ public class Background extends LauncherInstrumentation.VisibleContainer { case THREE_BUTTON: // Double press the recents button. UiObject2 recentsButton = mLauncher.waitForSystemUiObject("recent_apps"); - mLauncher.expectEvent(SQUARE_BUTTON_EVENT); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); mLauncher.runToState(() -> recentsButton.click(), OVERVIEW_STATE_ORDINAL); mLauncher.getOverview(); - mLauncher.expectEvent(SQUARE_BUTTON_EVENT); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); recentsButton.click(); break; } - mLauncher.expectEvent(TASK_START_EVENT); + mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT); } protected String getSwipeHeightRequestName() { diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 5eb164ecd4..8d98cef867 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -75,8 +75,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.Deque; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.function.Function; @@ -101,13 +103,17 @@ public final class LauncherInstrumentation { static final Pattern EVENT_LOG_ENTRY = Pattern.compile( "(?