Loading system/build/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -62,8 +62,10 @@ fluoride_defaults { }, defaults: ["fluoride_types_defaults"], header_libs: ["libbluetooth_headers"], shared_libs: ["libstatslog"], static_libs: [ "libbluetooth-types", "libbt-platform-protos-lite", ], cpp_std: "c++17", sanitize: { Loading system/common/metrics.cc +30 −0 Original line number Diff line number Diff line Loading @@ -29,11 +29,13 @@ #include <base/base64.h> #include <base/logging.h> #include <include/hardware/bt_av.h> #include <statslog.h> #include "bluetooth/metrics/bluetooth.pb.h" #include "osi/include/osi.h" #include "stack/include/btm_api_types.h" #include "address_obfuscator.h" #include "leaky_bonded_queue.h" #include "metrics.h" #include "time_util.h" Loading Loading @@ -567,6 +569,34 @@ void BluetoothMetricsLogger::Reset() { pimpl_->scan_event_queue_->Clear(); } void LogLinkLayerConnectionEvent(const RawAddress* address, uint32_t connection_handle, android::bluetooth::DirectionEnum direction, uint32_t link_type, uint32_t hci_cmd, uint32_t hci_event, uint32_t hci_ble_event, uint32_t cmd_status, uint32_t reason_code) { std::string obfuscated_id; if (address != nullptr) { obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(*address); } // nullptr and size 0 represent missing value for obfuscated_id android::util::BytesField bytes_field( address != nullptr ? obfuscated_id.c_str() : nullptr, address != nullptr ? obfuscated_id.size() : 0); int ret = android::util::stats_write( android::util::BLUETOOTH_LINK_LAYER_CONNECTION_EVENT, bytes_field, connection_handle, direction, link_type, hci_cmd, hci_event, hci_ble_event, cmd_status, reason_code); if (ret < 0) { LOG(WARNING) << __func__ << ": failed to log status 0x" << loghex(cmd_status) << ", reason 0x" << loghex(reason_code) << " from cmd 0x" << loghex(hci_cmd) << ", event 0x" << loghex(hci_event) << ", ble_event 0x" << loghex(hci_ble_event) << " for " << address << ", handle " << connection_handle << ", error " << ret; } } } // namespace common } // namespace bluetooth system/common/metrics.h +28 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #pragma once #include <bta/include/bta_api.h> #include <frameworks/base/core/proto/android/bluetooth/enums.pb.h> #include <stdint.h> #include <memory> #include <string> Loading Loading @@ -276,6 +277,33 @@ class BluetoothMetricsLogger { std::unique_ptr<impl> const pimpl_; }; /** * Unknown connection handle for metrics purpose */ static const uint32_t kUnknownConnectionHandle = 0xFFFF; /** * Log link layer connection event * * @param address Stack wide consistent Bluetooth address of this event, * nullptr if unknown * @param connection_handle connection handle of this event, * {@link kUnknownConnectionHandle} if unknown * @param direction direction of this connection * @param link_type type of the link * @param hci_cmd HCI command opecode associated with this event, if any * @param hci_event HCI event code associated with this event, if any * @param hci_ble_event HCI BLE event code associated with this event, if any * @param cmd_status Command status associated with this event, if any * @param reason_code Reason code associated with this event, if any */ void LogLinkLayerConnectionEvent(const RawAddress* address, uint32_t connection_handle, android::bluetooth::DirectionEnum direction, uint32_t link_type, uint32_t hci_cmd, uint32_t hci_event, uint32_t hci_ble_event, uint32_t cmd_status, uint32_t reason_code); } // namespace common } // namespace bluetooth system/osi/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,7 @@ cc_test { "liblog", "libprotobuf-cpp-lite", "libcutils", "libcrypto", ], static_libs: [ "libbt-common", Loading system/stack/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -267,6 +267,7 @@ cc_test { shared_libs: [ "libcutils", "libprotobuf-cpp-lite", "libcrypto", ], static_libs: [ "liblog", Loading Loading
system/build/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -62,8 +62,10 @@ fluoride_defaults { }, defaults: ["fluoride_types_defaults"], header_libs: ["libbluetooth_headers"], shared_libs: ["libstatslog"], static_libs: [ "libbluetooth-types", "libbt-platform-protos-lite", ], cpp_std: "c++17", sanitize: { Loading
system/common/metrics.cc +30 −0 Original line number Diff line number Diff line Loading @@ -29,11 +29,13 @@ #include <base/base64.h> #include <base/logging.h> #include <include/hardware/bt_av.h> #include <statslog.h> #include "bluetooth/metrics/bluetooth.pb.h" #include "osi/include/osi.h" #include "stack/include/btm_api_types.h" #include "address_obfuscator.h" #include "leaky_bonded_queue.h" #include "metrics.h" #include "time_util.h" Loading Loading @@ -567,6 +569,34 @@ void BluetoothMetricsLogger::Reset() { pimpl_->scan_event_queue_->Clear(); } void LogLinkLayerConnectionEvent(const RawAddress* address, uint32_t connection_handle, android::bluetooth::DirectionEnum direction, uint32_t link_type, uint32_t hci_cmd, uint32_t hci_event, uint32_t hci_ble_event, uint32_t cmd_status, uint32_t reason_code) { std::string obfuscated_id; if (address != nullptr) { obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(*address); } // nullptr and size 0 represent missing value for obfuscated_id android::util::BytesField bytes_field( address != nullptr ? obfuscated_id.c_str() : nullptr, address != nullptr ? obfuscated_id.size() : 0); int ret = android::util::stats_write( android::util::BLUETOOTH_LINK_LAYER_CONNECTION_EVENT, bytes_field, connection_handle, direction, link_type, hci_cmd, hci_event, hci_ble_event, cmd_status, reason_code); if (ret < 0) { LOG(WARNING) << __func__ << ": failed to log status 0x" << loghex(cmd_status) << ", reason 0x" << loghex(reason_code) << " from cmd 0x" << loghex(hci_cmd) << ", event 0x" << loghex(hci_event) << ", ble_event 0x" << loghex(hci_ble_event) << " for " << address << ", handle " << connection_handle << ", error " << ret; } } } // namespace common } // namespace bluetooth
system/common/metrics.h +28 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ #pragma once #include <bta/include/bta_api.h> #include <frameworks/base/core/proto/android/bluetooth/enums.pb.h> #include <stdint.h> #include <memory> #include <string> Loading Loading @@ -276,6 +277,33 @@ class BluetoothMetricsLogger { std::unique_ptr<impl> const pimpl_; }; /** * Unknown connection handle for metrics purpose */ static const uint32_t kUnknownConnectionHandle = 0xFFFF; /** * Log link layer connection event * * @param address Stack wide consistent Bluetooth address of this event, * nullptr if unknown * @param connection_handle connection handle of this event, * {@link kUnknownConnectionHandle} if unknown * @param direction direction of this connection * @param link_type type of the link * @param hci_cmd HCI command opecode associated with this event, if any * @param hci_event HCI event code associated with this event, if any * @param hci_ble_event HCI BLE event code associated with this event, if any * @param cmd_status Command status associated with this event, if any * @param reason_code Reason code associated with this event, if any */ void LogLinkLayerConnectionEvent(const RawAddress* address, uint32_t connection_handle, android::bluetooth::DirectionEnum direction, uint32_t link_type, uint32_t hci_cmd, uint32_t hci_event, uint32_t hci_ble_event, uint32_t cmd_status, uint32_t reason_code); } // namespace common } // namespace bluetooth
system/osi/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -115,6 +115,7 @@ cc_test { "liblog", "libprotobuf-cpp-lite", "libcutils", "libcrypto", ], static_libs: [ "libbt-common", Loading
system/stack/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -267,6 +267,7 @@ cc_test { shared_libs: [ "libcutils", "libprotobuf-cpp-lite", "libcrypto", ], static_libs: [ "liblog", Loading