From 853852351f3b1bd9fbaa063b0e99cd8067e61c50 Mon Sep 17 00:00:00 2001 From: vadimt Date: Fri, 28 Jun 2019 12:04:36 -0700 Subject: [PATCH] Correctly restarting Launcher from OOP tests Waiting for touch interaction service; waiting for package-restart events. Bug: 136215685 Change-Id: I0c31c09fe3a58b898168dfdb4e4d23757b94a47c --- .../android/quickstep/TouchInteractionService.java | 4 ++++ .../android/quickstep/TouchInteractionService.java | 7 +++++++ .../quickstep/QuickstepTestInformationHandler.java | 9 ++++++++- .../launcher3/testing/TestInformationHandler.java | 5 +++++ .../android/launcher3/testing/TestProtocol.java | 1 + .../launcher3/tapl/LauncherInstrumentation.java | 14 ++++++++++++++ 6 files changed, 39 insertions(+), 1 deletion(-) diff --git a/go/quickstep/src/com/android/quickstep/TouchInteractionService.java b/go/quickstep/src/com/android/quickstep/TouchInteractionService.java index c902826ed8..917800f2a6 100644 --- a/go/quickstep/src/com/android/quickstep/TouchInteractionService.java +++ b/go/quickstep/src/com/android/quickstep/TouchInteractionService.java @@ -185,4 +185,8 @@ public class TouchInteractionService extends Service { } return mMyBinder; } + + public static boolean isInputMonitorInitialized() { + return true; + } } 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 0ef2f5c5ad..dd04024539 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java @@ -226,12 +226,17 @@ public class TouchInteractionService extends Service implements }; private static boolean sConnected = false; + private static boolean sInputMonitorInitialized = false; private static final SwipeSharedState sSwipeSharedState = new SwipeSharedState(); public static boolean isConnected() { return sConnected; } + public static boolean isInputMonitorInitialized() { + return sInputMonitorInitialized; + } + public static SwipeSharedState getSwipeSharedState() { return sSwipeSharedState; } @@ -325,6 +330,7 @@ public class TouchInteractionService extends Service implements mInputMonitorCompat.dispose(); mInputMonitorCompat = null; } + sInputMonitorInitialized = false; } private void initInputMonitor() { @@ -342,6 +348,7 @@ public class TouchInteractionService extends Service implements Log.e(TAG, "Unable to create input monitor", e); } initTouchBounds(); + sInputMonitorInitialized = true; } private int getNavbarSize(String resName) { diff --git a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java index 89513634fe..b59e13362d 100644 --- a/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java +++ b/quickstep/src/com/android/quickstep/QuickstepTestInformationHandler.java @@ -10,7 +10,8 @@ import com.android.quickstep.util.LayoutUtils; public class QuickstepTestInformationHandler extends TestInformationHandler { - public QuickstepTestInformationHandler(Context context) { } + public QuickstepTestInformationHandler(Context context) { + } @Override public Bundle call(String method) { @@ -29,6 +30,12 @@ public class QuickstepTestInformationHandler extends TestInformationHandler { response.putInt(TestProtocol.TEST_INFO_RESPONSE_FIELD, (int) swipeHeight); return response; } + + case TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED: { + response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, + TouchInteractionService.isInputMonitorInitialized()); + break; + } } return super.call(method); diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index d2e196138c..bab454f070 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -74,6 +74,11 @@ public class TestInformationHandler implements ResourceBasedOverride { break; } + case TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED: { + response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, true); + break; + } + case TestProtocol.REQUEST_ENABLE_DEBUG_TRACING: TestProtocol.sDebugTracing = true; break; diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 3774042c93..3a07be0968 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -66,6 +66,7 @@ public final class TestProtocol { "all-apps-to-overview-swipe-height"; public static final String REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT = "home-to-all-apps-swipe-height"; + public static final String REQUEST_IS_LAUNCHER_INITIALIZED = "is-launcher-initialized"; public static final String REQUEST_FREEZE_APP_LIST = "freeze-app-list"; public static final String REQUEST_UNFREEZE_APP_LIST = "unfreeze-app-list"; public static final String REQUEST_APP_LIST_FREEZE_FLAGS = "app-list-freeze-flags"; diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 11b0665d95..2b0a794ea6 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -444,6 +444,8 @@ public final class LauncherInstrumentation { } private UiObject2 verifyContainerType(ContainerType containerType) { + waitForTouchInteractionService(); + assertEquals("Unexpected display rotation", mExpectedRotation, mDevice.getDisplayRotation()); @@ -514,6 +516,18 @@ public final class LauncherInstrumentation { } } + private void waitForTouchInteractionService() { + for (int i = 0; i < 100; ++i) { + if (getTestInfo( + TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED). + getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD)) { + return; + } + SystemClock.sleep(100); + } + fail("TouchInteractionService didn't connect"); + } + Parcelable executeAndWaitForEvent(Runnable command, UiAutomation.AccessibilityEventFilter eventFilter, String message) { try {