• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.systemui.notetask
17 
18 import com.android.internal.logging.UiEvent
19 import com.android.internal.logging.UiEventLogger
20 import com.android.systemui.notetask.NoteTaskEntryPoint.APP_CLIPS
21 import com.android.systemui.notetask.NoteTaskEntryPoint.KEYBOARD_SHORTCUT
22 import com.android.systemui.notetask.NoteTaskEntryPoint.QS_NOTES_TILE
23 import com.android.systemui.notetask.NoteTaskEntryPoint.QUICK_AFFORDANCE
24 import com.android.systemui.notetask.NoteTaskEntryPoint.TAIL_BUTTON
25 import com.android.systemui.notetask.NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT
26 import com.android.systemui.notetask.NoteTaskEntryPoint.WIDGET_PICKER_SHORTCUT_IN_MULTI_WINDOW_MODE
27 import com.android.systemui.notetask.NoteTaskEventLogger.NoteTaskUiEvent
28 import com.android.systemui.notetask.NoteTaskEventLogger.NoteTaskUiEvent.NOTE_OPENED_VIA_KEYGUARD_QUICK_AFFORDANCE
29 import com.android.systemui.notetask.NoteTaskEventLogger.NoteTaskUiEvent.NOTE_OPENED_VIA_SHORTCUT
30 import com.android.systemui.notetask.NoteTaskEventLogger.NoteTaskUiEvent.NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON
31 import com.android.systemui.notetask.NoteTaskEventLogger.NoteTaskUiEvent.NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON_LOCKED
32 import javax.inject.Inject
33 
34 /**
35  * A wrapper around [UiEventLogger] specialized in the note taking UI events.
36  *
37  * if the accepted [NoteTaskInfo] contains a [NoteTaskInfo.entryPoint], it will be logged as the
38  * correct [NoteTaskUiEvent]. If null, it will be ignored.
39  *
40  * @see NoteTaskController for usage examples.
41  */
42 class NoteTaskEventLogger @Inject constructor(private val uiEventLogger: UiEventLogger) {
43 
44     /** Logs a [NoteTaskInfo] as an **open** [NoteTaskUiEvent], including package name and uid. */
logNoteTaskOpenednull45     fun logNoteTaskOpened(info: NoteTaskInfo) {
46         val event =
47             when (info.entryPoint) {
48                 TAIL_BUTTON -> {
49                     if (info.isKeyguardLocked) {
50                         NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON_LOCKED
51                     } else {
52                         NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON
53                     }
54                 }
55 
56                 WIDGET_PICKER_SHORTCUT,
57                 WIDGET_PICKER_SHORTCUT_IN_MULTI_WINDOW_MODE -> NOTE_OPENED_VIA_SHORTCUT
58 
59                 QUICK_AFFORDANCE -> NOTE_OPENED_VIA_KEYGUARD_QUICK_AFFORDANCE
60                 APP_CLIPS,
61                 KEYBOARD_SHORTCUT,
62                 QS_NOTES_TILE,  // TODO(b/376640872): Add logging for QS Tile entry point.
63                 null -> return
64             }
65         uiEventLogger.log(event, info.uid, info.packageName)
66     }
67 
68     /** Logs a [NoteTaskInfo] as a **closed** [NoteTaskUiEvent], including package name and uid. */
logNoteTaskClosednull69     fun logNoteTaskClosed(info: NoteTaskInfo) {
70         val event =
71             when (info.entryPoint) {
72                 TAIL_BUTTON -> {
73                     if (info.isKeyguardLocked) {
74                         NoteTaskUiEvent.NOTE_CLOSED_VIA_STYLUS_TAIL_BUTTON_LOCKED
75                     } else {
76                         NoteTaskUiEvent.NOTE_CLOSED_VIA_STYLUS_TAIL_BUTTON
77                     }
78                 }
79 
80                 WIDGET_PICKER_SHORTCUT,
81                 WIDGET_PICKER_SHORTCUT_IN_MULTI_WINDOW_MODE,
82                 QUICK_AFFORDANCE,
83                 APP_CLIPS,
84                 KEYBOARD_SHORTCUT,
85                 QS_NOTES_TILE,
86                 null -> return
87             }
88         uiEventLogger.log(event, info.uid, info.packageName)
89     }
90 
91     /** IDs of UI events accepted by [NoteTaskController]. */
92     enum class NoteTaskUiEvent(private val _id: Int) : UiEventLogger.UiEventEnum {
93 
94         @UiEvent(doc = "User opened a note by tapping on the lockscreen shortcut.")
95         NOTE_OPENED_VIA_KEYGUARD_QUICK_AFFORDANCE(1294),
96         @UiEvent(
97             doc =
98                 "User opened a note by pressing the stylus tail button while the screen was unlocked."
99         )
100         NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON(1295),
101         @UiEvent(
102             doc =
103                 "User opened a note by pressing the stylus tail button while the screen was locked."
104         )
105         NOTE_OPENED_VIA_STYLUS_TAIL_BUTTON_LOCKED(1296),
106         @UiEvent(doc = "User opened a note by tapping on an app shortcut.")
107         NOTE_OPENED_VIA_SHORTCUT(1297),
108         @UiEvent(doc = "Note closed via a tail button while device is unlocked")
109         NOTE_CLOSED_VIA_STYLUS_TAIL_BUTTON(1311),
110         @UiEvent(doc = "Note closed via a tail button while device is locked")
111         NOTE_CLOSED_VIA_STYLUS_TAIL_BUTTON_LOCKED(1312);
112 
getIdnull113         override fun getId() = _id
114     }
115 }
116