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 HFP audio capture packet loss statistics 92 * 93 * @param address HFP device associated with this stats 94 * @param num_decoded_frames number of decoded frames 95 * @param packet_loss_ratio ratio of packet loss frames 96 */ 97 void LogMetricHfpPacketLossStats(const RawAddress& address, 98 int num_decoded_frames, 99 double packet_loss_ratio); 100 101 /** 102 * Log read RSSI result 103 * 104 * @param address device associated with this event 105 * @param handle connection handle of this event, 106 * {@link kUnknownConnectionHandle} if unknown 107 * @param cmd_status command status from read RSSI command 108 * @param rssi rssi value in dBm 109 */ 110 void LogMetricReadRssiResult(const RawAddress& address, uint16_t handle, 111 uint32_t cmd_status, int8_t rssi); 112 113 /** 114 * Log failed contact counter report 115 * 116 * @param address device associated with this event 117 * @param handle connection handle of this event, 118 * {@link kUnknownConnectionHandle} if unknown 119 * @param cmd_status command status from read failed contact counter command 120 * @param failed_contact_counter Number of consecutive failed contacts for a 121 * connection corresponding to the Handle 122 */ 123 void LogMetricReadFailedContactCounterResult(const RawAddress& address, 124 uint16_t handle, 125 uint32_t cmd_status, 126 int32_t failed_contact_counter); 127 128 /** 129 * Log transmit power level for a particular device after read 130 * 131 * @param address device associated with this event 132 * @param handle connection handle of this event, 133 * {@link kUnknownConnectionHandle} if unknown 134 * @param cmd_status command status from read failed contact counter command 135 * @param transmit_power_level transmit power level for connection to this 136 * device 137 */ 138 void LogMetricReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, 139 uint32_t cmd_status, 140 int32_t transmit_power_level); 141 142 /** 143 * Logs when there is an event related to Bluetooth Security Manager Protocol 144 * 145 * @param address address of associated device 146 * @param smp_cmd SMP command code associated with this event 147 * @param direction direction of this SMP command 148 * @param smp_fail_reason SMP pairing failure reason code from SMP spec 149 */ 150 void LogMetricSmpPairingEvent(const RawAddress& address, uint16_t smp_cmd, 151 android::bluetooth::DirectionEnum direction, 152 uint16_t smp_fail_reason); 153 154 /** 155 * Logs there is an event related Bluetooth classic pairing 156 * 157 * @param address address of associated device 158 * @param handle connection handle of this event, 159 * {@link kUnknownConnectionHandle} if unknown 160 * @param hci_cmd HCI command associated with this event 161 * @param hci_event HCI event associated with this event 162 * @param cmd_status Command status associated with this event 163 * @param reason_code Reason code associated with this event 164 * @param event_value A status value related to this specific event 165 */ 166 void LogMetricClassicPairingEvent(const RawAddress& address, uint16_t handle, 167 uint32_t hci_cmd, uint16_t hci_event, 168 uint16_t cmd_status, uint16_t reason_code, 169 int64_t event_value); 170 171 /** 172 * Logs when certain Bluetooth SDP attributes are discovered 173 * 174 * @param address address of associated device 175 * @param protocol_uuid 16 bit protocol UUID from Bluetooth Assigned Numbers 176 * @param attribute_id 16 bit attribute ID from Bluetooth Assigned Numbers 177 * @param attribute_size size of this attribute 178 * @param attribute_value pointer to the attribute data, must be larger than 179 * attribute_size 180 */ 181 void LogMetricSdpAttribute(const RawAddress& address, uint16_t protocol_uuid, 182 uint16_t attribute_id, size_t attribute_size, 183 const char* attribute_value); 184 185 /** 186 * Logs when there is a change in Bluetooth socket connection state 187 * 188 * @param address address of associated device, empty if this is a server port 189 * @param port port of this socket connection 190 * @param type type of socket 191 * @param connection_state socket connection state 192 * @param tx_bytes number of bytes transmitted 193 * @param rx_bytes number of bytes received 194 * @param server_port server port of this socket, if any. When both 195 * |server_port| and |port| fields are populated, |port| must be spawned 196 * by |server_port| 197 * @param socket_role role of this socket, server or connection 198 * @param uid socket owner's uid 199 */ 200 void LogMetricSocketConnectionState( 201 const RawAddress& address, int port, int type, 202 android::bluetooth::SocketConnectionstateEnum connection_state, 203 int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port, 204 android::bluetooth::SocketRoleEnum socket_role); 205 206 /** 207 * Logs when a Bluetooth device's manufacturer information is learnt 208 * 209 * @param address address of associated device 210 * @param source_type where is this device info obtained from 211 * @param source_name name of the data source, internal or external 212 * @param manufacturer name of the manufacturer of this device 213 * @param model model of this device 214 * @param hardware_version hardware version of this device 215 * @param software_version software version of this device 216 */ 217 void LogMetricManufacturerInfo( 218 const RawAddress& address, android::bluetooth::AddressTypeEnum address_type, 219 android::bluetooth::DeviceInfoSrcEnum source_type, 220 const std::string& source_name, const std::string& manufacturer, 221 const std::string& model, const std::string& hardware_version, 222 const std::string& software_version); 223 224 bool CountCounterMetrics(int32_t key, int64_t count); 225 226 void LogMetricBluetoothLEConnectionMetricEvent( 227 const RawAddress& raw_address, 228 android::bluetooth::le::LeConnectionOriginType origin_type, 229 android::bluetooth::le::LeConnectionType connection_type, 230 android::bluetooth::le::LeConnectionState transaction_state, 231 std::vector<std::pair<os::ArgumentType, int>> argument_list); 232 } // namespace shim 233 } // namespace bluetooth 234