1 /*
2  * Copyright (C) 2019 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.internal.logging;
18 
19 import com.android.internal.util.FrameworkStatsLog;
20 
21 /**
22  * Standard implementation of UiEventLogger, writing to FrameworkStatsLog.
23  *
24  * See UiEventReported atom in atoms.proto for more context.
25  */
26 public class UiEventLoggerImpl implements UiEventLogger {
27     @Override
log(UiEventEnum event)28     public void log(UiEventEnum event) {
29         log(event, 0, null);
30     }
31 
32     @Override
log(UiEventEnum event, int uid, String packageName)33     public void log(UiEventEnum event, int uid, String packageName) {
34         final int eventID = event.getId();
35         if (eventID > 0) {
36             FrameworkStatsLog.write(FrameworkStatsLog.UI_EVENT_REPORTED, eventID, uid, packageName);
37         }
38     }
39 
40     @Override
logWithInstanceId(UiEventEnum event, int uid, String packageName, InstanceId instance)41     public void logWithInstanceId(UiEventEnum event, int uid, String packageName,
42             InstanceId instance) {
43         final int eventID = event.getId();
44         if ((eventID > 0)  && (instance != null)) {
45             FrameworkStatsLog.write(FrameworkStatsLog.UI_EVENT_REPORTED, eventID, uid, packageName,
46                     instance.getId());
47         } else {
48             log(event, uid, packageName);
49         }
50     }
51 
52     @Override
logWithPosition(UiEventEnum event, int uid, String packageName, int position)53     public void logWithPosition(UiEventEnum event, int uid, String packageName, int position) {
54         final int eventID = event.getId();
55         if (eventID > 0) {
56             FrameworkStatsLog.write(FrameworkStatsLog.RANKING_SELECTED,
57                     /* event_id = 1 */ eventID,
58                     /* package_name = 2 */ packageName,
59                     /* instance_id = 3 */ 0,
60                     /* position_picked = 4 */ position);
61         }
62     }
63 
64     @Override
logWithInstanceIdAndPosition(UiEventEnum event, int uid, String packageName, InstanceId instance, int position)65     public void logWithInstanceIdAndPosition(UiEventEnum event, int uid, String packageName,
66             InstanceId instance, int position) {
67         final int eventID = event.getId();
68         if ((eventID > 0)  && (instance != null)) {
69             FrameworkStatsLog.write(FrameworkStatsLog.RANKING_SELECTED,
70                     /* event_id = 1 */ eventID,
71                     /* package_name = 2 */ packageName,
72                     /* instance_id = 3 */ instance.getId(),
73                     /* position_picked = 4 */ position);
74         } else {
75             logWithPosition(event, uid, packageName, position);
76         }
77     }
78 }
79