Fix waiting for launcher initialization

Bug: 137836033

Change-Id: Ifc8ce867abd85eaeacd09a2b39636ecc4109c046
diff --git a/go/quickstep/src/com/android/quickstep/TouchInteractionService.java b/go/quickstep/src/com/android/quickstep/TouchInteractionService.java
index 917800f..577b175 100644
--- a/go/quickstep/src/com/android/quickstep/TouchInteractionService.java
+++ b/go/quickstep/src/com/android/quickstep/TouchInteractionService.java
@@ -186,7 +186,7 @@
         return mMyBinder;
     }
 
-    public static boolean isInputMonitorInitialized() {
+    public static boolean isInitialized() {
         return true;
     }
 }
diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/QuickstepTestInformationHandler.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/QuickstepTestInformationHandler.java
index b507044..4eb9df2 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/QuickstepTestInformationHandler.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/QuickstepTestInformationHandler.java
@@ -38,7 +38,7 @@
 
             case TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED: {
                 response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD,
-                        TouchInteractionService.isInputMonitorInitialized());
+                        TouchInteractionService.isInitialized());
                 return response;
             }
 
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 debed89..d10e512 100644
--- a/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
+++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/TouchInteractionService.java
@@ -77,7 +77,6 @@
 import com.android.launcher3.logging.UserEventDispatcher;
 import com.android.launcher3.model.AppLaunchTracker;
 import com.android.launcher3.provider.RestoreDbTask;
-import com.android.launcher3.testing.TestProtocol;
 import com.android.launcher3.util.LooperExecutor;
 import com.android.launcher3.util.UiThreadHelper;
 import com.android.quickstep.SysUINavigationMode.Mode;
@@ -154,6 +153,7 @@
             MAIN_THREAD_EXECUTOR.execute(TouchInteractionService.this::initInputMonitor);
             MAIN_THREAD_EXECUTOR.execute(TouchInteractionService.this::onSystemUiProxySet);
             MAIN_THREAD_EXECUTOR.execute(() -> preloadOverview(true /* fromInit */));
+            sIsInitialized = true;
         }
 
         @Override
@@ -227,15 +227,15 @@
     };
 
     private static boolean sConnected = false;
-    private static boolean sInputMonitorInitialized = false;
+    private static boolean sIsInitialized = false;
     private static final SwipeSharedState sSwipeSharedState = new SwipeSharedState();
 
     public static boolean isConnected() {
         return sConnected;
     }
 
-    public static boolean isInputMonitorInitialized() {
-        return sInputMonitorInitialized;
+    public static boolean isInitialized() {
+        return sIsInitialized;
     }
 
     public static SwipeSharedState getSwipeSharedState() {
@@ -336,7 +336,6 @@
             mInputMonitorCompat.dispose();
             mInputMonitorCompat = null;
         }
-        sInputMonitorInitialized = false;
     }
 
     private void initInputMonitor() {
@@ -354,7 +353,6 @@
             Log.e(TAG, "Unable to create input monitor", e);
         }
         initTouchBounds();
-        sInputMonitorInitialized = true;
     }
 
     private int getNavbarSize(String resName) {
@@ -492,6 +490,7 @@
 
     @Override
     public void onDestroy() {
+        sIsInitialized = false;
         if (mIsUserUnlocked) {
             mInputConsumer.unregisterInputConsumer();
             mOverviewComponentObserver.onDestroy();
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 79379e5..8639ea2 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -396,7 +396,7 @@
     }
 
     private UiObject2 verifyContainerType(ContainerType containerType) {
-        //waitForTouchInteractionService();
+        waitForLauncherInitialized();
 
         assertEquals("Unexpected display rotation",
                 mExpectedRotation, mDevice.getDisplayRotation());
@@ -468,7 +468,7 @@
         }
     }
 
-    private void waitForTouchInteractionService() {
+    private void waitForLauncherInitialized() {
         for (int i = 0; i < 100; ++i) {
             if (getTestInfo(
                     TestProtocol.REQUEST_IS_LAUNCHER_INITIALIZED).
@@ -477,7 +477,7 @@
             }
             SystemClock.sleep(100);
         }
-        fail("TouchInteractionService didn't connect");
+        fail("Launcher didn't initialize");
     }
 
     Parcelable executeAndWaitForEvent(Runnable command,