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