• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.wm.shell.desktopmode
18 
19 import android.app.ActivityManager.RunningTaskInfo
20 import android.content.pm.PackageManager
21 import com.android.internal.logging.InstanceId
22 import com.android.internal.logging.InstanceIdSequence
23 import com.android.internal.logging.UiEvent
24 import com.android.internal.logging.UiEventLogger
25 import com.android.internal.logging.UiEventLogger.UiEventEnum
26 import com.android.internal.protolog.ProtoLog
27 import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL_DESKTOP_MODE
28 
29 /** Log Aster UIEvents for desktop windowing mode. */
30 class DesktopModeUiEventLogger(
31     private val uiEventLogger: UiEventLogger,
32     private val packageManager: PackageManager,
33 ) {
34     private val instanceIdSequence = InstanceIdSequence(Integer.MAX_VALUE)
35 
36     /**
37      * Logs an event for a CUI, on a particular package.
38      *
39      * @param uid The user id associated with the package the user is interacting with
40      * @param packageName The name of the package the user is interacting with
41      * @param event The event type to generate
42      */
lognull43     fun log(uid: Int, packageName: String, event: DesktopUiEventEnum) {
44         if (packageName.isEmpty() || uid < 0) {
45             logD("Skip logging since package name is empty or bad uid")
46             return
47         }
48         uiEventLogger.log(event, uid, packageName)
49     }
50 
51     /** Logs an event for a CUI on a particular task. */
lognull52     fun log(taskInfo: RunningTaskInfo, event: DesktopUiEventEnum) {
53         val packageName = taskInfo.baseActivity?.packageName
54         if (packageName == null) {
55             logD("Skip logging due to null base activity")
56             return
57         }
58         val uid = getUid(packageName, taskInfo.userId)
59         log(uid, packageName, event)
60     }
61 
62     /** Retrieves a new instance id for a new interaction. */
getNewInstanceIdnull63     fun getNewInstanceId(): InstanceId = instanceIdSequence.newInstanceId()
64 
65     /**
66      * Logs an event as part of a particular CUI, on a particular package.
67      *
68      * @param instanceId The id identifying an interaction, potentially taking place across multiple
69      *   surfaces. There should be a new id generated for each distinct CUI.
70      * @param uid The user id associated with the package the user is interacting with
71      * @param packageName The name of the package the user is interacting with
72      * @param event The event type to generate
73      */
74     fun logWithInstanceId(
75         instanceId: InstanceId,
76         uid: Int,
77         packageName: String,
78         event: DesktopUiEventEnum,
79     ) {
80         if (packageName.isEmpty() || uid < 0) {
81             logD("Skip logging since package name is empty or bad uid")
82             return
83         }
84         uiEventLogger.logWithInstanceId(event, uid, packageName, instanceId)
85     }
86 
getUidnull87     private fun getUid(packageName: String, userId: Int): Int =
88         try {
89             packageManager.getApplicationInfoAsUser(packageName, /* flags= */ 0, userId).uid
90         } catch (e: PackageManager.NameNotFoundException) {
91             INVALID_PACKAGE_UID
92         }
93 
logDnull94     private fun logD(msg: String, vararg arguments: Any?) {
95         ProtoLog.d(WM_SHELL_DESKTOP_MODE, "%s: $msg", TAG, *arguments)
96     }
97 
98     /** Enums for logging desktop windowing mode UiEvents. */
99     enum class DesktopUiEventEnum(private val mId: Int) : UiEventEnum {
100 
101         @UiEvent(doc = "Resize the window in desktop windowing mode by dragging the edge")
102         DESKTOP_WINDOW_EDGE_DRAG_RESIZE(1721),
103         @UiEvent(doc = "Resize the window in desktop windowing mode by dragging the corner")
104         DESKTOP_WINDOW_CORNER_DRAG_RESIZE(1722),
105         @UiEvent(doc = "Tap on the window header maximize button in desktop windowing mode")
106         DESKTOP_WINDOW_MAXIMIZE_BUTTON_TAP(1723),
107         @UiEvent(doc = "Tap on the window header restore button in desktop windowing mode")
108         DESKTOP_WINDOW_RESTORE_BUTTON_TAP(2017),
109         @UiEvent(doc = "Double tap on window header to maximize it in desktop windowing mode")
110         DESKTOP_WINDOW_HEADER_DOUBLE_TAP_TO_MAXIMIZE(1724),
111         @UiEvent(doc = "Double tap on window header to restore from maximize in desktop windowing")
112         DESKTOP_WINDOW_HEADER_DOUBLE_TAP_TO_RESTORE(2018),
113         @UiEvent(doc = "Tap on the window Handle to open the Handle Menu")
114         DESKTOP_WINDOW_APP_HANDLE_TAP(1998),
115         @UiEvent(doc = "Tap on the desktop mode option under app handle menu")
116         DESKTOP_WINDOW_APP_HANDLE_MENU_TAP_TO_DESKTOP_MODE(1999),
117         @UiEvent(doc = "Tap on the split screen option under app handle menu")
118         DESKTOP_WINDOW_APP_HANDLE_MENU_TAP_TO_SPLIT_SCREEN(2000),
119         @UiEvent(doc = "Tap on the full screen option under app handle menu")
120         DESKTOP_WINDOW_APP_HANDLE_MENU_TAP_TO_FULL_SCREEN(2001),
121         @UiEvent(doc = "When user successfully drags the app handle to desktop mode")
122         DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_DESKTOP_MODE(2002),
123         @UiEvent(doc = "When user successfully drags the app handle to split screen")
124         DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_SPLIT_SCREEN(2003),
125         @UiEvent(doc = "When user successfully drags the app handle to full screen")
126         DESKTOP_WINDOW_APP_HANDLE_DRAG_TO_FULL_SCREEN(2004),
127         @UiEvent(doc = "Drag the window header to the top to switch to full screen mode")
128         DESKTOP_WINDOW_APP_HEADER_DRAG_TO_FULL_SCREEN(2005),
129         @UiEvent(doc = "Drag the window header to an edge to tile it to the left side")
130         DESKTOP_WINDOW_APP_HEADER_DRAG_TO_TILE_TO_LEFT(2006),
131         @UiEvent(doc = "Drag the window header to an edge to tile it to the right side")
132         DESKTOP_WINDOW_APP_HEADER_DRAG_TO_TILE_TO_RIGHT(2007),
133         @UiEvent(doc = "Hover or long press the maximize button to reveal the menu")
134         DESKTOP_WINDOW_MAXIMIZE_BUTTON_REVEAL_MENU(2015),
135         @UiEvent(doc = "Tap on the maximize option in the maximize button menu")
136         DESKTOP_WINDOW_MAXIMIZE_BUTTON_MENU_TAP_TO_MAXIMIZE(2009),
137         @UiEvent(doc = "Tap on the immersive option in the maximize button menu")
138         DESKTOP_WINDOW_MAXIMIZE_BUTTON_MENU_TAP_TO_IMMERSIVE(2010),
139         @UiEvent(doc = "Tap on the restore option in the maximize button menu")
140         DESKTOP_WINDOW_MAXIMIZE_BUTTON_MENU_TAP_TO_RESTORE(2011),
141         @UiEvent(doc = "Tap on the tile to left option in the maximize button menu")
142         DESKTOP_WINDOW_MAXIMIZE_BUTTON_MENU_TAP_TO_TILE_TO_LEFT(2012),
143         @UiEvent(doc = "Tap on the tile to right option in the maximize button menu")
144         DESKTOP_WINDOW_MAXIMIZE_BUTTON_MENU_TAP_TO_TILE_TO_RIGHT(2013),
145         @UiEvent(doc = "Moving the desktop window by dragging the header")
146         DESKTOP_WINDOW_MOVE_BY_HEADER_DRAG(2021),
147         @UiEvent(doc = "Double tap on the window header to refocus a desktop window")
148         DESKTOP_WINDOW_HEADER_TAP_TO_REFOCUS(2022),
149         @UiEvent(doc = "Enter multi-instance by using the New Window button")
150         DESKTOP_WINDOW_MULTI_INSTANCE_NEW_WINDOW_CLICK(2069),
151         @UiEvent(doc = "Enter multi-instance by clicking an icon in the Manage Windows menu")
152         DESKTOP_WINDOW_MULTI_INSTANCE_MANAGE_WINDOWS_ICON_CLICK(2070),
153         @UiEvent(doc = "Education tooltip on the app handle is shown")
154         APP_HANDLE_EDUCATION_TOOLTIP_SHOWN(2097),
155         @UiEvent(doc = "Education tooltip on the app handle is clicked")
156         APP_HANDLE_EDUCATION_TOOLTIP_CLICKED(2098),
157         @UiEvent(doc = "Education tooltip on the app handle is dismissed by the user")
158         APP_HANDLE_EDUCATION_TOOLTIP_DISMISSED(2099),
159         @UiEvent(doc = "Enter desktop mode education tooltip on the app handle menu is shown")
160         ENTER_DESKTOP_MODE_EDUCATION_TOOLTIP_SHOWN(2100),
161         @UiEvent(doc = "Enter desktop mode education tooltip on the app handle menu is clicked")
162         ENTER_DESKTOP_MODE_EDUCATION_TOOLTIP_CLICKED(2101),
163         @UiEvent(doc = "Enter desktop mode education tooltip is dismissed by the user")
164         ENTER_DESKTOP_MODE_EDUCATION_TOOLTIP_DISMISSED(2102),
165         @UiEvent(doc = "Exit desktop mode education tooltip on the app header menu is shown")
166         EXIT_DESKTOP_MODE_EDUCATION_TOOLTIP_SHOWN(2103),
167         @UiEvent(doc = "Exit desktop mode education tooltip on the app header menu is clicked")
168         EXIT_DESKTOP_MODE_EDUCATION_TOOLTIP_CLICKED(2104),
169         @UiEvent(doc = "Exit desktop mode education tooltip is dismissed by the user")
170         EXIT_DESKTOP_MODE_EDUCATION_TOOLTIP_DISMISSED(2105),
171         @UiEvent(doc = "A11y service opened app handle menu by selecting handle from fullscreen")
172         A11Y_APP_HANDLE_MENU_OPENED(2156),
173         @UiEvent(doc = "A11y service opened app handle menu through Switch Access actions menu ")
174         A11Y_SYSTEM_ACTION_APP_HANDLE_MENU(2157),
175         @UiEvent(doc = "A11y service selected desktop mode from app handle menu")
176         A11Y_APP_HANDLE_MENU_DESKTOP_VIEW(2158),
177         @UiEvent(doc = "A11y service selected fullscreen mode from app handle menu")
178         A11Y_APP_HANDLE_MENU_FULLSCREEN(2159),
179         @UiEvent(doc = "A11y service selected split screen mode from app handle menu")
180         A11Y_APP_HANDLE_MENU_SPLIT_SCREEN(2160),
181         @UiEvent(doc = "A11y service selected maximize/restore button from app header")
182         A11Y_APP_WINDOW_MAXIMIZE_RESTORE_BUTTON(2161),
183         @UiEvent(doc = "A11y service selected minimize button from app header")
184         A11Y_APP_WINDOW_MINIMIZE_BUTTON(2162),
185         @UiEvent(doc = "A11y service selected close button from app header")
186         A11Y_APP_WINDOW_CLOSE_BUTTON(2163),
187         @UiEvent(doc = "A11y service selected maximize button from app header maximize menu")
188         A11Y_MAXIMIZE_MENU_MAXIMIZE(2164),
189         @UiEvent(doc = "A11y service selected resize left button from app header maximize menu")
190         A11Y_MAXIMIZE_MENU_RESIZE_LEFT(2165),
191         @UiEvent(doc = "A11y service selected resize right button from app header maximize menu")
192         A11Y_MAXIMIZE_MENU_RESIZE_RIGHT(2166),
193         @UiEvent(doc = "A11y service triggered a11y action to maximize/restore app window")
194         A11Y_ACTION_MAXIMIZE_RESTORE(2167),
195         @UiEvent(doc = "A11y service triggered a11y action to resize app window left")
196         A11Y_ACTION_RESIZE_LEFT(2168),
197         @UiEvent(doc = "A11y service triggered a11y action to resize app window right")
198         A11Y_ACTION_RESIZE_RIGHT(2169);
199 
getIdnull200         override fun getId(): Int = mId
201     }
202 
203     companion object {
204         private const val TAG = "DesktopModeUiEventLogger"
205         private const val INVALID_PACKAGE_UID = -1
206     }
207 }
208