From 539c2703ea9587bcc21ea7365b40fc9d46f6002c Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Thu, 30 Jun 2022 12:10:03 -0700 Subject: [PATCH] Move TEST_HARNESS_TRIGGER_TIMEOUT to MotionPauseDetector directly - Removed TestProtocol.sForcePauseTimeout and TestProtocol.REQUEST_SET_FORCE_PAUSE_TIMEOUT - Instead, add MotionPauseDetector.TEST_HARNESS_TRIGGER_TIMEOUT, which is used when Utilities.IS_RUNNING_IN_TEST_HARNESS. Test: unbundled/launcher/launcher3_test_platform Fixes: 232548865 Change-Id: I224e99042b41375cab6bffd555434217518958c5 --- .../quickstep/util/MotionPauseDetector.java | 16 ++++++++++++---- .../testing/TestInformationHandler.java | 4 ---- .../android/launcher3/testing/TestProtocol.java | 3 --- .../launcher3/tapl/LauncherInstrumentation.java | 7 ------- 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java index b83e26e5de..bad5a58980 100644 --- a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java +++ b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java @@ -22,8 +22,8 @@ import android.view.VelocityTracker; import com.android.launcher3.Alarm; import com.android.launcher3.R; +import com.android.launcher3.Utilities; import com.android.launcher3.compat.AccessibilityManagerCompat; -import com.android.launcher3.testing.TestProtocol; /** * Given positions along x- or y-axis, tracks velocity and acceleration and determines when there is @@ -43,6 +43,12 @@ public class MotionPauseDetector { */ private static final long HARDER_TRIGGER_TIMEOUT = 400; + /** + * When running in a test harness, if no motion is added for this amount of time, assume the + * motion has paused. (We use an increased timeout since sometimes test devices can be slow.) + */ + private static final long TEST_HARNESS_TRIGGER_TIMEOUT = 2000; + private final float mSpeedVerySlow; private final float mSpeedSlow; private final float mSpeedSomewhatFast; @@ -119,9 +125,11 @@ public class MotionPauseDetector { * @param pointerIndex Index for the pointer being tracked in the motion event */ public void addPosition(MotionEvent ev, int pointerIndex) { - long timeoutMs = TestProtocol.sForcePauseTimeout != null - ? TestProtocol.sForcePauseTimeout - : mMakePauseHarderToTrigger ? HARDER_TRIGGER_TIMEOUT : FORCE_PAUSE_TIMEOUT; + long timeoutMs = Utilities.IS_RUNNING_IN_TEST_HARNESS + ? TEST_HARNESS_TRIGGER_TIMEOUT + : mMakePauseHarderToTrigger + ? HARDER_TRIGGER_TIMEOUT + : FORCE_PAUSE_TIMEOUT; mForcePauseTimeout.setAlarm(timeoutMs); float newVelocity = mVelocityProvider.addMotionEvent(ev, ev.getPointerId(pointerIndex)); if (mPreviousVelocity != null) { diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 242d2d423c..94d8865501 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -153,10 +153,6 @@ public class TestInformationHandler implements ResourceBasedOverride { mDeviceProfile.isTwoPanels); return response; - case TestProtocol.REQUEST_SET_FORCE_PAUSE_TIMEOUT: - TestProtocol.sForcePauseTimeout = Long.parseLong(arg); - return response; - case TestProtocol.REQUEST_GET_HAD_NONTEST_EVENTS: response.putBoolean( TestProtocol.TEST_INFO_RESPONSE_FIELD, TestLogging.sHadEventsNotFromTest); diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 3a030a8b87..926ca71c88 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -122,9 +122,6 @@ public final class TestProtocol { public static final String REQUEST_GET_OVERVIEW_PAGE_SPACING = "get-overview-page-spacing"; public static final String REQUEST_ENABLE_ROTATION = "enable_rotation"; - public static Long sForcePauseTimeout; - public static final String REQUEST_SET_FORCE_PAUSE_TIMEOUT = "set-force-pause-timeout"; - public static boolean sDebugTracing = false; public static final String REQUEST_ENABLE_DEBUG_TRACING = "enable-debug-tracing"; public static final String REQUEST_DISABLE_DEBUG_TRACING = "disable-debug-tracing"; diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 9d25b1ba90..41f3bd37d0 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -84,7 +84,6 @@ import java.util.Deque; import java.util.LinkedList; import java.util.List; import java.util.Optional; -import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.function.Function; @@ -101,7 +100,6 @@ public final class LauncherInstrumentation { private static final String TAG = "Tapl"; private static final int ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME = 15; private static final int GESTURE_STEP_MS = 16; - private static final long FORCE_PAUSE_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(2); static final Pattern EVENT_TOUCH_DOWN = getTouchEventPattern("ACTION_DOWN"); static final Pattern EVENT_TOUCH_UP = getTouchEventPattern("ACTION_UP"); @@ -362,10 +360,6 @@ public final class LauncherInstrumentation { return getRealDisplaySize().x / 2f; } - private void setForcePauseTimeout(long timeout) { - getTestInfo(TestProtocol.REQUEST_SET_FORCE_PAUSE_TIMEOUT, Long.toString(timeout)); - } - public void setEnableRotation(boolean on) { getTestInfo(TestProtocol.REQUEST_ENABLE_ROTATION, Boolean.toString(on)); } @@ -886,7 +880,6 @@ public final class LauncherInstrumentation { final String action; if (getNavigationModel() == NavigationModel.ZERO_BUTTON) { checkForAnomaly(false, true); - setForcePauseTimeout(FORCE_PAUSE_TIMEOUT_MS); final Point displaySize = getRealDisplaySize(); // The swipe up to home gesture starts from inside the launcher when the user is