Loading system/btif/src/bluetooth.cc +7 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ #include "btsnoop.h" #include "btsnoop_mem.h" #include "common/address_obfuscator.h" #include "common/metric_id_allocator.h" #include "common/metrics.h" #include "device/include/interop.h" #include "main/shim/dumpsys.h" Loading Loading @@ -460,6 +461,11 @@ static std::string obfuscate_address(const RawAddress& address) { address); } static int get_metric_id(const RawAddress& address) { return bluetooth::common::MetricIdAllocator::GetInstance().AllocateId( address); } EXPORT_SYMBOL bt_interface_t bluetoothInterface = { sizeof(bluetoothInterface), init, Loading Loading @@ -496,4 +502,5 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = { interop_database_add, get_avrcp_service, obfuscate_address, get_metric_id, }; system/common/metric_id_allocator.cc +6 −6 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ namespace bluetooth { namespace common { const std::string MetricIdAllocator::LOG_TAG = "BluetoothMetricIdAllocator"; const std::string MetricIdAllocator::LOGGING_TAG = "BluetoothMetricIdAllocator"; const size_t MetricIdAllocator::kMaxNumUnpairedDevicesInMemory = 200; const size_t MetricIdAllocator::kMaxNumPairedDevicesInMemory = 400; const int MetricIdAllocator::kMinId = 1; Loading @@ -42,11 +42,11 @@ static_assert((MetricIdAllocator::kMaxNumUnpairedDevicesInMemory + "kMaxNumPairedDevicesInMemory + MaxNumUnpairedDevicesInMemory"); MetricIdAllocator::MetricIdAllocator() : paired_device_cache_(kMaxNumPairedDevicesInMemory, LOG_TAG, : paired_device_cache_(kMaxNumPairedDevicesInMemory, LOGGING_TAG, [this](RawAddress dummy, int to_remove) { this->id_set_.erase(to_remove); }), temporary_device_cache_(kMaxNumUnpairedDevicesInMemory, LOG_TAG, temporary_device_cache_(kMaxNumUnpairedDevicesInMemory, LOGGING_TAG, [this](RawAddress dummy, int to_remove) { this->id_set_.erase(to_remove); }) {} Loading @@ -62,7 +62,7 @@ bool MetricIdAllocator::Init( // init paired_devices_map if (paired_device_map.size() > kMaxNumPairedDevicesInMemory) { LOG(FATAL) << LOG_TAG << LOGGING_TAG << "Paired device map is bigger than kMaxNumPairedDevicesInMemory"; // fail loudly to let caller know return false; Loading @@ -71,7 +71,7 @@ bool MetricIdAllocator::Init( next_id_ = kMinId; for (const std::pair<RawAddress, int>& p : paired_device_map) { if (p.second < kMinId || p.second > kMaxId) { LOG(FATAL) << LOG_TAG << "Invalid Bluetooth Metric Id in config"; LOG(FATAL) << LOGGING_TAG << "Invalid Bluetooth Metric Id in config"; } paired_device_cache_.Put(p.first, p.second); id_set_.insert(p.second); Loading Loading @@ -130,7 +130,7 @@ int MetricIdAllocator::AllocateId(const RawAddress& mac_address) { next_id_++; if (next_id_ > kMaxId) { next_id_ = kMinId; LOG(WARNING) << LOG_TAG << "Bluetooth metric id overflow."; LOG(WARNING) << LOGGING_TAG << "Bluetooth metric id overflow."; } } id = next_id_++; Loading system/common/metric_id_allocator.h +1 −1 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ class MetricIdAllocator { MetricIdAllocator(); private: static const std::string LOG_TAG; static const std::string LOGGING_TAG; mutable std::mutex id_allocator_mutex_; LruCache<RawAddress, int> paired_device_cache_; Loading system/include/hardware/bluetooth.h +8 −0 Original line number Diff line number Diff line Loading @@ -625,6 +625,14 @@ typedef struct { * @return a string of uint8_t that is unique to this MAC address */ std::string (*obfuscate_address)(const RawAddress& address); /** * Get an incremental id for as primary key for Bluetooth metric and log * * @param address Bluetooth MAC address of Bluetooth device * @return int incremental Bluetooth id */ int (*get_metric_id)(const RawAddress& address); } bt_interface_t; #define BLUETOOTH_INTERFACE_STRING "bluetoothInterface" Loading system/service/hal/fake_bluetooth_interface.cc +1 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ bt_interface_t fake_bt_iface = { nullptr, /* interop_database_add */ nullptr, /* get_avrcp_service */ nullptr, /* obfuscate_address */ nullptr, /* get_metric_id */ }; } // namespace Loading Loading
system/btif/src/bluetooth.cc +7 −0 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ #include "btsnoop.h" #include "btsnoop_mem.h" #include "common/address_obfuscator.h" #include "common/metric_id_allocator.h" #include "common/metrics.h" #include "device/include/interop.h" #include "main/shim/dumpsys.h" Loading Loading @@ -460,6 +461,11 @@ static std::string obfuscate_address(const RawAddress& address) { address); } static int get_metric_id(const RawAddress& address) { return bluetooth::common::MetricIdAllocator::GetInstance().AllocateId( address); } EXPORT_SYMBOL bt_interface_t bluetoothInterface = { sizeof(bluetoothInterface), init, Loading Loading @@ -496,4 +502,5 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = { interop_database_add, get_avrcp_service, obfuscate_address, get_metric_id, };
system/common/metric_id_allocator.cc +6 −6 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ namespace bluetooth { namespace common { const std::string MetricIdAllocator::LOG_TAG = "BluetoothMetricIdAllocator"; const std::string MetricIdAllocator::LOGGING_TAG = "BluetoothMetricIdAllocator"; const size_t MetricIdAllocator::kMaxNumUnpairedDevicesInMemory = 200; const size_t MetricIdAllocator::kMaxNumPairedDevicesInMemory = 400; const int MetricIdAllocator::kMinId = 1; Loading @@ -42,11 +42,11 @@ static_assert((MetricIdAllocator::kMaxNumUnpairedDevicesInMemory + "kMaxNumPairedDevicesInMemory + MaxNumUnpairedDevicesInMemory"); MetricIdAllocator::MetricIdAllocator() : paired_device_cache_(kMaxNumPairedDevicesInMemory, LOG_TAG, : paired_device_cache_(kMaxNumPairedDevicesInMemory, LOGGING_TAG, [this](RawAddress dummy, int to_remove) { this->id_set_.erase(to_remove); }), temporary_device_cache_(kMaxNumUnpairedDevicesInMemory, LOG_TAG, temporary_device_cache_(kMaxNumUnpairedDevicesInMemory, LOGGING_TAG, [this](RawAddress dummy, int to_remove) { this->id_set_.erase(to_remove); }) {} Loading @@ -62,7 +62,7 @@ bool MetricIdAllocator::Init( // init paired_devices_map if (paired_device_map.size() > kMaxNumPairedDevicesInMemory) { LOG(FATAL) << LOG_TAG << LOGGING_TAG << "Paired device map is bigger than kMaxNumPairedDevicesInMemory"; // fail loudly to let caller know return false; Loading @@ -71,7 +71,7 @@ bool MetricIdAllocator::Init( next_id_ = kMinId; for (const std::pair<RawAddress, int>& p : paired_device_map) { if (p.second < kMinId || p.second > kMaxId) { LOG(FATAL) << LOG_TAG << "Invalid Bluetooth Metric Id in config"; LOG(FATAL) << LOGGING_TAG << "Invalid Bluetooth Metric Id in config"; } paired_device_cache_.Put(p.first, p.second); id_set_.insert(p.second); Loading Loading @@ -130,7 +130,7 @@ int MetricIdAllocator::AllocateId(const RawAddress& mac_address) { next_id_++; if (next_id_ > kMaxId) { next_id_ = kMinId; LOG(WARNING) << LOG_TAG << "Bluetooth metric id overflow."; LOG(WARNING) << LOGGING_TAG << "Bluetooth metric id overflow."; } } id = next_id_++; Loading
system/common/metric_id_allocator.h +1 −1 Original line number Diff line number Diff line Loading @@ -107,7 +107,7 @@ class MetricIdAllocator { MetricIdAllocator(); private: static const std::string LOG_TAG; static const std::string LOGGING_TAG; mutable std::mutex id_allocator_mutex_; LruCache<RawAddress, int> paired_device_cache_; Loading
system/include/hardware/bluetooth.h +8 −0 Original line number Diff line number Diff line Loading @@ -625,6 +625,14 @@ typedef struct { * @return a string of uint8_t that is unique to this MAC address */ std::string (*obfuscate_address)(const RawAddress& address); /** * Get an incremental id for as primary key for Bluetooth metric and log * * @param address Bluetooth MAC address of Bluetooth device * @return int incremental Bluetooth id */ int (*get_metric_id)(const RawAddress& address); } bt_interface_t; #define BLUETOOTH_INTERFACE_STRING "bluetoothInterface" Loading
system/service/hal/fake_bluetooth_interface.cc +1 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,7 @@ bt_interface_t fake_bt_iface = { nullptr, /* interop_database_add */ nullptr, /* get_avrcp_service */ nullptr, /* obfuscate_address */ nullptr, /* get_metric_id */ }; } // namespace Loading