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