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 android.app.NotificationChannel;
20 import android.app.NotificationChannelGroup;
21 
22 import com.android.internal.logging.UiEventLogger;
23 import com.android.internal.logging.UiEventLoggerImpl;
24 import com.android.internal.util.FrameworkStatsLog;
25 
26 /**
27  * Standard implementation of NotificationChannelLogger, which passes data through to StatsLog.
28  * This layer is as skinny as possible, to maximize code coverage of unit tests.  Nontrivial code
29  * should live in the interface so it can be tested.
30  */
31 public class NotificationChannelLoggerImpl implements NotificationChannelLogger {
32     UiEventLogger mUiEventLogger = new UiEventLoggerImpl();
33 
34     @Override
logNotificationChannel(NotificationChannelEvent event, NotificationChannel channel, int uid, String pkg, int oldImportance, int newImportance)35     public void logNotificationChannel(NotificationChannelEvent event,
36             NotificationChannel channel, int uid, String pkg,
37             int oldImportance, int newImportance) {
38         FrameworkStatsLog.write(FrameworkStatsLog.NOTIFICATION_CHANNEL_MODIFIED,
39                 /* int event_id*/ event.getId(),
40                 /* int uid*/ uid,
41                 /* String package_name */ pkg,
42                 /* int32 channel_id_hash */ NotificationChannelLogger.getIdHash(channel),
43                 /* int old_importance*/ oldImportance,
44                 /* int importance*/ newImportance,
45                 /* bool is_conversation */ channel.isConversation(),
46                 /* int32 conversation_id_hash */
47                 NotificationChannelLogger.getConversationIdHash(channel),
48                 /* bool is_conversation_demoted */ channel.isDemoted(),
49                 /* bool is_conversation_priority */ channel.isImportantConversation());
50     }
51 
52     @Override
logNotificationChannelGroup(NotificationChannelEvent event, NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked)53     public void logNotificationChannelGroup(NotificationChannelEvent event,
54             NotificationChannelGroup channelGroup, int uid, String pkg, boolean wasBlocked) {
55         FrameworkStatsLog.write(FrameworkStatsLog.NOTIFICATION_CHANNEL_MODIFIED,
56                 /* int event_id*/ event.getId(),
57                 /* int uid*/ uid,
58                 /* String package_name */ pkg,
59                 /* int32 channel_id_hash */ NotificationChannelLogger.getIdHash(channelGroup),
60                 /* int old_importance*/ NotificationChannelLogger.getImportance(wasBlocked),
61                 /* int importance*/ NotificationChannelLogger.getImportance(channelGroup),
62                 /* bool is_conversation */ false,
63                 /* int32 conversation_id_hash */ 0,
64                 /* bool is_conversation_demoted */ false,
65                 /* bool is_conversation_priority */ false);
66     }
67 
68     @Override
logAppEvent(NotificationChannelEvent event, int uid, String pkg)69     public void logAppEvent(NotificationChannelEvent event, int uid, String pkg) {
70         mUiEventLogger.log(event, uid, pkg);
71     }
72 }
73