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.NonNull;
27 import androidx.annotation.Nullable;
28 import androidx.slice.SliceItem;
29 
30 import com.android.launcher3.R;
31 import com.android.launcher3.logger.LauncherAtom;
32 import com.android.launcher3.logger.LauncherAtom.ContainerInfo;
33 import com.android.launcher3.logger.LauncherAtom.FromState;
34 import com.android.launcher3.logger.LauncherAtom.ToState;
35 import com.android.launcher3.model.data.ItemInfo;
36 import com.android.launcher3.util.ResourceBasedOverride;
37 import com.android.launcher3.views.ActivityContext;
38 
39 /**
40  * Handles the user event logging in R+.
41  *
42  * <pre>
43  * All of the event ids are defined here.
44  * Most of the methods are placeholder methods for Launcher3
45  * Actual call happens only for Launcher variant that implements QuickStep.
46  * </pre>
47  */
48 public class StatsLogManager implements ResourceBasedOverride {
49 
50     public static final int LAUNCHER_STATE_UNSPECIFIED = 0;
51     public static final int LAUNCHER_STATE_BACKGROUND = 1;
52     public static final int LAUNCHER_STATE_HOME = 2;
53     public static final int LAUNCHER_STATE_OVERVIEW = 3;
54     public static final int LAUNCHER_STATE_ALLAPPS = 4;
55     public static final int LAUNCHER_STATE_UNCHANGED = 5;
56 
57     @NonNull
58     protected final Context mContext;
59     @Nullable
60     protected final ActivityContext mActivityContext;
61 
62     private KeyboardStateManager mKeyboardStateManager;
63     private InstanceId mInstanceId;
64 
StatsLogManager(@onNull Context context)65     public StatsLogManager(@NonNull Context context) {
66         mContext = context;
67         mActivityContext = ActivityContext.lookupContextNoThrow(context);
68     }
69 
70     /**
71      * Returns event enum based on the two state transition information when swipe
72      * gesture happens(to be removed during UserEventDispatcher cleanup).
73      */
getLauncherAtomEvent(int startState, int targetState, EventEnum fallbackEvent)74     public static EventEnum getLauncherAtomEvent(int startState,
75             int targetState, EventEnum fallbackEvent) {
76         if (startState == LAUNCHER_STATE_HOME
77                 && targetState == LAUNCHER_STATE_HOME) {
78             return LAUNCHER_HOME_GESTURE;
79         } else if (startState != LAUNCHER_STATE_OVERVIEW
80                 && targetState == LAUNCHER_STATE_OVERVIEW) {
81             return LAUNCHER_OVERVIEW_GESTURE;
82         } else if (startState != LAUNCHER_STATE_ALLAPPS
83                 && targetState == LAUNCHER_STATE_ALLAPPS) {
84             return LAUNCHER_ALLAPPS_OPEN_UP;
85         } else if (startState == LAUNCHER_STATE_ALLAPPS
86                 && targetState != LAUNCHER_STATE_ALLAPPS) {
87             return LAUNCHER_ALLAPPS_CLOSE_DOWN;
88         }
89         return fallbackEvent; // TODO fix
90     }
91 
92     public interface EventEnum {
93 
94         /**
95          * Tag used to request new UI Event IDs via presubmit analysis.
96          *
97          * <p>Use RESERVE_NEW_UI_EVENT_ID as the constructor parameter for a new {@link EventEnum}
98          * to signal the presubmit analyzer to reserve a new ID for the event. The new ID will be
99          * returned as a Gerrit presubmit finding.  Do not submit {@code RESERVE_NEW_UI_EVENT_ID} as
100          * the constructor parameter for any event.
101          *
102          * <pre>
103          * &#064;UiEvent(doc = "Briefly describe the interaction when this event will be logged")
104          * UNIQUE_EVENT_NAME(RESERVE_NEW_UI_EVENT_ID);
105          * </pre>
106          */
107         int RESERVE_NEW_UI_EVENT_ID = Integer.MIN_VALUE; // Negative IDs are ignored by the logger.
108 
getId()109         int getId();
110     }
111 
112     public enum LauncherEvent implements EventEnum {
113         /* Used to prevent double logging. */
114         IGNORE(-1),
115 
116         @UiEvent(doc = "App launched from workspace, hotseat or folder in launcher")
117         LAUNCHER_APP_LAUNCH_TAP(338),
118 
119         @UiEvent(doc = "Task launched from overview using TAP")
120         LAUNCHER_TASK_LAUNCH_TAP(339),
121 
122         @UiEvent(doc = "User tapped on notification inside popup context menu.")
123         LAUNCHER_NOTIFICATION_LAUNCH_TAP(516),
124 
125         @UiEvent(doc = "Task launched from overview using SWIPE DOWN")
126         LAUNCHER_TASK_LAUNCH_SWIPE_DOWN(340),
127 
128         @UiEvent(doc = "App launched by dragging and dropping, probably from taskbar")
129         LAUNCHER_APP_LAUNCH_DRAGDROP(1552),
130 
131         @UiEvent(doc = "TASK dismissed from overview using SWIPE UP")
132         LAUNCHER_TASK_DISMISS_SWIPE_UP(341),
133 
134         @UiEvent(doc = "User dragged a launcher item")
135         LAUNCHER_ITEM_DRAG_STARTED(383),
136 
137         @UiEvent(doc = "A dragged launcher item is successfully dropped onto workspace, hotseat "
138                 + "open folder etc")
139         LAUNCHER_ITEM_DROP_COMPLETED(385),
140 
141         @UiEvent(doc = "A dragged launcher item is successfully dropped onto a folder icon.")
142         LAUNCHER_ITEM_DROP_COMPLETED_ON_FOLDER_ICON(697),
143 
144         @UiEvent(doc = "A dragged launcher item is successfully dropped on another item "
145                 + "resulting in a new folder creation")
146         LAUNCHER_ITEM_DROP_FOLDER_CREATED(386),
147 
148         @UiEvent(doc = "Folder's label is automatically assigned.")
149         LAUNCHER_FOLDER_AUTO_LABELED(591),
150 
151         @UiEvent(doc = "Could not auto-label a folder because primary suggestion is null or empty.")
152         LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY(592),
153 
154         @UiEvent(doc = "Could not auto-label a folder because no suggestions exist.")
155         LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_SUGGESTIONS(593),
156 
157         @UiEvent(doc = "User manually updated the folder label.")
158         LAUNCHER_FOLDER_LABEL_UPDATED(460),
159 
160         @UiEvent(doc = "User long pressed on the workspace empty space.")
161         LAUNCHER_WORKSPACE_LONGPRESS(461),
162 
163         @UiEvent(doc = "User tapped or long pressed on a wallpaper icon inside launcher settings.")
164         LAUNCHER_WALLPAPER_BUTTON_TAP_OR_LONGPRESS(462),
165 
166         @UiEvent(doc = "User tapped or long pressed on settings icon inside launcher settings.")
167         LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS(463),
168 
169         @UiEvent(doc = "User tapped or long pressed on widget tray icon inside launcher settings.")
170         LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS(464),
171 
172         @UiEvent(doc = "User expanded the list of widgets for a single app in the widget picker.")
173         LAUNCHER_WIDGETSTRAY_APP_EXPANDED(818),
174 
175         @UiEvent(doc = "User searched for a widget in the widget picker.")
176         LAUNCHER_WIDGETSTRAY_SEARCHED(819),
177 
178         @UiEvent(doc = "A dragged item is dropped on 'Remove' button in the target bar")
179         LAUNCHER_ITEM_DROPPED_ON_REMOVE(465),
180 
181         @UiEvent(doc = "A dragged item is dropped on 'Cancel' button in the target bar")
182         LAUNCHER_ITEM_DROPPED_ON_CANCEL(466),
183 
184         @UiEvent(doc = "A predicted item is dragged and dropped on 'Don't suggest app'"
185                 + " button in the target bar")
186         LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST(467),
187 
188         @UiEvent(doc = "A dragged item is dropped on 'Uninstall' button in target bar")
189         LAUNCHER_ITEM_DROPPED_ON_UNINSTALL(468),
190 
191         @UiEvent(doc = "User completed uninstalling the package after dropping on "
192                 + "the icon onto 'Uninstall' button in the target bar")
193         LAUNCHER_ITEM_UNINSTALL_COMPLETED(469),
194 
195         @UiEvent(doc = "User cancelled uninstalling the package after dropping on "
196                 + "the icon onto 'Uninstall' button in the target bar")
197         LAUNCHER_ITEM_UNINSTALL_CANCELLED(470),
198 
199         @UiEvent(doc = "User tapped or long pressed on the task icon(aka package icon) "
200                 + "from overview to open task menu.")
201         LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS(517),
202 
203         @UiEvent(doc = "User opened package specific widgets list by tapping on widgets system "
204                 + "shortcut inside popup context menu.")
205         LAUNCHER_SYSTEM_SHORTCUT_WIDGETS_TAP(514),
206 
207         @UiEvent(doc = "User tapped on app info system shortcut.")
208         LAUNCHER_SYSTEM_SHORTCUT_APP_INFO_TAP(515),
209 
210         /**
211          * @deprecated Use {@link #LAUNCHER_APP_ICON_MENU_SPLIT_LEFT_TOP} or
212          *             {@link #LAUNCHER_APP_ICON_MENU_SPLIT_RIGHT_BOTTOM}
213          */
214         @Deprecated
215         @UiEvent(doc = "User tapped on split screen icon on a task menu.")
216         LAUNCHER_SYSTEM_SHORTCUT_SPLIT_SCREEN_TAP(518),
217 
218         @UiEvent(doc = "User tapped on free form icon on a task menu.")
219         LAUNCHER_SYSTEM_SHORTCUT_FREE_FORM_TAP(519),
220 
221         @UiEvent(doc = "User tapped on desktop icon on a task menu.")
222         LAUNCHER_SYSTEM_SHORTCUT_DESKTOP_TAP(1706),
223 
224         @UiEvent(doc = "User tapped on pause app system shortcut.")
225         LAUNCHER_SYSTEM_SHORTCUT_PAUSE_TAP(521),
226 
227         @UiEvent(doc = "User tapped on pin system shortcut.")
228         LAUNCHER_SYSTEM_SHORTCUT_PIN_TAP(522),
229 
230         @UiEvent(doc = "User tapped on don't suggest app system shortcut.")
231         LAUNCHER_SYSTEM_SHORTCUT_DONT_SUGGEST_APP_TAP(1603),
232 
233         @UiEvent(doc = "User is shown All Apps education view.")
234         LAUNCHER_ALL_APPS_EDU_SHOWN(523),
235 
236         @UiEvent(doc = "User opened a folder.")
237         LAUNCHER_FOLDER_OPEN(551),
238 
239         @UiEvent(doc = "Hotseat education half sheet seen")
240         LAUNCHER_HOTSEAT_EDU_SEEN(479),
241 
242         @UiEvent(doc = "Hotseat migration accepted")
243         LAUNCHER_HOTSEAT_EDU_ACCEPT(480),
244 
245         @UiEvent(doc = "Hotseat migration denied")
246         LAUNCHER_HOTSEAT_EDU_DENY(481),
247 
248         @UiEvent(doc = "Hotseat education tip shown")
249         LAUNCHER_HOTSEAT_EDU_ONLY_TIP(482),
250 
251         /**
252          * @deprecated LauncherUiChanged.rank field is repurposed to store all apps rank, so no
253          * separate event is required.
254          */
255         @Deprecated
256         @UiEvent(doc = "App launch ranking logged for all apps predictions")
257         LAUNCHER_ALL_APPS_RANKED(552),
258 
259         @UiEvent(doc = "App launch ranking logged for hotseat predictions)")
260         LAUNCHER_HOTSEAT_RANKED(553),
261         @UiEvent(doc = "Launcher is now in background. e.g., Screen off event")
262         LAUNCHER_ONSTOP(562),
263 
264         @UiEvent(doc = "Launcher is now in foreground. e.g., Screen on event, back button")
265         LAUNCHER_ONRESUME(563),
266 
267         @UiEvent(doc = "User swipes or fling in LEFT direction on workspace.")
268         LAUNCHER_SWIPELEFT(564),
269 
270         @UiEvent(doc = "User swipes or fling in RIGHT direction on workspace.")
271         LAUNCHER_SWIPERIGHT(565),
272 
273         @UiEvent(doc = "User swipes or fling in UP direction in unknown way.")
274         LAUNCHER_UNKNOWN_SWIPEUP(566),
275 
276         @UiEvent(doc = "User swipes or fling in DOWN direction in unknown way.")
277         LAUNCHER_UNKNOWN_SWIPEDOWN(567),
278 
279         @UiEvent(doc = "User swipes or fling in UP direction to open apps drawer.")
280         LAUNCHER_ALLAPPS_OPEN_UP(568),
281 
282         @UiEvent(doc = "User swipes or fling in DOWN direction to close apps drawer.")
283         LAUNCHER_ALLAPPS_CLOSE_DOWN(569),
284 
285         @UiEvent(doc = "User tap outside apps drawer sheet to close apps drawer.")
286         LAUNCHER_ALLAPPS_CLOSE_TAP_OUTSIDE(941),
287 
288         @UiEvent(doc = "User swipes or fling in UP direction and hold from the bottom bazel area")
289         LAUNCHER_OVERVIEW_GESTURE(570),
290 
291         @UiEvent(doc = "User swipes or fling in LEFT direction on the bottom bazel area.")
292         LAUNCHER_QUICKSWITCH_LEFT(571),
293 
294         @UiEvent(doc = "User swipes or fling in RIGHT direction on the bottom bazel area.")
295         LAUNCHER_QUICKSWITCH_RIGHT(572),
296 
297         @UiEvent(doc = "User swipes or fling in DOWN direction on the bottom bazel area.")
298         LAUNCHER_SWIPEDOWN_NAVBAR(573),
299 
300         @UiEvent(doc = "User deep presses on the bottom bezel area.")
301         LAUNCHER_DEEP_PRESS_NAVBAR(1543),
302 
303         @UiEvent(doc = "User long presses on the bottom bezel area.")
304         LAUNCHER_LONG_PRESS_NAVBAR(1544),
305 
306         @UiEvent(doc = "User deep presses on the stashed taskbar")
307         LAUNCHER_DEEP_PRESS_STASHED_TASKBAR(1602),
308 
309         @UiEvent(doc = "User long presses on the stashed taskbar")
310         LAUNCHER_LONG_PRESS_STASHED_TASKBAR(1592),
311 
312         @UiEvent(doc = "User swipes or fling in UP direction from bottom bazel area.")
313         LAUNCHER_HOME_GESTURE(574),
314 
315         @UiEvent(doc = "User's workspace layout information is snapshot in the background.")
316         LAUNCHER_WORKSPACE_SNAPSHOT(579),
317 
318         @UiEvent(doc = "User tapped on the screenshot button on overview)")
319         LAUNCHER_OVERVIEW_ACTIONS_SCREENSHOT(580),
320 
321         @UiEvent(doc = "User tapped on the select button on overview)")
322         LAUNCHER_OVERVIEW_ACTIONS_SELECT(581),
323 
324         @UiEvent(doc = "User tapped on the share button on overview")
325         LAUNCHER_OVERVIEW_ACTIONS_SHARE(582),
326 
327         @UiEvent(doc = "User tapped on the split screen button on overview")
328         LAUNCHER_OVERVIEW_ACTIONS_SPLIT(895),
329 
330         @UiEvent(doc = "User tapped on the close button in select mode")
331         LAUNCHER_SELECT_MODE_CLOSE(583),
332 
333         @UiEvent(doc = "User tapped on the highlight items in select mode")
334         LAUNCHER_SELECT_MODE_ITEM(584),
335 
336         @UiEvent(doc = "Notification dot on app icon enabled.")
337         LAUNCHER_NOTIFICATION_DOT_ENABLED(611),
338 
339         @UiEvent(doc = "Notification dot on app icon disabled.")
340         LAUNCHER_NOTIFICATION_DOT_DISABLED(612),
341 
342         @UiEvent(doc = "For new apps, add app icons to home screen enabled.")
343         LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED(613),
344 
345         @UiEvent(doc = "For new apps, add app icons to home screen disabled.")
346         LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_DISABLED(614),
347 
348         @UiEvent(doc = "Home screen rotation is enabled when phone is rotated.")
349         LAUNCHER_HOME_SCREEN_ROTATION_ENABLED(615),
350 
351         @UiEvent(doc = "Home screen rotation is disabled when phone is rotated.")
352         LAUNCHER_HOME_SCREEN_ROTATION_DISABLED(616),
353 
354         @UiEvent(doc = "Suggestions in all apps list enabled.")
355         LAUNCHER_ALL_APPS_SUGGESTIONS_ENABLED(619),
356 
357         @UiEvent(doc = "Suggestions in all apps list disabled.")
358         LAUNCHER_ALL_APPS_SUGGESTIONS_DISABLED(620),
359 
360         @UiEvent(doc = "Suggestions on home screen is enabled.")
361         LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED(621),
362 
363         @UiEvent(doc = "Suggestions on home screen is disabled.")
364         LAUNCHER_HOME_SCREEN_SUGGESTIONS_DISABLED(622),
365 
366         @UiEvent(doc = "System navigation is 3 button mode.")
367         LAUNCHER_NAVIGATION_MODE_3_BUTTON(623),
368 
369         @UiEvent(doc = "System navigation mode is 2 button mode.")
370         LAUNCHER_NAVIGATION_MODE_2_BUTTON(624),
371 
372         @UiEvent(doc = "System navigation mode is 0 button mode/gesture navigation mode .")
373         LAUNCHER_NAVIGATION_MODE_GESTURE_BUTTON(625),
374 
375         @UiEvent(doc = "User tapped on image content in Overview Select mode.")
376         LAUNCHER_SELECT_MODE_IMAGE(627),
377 
378         @UiEvent(doc = "User tapped on barcode content in Overview Select mode.")
379         LAUNCHER_SELECT_MODE_BARCODE(1531),
380 
381         @UiEvent(doc = "Highlight gleams for barcode content in Overview Select mode.")
382         LAUNCHER_SELECT_MODE_SHOW_BARCODE_REGIONS(1532),
383 
384         @UiEvent(doc = "Activity to add external item was started")
385         LAUNCHER_ADD_EXTERNAL_ITEM_START(641),
386 
387         @UiEvent(doc = "Activity to add external item was cancelled")
388         LAUNCHER_ADD_EXTERNAL_ITEM_CANCELLED(642),
389 
390         @UiEvent(doc = "Activity to add external item was backed out")
391         LAUNCHER_ADD_EXTERNAL_ITEM_BACK(643),
392 
393         @UiEvent(doc = "Item was placed automatically in external item addition flow")
394         LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY(644),
395 
396         @UiEvent(doc = "Item was dragged in external item addition flow")
397         LAUNCHER_ADD_EXTERNAL_ITEM_DRAGGED(645),
398 
399         @UiEvent(doc = "A folder was replaced by a single item")
400         LAUNCHER_FOLDER_CONVERTED_TO_ICON(646),
401 
402         @UiEvent(doc = "A hotseat prediction item was pinned")
403         LAUNCHER_HOTSEAT_PREDICTION_PINNED(647),
404 
405         @UiEvent(doc = "Undo event was tapped.")
406         LAUNCHER_UNDO(648),
407 
408         @UiEvent(doc = "Task switcher clear all target was tapped.")
409         LAUNCHER_TASK_CLEAR_ALL(649),
410 
411         @UiEvent(doc = "Task preview was long pressed.")
412         LAUNCHER_TASK_PREVIEW_LONGPRESS(650),
413 
414         @UiEvent(doc = "User swiped down on workspace (triggering noti shade to open).")
415         LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN(651),
416 
417         @UiEvent(doc = "Notification dismissed by swiping right.")
418         LAUNCHER_NOTIFICATION_DISMISSED(652),
419 
420         @UiEvent(doc = "Current grid size is changed to 6.")
421         LAUNCHER_GRID_SIZE_6(930),
422 
423         @UiEvent(doc = "Current grid size is changed to 5.")
424         LAUNCHER_GRID_SIZE_5(662),
425 
426         @UiEvent(doc = "Current grid size is changed to 4.")
427         LAUNCHER_GRID_SIZE_4(663),
428 
429         @UiEvent(doc = "Current grid size is changed to 3.")
430         LAUNCHER_GRID_SIZE_3(664),
431 
432         @UiEvent(doc = "Current grid size is changed to 2.")
433         LAUNCHER_GRID_SIZE_2(665),
434 
435         @UiEvent(doc = "Launcher entered into AllApps state.")
436         LAUNCHER_ALLAPPS_ENTRY(692),
437 
438         @UiEvent(doc = "Launcher exited from AllApps state.")
439         LAUNCHER_ALLAPPS_EXIT(693),
440 
441         @UiEvent(doc = "User closed the AllApps keyboard.")
442         LAUNCHER_ALLAPPS_KEYBOARD_CLOSED(694),
443 
444         @UiEvent(doc = "User switched to AllApps Main/Personal tab by swiping left.")
445         LAUNCHER_ALLAPPS_SWIPE_TO_PERSONAL_TAB(695),
446 
447         @UiEvent(doc = "User switched to AllApps Work tab by swiping right.")
448         LAUNCHER_ALLAPPS_SWIPE_TO_WORK_TAB(696),
449 
450         @UiEvent(doc = "Default event when dedicated UI event is not available for the user action"
451                 + " on slice .")
452         LAUNCHER_SLICE_DEFAULT_ACTION(700),
453 
454         @UiEvent(doc = "User toggled-on a Slice item.")
455         LAUNCHER_SLICE_TOGGLE_ON(701),
456 
457         @UiEvent(doc = "User toggled-off a Slice item.")
458         LAUNCHER_SLICE_TOGGLE_OFF(702),
459 
460         @UiEvent(doc = "User acted on a Slice item with a button.")
461         LAUNCHER_SLICE_BUTTON_ACTION(703),
462 
463         @UiEvent(doc = "User acted on a Slice item with a slider.")
464         LAUNCHER_SLICE_SLIDER_ACTION(704),
465 
466         @UiEvent(doc = "User tapped on the entire row of a Slice.")
467         LAUNCHER_SLICE_CONTENT_ACTION(705),
468 
469         @UiEvent(doc = "User tapped on the see more button of a Slice.")
470         LAUNCHER_SLICE_SEE_MORE_ACTION(706),
471 
472         @UiEvent(doc = "User selected from a selection row of Slice.")
473         LAUNCHER_SLICE_SELECTION_ACTION(707),
474 
475         @UiEvent(doc = "IME is used for selecting the focused item on the AllApps screen.")
476         LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME(718),
477 
478         @UiEvent(doc = "User long-pressed on an AllApps item.")
479         LAUNCHER_ALLAPPS_ITEM_LONG_PRESSED(719),
480 
481         @UiEvent(doc = "Launcher entered into AllApps state with device search enabled.")
482         LAUNCHER_ALLAPPS_ENTRY_WITH_DEVICE_SEARCH(720),
483 
484         @UiEvent(doc = "User switched to AllApps Main/Personal tab by tapping on it.")
485         LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB(721),
486 
487         @UiEvent(doc = "User switched to AllApps Work tab by tapping on it.")
488         LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB(722),
489 
490         @UiEvent(doc = "All apps vertical fling started.")
491         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_BEGIN(724),
492 
493         @UiEvent(doc = "All apps vertical fling ended.")
494         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_END(725),
495 
496         @UiEvent(doc = "Show URL indicator for Overview Sharing")
497         LAUNCHER_OVERVIEW_SHARING_SHOW_URL_INDICATOR(764),
498 
499         @UiEvent(doc = "Show image indicator for Overview Sharing")
500         LAUNCHER_OVERVIEW_SHARING_SHOW_IMAGE_INDICATOR(765),
501 
502         @UiEvent(doc = "User taps URL indicator in Overview")
503         LAUNCHER_OVERVIEW_SHARING_URL_INDICATOR_TAP(766),
504 
505         @UiEvent(doc = "User taps image indicator in Overview")
506         LAUNCHER_OVERVIEW_SHARING_IMAGE_INDICATOR_TAP(767),
507 
508         @UiEvent(doc = "User long presses an image in Overview")
509         LAUNCHER_OVERVIEW_SHARING_IMAGE_LONG_PRESS(768),
510 
511         @UiEvent(doc = "User drags a URL in Overview")
512         LAUNCHER_OVERVIEW_SHARING_URL_DRAG(769),
513 
514         @UiEvent(doc = "User drags an image in Overview")
515         LAUNCHER_OVERVIEW_SHARING_IMAGE_DRAG(770),
516 
517         @UiEvent(doc = "User drops URL to a direct share target")
518         LAUNCHER_OVERVIEW_SHARING_DROP_URL_TO_TARGET(771),
519 
520         @UiEvent(doc = "User drops an image to a direct share target")
521         LAUNCHER_OVERVIEW_SHARING_DROP_IMAGE_TO_TARGET(772),
522 
523         @UiEvent(doc = "User drops URL to the More button")
524         LAUNCHER_OVERVIEW_SHARING_DROP_URL_TO_MORE(773),
525 
526         @UiEvent(doc = "User drops an image to the More button")
527         LAUNCHER_OVERVIEW_SHARING_DROP_IMAGE_TO_MORE(774),
528 
529         @UiEvent(doc = "User taps a share target to share URL")
530         LAUNCHER_OVERVIEW_SHARING_TAP_TARGET_TO_SHARE_URL(775),
531 
532         @UiEvent(doc = "User taps a share target to share an image")
533         LAUNCHER_OVERVIEW_SHARING_TAP_TARGET_TO_SHARE_IMAGE(776),
534 
535         @UiEvent(doc = "User taps the More button to share URL")
536         LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_URL(777),
537 
538         @UiEvent(doc = "User taps the More button to share an image")
539         LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_IMAGE(778),
540 
541         @UiEvent(doc = "Show Barode indicator for overview sharing")
542         LAUNCHER_OVERVIEW_SHARING_SHOW_BARCODE_INDICATOR(1533),
543 
544         @UiEvent(doc = "User taps barcode indicator in overview")
545         LAUNCHER_OVERVIEW_SHARING_BARCODE_INDICATOR_TAP(1534),
546 
547         @UiEvent(doc = "Configure barcode region for long_press action for overview sharing")
548         LAUNCHER_OVERVIEW_SHARING_CONFIGURE_BARCODE_REGION_LONG_PRESS(1535),
549 
550         @UiEvent(doc = "User long presses a barcode region in overview")
551         LAUNCHER_OVERVIEW_SHARING_BARCODE_REGION_LONG_PRESS(1536),
552 
553         @UiEvent(doc = "User drags a barcode region in overview")
554         LAUNCHER_OVERVIEW_SHARING_BARCODE_REGION_DRAG(1537),
555 
556         @UiEvent(doc = "User started resizing a widget on their home screen.")
557         LAUNCHER_WIDGET_RESIZE_STARTED(820),
558 
559         @UiEvent(doc = "User finished resizing a widget on their home screen.")
560         LAUNCHER_WIDGET_RESIZE_COMPLETED(824),
561 
562         @UiEvent(doc = "User reconfigured a widget on their home screen.")
563         LAUNCHER_WIDGET_RECONFIGURED(821),
564 
565         @UiEvent(doc = "User enabled themed icons option in wallpaper & style settings.")
566         LAUNCHER_THEMED_ICON_ENABLED(836),
567 
568         @UiEvent(doc = "User disabled themed icons option in wallpaper & style settings.")
569         LAUNCHER_THEMED_ICON_DISABLED(837),
570 
571         @UiEvent(doc = "User tapped on 'Turn on work apps' button in all apps window.")
572         LAUNCHER_TURN_ON_WORK_APPS_TAP(838),
573 
574         @UiEvent(doc = "User tapped on 'Turn off work apps' button in all apps window.")
575         LAUNCHER_TURN_OFF_WORK_APPS_TAP(839),
576 
577         @UiEvent(doc = "Launcher item drop failed since there was not enough room on the screen.")
578         LAUNCHER_ITEM_DROP_FAILED_INSUFFICIENT_SPACE(872),
579 
580         @UiEvent(doc = "User clicks on the search icon on header to launch search in app.")
581         LAUNCHER_ALLAPPS_SEARCHINAPP_LAUNCH(913),
582 
583         @UiEvent(doc = "User is shown the back gesture navigation tutorial step.")
584         LAUNCHER_GESTURE_TUTORIAL_BACK_STEP_SHOWN(959),
585 
586         @UiEvent(doc = "User is shown the home gesture navigation tutorial step.")
587         LAUNCHER_GESTURE_TUTORIAL_HOME_STEP_SHOWN(960),
588 
589         @UiEvent(doc = "User is shown the overview gesture navigation tutorial step.")
590         LAUNCHER_GESTURE_TUTORIAL_OVERVIEW_STEP_SHOWN(961),
591 
592         @UiEvent(doc = "User completed the back gesture navigation tutorial step.")
593         LAUNCHER_GESTURE_TUTORIAL_BACK_STEP_COMPLETED(962),
594 
595         @UiEvent(doc = "User completed the home gesture navigation tutorial step.")
596         LAUNCHER_GESTURE_TUTORIAL_HOME_STEP_COMPLETED(963),
597 
598         @UiEvent(doc = "User completed the overview gesture navigation tutorial step.")
599         LAUNCHER_GESTURE_TUTORIAL_OVERVIEW_STEP_COMPLETED(964),
600 
601         @UiEvent(doc = "User skips the gesture navigation tutorial.")
602         LAUNCHER_GESTURE_TUTORIAL_SKIPPED(965),
603 
604         @UiEvent(doc = "User scrolled on one of the all apps surfaces such as A-Z list, search "
605                 + "result page etc.")
606         LAUNCHER_ALLAPPS_SCROLLED(985),
607 
608         @UiEvent(doc = "User scrolled up on the all apps personal A-Z list.")
609         LAUNCHER_ALLAPPS_PERSONAL_SCROLLED_UP(1287),
610 
611         @UiEvent(doc = "User scrolled down on the all apps personal A-Z list.")
612         LAUNCHER_ALLAPPS_PERSONAL_SCROLLED_DOWN(1288),
613 
614         @UiEvent(doc = "User scrolled on one of the all apps surfaces such as A-Z list, search "
615                 + "result page etc and we don't know the direction since user came back to "
616                 + "original position from which they scrolled.")
617         LAUNCHER_ALLAPPS_SCROLLED_UNKNOWN_DIRECTION(1231),
618 
619         @UiEvent(doc = "User tapped taskbar home button")
620         LAUNCHER_TASKBAR_HOME_BUTTON_TAP(1003),
621 
622         @UiEvent(doc = "User tapped taskbar back button")
623         LAUNCHER_TASKBAR_BACK_BUTTON_TAP(1004),
624 
625         @UiEvent(doc = "User tapped taskbar overview/recents button")
626         LAUNCHER_TASKBAR_OVERVIEW_BUTTON_TAP(1005),
627 
628         @UiEvent(doc = "User tapped taskbar IME switcher button")
629         LAUNCHER_TASKBAR_IME_SWITCHER_BUTTON_TAP(1006),
630 
631         @UiEvent(doc = "User tapped taskbar a11y button")
632         LAUNCHER_TASKBAR_A11Y_BUTTON_TAP(1007),
633 
634         @UiEvent(doc = "User tapped taskbar home button")
635         LAUNCHER_TASKBAR_HOME_BUTTON_LONGPRESS(1008),
636 
637         @UiEvent(doc = "User tapped taskbar back button")
638         LAUNCHER_TASKBAR_BACK_BUTTON_LONGPRESS(1009),
639 
640         @UiEvent(doc = "User tapped taskbar overview/recents button")
641         LAUNCHER_TASKBAR_OVERVIEW_BUTTON_LONGPRESS(1010),
642 
643         @UiEvent(doc = "User tapped taskbar a11y button")
644         LAUNCHER_TASKBAR_A11Y_BUTTON_LONGPRESS(1011),
645 
646         @UiEvent(doc = "Show an 'Undo' snackbar when users dismiss a predicted hotseat item")
647         LAUNCHER_DISMISS_PREDICTION_UNDO(1035),
648 
649         @UiEvent(doc = "User clicked on IME quicksearch button.")
650         LAUNCHER_ALLAPPS_QUICK_SEARCH_WITH_IME(1047),
651 
652         @UiEvent(doc = "User tapped taskbar All Apps button.")
653         LAUNCHER_TASKBAR_ALLAPPS_BUTTON_TAP(1057),
654 
655         @UiEvent(doc = "User long pressed taskbar All Apps button.")
656         LAUNCHER_TASKBAR_ALLAPPS_BUTTON_LONG_PRESS(1607),
657 
658         @UiEvent(doc = "User tapped on Share app system shortcut.")
659         LAUNCHER_SYSTEM_SHORTCUT_APP_SHARE_TAP(1075),
660 
661         @UiEvent(doc = "User has invoked split to right half from an app icon menu")
662         LAUNCHER_APP_ICON_MENU_SPLIT_RIGHT_BOTTOM(1199),
663 
664         @UiEvent(doc = "User has invoked split to left half from an app icon menu")
665         LAUNCHER_APP_ICON_MENU_SPLIT_LEFT_TOP(1200),
666 
667         @UiEvent(doc = "Number of apps in A-Z list (personal and work profile)")
668         LAUNCHER_ALLAPPS_COUNT(1225),
669 
670         @UiEvent(doc = "User has invoked split to right half with a keyboard shortcut.")
671         LAUNCHER_KEYBOARD_SHORTCUT_SPLIT_RIGHT_BOTTOM(1232),
672 
673         @UiEvent(doc = "User has invoked split to left half with a keyboard shortcut.")
674         LAUNCHER_KEYBOARD_SHORTCUT_SPLIT_LEFT_TOP(1233),
675 
676         @UiEvent(doc = "User has invoked split to right half from desktop mode.")
677         LAUNCHER_DESKTOP_MODE_SPLIT_RIGHT_BOTTOM(1412),
678 
679         @UiEvent(doc = "User has invoked split to left half from desktop mode.")
680         LAUNCHER_DESKTOP_MODE_SPLIT_LEFT_TOP(1464),
681 
682         @UiEvent(doc = "User has collapsed the work FAB button by scrolling down in the all apps"
683                 + " work A-Z list.")
684         LAUNCHER_WORK_FAB_BUTTON_COLLAPSE(1276),
685 
686         @UiEvent(doc = "User has collapsed the work FAB button by scrolling up in the all apps"
687                 + " work A-Z list.")
688         LAUNCHER_WORK_FAB_BUTTON_EXTEND(1277),
689 
690         @UiEvent(doc = "User scrolled down on the search result page.")
691         LAUNCHER_ALLAPPS_SEARCH_SCROLLED_DOWN(1285),
692 
693         @UiEvent(doc = "User scrolled up on the search result page.")
694         LAUNCHER_ALLAPPS_SEARCH_SCROLLED_UP(1286),
695 
696         @UiEvent(doc = "User or automatic timeout has hidden transient taskbar.")
697         LAUNCHER_TRANSIENT_TASKBAR_HIDE(1330),
698 
699         @UiEvent(doc = "User has swiped upwards from the gesture handle to show transient taskbar.")
700         LAUNCHER_TRANSIENT_TASKBAR_SHOW(1331),
701 
702         @UiEvent(doc = "User has clicked an app pair and launched directly into split screen.")
703         LAUNCHER_APP_PAIR_LAUNCH(1374),
704 
705         @UiEvent(doc = "User saved an app pair.")
706         LAUNCHER_APP_PAIR_SAVE(1456),
707 
708         @UiEvent(doc = "App launched through pending intent")
709         LAUNCHER_APP_LAUNCH_PENDING_INTENT(1394),
710 
711         @UiEvent(doc = "User long pressed on taskbar divider icon to open popup menu")
712         LAUNCHER_TASKBAR_DIVIDER_MENU_OPEN(1488),
713 
714         @UiEvent(doc = "User long pressed on taskbar divider icon to close popup menu")
715         LAUNCHER_TASKBAR_DIVIDER_MENU_CLOSE(1489),
716 
717         @UiEvent(doc = "User has pinned taskbar using taskbar divider menu")
718         LAUNCHER_TASKBAR_PINNED(1490),
719 
720         @UiEvent(doc = "User has unpinned taskbar using taskbar divider menu")
721         LAUNCHER_TASKBAR_UNPINNED(1491),
722 
723         @UiEvent(doc = "User tapped private space lock button")
724         LAUNCHER_PRIVATE_SPACE_LOCK_TAP(1548),
725 
726         @UiEvent(doc = "User tapped private space unlock button")
727         LAUNCHER_PRIVATE_SPACE_UNLOCK_TAP(1549),
728 
729         @UiEvent(doc = "User tapped private space settings button")
730         LAUNCHER_PRIVATE_SPACE_SETTINGS_TAP(1550),
731 
732         @UiEvent(doc = "User tapped on install to private space system shortcut.")
733         LAUNCHER_PRIVATE_SPACE_INSTALL_SYSTEM_SHORTCUT_TAP(1565),
734 
735         @UiEvent(doc = "User tapped private space install app button.")
736         LAUNCHER_PRIVATE_SPACE_INSTALL_APP_BUTTON_TAP(1605),
737 
738         @UiEvent(doc = "User attempted to create split screen with a widget")
739         LAUNCHER_SPLIT_WIDGET_ATTEMPT(1604),
740 
741         @UiEvent(doc = "User tapped on private space uninstall system shortcut.")
742         LAUNCHER_PRIVATE_SPACE_UNINSTALL_SYSTEM_SHORTCUT_TAP(1608),
743 
744         @UiEvent(doc = "User initiated split selection")
745         LAUNCHER_SPLIT_SELECTION_INITIATED(1618),
746 
747         @UiEvent(doc = "User finished a split selection session")
748         LAUNCHER_SPLIT_SELECTION_COMPLETE(1619),
749 
750         @UiEvent(doc = "User selected both apps for split screen")
751         LAUNCHER_SPLIT_SELECTED_SECOND_APP(1609),
752 
753         @UiEvent(doc = "User exited split selection by going home via swipe, button, or state "
754                 + "transition")
755         LAUNCHER_SPLIT_SELECTION_EXIT_HOME(1610),
756 
757         @UiEvent(doc = "User exited split selection by tapping cancel in split instructions view")
758         LAUNCHER_SPLIT_SELECTION_EXIT_CANCEL_BUTTON(1611),
759 
760         @UiEvent(doc = "User exited split selection when another activity/app came to foreground"
761                 + " after first app had been selected OR if user long-pressed on home. Default exit"
762                 + " metric.")
763         LAUNCHER_SPLIT_SELECTION_EXIT_INTERRUPTED(1612),
764 
765         @UiEvent(doc = "User tapped add widget button in widget sheet.")
766         LAUNCHER_WIDGET_ADD_BUTTON_TAP(1622),
767 
768         @UiEvent(doc = "Number of user installed Private profile apps, shown above separator line")
769         LAUNCHER_PRIVATE_SPACE_USER_INSTALLED_APPS_COUNT(1672),
770 
771         @UiEvent(doc = "Number of preinstalled Private profile apps, shown under separator line")
772         LAUNCHER_PRIVATE_SPACE_PREINSTALLED_APPS_COUNT(1673),
773 
774         @UiEvent(doc = "Private space lock animation started")
775         LAUNCHER_PRIVATE_SPACE_LOCK_ANIMATION_BEGIN(1725),
776 
777         @UiEvent(doc = "Private space lock animation finished")
778         LAUNCHER_PRIVATE_SPACE_LOCK_ANIMATION_END(1726),
779 
780         @UiEvent(doc = "Private space unlock animation started")
781         LAUNCHER_PRIVATE_SPACE_UNLOCK_ANIMATION_BEGIN(1727),
782 
783         @UiEvent(doc = "Private space unlock animation finished")
784         LAUNCHER_PRIVATE_SPACE_UNLOCK_ANIMATION_END(1728),
785 
786         @UiEvent(doc = "User rotates whilst in Overview / RecentsView")
787         LAUNCHER_OVERVIEW_ORIENTATION_CHANGED(1762),
788 
789         @UiEvent(doc = "User launches Overview from 3 button navigation")
790         LAUNCHER_OVERVIEW_SHOW_OVERVIEW_FROM_3_BUTTON(1763),
791 
792         @UiEvent(doc = "User launches Overview from alt+tab keyboard quick switch")
793         LAUNCHER_OVERVIEW_SHOW_OVERVIEW_FROM_KEYBOARD_QUICK_SWITCH(1764),
794 
795         @UiEvent(doc = "User launches Overview from meta+tab keyboard shortcut")
796         LAUNCHER_OVERVIEW_SHOW_OVERVIEW_FROM_KEYBOARD_SHORTCUT(1765),
797 
798         // ADD MORE
799         ;
800 
801         private final int mId;
802 
LauncherEvent(int id)803         LauncherEvent(int id) {
804             mId = id;
805         }
806 
getId()807         public int getId() {
808             return mId;
809         }
810     }
811 
812     /** Launcher's latency events. */
813     public enum LauncherLatencyEvent implements EventEnum {
814         // Details of below 6 events with prefix of "LAUNCHER_LATENCY_STARTUP_" are discussed in
815         // go/launcher-startup-latency
816         @UiEvent(doc = "The total duration of launcher startup latency.")
817         LAUNCHER_LATENCY_STARTUP_TOTAL_DURATION(1362),
818 
819         @UiEvent(doc = "The duration of launcher activity's onCreate().")
820         LAUNCHER_LATENCY_STARTUP_ACTIVITY_ON_CREATE(1363),
821 
822         @UiEvent(doc =
823                 "The duration to inflate launcher root view in launcher activity's onCreate().")
824         LAUNCHER_LATENCY_STARTUP_VIEW_INFLATION(1364),
825 
826         @UiEvent(doc = "The duration of asynchronous loading workspace")
827         LAUNCHER_LATENCY_STARTUP_WORKSPACE_LOADER_ASYNC(1367),
828         ;
829 
830         private final int mId;
831 
LauncherLatencyEvent(int id)832         LauncherLatencyEvent(int id) {
833             mId = id;
834         }
835 
836         @Override
getId()837         public int getId() {
838             return mId;
839         }
840     }
841 
842     /**
843      * Launcher specific ranking related events.
844      */
845     public enum LauncherRankingEvent implements EventEnum {
846 
847         UNKNOWN(0);
848         // ADD MORE
849 
850         private final int mId;
851 
LauncherRankingEvent(int id)852         LauncherRankingEvent(int id) {
853             mId = id;
854         }
855 
getId()856         public int getId() {
857             return mId;
858         }
859     }
860 
861     /**
862      * Helps to construct and log launcher event.
863      */
864     public interface StatsLogger {
865 
866         /**
867          * Sets log fields from provided {@link ItemInfo}.
868          */
withItemInfo(ItemInfo itemInfo)869         default StatsLogger withItemInfo(ItemInfo itemInfo) {
870             return this;
871         }
872 
873 
874         /**
875          * Sets {@link InstanceId} of log message.
876          */
withInstanceId(InstanceId instanceId)877         default StatsLogger withInstanceId(InstanceId instanceId) {
878             return this;
879         }
880 
881         /**
882          * Sets rank field of log message.
883          */
withRank(int rank)884         default StatsLogger withRank(int rank) {
885             return this;
886         }
887 
888         /**
889          * Sets source launcher state field of log message.
890          */
withSrcState(int srcState)891         default StatsLogger withSrcState(int srcState) {
892             return this;
893         }
894 
895         /**
896          * Sets destination launcher state field of log message.
897          */
withDstState(int dstState)898         default StatsLogger withDstState(int dstState) {
899             return this;
900         }
901 
902         /**
903          * Sets FromState field of log message.
904          */
withFromState(FromState fromState)905         default StatsLogger withFromState(FromState fromState) {
906             return this;
907         }
908 
909         /**
910          * Sets ToState field of log message.
911          */
withToState(ToState toState)912         default StatsLogger withToState(ToState toState) {
913             return this;
914         }
915 
916         /**
917          * Sets editText field of log message.
918          */
withEditText(String editText)919         default StatsLogger withEditText(String editText) {
920             return this;
921         }
922 
923         /**
924          * Sets the final value for container related fields of log message.
925          *
926          * By default container related fields are derived from {@link ItemInfo}, this method would
927          * override those values.
928          */
withContainerInfo(ContainerInfo containerInfo)929         default StatsLogger withContainerInfo(ContainerInfo containerInfo) {
930             return this;
931         }
932 
933         /**
934          * Sets logging fields from provided {@link SliceItem}.
935          */
withSliceItem(SliceItem sliceItem)936         default StatsLogger withSliceItem(SliceItem sliceItem) {
937             return this;
938         }
939 
940         /**
941          * Sets logging fields from provided {@link LauncherAtom.Slice}.
942          */
withSlice(LauncherAtom.Slice slice)943         default StatsLogger withSlice(LauncherAtom.Slice slice) {
944             return this;
945         }
946 
947         /**
948          * Sets cardinality of log message.
949          */
withCardinality(int cardinality)950         default StatsLogger withCardinality(int cardinality) {
951             return this;
952         }
953 
954         /**
955          * Sets the input type of the log message.
956          */
withInputType(int inputType)957         default StatsLogger withInputType(int inputType) {
958             return this;
959         }
960 
961         /**
962          * Set the features of the log message.
963          */
withFeatures(int feature)964         default StatsLogger withFeatures(int feature) {
965             return this;
966         }
967 
968         /**
969          * Set the package name of the log message.
970          */
withPackageName(@ullable String packageName)971         default StatsLogger withPackageName(@Nullable String packageName) {
972             return this;
973         }
974 
975         /**
976          * Builds the final message and logs it as {@link EventEnum}.
977          */
log(EventEnum event)978         default void log(EventEnum event) {
979         }
980 
981         /**
982          * Builds the final message and logs it to two different atoms, one for
983          * event tracking and the other for jank tracking.
984          */
sendToInteractionJankMonitor(EventEnum event, View v)985         default void sendToInteractionJankMonitor(EventEnum event, View v) {
986         }
987     }
988 
989     /**
990      * Helps to construct and log latency event.
991      */
992     public interface StatsLatencyLogger {
993 
994         /**
995          * Should be in sync with:
996          * google3/wireless/android/sysui/aster/asterstats/launcher_event_processed.proto
997          */
998         enum LatencyType {
999             UNKNOWN(0),
1000             // example: launcher restart that happens via daily backup and restore
1001             COLD(1),
1002             HOT(2),
1003             TIMEOUT(3),
1004             FAIL(4),
1005             COLD_USERWAITING(5),
1006             ATOMIC(6),
1007             CONTROLLED(7),
1008             CACHED(8),
1009             // example: device is rebooting via power key or shell command `adb reboot`
1010             COLD_DEVICE_REBOOTING(9),
1011             // Tracking warm startup latency:
1012             // https://developer.android.com/topic/performance/vitals/launch-time#warm
1013             WARM(10);
1014             private final int mId;
1015 
LatencyType(int id)1016             LatencyType(int id) {
1017                 this.mId = id;
1018             }
1019 
getId()1020             public int getId() {
1021                 return mId;
1022             }
1023         }
1024 
1025         /**
1026          * Sets {@link InstanceId} of log message.
1027          */
withInstanceId(InstanceId instanceId)1028         default StatsLatencyLogger withInstanceId(InstanceId instanceId) {
1029             return this;
1030         }
1031 
1032 
1033         /**
1034          * Sets latency of the event.
1035          */
withLatency(long latencyInMillis)1036         default StatsLatencyLogger withLatency(long latencyInMillis) {
1037             return this;
1038         }
1039 
1040         /**
1041          * Sets {@link LatencyType} of log message.
1042          */
withType(LatencyType type)1043         default StatsLatencyLogger withType(LatencyType type) {
1044             return this;
1045         }
1046 
1047         /**
1048          * Sets query length of the event.
1049          */
withQueryLength(int queryLength)1050         default StatsLatencyLogger withQueryLength(int queryLength) {
1051             return this;
1052         }
1053 
1054         /**
1055          * Sets sub event type.
1056          */
withSubEventType(int type)1057         default StatsLatencyLogger withSubEventType(int type) {
1058             return this;
1059         }
1060 
1061 
1062         /** Sets cardinality of the event. */
withCardinality(int cardinality)1063         default StatsLatencyLogger withCardinality(int cardinality) {
1064             return this;
1065         }
1066 
1067         /**
1068          * Sets packageId of log message.
1069          */
withPackageId(int packageId)1070         default StatsLatencyLogger withPackageId(int packageId) {
1071             return this;
1072         }
1073 
1074         /**
1075          * Builds the final message and logs it as {@link EventEnum}.
1076          */
log(EventEnum event)1077         default void log(EventEnum event) {
1078         }
1079     }
1080 
1081     /**
1082      * Helps to construct and log impression event.
1083      */
1084     public interface StatsImpressionLogger {
1085 
1086         enum State {
1087             UNKNOWN(0),
1088             ALLAPPS(1),
1089             SEARCHBOX_WIDGET(2);
1090             private final int mLauncherState;
1091 
State(int id)1092             State(int id) {
1093                 this.mLauncherState = id;
1094             }
1095 
getLauncherState()1096             public int getLauncherState() {
1097                 return mLauncherState;
1098             }
1099         }
1100 
1101         /**
1102          * Sets {@link InstanceId} of log message.
1103          */
withInstanceId(InstanceId instanceId)1104         default StatsImpressionLogger withInstanceId(InstanceId instanceId) {
1105             return this;
1106         }
1107 
1108         /**
1109          * Sets {@link State} of impression event.
1110          */
withState(State state)1111         default StatsImpressionLogger withState(State state) {
1112             return this;
1113         }
1114 
1115         /**
1116          * Sets query length of the event.
1117          */
withQueryLength(int queryLength)1118         default StatsImpressionLogger withQueryLength(int queryLength) {
1119             return this;
1120         }
1121 
1122         /**
1123          * Sets {@link com.android.app.search.ResultType} for the impression event.
1124          */
withResultType(int resultType)1125         default StatsImpressionLogger withResultType(int resultType) {
1126             return this;
1127         }
1128 
1129         /**
1130          * Sets boolean for each of {@link com.android.app.search.ResultType} that indicates
1131          * if this result is above keyboard or not for the impression event.
1132          */
withAboveKeyboard(boolean aboveKeyboard)1133         default StatsImpressionLogger withAboveKeyboard(boolean aboveKeyboard) {
1134             return this;
1135         }
1136 
1137         /**
1138          * Sets uid for each of {@link com.android.app.search.ResultType} that indicates
1139          * package name for the impression event.
1140          */
withUid(int uid)1141         default StatsImpressionLogger withUid(int uid) {
1142             return this;
1143         }
1144 
1145         /**
1146          * Sets result source that indicates the origin of the result for the impression event.
1147          */
withResultSource(int resultSource)1148         default StatsImpressionLogger withResultSource(int resultSource) {
1149             return this;
1150         }
1151 
1152         /**
1153          * Builds the final message and logs it as {@link EventEnum}.
1154          */
log(EventEnum event)1155         default void log(EventEnum event) {
1156         }
1157     }
1158 
1159     /**
1160      * Returns new logger object.
1161      */
logger()1162     public StatsLogger logger() {
1163         StatsLogger logger = createLogger();
1164         if (mInstanceId != null) {
1165             logger.withInstanceId(mInstanceId);
1166         }
1167         return logger;
1168     }
1169 
1170     /**
1171      * Returns new latency logger object.
1172      */
latencyLogger()1173     public StatsLatencyLogger latencyLogger() {
1174         StatsLatencyLogger logger = createLatencyLogger();
1175         if (mInstanceId != null) {
1176             logger.withInstanceId(mInstanceId);
1177         }
1178         return logger;
1179     }
1180 
1181     /**
1182      * Returns new impression logger object.
1183      */
impressionLogger()1184     public StatsImpressionLogger impressionLogger() {
1185         StatsImpressionLogger logger = createImpressionLogger();
1186         if (mInstanceId != null) {
1187             logger.withInstanceId(mInstanceId);
1188         }
1189         return logger;
1190     }
1191 
1192     /**
1193      * Returns a singleton KeyboardStateManager.
1194      */
keyboardStateManager()1195     public KeyboardStateManager keyboardStateManager() {
1196         if (mKeyboardStateManager == null) {
1197             mKeyboardStateManager = new KeyboardStateManager(
1198                     mContext != null ? mContext.getResources().getDimensionPixelSize(
1199                             R.dimen.default_ime_height) : 0);
1200         }
1201         return mKeyboardStateManager;
1202     }
1203 
createLogger()1204     protected StatsLogger createLogger() {
1205         return new StatsLogger() {
1206         };
1207     }
1208 
createLatencyLogger()1209     protected StatsLatencyLogger createLatencyLogger() {
1210         return new StatsLatencyLogger() {
1211         };
1212     }
1213 
createImpressionLogger()1214     protected StatsImpressionLogger createImpressionLogger() {
1215         return new StatsImpressionLogger() {
1216         };
1217     }
1218 
1219     /**
1220      * Sets InstanceId to every new {@link StatsLogger} object returned by {@link #logger()} when
1221      * not-null.
1222      */
withDefaultInstanceId(@ullable InstanceId instanceId)1223     public StatsLogManager withDefaultInstanceId(@Nullable InstanceId instanceId) {
1224         this.mInstanceId = instanceId;
1225         return this;
1226     }
1227 
1228     /**
1229      * Creates a new instance of {@link StatsLogManager} based on provided context.
1230      */
newInstance(Context context)1231     public static StatsLogManager newInstance(Context context) {
1232         return Overrides.getObject(
1233                 StatsLogManager.class, context, R.string.stats_log_manager_class);
1234     }
1235 }
1236