• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 package com.android.launcher3.logging;
17 
18 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_CLOSE_DOWN;
19 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ALLAPPS_OPEN_UP;
20 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_HOME_GESTURE;
21 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_OVERVIEW_GESTURE;
22 
23 import android.content.Context;
24 import android.view.View;
25 
26 import androidx.annotation.Nullable;
27 import androidx.slice.SliceItem;
28 
29 import com.android.launcher3.R;
30 import com.android.launcher3.logger.LauncherAtom;
31 import com.android.launcher3.logger.LauncherAtom.ContainerInfo;
32 import com.android.launcher3.logger.LauncherAtom.FromState;
33 import com.android.launcher3.logger.LauncherAtom.ToState;
34 import com.android.launcher3.model.data.ItemInfo;
35 import com.android.launcher3.util.IntArray;
36 import com.android.launcher3.util.ResourceBasedOverride;
37 import com.android.launcher3.views.ActivityContext;
38 
39 import java.util.List;
40 
41 /**
42  * Handles the user event logging in R+.
43  *
44  * <pre>
45  * All of the event ids are defined here.
46  * Most of the methods are placeholder methods for Launcher3
47  * Actual call happens only for Launcher variant that implements QuickStep.
48  * </pre>
49  */
50 public class StatsLogManager implements ResourceBasedOverride {
51 
52     public static final int LAUNCHER_STATE_UNSPECIFIED = 0;
53     public static final int LAUNCHER_STATE_BACKGROUND = 1;
54     public static final int LAUNCHER_STATE_HOME = 2;
55     public static final int LAUNCHER_STATE_OVERVIEW = 3;
56     public static final int LAUNCHER_STATE_ALLAPPS = 4;
57     public static final int LAUNCHER_STATE_UNCHANGED = 5;
58 
59     private InstanceId mInstanceId;
60 
61     protected @Nullable ActivityContext mActivityContext = null;
62     private KeyboardStateManager mKeyboardStateManager;
63 
64     /**
65      * Returns event enum based on the two state transition information when swipe
66      * gesture happens(to be removed during UserEventDispatcher cleanup).
67      */
getLauncherAtomEvent(int startState, int targetState, EventEnum fallbackEvent)68     public static EventEnum getLauncherAtomEvent(int startState,
69             int targetState, EventEnum fallbackEvent) {
70         if (startState == LAUNCHER_STATE_HOME
71                 && targetState == LAUNCHER_STATE_HOME) {
72             return LAUNCHER_HOME_GESTURE;
73         } else if (startState != LAUNCHER_STATE_OVERVIEW
74                 && targetState == LAUNCHER_STATE_OVERVIEW) {
75             return LAUNCHER_OVERVIEW_GESTURE;
76         } else if (startState != LAUNCHER_STATE_ALLAPPS
77                 && targetState == LAUNCHER_STATE_ALLAPPS) {
78             return LAUNCHER_ALLAPPS_OPEN_UP;
79         } else if (startState == LAUNCHER_STATE_ALLAPPS
80                 && targetState != LAUNCHER_STATE_ALLAPPS) {
81             return LAUNCHER_ALLAPPS_CLOSE_DOWN;
82         }
83         return fallbackEvent; // TODO fix
84     }
85 
86     public interface EventEnum {
87 
88         /**
89          * Tag used to request new UI Event IDs via presubmit analysis.
90          *
91          * <p>Use RESERVE_NEW_UI_EVENT_ID as the constructor parameter for a new {@link EventEnum}
92          * to signal the presubmit analyzer to reserve a new ID for the event. The new ID will be
93          * returned as a Gerrit presubmit finding.  Do not submit {@code RESERVE_NEW_UI_EVENT_ID} as
94          * the constructor parameter for any event.
95          *
96          * <pre>
97          * &#064;UiEvent(doc = "Briefly describe the interaction when this event will be logged")
98          * UNIQUE_EVENT_NAME(RESERVE_NEW_UI_EVENT_ID);
99          * </pre>
100          */
101         int RESERVE_NEW_UI_EVENT_ID = Integer.MIN_VALUE; // Negative IDs are ignored by the logger.
102 
getId()103         int getId();
104     }
105 
106     public enum LauncherEvent implements EventEnum {
107         /* Used to prevent double logging. */
108         IGNORE(-1),
109 
110         @UiEvent(doc = "App launched from workspace, hotseat or folder in launcher")
111         LAUNCHER_APP_LAUNCH_TAP(338),
112 
113         @UiEvent(doc = "Task launched from overview using TAP")
114         LAUNCHER_TASK_LAUNCH_TAP(339),
115 
116         @UiEvent(doc = "User tapped on notification inside popup context menu.")
117         LAUNCHER_NOTIFICATION_LAUNCH_TAP(516),
118 
119         @UiEvent(doc = "Task launched from overview using SWIPE DOWN")
120         LAUNCHER_TASK_LAUNCH_SWIPE_DOWN(340),
121 
122         @UiEvent(doc = "TASK dismissed from overview using SWIPE UP")
123         LAUNCHER_TASK_DISMISS_SWIPE_UP(341),
124 
125         @UiEvent(doc = "User dragged a launcher item")
126         LAUNCHER_ITEM_DRAG_STARTED(383),
127 
128         @UiEvent(doc = "A dragged launcher item is successfully dropped onto workspace, hotseat "
129                 + "open folder etc")
130         LAUNCHER_ITEM_DROP_COMPLETED(385),
131 
132         @UiEvent(doc = "A dragged launcher item is successfully dropped onto a folder icon.")
133         LAUNCHER_ITEM_DROP_COMPLETED_ON_FOLDER_ICON(697),
134 
135         @UiEvent(doc = "A dragged launcher item is successfully dropped on another item "
136                 + "resulting in a new folder creation")
137         LAUNCHER_ITEM_DROP_FOLDER_CREATED(386),
138 
139         @UiEvent(doc = "Folder's label is automatically assigned.")
140         LAUNCHER_FOLDER_AUTO_LABELED(591),
141 
142         @UiEvent(doc = "Could not auto-label a folder because primary suggestion is null or empty.")
143         LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY(592),
144 
145         @UiEvent(doc = "Could not auto-label a folder because no suggestions exist.")
146         LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_SUGGESTIONS(593),
147 
148         @UiEvent(doc = "User manually updated the folder label.")
149         LAUNCHER_FOLDER_LABEL_UPDATED(460),
150 
151         @UiEvent(doc = "User long pressed on the workspace empty space.")
152         LAUNCHER_WORKSPACE_LONGPRESS(461),
153 
154         @UiEvent(doc = "User tapped or long pressed on a wallpaper icon inside launcher settings.")
155         LAUNCHER_WALLPAPER_BUTTON_TAP_OR_LONGPRESS(462),
156 
157         @UiEvent(doc = "User tapped or long pressed on settings icon inside launcher settings.")
158         LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS(463),
159 
160         @UiEvent(doc = "User tapped or long pressed on widget tray icon inside launcher settings.")
161         LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS(464),
162 
163         @UiEvent(doc = "User expanded the list of widgets for a single app in the widget picker.")
164         LAUNCHER_WIDGETSTRAY_APP_EXPANDED(818),
165 
166         @UiEvent(doc = "User searched for a widget in the widget picker.")
167         LAUNCHER_WIDGETSTRAY_SEARCHED(819),
168 
169         @UiEvent(doc = "A dragged item is dropped on 'Remove' button in the target bar")
170         LAUNCHER_ITEM_DROPPED_ON_REMOVE(465),
171 
172         @UiEvent(doc = "A dragged item is dropped on 'Cancel' button in the target bar")
173         LAUNCHER_ITEM_DROPPED_ON_CANCEL(466),
174 
175         @UiEvent(doc = "A predicted item is dragged and dropped on 'Don't suggest app'"
176                 + " button in the target bar")
177         LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST(467),
178 
179         @UiEvent(doc = "A dragged item is dropped on 'Uninstall' button in target bar")
180         LAUNCHER_ITEM_DROPPED_ON_UNINSTALL(468),
181 
182         @UiEvent(doc = "User completed uninstalling the package after dropping on "
183                 + "the icon onto 'Uninstall' button in the target bar")
184         LAUNCHER_ITEM_UNINSTALL_COMPLETED(469),
185 
186         @UiEvent(doc = "User cancelled uninstalling the package after dropping on "
187                 + "the icon onto 'Uninstall' button in the target bar")
188         LAUNCHER_ITEM_UNINSTALL_CANCELLED(470),
189 
190         @UiEvent(doc = "User tapped or long pressed on the task icon(aka package icon) "
191                 + "from overview to open task menu.")
192         LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS(517),
193 
194         @UiEvent(doc = "User opened package specific widgets list by tapping on widgets system "
195                 + "shortcut inside popup context menu.")
196         LAUNCHER_SYSTEM_SHORTCUT_WIDGETS_TAP(514),
197 
198         @UiEvent(doc = "User tapped on app info system shortcut.")
199         LAUNCHER_SYSTEM_SHORTCUT_APP_INFO_TAP(515),
200 
201         @UiEvent(doc = "User tapped on split screen icon on a task menu.")
202         LAUNCHER_SYSTEM_SHORTCUT_SPLIT_SCREEN_TAP(518),
203 
204         @UiEvent(doc = "User tapped on free form icon on a task menu.")
205         LAUNCHER_SYSTEM_SHORTCUT_FREE_FORM_TAP(519),
206 
207         @UiEvent(doc = "User tapped on pause app system shortcut.")
208         LAUNCHER_SYSTEM_SHORTCUT_PAUSE_TAP(521),
209 
210         @UiEvent(doc = "User tapped on pin system shortcut.")
211         LAUNCHER_SYSTEM_SHORTCUT_PIN_TAP(522),
212 
213         @UiEvent(doc = "User is shown All Apps education view.")
214         LAUNCHER_ALL_APPS_EDU_SHOWN(523),
215 
216         @UiEvent(doc = "User opened a folder.")
217         LAUNCHER_FOLDER_OPEN(551),
218 
219         @UiEvent(doc = "Hotseat education half sheet seen")
220         LAUNCHER_HOTSEAT_EDU_SEEN(479),
221 
222         @UiEvent(doc = "Hotseat migration accepted")
223         LAUNCHER_HOTSEAT_EDU_ACCEPT(480),
224 
225         @UiEvent(doc = "Hotseat migration denied")
226         LAUNCHER_HOTSEAT_EDU_DENY(481),
227 
228         @UiEvent(doc = "Hotseat education tip shown")
229         LAUNCHER_HOTSEAT_EDU_ONLY_TIP(482),
230 
231         /**
232          * @deprecated LauncherUiChanged.rank field is repurposed to store all apps rank, so no
233          * separate event is required.
234          */
235         @Deprecated
236         @UiEvent(doc = "App launch ranking logged for all apps predictions")
237         LAUNCHER_ALL_APPS_RANKED(552),
238 
239         @UiEvent(doc = "App launch ranking logged for hotseat predictions)")
240         LAUNCHER_HOTSEAT_RANKED(553),
241         @UiEvent(doc = "Launcher is now in background. e.g., Screen off event")
242         LAUNCHER_ONSTOP(562),
243 
244         @UiEvent(doc = "Launcher is now in foreground. e.g., Screen on event, back button")
245         LAUNCHER_ONRESUME(563),
246 
247         @UiEvent(doc = "User swipes or fling in LEFT direction on workspace.")
248         LAUNCHER_SWIPELEFT(564),
249 
250         @UiEvent(doc = "User swipes or fling in RIGHT direction on workspace.")
251         LAUNCHER_SWIPERIGHT(565),
252 
253         @UiEvent(doc = "User swipes or fling in UP direction in unknown way.")
254         LAUNCHER_UNKNOWN_SWIPEUP(566),
255 
256         @UiEvent(doc = "User swipes or fling in DOWN direction in unknown way.")
257         LAUNCHER_UNKNOWN_SWIPEDOWN(567),
258 
259         @UiEvent(doc = "User swipes or fling in UP direction to open apps drawer.")
260         LAUNCHER_ALLAPPS_OPEN_UP(568),
261 
262         @UiEvent(doc = "User swipes or fling in DOWN direction to close apps drawer.")
263         LAUNCHER_ALLAPPS_CLOSE_DOWN(569),
264 
265         @UiEvent(doc = "User tap outside apps drawer sheet to close apps drawer.")
266         LAUNCHER_ALLAPPS_CLOSE_TAP_OUTSIDE(941),
267 
268         @UiEvent(doc = "User swipes or fling in UP direction and hold from the bottom bazel area")
269         LAUNCHER_OVERVIEW_GESTURE(570),
270 
271         @UiEvent(doc = "User swipes or fling in LEFT direction on the bottom bazel area.")
272         LAUNCHER_QUICKSWITCH_LEFT(571),
273 
274         @UiEvent(doc = "User swipes or fling in RIGHT direction on the bottom bazel area.")
275         LAUNCHER_QUICKSWITCH_RIGHT(572),
276 
277         @UiEvent(doc = "User swipes or fling in DOWN direction on the bottom bazel area.")
278         LAUNCHER_SWIPEDOWN_NAVBAR(573),
279 
280         @UiEvent(doc = "User swipes or fling in UP direction from bottom bazel area.")
281         LAUNCHER_HOME_GESTURE(574),
282 
283         @UiEvent(doc = "User's workspace layout information is snapshot in the background.")
284         LAUNCHER_WORKSPACE_SNAPSHOT(579),
285 
286         @UiEvent(doc = "User tapped on the screenshot button on overview)")
287         LAUNCHER_OVERVIEW_ACTIONS_SCREENSHOT(580),
288 
289         @UiEvent(doc = "User tapped on the select button on overview)")
290         LAUNCHER_OVERVIEW_ACTIONS_SELECT(581),
291 
292         @UiEvent(doc = "User tapped on the share button on overview")
293         LAUNCHER_OVERVIEW_ACTIONS_SHARE(582),
294 
295         @UiEvent(doc = "User tapped on the split screen button on overview")
296         LAUNCHER_OVERVIEW_ACTIONS_SPLIT(895),
297 
298         @UiEvent(doc = "User tapped on the close button in select mode")
299         LAUNCHER_SELECT_MODE_CLOSE(583),
300 
301         @UiEvent(doc = "User tapped on the highlight items in select mode")
302         LAUNCHER_SELECT_MODE_ITEM(584),
303 
304         @UiEvent(doc = "Notification dot on app icon enabled.")
305         LAUNCHER_NOTIFICATION_DOT_ENABLED(611),
306 
307         @UiEvent(doc = "Notification dot on app icon disabled.")
308         LAUNCHER_NOTIFICATION_DOT_DISABLED(612),
309 
310         @UiEvent(doc = "For new apps, add app icons to home screen enabled.")
311         LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED(613),
312 
313         @UiEvent(doc = "For new apps, add app icons to home screen disabled.")
314         LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_DISABLED(614),
315 
316         @UiEvent(doc = "Home screen rotation is enabled when phone is rotated.")
317         LAUNCHER_HOME_SCREEN_ROTATION_ENABLED(615),
318 
319         @UiEvent(doc = "Home screen rotation is disabled when phone is rotated.")
320         LAUNCHER_HOME_SCREEN_ROTATION_DISABLED(616),
321 
322         @UiEvent(doc = "Suggestions in all apps list enabled.")
323         LAUNCHER_ALL_APPS_SUGGESTIONS_ENABLED(619),
324 
325         @UiEvent(doc = "Suggestions in all apps list disabled.")
326         LAUNCHER_ALL_APPS_SUGGESTIONS_DISABLED(620),
327 
328         @UiEvent(doc = "Suggestions on home screen is enabled.")
329         LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED(621),
330 
331         @UiEvent(doc = "Suggestions on home screen is disabled.")
332         LAUNCHER_HOME_SCREEN_SUGGESTIONS_DISABLED(622),
333 
334         @UiEvent(doc = "System navigation is 3 button mode.")
335         LAUNCHER_NAVIGATION_MODE_3_BUTTON(623),
336 
337         @UiEvent(doc = "System navigation mode is 2 button mode.")
338         LAUNCHER_NAVIGATION_MODE_2_BUTTON(624),
339 
340         @UiEvent(doc = "System navigation mode is 0 button mode/gesture navigation mode .")
341         LAUNCHER_NAVIGATION_MODE_GESTURE_BUTTON(625),
342 
343         @UiEvent(doc = "User tapped on image content in Overview Select mode.")
344         LAUNCHER_SELECT_MODE_IMAGE(627),
345 
346         @UiEvent(doc = "Activity to add external item was started")
347         LAUNCHER_ADD_EXTERNAL_ITEM_START(641),
348 
349         @UiEvent(doc = "Activity to add external item was cancelled")
350         LAUNCHER_ADD_EXTERNAL_ITEM_CANCELLED(642),
351 
352         @UiEvent(doc = "Activity to add external item was backed out")
353         LAUNCHER_ADD_EXTERNAL_ITEM_BACK(643),
354 
355         @UiEvent(doc = "Item was placed automatically in external item addition flow")
356         LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY(644),
357 
358         @UiEvent(doc = "Item was dragged in external item addition flow")
359         LAUNCHER_ADD_EXTERNAL_ITEM_DRAGGED(645),
360 
361         @UiEvent(doc = "A folder was replaced by a single item")
362         LAUNCHER_FOLDER_CONVERTED_TO_ICON(646),
363 
364         @UiEvent(doc = "A hotseat prediction item was pinned")
365         LAUNCHER_HOTSEAT_PREDICTION_PINNED(647),
366 
367         @UiEvent(doc = "Undo event was tapped.")
368         LAUNCHER_UNDO(648),
369 
370         @UiEvent(doc = "Task switcher clear all target was tapped.")
371         LAUNCHER_TASK_CLEAR_ALL(649),
372 
373         @UiEvent(doc = "Task preview was long pressed.")
374         LAUNCHER_TASK_PREVIEW_LONGPRESS(650),
375 
376         @UiEvent(doc = "User swiped down on workspace (triggering noti shade to open).")
377         LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN(651),
378 
379         @UiEvent(doc = "Notification dismissed by swiping right.")
380         LAUNCHER_NOTIFICATION_DISMISSED(652),
381 
382         @UiEvent(doc = "Current grid size is changed to 6.")
383         LAUNCHER_GRID_SIZE_6(930),
384 
385         @UiEvent(doc = "Current grid size is changed to 5.")
386         LAUNCHER_GRID_SIZE_5(662),
387 
388         @UiEvent(doc = "Current grid size is changed to 4.")
389         LAUNCHER_GRID_SIZE_4(663),
390 
391         @UiEvent(doc = "Current grid size is changed to 3.")
392         LAUNCHER_GRID_SIZE_3(664),
393 
394         @UiEvent(doc = "Current grid size is changed to 2.")
395         LAUNCHER_GRID_SIZE_2(665),
396 
397         @UiEvent(doc = "Launcher entered into AllApps state.")
398         LAUNCHER_ALLAPPS_ENTRY(692),
399 
400         @UiEvent(doc = "Launcher exited from AllApps state.")
401         LAUNCHER_ALLAPPS_EXIT(693),
402 
403         @UiEvent(doc = "User closed the AllApps keyboard.")
404         LAUNCHER_ALLAPPS_KEYBOARD_CLOSED(694),
405 
406         @UiEvent(doc = "User switched to AllApps Main/Personal tab by swiping left.")
407         LAUNCHER_ALLAPPS_SWIPE_TO_PERSONAL_TAB(695),
408 
409         @UiEvent(doc = "User switched to AllApps Work tab by swiping right.")
410         LAUNCHER_ALLAPPS_SWIPE_TO_WORK_TAB(696),
411 
412         @UiEvent(doc = "Default event when dedicated UI event is not available for the user action"
413                 + " on slice .")
414         LAUNCHER_SLICE_DEFAULT_ACTION(700),
415 
416         @UiEvent(doc = "User toggled-on a Slice item.")
417         LAUNCHER_SLICE_TOGGLE_ON(701),
418 
419         @UiEvent(doc = "User toggled-off a Slice item.")
420         LAUNCHER_SLICE_TOGGLE_OFF(702),
421 
422         @UiEvent(doc = "User acted on a Slice item with a button.")
423         LAUNCHER_SLICE_BUTTON_ACTION(703),
424 
425         @UiEvent(doc = "User acted on a Slice item with a slider.")
426         LAUNCHER_SLICE_SLIDER_ACTION(704),
427 
428         @UiEvent(doc = "User tapped on the entire row of a Slice.")
429         LAUNCHER_SLICE_CONTENT_ACTION(705),
430 
431         @UiEvent(doc = "User tapped on the see more button of a Slice.")
432         LAUNCHER_SLICE_SEE_MORE_ACTION(706),
433 
434         @UiEvent(doc = "User selected from a selection row of Slice.")
435         LAUNCHER_SLICE_SELECTION_ACTION(707),
436 
437         @UiEvent(doc = "IME is used for selecting the focused item on the AllApps screen.")
438         LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME(718),
439 
440         @UiEvent(doc = "User long-pressed on an AllApps item.")
441         LAUNCHER_ALLAPPS_ITEM_LONG_PRESSED(719),
442 
443         @UiEvent(doc = "Launcher entered into AllApps state with device search enabled.")
444         LAUNCHER_ALLAPPS_ENTRY_WITH_DEVICE_SEARCH(720),
445 
446         @UiEvent(doc = "User switched to AllApps Main/Personal tab by tapping on it.")
447         LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB(721),
448 
449         @UiEvent(doc = "User switched to AllApps Work tab by tapping on it.")
450         LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB(722),
451 
452         @UiEvent(doc = "All apps vertical fling started.")
453         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_BEGIN(724),
454 
455         @UiEvent(doc = "All apps vertical fling ended.")
456         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_END(725),
457 
458         @UiEvent(doc = "Show URL indicator for Overview Sharing")
459         LAUNCHER_OVERVIEW_SHARING_SHOW_URL_INDICATOR(764),
460 
461         @UiEvent(doc = "Show image indicator for Overview Sharing")
462         LAUNCHER_OVERVIEW_SHARING_SHOW_IMAGE_INDICATOR(765),
463 
464         @UiEvent(doc = "User taps URL indicator in Overview")
465         LAUNCHER_OVERVIEW_SHARING_URL_INDICATOR_TAP(766),
466 
467         @UiEvent(doc = "User taps image indicator in Overview")
468         LAUNCHER_OVERVIEW_SHARING_IMAGE_INDICATOR_TAP(767),
469 
470         @UiEvent(doc = "User long presses an image in Overview")
471         LAUNCHER_OVERVIEW_SHARING_IMAGE_LONG_PRESS(768),
472 
473         @UiEvent(doc = "User drags a URL in Overview")
474         LAUNCHER_OVERVIEW_SHARING_URL_DRAG(769),
475 
476         @UiEvent(doc = "User drags an image in Overview")
477         LAUNCHER_OVERVIEW_SHARING_IMAGE_DRAG(770),
478 
479         @UiEvent(doc = "User drops URL to a direct share target")
480         LAUNCHER_OVERVIEW_SHARING_DROP_URL_TO_TARGET(771),
481 
482         @UiEvent(doc = "User drops an image to a direct share target")
483         LAUNCHER_OVERVIEW_SHARING_DROP_IMAGE_TO_TARGET(772),
484 
485         @UiEvent(doc = "User drops URL to the More button")
486         LAUNCHER_OVERVIEW_SHARING_DROP_URL_TO_MORE(773),
487 
488         @UiEvent(doc = "User drops an image to the More button")
489         LAUNCHER_OVERVIEW_SHARING_DROP_IMAGE_TO_MORE(774),
490 
491         @UiEvent(doc = "User taps a share target to share URL")
492         LAUNCHER_OVERVIEW_SHARING_TAP_TARGET_TO_SHARE_URL(775),
493 
494         @UiEvent(doc = "User taps a share target to share an image")
495         LAUNCHER_OVERVIEW_SHARING_TAP_TARGET_TO_SHARE_IMAGE(776),
496 
497         @UiEvent(doc = "User taps the More button to share URL")
498         LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_URL(777),
499 
500         @UiEvent(doc = "User taps the More button to share an image")
501         LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_IMAGE(778),
502 
503         @UiEvent(doc = "User started resizing a widget on their home screen.")
504         LAUNCHER_WIDGET_RESIZE_STARTED(820),
505 
506         @UiEvent(doc = "User finished resizing a widget on their home screen.")
507         LAUNCHER_WIDGET_RESIZE_COMPLETED(824),
508 
509         @UiEvent(doc = "User reconfigured a widget on their home screen.")
510         LAUNCHER_WIDGET_RECONFIGURED(821),
511 
512         @UiEvent(doc = "User enabled themed icons option in wallpaper & style settings.")
513         LAUNCHER_THEMED_ICON_ENABLED(836),
514 
515         @UiEvent(doc = "User disabled themed icons option in wallpaper & style settings.")
516         LAUNCHER_THEMED_ICON_DISABLED(837),
517 
518         @UiEvent(doc = "User tapped on 'Turn on work apps' button in all apps window.")
519         LAUNCHER_TURN_ON_WORK_APPS_TAP(838),
520 
521         @UiEvent(doc = "User tapped on 'Turn off work apps' button in all apps window.")
522         LAUNCHER_TURN_OFF_WORK_APPS_TAP(839),
523 
524         @UiEvent(doc = "Launcher item drop failed since there was not enough room on the screen.")
525         LAUNCHER_ITEM_DROP_FAILED_INSUFFICIENT_SPACE(872),
526 
527         @UiEvent(doc = "User long pressed on the taskbar background to hide the taskbar")
528         LAUNCHER_TASKBAR_LONGPRESS_HIDE(896),
529 
530         @UiEvent(doc = "User long pressed on the taskbar gesture handle to show the taskbar")
531         LAUNCHER_TASKBAR_LONGPRESS_SHOW(897),
532 
533         @UiEvent(doc = "User clicks on the search icon on header to launch search in app.")
534         LAUNCHER_ALLAPPS_SEARCHINAPP_LAUNCH(913),
535 
536         @UiEvent(doc = "User is shown the back gesture navigation tutorial step.")
537         LAUNCHER_GESTURE_TUTORIAL_BACK_STEP_SHOWN(959),
538 
539         @UiEvent(doc = "User is shown the home gesture navigation tutorial step.")
540         LAUNCHER_GESTURE_TUTORIAL_HOME_STEP_SHOWN(960),
541 
542         @UiEvent(doc = "User is shown the overview gesture navigation tutorial step.")
543         LAUNCHER_GESTURE_TUTORIAL_OVERVIEW_STEP_SHOWN(961),
544 
545         @UiEvent(doc = "User completed the back gesture navigation tutorial step.")
546         LAUNCHER_GESTURE_TUTORIAL_BACK_STEP_COMPLETED(962),
547 
548         @UiEvent(doc = "User completed the home gesture navigation tutorial step.")
549         LAUNCHER_GESTURE_TUTORIAL_HOME_STEP_COMPLETED(963),
550 
551         @UiEvent(doc = "User completed the overview gesture navigation tutorial step.")
552         LAUNCHER_GESTURE_TUTORIAL_OVERVIEW_STEP_COMPLETED(964),
553 
554         @UiEvent(doc = "User skips the gesture navigation tutorial.")
555         LAUNCHER_GESTURE_TUTORIAL_SKIPPED(965),
556 
557         @UiEvent(doc = "User scrolled on one of the all apps surfaces such as A-Z list, search "
558                 + "result page etc.")
559         LAUNCHER_ALLAPPS_SCROLLED(985),
560 
561         @UiEvent(doc = "User scrolled up on the all apps personal A-Z list.")
562         LAUNCHER_ALLAPPS_PERSONAL_SCROLLED_UP(1287),
563 
564         @UiEvent(doc = "User scrolled down on the all apps personal A-Z list.")
565         LAUNCHER_ALLAPPS_PERSONAL_SCROLLED_DOWN(1288),
566 
567         @UiEvent(doc = "User scrolled on one of the all apps surfaces such as A-Z list, search "
568                 + "result page etc and we don't know the direction since user came back to "
569                 + "original position from which they scrolled.")
570         LAUNCHER_ALLAPPS_SCROLLED_UNKNOWN_DIRECTION(1231),
571 
572         @UiEvent(doc = "User tapped taskbar home button")
573         LAUNCHER_TASKBAR_HOME_BUTTON_TAP(1003),
574 
575         @UiEvent(doc = "User tapped taskbar back button")
576         LAUNCHER_TASKBAR_BACK_BUTTON_TAP(1004),
577 
578         @UiEvent(doc = "User tapped taskbar overview/recents button")
579         LAUNCHER_TASKBAR_OVERVIEW_BUTTON_TAP(1005),
580 
581         @UiEvent(doc = "User tapped taskbar IME switcher button")
582         LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP(1006),
583 
584         @UiEvent(doc = "User tapped taskbar a11y button")
585         LAUNCHER_TASKBAR_A11Y_BUTTON_TAP(1007),
586 
587         @UiEvent(doc = "User tapped taskbar home button")
588         LAUNCHER_TASKBAR_HOME_BUTTON_LONGPRESS(1008),
589 
590         @UiEvent(doc = "User tapped taskbar back button")
591         LAUNCHER_TASKBAR_BACK_BUTTON_LONGPRESS(1009),
592 
593         @UiEvent(doc = "User tapped taskbar overview/recents button")
594         LAUNCHER_TASKBAR_OVERVIEW_BUTTON_LONGPRESS(1010),
595 
596         @UiEvent(doc = "User tapped taskbar a11y button")
597         LAUNCHER_TASKBAR_A11Y_BUTTON_LONGPRESS(1011),
598 
599         @UiEvent(doc = "Show an 'Undo' snackbar when users dismiss a predicted hotseat item")
600         LAUNCHER_DISMISS_PREDICTION_UNDO(1035),
601 
602         @UiEvent(doc = "User clicked on IME quicksearch button.")
603         LAUNCHER_ALLAPPS_QUICK_SEARCH_WITH_IME(1047),
604 
605         @UiEvent(doc = "User tapped taskbar All Apps button.")
606         LAUNCHER_TASKBAR_ALLAPPS_BUTTON_TAP(1057),
607 
608         @UiEvent(doc = "User tapped on Share app system shortcut.")
609         LAUNCHER_SYSTEM_SHORTCUT_APP_SHARE_TAP(1075),
610 
611         @UiEvent(doc = "User has invoked split to right half from an app icon menu")
612         LAUNCHER_APP_ICON_MENU_SPLIT_RIGHT_BOTTOM(1199),
613 
614         @UiEvent(doc = "User has invoked split to left half from an app icon menu")
615         LAUNCHER_APP_ICON_MENU_SPLIT_LEFT_TOP(1200),
616 
617         @UiEvent(doc = "Number of apps in A-Z list (personal and work profile)")
618         LAUNCHER_ALLAPPS_COUNT(1225),
619 
620         @UiEvent(doc = "User has invoked split to right half with a keyboard shortcut.")
621         LAUNCHER_KEYBOARD_SHORTCUT_SPLIT_RIGHT_BOTTOM(1232),
622 
623         @UiEvent(doc = "User has invoked split to left half with a keyboard shortcut.")
624         LAUNCHER_KEYBOARD_SHORTCUT_SPLIT_LEFT_TOP(1233),
625 
626         @UiEvent(doc = "User has collapsed the work FAB button by scrolling down in the all apps"
627                 + " work A-Z list.")
628         LAUNCHER_WORK_FAB_BUTTON_COLLAPSE(1276),
629 
630         @UiEvent(doc = "User has collapsed the work FAB button by scrolling up in the all apps"
631                 + " work A-Z list.")
632         LAUNCHER_WORK_FAB_BUTTON_EXTEND(1277),
633 
634         @UiEvent(doc = "User scrolled down on the search result page.")
635         LAUNCHER_ALLAPPS_SEARCH_SCROLLED_DOWN(1285),
636 
637         @UiEvent(doc = "User scrolled up on the search result page.")
638         LAUNCHER_ALLAPPS_SEARCH_SCROLLED_UP(1286),
639 
640         @UiEvent(doc = "User or automatic timeout has hidden transient taskbar.")
641         LAUNCHER_TRANSIENT_TASKBAR_HIDE(1330),
642 
643         @UiEvent(doc = "User has swiped upwards from the gesture handle to show transient taskbar.")
644         LAUNCHER_TRANSIENT_TASKBAR_SHOW(1331),
645         ;
646 
647         // ADD MORE
648 
649         private final int mId;
650 
LauncherEvent(int id)651         LauncherEvent(int id) {
652             mId = id;
653         }
654 
getId()655         public int getId() {
656             return mId;
657         }
658     }
659 
660     /**
661      * Launcher specific ranking related events.
662      */
663     public enum LauncherRankingEvent implements EventEnum {
664 
665         UNKNOWN(0);
666         // ADD MORE
667 
668         private final int mId;
669 
LauncherRankingEvent(int id)670         LauncherRankingEvent(int id) {
671             mId = id;
672         }
673 
getId()674         public int getId() {
675             return mId;
676         }
677     }
678 
679     /**
680      * Helps to construct and log launcher event.
681      */
682     public interface StatsLogger {
683 
684         /**
685          * Sets log fields from provided {@link ItemInfo}.
686          */
withItemInfo(ItemInfo itemInfo)687         default StatsLogger withItemInfo(ItemInfo itemInfo) {
688             return this;
689         }
690 
691 
692         /**
693          * Sets {@link InstanceId} of log message.
694          */
withInstanceId(InstanceId instanceId)695         default StatsLogger withInstanceId(InstanceId instanceId) {
696             return this;
697         }
698 
699         /**
700          * Sets rank field of log message.
701          */
withRank(int rank)702         default StatsLogger withRank(int rank) {
703             return this;
704         }
705 
706         /**
707          * Sets source launcher state field of log message.
708          */
withSrcState(int srcState)709         default StatsLogger withSrcState(int srcState) {
710             return this;
711         }
712 
713         /**
714          * Sets destination launcher state field of log message.
715          */
withDstState(int dstState)716         default StatsLogger withDstState(int dstState) {
717             return this;
718         }
719 
720         /**
721          * Sets FromState field of log message.
722          */
withFromState(FromState fromState)723         default StatsLogger withFromState(FromState fromState) {
724             return this;
725         }
726 
727         /**
728          * Sets ToState field of log message.
729          */
withToState(ToState toState)730         default StatsLogger withToState(ToState toState) {
731             return this;
732         }
733 
734         /**
735          * Sets editText field of log message.
736          */
withEditText(String editText)737         default StatsLogger withEditText(String editText) {
738             return this;
739         }
740 
741         /**
742          * Sets the final value for container related fields of log message.
743          *
744          * By default container related fields are derived from {@link ItemInfo}, this method would
745          * override those values.
746          */
withContainerInfo(ContainerInfo containerInfo)747         default StatsLogger withContainerInfo(ContainerInfo containerInfo) {
748             return this;
749         }
750 
751         /**
752          * Sets logging fields from provided {@link SliceItem}.
753          */
withSliceItem(SliceItem sliceItem)754         default StatsLogger withSliceItem(SliceItem sliceItem) {
755             return this;
756         }
757 
758         /**
759          * Sets logging fields from provided {@link LauncherAtom.Slice}.
760          */
withSlice(LauncherAtom.Slice slice)761         default StatsLogger withSlice(LauncherAtom.Slice slice) {
762             return this;
763         }
764 
765         /**
766          * Sets cardinality of log message.
767          */
withCardinality(int cardinality)768         default StatsLogger withCardinality(int cardinality) {
769             return this;
770         }
771 
772         /**
773          * Builds the final message and logs it as {@link EventEnum}.
774          */
log(EventEnum event)775         default void log(EventEnum event) {
776         }
777 
778         /**
779          * Builds the final message and logs it to two different atoms, one for
780          * event tracking and the other for jank tracking.
781          */
sendToInteractionJankMonitor(EventEnum event, View v)782         default void sendToInteractionJankMonitor(EventEnum event, View v) {
783         }
784     }
785 
786     /**
787      * Helps to construct and log latency event.
788      */
789     public interface StatsLatencyLogger {
790 
791         enum LatencyType {
792             UNKNOWN(0),
793             COLD(1),
794             HOT(2),
795             TIMEOUT(3),
796             FAIL(4),
797             COLD_USERWAITING(5),
798             ATOMIC(6),
799             CONTROLLED(7),
800             CACHED(8);
801             private final int mId;
802 
LatencyType(int id)803             LatencyType(int id) {
804                 this.mId = id;
805             }
806 
getId()807             public int getId() {
808                 return mId;
809             }
810         }
811 
812         /**
813          * Sets {@link InstanceId} of log message.
814          */
withInstanceId(InstanceId instanceId)815         default StatsLatencyLogger withInstanceId(InstanceId instanceId) {
816             return this;
817         }
818 
819 
820         /**
821          * Sets latency of the event.
822          */
withLatency(long latencyInMillis)823         default StatsLatencyLogger withLatency(long latencyInMillis) {
824             return this;
825         }
826 
827         /**
828          * Sets {@link LatencyType} of log message.
829          */
withType(LatencyType type)830         default StatsLatencyLogger withType(LatencyType type) {
831             return this;
832         }
833 
834         /**
835          * Sets query length of the event.
836          */
withQueryLength(int queryLength)837         default StatsLatencyLogger withQueryLength(int queryLength) {
838             return this;
839         }
840 
841         /**
842          * Sets sub event type.
843          */
withSubEventType(int type)844         default StatsLatencyLogger withSubEventType(int type) {
845             return this;
846         }
847 
848         /**
849          * Sets packageId of log message.
850          */
withPackageId(int packageId)851         default StatsLatencyLogger withPackageId(int packageId) {
852             return this;
853         }
854 
855         /**
856          * Builds the final message and logs it as {@link EventEnum}.
857          */
log(EventEnum event)858         default void log(EventEnum event) {
859         }
860     }
861 
862     /**
863      * Helps to construct and log impression event.
864      */
865     public interface StatsImpressionLogger {
866 
867         enum State {
868             UNKNOWN(0),
869             ALLAPPS(1),
870             SEARCHBOX_WIDGET(2);
871             private final int mLauncherState;
872 
State(int id)873             State(int id) {
874                 this.mLauncherState = id;
875             }
876 
getLauncherState()877             public int getLauncherState() {
878                 return mLauncherState;
879             }
880         }
881 
882         /**
883          * Sets {@link InstanceId} of log message.
884          */
withInstanceId(InstanceId instanceId)885         default StatsImpressionLogger withInstanceId(InstanceId instanceId) {
886             return this;
887         }
888 
889         /**
890          * Sets {@link State} of impression event.
891          */
withState(State state)892         default StatsImpressionLogger withState(State state) {
893             return this;
894         }
895 
896         /**
897          * Sets query length of the event.
898          */
withQueryLength(int queryLength)899         default StatsImpressionLogger withQueryLength(int queryLength) {
900             return this;
901         }
902 
903         /**
904          * Sets list of {@link com.android.app.search.ResultType} for the impression event.
905          */
withResultType(IntArray resultType)906         default StatsImpressionLogger withResultType(IntArray resultType) {
907             return this;
908         }
909 
910         /**
911          * Sets list of count for each of {@link com.android.app.search.ResultType} for the
912          * impression event.
913          */
withResultCount(IntArray resultCount)914         default StatsImpressionLogger withResultCount(IntArray resultCount) {
915             return this;
916         }
917 
918         /**
919          * Sets list of boolean for each of {@link com.android.app.search.ResultType} that indicates
920          * if this result is above keyboard or not for the impression event.
921          */
withAboveKeyboard(List<Boolean> aboveKeyboard)922         default StatsImpressionLogger withAboveKeyboard(List<Boolean> aboveKeyboard) {
923             return this;
924         }
925 
926         /**
927          * Builds the final message and logs it as {@link EventEnum}.
928          */
log(EventEnum event)929         default void log(EventEnum event) {
930         }
931     }
932 
933     /**
934      * Returns new logger object.
935      */
logger()936     public StatsLogger logger() {
937         StatsLogger logger = createLogger();
938         if (mInstanceId != null) {
939             logger.withInstanceId(mInstanceId);
940         }
941         return logger;
942     }
943 
944     /**
945      * Returns new latency logger object.
946      */
latencyLogger()947     public StatsLatencyLogger latencyLogger() {
948         StatsLatencyLogger logger = createLatencyLogger();
949         if (mInstanceId != null) {
950             logger.withInstanceId(mInstanceId);
951         }
952         return logger;
953     }
954 
955     /**
956      * Returns new impression logger object.
957      */
impressionLogger()958     public StatsImpressionLogger impressionLogger() {
959         StatsImpressionLogger logger = createImpressionLogger();
960         if (mInstanceId != null) {
961             logger.withInstanceId(mInstanceId);
962         }
963         return logger;
964     }
965 
966     /**
967      * Returns a singleton KeyboardStateManager.
968      */
keyboardStateManager()969     public KeyboardStateManager keyboardStateManager() {
970         if (mKeyboardStateManager == null) {
971             mKeyboardStateManager = new KeyboardStateManager();
972         }
973         return mKeyboardStateManager;
974     }
975 
createLogger()976     protected StatsLogger createLogger() {
977         return new StatsLogger() {
978         };
979     }
980 
createLatencyLogger()981     protected StatsLatencyLogger createLatencyLogger() {
982         return new StatsLatencyLogger() {
983         };
984     }
985 
createImpressionLogger()986     protected StatsImpressionLogger createImpressionLogger() {
987         return new StatsImpressionLogger() {
988         };
989     }
990 
991     /**
992      * Sets InstanceId to every new {@link StatsLogger} object returned by {@link #logger()} when
993      * not-null.
994      */
withDefaultInstanceId(@ullable InstanceId instanceId)995     public StatsLogManager withDefaultInstanceId(@Nullable InstanceId instanceId) {
996         this.mInstanceId = instanceId;
997         return this;
998     }
999 
1000     /**
1001      * Creates a new instance of {@link StatsLogManager} based on provided context.
1002      */
newInstance(Context context)1003     public static StatsLogManager newInstance(Context context) {
1004         StatsLogManager manager = Overrides.getObject(StatsLogManager.class,
1005                 context.getApplicationContext(), R.string.stats_log_manager_class);
1006         manager.mActivityContext = ActivityContext.lookupContextNoThrow(context);
1007         return manager;
1008     }
1009 }
1010