Will Brockman | 492b381 | 2020-03-03 16:29:36 +0000 | [diff] [blame] | 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.systemui.statusbar.notification.logging; |
| 18 | |
| 19 | import android.annotation.Nullable; |
| 20 | import android.service.notification.StatusBarNotification; |
| 21 | |
| 22 | import com.android.internal.logging.UiEvent; |
| 23 | import com.android.internal.logging.UiEventLogger; |
| 24 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
| 25 | import com.android.systemui.statusbar.notification.logging.nano.Notifications; |
| 26 | |
| 27 | import java.util.List; |
| 28 | /** |
| 29 | * Statsd logging for notification panel. |
| 30 | */ |
| 31 | public interface NotificationPanelLogger { |
| 32 | |
| 33 | /** |
| 34 | * Log a NOTIFICATION_PANEL_REPORTED statsd event. |
| 35 | * @param visibleNotifications as provided by NotificationEntryManager.getVisibleNotifications() |
| 36 | */ |
| 37 | void logPanelShown(boolean isLockscreen, |
| 38 | @Nullable List<NotificationEntry> visibleNotifications); |
| 39 | |
| 40 | enum NotificationPanelEvent implements UiEventLogger.UiEventEnum { |
| 41 | @UiEvent(doc = "Notification panel shown from status bar.") |
| 42 | NOTIFICATION_PANEL_OPEN_STATUS_BAR(200), |
| 43 | @UiEvent(doc = "Notification panel shown from lockscreen.") |
| 44 | NOTIFICATION_PANEL_OPEN_LOCKSCREEN(201); |
| 45 | |
| 46 | private final int mId; |
| 47 | NotificationPanelEvent(int id) { |
| 48 | mId = id; |
| 49 | } |
| 50 | @Override public int getId() { |
| 51 | return mId; |
| 52 | } |
| 53 | |
| 54 | public static NotificationPanelEvent fromLockscreen(boolean isLockscreen) { |
| 55 | return isLockscreen ? NOTIFICATION_PANEL_OPEN_LOCKSCREEN : |
| 56 | NOTIFICATION_PANEL_OPEN_STATUS_BAR; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Composes a NotificationsList proto from the list of visible notifications. |
| 62 | * @param visibleNotifications as provided by NotificationEntryManager.getVisibleNotifications() |
| 63 | * @return NotificationList proto suitable for SysUiStatsLog.write(NOTIFICATION_PANEL_REPORTED) |
| 64 | */ |
| 65 | static Notifications.NotificationList toNotificationProto( |
| 66 | @Nullable List<NotificationEntry> visibleNotifications) { |
| 67 | Notifications.NotificationList notificationList = new Notifications.NotificationList(); |
| 68 | if (visibleNotifications == null) { |
| 69 | return notificationList; |
| 70 | } |
| 71 | final Notifications.Notification[] proto_array = |
| 72 | new Notifications.Notification[visibleNotifications.size()]; |
| 73 | int i = 0; |
| 74 | for (NotificationEntry ne : visibleNotifications) { |
| 75 | final StatusBarNotification n = ne.getSbn(); |
| 76 | if (n != null) { |
| 77 | final Notifications.Notification proto = new Notifications.Notification(); |
| 78 | proto.uid = n.getUid(); |
| 79 | proto.packageName = n.getPackageName(); |
| 80 | if (n.getInstanceId() != null) { |
| 81 | proto.instanceId = n.getInstanceId().getId(); |
| 82 | } |
| 83 | // TODO set np.groupInstanceId |
| 84 | if (n.getNotification() != null) { |
| 85 | proto.isGroupSummary = n.getNotification().isGroupSummary(); |
| 86 | } |
| 87 | proto.section = 1 + ne.getBucket(); // We want 0 to mean not set / unknown |
| 88 | proto_array[i] = proto; |
| 89 | } |
| 90 | ++i; |
| 91 | } |
| 92 | notificationList.notifications = proto_array; |
| 93 | return notificationList; |
| 94 | } |
| 95 | } |