• 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.server.notification;
18 
19 import com.android.internal.logging.InstanceId;
20 import com.android.internal.logging.UiEventLogger;
21 import com.android.internal.logging.UiEventLoggerImpl;
22 import com.android.internal.util.FrameworkStatsLog;
23 
24 /**
25  * Standard implementation of NotificationRecordLogger interface.
26  * @hide
27  */
28 public class NotificationRecordLoggerImpl implements NotificationRecordLogger {
29 
30     private UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
31 
32     @Override
maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old, int position, int buzzBeepBlink, InstanceId groupId)33     public void maybeLogNotificationPosted(NotificationRecord r, NotificationRecord old,
34             int position, int buzzBeepBlink,
35             InstanceId groupId) {
36         NotificationRecordPair p = new NotificationRecordPair(r, old);
37         if (!p.shouldLogReported(buzzBeepBlink)) {
38             return;
39         }
40         FrameworkStatsLog.write(FrameworkStatsLog.NOTIFICATION_REPORTED,
41                 /* int32 event_id = 1 */ NotificationReportedEvent.fromRecordPair(p).getId(),
42                 /* int32 uid = 2 */ r.getUid(),
43                 /* string package_name = 3 */ r.getSbn().getPackageName(),
44                 /* int32 instance_id = 4 */ p.getInstanceId(),
45                 /* int32 notification_id_hash = 5 */ p.getNotificationIdHash(),
46                 /* int32 channel_id_hash = 6 */ p.getChannelIdHash(),
47                 /* string group_id_hash = 7 */ p.getGroupIdHash(),
48                 /* int32 group_instance_id = 8 */ (groupId == null) ? 0 : groupId.getId(),
49                 /* bool is_group_summary = 9 */ r.getSbn().getNotification().isGroupSummary(),
50                 /* string category = 10 */ r.getSbn().getNotification().category,
51                 /* int32 style = 11 */ p.getStyle(),
52                 /* int32 num_people = 12 */ p.getNumPeople(),
53                 /* int32 position = 13 */ position,
54                 /* android.stats.sysui.NotificationImportance importance = 14 */
55                 NotificationRecordLogger.getLoggingImportance(r),
56                 /* int32 alerting = 15 */ buzzBeepBlink,
57                 /* NotificationImportanceExplanation importance_source = 16 */
58                 r.getImportanceExplanationCode(),
59                 /* android.stats.sysui.NotificationImportance importance_initial = 17 */
60                 r.getInitialImportance(),
61                 /* NotificationImportanceExplanation importance_initial_source = 18 */
62                 r.getInitialImportanceExplanationCode(),
63                 /* android.stats.sysui.NotificationImportance importance_asst = 19 */
64                 r.getAssistantImportance(),
65                 /* int32 assistant_hash = 20 */ p.getAssistantHash(),
66                 /* float assistant_ranking_score = 21 */ r.getRankingScore()
67         );
68     }
69 
70     @Override
log(UiEventLogger.UiEventEnum event, NotificationRecord r)71     public void log(UiEventLogger.UiEventEnum event, NotificationRecord r) {
72         if (r == null) {
73             return;
74         }
75         mUiEventLogger.logWithInstanceId(event, r.getUid(), r.getSbn().getPackageName(),
76                 r.getSbn().getInstanceId());
77     }
78 
79     @Override
log(UiEventLogger.UiEventEnum event)80     public void log(UiEventLogger.UiEventEnum event) {
81         mUiEventLogger.log(event);
82     }
83 }
84