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