Skip to content
Snippets Groups Projects
Commit 7c6713b8 authored by Chen Chen's avatar Chen Chen
Browse files

BluetoothMetricid: Add metric allocator api in java

Bug: 142563377
Test: Manual atest AdapterServiceTest

Change-Id: I46d1c1d5bf0c8beea1f46b1024cbd5ceb9c0b562
Merged-In: I46d1c1d5bf0c8beea1f46b1024cbd5ceb9c0b562
(cherry picked from commit 35292e66ecf1508ee64ef76ae297245fb157ff54)
parent 06793fb2
No related branches found
No related tags found
No related merge requests found
......@@ -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"
......@@ -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,
......@@ -496,4 +502,5 @@ EXPORT_SYMBOL bt_interface_t bluetoothInterface = {
interop_database_add,
get_avrcp_service,
obfuscate_address,
get_metric_id,
};
......@@ -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;
......@@ -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);
}) {}
......@@ -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;
......@@ -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);
......@@ -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_++;
......
......@@ -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_;
......
......@@ -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"
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment