• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
PipUiEventLogger(UiEventLogger uiEventLogger, PackageManager packageManager)38     public PipUiEventLogger(UiEventLogger uiEventLogger, PackageManager packageManager) {
39         mUiEventLogger = uiEventLogger;
40         mPackageManager = packageManager;
41     }
42 
setTaskInfo(TaskInfo taskInfo)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      */
log(PipUiEventEnum event)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 
getUid(String packageName, int userId)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         private final int mId;
113 
PipUiEventEnum(int id)114         PipUiEventEnum(int id) {
115             mId = id;
116         }
117 
118         @Override
getId()119         public int getId() {
120             return mId;
121         }
122     }
123 }
124