• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
37                     /* event_id = 1 */ eventID,
38                     /* uid = 2 */ uid,
39                     /* package_name = 3 */ packageName,
40                     /* instance_id = 4 */ 0);
41         }
42     }
43 
44     @Override
logWithInstanceId(UiEventEnum event, int uid, String packageName, InstanceId instance)45     public void logWithInstanceId(UiEventEnum event, int uid, String packageName,
46             InstanceId instance) {
47         final int eventID = event.getId();
48         if ((eventID > 0)  && (instance != null)) {
49             FrameworkStatsLog.write(FrameworkStatsLog.UI_EVENT_REPORTED,
50                     /* event_id = 1 */ eventID,
51                     /* uid = 2 */ uid,
52                     /* package_name = 3 */ packageName,
53                     /* instance_id = 4 */ instance.getId());
54         } else {
55             log(event, uid, packageName);
56         }
57     }
58 
59     @Override
logWithPosition(UiEventEnum event, int uid, String packageName, int position)60     public void logWithPosition(UiEventEnum event, int uid, String packageName, int position) {
61         final int eventID = event.getId();
62         if (eventID > 0) {
63             FrameworkStatsLog.write(FrameworkStatsLog.RANKING_SELECTED,
64                     /* event_id = 1 */ eventID,
65                     /* package_name = 2 */ packageName,
66                     /* instance_id = 3 */ 0,
67                     /* position_picked = 4 */ position);
68         }
69     }
70 
71     @Override
logWithInstanceIdAndPosition(UiEventEnum event, int uid, String packageName, InstanceId instance, int position)72     public void logWithInstanceIdAndPosition(UiEventEnum event, int uid, String packageName,
73             InstanceId instance, int position) {
74         final int eventID = event.getId();
75         if ((eventID > 0)  && (instance != null)) {
76             FrameworkStatsLog.write(FrameworkStatsLog.RANKING_SELECTED,
77                     /* event_id = 1 */ eventID,
78                     /* package_name = 2 */ packageName,
79                     /* instance_id = 3 */ instance.getId(),
80                     /* position_picked = 4 */ position);
81         } else {
82             logWithPosition(event, uid, packageName, position);
83         }
84     }
85 }
86