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 "stack/include/stack_metrics_logging.h"
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 "common/metrics.h"
23 #include "main/shim/metrics_api.h"
24 #include "main/shim/shim.h"
25 #include "types/raw_address.h"
26
log_classic_pairing_event(const RawAddress & address,uint16_t handle,uint32_t hci_cmd,uint16_t hci_event,uint16_t cmd_status,uint16_t reason_code,int64_t event_value)27 void log_classic_pairing_event(const RawAddress& address, uint16_t handle, uint32_t hci_cmd,
28 uint16_t hci_event, uint16_t cmd_status, uint16_t reason_code,
29 int64_t event_value) {
30 bluetooth::shim::LogMetricClassicPairingEvent(address, handle, hci_cmd, hci_event, cmd_status,
31 reason_code, event_value);
32 }
33
log_link_layer_connection_event(const RawAddress * 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)34 void log_link_layer_connection_event(const RawAddress* address, uint32_t connection_handle,
35 android::bluetooth::DirectionEnum direction,
36 uint16_t link_type, uint32_t hci_cmd, uint16_t hci_event,
37 uint16_t hci_ble_event, uint16_t cmd_status,
38 uint16_t reason_code) {
39 bluetooth::shim::LogMetricLinkLayerConnectionEvent(address, connection_handle, direction,
40 link_type, hci_cmd, hci_event, hci_ble_event,
41 cmd_status, reason_code);
42 }
43
log_smp_pairing_event(const RawAddress & address,uint16_t smp_cmd,android::bluetooth::DirectionEnum direction,uint16_t smp_fail_reason)44 void log_smp_pairing_event(const RawAddress& address, uint16_t smp_cmd,
45 android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason) {
46 bluetooth::shim::LogMetricSmpPairingEvent(address, smp_cmd, direction, smp_fail_reason);
47 }
48
log_sdp_attribute(const RawAddress & address,uint16_t protocol_uuid,uint16_t attribute_id,size_t attribute_size,const char * attribute_value)49 void log_sdp_attribute(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
50 size_t attribute_size, const char* attribute_value) {
51 bluetooth::shim::LogMetricSdpAttribute(address, protocol_uuid, attribute_id, attribute_size,
52 attribute_value);
53 }
54
log_manufacturer_info(const RawAddress & address,android::bluetooth::AddressTypeEnum address_type,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)55 void log_manufacturer_info(const RawAddress& address,
56 android::bluetooth::AddressTypeEnum address_type,
57 android::bluetooth::DeviceInfoSrcEnum source_type,
58 const std::string& source_name, const std::string& manufacturer,
59 const std::string& model, const std::string& hardware_version,
60 const std::string& software_version) {
61 bluetooth::shim::LogMetricManufacturerInfo(address, address_type, source_type, source_name,
62 manufacturer, model, hardware_version,
63 software_version);
64 }
65
log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key,int64_t value)66 void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t value) {
67 bluetooth::shim::CountCounterMetrics(key, value);
68 }
69
log_hfp_audio_packet_loss_stats(const RawAddress & address,int num_decoded_frames,double packet_loss_ratio,uint16_t codec_type)70 void log_hfp_audio_packet_loss_stats(const RawAddress& address, int num_decoded_frames,
71 double packet_loss_ratio, uint16_t codec_type) {
72 bluetooth::shim::LogMetricHfpPacketLossStats(address, num_decoded_frames, packet_loss_ratio,
73 codec_type);
74 }
75
log_mmc_transcode_rtt_stats(int maximum_rtt,double mean_rtt,int num_requests,int codec_type)76 void log_mmc_transcode_rtt_stats(int maximum_rtt, double mean_rtt, int num_requests,
77 int codec_type) {
78 bluetooth::shim::LogMetricMmcTranscodeRttStats(maximum_rtt, mean_rtt, num_requests, codec_type);
79 }
80
log_le_pairing_fail(const RawAddress & raw_address,uint8_t failure_reason,bool is_outgoing)81 void log_le_pairing_fail(const RawAddress& raw_address, uint8_t failure_reason, bool is_outgoing) {
82 bluetooth::shim::LogMetricLePairingFail(raw_address, failure_reason, is_outgoing);
83 }
84
log_le_connection_status(bluetooth::hci::Address address,bool is_connect,bluetooth::hci::ErrorCode reason)85 void log_le_connection_status(bluetooth::hci::Address address, bool is_connect,
86 bluetooth::hci::ErrorCode reason) {
87 bluetooth::shim::LogMetricLeConnectionStatus(address, is_connect, reason);
88 }
89
log_le_device_in_accept_list(bluetooth::hci::Address address,bool is_add)90 void log_le_device_in_accept_list(bluetooth::hci::Address address, bool is_add) {
91 bluetooth::shim::LogMetricLeDeviceInAcceptList(address, is_add);
92 }
93
log_le_connection_lifecycle(bluetooth::hci::Address address,bool is_connect,bool is_direct)94 void log_le_connection_lifecycle(bluetooth::hci::Address address, bool is_connect, bool is_direct) {
95 bluetooth::shim::LogMetricLeConnectionLifecycle(address, is_connect, is_direct);
96 }
97