• 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.bubbles;
18 
19 import com.android.internal.logging.UiEvent;
20 import com.android.internal.logging.UiEventLogger;
21 import com.android.internal.util.FrameworkStatsLog;
22 
23 import javax.inject.Inject;
24 
25 /**
26  * Implementation of UiEventLogger for logging bubble UI events.
27  *
28  * See UiEventReported atom in atoms.proto for more context.
29  */
30 public class BubbleLogger {
31 
32     private final UiEventLogger mUiEventLogger;
33 
34     /**
35      * Bubble UI event.
36      */
37     public enum Event implements UiEventLogger.UiEventEnum {
38 
39         // region bubble events
40 
41         @UiEvent(doc = "User dismissed the bubble via gesture, add bubble to overflow.")
42         BUBBLE_OVERFLOW_ADD_USER_GESTURE(483),
43 
44         @UiEvent(doc = "No more space in top row, add bubble to overflow.")
45         BUBBLE_OVERFLOW_ADD_AGED(484),
46 
47         @UiEvent(doc = "No more space in overflow, remove bubble from overflow")
48         BUBBLE_OVERFLOW_REMOVE_MAX_REACHED(485),
49 
50         @UiEvent(doc = "Notification canceled, remove bubble from overflow.")
51         BUBBLE_OVERFLOW_REMOVE_CANCEL(486),
52 
53         @UiEvent(doc = "Notification group canceled, remove bubble for child notif from overflow.")
54         BUBBLE_OVERFLOW_REMOVE_GROUP_CANCEL(487),
55 
56         @UiEvent(doc = "Notification no longer bubble, remove bubble from overflow.")
57         BUBBLE_OVERFLOW_REMOVE_NO_LONGER_BUBBLE(488),
58 
59         @UiEvent(doc = "User tapped overflow bubble. Promote bubble back to top row.")
60         BUBBLE_OVERFLOW_REMOVE_BACK_TO_STACK(489),
61 
62         @UiEvent(doc = "User blocked notification from bubbling, remove bubble from overflow.")
63         BUBBLE_OVERFLOW_REMOVE_BLOCKED(490),
64 
65         @UiEvent(doc = "User selected the overflow.")
66         BUBBLE_OVERFLOW_SELECTED(600),
67 
68         @UiEvent(doc = "Restore bubble to overflow after phone reboot.")
69         BUBBLE_OVERFLOW_RECOVER(691),
70 
71         // endregion
72 
73         // region bubble bar events
74 
75         @UiEvent(doc = "new bubble posted")
76         BUBBLE_BAR_BUBBLE_POSTED(1927),
77 
78         @UiEvent(doc = "existing bubble updated")
79         BUBBLE_BAR_BUBBLE_UPDATED(1928),
80 
81         @UiEvent(doc = "expanded a bubble from bubble bar")
82         BUBBLE_BAR_EXPANDED(1929),
83 
84         @UiEvent(doc = "bubble bar collapsed")
85         BUBBLE_BAR_COLLAPSED(1930),
86 
87         @UiEvent(doc = "dismissed single bubble from bubble bar by dragging it to dismiss target")
88         BUBBLE_BAR_BUBBLE_DISMISSED_DRAG_BUBBLE(1931),
89 
90         @UiEvent(doc = "dismissed single bubble from bubble bar by dragging the expanded view to "
91                 + "dismiss target")
92         BUBBLE_BAR_BUBBLE_DISMISSED_DRAG_EXP_VIEW(1932),
93 
94         @UiEvent(doc = "dismiss bubble from app handle menu")
95         BUBBLE_BAR_BUBBLE_DISMISSED_APP_MENU(1933),
96 
97         @UiEvent(doc = "bubble is dismissed due to app finishing the bubble activity")
98         BUBBLE_BAR_BUBBLE_ACTIVITY_FINISH(1934),
99 
100         @UiEvent(doc = "dismissed the bubble bar by dragging it to dismiss target")
101         BUBBLE_BAR_DISMISSED_DRAG_BAR(1935),
102 
103         @UiEvent(doc = "bubble bar moved to the left edge of the screen by dragging from the "
104                 + "expanded view")
105         BUBBLE_BAR_MOVED_LEFT_DRAG_EXP_VIEW(1936),
106 
107         @UiEvent(doc = "bubble bar moved to the left edge of the screen by dragging from a single"
108                 + " bubble")
109         BUBBLE_BAR_MOVED_LEFT_DRAG_BUBBLE(1937),
110 
111         @UiEvent(doc = "bubble bar moved to the left edge of the screen by dragging the bubble bar")
112         BUBBLE_BAR_MOVED_LEFT_DRAG_BAR(1938),
113 
114         @UiEvent(doc = "bubble bar moved to the right edge of the screen by dragging from the "
115                 + "expanded view")
116         BUBBLE_BAR_MOVED_RIGHT_DRAG_EXP_VIEW(1939),
117 
118         @UiEvent(doc = "bubble bar moved to the right edge of the screen by dragging from a "
119                 + "single bubble")
120         BUBBLE_BAR_MOVED_RIGHT_DRAG_BUBBLE(1940),
121 
122         @UiEvent(doc = "bubble bar moved to the right edge of the screen by dragging the bubble "
123                 + "bar")
124         BUBBLE_BAR_MOVED_RIGHT_DRAG_BAR(1941),
125 
126         @UiEvent(doc = "stop bubbling conversation from app handle menu")
127         BUBBLE_BAR_APP_MENU_OPT_OUT(1942),
128 
129         @UiEvent(doc = "open app settings from app handle menu")
130         BUBBLE_BAR_APP_MENU_GO_TO_SETTINGS(1943),
131 
132         @UiEvent(doc = "flyout shown for a bubble")
133         BUBBLE_BAR_FLYOUT(1944),
134 
135         @UiEvent(doc = "notification for the bubble was canceled")
136         BUBBLE_BAR_BUBBLE_REMOVED_CANCELED(1945),
137 
138         @UiEvent(doc = "user turned off bubbles from settings")
139         BUBBLE_BAR_BUBBLE_REMOVED_BLOCKED(1946),
140 
141         @UiEvent(doc = "bubble bar overflow opened")
142         BUBBLE_BAR_OVERFLOW_SELECTED(1947),
143 
144         @UiEvent(doc = "max number of bubbles was reached in bubble bar, move bubble to overflow")
145         BUBBLE_BAR_OVERFLOW_ADD_AGED(1948),
146 
147         @UiEvent(doc = "bubble promoted from overflow back to bubble bar")
148         BUBBLE_BAR_OVERFLOW_REMOVE_BACK_TO_BAR(1949),
149 
150         @UiEvent(doc = "application icon is dropped in the BubbleBar left drop zone")
151         BUBBLE_BAR_MOVED_LEFT_APP_ICON_DROP(2082),
152 
153         @UiEvent(doc = "application icon is dropped in the BubbleBar right drop zone")
154         BUBBLE_BAR_MOVED_RIGHT_APP_ICON_DROP(2083),
155 
156         @UiEvent(doc = "while bubble bar is expanded, switch to another/existing bubble")
157         BUBBLE_BAR_BUBBLE_SWITCHED(1977),
158 
159         @UiEvent(doc = "bubble bar moved to the left edge of the screen by dragging a task")
160         BUBBLE_BAR_MOVED_LEFT_DRAG_TASK(2146),
161 
162         @UiEvent(doc = "bubble bar moved to the right edge of the screen by dragging a task")
163         BUBBLE_BAR_MOVED_RIGHT_DRAG_TASK(2147),
164 
165         // endregion
166         ;
167 
168         private final int mId;
169 
Event(int id)170         Event(int id) {
171             mId = id;
172         }
173 
174         @Override
getId()175         public int getId() {
176             return mId;
177         }
178     }
179 
180     @Inject
BubbleLogger(UiEventLogger uiEventLogger)181     public BubbleLogger(UiEventLogger uiEventLogger) {
182         mUiEventLogger = uiEventLogger;
183     }
184 
185     /**
186      * Log an UIEvent
187      */
log(UiEventLogger.UiEventEnum e)188     public void log(UiEventLogger.UiEventEnum e) {
189         mUiEventLogger.log(e);
190     }
191 
192     /**
193      * Log an UIEvent with the given bubble info
194      */
log(Bubble b, UiEventLogger.UiEventEnum e)195     public void log(Bubble b, UiEventLogger.UiEventEnum e) {
196         mUiEventLogger.logWithInstanceId(e, b.getAppUid(), b.getPackageName(), b.getInstanceId());
197     }
198 
199     /**
200      * Log when a bubble is removed from overflow in stack view
201      *
202      * @param b Bubble removed from overflow
203      * @param r Reason that bubble was removed
204      */
logStackOverflowRemove(Bubble b, @Bubbles.DismissReason int r)205     public void logStackOverflowRemove(Bubble b, @Bubbles.DismissReason int r) {
206         if (r == Bubbles.DISMISS_NOTIF_CANCEL) {
207             log(b, BubbleLogger.Event.BUBBLE_OVERFLOW_REMOVE_CANCEL);
208         } else if (r == Bubbles.DISMISS_GROUP_CANCELLED) {
209             log(b, BubbleLogger.Event.BUBBLE_OVERFLOW_REMOVE_GROUP_CANCEL);
210         } else if (r == Bubbles.DISMISS_NO_LONGER_BUBBLE) {
211             log(b, BubbleLogger.Event.BUBBLE_OVERFLOW_REMOVE_NO_LONGER_BUBBLE);
212         } else if (r == Bubbles.DISMISS_BLOCKED) {
213             log(b, BubbleLogger.Event.BUBBLE_OVERFLOW_REMOVE_BLOCKED);
214         }
215     }
216 
217     /**
218      * @param b Bubble added to overflow
219      * @param r Reason that bubble was added to overflow
220      */
logOverflowAdd(Bubble b, boolean bubbleBar, @Bubbles.DismissReason int r)221     public void logOverflowAdd(Bubble b, boolean bubbleBar, @Bubbles.DismissReason int r) {
222         if (bubbleBar) {
223             if (r == Bubbles.DISMISS_AGED) {
224                 log(b, Event.BUBBLE_BAR_OVERFLOW_ADD_AGED);
225             }
226         } else {
227             if (r == Bubbles.DISMISS_AGED) {
228                 log(b, Event.BUBBLE_OVERFLOW_ADD_AGED);
229             } else if (r == Bubbles.DISMISS_USER_GESTURE) {
230                 log(b, Event.BUBBLE_OVERFLOW_ADD_USER_GESTURE);
231             } else if (r == Bubbles.DISMISS_RELOAD_FROM_DISK) {
232                 log(b, Event.BUBBLE_OVERFLOW_RECOVER);
233             }
234         }
235     }
236 
logStackUiChanged(String packageName, int action, int bubbleCount, float normalX, float normalY)237     void logStackUiChanged(String packageName, int action, int bubbleCount, float normalX,
238             float normalY) {
239         FrameworkStatsLog.write(FrameworkStatsLog.BUBBLE_UI_CHANGED,
240                 packageName,
241                 null /* notification channel */,
242                 0 /* notification ID */,
243                 0 /* bubble position */,
244                 bubbleCount,
245                 action,
246                 normalX,
247                 normalY,
248                 false /* unread bubble */,
249                 false /* on-going bubble */,
250                 false /* isAppForeground (unused) */);
251     }
252 
logShowOverflow(String packageName, int currentUserId)253     void logShowOverflow(String packageName, int currentUserId) {
254         mUiEventLogger.log(BubbleLogger.Event.BUBBLE_OVERFLOW_SELECTED, currentUserId,
255                 packageName);
256     }
257 
logBubbleUiChanged(Bubble bubble, String packageName, int action, int bubbleCount, float normalX, float normalY, int index)258     void logBubbleUiChanged(Bubble bubble, String packageName, int action, int bubbleCount,
259             float normalX, float normalY, int index) {
260         FrameworkStatsLog.write(FrameworkStatsLog.BUBBLE_UI_CHANGED,
261                 packageName,
262                 bubble.getChannelId() /* notification channel */,
263                 bubble.getNotificationId() /* notification ID */,
264                 index,
265                 bubbleCount,
266                 action,
267                 normalX,
268                 normalY,
269                 bubble.showInShade() /* isUnread */,
270                 false /* isOngoing (unused) */,
271                 false /* isAppForeground (unused) */);
272     }
273 }