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