1 /*
2  * Copyright (C) 2017 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 #include <log/log_event_list.h>
18 #include <cstdint>
19 #include <string>
20 
21 namespace android {
22 namespace metricslogger {
23 
24 // Logs a Tron histogram metric named |event| containing |data| to the Tron log
25 // buffer.
26 void LogHistogram(const std::string& event, int32_t data);
27 
28 // Logs a Tron counter metric named |name| containing |val| count to the Tron
29 // log buffer.
30 void LogCounter(const std::string& name, int32_t val);
31 
32 // Logs a Tron multi_action with category|category| containing the string
33 // |value| in the field |field|.
34 void LogMultiAction(int32_t category, int32_t field, const std::string& value);
35 
36 // Logs a Tron complex event.
37 //
38 // A complex event can include data in a structure not suppored by the other
39 // log event types above.
40 //
41 // Note that instances of this class are single use. You must call Record()
42 // to write the event to the event log.
43 class ComplexEventLogger {
44   private:
45     android_log_event_list logger;
46 
47   public:
48     // Create a complex event with category|category|.
49     explicit ComplexEventLogger(int category);
50     // Set the package name that this event originates from.
51     void SetPackageName(const std::string& package_name);
52     // Add tagged data to the event, with the given tag and integer value.
53     void AddTaggedData(int tag, int32_t value);
54     // Add tagged data to the event, with the given tag and string value.
55     void AddTaggedData(int tag, const std::string& value);
56     // Add tagged data to the event, with the given tag and integer value.
57     void AddTaggedData(int tag, int64_t value);
58     // Add tagged data to the event, with the given tag and float value.
59     void AddTaggedData(int tag, float value);
60     // Record this event. This method can only be used once per instance
61     // of ComplexEventLogger. Do not made any subsequent calls to AddTaggedData
62     // after recording an event.
63     void Record();
64 };
65 
66 // TODO: replace these with the metric_logger.proto definitions
67 enum {
68     LOGBUILDER_CATEGORY = 757,
69     LOGBUILDER_TYPE = 758,
70     LOGBUILDER_NAME = 799,
71     LOGBUILDER_BUCKET = 801,
72     LOGBUILDER_VALUE = 802,
73     LOGBUILDER_COUNTER = 803,
74     LOGBUILDER_HISTOGRAM = 804,
75     LOGBUILDER_PACKAGENAME = 806,
76 
77     ACTION_BOOT = 1098,
78     FIELD_PLATFORM_REASON = 1099,
79 
80     FIELD_DURATION_MILLIS = 1304,
81 
82     FIELD_END_BATTERY_PERCENT = 1308,
83 
84     ACTION_HIDDEN_API_ACCESSED = 1391,
85     FIELD_HIDDEN_API_ACCESS_METHOD = 1392,
86     FIELD_HIDDEN_API_ACCESS_DENIED = 1393,
87     FIELD_HIDDEN_API_SIGNATURE = 1394,
88 
89     ACTION_USB_CONNECTOR_CONNECTED = 1422,
90     ACTION_USB_CONNECTOR_DISCONNECTED = 1423,
91     ACTION_USB_AUDIO_CONNECTED = 1424,
92     FIELD_USB_AUDIO_VIDPID = 1425,
93     ACTION_USB_AUDIO_DISCONNECTED = 1426,
94     ACTION_HARDWARE_FAILED = 1427,
95     FIELD_HARDWARE_TYPE = 1428,
96     FIELD_HARDWARE_FAILURE_CODE = 1429,
97     ACTION_PHYSICAL_DROP = 1430,
98     FIELD_CONFIDENCE_PERCENT = 1431,
99     FIELD_ACCEL_MILLI_G = 1432,
100     ACTION_BATTERY_HEALTH = 1433,
101     FIELD_BATTERY_HEALTH_SNAPSHOT_TYPE = 1434,
102     FIELD_BATTERY_TEMPERATURE_DECI_C = 1435,
103     FIELD_BATTERY_VOLTAGE_UV = 1436,
104     FIELD_BATTERY_OPEN_CIRCUIT_VOLTAGE_UV = 1437,
105     ACTION_BATTERY_CHARGE_CYCLES = 1438,
106     FIELD_BATTERY_CHARGE_CYCLES = 1439,
107 
108     ACTION_SLOW_IO = 1442,
109     FIELD_IO_OPERATION_TYPE = 1443,
110     FIELD_IO_OPERATION_COUNT = 1444,
111     ACTION_SPEAKER_IMPEDANCE = 1445,
112     FIELD_SPEAKER_IMPEDANCE_MILLIOHMS = 1446,
113     FIELD_SPEAKER_LOCATION = 1447,
114     FIELD_BATTERY_RESISTANCE_UOHMS = 1448,
115     FIELD_BATTERY_CURRENT_UA = 1449,
116     FIELD_HARDWARE_LOCATION = 1450,
117     ACTION_BATTERY_CAUSED_SHUTDOWN = 1441,
118 };
119 
120 enum {
121     TYPE_ACTION = 4,
122 };
123 
124 enum {
125     ACCESS_METHOD_NONE = 0,
126     ACCESS_METHOD_REFLECTION = 1,
127     ACCESS_METHOD_JNI = 2,
128     ACCESS_METHOD_LINKING = 3,
129 };
130 
131 enum HardwareType {
132     HARDWARE_UNKNOWN = 0,
133     HARDWARE_MICROPHONE = 1,
134     HARDWARE_CODEC = 2,
135     HARDWARE_SPEAKER = 3,
136     HARDWARE_FINGERPRINT = 4,
137 };
138 
139 enum HardwareFailureCode {
140     HARDWARE_FAILURE_UNKNOWN = 0,
141     HARDWARE_FAILURE_COMPLETE = 1,
142     HARDWARE_FAILURE_SPEAKER_HIGH_Z = 2,
143     HARDWARE_FAILURE_SPEAKER_SHORT = 3,
144     HARDWARE_FAILURE_FINGERPRINT_SENSOR_BROKEN = 4,
145     HARDWARE_FAILURE_FINGERPRINT_TOO_MANY_DEAD_PIXELS = 5,
146 };
147 
148 enum IoOperation {
149     IOOP_UNKNOWN = 0,
150     IOOP_READ = 1,
151     IOOP_WRITE = 2,
152     IOOP_UNMAP = 3,
153     IOOP_SYNC = 4,
154 };
155 
156 }  // namespace metricslogger
157 }  // namespace android
158