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