• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 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 #pragma once
18 
19 #include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
20 #include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
21 #include <frameworks/proto_logging/stats/enums/bluetooth/le/enums.pb.h>
22 
23 #include <unordered_map>
24 #include "types/raw_address.h"
25 #include "metrics/metrics_state.h"
26 
27 namespace bluetooth {
28 namespace shim {
29 
30 /**
31  * Log link layer connection event
32  *
33  * @param address Stack wide consistent Bluetooth address of this event,
34  *                nullptr if unknown
35  * @param connection_handle connection handle of this event,
36  *                          {@link kUnknownConnectionHandle} if unknown
37  * @param direction direction of this connection
38  * @param link_type type of the link
39  * @param hci_cmd HCI command opecode associated with this event, if any
40  * @param hci_event HCI event code associated with this event, if any
41  * @param hci_ble_event HCI BLE event code associated with this event, if any
42  * @param cmd_status Command status associated with this event, if any
43  * @param reason_code Reason code associated with this event, if any
44  */
45 void LogMetricLinkLayerConnectionEvent(
46     const RawAddress* address, uint32_t connection_handle,
47     android::bluetooth::DirectionEnum direction, uint16_t link_type,
48     uint32_t hci_cmd, uint16_t hci_event, uint16_t hci_ble_event,
49     uint16_t cmd_status, uint16_t reason_code);
50 
51 /**
52  * Log A2DP audio buffer underrun event
53  *
54  * @param address A2DP device associated with this event
55  * @param encoding_interval_millis encoding interval in milliseconds
56  * @param num_missing_pcm_bytes number of PCM bytes that cannot be read from
57  *                              the source
58  */
59 void LogMetricA2dpAudioUnderrunEvent(const RawAddress& address,
60                                      uint64_t encoding_interval_millis,
61                                      int num_missing_pcm_bytes);
62 
63 /**
64  * Log A2DP audio buffer overrun event
65  *
66  * @param address A2DP device associated with this event
67  * @param encoding_interval_millis encoding interval in milliseconds
68  * @param num_dropped_buffers number of encoded buffers dropped from Tx queue
69  * @param num_dropped_encoded_frames number of encoded frames dropped from Tx
70  *                                   queue
71  * @param num_dropped_encoded_bytes number of encoded bytes dropped from Tx
72  *                                  queue
73  */
74 void LogMetricA2dpAudioOverrunEvent(const RawAddress& address,
75                                     uint64_t encoding_interval_millis,
76                                     int num_dropped_buffers,
77                                     int num_dropped_encoded_frames,
78                                     int num_dropped_encoded_bytes);
79 
80 /**
81  * Log A2DP audio playback state changed event
82  *
83  * @param address A2DP device associated with this event
84  * @param playback_state A2DP audio playback state, on/off
85  * @param audio_coding_mode A2DP audio codec encoding mode, hw/sw
86  */
87 void LogMetricA2dpPlaybackEvent(const RawAddress& raw_address,
88                                 int playback_state, int audio_coding_mode);
89 
90 /**
91  * Log read RSSI result
92  *
93  * @param address device associated with this event
94  * @param handle connection handle of this event,
95  *               {@link kUnknownConnectionHandle} if unknown
96  * @param cmd_status command status from read RSSI command
97  * @param rssi rssi value in dBm
98  */
99 void LogMetricReadRssiResult(const RawAddress& address, uint16_t handle,
100                              uint32_t cmd_status, int8_t rssi);
101 
102 /**
103  * Log failed contact counter report
104  *
105  * @param address device associated with this event
106  * @param handle connection handle of this event,
107  *               {@link kUnknownConnectionHandle} if unknown
108  * @param cmd_status command status from read failed contact counter command
109  * @param failed_contact_counter Number of consecutive failed contacts for a
110  *                               connection corresponding to the Handle
111  */
112 void LogMetricReadFailedContactCounterResult(const RawAddress& address,
113                                              uint16_t handle,
114                                              uint32_t cmd_status,
115                                              int32_t failed_contact_counter);
116 
117 /**
118  * Log transmit power level for a particular device after read
119  *
120  * @param address device associated with this event
121  * @param handle connection handle of this event,
122  *               {@link kUnknownConnectionHandle} if unknown
123  * @param cmd_status command status from read failed contact counter command
124  * @param transmit_power_level transmit power level for connection to this
125  *                             device
126  */
127 void LogMetricReadTxPowerLevelResult(const RawAddress& address, uint16_t handle,
128                                      uint32_t cmd_status,
129                                      int32_t transmit_power_level);
130 
131 /**
132  * Logs when there is an event related to Bluetooth Security Manager Protocol
133  *
134  * @param address address of associated device
135  * @param smp_cmd SMP command code associated with this event
136  * @param direction direction of this SMP command
137  * @param smp_fail_reason SMP pairing failure reason code from SMP spec
138  */
139 void LogMetricSmpPairingEvent(const RawAddress& address, uint16_t smp_cmd,
140                               android::bluetooth::DirectionEnum direction,
141                               uint16_t smp_fail_reason);
142 
143 /**
144  * Logs there is an event related Bluetooth classic pairing
145  *
146  * @param address address of associated device
147  * @param handle connection handle of this event,
148  *               {@link kUnknownConnectionHandle} if unknown
149  * @param hci_cmd HCI command associated with this event
150  * @param hci_event HCI event associated with this event
151  * @param cmd_status Command status associated with this event
152  * @param reason_code Reason code associated with this event
153  * @param event_value A status value related to this specific event
154  */
155 void LogMetricClassicPairingEvent(const RawAddress& address, uint16_t handle,
156                                   uint32_t hci_cmd, uint16_t hci_event,
157                                   uint16_t cmd_status, uint16_t reason_code,
158                                   int64_t event_value);
159 
160 /**
161  * Logs when certain Bluetooth SDP attributes are discovered
162  *
163  * @param address address of associated device
164  * @param protocol_uuid 16 bit protocol UUID from Bluetooth Assigned Numbers
165  * @param attribute_id 16 bit attribute ID from Bluetooth Assigned Numbers
166  * @param attribute_size size of this attribute
167  * @param attribute_value pointer to the attribute data, must be larger than
168  *                        attribute_size
169  */
170 void LogMetricSdpAttribute(const RawAddress& address, uint16_t protocol_uuid,
171                            uint16_t attribute_id, size_t attribute_size,
172                            const char* attribute_value);
173 
174 /**
175  * Logs when there is a change in Bluetooth socket connection state
176  *
177  * @param address address of associated device, empty if this is a server port
178  * @param port port of this socket connection
179  * @param type type of socket
180  * @param connection_state socket connection state
181  * @param tx_bytes number of bytes transmitted
182  * @param rx_bytes number of bytes received
183  * @param server_port server port of this socket, if any. When both
184  *        |server_port| and |port| fields are populated, |port| must be spawned
185  *        by |server_port|
186  * @param socket_role role of this socket, server or connection
187  * @param uid socket owner's uid
188  */
189 void LogMetricSocketConnectionState(
190     const RawAddress& address, int port, int type,
191     android::bluetooth::SocketConnectionstateEnum connection_state,
192     int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
193     android::bluetooth::SocketRoleEnum socket_role);
194 
195 /**
196  * Logs when a Bluetooth device's manufacturer information is learnt
197  *
198  * @param address address of associated device
199  * @param source_type where is this device info obtained from
200  * @param source_name name of the data source, internal or external
201  * @param manufacturer name of the manufacturer of this device
202  * @param model model of this device
203  * @param hardware_version hardware version of this device
204  * @param software_version software version of this device
205  */
206 void LogMetricManufacturerInfo(
207     const RawAddress& address, android::bluetooth::AddressTypeEnum address_type,
208     android::bluetooth::DeviceInfoSrcEnum source_type,
209     const std::string& source_name, const std::string& manufacturer,
210     const std::string& model, const std::string& hardware_version,
211     const std::string& software_version);
212 
213 bool CountCounterMetrics(int32_t key, int64_t count);
214 
215 void LogMetricBluetoothLEConnectionMetricEvent(
216     const RawAddress& raw_address,
217     android::bluetooth::le::LeConnectionOriginType origin_type,
218     android::bluetooth::le::LeConnectionType connection_type,
219     android::bluetooth::le::LeConnectionState transaction_state,
220     std::vector<std::pair<os::ArgumentType, int>> argument_list);
221 }  // namespace shim
222 }  // namespace bluetooth
223