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.ResourceBasedOverride;
36 import com.android.launcher3.views.ActivityContext;
37 
38 /**
39  * Handles the user event logging in R+.
40  *
41  * <pre>
42  * All of the event ids are defined here.
43  * Most of the methods are placeholder methods for Launcher3
44  * Actual call happens only for Launcher variant that implements QuickStep.
45  * </pre>
46  */
47 public class StatsLogManager implements ResourceBasedOverride {
48 
49     public static final int LAUNCHER_STATE_UNSPECIFIED = 0;
50     public static final int LAUNCHER_STATE_BACKGROUND = 1;
51     public static final int LAUNCHER_STATE_HOME = 2;
52     public static final int LAUNCHER_STATE_OVERVIEW = 3;
53     public static final int LAUNCHER_STATE_ALLAPPS = 4;
54     public static final int LAUNCHER_STATE_UNCHANGED = 5;
55 
56     private InstanceId mInstanceId;
57 
58     protected @Nullable ActivityContext mActivityContext = null;
59 
60     /**
61      * Returns event enum based on the two state transition information when swipe
62      * gesture happens(to be removed during UserEventDispatcher cleanup).
63      */
getLauncherAtomEvent(int startState, int targetState, EventEnum fallbackEvent)64     public static EventEnum getLauncherAtomEvent(int startState,
65             int targetState, EventEnum fallbackEvent) {
66         if (startState == LAUNCHER_STATE_HOME
67                 && targetState == LAUNCHER_STATE_HOME) {
68             return LAUNCHER_HOME_GESTURE;
69         } else if (startState != LAUNCHER_STATE_OVERVIEW
70                 && targetState == LAUNCHER_STATE_OVERVIEW) {
71             return LAUNCHER_OVERVIEW_GESTURE;
72         } else if (startState != LAUNCHER_STATE_ALLAPPS
73                 && targetState == LAUNCHER_STATE_ALLAPPS) {
74             return LAUNCHER_ALLAPPS_OPEN_UP;
75         } else if (startState == LAUNCHER_STATE_ALLAPPS
76                 && targetState != LAUNCHER_STATE_ALLAPPS) {
77             return LAUNCHER_ALLAPPS_CLOSE_DOWN;
78         }
79         return fallbackEvent; // TODO fix
80     }
81 
82     public interface EventEnum {
83 
84         /**
85          * Tag used to request new UI Event IDs via presubmit analysis.
86          *
87          * <p>Use RESERVE_NEW_UI_EVENT_ID as the constructor parameter for a new {@link EventEnum}
88          * to signal the presubmit analyzer to reserve a new ID for the event. The new ID will be
89          * returned as a Gerrit presubmit finding.  Do not submit {@code RESERVE_NEW_UI_EVENT_ID} as
90          * the constructor parameter for any event.
91          *
92          * <pre>
93          * &#064;UiEvent(doc = "Briefly describe the interaction when this event will be logged")
94          * UNIQUE_EVENT_NAME(RESERVE_NEW_UI_EVENT_ID);
95          * </pre>
96          */
97         int RESERVE_NEW_UI_EVENT_ID = Integer.MIN_VALUE; // Negative IDs are ignored by the logger.
98 
getId()99         int getId();
100     }
101 
102     public enum LauncherEvent implements EventEnum {
103         /* Used to prevent double logging. */
104         IGNORE(-1),
105 
106         @UiEvent(doc = "App launched from workspace, hotseat or folder in launcher")
107         LAUNCHER_APP_LAUNCH_TAP(338),
108 
109         @UiEvent(doc = "Task launched from overview using TAP")
110         LAUNCHER_TASK_LAUNCH_TAP(339),
111 
112         @UiEvent(doc = "User tapped on notification inside popup context menu.")
113         LAUNCHER_NOTIFICATION_LAUNCH_TAP(516),
114 
115         @UiEvent(doc = "Task launched from overview using SWIPE DOWN")
116         LAUNCHER_TASK_LAUNCH_SWIPE_DOWN(340),
117 
118         @UiEvent(doc = "TASK dismissed from overview using SWIPE UP")
119         LAUNCHER_TASK_DISMISS_SWIPE_UP(341),
120 
121         @UiEvent(doc = "User dragged a launcher item")
122         LAUNCHER_ITEM_DRAG_STARTED(383),
123 
124         @UiEvent(doc = "A dragged launcher item is successfully dropped onto workspace, hotseat "
125                 + "open folder etc")
126         LAUNCHER_ITEM_DROP_COMPLETED(385),
127 
128         @UiEvent(doc = "A dragged launcher item is successfully dropped onto a folder icon.")
129         LAUNCHER_ITEM_DROP_COMPLETED_ON_FOLDER_ICON(697),
130 
131         @UiEvent(doc = "A dragged launcher item is successfully dropped on another item "
132                 + "resulting in a new folder creation")
133         LAUNCHER_ITEM_DROP_FOLDER_CREATED(386),
134 
135         @UiEvent(doc = "Folder's label is automatically assigned.")
136         LAUNCHER_FOLDER_AUTO_LABELED(591),
137 
138         @UiEvent(doc = "Could not auto-label a folder because primary suggestion is null or empty.")
139         LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_PRIMARY(592),
140 
141         @UiEvent(doc = "Could not auto-label a folder because no suggestions exist.")
142         LAUNCHER_FOLDER_AUTO_LABELING_SKIPPED_EMPTY_SUGGESTIONS(593),
143 
144         @UiEvent(doc = "User manually updated the folder label.")
145         LAUNCHER_FOLDER_LABEL_UPDATED(460),
146 
147         @UiEvent(doc = "User long pressed on the workspace empty space.")
148         LAUNCHER_WORKSPACE_LONGPRESS(461),
149 
150         @UiEvent(doc = "User tapped or long pressed on a wallpaper icon inside launcher settings.")
151         LAUNCHER_WALLPAPER_BUTTON_TAP_OR_LONGPRESS(462),
152 
153         @UiEvent(doc = "User tapped or long pressed on settings icon inside launcher settings.")
154         LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS(463),
155 
156         @UiEvent(doc = "User tapped or long pressed on widget tray icon inside launcher settings.")
157         LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS(464),
158 
159         @UiEvent(doc = "User expanded the list of widgets for a single app in the widget picker.")
160         LAUNCHER_WIDGETSTRAY_APP_EXPANDED(818),
161 
162         @UiEvent(doc = "User searched for a widget in the widget picker.")
163         LAUNCHER_WIDGETSTRAY_SEARCHED(819),
164 
165         @UiEvent(doc = "A dragged item is dropped on 'Remove' button in the target bar")
166         LAUNCHER_ITEM_DROPPED_ON_REMOVE(465),
167 
168         @UiEvent(doc = "A dragged item is dropped on 'Cancel' button in the target bar")
169         LAUNCHER_ITEM_DROPPED_ON_CANCEL(466),
170 
171         @UiEvent(doc = "A predicted item is dragged and dropped on 'Don't suggest app'"
172                 + " button in the target bar")
173         LAUNCHER_ITEM_DROPPED_ON_DONT_SUGGEST(467),
174 
175         @UiEvent(doc = "A dragged item is dropped on 'Uninstall' button in target bar")
176         LAUNCHER_ITEM_DROPPED_ON_UNINSTALL(468),
177 
178         @UiEvent(doc = "User completed uninstalling the package after dropping on "
179                 + "the icon onto 'Uninstall' button in the target bar")
180         LAUNCHER_ITEM_UNINSTALL_COMPLETED(469),
181 
182         @UiEvent(doc = "User cancelled uninstalling the package after dropping on "
183                 + "the icon onto 'Uninstall' button in the target bar")
184         LAUNCHER_ITEM_UNINSTALL_CANCELLED(470),
185 
186         @UiEvent(doc = "User tapped or long pressed on the task icon(aka package icon) "
187                 + "from overview to open task menu.")
188         LAUNCHER_TASK_ICON_TAP_OR_LONGPRESS(517),
189 
190         @UiEvent(doc = "User opened package specific widgets list by tapping on widgets system "
191                 + "shortcut inside popup context menu.")
192         LAUNCHER_SYSTEM_SHORTCUT_WIDGETS_TAP(514),
193 
194         @UiEvent(doc = "User tapped on app info system shortcut.")
195         LAUNCHER_SYSTEM_SHORTCUT_APP_INFO_TAP(515),
196 
197         @UiEvent(doc = "User tapped on split screen icon on a task menu.")
198         LAUNCHER_SYSTEM_SHORTCUT_SPLIT_SCREEN_TAP(518),
199 
200         @UiEvent(doc = "User tapped on free form icon on a task menu.")
201         LAUNCHER_SYSTEM_SHORTCUT_FREE_FORM_TAP(519),
202 
203         @UiEvent(doc = "User tapped on pause app system shortcut.")
204         LAUNCHER_SYSTEM_SHORTCUT_PAUSE_TAP(521),
205 
206         @UiEvent(doc = "User tapped on pin system shortcut.")
207         LAUNCHER_SYSTEM_SHORTCUT_PIN_TAP(522),
208 
209         @UiEvent(doc = "User is shown All Apps education view.")
210         LAUNCHER_ALL_APPS_EDU_SHOWN(523),
211 
212         @UiEvent(doc = "User opened a folder.")
213         LAUNCHER_FOLDER_OPEN(551),
214 
215         @UiEvent(doc = "Hotseat education half sheet seen")
216         LAUNCHER_HOTSEAT_EDU_SEEN(479),
217 
218         @UiEvent(doc = "Hotseat migration accepted")
219         LAUNCHER_HOTSEAT_EDU_ACCEPT(480),
220 
221         @UiEvent(doc = "Hotseat migration denied")
222         LAUNCHER_HOTSEAT_EDU_DENY(481),
223 
224         @UiEvent(doc = "Hotseat education tip shown")
225         LAUNCHER_HOTSEAT_EDU_ONLY_TIP(482),
226 
227         /**
228          * @deprecated LauncherUiChanged.rank field is repurposed to store all apps rank, so no
229          * separate event is required.
230          */
231         @Deprecated
232         @UiEvent(doc = "App launch ranking logged for all apps predictions")
233         LAUNCHER_ALL_APPS_RANKED(552),
234 
235         @UiEvent(doc = "App launch ranking logged for hotseat predictions)")
236         LAUNCHER_HOTSEAT_RANKED(553),
237         @UiEvent(doc = "Launcher is now in background. e.g., Screen off event")
238         LAUNCHER_ONSTOP(562),
239 
240         @UiEvent(doc = "Launcher is now in foreground. e.g., Screen on event, back button")
241         LAUNCHER_ONRESUME(563),
242 
243         @UiEvent(doc = "User swipes or fling in LEFT direction on workspace.")
244         LAUNCHER_SWIPELEFT(564),
245 
246         @UiEvent(doc = "User swipes or fling in RIGHT direction on workspace.")
247         LAUNCHER_SWIPERIGHT(565),
248 
249         @UiEvent(doc = "User swipes or fling in UP direction in unknown way.")
250         LAUNCHER_UNKNOWN_SWIPEUP(566),
251 
252         @UiEvent(doc = "User swipes or fling in DOWN direction in unknown way.")
253         LAUNCHER_UNKNOWN_SWIPEDOWN(567),
254 
255         @UiEvent(doc = "User swipes or fling in UP direction to open apps drawer.")
256         LAUNCHER_ALLAPPS_OPEN_UP(568),
257 
258         @UiEvent(doc = "User swipes or fling in DOWN direction to close apps drawer.")
259         LAUNCHER_ALLAPPS_CLOSE_DOWN(569),
260 
261         @UiEvent(doc = "User swipes or fling in UP direction and hold from the bottom bazel area")
262         LAUNCHER_OVERVIEW_GESTURE(570),
263 
264         @UiEvent(doc = "User swipes or fling in LEFT direction on the bottom bazel area.")
265         LAUNCHER_QUICKSWITCH_LEFT(571),
266 
267         @UiEvent(doc = "User swipes or fling in RIGHT direction on the bottom bazel area.")
268         LAUNCHER_QUICKSWITCH_RIGHT(572),
269 
270         @UiEvent(doc = "User swipes or fling in DOWN direction on the bottom bazel area.")
271         LAUNCHER_SWIPEDOWN_NAVBAR(573),
272 
273         @UiEvent(doc = "User swipes or fling in UP direction from bottom bazel area.")
274         LAUNCHER_HOME_GESTURE(574),
275 
276         @UiEvent(doc = "User's workspace layout information is snapshot in the background.")
277         LAUNCHER_WORKSPACE_SNAPSHOT(579),
278 
279         @UiEvent(doc = "User tapped on the screenshot button on overview)")
280         LAUNCHER_OVERVIEW_ACTIONS_SCREENSHOT(580),
281 
282         @UiEvent(doc = "User tapped on the select button on overview)")
283         LAUNCHER_OVERVIEW_ACTIONS_SELECT(581),
284 
285         @UiEvent(doc = "User tapped on the share button on overview")
286         LAUNCHER_OVERVIEW_ACTIONS_SHARE(582),
287 
288         @UiEvent(doc = "User tapped on the split screen button on overview")
289         LAUNCHER_OVERVIEW_ACTIONS_SPLIT(895),
290 
291         @UiEvent(doc = "User tapped on the close button in select mode")
292         LAUNCHER_SELECT_MODE_CLOSE(583),
293 
294         @UiEvent(doc = "User tapped on the highlight items in select mode")
295         LAUNCHER_SELECT_MODE_ITEM(584),
296 
297         @UiEvent(doc = "Notification dot on app icon enabled.")
298         LAUNCHER_NOTIFICATION_DOT_ENABLED(611),
299 
300         @UiEvent(doc = "Notification dot on app icon disabled.")
301         LAUNCHER_NOTIFICATION_DOT_DISABLED(612),
302 
303         @UiEvent(doc = "For new apps, add app icons to home screen enabled.")
304         LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_ENABLED(613),
305 
306         @UiEvent(doc = "For new apps, add app icons to home screen disabled.")
307         LAUNCHER_ADD_NEW_APPS_TO_HOME_SCREEN_DISABLED(614),
308 
309         @UiEvent(doc = "Home screen rotation is enabled when phone is rotated.")
310         LAUNCHER_HOME_SCREEN_ROTATION_ENABLED(615),
311 
312         @UiEvent(doc = "Home screen rotation is disabled when phone is rotated.")
313         LAUNCHER_HOME_SCREEN_ROTATION_DISABLED(616),
314 
315         @UiEvent(doc = "Suggestions in all apps list enabled.")
316         LAUNCHER_ALL_APPS_SUGGESTIONS_ENABLED(619),
317 
318         @UiEvent(doc = "Suggestions in all apps list disabled.")
319         LAUNCHER_ALL_APPS_SUGGESTIONS_DISABLED(620),
320 
321         @UiEvent(doc = "Suggestions on home screen is enabled.")
322         LAUNCHER_HOME_SCREEN_SUGGESTIONS_ENABLED(621),
323 
324         @UiEvent(doc = "Suggestions on home screen is disabled.")
325         LAUNCHER_HOME_SCREEN_SUGGESTIONS_DISABLED(622),
326 
327         @UiEvent(doc = "System navigation is 3 button mode.")
328         LAUNCHER_NAVIGATION_MODE_3_BUTTON(623),
329 
330         @UiEvent(doc = "System navigation mode is 2 button mode.")
331         LAUNCHER_NAVIGATION_MODE_2_BUTTON(624),
332 
333         @UiEvent(doc = "System navigation mode is 0 button mode/gesture navigation mode .")
334         LAUNCHER_NAVIGATION_MODE_GESTURE_BUTTON(625),
335 
336         @UiEvent(doc = "User tapped on image content in Overview Select mode.")
337         LAUNCHER_SELECT_MODE_IMAGE(627),
338 
339         @UiEvent(doc = "Activity to add external item was started")
340         LAUNCHER_ADD_EXTERNAL_ITEM_START(641),
341 
342         @UiEvent(doc = "Activity to add external item was cancelled")
343         LAUNCHER_ADD_EXTERNAL_ITEM_CANCELLED(642),
344 
345         @UiEvent(doc = "Activity to add external item was backed out")
346         LAUNCHER_ADD_EXTERNAL_ITEM_BACK(643),
347 
348         @UiEvent(doc = "Item was placed automatically in external item addition flow")
349         LAUNCHER_ADD_EXTERNAL_ITEM_PLACED_AUTOMATICALLY(644),
350 
351         @UiEvent(doc = "Item was dragged in external item addition flow")
352         LAUNCHER_ADD_EXTERNAL_ITEM_DRAGGED(645),
353 
354         @UiEvent(doc = "A folder was replaced by a single item")
355         LAUNCHER_FOLDER_CONVERTED_TO_ICON(646),
356 
357         @UiEvent(doc = "A hotseat prediction item was pinned")
358         LAUNCHER_HOTSEAT_PREDICTION_PINNED(647),
359 
360         @UiEvent(doc = "Undo event was tapped.")
361         LAUNCHER_UNDO(648),
362 
363         @UiEvent(doc = "Task switcher clear all target was tapped.")
364         LAUNCHER_TASK_CLEAR_ALL(649),
365 
366         @UiEvent(doc = "Task preview was long pressed.")
367         LAUNCHER_TASK_PREVIEW_LONGPRESS(650),
368 
369         @UiEvent(doc = "User swiped down on workspace (triggering noti shade to open).")
370         LAUNCHER_SWIPE_DOWN_WORKSPACE_NOTISHADE_OPEN(651),
371 
372         @UiEvent(doc = "Notification dismissed by swiping right.")
373         LAUNCHER_NOTIFICATION_DISMISSED(652),
374 
375         @UiEvent(doc = "Current grid size is changed to 5.")
376         LAUNCHER_GRID_SIZE_5(662),
377 
378         @UiEvent(doc = "Current grid size is changed to 4.")
379         LAUNCHER_GRID_SIZE_4(663),
380 
381         @UiEvent(doc = "Current grid size is changed to 3.")
382         LAUNCHER_GRID_SIZE_3(664),
383 
384         @UiEvent(doc = "Current grid size is changed to 2.")
385         LAUNCHER_GRID_SIZE_2(665),
386 
387         @UiEvent(doc = "Launcher entered into AllApps state.")
388         LAUNCHER_ALLAPPS_ENTRY(692),
389 
390         @UiEvent(doc = "Launcher exited from AllApps state.")
391         LAUNCHER_ALLAPPS_EXIT(693),
392 
393         @UiEvent(doc = "User closed the AllApps keyboard.")
394         LAUNCHER_ALLAPPS_KEYBOARD_CLOSED(694),
395 
396         @UiEvent(doc = "User switched to AllApps Main/Personal tab by swiping left.")
397         LAUNCHER_ALLAPPS_SWIPE_TO_PERSONAL_TAB(695),
398 
399         @UiEvent(doc = "User switched to AllApps Work tab by swiping right.")
400         LAUNCHER_ALLAPPS_SWIPE_TO_WORK_TAB(696),
401 
402         @UiEvent(doc = "Default event when dedicated UI event is not available for the user action"
403                 + " on slice .")
404         LAUNCHER_SLICE_DEFAULT_ACTION(700),
405 
406         @UiEvent(doc = "User toggled-on a Slice item.")
407         LAUNCHER_SLICE_TOGGLE_ON(701),
408 
409         @UiEvent(doc = "User toggled-off a Slice item.")
410         LAUNCHER_SLICE_TOGGLE_OFF(702),
411 
412         @UiEvent(doc = "User acted on a Slice item with a button.")
413         LAUNCHER_SLICE_BUTTON_ACTION(703),
414 
415         @UiEvent(doc = "User acted on a Slice item with a slider.")
416         LAUNCHER_SLICE_SLIDER_ACTION(704),
417 
418         @UiEvent(doc = "User tapped on the entire row of a Slice.")
419         LAUNCHER_SLICE_CONTENT_ACTION(705),
420 
421         @UiEvent(doc = "User tapped on the see more button of a Slice.")
422         LAUNCHER_SLICE_SEE_MORE_ACTION(706),
423 
424         @UiEvent(doc = "User selected from a selection row of Slice.")
425         LAUNCHER_SLICE_SELECTION_ACTION(707),
426 
427         @UiEvent(doc = "IME is used for selecting the focused item on the AllApps screen.")
428         LAUNCHER_ALLAPPS_FOCUSED_ITEM_SELECTED_WITH_IME(718),
429 
430         @UiEvent(doc = "User long-pressed on an AllApps item.")
431         LAUNCHER_ALLAPPS_ITEM_LONG_PRESSED(719),
432 
433         @UiEvent(doc = "Launcher entered into AllApps state with device search enabled.")
434         LAUNCHER_ALLAPPS_ENTRY_WITH_DEVICE_SEARCH(720),
435 
436         @UiEvent(doc = "User switched to AllApps Main/Personal tab by tapping on it.")
437         LAUNCHER_ALLAPPS_TAP_ON_PERSONAL_TAB(721),
438 
439         @UiEvent(doc = "User switched to AllApps Work tab by tapping on it.")
440         LAUNCHER_ALLAPPS_TAP_ON_WORK_TAB(722),
441 
442         @UiEvent(doc = "All apps vertical fling started.")
443         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_BEGIN(724),
444 
445         @UiEvent(doc = "All apps vertical fling ended.")
446         LAUNCHER_ALLAPPS_VERTICAL_SWIPE_END(725),
447 
448         @UiEvent(doc = "Show URL indicator for Overview Sharing")
449         LAUNCHER_OVERVIEW_SHARING_SHOW_URL_INDICATOR(764),
450 
451         @UiEvent(doc = "Show image indicator for Overview Sharing")
452         LAUNCHER_OVERVIEW_SHARING_SHOW_IMAGE_INDICATOR(765),
453 
454         @UiEvent(doc = "User taps URL indicator in Overview")
455         LAUNCHER_OVERVIEW_SHARING_URL_INDICATOR_TAP(766),
456 
457         @UiEvent(doc = "User taps image indicator in Overview")
458         LAUNCHER_OVERVIEW_SHARING_IMAGE_INDICATOR_TAP(767),
459 
460         @UiEvent(doc = "User long presses an image in Overview")
461         LAUNCHER_OVERVIEW_SHARING_IMAGE_LONG_PRESS(768),
462 
463         @UiEvent(doc = "User drags a URL in Overview")
464         LAUNCHER_OVERVIEW_SHARING_URL_DRAG(769),
465 
466         @UiEvent(doc = "User drags an image in Overview")
467         LAUNCHER_OVERVIEW_SHARING_IMAGE_DRAG(770),
468 
469         @UiEvent(doc = "User drops URL to a direct share target")
470         LAUNCHER_OVERVIEW_SHARING_DROP_URL_TO_TARGET(771),
471 
472         @UiEvent(doc = "User drops an image to a direct share target")
473         LAUNCHER_OVERVIEW_SHARING_DROP_IMAGE_TO_TARGET(772),
474 
475         @UiEvent(doc = "User drops URL to the More button")
476         LAUNCHER_OVERVIEW_SHARING_DROP_URL_TO_MORE(773),
477 
478         @UiEvent(doc = "User drops an image to the More button")
479         LAUNCHER_OVERVIEW_SHARING_DROP_IMAGE_TO_MORE(774),
480 
481         @UiEvent(doc = "User taps a share target to share URL")
482         LAUNCHER_OVERVIEW_SHARING_TAP_TARGET_TO_SHARE_URL(775),
483 
484         @UiEvent(doc = "User taps a share target to share an image")
485         LAUNCHER_OVERVIEW_SHARING_TAP_TARGET_TO_SHARE_IMAGE(776),
486 
487         @UiEvent(doc = "User taps the More button to share URL")
488         LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_URL(777),
489 
490         @UiEvent(doc = "User taps the More button to share an image")
491         LAUNCHER_OVERVIEW_SHARING_TAP_MORE_TO_SHARE_IMAGE(778),
492 
493         @UiEvent(doc = "User started resizing a widget on their home screen.")
494         LAUNCHER_WIDGET_RESIZE_STARTED(820),
495 
496         @UiEvent(doc = "User finished resizing a widget on their home screen.")
497         LAUNCHER_WIDGET_RESIZE_COMPLETED(824),
498 
499         @UiEvent(doc = "User reconfigured a widget on their home screen.")
500         LAUNCHER_WIDGET_RECONFIGURED(821),
501 
502         @UiEvent(doc = "User enabled themed icons option in wallpaper & style settings.")
503         LAUNCHER_THEMED_ICON_ENABLED(836),
504 
505         @UiEvent(doc = "User disabled themed icons option in wallpaper & style settings.")
506         LAUNCHER_THEMED_ICON_DISABLED(837),
507 
508         @UiEvent(doc = "User tapped on 'Turn on work apps' button in all apps window.")
509         LAUNCHER_TURN_ON_WORK_APPS_TAP(838),
510 
511         @UiEvent(doc = "User tapped on 'Turn off work apps' button in all apps window.")
512         LAUNCHER_TURN_OFF_WORK_APPS_TAP(839),
513 
514         @UiEvent(doc = "Launcher item drop failed since there was not enough room on the screen.")
515         LAUNCHER_ITEM_DROP_FAILED_INSUFFICIENT_SPACE(872),
516 
517         @UiEvent(doc = "User long pressed on the taskbar background to hide the taskbar")
518         LAUNCHER_TASKBAR_LONGPRESS_HIDE(896),
519 
520         @UiEvent(doc = "User long pressed on the taskbar gesture handle to show the taskbar")
521         LAUNCHER_TASKBAR_LONGPRESS_SHOW(897),
522 
523         @UiEvent(doc = "User clicks on the search icon on header to launch search in app.")
524         LAUNCHER_ALLAPPS_SEARCHINAPP_LAUNCH(913);
525 
526         // ADD MORE
527 
528         private final int mId;
529 
LauncherEvent(int id)530         LauncherEvent(int id) {
531             mId = id;
532         }
533 
getId()534         public int getId() {
535             return mId;
536         }
537     }
538 
539     /**
540      * Launcher specific ranking related events.
541      */
542     public enum LauncherRankingEvent implements EventEnum {
543 
544         UNKNOWN(0);
545         // ADD MORE
546 
547         private final int mId;
548 
LauncherRankingEvent(int id)549         LauncherRankingEvent(int id) {
550             mId = id;
551         }
552 
getId()553         public int getId() {
554             return mId;
555         }
556     }
557 
558     /**
559      * Helps to construct and write the log message.
560      */
561     public interface StatsLogger {
562 
563         /**
564          * Sets log fields from provided {@link ItemInfo}.
565          */
withItemInfo(ItemInfo itemInfo)566         default StatsLogger withItemInfo(ItemInfo itemInfo) {
567             return this;
568         }
569 
570 
571         /**
572          * Sets {@link InstanceId} of log message.
573          */
withInstanceId(InstanceId instanceId)574         default StatsLogger withInstanceId(InstanceId instanceId) {
575             return this;
576         }
577 
578         /**
579          * Sets rank field of log message.
580          */
withRank(int rank)581         default StatsLogger withRank(int rank) {
582             return this;
583         }
584 
585         /**
586          * Sets source launcher state field of log message.
587          */
withSrcState(int srcState)588         default StatsLogger withSrcState(int srcState) {
589             return this;
590         }
591 
592         /**
593          * Sets destination launcher state field of log message.
594          */
withDstState(int dstState)595         default StatsLogger withDstState(int dstState) {
596             return this;
597         }
598 
599         /**
600          * Sets FromState field of log message.
601          */
withFromState(FromState fromState)602         default StatsLogger withFromState(FromState fromState) {
603             return this;
604         }
605 
606         /**
607          * Sets ToState field of log message.
608          */
withToState(ToState toState)609         default StatsLogger withToState(ToState toState) {
610             return this;
611         }
612 
613         /**
614          * Sets editText field of log message.
615          */
withEditText(String editText)616         default StatsLogger withEditText(String editText) {
617             return this;
618         }
619 
620         /**
621          * Sets the final value for container related fields of log message.
622          *
623          * By default container related fields are derived from {@link ItemInfo}, this method would
624          * override those values.
625          */
withContainerInfo(ContainerInfo containerInfo)626         default StatsLogger withContainerInfo(ContainerInfo containerInfo) {
627             return this;
628         }
629 
630         /**
631          * Sets logging fields from provided {@link SliceItem}.
632          */
withSliceItem(SliceItem sliceItem)633         default StatsLogger withSliceItem(SliceItem sliceItem) {
634             return this;
635         }
636 
637         /**
638          * Sets logging fields from provided {@link LauncherAtom.Slice}.
639          */
withSlice(LauncherAtom.Slice slice)640         default StatsLogger withSlice(LauncherAtom.Slice slice) {
641             return this;
642         }
643 
644         /**
645          * Builds the final message and logs it as {@link EventEnum}.
646          */
log(EventEnum event)647         default void log(EventEnum event) {
648         }
649 
650         /**
651          * Builds the final message and logs it to two different atoms, one for
652          * event tracking and the other for jank tracking.
653          */
sendToInteractionJankMonitor(EventEnum event, View v)654         default void sendToInteractionJankMonitor(EventEnum event, View v) {
655         }
656     }
657 
658     /**
659      * Returns new logger object.
660      */
logger()661     public StatsLogger logger() {
662         StatsLogger logger = createLogger();
663         if (mInstanceId != null) {
664             logger.withInstanceId(mInstanceId);
665         }
666         return logger;
667     }
668 
createLogger()669     protected StatsLogger createLogger() {
670         return new StatsLogger() {
671         };
672     }
673 
674     /**
675      * Sets InstanceId to every new {@link StatsLogger} object returned by {@link #logger()} when
676      * not-null.
677      */
withDefaultInstanceId(@ullable InstanceId instanceId)678     public StatsLogManager withDefaultInstanceId(@Nullable InstanceId instanceId) {
679         this.mInstanceId = instanceId;
680         return this;
681     }
682 
683     /**
684      * Creates a new instance of {@link StatsLogManager} based on provided context.
685      */
newInstance(Context context)686     public static StatsLogManager newInstance(Context context) {
687         StatsLogManager manager = Overrides.getObject(StatsLogManager.class,
688                 context.getApplicationContext(), R.string.stats_log_manager_class);
689         manager.mActivityContext = ActivityContext.lookupContextNoThrow(context);
690         return manager;
691     }
692 }
693