Debian Codegraph @

libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipUiEventLogger.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2020 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.pip;
18
19 import android.app.TaskInfo;
20 import android.content.pm.PackageManager;
21
22 import com.android.internal.logging.UiEvent;
23 import com.android.internal.logging.UiEventLogger;
24
25 /**
26 * Helper class that ends PiP log to UiEvent, see also go/uievent
27 */
28 public class PipUiEventLogger {
29
30 private static final int INVALID_PACKAGE_UID = -1;
31
32 private final UiEventLogger mUiEventLogger;
33 private final PackageManager mPackageManager;
34
35 private String mPackageName;
36 private int mPackageUid = INVALID_PACKAGE_UID;
37
38 public PipUiEventLogger(UiEventLogger uiEventLogger, PackageManager packageManager) {
39 mUiEventLogger = uiEventLogger;
40 mPackageManager = packageManager;
41 }
42
43 public void setTaskInfo(TaskInfo taskInfo) {
44 if (taskInfo != null && taskInfo.topActivity != null) {
45 mPackageName = taskInfo.topActivity.getPackageName();
46 mPackageUid = getUid(mPackageName, taskInfo.userId);
47 } else {
48 mPackageName = null;
49 mPackageUid = INVALID_PACKAGE_UID;
50 }
51 }
52
53 /**
54 * Sends log via UiEvent, reference go/uievent for how to debug locally
55 */
56 public void log(PipUiEventEnum event) {
57 if (mPackageName == null || mPackageUid == INVALID_PACKAGE_UID) {
58 return;
59 }
60 mUiEventLogger.log(event, mPackageUid, mPackageName);
61 }
62
63 private int getUid(String packageName, int userId) {
64 int uid = INVALID_PACKAGE_UID;
65 try {
66 uid = mPackageManager.getApplicationInfoAsUser(
67 packageName, 0 /* ApplicationInfoFlags */, userId).uid;
68 } catch (PackageManager.NameNotFoundException e) {
69 // do nothing.
70 }
71 return uid;
72 }
73
74 /**
75 * Enums for logging the PiP events to UiEvent
76 */
77 public enum PipUiEventEnum implements UiEventLogger.UiEventEnum {
78 @UiEvent(doc = "Activity enters picture-in-picture mode")
79 PICTURE_IN_PICTURE_ENTER(603),
80
81 @UiEvent(doc = "Expands from picture-in-picture to fullscreen")
82 PICTURE_IN_PICTURE_EXPAND_TO_FULLSCREEN(604),
83
84 @UiEvent(doc = "Removes picture-in-picture by tap close button")
85 PICTURE_IN_PICTURE_TAP_TO_REMOVE(605),
86
87 @UiEvent(doc = "Removes picture-in-picture by drag to dismiss area")
88 PICTURE_IN_PICTURE_DRAG_TO_REMOVE(606),
89
90 @UiEvent(doc = "Shows picture-in-picture menu")
91 PICTURE_IN_PICTURE_SHOW_MENU(607),
92
93 @UiEvent(doc = "Hides picture-in-picture menu")
94 PICTURE_IN_PICTURE_HIDE_MENU(608),
95
96 @UiEvent(doc = "Changes the aspect ratio of picture-in-picture window. This is inherited"
97 + " from previous Tron-based logging and currently not in use.")
98 PICTURE_IN_PICTURE_CHANGE_ASPECT_RATIO(609),
99
100 @UiEvent(doc = "User resize of the picture-in-picture window")
101 PICTURE_IN_PICTURE_RESIZE(610),
102
103 @UiEvent(doc = "User unstashed picture-in-picture")
104 PICTURE_IN_PICTURE_STASH_UNSTASHED(709),
105
106 @UiEvent(doc = "User stashed picture-in-picture to the left side")
107 PICTURE_IN_PICTURE_STASH_LEFT(710),
108
109 @UiEvent(doc = "User stashed picture-in-picture to the right side")
110 PICTURE_IN_PICTURE_STASH_RIGHT(711),
111
112 @UiEvent(doc = "User taps on the settings button in PiP menu")
113 PICTURE_IN_PICTURE_SHOW_SETTINGS(933),
114
115 @UiEvent(doc = "Closes PiP with app-provided close action")
116 PICTURE_IN_PICTURE_CUSTOM_CLOSE(1058);
117
118 private final int mId;
119
120 PipUiEventEnum(int id) {
121 mId = id;
122 }
123
124 @Override
125 public int getId() {
126 return mId;
127 }
128 }
129 }