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   if (bluetooth::shim::is_any_gd_enabled()) {
31     bluetooth::shim::LogMetricClassicPairingEvent(address, handle, hci_cmd,
32                                                   hci_event, cmd_status,
33                                                   reason_code, event_value);
34   } else {
35     bluetooth::common::LogClassicPairingEvent(address, handle, hci_cmd,
36                                               hci_event, cmd_status,
37                                               reason_code, event_value);
38   }
39 }
40 
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)41 void log_link_layer_connection_event(
42     const RawAddress* address, uint32_t connection_handle,
43     android::bluetooth::DirectionEnum direction, uint16_t link_type,
44     uint32_t hci_cmd, uint16_t hci_event, uint16_t hci_ble_event,
45     uint16_t cmd_status, uint16_t reason_code) {
46   if (bluetooth::shim::is_any_gd_enabled()) {
47     bluetooth::shim::LogMetricLinkLayerConnectionEvent(
48         address, connection_handle, direction, link_type, hci_cmd, hci_event,
49         hci_ble_event, cmd_status, reason_code);
50   } else {
51     bluetooth::common::LogLinkLayerConnectionEvent(
52         address, connection_handle, direction, link_type, hci_cmd, hci_event,
53         hci_ble_event, cmd_status, reason_code);
54   }
55 }
56 
log_smp_pairing_event(const RawAddress & address,uint8_t smp_cmd,android::bluetooth::DirectionEnum direction,uint8_t smp_fail_reason)57 void log_smp_pairing_event(const RawAddress& address, uint8_t smp_cmd,
58                            android::bluetooth::DirectionEnum direction,
59                            uint8_t smp_fail_reason) {
60   if (bluetooth::shim::is_any_gd_enabled()) {
61     bluetooth::shim::LogMetricSmpPairingEvent(address, smp_cmd, direction,
62                                               smp_fail_reason);
63   } else {
64     bluetooth::common::LogSmpPairingEvent(address, smp_cmd, direction,
65                                           smp_fail_reason);
66   }
67 }
68 
log_sdp_attribute(const RawAddress & address,uint16_t protocol_uuid,uint16_t attribute_id,size_t attribute_size,const char * attribute_value)69 void log_sdp_attribute(const RawAddress& address, uint16_t protocol_uuid,
70                        uint16_t attribute_id, size_t attribute_size,
71                        const char* attribute_value) {
72   if (bluetooth::shim::is_any_gd_enabled()) {
73     bluetooth::shim::LogMetricSdpAttribute(address, protocol_uuid, attribute_id,
74                                            attribute_size, attribute_value);
75   } else {
76     bluetooth::common::LogSdpAttribute(address, protocol_uuid, attribute_id,
77                                        attribute_size, attribute_value);
78   }
79 }
80 
log_manufacturer_info(const RawAddress & 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)81 void log_manufacturer_info(const RawAddress& address,
82                            android::bluetooth::DeviceInfoSrcEnum source_type,
83                            const std::string& source_name,
84                            const std::string& manufacturer,
85                            const std::string& model,
86                            const std::string& hardware_version,
87                            const std::string& software_version) {
88   if (bluetooth::shim::is_any_gd_enabled()) {
89     bluetooth::shim::LogMetricManufacturerInfo(
90         address, source_type, source_name, manufacturer, model,
91         hardware_version, software_version);
92   } else {
93     bluetooth::common::LogManufacturerInfo(address, source_type, source_name,
94                                            manufacturer, model,
95                                            hardware_version, software_version);
96   }
97 }