Sharing protocol constants between Launcher and TAPL

Bug: 110103162
Test: TaplTests
Change-Id: I5b2a2b8576a7a6ea4a156f00858711496d6b5bba
diff --git a/quickstep/src/com/android/quickstep/ActivityControlHelper.java b/quickstep/src/com/android/quickstep/ActivityControlHelper.java
index 185080ee..322e270 100644
--- a/quickstep/src/com/android/quickstep/ActivityControlHelper.java
+++ b/quickstep/src/com/android/quickstep/ActivityControlHelper.java
@@ -51,6 +51,7 @@
 import com.android.launcher3.LauncherInitListener;
 import com.android.launcher3.LauncherState;
 import com.android.launcher3.R;
+import com.android.launcher3.TestProtocol;
 import com.android.launcher3.allapps.AllAppsTransitionController;
 import com.android.launcher3.allapps.DiscoveryBounce;
 import com.android.launcher3.anim.AnimationSuccessListener;
@@ -233,7 +234,8 @@
                 // Optimization, hide the all apps view to prevent layout while initializing
                 activity.getAppsView().getContentView().setVisibility(View.GONE);
 
-                AccessibilityManagerCompat.sendEventToTest(activity, "TAPL_WENT_TO_STATE");
+                AccessibilityManagerCompat.sendEventToTest(
+                        activity, TestProtocol.SWITCHED_TO_STATE_MESSAGE);
             }
 
             return new AnimationFactory() {
diff --git a/src/com/android/launcher3/TestProtocol.java b/src/com/android/launcher3/TestProtocol.java
new file mode 100644
index 0000000..0a3b86d
--- /dev/null
+++ b/src/com/android/launcher3/TestProtocol.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3;
+
+/**
+ * Protocol for custom accessibility events for communication with UI Automation tests.
+ */
+public final class TestProtocol {
+    public static final String GET_SCROLL_MESSAGE = "TAPL_GET_SCROLL";
+    public static final String SCROLL_Y_FIELD = "scrollY";
+    public static final String SWITCHED_TO_STATE_MESSAGE = "TAPL_SWITCHED_TO_STATE";
+    public static final String RESPONSE_MESSAGE_POSTFIX = "_RESPONSE";
+}
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index e5cda21..6908ab4 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -42,6 +42,7 @@
 import com.android.launcher3.ItemInfo;
 import com.android.launcher3.Launcher;
 import com.android.launcher3.R;
+import com.android.launcher3.TestProtocol;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.compat.AccessibilityManagerCompat;
 import com.android.launcher3.config.FeatureFlags;
@@ -576,9 +577,10 @@
     @Override
     public boolean performAccessibilityAction(int action, Bundle arguments) {
         if (AccessibilityManagerCompat.processTestRequest(
-                mLauncher, "TAPL_GET_SCROLL", action, arguments,
+                mLauncher, TestProtocol.GET_SCROLL_MESSAGE, action, arguments,
                 response ->
-                        response.putInt("scrollY", getActiveRecyclerView().getCurrentScrollY()))) {
+                        response.putInt(TestProtocol.SCROLL_Y_FIELD,
+                                getActiveRecyclerView().getCurrentScrollY()))) {
             return true;
         }
 
diff --git a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java
index 3b0226e..02da861 100644
--- a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java
+++ b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java
@@ -23,6 +23,7 @@
 import android.view.accessibility.AccessibilityManager;
 import android.view.accessibility.AccessibilityNodeInfo;
 
+import com.android.launcher3.TestProtocol;
 import com.android.launcher3.Utilities;
 
 public class AccessibilityManagerCompat {
@@ -95,7 +96,7 @@
             final Bundle response = new Bundle();
             responseFiller.accept(response);
             AccessibilityManagerCompat.sendEventToTest(
-                    accessibilityManager, eventTag + "_RESPONSE", response);
+                    accessibilityManager, eventTag + TestProtocol.RESPONSE_MESSAGE_POSTFIX, response);
             return true;
         }
         return false;
diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
index 0e277ea..fd9157e 100644
--- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
+++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
@@ -39,6 +39,7 @@
 import com.android.launcher3.LauncherStateManager.AnimationComponents;
 import com.android.launcher3.LauncherStateManager.AnimationConfig;
 import com.android.launcher3.LauncherStateManager.StateHandler;
+import com.android.launcher3.TestProtocol;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.anim.AnimationSuccessListener;
 import com.android.launcher3.anim.AnimatorPlaybackController;
@@ -517,7 +518,8 @@
             }
             mLauncher.getStateManager().goToState(targetState, false /* animated */);
 
-            AccessibilityManagerCompat.sendEventToTest(mLauncher, "TAPL_WENT_TO_STATE");
+            AccessibilityManagerCompat.sendEventToTest(
+                    mLauncher, TestProtocol.SWITCHED_TO_STATE_MESSAGE);
         }
     }
 
diff --git a/tests/Android.mk b/tests/Android.mk
index 1531c32..03cb154 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -46,7 +46,8 @@
 	libSharedSystemUI
 
 LOCAL_SRC_FILES := $(call all-java-files-under, tapl) \
-  ../quickstep/src/com/android/quickstep/SwipeUpSetting.java
+  ../quickstep/src/com/android/quickstep/SwipeUpSetting.java \
+  ../src/com/android/launcher3/TestProtocol.java
 
 LOCAL_SDK_VERSION := current
 LOCAL_MODULE := ub-launcher-aosp-tapl
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index d64f86c..c3bc61b 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -24,6 +24,8 @@
 
 import androidx.annotation.NonNull;
 
+import com.android.launcher3.TestProtocol;
+
 /**
  * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview.
  */
@@ -96,8 +98,8 @@
     }
 
     private int getScroll(UiObject2 allAppsContainer) {
-        return mLauncher.getAnswerFromLauncher(allAppsContainer, "TAPL_GET_SCROLL").
-                getInt("scrollY", -1);
+        return mLauncher.getAnswerFromLauncher(allAppsContainer, TestProtocol.GET_SCROLL_MESSAGE).
+                getInt(TestProtocol.SCROLL_Y_FIELD, -1);
     }
 
     private void ensureIconVisible(UiObject2 appIcon, UiObject2 allAppsContainer) {
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index fa282c3..01e76f3 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -34,6 +34,7 @@
 import android.support.test.uiautomator.Until;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.launcher3.TestProtocol;
 import com.android.quickstep.SwipeUpSetting;
 
 import java.lang.ref.WeakReference;
@@ -174,7 +175,7 @@
 
     Bundle getAnswerFromLauncher(UiObject2 view, String requestTag) {
         // Send a fake set-text request to Launcher to initiate a response with requested data.
-        final String responseTag = requestTag + "_RESPONSE";
+        final String responseTag = requestTag + TestProtocol.RESPONSE_MESSAGE_POSTFIX;
         return executeAndWaitForEvent(
                 () -> view.setText(requestTag),
                 event -> responseTag.equals(event.getClassName()),
@@ -338,7 +339,7 @@
     void swipe(int startX, int startY, int endX, int endY) {
         executeAndWaitForEvent(
                 () -> mDevice.swipe(startX, startY, endX, endY, 60),
-                event -> "TAPL_WENT_TO_STATE".equals(event.getClassName()),
+                event -> TestProtocol.SWITCHED_TO_STATE_MESSAGE.equals(event.getClassName()),
                 "Swipe failed to receive an event for the swipe end: " + startX + ", " + startY
                         + ", " + endX + ", " + endY);
     }