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 #include "main/shim/metrics_api.h"
18 #include "gd/hci/address.h"
19 #include "gd/os/metrics.h"
20 #include "main/shim/helpers.h"
21 #include "types/raw_address.h"
22
23 using bluetooth::hci::Address;
24
25 namespace bluetooth {
26 namespace shim {
LogMetricLinkLayerConnectionEvent(const RawAddress * raw_address,uint32_t connection_handle,android::bluetooth::DirectionEnum direction,uint16_t link_type,uint32_t hci_cmd,uint16_t hci_event,uint16_t hci_ble_event,uint16_t cmd_status,uint16_t reason_code)27 void LogMetricLinkLayerConnectionEvent(
28 const RawAddress* raw_address, uint32_t connection_handle,
29 android::bluetooth::DirectionEnum direction, uint16_t link_type,
30 uint32_t hci_cmd, uint16_t hci_event, uint16_t hci_ble_event,
31 uint16_t cmd_status, uint16_t reason_code) {
32 Address address = Address::kEmpty;
33 if (raw_address != nullptr) {
34 address = bluetooth::ToGdAddress(*raw_address);
35 }
36 bluetooth::os::LogMetricLinkLayerConnectionEvent(
37 raw_address == nullptr ? nullptr : &address, connection_handle, direction,
38 link_type, hci_cmd, hci_event, hci_ble_event, cmd_status, reason_code);
39 }
40
LogMetricA2dpAudioUnderrunEvent(const RawAddress & raw_address,uint64_t encoding_interval_millis,int num_missing_pcm_bytes)41 void LogMetricA2dpAudioUnderrunEvent(const RawAddress& raw_address,
42 uint64_t encoding_interval_millis,
43 int num_missing_pcm_bytes) {
44 Address address = bluetooth::ToGdAddress(raw_address);
45 bluetooth::os::LogMetricA2dpAudioUnderrunEvent(
46 address, encoding_interval_millis, num_missing_pcm_bytes);
47 }
48
LogMetricA2dpAudioOverrunEvent(const RawAddress & raw_address,uint64_t encoding_interval_millis,int num_dropped_buffers,int num_dropped_encoded_frames,int num_dropped_encoded_bytes)49 void LogMetricA2dpAudioOverrunEvent(const RawAddress& raw_address,
50 uint64_t encoding_interval_millis,
51 int num_dropped_buffers,
52 int num_dropped_encoded_frames,
53 int num_dropped_encoded_bytes) {
54 Address address = bluetooth::ToGdAddress(raw_address);
55 bluetooth::os::LogMetricA2dpAudioOverrunEvent(
56 address, encoding_interval_millis, num_dropped_buffers,
57 num_dropped_encoded_frames, num_dropped_encoded_bytes);
58 }
59
LogMetricA2dpPlaybackEvent(const RawAddress & raw_address,int playback_state,int audio_coding_mode)60 void LogMetricA2dpPlaybackEvent(const RawAddress& raw_address,
61 int playback_state, int audio_coding_mode) {
62 Address address = bluetooth::ToGdAddress(raw_address);
63 bluetooth::os::LogMetricA2dpPlaybackEvent(address, playback_state,
64 audio_coding_mode);
65 }
66
LogMetricReadRssiResult(const RawAddress & raw_address,uint16_t handle,uint32_t cmd_status,int8_t rssi)67 void LogMetricReadRssiResult(const RawAddress& raw_address, uint16_t handle,
68 uint32_t cmd_status, int8_t rssi) {
69 Address address = bluetooth::ToGdAddress(raw_address);
70 bluetooth::os::LogMetricReadRssiResult(address, handle, cmd_status, rssi);
71 }
72
LogMetricReadFailedContactCounterResult(const RawAddress & raw_address,uint16_t handle,uint32_t cmd_status,int32_t failed_contact_counter)73 void LogMetricReadFailedContactCounterResult(const RawAddress& raw_address,
74 uint16_t handle,
75 uint32_t cmd_status,
76 int32_t failed_contact_counter) {
77 Address address = bluetooth::ToGdAddress(raw_address);
78 bluetooth::os::LogMetricReadFailedContactCounterResult(
79 address, handle, cmd_status, failed_contact_counter);
80 }
81
LogMetricReadTxPowerLevelResult(const RawAddress & raw_address,uint16_t handle,uint32_t cmd_status,int32_t transmit_power_level)82 void LogMetricReadTxPowerLevelResult(const RawAddress& raw_address,
83 uint16_t handle, uint32_t cmd_status,
84 int32_t transmit_power_level) {
85 Address address = bluetooth::ToGdAddress(raw_address);
86 bluetooth::os::LogMetricReadTxPowerLevelResult(address, handle, cmd_status,
87 transmit_power_level);
88 }
89
LogMetricSmpPairingEvent(const RawAddress & raw_address,uint8_t smp_cmd,android::bluetooth::DirectionEnum direction,uint8_t smp_fail_reason)90 void LogMetricSmpPairingEvent(const RawAddress& raw_address, uint8_t smp_cmd,
91 android::bluetooth::DirectionEnum direction,
92 uint8_t smp_fail_reason) {
93 Address address = bluetooth::ToGdAddress(raw_address);
94 bluetooth::os::LogMetricSmpPairingEvent(address, smp_cmd, direction,
95 smp_fail_reason);
96 }
97
LogMetricClassicPairingEvent(const RawAddress & raw_address,uint16_t handle,uint32_t hci_cmd,uint16_t hci_event,uint16_t cmd_status,uint16_t reason_code,int64_t event_value)98 void LogMetricClassicPairingEvent(const RawAddress& raw_address,
99 uint16_t handle, uint32_t hci_cmd,
100 uint16_t hci_event, uint16_t cmd_status,
101 uint16_t reason_code, int64_t event_value) {
102 Address address = bluetooth::ToGdAddress(raw_address);
103 bluetooth::os::LogMetricClassicPairingEvent(address, handle, hci_cmd,
104 hci_event, cmd_status,
105 reason_code, event_value);
106 }
107
LogMetricSdpAttribute(const RawAddress & raw_address,uint16_t protocol_uuid,uint16_t attribute_id,size_t attribute_size,const char * attribute_value)108 void LogMetricSdpAttribute(const RawAddress& raw_address,
109 uint16_t protocol_uuid, uint16_t attribute_id,
110 size_t attribute_size, const char* attribute_value) {
111 Address address = bluetooth::ToGdAddress(raw_address);
112 bluetooth::os::LogMetricSdpAttribute(address, protocol_uuid, attribute_id,
113 attribute_size, attribute_value);
114 }
115
LogMetricSocketConnectionState(const RawAddress & raw_address,int port,int type,android::bluetooth::SocketConnectionstateEnum connection_state,int64_t tx_bytes,int64_t rx_bytes,int uid,int server_port,android::bluetooth::SocketRoleEnum socket_role)116 void LogMetricSocketConnectionState(
117 const RawAddress& raw_address, int port, int type,
118 android::bluetooth::SocketConnectionstateEnum connection_state,
119 int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
120 android::bluetooth::SocketRoleEnum socket_role) {
121 Address address = bluetooth::ToGdAddress(raw_address);
122 bluetooth::os::LogMetricSocketConnectionState(
123 address, port, type, connection_state, tx_bytes, rx_bytes, uid,
124 server_port, socket_role);
125 }
126
LogMetricManufacturerInfo(const RawAddress & raw_address,android::bluetooth::DeviceInfoSrcEnum source_type,const std::string & source_name,const std::string & manufacturer,const std::string & model,const std::string & hardware_version,const std::string & software_version)127 void LogMetricManufacturerInfo(
128 const RawAddress& raw_address,
129 android::bluetooth::DeviceInfoSrcEnum source_type,
130 const std::string& source_name, const std::string& manufacturer,
131 const std::string& model, const std::string& hardware_version,
132 const std::string& software_version) {
133 Address address = bluetooth::ToGdAddress(raw_address);
134 bluetooth::os::LogMetricManufacturerInfo(address, source_type, source_name,
135 manufacturer, model,
136 hardware_version, software_version);
137 }
138 } // namespace shim
139 } // namespace bluetooth