1 /*
2  * Copyright (C) 2022 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 
17 package com.android.providers.media.photopicker.metrics;
18 
19 import androidx.annotation.NonNull;
20 import androidx.annotation.VisibleForTesting;
21 
22 import com.android.internal.logging.InstanceId;
23 import com.android.internal.logging.UiEvent;
24 import com.android.internal.logging.UiEventLogger;
25 import com.android.providers.media.metrics.MPUiEventLoggerImpl;
26 
27 public class PhotoPickerUiEventLogger {
28 
29     @VisibleForTesting
30     public enum PhotoPickerEvent implements UiEventLogger.UiEventEnum {
31         @UiEvent(doc = "Photo picker opened in personal profile")
32         PHOTO_PICKER_OPEN_PERSONAL_PROFILE(942),
33         @UiEvent(doc = "Photo picker opened in work profile")
34         PHOTO_PICKER_OPEN_WORK_PROFILE(943),
35         @UiEvent(doc = "Photo picker opened in unknown profile")
36         PHOTO_PICKER_OPEN_UNKNOWN_PROFILE(1691),
37         @UiEvent(doc = "Photo picker opened via GET_CONTENT intent")
38         PHOTO_PICKER_OPEN_GET_CONTENT(1080),
39         @UiEvent(doc = "Photo picker opened in half screen")
40         PHOTO_PICKER_OPEN_HALF_SCREEN(1166),
41         @UiEvent(doc = "Photo picker opened in full screen")
42         PHOTO_PICKER_OPEN_FULL_SCREEN(1167),
43         @UiEvent(doc = "Photo picker opened in single select mode")
44         PHOTO_PICKER_OPEN_SINGLE_SELECT(1168),
45         @UiEvent(doc = "Photo picker opened in multi select mode")
46         PHOTO_PICKER_OPEN_MULTI_SELECT(1169),
47         @UiEvent(doc = "Photo picker opened with the filter to show all images")
48         PHOTO_PICKER_FILTER_ALL_IMAGES(1170),
49         @UiEvent(doc = "Photo picker opened with the filter to show all videos")
50         PHOTO_PICKER_FILTER_ALL_VIDEOS(1171),
51         @UiEvent(doc = "Photo picker opened with some other specific filter")
52         PHOTO_PICKER_FILTER_OTHER(1172),
53         @UiEvent(doc = "DocumentsUi opened by clicking on Browse in Photo picker")
54         PHOTO_PICKER_BROWSE_DOCUMENTSUI(1085),
55         @UiEvent(doc = "Photo picker cancelled in work profile")
56         PHOTO_PICKER_CANCEL_WORK_PROFILE(1125),
57         @UiEvent(doc = "Photo picker cancelled in personal profile")
58         PHOTO_PICKER_CANCEL_PERSONAL_PROFILE(1126),
59         @UiEvent(doc = "Photo picker cancelled in unknown profile")
60         PHOTO_PICKER_CANCEL_UNKNOWN_PROFILE(1692),
61         @UiEvent(doc = "Confirmed selection in Photo picker in work profile")
62         PHOTO_PICKER_CONFIRM_WORK_PROFILE(1127),
63         @UiEvent(doc = "Confirmed selection in Photo picker in personal profile")
64         PHOTO_PICKER_CONFIRM_PERSONAL_PROFILE(1128),
65         @UiEvent(doc = "Confirmed selection in Photo picker in unknown profile")
66         PHOTO_PICKER_CONFIRM_UNKNOWN_PROFILE(1693),
67         @UiEvent(doc = "Photo picker opened with an active cloud provider")
68         PHOTO_PICKER_CLOUD_PROVIDER_ACTIVE(1198),
69         @UiEvent(doc = "Clicked the mute / unmute button in a photo picker video preview")
70         PHOTO_PICKER_VIDEO_PREVIEW_AUDIO_BUTTON_CLICK(1413),
71         @UiEvent(doc = "Clicked the 'view selected' button in photo picker")
72         PHOTO_PICKER_PREVIEW_ALL_SELECTED(1414),
73         @UiEvent(doc = "Photo picker opened with the 'switch profile' button visible and enabled")
74         PHOTO_PICKER_PROFILE_SWITCH_BUTTON_ENABLED(1415),
75         @UiEvent(doc = "Photo picker opened with the 'switch profile menu' button visible")
76         PHOTO_PICKER_PROFILE_SWITCH_MENU_BUTTON_VISIBLE(1694),
77         @UiEvent(doc = "Photo picker opened with the 'switch profile' button visible but disabled")
78         PHOTO_PICKER_PROFILE_SWITCH_BUTTON_DISABLED(1416),
79 
80         @UiEvent(doc = "Clicked the 'switch profile' button in photo picker")
81         PHOTO_PICKER_PROFILE_SWITCH_BUTTON_CLICK(1417),
82         @UiEvent(doc = "Clicked the 'switch profile menu' button in photo picker")
83         PHOTO_PICKER_PROFILE_SWITCH_MENU_BUTTON_CLICK(1695),
84         @UiEvent(doc = "Exited photo picker by swiping down")
85         PHOTO_PICKER_EXIT_SWIPE_DOWN(1420),
86         @UiEvent(doc = "Back pressed in photo picker")
87         PHOTO_PICKER_BACK_GESTURE(1421),
88         @UiEvent(doc = "Action bar home button clicked in photo picker")
89         PHOTO_PICKER_ACTION_BAR_HOME_BUTTON_CLICK(1422),
90         @UiEvent(doc = "Expanded from half screen to full in photo picker")
91         PHOTO_PICKER_FROM_HALF_TO_FULL_SCREEN(1423),
92         @UiEvent(doc = "Photo picker menu opened")
93         PHOTO_PICKER_MENU(1424),
94         @UiEvent(doc = "User switched to the photos tab in photo picker")
95         PHOTO_PICKER_TAB_PHOTOS_OPEN(1425),
96         @UiEvent(doc = "User switched to the albums tab in photo picker")
97         PHOTO_PICKER_TAB_ALBUMS_OPEN(1426),
98         @UiEvent(doc = "Opened the device favorites album in photo picker")
99         PHOTO_PICKER_ALBUM_FAVORITES_OPEN(1427),
100         @UiEvent(doc = "Opened the device camera album in photo picker")
101         PHOTO_PICKER_ALBUM_CAMERA_OPEN(1428),
102         @UiEvent(doc = "Opened the device downloads album in photo picker")
103         PHOTO_PICKER_ALBUM_DOWNLOADS_OPEN(1429),
104         @UiEvent(doc = "Opened the device screenshots album in photo picker")
105         PHOTO_PICKER_ALBUM_SCREENSHOTS_OPEN(1430),
106         @UiEvent(doc = "Opened the device videos album in photo picker")
107         PHOTO_PICKER_ALBUM_VIDEOS_OPEN(1431),
108         @UiEvent(doc = "Opened a cloud album in photo picker")
109         PHOTO_PICKER_ALBUM_FROM_CLOUD_OPEN(1432),
110         @UiEvent(doc = "Selected a media item in the main grid")
111         PHOTO_PICKER_SELECTED_ITEM_MAIN_GRID(1433),
112         @UiEvent(doc = "Selected a media item in an album")
113         PHOTO_PICKER_SELECTED_ITEM_ALBUM(1434),
114         @UiEvent(doc = "Selected a cloud only media item")
115         PHOTO_PICKER_SELECTED_ITEM_CLOUD_ONLY(1435),
116         @UiEvent(doc = "Previewed a media item in the main grid")
117         PHOTO_PICKER_PREVIEW_ITEM_MAIN_GRID(1436),
118         @UiEvent(doc = "Loaded media items in the main grid in photo picker")
119         PHOTO_PICKER_UI_LOADED_PHOTOS(1437),
120         @UiEvent(doc = "Loaded albums in photo picker")
121         PHOTO_PICKER_UI_LOADED_ALBUMS(1438),
122         @UiEvent(doc = "Loaded media items in an album grid in photo picker")
123         PHOTO_PICKER_UI_LOADED_ALBUM_CONTENTS(1439),
124         @UiEvent(doc = "Triggered create surface controller in photo picker")
125         PHOTO_PICKER_CREATE_SURFACE_CONTROLLER_START(1452),
126         @UiEvent(doc = "Ended create surface controller in photo picker")
127         PHOTO_PICKER_CREATE_SURFACE_CONTROLLER_END(1453),
128         @UiEvent(doc = "Started the selected media preloading in photo picker")
129         PHOTO_PICKER_PRELOADING_STARTED(1524),
130         @UiEvent(doc = "Finished the selected media preloading in photo picker")
131         PHOTO_PICKER_PRELOADING_FINISHED(1525),
132         @UiEvent(doc = "User cancelled the selected media preloading in photo picker")
133         PHOTO_PICKER_PRELOADING_CANCELLED(1526),
134         @UiEvent(doc = "Failed to preload some selected media items in photo picker")
135         PHOTO_PICKER_PRELOADING_FAILED(1527),
136         @UiEvent(doc = "The banner is added to display in the recycler view grids in photo picker")
137         PHOTO_PICKER_BANNER_ADDED(1539),
138         @UiEvent(doc = "The user clicks the dismiss button of the banner in photo picker")
139         PHOTO_PICKER_BANNER_DISMISSED(1540),
140         @UiEvent(doc = "The user clicks the action button of the banner in photo picker")
141         PHOTO_PICKER_BANNER_ACTION_BUTTON_CLICKED(1541),
142         @UiEvent(doc = "The user clicks on the remaining part of the banner in photo picker")
143         PHOTO_PICKER_BANNER_CLICKED(1542);
144 
145         private final int mId;
146 
PhotoPickerEvent(int id)147         PhotoPickerEvent(int id) {
148             mId = id;
149         }
150 
151         @Override
getId()152         public int getId() {
153             return mId;
154         }
155     }
156 
157     private UiEventLogger logger;
158 
PhotoPickerUiEventLogger()159     public PhotoPickerUiEventLogger() {
160         logger = new MPUiEventLoggerImpl();
161     }
162 
163     @VisibleForTesting
PhotoPickerUiEventLogger(@onNull UiEventLogger logger)164     public PhotoPickerUiEventLogger(@NonNull UiEventLogger logger) {
165         this.logger = logger;
166     }
167 
logPickerOpenPersonal(InstanceId instanceId, int callingUid, String callingPackage)168     public void logPickerOpenPersonal(InstanceId instanceId, int callingUid,
169             String callingPackage) {
170         logger.logWithInstanceId(
171                 PhotoPickerEvent.PHOTO_PICKER_OPEN_PERSONAL_PROFILE,
172                 callingUid,
173                 callingPackage,
174                 instanceId);
175     }
176 
logPickerOpenWork(InstanceId instanceId, int callingUid, String callingPackage)177     public void logPickerOpenWork(InstanceId instanceId, int callingUid,
178             String callingPackage) {
179         logger.logWithInstanceId(
180                 PhotoPickerEvent.PHOTO_PICKER_OPEN_WORK_PROFILE,
181                 callingUid,
182                 callingPackage,
183                 instanceId);
184     }
185 
186     /**
187      * Log metrics to notify that the picker has opened in unknown profile
188      * @param instanceId     an identifier for the current picker session
189      * @param callingUid     the uid of the app initiating the picker launch
190      * @param callingPackage the package name of the app initiating the picker launch
191      */
logPickerOpenUnknown(InstanceId instanceId, int callingUid, String callingPackage)192     public void logPickerOpenUnknown(InstanceId instanceId, int callingUid,
193             String callingPackage) {
194         logger.logWithInstanceId(
195                 PhotoPickerEvent.PHOTO_PICKER_OPEN_UNKNOWN_PROFILE,
196                 callingUid,
197                 callingPackage,
198                 instanceId);
199     }
200 
logPickerOpenViaGetContent(InstanceId instanceId, int callingUid, String callingPackage)201     public void logPickerOpenViaGetContent(InstanceId instanceId, int callingUid,
202             String callingPackage) {
203         logger.logWithInstanceId(
204                 PhotoPickerEvent.PHOTO_PICKER_OPEN_GET_CONTENT,
205                 callingUid,
206                 callingPackage,
207                 instanceId);
208     }
209 
210     /**
211      * Log metrics to notify that the picker has opened in half screen
212      * @param instanceId     an identifier for the current picker session
213      * @param callingUid     the uid of the app initiating the picker launch
214      * @param callingPackage the package name of the app initiating the picker launch
215      */
logPickerOpenInHalfScreen(InstanceId instanceId, int callingUid, String callingPackage)216     public void logPickerOpenInHalfScreen(InstanceId instanceId, int callingUid,
217             String callingPackage) {
218         logger.logWithInstanceId(
219                 PhotoPickerEvent.PHOTO_PICKER_OPEN_HALF_SCREEN,
220                 callingUid,
221                 callingPackage,
222                 instanceId);
223     }
224 
225     /**
226      * Log metrics to notify that the picker has opened in full screen
227      * @param instanceId     an identifier for the current picker session
228      * @param callingUid     the uid of the app initiating the picker launch
229      * @param callingPackage the package name of the app initiating the picker launch
230      */
logPickerOpenInFullScreen(InstanceId instanceId, int callingUid, String callingPackage)231     public void logPickerOpenInFullScreen(InstanceId instanceId, int callingUid,
232             String callingPackage) {
233         logger.logWithInstanceId(
234                 PhotoPickerEvent.PHOTO_PICKER_OPEN_FULL_SCREEN,
235                 callingUid,
236                 callingPackage,
237                 instanceId);
238     }
239 
240     /**
241      * Log metrics to notify that the picker has opened in single select mode
242      * @param instanceId     an identifier for the current picker session
243      * @param callingUid     the uid of the app initiating the picker launch
244      * @param callingPackage the package name of the app initiating the picker launch
245      */
logPickerOpenInSingleSelect(InstanceId instanceId, int callingUid, String callingPackage)246     public void logPickerOpenInSingleSelect(InstanceId instanceId, int callingUid,
247             String callingPackage) {
248         logger.logWithInstanceId(
249                 PhotoPickerEvent.PHOTO_PICKER_OPEN_SINGLE_SELECT,
250                 callingUid,
251                 callingPackage,
252                 instanceId);
253     }
254 
255     /**
256      * Log metrics to notify that the picker has opened in multi select mode
257      * @param instanceId     an identifier for the current picker session
258      * @param callingUid     the uid of the app initiating the picker launch
259      * @param callingPackage the package name of the app initiating the picker launch
260      */
logPickerOpenInMultiSelect(InstanceId instanceId, int callingUid, String callingPackage)261     public void logPickerOpenInMultiSelect(InstanceId instanceId, int callingUid,
262             String callingPackage) {
263         logger.logWithInstanceId(
264                 PhotoPickerEvent.PHOTO_PICKER_OPEN_MULTI_SELECT,
265                 callingUid,
266                 callingPackage,
267                 instanceId);
268     }
269 
270     /**
271      * Log metrics to notify that the picker has opened with the filter to show all images
272      * @param instanceId     an identifier for the current picker session
273      * @param callingUid     the uid of the app initiating the picker launch
274      * @param callingPackage the package name of the app initiating the picker launch
275      */
logPickerOpenWithFilterAllImages(InstanceId instanceId, int callingUid, String callingPackage)276     public void logPickerOpenWithFilterAllImages(InstanceId instanceId, int callingUid,
277             String callingPackage) {
278         logger.logWithInstanceId(
279                 PhotoPickerEvent.PHOTO_PICKER_FILTER_ALL_IMAGES,
280                 callingUid,
281                 callingPackage,
282                 instanceId);
283     }
284 
285     /**
286      * Log metrics to notify that the picker has opened with the filter to show all videos
287      * @param instanceId     an identifier for the current picker session
288      * @param callingUid     the uid of the app initiating the picker launch
289      * @param callingPackage the package name of the app initiating the picker launch
290      */
logPickerOpenWithFilterAllVideos(InstanceId instanceId, int callingUid, String callingPackage)291     public void logPickerOpenWithFilterAllVideos(InstanceId instanceId, int callingUid,
292             String callingPackage) {
293         logger.logWithInstanceId(
294                 PhotoPickerEvent.PHOTO_PICKER_FILTER_ALL_VIDEOS,
295                 callingUid,
296                 callingPackage,
297                 instanceId);
298     }
299 
300     /**
301      * Log metrics to notify that the picker has opened with a specific filter, other than the ones
302      * tracked explicitly
303      * @param instanceId     an identifier for the current picker session
304      * @param callingUid     the uid of the app initiating the picker launch
305      * @param callingPackage the package name of the app initiating the picker launch
306      */
logPickerOpenWithAnyOtherFilter(InstanceId instanceId, int callingUid, String callingPackage)307     public void logPickerOpenWithAnyOtherFilter(InstanceId instanceId, int callingUid,
308             String callingPackage) {
309         logger.logWithInstanceId(
310                 PhotoPickerEvent.PHOTO_PICKER_FILTER_OTHER,
311                 callingUid,
312                 callingPackage,
313                 instanceId);
314     }
315 
316     /**
317      * Log metrics to notify that user has clicked on "Browse..." in Photo picker overflow menu.
318      * This UI click even opens DocumentsUi.
319      */
logBrowseToDocumentsUi(InstanceId instanceId, int callingUid, String callingPackage)320     public void logBrowseToDocumentsUi(InstanceId instanceId, int callingUid,
321             String callingPackage) {
322         logger.logWithInstanceId(
323                 PhotoPickerEvent.PHOTO_PICKER_BROWSE_DOCUMENTSUI,
324                 callingUid,
325                 callingPackage,
326                 instanceId);
327     }
328 
329     /**
330      * Log metrics to notify that user has confirmed selection in personal profile
331      */
logPickerConfirmPersonal(InstanceId instanceId, int callingUid, String callingPackage, int countOfItemsConfirmed)332     public void logPickerConfirmPersonal(InstanceId instanceId, int callingUid,
333             String callingPackage, int countOfItemsConfirmed) {
334         logger.logWithInstanceIdAndPosition(
335                 PhotoPickerEvent.PHOTO_PICKER_CONFIRM_PERSONAL_PROFILE,
336                 callingUid,
337                 callingPackage,
338                 instanceId,
339                 countOfItemsConfirmed);
340     }
341 
342     /**
343      * Log metrics to notify that user has confirmed selection in work profile
344      */
logPickerConfirmWork(InstanceId instanceId, int callingUid, String callingPackage, int countOfItemsConfirmed)345     public void logPickerConfirmWork(InstanceId instanceId, int callingUid,
346             String callingPackage, int countOfItemsConfirmed) {
347         logger.logWithInstanceIdAndPosition(
348                 PhotoPickerEvent.PHOTO_PICKER_CONFIRM_WORK_PROFILE,
349                 callingUid,
350                 callingPackage,
351                 instanceId,
352                 countOfItemsConfirmed);
353     }
354 
355     /**
356      * Log metrics to notify that user has confirmed selection in unknown profile
357      */
logPickerConfirmUnknown(InstanceId instanceId, int callingUid, String callingPackage, int countOfItemsConfirmed)358     public void logPickerConfirmUnknown(InstanceId instanceId, int callingUid,
359             String callingPackage, int countOfItemsConfirmed) {
360         logger.logWithInstanceIdAndPosition(
361                 PhotoPickerEvent.PHOTO_PICKER_CONFIRM_UNKNOWN_PROFILE,
362                 callingUid,
363                 callingPackage,
364                 instanceId,
365                 countOfItemsConfirmed);
366     }
367 
368     /**
369      * Log metrics to notify that user has cancelled picker (without any selection) in personal
370      * profile
371      */
logPickerCancelPersonal(InstanceId instanceId, int callingUid, String callingPackage)372     public void logPickerCancelPersonal(InstanceId instanceId, int callingUid,
373             String callingPackage) {
374         logger.logWithInstanceId(
375                 PhotoPickerEvent.PHOTO_PICKER_CANCEL_PERSONAL_PROFILE,
376                 callingUid,
377                 callingPackage,
378                 instanceId);
379     }
380 
381     /**
382      * Log metrics to notify that user has cancelled picker (without any selection) in work
383      * profile
384      */
logPickerCancelWork(InstanceId instanceId, int callingUid, String callingPackage)385     public void logPickerCancelWork(InstanceId instanceId, int callingUid,
386             String callingPackage) {
387         logger.logWithInstanceId(
388                 PhotoPickerEvent.PHOTO_PICKER_CANCEL_WORK_PROFILE,
389                 callingUid,
390                 callingPackage,
391                 instanceId);
392     }
393 
394     /**
395      * Log metrics to notify that user has cancelled picker (without any selection) in unknown
396      * profile
397      */
logPickerCancelUnknown(InstanceId instanceId, int callingUid, String callingPackage)398     public void logPickerCancelUnknown(InstanceId instanceId, int callingUid,
399             String callingPackage) {
400         logger.logWithInstanceId(
401                 PhotoPickerEvent.PHOTO_PICKER_CANCEL_UNKNOWN_PROFILE,
402                 callingUid,
403                 callingPackage,
404                 instanceId);
405     }
406 
407     /**
408      * Log metrics to notify that the picker has opened with an active cloud provider
409      * @param instanceId           an identifier for the current picker session
410      * @param cloudProviderUid     the uid of the cloud provider app
411      * @param cloudProviderPackage the package name of the cloud provider app
412      */
logPickerOpenWithActiveCloudProvider(InstanceId instanceId, int cloudProviderUid, String cloudProviderPackage)413     public void logPickerOpenWithActiveCloudProvider(InstanceId instanceId, int cloudProviderUid,
414             String cloudProviderPackage) {
415         logger.logWithInstanceId(
416                 PhotoPickerEvent.PHOTO_PICKER_CLOUD_PROVIDER_ACTIVE,
417                 cloudProviderUid,
418                 cloudProviderPackage,
419                 instanceId);
420     }
421 
422     /**
423      * Log metrics to notify that the user has clicked the mute / unmute button in a video preview
424      * @param instanceId an identifier for the current picker session
425      */
logVideoPreviewMuteButtonClick(InstanceId instanceId)426     public void logVideoPreviewMuteButtonClick(InstanceId instanceId) {
427         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_VIDEO_PREVIEW_AUDIO_BUTTON_CLICK, instanceId);
428     }
429 
430     /**
431      * Log metrics to notify that the user has clicked the 'view selected' button
432      * @param instanceId        an identifier for the current picker session
433      * @param selectedItemCount the number of items selected for preview all
434      */
logPreviewAllSelected(InstanceId instanceId, int selectedItemCount)435     public void logPreviewAllSelected(InstanceId instanceId, int selectedItemCount) {
436         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_PREVIEW_ALL_SELECTED, instanceId,
437                 selectedItemCount);
438     }
439 
440     /**
441      * Log metrics to notify that the 'switch profile' button is visible & enabled
442      * @param instanceId an identifier for the current picker session
443      */
logProfileSwitchButtonEnabled(InstanceId instanceId)444     public void logProfileSwitchButtonEnabled(InstanceId instanceId) {
445         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_PROFILE_SWITCH_BUTTON_ENABLED, instanceId);
446     }
447 
448     /**
449      * Log metrics to notify that the 'switch profile menu' button is visible
450      * @param instanceId an identifier for the current picker session
451      */
logProfileSwitchMenuButtonVisible(InstanceId instanceId)452     public void logProfileSwitchMenuButtonVisible(InstanceId instanceId) {
453         logWithInstance(
454                 PhotoPickerEvent.PHOTO_PICKER_PROFILE_SWITCH_MENU_BUTTON_VISIBLE, instanceId);
455     }
456 
457     /**
458      * Log metrics to notify that the 'switch profile' button is visible but disabled
459      * @param instanceId an identifier for the current picker session
460      */
logProfileSwitchButtonDisabled(InstanceId instanceId)461     public void logProfileSwitchButtonDisabled(InstanceId instanceId) {
462         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_PROFILE_SWITCH_BUTTON_DISABLED, instanceId);
463     }
464 
465     /**
466      * Log metrics to notify that the user has clicked the 'switch profile' button
467      * @param instanceId an identifier for the current picker session
468      */
logProfileSwitchButtonClick(InstanceId instanceId)469     public void logProfileSwitchButtonClick(InstanceId instanceId) {
470         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_PROFILE_SWITCH_BUTTON_CLICK, instanceId);
471     }
472 
473     /**
474      * Log metrics to notify that the user has clicked the 'switch profile menu' button
475      * @param instanceId an identifier for the current picker session
476      */
logProfileSwitchMenuButtonClick(InstanceId instanceId)477     public void logProfileSwitchMenuButtonClick(InstanceId instanceId) {
478         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_PROFILE_SWITCH_MENU_BUTTON_CLICK, instanceId);
479     }
480 
481     /**
482      * Log metrics to notify that the user has cancelled the current session by swiping down
483      * @param instanceId an identifier for the current picker session
484      */
logSwipeDownExit(InstanceId instanceId)485     public void logSwipeDownExit(InstanceId instanceId) {
486         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_EXIT_SWIPE_DOWN, instanceId);
487     }
488 
489     /**
490      * Log metrics to notify that the user has made a back gesture
491      * @param instanceId          an identifier for the current picker session
492      * @param backStackEntryCount the number of fragment entries currently in the back stack
493      */
logBackGestureWithStackCount(InstanceId instanceId, int backStackEntryCount)494     public void logBackGestureWithStackCount(InstanceId instanceId, int backStackEntryCount) {
495         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_BACK_GESTURE, instanceId,
496                 backStackEntryCount);
497     }
498 
499     /**
500      * Log metrics to notify that the user has clicked the action bar home button
501      * @param instanceId          an identifier for the current picker session
502      * @param backStackEntryCount the number of fragment entries currently in the back stack
503      */
logActionBarHomeButtonClick(InstanceId instanceId, int backStackEntryCount)504     public void logActionBarHomeButtonClick(InstanceId instanceId, int backStackEntryCount) {
505         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_ACTION_BAR_HOME_BUTTON_CLICK,
506                 instanceId, backStackEntryCount);
507     }
508 
509     /**
510      * Log metrics to notify that the user has expanded from half screen to full
511      * @param instanceId an identifier for the current picker session
512      */
logExpandToFullScreen(InstanceId instanceId)513     public void logExpandToFullScreen(InstanceId instanceId) {
514         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_FROM_HALF_TO_FULL_SCREEN, instanceId);
515     }
516 
517     /**
518      * Log metrics to notify that the user has opened the photo picker menu
519      * @param instanceId an identifier for the current picker session
520      */
logMenuOpened(InstanceId instanceId)521     public void logMenuOpened(InstanceId instanceId) {
522         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_MENU, instanceId);
523     }
524 
525     /**
526      * Log metrics to notify that the user has switched to the photos tab
527      * @param instanceId an identifier for the current picker session
528      */
logSwitchToPhotosTab(InstanceId instanceId)529     public void logSwitchToPhotosTab(InstanceId instanceId) {
530         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_TAB_PHOTOS_OPEN, instanceId);
531     }
532 
533     /**
534      * Log metrics to notify that the user has switched to the albums tab
535      * @param instanceId an identifier for the current picker session
536      */
logSwitchToAlbumsTab(InstanceId instanceId)537     public void logSwitchToAlbumsTab(InstanceId instanceId) {
538         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_TAB_ALBUMS_OPEN, instanceId);
539     }
540 
541     /**
542      * Log metrics to notify that the user has opened the device favorites album
543      * @param instanceId an identifier for the current picker session
544      */
logFavoritesAlbumOpened(InstanceId instanceId)545     public void logFavoritesAlbumOpened(InstanceId instanceId) {
546         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_ALBUM_FAVORITES_OPEN, instanceId);
547     }
548 
549     /**
550      * Log metrics to notify that the user has opened the device camera album
551      * @param instanceId an identifier for the current picker session
552      */
logCameraAlbumOpened(InstanceId instanceId)553     public void logCameraAlbumOpened(InstanceId instanceId) {
554         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_ALBUM_CAMERA_OPEN, instanceId);
555     }
556 
557     /**
558      * Log metrics to notify that the user has opened the device downloads album
559      * @param instanceId an identifier for the current picker session
560      */
logDownloadsAlbumOpened(InstanceId instanceId)561     public void logDownloadsAlbumOpened(InstanceId instanceId) {
562         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_ALBUM_DOWNLOADS_OPEN, instanceId);
563     }
564 
565     /**
566      * Log metrics to notify that the user has opened the device screenshots album
567      * @param instanceId an identifier for the current picker session
568      */
logScreenshotsAlbumOpened(InstanceId instanceId)569     public void logScreenshotsAlbumOpened(InstanceId instanceId) {
570         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_ALBUM_SCREENSHOTS_OPEN, instanceId);
571     }
572 
573     /**
574      * Log metrics to notify that the user has opened the device videos album
575      * @param instanceId an identifier for the current picker session
576      */
logVideosAlbumOpened(InstanceId instanceId)577     public void logVideosAlbumOpened(InstanceId instanceId) {
578         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_ALBUM_VIDEOS_OPEN, instanceId);
579     }
580 
581     /**
582      * Log metrics to notify that the user has opened a cloud album
583      * @param instanceId an identifier for the current picker session
584      * @param position   the position of the album in the recycler view
585      */
logCloudAlbumOpened(InstanceId instanceId, int position)586     public void logCloudAlbumOpened(InstanceId instanceId, int position) {
587         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_ALBUM_FROM_CLOUD_OPEN, instanceId,
588                 position);
589     }
590 
591     /**
592      * Log metrics to notify that the user selected a media item in the main grid
593      * @param instanceId an identifier for the current picker session
594      * @param position   the position of the album in the recycler view
595      */
logSelectedMainGridItem(InstanceId instanceId, int position)596     public void logSelectedMainGridItem(InstanceId instanceId, int position) {
597         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_SELECTED_ITEM_MAIN_GRID,
598                 instanceId, position);
599     }
600 
601     /**
602      * Log metrics to notify that the user selected a media item in an album
603      * @param instanceId an identifier for the current picker session
604      * @param position   the position of the album in the recycler view
605      */
logSelectedAlbumItem(InstanceId instanceId, int position)606     public void logSelectedAlbumItem(InstanceId instanceId, int position) {
607         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_SELECTED_ITEM_ALBUM, instanceId,
608                 position);
609     }
610 
611     /**
612      * Log metrics to notify that the user has selected a cloud only media item
613      * @param instanceId an identifier for the current picker session
614      * @param position   the position of the album in the recycler view
615      */
logSelectedCloudOnlyItem(InstanceId instanceId, int position)616     public void logSelectedCloudOnlyItem(InstanceId instanceId, int position) {
617         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_SELECTED_ITEM_CLOUD_ONLY,
618                 instanceId, position);
619     }
620 
621     /**
622      * Log metrics to notify that the user has previewed an item in the main grid
623      * @param specialFormat the special format of the previewed item (used to identify special
624      *                      categories like motion photos)
625      * @param mimeType      the mime type of the previewed item
626      * @param instanceId    an identifier for the current picker session
627      * @param position      the position of the album in the recycler view
628      */
logPreviewedMainGridItem( int specialFormat, String mimeType, InstanceId instanceId, int position)629     public void logPreviewedMainGridItem(
630             int specialFormat, String mimeType, InstanceId instanceId, int position) {
631         logger.logWithInstanceIdAndPosition(PhotoPickerEvent.PHOTO_PICKER_PREVIEW_ITEM_MAIN_GRID,
632                 specialFormat, mimeType, instanceId, position);
633     }
634 
635     /**
636      * Log metrics to notify that the picker has loaded some media items in the main grid
637      * @param authority  the authority of the selected cloud provider, null if no non-local items
638      * @param instanceId an identifier for the current picker session
639      * @param count      the number of media items loaded
640      */
logLoadedMainGridMediaItems(String authority, InstanceId instanceId, int count)641     public void logLoadedMainGridMediaItems(String authority, InstanceId instanceId, int count) {
642         logger.logWithInstanceIdAndPosition(PhotoPickerEvent.PHOTO_PICKER_UI_LOADED_PHOTOS,
643                 /* uid */ 0, authority, instanceId, count);
644     }
645 
646     /**
647      * Log metrics to notify that the picker has loaded some albums
648      * @param authority  the authority of the selected cloud provider, null if no non-local albums
649      * @param instanceId an identifier for the current picker session
650      * @param count      the number of albums loaded
651      */
logLoadedAlbums(String authority, InstanceId instanceId, int count)652     public void logLoadedAlbums(String authority, InstanceId instanceId, int count) {
653         logger.logWithInstanceIdAndPosition(PhotoPickerEvent.PHOTO_PICKER_UI_LOADED_ALBUMS,
654                 /* uid */ 0, authority, instanceId, count);
655     }
656 
657     /**
658      * Log metrics to notify that the picker has loaded some media items in an album grid
659      * @param authority  the authority of the selected cloud provider, null if no non-local items
660      * @param instanceId an identifier for the current picker session
661      * @param count      the number of media items loaded
662      */
logLoadedAlbumGridMediaItems(String authority, InstanceId instanceId, int count)663     public void logLoadedAlbumGridMediaItems(String authority, InstanceId instanceId, int count) {
664         logger.logWithInstanceIdAndPosition(PhotoPickerEvent.PHOTO_PICKER_UI_LOADED_ALBUM_CONTENTS,
665                 /* uid */ 0, authority, instanceId, count);
666     }
667 
668     /**
669      * Log metrics to notify create surface controller triggered
670      * @param instanceId an identifier for the current picker session
671      * @param authority  the authority of the provider
672      */
logPickerCreateSurfaceControllerStart(InstanceId instanceId, String authority)673     public void logPickerCreateSurfaceControllerStart(InstanceId instanceId, String authority) {
674         logger.logWithInstanceId(PhotoPickerEvent.PHOTO_PICKER_CREATE_SURFACE_CONTROLLER_START,
675                 /* uid */ 0, authority, instanceId);
676     }
677 
678     /**
679      * Log metrics to notify create surface controller ended
680      * @param instanceId an identifier for the current picker session
681      * @param authority  the authority of the provider
682      */
logPickerCreateSurfaceControllerEnd(InstanceId instanceId, String authority)683     public void logPickerCreateSurfaceControllerEnd(InstanceId instanceId, String authority) {
684         logger.logWithInstanceId(PhotoPickerEvent.PHOTO_PICKER_CREATE_SURFACE_CONTROLLER_END,
685                 /* uid */ 0, authority, instanceId);
686     }
687 
688     /**
689      * Log metrics to notify that the picker has started preloading the selected media items
690      * @param instanceId an identifier for the current picker session
691      * @param count      the number of items to be preloaded
692      */
logPreloadingStarted(@onNull InstanceId instanceId, int count)693     public void logPreloadingStarted(@NonNull InstanceId instanceId, int count) {
694         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_PRELOADING_STARTED, instanceId,
695                 count);
696     }
697 
698     /**
699      * Log metrics to notify that the picker has finished preloading the selected media items
700      * @param instanceId an identifier for the current picker session
701      */
logPreloadingFinished(@onNull InstanceId instanceId)702     public void logPreloadingFinished(@NonNull InstanceId instanceId) {
703         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_PRELOADING_FINISHED, instanceId);
704     }
705 
706     /**
707      * Log metrics to notify that the user cancelled the selected media preloading
708      * @param instanceId an identifier for the current picker session
709      * @param count      the number of items pending to preload
710      */
logPreloadingCancelled(@onNull InstanceId instanceId, int count)711     public void logPreloadingCancelled(@NonNull InstanceId instanceId, int count) {
712         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_PRELOADING_CANCELLED, instanceId,
713                 count);
714     }
715 
716     /**
717      * Log metrics to notify that the selected media preloading failed for some items
718      * @param instanceId an identifier for the current picker session
719      * @param count      the number of items pending / failed to preload
720      */
logPreloadingFailed(@onNull InstanceId instanceId, int count)721     public void logPreloadingFailed(@NonNull InstanceId instanceId, int count) {
722         logWithInstanceAndPosition(PhotoPickerEvent.PHOTO_PICKER_PRELOADING_FAILED, instanceId,
723                 count);
724     }
725 
726     /**
727      * Log metrics to notify that the banner is added to display in the recycler view grids
728      * @param instanceId an identifier for the current picker session
729      * @param bannerName the name of the banner added,
730      *                   refer {@link com.android.providers.media.photopicker.ui.TabAdapter.Banner}
731      */
logBannerAdded(@onNull InstanceId instanceId, @NonNull String bannerName)732     public void logBannerAdded(@NonNull InstanceId instanceId, @NonNull String bannerName) {
733         logger.logWithInstanceId(PhotoPickerEvent.PHOTO_PICKER_BANNER_ADDED, /* uid= */ 0,
734                 bannerName, instanceId);
735     }
736 
737     /**
738      * Log metrics to notify that the banner is dismissed by the user
739      * @param instanceId an identifier for the current picker session
740      */
logBannerDismissed(@onNull InstanceId instanceId)741     public void logBannerDismissed(@NonNull InstanceId instanceId) {
742         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_BANNER_DISMISSED, instanceId);
743     }
744 
745     /**
746      * Log metrics to notify that the user clicked the banner action button
747      * @param instanceId an identifier for the current picker session
748      */
logBannerActionButtonClicked(@onNull InstanceId instanceId)749     public void logBannerActionButtonClicked(@NonNull InstanceId instanceId) {
750         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_BANNER_ACTION_BUTTON_CLICKED, instanceId);
751     }
752 
753     /**
754      * Log metrics to notify that the user clicked on the remaining part of the banner
755      * @param instanceId an identifier for the current picker session
756      */
logBannerClicked(@onNull InstanceId instanceId)757     public void logBannerClicked(@NonNull InstanceId instanceId) {
758         logWithInstance(PhotoPickerEvent.PHOTO_PICKER_BANNER_CLICKED, instanceId);
759     }
760 
logWithInstance(@onNull UiEventLogger.UiEventEnum event, InstanceId instance)761     private void logWithInstance(@NonNull UiEventLogger.UiEventEnum event, InstanceId instance) {
762         logger.logWithInstanceId(event, /* uid */ 0, /* packageName */ null, instance);
763     }
764 
logWithInstanceAndPosition(@onNull UiEventLogger.UiEventEnum event, @NonNull InstanceId instance, int position)765     private void logWithInstanceAndPosition(@NonNull UiEventLogger.UiEventEnum event,
766             @NonNull InstanceId instance, int position) {
767         logger.logWithInstanceIdAndPosition(event, /* uid= */ 0, /* packageName= */ null, instance,
768                 position);
769     }
770 }
771