1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.launcher3.testing.shared;
18 
19 import android.util.Log;
20 
21 /**
22  * Protocol for custom accessibility events for communication with UI Automation tests.
23  */
24 public final class TestProtocol {
25     public static final String STATE_FIELD = "state";
26     public static final String SWITCHED_TO_STATE_MESSAGE = "TAPL_SWITCHED_TO_STATE";
27     public static final String SCROLL_FINISHED_MESSAGE = "TAPL_SCROLL_FINISHED";
28     public static final String PAUSE_DETECTED_MESSAGE = "TAPL_PAUSE_DETECTED";
29     public static final String DISMISS_ANIMATION_ENDS_MESSAGE = "TAPL_DISMISS_ANIMATION_ENDS";
30     public static final String FOLDER_OPENED_MESSAGE = "TAPL_FOLDER_OPENED";
31     public static final String SEARCH_RESULT_COMPLETE = "SEARCH_RESULT_COMPLETE";
32     public static final String LAUNCHER_ACTIVITY_STOPPED_MESSAGE = "TAPL_LAUNCHER_ACTIVITY_STOPPED";
33     public static final String WALLPAPER_OPEN_ANIMATION_FINISHED_MESSAGE =
34             "TAPL_WALLPAPER_OPEN_ANIMATION_FINISHED";
35     public static final int NORMAL_STATE_ORDINAL = 0;
36     public static final int SPRING_LOADED_STATE_ORDINAL = 1;
37     public static final int OVERVIEW_STATE_ORDINAL = 2;
38     public static final int OVERVIEW_MODAL_TASK_STATE_ORDINAL = 3;
39     public static final int QUICK_SWITCH_STATE_ORDINAL = 4;
40     public static final int ALL_APPS_STATE_ORDINAL = 5;
41     public static final int BACKGROUND_APP_STATE_ORDINAL = 6;
42     public static final int HINT_STATE_ORDINAL = 7;
43     public static final int HINT_STATE_TWO_BUTTON_ORDINAL = 8;
44     public static final int OVERVIEW_SPLIT_SELECT_ORDINAL = 9;
45     public static final int EDIT_MODE_STATE_ORDINAL = 10;
46     public static final String SEQUENCE_MAIN = "Main";
47     public static final String SEQUENCE_TIS = "TIS";
48     public static final String SEQUENCE_PILFER = "Pilfer";
49 
stateOrdinalToString(int ordinal)50     public static String stateOrdinalToString(int ordinal) {
51         switch (ordinal) {
52             case NORMAL_STATE_ORDINAL:
53                 return "Normal";
54             case SPRING_LOADED_STATE_ORDINAL:
55                 return "SpringLoaded";
56             case OVERVIEW_STATE_ORDINAL:
57                 return "Overview";
58             case OVERVIEW_MODAL_TASK_STATE_ORDINAL:
59                 return "OverviewModal";
60             case QUICK_SWITCH_STATE_ORDINAL:
61                 return "QuickSwitch";
62             case ALL_APPS_STATE_ORDINAL:
63                 return "AllApps";
64             case BACKGROUND_APP_STATE_ORDINAL:
65                 return "Background";
66             case HINT_STATE_ORDINAL:
67                 return "Hint";
68             case HINT_STATE_TWO_BUTTON_ORDINAL:
69                 return "Hint2Button";
70             case OVERVIEW_SPLIT_SELECT_ORDINAL:
71                 return "OverviewSplitSelect";
72             case EDIT_MODE_STATE_ORDINAL:
73                 return "EditMode";
74             default:
75                 return "Unknown";
76         }
77     }
78 
79     public static final String TEST_INFO_REQUEST_FIELD = "request";
80     public static final String TEST_INFO_RESPONSE_FIELD = "response";
81 
82     public static final String REQUEST_HOME_TO_OVERVIEW_SWIPE_HEIGHT =
83             "home-to-overview-swipe-height";
84     public static final String REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT =
85             "background-to-overview-swipe-height";
86     public static final String REQUEST_HOME_TO_ALL_APPS_SWIPE_HEIGHT =
87             "home-to-all-apps-swipe-height";
88     public static final String REQUEST_ICON_HEIGHT =
89             "icon-height";
90     public static final String REQUEST_IS_LAUNCHER_INITIALIZED = "is-launcher-initialized";
91     public static final String REQUEST_IS_LAUNCHER_LAUNCHER_ACTIVITY_STARTED =
92             "is-launcher-activity-started";
93     public static final String REQUEST_FREEZE_APP_LIST = "freeze-app-list";
94     public static final String REQUEST_UNFREEZE_APP_LIST = "unfreeze-app-list";
95     public static final String REQUEST_ENABLE_BLOCK_TIMEOUT = "enable-block-timeout";
96     public static final String REQUEST_DISABLE_BLOCK_TIMEOUT = "disable-block-timeout";
97     public static final String REQUEST_ENABLE_TRANSIENT_TASKBAR = "enable-transient-taskbar";
98     public static final String REQUEST_DISABLE_TRANSIENT_TASKBAR = "disable-transient-taskbar";
99     public static final String REQUEST_IS_TRANSIENT_TASKBAR = "is-transient-taskbar";
100     public static final String REQUEST_UNSTASH_TASKBAR_IF_STASHED = "unstash-taskbar-if-stashed";
101     public static final String REQUEST_TASKBAR_FROM_NAV_THRESHOLD = "taskbar-from-nav-threshold";
102     public static final String REQUEST_STASHED_TASKBAR_SCALE = "taskbar-stash-handle-scale";
103     public static final String REQUEST_RECREATE_TASKBAR = "recreate-taskbar";
104     public static final String REQUEST_TASKBAR_IME_DOCKED = "taskbar-ime-docked";
105     public static final String REQUEST_APP_LIST_FREEZE_FLAGS = "app-list-freeze-flags";
106     public static final String REQUEST_APPS_LIST_SCROLL_Y = "apps-list-scroll-y";
107     public static final String REQUEST_TASKBAR_APPS_LIST_SCROLL_Y = "taskbar-apps-list-scroll-y";
108     public static final String REQUEST_WIDGETS_SCROLL_Y = "widgets-scroll-y";
109     public static final String REQUEST_TARGET_INSETS = "target-insets";
110     public static final String REQUEST_WINDOW_INSETS = "window-insets";
111     public static final String REQUEST_SYSTEM_GESTURE_REGION = "gesture-region";
112     public static final String REQUEST_PID = "pid";
113     public static final String REQUEST_FORCE_GC = "gc";
114     public static final String REQUEST_RECENT_TASKS_LIST = "recent-tasks-list";
115     public static final String REQUEST_START_EVENT_LOGGING = "start-event-logging";
116     public static final String REQUEST_GET_TEST_EVENTS = "get-test-events";
117     public static final String REQUEST_GET_HAD_NONTEST_EVENTS = "get-had-nontest-events";
118     public static final String REQUEST_STOP_EVENT_LOGGING = "stop-event-logging";
119     public static final String REQUEST_REINITIALIZE_DATA = "reinitialize-data";
120     public static final String REQUEST_CLEAR_DATA = "clear-data";
121     public static final String REQUEST_HOTSEAT_ICON_NAMES = "get-hotseat-icon-names";
122     public static final String REQUEST_IS_TABLET = "is-tablet";
123     public static final String REQUEST_IS_PREDICTIVE_BACK_SWIPE_ENABLED =
124             "is-predictive-back-swipe-enabled";
125     public static final String REQUEST_ENABLE_TASKBAR_NAVBAR_UNIFICATION =
126             "enable-taskbar-navbar-unification";
127     public static final String REQUEST_NUM_ALL_APPS_COLUMNS = "num-all-apps-columns";
128     public static final String REQUEST_IS_TWO_PANELS = "is-two-panel";
129     public static final String REQUEST_CELL_LAYOUT_BOARDER_HEIGHT = "cell-layout-boarder-height";
130     public static final String REQUEST_START_DRAG_THRESHOLD = "start-drag-threshold";
131     public static final String REQUEST_SHELL_DRAG_READY = "shell-drag-ready";
132     public static final String REQUEST_GET_ACTIVITIES_CREATED_COUNT =
133             "get-activities-created-count";
134     public static final String REQUEST_GET_ACTIVITIES = "get-activities";
135     public static final String REQUEST_HAS_TIS = "has-touch-interaction-service";
136     public static final String REQUEST_TASKBAR_ALL_APPS_TOP_PADDING =
137             "taskbar-all-apps-top-padding";
138     public static final String REQUEST_ALL_APPS_TOP_PADDING = "all-apps-top-padding";
139     public static final String REQUEST_ALL_APPS_BOTTOM_PADDING = "all-apps-bottom-padding";
140     public static final String REQUEST_REFRESH_OVERVIEW_TARGET = "refresh-overview-target";
141 
142     public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size";
143     public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center";
144     public static final String REQUEST_WORKSPACE_COLUMNS_ROWS = "workspace-columns-rows";
145 
146     public static final String REQUEST_WORKSPACE_CURRENT_PAGE_INDEX =
147             "workspace-current-page-index";
148 
149     public static final String REQUEST_HOTSEAT_CELL_CENTER = "hotseat-cell-center";
150 
151     public static final String REQUEST_GET_FOCUSED_TASK_HEIGHT_FOR_TABLET =
152             "get-focused-task-height-for-tablet";
153     public static final String REQUEST_GET_GRID_TASK_SIZE_RECT_FOR_TABLET =
154             "get-grid-task-size-rect-for-tablet";
155     public static final String REQUEST_GET_OVERVIEW_PAGE_SPACING = "get-overview-page-spacing";
156     public static final String REQUEST_GET_OVERVIEW_CURRENT_PAGE_INDEX =
157             "get-overview-current-page-index";
158     public static final String REQUEST_GET_SPLIT_SELECTION_ACTIVE = "get-split-selection-active";
159     public static final String REQUEST_ENABLE_ROTATION = "enable_rotation";
160     public static final String REQUEST_ENABLE_SUGGESTION = "enable-suggestion";
161     public static final String REQUEST_MODEL_QUEUE_CLEARED = "model-queue-cleared";
162 
163     public static boolean sDebugTracing = false;
164     public static final String REQUEST_ENABLE_DEBUG_TRACING = "enable-debug-tracing";
165     public static final String REQUEST_DISABLE_DEBUG_TRACING = "disable-debug-tracing";
166 
167 
168     public static boolean sDisableSensorRotation;
169     public static final String REQUEST_MOCK_SENSOR_ROTATION = "mock-sensor-rotation";
170 
171     public static final String PERMANENT_DIAG_TAG = "TaplTarget";
172     public static final String ICON_MISSING = "b/282963545";
173     public static final String UIOBJECT_STALE_ELEMENT = "b/319501259";
174     public static final String TEST_DRAG_APP_ICON_TO_MULTIPLE_WORKSPACES_FAILURE = "b/326908466";
175     public static final String WIDGET_CONFIG_NULL_EXTRA_INTENT = "b/324419890";
176     public static final String OVERVIEW_SELECT_TOOLTIP_MISALIGNED = "b/332485341";
177 
178     public static final String REQUEST_FLAG_ENABLE_GRID_ONLY_OVERVIEW = "enable-grid-only-overview";
179     public static final String REQUEST_FLAG_ENABLE_APP_PAIRS = "enable-app-pairs";
180 
181     public static final String REQUEST_UNSTASH_BUBBLE_BAR_IF_STASHED =
182             "unstash-bubble-bar-if-stashed";
183 
184     public static final String REQUEST_INJECT_FAKE_TRACKPAD = "inject-fake-trackpad";
185     public static final String REQUEST_EJECT_FAKE_TRACKPAD = "eject-fake-trackpad";
186 
187     /** Logs {@link Log#d(String, String)} if {@link #sDebugTracing} is true. */
testLogD(String tag, String message)188     public static void testLogD(String tag, String message) {
189         if (!sDebugTracing) {
190             return;
191         }
192         Log.d(tag, message);
193     }
194 }
195