summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
Diffstat (limited to 'system')
-rw-r--r--system/BUILD.gn1
-rw-r--r--system/OWNERS18
-rw-r--r--system/bta/Android.bp72
-rw-r--r--system/bta/BUILD.gn1
-rw-r--r--system/bta/dm/bta_dm_act.cc2
-rw-r--r--system/bta/dm/bta_dm_disc.cc9
-rw-r--r--system/bta/dm/bta_dm_int.h4
-rw-r--r--system/bta/gatt/bta_gattc_act.cc272
-rw-r--r--system/bta/gatt/bta_gattc_utils.cc266
-rw-r--r--system/bta/hearing_aid/OWNERS1
-rw-r--r--system/bta/hearing_aid/hearing_aid_test.cc474
-rw-r--r--system/bta/include/OWNERS1
-rw-r--r--system/bta/le_audio/OWNERS1
-rw-r--r--system/bta/le_audio/broadcaster/broadcaster_test.cc9
-rw-r--r--system/bta/le_audio/codec_manager_test.cc14
-rw-r--r--system/bta/le_audio/devices_test.cc7
-rw-r--r--system/bta/le_audio/le_audio_client_test.cc13
-rw-r--r--system/bta/le_audio/metrics_collector.cc6
-rw-r--r--system/bta/le_audio/metrics_collector_test.cc10
-rw-r--r--system/bta/le_audio/state_machine_test.cc7
-rw-r--r--system/bta/test/bta_ag_sco_test.cc6
-rw-r--r--system/bta/test/bta_ag_test.cc6
-rw-r--r--system/bta/test/bta_dm_test.cc11
-rw-r--r--system/bta/test/bta_sdp_test.cc11
-rw-r--r--system/bta/test/bta_test_fixtures.h6
-rw-r--r--system/bta/test/common/btif_storage_mock.cc15
-rw-r--r--system/bta/test/common/btif_storage_mock.h12
-rw-r--r--system/btif/src/OWNERS1
-rw-r--r--system/btif/src/btif_a2dp_source.cc8
-rw-r--r--system/btif/src/btif_dm.cc10
-rw-r--r--system/btif/src/btif_hf.cc12
-rw-r--r--system/btif/test/btif_core_test.cc27
-rw-r--r--system/common/Android.bp11
-rw-r--r--system/common/BUILD.gn3
-rw-r--r--system/common/metrics.cc433
-rw-r--r--system/common/metrics.h272
-rw-r--r--system/common/metrics_linux.cc111
-rw-r--r--system/conf/interop_database.conf5
-rw-r--r--system/device/include/interop.h10
-rw-r--r--system/device/src/interop.cc1
-rw-r--r--system/gd/Android.bp10
-rw-r--r--system/gd/common/audit_log.cc6
-rw-r--r--system/gd/hal/hci_hal_android_test.cc8
-rw-r--r--system/gd/hal/hci_hal_host_test.cc8
-rw-r--r--system/gd/hal/snoop_logger.h8
-rw-r--r--system/gd/hci/acl_manager.cc15
-rw-r--r--system/gd/hci/acl_manager.h7
-rw-r--r--system/gd/hci/acl_manager/le_impl.h43
-rw-r--r--system/gd/hci/acl_manager/le_impl_test.cc23
-rw-r--r--system/gd/hci/acl_manager/round_robin_scheduler.cc10
-rw-r--r--system/gd/hci/acl_manager/round_robin_scheduler_test.cc3
-rw-r--r--system/gd/hci/controller.cc4
-rw-r--r--system/gd/hci/distance_measurement_manager.cc108
-rw-r--r--system/gd/hci/distance_measurement_manager_test.cc286
-rw-r--r--system/gd/hci/le_address_manager.cc58
-rw-r--r--system/gd/hci/le_advertising_manager.cc171
-rw-r--r--system/gd/metrics/chromeos/OWNERS1
-rw-r--r--system/gd/metrics/counter_metrics.h9
-rw-r--r--system/gd/metrics/linux/OWNERS1
-rw-r--r--system/gd/module.cc31
-rw-r--r--system/gd/module.h6
-rw-r--r--system/gd/module_unittest.cc6
-rw-r--r--system/gd/os/android/metrics.cc56
-rw-r--r--system/gd/os/chromeos/metrics.cc14
-rw-r--r--system/gd/os/host/metrics.cc14
-rw-r--r--system/gd/os/linux/metrics.cc15
-rw-r--r--system/gd/os/linux_generic/alarm.cc6
-rw-r--r--system/gd/os/metrics.h17
-rw-r--r--system/gd/rust/linux/OWNERS1
-rw-r--r--system/gd/rust/topshim/OWNERS1
-rw-r--r--system/gd/storage/storage_module.cc7
-rw-r--r--system/include/hardware/bluetooth_headset_interface.h3
-rw-r--r--system/linux_include/log/log.h24
-rw-r--r--system/log/OWNERS1
-rw-r--r--system/main/shim/acl.cc11
-rw-r--r--system/main/shim/acl.h2
-rw-r--r--system/main/shim/acl_api.cc6
-rw-r--r--system/main/shim/acl_api.h2
-rw-r--r--system/main/shim/stack.cc50
-rw-r--r--system/main/test/main_shim_test.cc13
-rw-r--r--system/osi/BUILD.gn1
-rw-r--r--system/stack/Android.bp35
-rw-r--r--system/stack/BUILD.gn3
-rw-r--r--system/stack/acl/btm_acl.cc8
-rw-r--r--system/stack/btm/btm_ble_sec.cc24
-rw-r--r--system/stack/btm/btm_dev.cc6
-rw-r--r--system/stack/btm/btm_sco.cc5
-rw-r--r--system/stack/btm/btm_sec.cc35
-rw-r--r--system/stack/btm/security_event_parser.cc23
-rw-r--r--system/stack/btu/btu_hcif.cc135
-rw-r--r--system/stack/fuzzers/l2cap_fuzzer.cc20
-rw-r--r--system/stack/gatt/gatt_api.cc91
-rw-r--r--system/stack/gatt/gatt_auth.cc15
-rw-r--r--system/stack/gatt/gatt_cl.cc49
-rw-r--r--system/stack/gatt/gatt_main.cc117
-rw-r--r--system/stack/gatt/gatt_sr.cc46
-rw-r--r--system/stack/gatt/gatt_utils.cc192
-rw-r--r--system/stack/hid/hidd_api.cc48
-rw-r--r--system/stack/hid/hidd_conn.cc33
-rw-r--r--system/stack/hid/hidh_api.cc30
-rw-r--r--system/stack/hid/hidh_conn.cc22
-rw-r--r--system/stack/include/l2cap_interface.h15
-rw-r--r--system/stack/include/stack_metrics_logging.h69
-rw-r--r--system/stack/l2cap/internal/l2c_api.h14
-rw-r--r--system/stack/l2cap/l2c_api.h2
-rw-r--r--system/stack/l2cap/l2c_ble.cc9
-rw-r--r--system/stack/l2cap/l2c_ble_conn_params.cc20
-rw-r--r--system/stack/l2cap/l2cap_api.cc7
-rw-r--r--system/stack/metrics/stack_metrics_logging.cc101
-rw-r--r--system/stack/mmc/OWNERS1
-rw-r--r--system/stack/mmc/metrics/mmc_rtt_logger.cc5
-rw-r--r--system/stack/rfcomm/port_rfc.cc41
-rw-r--r--system/stack/sdp/sdp_utils.cc38
-rw-r--r--system/stack/smp/smp_l2c.cc7
-rw-r--r--system/stack/smp/smp_utils.cc10
-rw-r--r--system/stack/test/btm/stack_btm_power_mode_test.cc9
-rw-r--r--system/stack/test/btm/stack_btm_sec_test.cc5
-rw-r--r--system/stack/test/btm/stack_btm_test.cc39
-rw-r--r--system/stack/test/btm_iso_test.cc21
-rw-r--r--system/stack/test/connection_manager_test.cc59
-rw-r--r--system/stack/test/eatt/eatt_test.cc9
-rw-r--r--system/stack/test/gatt/gatt_sr_test.cc22
-rw-r--r--system/stack/test/sdp/stack_sdp_test.cc2
-rw-r--r--system/stack/test/stack_acl_test.cc6
-rw-r--r--system/stack/test/stack_l2cap_test.cc14
-rw-r--r--system/test/Android.bp16
-rw-r--r--system/test/README.md81
-rw-r--r--system/test/mock/mock_bta_hearing_aid_audio_source.cc43
-rw-r--r--system/test/mock/mock_main_shim_acl.cc6
-rw-r--r--system/test/mock/mock_main_shim_acl_api.cc6
-rw-r--r--system/test/mock/mock_main_shim_acl_api.h15
-rw-r--r--system/test/mock/mock_main_shim_entry.cc12
-rw-r--r--system/test/mock/mock_main_shim_entry.h9
-rw-r--r--system/test/mock/mock_stack_gap_conn_interface.cc (renamed from system/test/mock/mock_stack_gap_conn.cc)53
-rw-r--r--system/test/mock/mock_stack_gap_conn_interface.h63
-rw-r--r--system/test/mock/mock_stack_l2cap_interface.h3
-rw-r--r--system/test/mock/mock_stack_metrics_logging.cc151
-rw-r--r--system/test/mock/mock_stack_metrics_logging.h254
138 files changed, 2173 insertions, 3226 deletions
diff --git a/system/BUILD.gn b/system/BUILD.gn
index 4f541bbab5..1d6325e6d9 100644
--- a/system/BUILD.gn
+++ b/system/BUILD.gn
@@ -75,7 +75,6 @@ config("target_defaults") {
"//bt/system",
"//bt/flags/exported_include",
"//bt/sysprop/exported_include",
- "//bt/system/linux_include",
"//bt/system/include",
"//bt/system/gd",
"//bt/system/pdl/hci/include",
diff --git a/system/OWNERS b/system/OWNERS
deleted file mode 100644
index b2acb91716..0000000000
--- a/system/OWNERS
+++ /dev/null
@@ -1,18 +0,0 @@
-# Reviewers for /system
-
-bhaktha@google.com
-eruffieux@google.com
-hallstrom@google.com
-henrichataing@google.com
-jpawlowski@google.com
-okamil@google.com
-poahlo@google.com
-rongxuan@google.com
-rwt@google.com
-wescande@google.com
-
-# Reviewers for Channel Sounding related files
-per-file /bta/ras/*=file:/OWNERS_channel_sounding
-per-file /gd/hal/ranging_hal*=file:/OWNERS_channel_sounding
-per-file /gd/hci/distance_measurement_*=file:/OWNERS_channel_sounding
-per-file /main/shim/distance_measurement_manager*=file:/OWNERS_channel_sounding
diff --git a/system/bta/Android.bp b/system/bta/Android.bp
index 52d34d59cc..22074caf65 100644
--- a/system/bta/Android.bp
+++ b/system/bta/Android.bp
@@ -231,6 +231,7 @@ cc_test {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackA2dp",
":TestMockStackAcl",
@@ -243,7 +244,6 @@ cc_test {
":TestMockStackGatt",
":TestMockStackHid",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackPan",
":TestMockStackRfcomm",
":TestMockStackRnr",
@@ -339,10 +339,10 @@ cc_test {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackBtm",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"test/gatt/database_builder_sample_device_test.cc",
"test/gatt/database_builder_test.cc",
"test/gatt/database_test.cc",
@@ -1347,6 +1347,74 @@ cc_test {
}
cc_test {
+ name: "bluetooth_hearing_aid_test",
+ test_suites: ["general-tests"],
+ defaults: [
+ "fluoride_bta_defaults",
+ "mts_defaults",
+ ],
+ host_supported: true,
+ include_dirs: [
+ "packages/modules/Bluetooth/system",
+ "packages/modules/Bluetooth/system/bta/include",
+ "packages/modules/Bluetooth/system/bta/test/common",
+ "packages/modules/Bluetooth/system/stack/include",
+ ],
+ srcs: [
+ ":TestCommonMockFunctions",
+ ":TestMockBtaHearingAidAudioSource",
+ ":TestMockDevice",
+ ":TestMockMainShim",
+ ":TestMockMainShimEntry",
+ ":TestMockStackBtmInterface",
+ ":TestMockStackBtmIso",
+ ":TestMockStackGapConnInterface",
+ ":TestMockStackL2cap",
+ ":TestStubOsi",
+ "gatt/database.cc",
+ "gatt/database_builder.cc",
+ "hearing_aid/hearing_aid.cc",
+ "hearing_aid/hearing_aid_test.cc",
+ "test/common/bta_gatt_api_mock.cc",
+ "test/common/bta_gatt_queue_mock.cc",
+ "test/common/btif_storage_mock.cc",
+ "test/common/btm_api_mock.cc",
+ ],
+ shared_libs: [
+ "libbase",
+ "libcrypto",
+ "liblog",
+ ],
+ static_libs: [
+ "bluetooth_flags_c_lib_for_test",
+ "libaconfig_storage_read_api_cc",
+ "libbluetooth-types",
+ "libbluetooth_crypto_toolbox",
+ "libbluetooth_gd",
+ "libbluetooth_log",
+ "libbt-audio-asrc",
+ "libbt-btu-main-thread",
+ "libbt-common",
+ "libbt-platform-protos-lite",
+ "libchrome",
+ "libevent",
+ "libg722codec",
+ "libgmock",
+ "server_configurable_flags",
+ ],
+ sanitize: {
+ cfi: true,
+ scs: true,
+ address: true,
+ all_undefined: true,
+ integer_overflow: true,
+ diag: {
+ undefined: true,
+ },
+ },
+}
+
+cc_test {
name: "bluetooth_hh_test",
test_suites: ["general-tests"],
defaults: [
diff --git a/system/bta/BUILD.gn b/system/bta/BUILD.gn
index 9c28016617..f621539151 100644
--- a/system/bta/BUILD.gn
+++ b/system/bta/BUILD.gn
@@ -143,7 +143,6 @@ static_library("bta") {
"sys",
"//bt/system/",
"//bt/system/include",
- "//bt/system/linux_include",
"//bt/system/bta",
"//bt/system/bta/aics/include",
"//bt/system/gd",
diff --git a/system/bta/dm/bta_dm_act.cc b/system/bta/dm/bta_dm_act.cc
index 48e0f16c99..ddc481171f 100644
--- a/system/bta/dm/bta_dm_act.cc
+++ b/system/bta/dm/bta_dm_act.cc
@@ -545,7 +545,7 @@ void bta_dm_remove_device(const RawAddress& target) {
if (le_connected || bredr_connected) {
// Wait for all transports to be disconnected
- tBTA_DM_REMOVE_PENDNIG node = {pseudo_addr, identity_addr, le_connected, bredr_connected};
+ tBTA_DM_REMOVE_PENDING node = {pseudo_addr, identity_addr, le_connected, bredr_connected};
bta_dm_cb.pending_removals.push_back(node);
log::info(
"Waiting for disconnection over LE:{}, BR/EDR:{} for pseudo address: {}, identity "
diff --git a/system/bta/dm/bta_dm_disc.cc b/system/bta/dm/bta_dm_disc.cc
index b3f010e86e..79d3421361 100644
--- a/system/bta/dm/bta_dm_disc.cc
+++ b/system/bta/dm/bta_dm_disc.cc
@@ -152,8 +152,7 @@ gatt_interface_t& get_gatt_interface() { return *gatt_interface; }
void bta_dm_disc_gatt_cancel_open(const RawAddress& bd_addr) {
get_gatt_interface().BTA_GATTC_CancelOpen(0, bd_addr, false);
- if (com::android::bluetooth::flags::cancel_open_discovery_client() &&
- bta_dm_discovery_cb.client_if != BTA_GATTS_INVALID_IF) {
+ if (bta_dm_discovery_cb.client_if != BTA_GATTS_INVALID_IF) {
get_gatt_interface().BTA_GATTC_CancelOpen(bta_dm_discovery_cb.client_if, bd_addr, true);
}
}
@@ -559,11 +558,7 @@ static void bta_dm_gatt_disc_complete(tCONN_ID conn_id, tGATT_STATUS status) {
} else {
log::info("Discovery complete for invalid conn ID. Will pick up next job");
- if (com::android::bluetooth::flags::cancel_open_discovery_client()) {
- bta_dm_close_gatt_conn(bta_dm_discovery_cb.conn_id);
- } else {
- bta_dm_discovery_cb.conn_id = GATT_INVALID_CONN_ID;
- }
+ bta_dm_close_gatt_conn(bta_dm_discovery_cb.conn_id);
if (bta_dm_discovery_cb.transports & BT_TRANSPORT_BR_EDR) {
log::info("classic discovery still pending {}", bta_dm_discovery_cb.peer_bdaddr);
return;
diff --git a/system/bta/dm/bta_dm_int.h b/system/bta/dm/bta_dm_int.h
index 521a8072de..26f7e4d97c 100644
--- a/system/bta/dm/bta_dm_int.h
+++ b/system/bta/dm/bta_dm_int.h
@@ -81,7 +81,7 @@ inline std::string device_info_text(tBTA_DM_DEV_INFO info) {
#define BTA_DM_PM_EXECUTE 3
typedef uint8_t tBTA_DM_PM_REQ;
-struct tBTA_DM_REMOVE_PENDNIG {
+struct tBTA_DM_REMOVE_PENDING {
RawAddress pseudo_addr;
RawAddress identity_addr;
bool le_connected;
@@ -215,7 +215,7 @@ typedef struct {
#endif
alarm_t* switch_delay_timer;
- std::list<tBTA_DM_REMOVE_PENDNIG> pending_removals;
+ std::list<tBTA_DM_REMOVE_PENDING> pending_removals;
} tBTA_DM_CB;
/* DI control block */
diff --git a/system/bta/gatt/bta_gattc_act.cc b/system/bta/gatt/bta_gattc_act.cc
index 3b6069b1a1..346d7c3d6a 100644
--- a/system/bta/gatt/bta_gattc_act.cc
+++ b/system/bta/gatt/bta_gattc_act.cc
@@ -132,28 +132,17 @@ void bta_gattc_disable() {
return;
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (!bta_gattc_cb.cl_rcb_map.empty()) {
- bta_gattc_cb.state = BTA_GATTC_STATE_DISABLING;
- }
-
- // An entry can be erased during deregister, use a copied collection
- std::vector<tGATT_IF> gatt_ifs;
- for (auto& [gatt_if, p_rcb] : bta_gattc_cb.cl_rcb_map) {
- gatt_ifs.push_back(gatt_if);
- }
- for (auto& gatt_if : gatt_ifs) {
- bta_gattc_deregister(bta_gattc_cb.cl_rcb_map[gatt_if].get());
- }
- } else {
- for (i = 0; i < BTA_GATTC_CL_MAX; i++) {
- if (!bta_gattc_cb.cl_rcb[i].in_use) {
- continue;
- }
+ if (!bta_gattc_cb.cl_rcb_map.empty()) {
+ bta_gattc_cb.state = BTA_GATTC_STATE_DISABLING;
+ }
- bta_gattc_cb.state = BTA_GATTC_STATE_DISABLING;
- bta_gattc_deregister(&bta_gattc_cb.cl_rcb[i]);
- }
+ // An entry can be erased during deregister, use a copied collection
+ std::vector<tGATT_IF> gatt_ifs;
+ for (auto& [gatt_if, p_rcb] : bta_gattc_cb.cl_rcb_map) {
+ gatt_ifs.push_back(gatt_if);
+ }
+ for (auto& gatt_if : gatt_ifs) {
+ bta_gattc_deregister(bta_gattc_cb.cl_rcb_map[gatt_if].get());
}
/* no registered apps, indicate disable completed */
@@ -187,55 +176,25 @@ void bta_gattc_register(const Uuid& app_uuid, const std::string& name, tBTA_GATT
bta_gattc_enable();
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- client_if = GATT_Register(app_uuid, name, &bta_gattc_cl_cback, eatt_support);
- if (client_if == 0) {
- log::error("Register with GATT stack failed");
- status = GATT_ERROR;
- } else {
- auto p_rcb = std::make_unique<tBTA_GATTC_RCB>();
- p_rcb->in_use = true;
- p_rcb->p_cback = p_cback;
- p_rcb->app_uuid = app_uuid;
- p_rcb->client_if = client_if;
- bta_gattc_cb.cl_rcb_map.emplace(client_if, std::move(p_rcb));
-
- log::debug(
- "Registered GATT client interface {} with uuid={}, starting it on "
- "main thread",
- client_if, app_uuid.ToString());
-
- do_in_main_thread(base::BindOnce(&bta_gattc_start_if, client_if));
- status = GATT_SUCCESS;
- }
+ client_if = GATT_Register(app_uuid, name, &bta_gattc_cl_cback, eatt_support);
+ if (client_if == 0) {
+ log::error("Register with GATT stack failed");
+ status = GATT_ERROR;
} else {
- for (uint8_t i = 0; i < BTA_GATTC_CL_MAX; i++) {
- if (!bta_gattc_cb.cl_rcb[i].in_use) {
- bta_gattc_cb.cl_rcb[i].client_if =
- GATT_Register(app_uuid, "GattClient", &bta_gattc_cl_cback, eatt_support);
- if (bta_gattc_cb.cl_rcb[i].client_if == 0) {
- log::error("Register with GATT stack failed with index {}, trying next index", i);
- status = GATT_ERROR;
- } else {
- bta_gattc_cb.cl_rcb[i].in_use = true;
- bta_gattc_cb.cl_rcb[i].p_cback = p_cback;
- bta_gattc_cb.cl_rcb[i].app_uuid = app_uuid;
-
- /* BTA use the same client interface as BTE GATT statck */
- client_if = bta_gattc_cb.cl_rcb[i].client_if;
-
- log::debug(
- "Registered GATT client interface {} with uuid={}, starting it on "
- "main thread",
- client_if, app_uuid.ToString());
-
- do_in_main_thread(base::BindOnce(&bta_gattc_start_if, client_if));
-
- status = GATT_SUCCESS;
- break;
- }
- }
- }
+ auto p_rcb = std::make_unique<tBTA_GATTC_RCB>();
+ p_rcb->in_use = true;
+ p_rcb->p_cback = p_cback;
+ p_rcb->app_uuid = app_uuid;
+ p_rcb->client_if = client_if;
+ bta_gattc_cb.cl_rcb_map.emplace(client_if, std::move(p_rcb));
+
+ log::debug(
+ "Registered GATT client interface {} with uuid={}, starting it on "
+ "main thread",
+ client_if, app_uuid.ToString());
+
+ do_in_main_thread(base::BindOnce(&bta_gattc_start_if, client_if));
+ status = GATT_SUCCESS;
}
if (!cb.is_null()) {
@@ -258,26 +217,13 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) {
continue;
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (bta_gattc_cb.bg_track[i].cif_set.contains(p_clreg->client_if)) {
- bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
- if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) {
- log::warn(
- "Unable to cancel GATT connection client_if:{} peer:{} "
- "is_direct:{}",
- p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
- }
- }
- } else {
- if (bta_gattc_cb.bg_track[i].cif_mask &
- ((tBTA_GATTC_CIF_MASK)1 << (p_clreg->client_if - 1))) {
- bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
- if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) {
- log::warn(
- "Unable to cancel GATT connection client_if:{} peer:{} "
- "is_direct:{}",
- p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
- }
+ if (bta_gattc_cb.bg_track[i].cif_set.contains(p_clreg->client_if)) {
+ bta_gattc_mark_bg_conn(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
+ if (!GATT_CancelConnect(p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false)) {
+ log::warn(
+ "Unable to cancel GATT connection client_if:{} peer:{} "
+ "is_direct:{}",
+ p_clreg->client_if, bta_gattc_cb.bg_track[i].remote_bda, false);
}
}
}
@@ -288,38 +234,23 @@ void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) {
}
/* close all CLCB related to this app */
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb : bta_gattc_cb.clcb_set) {
- if (!p_clcb->in_use || p_clcb->p_rcb != p_clreg) {
- continue;
- }
- p_clreg->dereg_pending = true;
-
- tBTA_GATTC_DATA gattc_data = {
- .hdr =
- {
- .event = BTA_GATTC_API_CLOSE_EVT,
- .layer_specific = static_cast<uint16_t>(p_clcb->bta_conn_id),
- },
- };
- bta_gattc_close(p_clcb.get(), &gattc_data);
- }
- // deallocated clcbs will not be accessed. Let them be claened up.
- bta_gattc_cleanup_clcb();
- } else {
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
- if (!bta_gattc_cb.clcb[i].in_use || (bta_gattc_cb.clcb[i].p_rcb != p_clreg)) {
- continue;
- }
-
- p_clreg->dereg_pending = true;
-
- BT_HDR_RIGID buf;
- buf.event = BTA_GATTC_API_CLOSE_EVT;
- buf.layer_specific = static_cast<uint16_t>(bta_gattc_cb.clcb[i].bta_conn_id);
- bta_gattc_close(&bta_gattc_cb.clcb[i], (tBTA_GATTC_DATA*)&buf);
+ for (auto& p_clcb : bta_gattc_cb.clcb_set) {
+ if (!p_clcb->in_use || p_clcb->p_rcb != p_clreg) {
+ continue;
}
+ p_clreg->dereg_pending = true;
+
+ tBTA_GATTC_DATA gattc_data = {
+ .hdr =
+ {
+ .event = BTA_GATTC_API_CLOSE_EVT,
+ .layer_specific = static_cast<uint16_t>(p_clcb->bta_conn_id),
+ },
+ };
+ bta_gattc_close(p_clcb.get(), &gattc_data);
}
+ // deallocated clcbs will not be accessed. Let them be claened up.
+ bta_gattc_cleanup_clcb();
}
/** process connect API request */
@@ -736,21 +667,12 @@ void bta_gattc_close(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data) {
/** when a SRCB finished discovery, tell all related clcb */
void bta_gattc_reset_discover_st(tBTA_GATTC_SERV* p_srcb, tGATT_STATUS status) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb : bta_gattc_cb.clcb_set) {
- if (p_clcb->p_srcb != p_srcb) {
- continue;
- }
- p_clcb->status = status;
- bta_gattc_sm_execute(p_clcb.get(), BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
- }
- } else {
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
- if (bta_gattc_cb.clcb[i].p_srcb == p_srcb) {
- bta_gattc_cb.clcb[i].status = status;
- bta_gattc_sm_execute(&bta_gattc_cb.clcb[i], BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
- }
+ for (auto& p_clcb : bta_gattc_cb.clcb_set) {
+ if (p_clcb->p_srcb != p_srcb) {
+ continue;
}
+ p_clcb->status = status;
+ bta_gattc_sm_execute(p_clcb.get(), BTA_GATTC_DISCOVER_CMPL_EVT, NULL);
}
}
@@ -777,23 +699,13 @@ void bta_gattc_disc_close(tBTA_GATTC_CLCB* p_clcb, const tBTA_GATTC_DATA* p_data
/** when a SRCB start discovery, tell all related clcb and set the state */
static void bta_gattc_set_discover_st(tBTA_GATTC_SERV* p_srcb) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb : bta_gattc_cb.clcb_set) {
- if (p_clcb->p_srcb != p_srcb) {
- continue;
- }
- p_clcb->status = GATT_SUCCESS;
- p_clcb->state = BTA_GATTC_DISCOVER_ST;
- p_clcb->request_during_discovery = BTA_GATTC_DISCOVER_REQ_NONE;
- }
- } else {
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
- if (bta_gattc_cb.clcb[i].p_srcb == p_srcb) {
- bta_gattc_cb.clcb[i].status = GATT_SUCCESS;
- bta_gattc_cb.clcb[i].state = BTA_GATTC_DISCOVER_ST;
- bta_gattc_cb.clcb[i].request_during_discovery = BTA_GATTC_DISCOVER_REQ_NONE;
- }
+ for (auto& p_clcb : bta_gattc_cb.clcb_set) {
+ if (p_clcb->p_srcb != p_srcb) {
+ continue;
}
+ p_clcb->status = GATT_SUCCESS;
+ p_clcb->state = BTA_GATTC_DISCOVER_ST;
+ p_clcb->request_during_discovery = BTA_GATTC_DISCOVER_REQ_NONE;
}
}
@@ -1422,12 +1334,8 @@ static void bta_gattc_deregister_cmpl(tBTA_GATTC_RCB* p_clreg) {
memset(&cb_data, 0, sizeof(tBTA_GATTC));
GATT_Deregister(p_clreg->client_if);
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (bta_gattc_cb.cl_rcb_map.erase(p_clreg->client_if) == 0) {
- log::warn("deregistered unknown rcb client_if={}", p_clreg->client_if);
- }
- } else {
- memset(p_clreg, 0, sizeof(tBTA_GATTC_RCB));
+ if (bta_gattc_cb.cl_rcb_map.erase(p_clreg->client_if) == 0) {
+ log::warn("deregistered unknown rcb client_if={}", p_clreg->client_if);
}
cb_data.reg_oper.client_if = client_if;
@@ -1490,20 +1398,11 @@ void bta_gattc_process_api_refresh(const RawAddress& remote_bda) {
if (p_srvc_cb->connected && p_srvc_cb->num_clcb != 0) {
bool found = false;
tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[0];
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb_i : bta_gattc_cb.clcb_set) {
- if (p_clcb_i->in_use && p_clcb_i->p_srcb == p_srvc_cb) {
- p_clcb = p_clcb_i.get();
- found = true;
- break;
- }
- }
- } else {
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
- if (p_clcb->in_use && p_clcb->p_srcb == p_srvc_cb) {
- found = true;
- break;
- }
+ for (auto& p_clcb_i : bta_gattc_cb.clcb_set) {
+ if (p_clcb_i->in_use && p_clcb_i->p_srcb == p_srvc_cb) {
+ p_clcb = p_clcb_i.get();
+ found = true;
+ break;
}
}
if (found) {
@@ -1563,38 +1462,19 @@ static bool bta_gattc_process_srvc_chg_ind(tCONN_ID conn_id, tBTA_GATTC_RCB* p_c
/* not an opened connection; or connection busy */
/* search for first available clcb and start discovery */
if (p_clcb == NULL || (p_clcb && p_clcb->p_q_cmd != NULL)) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb_i : bta_gattc_cb.clcb_set) {
- if (p_clcb_i->in_use && p_clcb_i->p_srcb == p_srcb && p_clcb_i->p_q_cmd == NULL) {
- p_clcb = p_clcb_i.get();
- break;
- }
- }
- } else {
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
- if (bta_gattc_cb.clcb[i].in_use && bta_gattc_cb.clcb[i].p_srcb == p_srcb &&
- bta_gattc_cb.clcb[i].p_q_cmd == NULL) {
- p_clcb = &bta_gattc_cb.clcb[i];
- break;
- }
+ for (auto& p_clcb_i : bta_gattc_cb.clcb_set) {
+ if (p_clcb_i->in_use && p_clcb_i->p_srcb == p_srcb && p_clcb_i->p_q_cmd == NULL) {
+ p_clcb = p_clcb_i.get();
+ break;
}
}
}
// Use a busy CLCB to start discovery if no CLCB is available, this will be queued.
if (com::android::bluetooth::flags::start_discover_service_changed() && p_clcb == NULL) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb_i : bta_gattc_cb.clcb_set) {
- if (p_clcb_i->in_use && p_clcb_i->p_srcb == p_srcb) {
- p_clcb = p_clcb_i.get();
- break;
- }
- }
- } else {
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
- if (bta_gattc_cb.clcb[i].in_use && bta_gattc_cb.clcb[i].p_srcb == p_srcb) {
- p_clcb = &bta_gattc_cb.clcb[i];
- break;
- }
+ for (auto& p_clcb_i : bta_gattc_cb.clcb_set) {
+ if (p_clcb_i->in_use && p_clcb_i->p_srcb == p_srcb) {
+ p_clcb = p_clcb_i.get();
+ break;
}
}
}
diff --git a/system/bta/gatt/bta_gattc_utils.cc b/system/bta/gatt/bta_gattc_utils.cc
index 23b150b829..523cf90fe5 100644
--- a/system/bta/gatt/bta_gattc_utils.cc
+++ b/system/bta/gatt/bta_gattc_utils.cc
@@ -25,7 +25,6 @@
#define LOG_TAG "bt_bta_gattc"
#include <bluetooth/log.h>
-#include <com_android_bluetooth_flags.h>
#include <cstdint>
@@ -58,23 +57,11 @@ static uint8_t ble_acceptlist_size() {
*
******************************************************************************/
tBTA_GATTC_RCB* bta_gattc_cl_get_regcb(uint8_t client_if) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- auto it = bta_gattc_cb.cl_rcb_map.find(client_if);
- if (it == bta_gattc_cb.cl_rcb_map.end()) {
- return NULL;
- } else {
- return it->second.get();
- }
- } else {
- uint8_t i = 0;
- tBTA_GATTC_RCB* p_clrcb = &bta_gattc_cb.cl_rcb[0];
-
- for (i = 0; i < BTA_GATTC_CL_MAX; i++, p_clrcb++) {
- if (p_clrcb->in_use && p_clrcb->client_if == client_if) {
- return p_clrcb;
- }
- }
+ auto it = bta_gattc_cb.cl_rcb_map.find(client_if);
+ if (it == bta_gattc_cb.cl_rcb_map.end()) {
return NULL;
+ } else {
+ return it->second.get();
}
}
/*******************************************************************************
@@ -86,20 +73,7 @@ tBTA_GATTC_RCB* bta_gattc_cl_get_regcb(uint8_t client_if) {
* Returns pointer to the regcb
*
******************************************************************************/
-uint8_t bta_gattc_num_reg_app(void) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- return (uint8_t)bta_gattc_cb.cl_rcb_map.size();
- } else {
- uint8_t i = 0, j = 0;
-
- for (i = 0; i < BTA_GATTC_CL_MAX; i++) {
- if (bta_gattc_cb.cl_rcb[i].in_use) {
- j++;
- }
- }
- return j;
- }
-}
+uint8_t bta_gattc_num_reg_app(void) { return (uint8_t)bta_gattc_cb.cl_rcb_map.size(); }
/*******************************************************************************
*
* Function bta_gattc_find_clcb_by_cif
@@ -111,21 +85,10 @@ uint8_t bta_gattc_num_reg_app(void) {
******************************************************************************/
tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_cif(uint8_t client_if, const RawAddress& remote_bda,
tBT_TRANSPORT transport) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb : bta_gattc_cb.clcb_set) {
- if (p_clcb->in_use && p_clcb->p_rcb->client_if == client_if &&
- p_clcb->transport == transport && p_clcb->bda == remote_bda) {
- return p_clcb.get();
- }
- }
- } else {
- tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[0];
-
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
- if (p_clcb->in_use && p_clcb->p_rcb->client_if == client_if &&
- p_clcb->transport == transport && p_clcb->bda == remote_bda) {
- return p_clcb;
- }
+ for (auto& p_clcb : bta_gattc_cb.clcb_set) {
+ if (p_clcb->in_use && p_clcb->p_rcb->client_if == client_if && p_clcb->transport == transport &&
+ p_clcb->bda == remote_bda) {
+ return p_clcb.get();
}
}
return NULL;
@@ -140,19 +103,9 @@ tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_cif(uint8_t client_if, const RawAddress&
*
******************************************************************************/
tBTA_GATTC_CLCB* bta_gattc_find_clcb_by_conn_id(tCONN_ID conn_id) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& p_clcb : bta_gattc_cb.clcb_set) {
- if (p_clcb->in_use && p_clcb->bta_conn_id == conn_id) {
- return p_clcb.get();
- }
- }
- } else {
- tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[0];
-
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++, p_clcb++) {
- if (p_clcb->in_use && p_clcb->bta_conn_id == conn_id) {
- return p_clcb;
- }
+ for (auto& p_clcb : bta_gattc_cb.clcb_set) {
+ if (p_clcb != NULL && p_clcb->in_use && p_clcb->bta_conn_id == conn_id) {
+ return p_clcb.get();
}
}
return NULL;
@@ -171,63 +124,30 @@ tBTA_GATTC_CLCB* bta_gattc_clcb_alloc(tGATT_IF client_if, const RawAddress& remo
tBT_TRANSPORT transport) {
tBTA_GATTC_CLCB* p_clcb = NULL;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- bta_gattc_cleanup_clcb();
- auto [p_clcb_i, b] = bta_gattc_cb.clcb_set.emplace(std::make_unique<tBTA_GATTC_CLCB>());
- p_clcb = p_clcb_i->get();
+ bta_gattc_cleanup_clcb();
+ auto [p_clcb_i, b] = bta_gattc_cb.clcb_set.emplace(std::make_unique<tBTA_GATTC_CLCB>());
+ p_clcb = p_clcb_i->get();
- p_clcb->in_use = true;
- p_clcb->status = GATT_SUCCESS;
- p_clcb->transport = transport;
- p_clcb->bda = remote_bda;
- p_clcb->p_q_cmd = NULL;
+ p_clcb->in_use = true;
+ p_clcb->status = GATT_SUCCESS;
+ p_clcb->transport = transport;
+ p_clcb->bda = remote_bda;
+ p_clcb->p_q_cmd = NULL;
- p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if);
+ p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if);
- p_clcb->p_srcb = bta_gattc_find_srcb(remote_bda);
- if (p_clcb->p_srcb == NULL) {
- p_clcb->p_srcb = bta_gattc_srcb_alloc(remote_bda);
- }
+ p_clcb->p_srcb = bta_gattc_find_srcb(remote_bda);
+ if (p_clcb->p_srcb == NULL) {
+ p_clcb->p_srcb = bta_gattc_srcb_alloc(remote_bda);
+ }
- if (p_clcb->p_rcb != NULL && p_clcb->p_srcb != NULL) {
- p_clcb->p_srcb->num_clcb++;
- p_clcb->p_rcb->num_clcb++;
- } else {
- /* release this clcb if clcb or srcb allocation failed */
- bta_gattc_cb.clcb_set.erase(p_clcb_i);
- p_clcb = NULL;
- }
+ if (p_clcb->p_rcb != NULL && p_clcb->p_srcb != NULL) {
+ p_clcb->p_srcb->num_clcb++;
+ p_clcb->p_rcb->num_clcb++;
} else {
- for (int i_clcb = 0; i_clcb < BTA_GATTC_CLCB_MAX; i_clcb++) {
- if (!bta_gattc_cb.clcb[i_clcb].in_use) {
-#if (BTA_GATT_DEBUG == TRUE)
- log::verbose("found clcb:{} available", i_clcb);
-#endif
- p_clcb = &bta_gattc_cb.clcb[i_clcb];
- p_clcb->in_use = true;
- p_clcb->status = GATT_SUCCESS;
- p_clcb->transport = transport;
- p_clcb->bda = remote_bda;
- p_clcb->p_q_cmd = NULL;
-
- p_clcb->p_rcb = bta_gattc_cl_get_regcb(client_if);
-
- p_clcb->p_srcb = bta_gattc_find_srcb(remote_bda);
- if (p_clcb->p_srcb == NULL) {
- p_clcb->p_srcb = bta_gattc_srcb_alloc(remote_bda);
- }
-
- if (p_clcb->p_rcb != NULL && p_clcb->p_srcb != NULL) {
- p_clcb->p_srcb->num_clcb++;
- p_clcb->p_rcb->num_clcb++;
- } else {
- /* release this clcb if clcb or srcb allocation failed */
- p_clcb->in_use = false;
- p_clcb = NULL;
- }
- break;
- }
- }
+ /* release this clcb if clcb or srcb allocation failed */
+ bta_gattc_cb.clcb_set.erase(p_clcb_i);
+ p_clcb = NULL;
}
return p_clcb;
}
@@ -330,9 +250,7 @@ void bta_gattc_clcb_dealloc(tBTA_GATTC_CLCB* p_clcb) {
p_clcb->status = GATT_SUCCESS;
// in bta_gattc_sm_execute(), p_clcb is accessed again so we dealloc clcb later.
// it will be claned up when the client is deregistered or a new clcb is allocated.
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- bta_gattc_cb.clcb_pending_dealloc.insert(p_clcb);
- }
+ bta_gattc_cb.clcb_pending_dealloc.insert(p_clcb);
}
/*******************************************************************************
@@ -643,39 +561,21 @@ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda_ptr
for (i = 0; i < ble_acceptlist_size(); i++, p_bg_tck++) {
if (p_bg_tck->in_use &&
((p_bg_tck->remote_bda == remote_bda_ptr) || (p_bg_tck->remote_bda.IsEmpty()))) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- auto& p_cif_set = p_bg_tck->cif_set;
- if (add) { /* mask on the cif bit */
- p_cif_set.insert(client_if);
- } else {
- if (client_if != 0) {
- p_cif_set.erase(client_if);
- } else {
- p_cif_set.clear();
- }
- }
- /* no BG connection for this device, make it available */
- if (p_bg_tck->cif_set.empty()) {
- p_bg_tck->in_use = false;
- p_bg_tck->remote_bda = RawAddress::kEmpty;
- }
+ auto& p_cif_set = p_bg_tck->cif_set;
+ if (add) { /* mask on the cif bit */
+ p_cif_set.insert(client_if);
} else {
- p_cif_mask = &p_bg_tck->cif_mask;
-
- if (add) { /* mask on the cif bit */
- *p_cif_mask |= (1 << (client_if - 1));
+ if (client_if != 0) {
+ p_cif_set.erase(client_if);
} else {
- if (client_if != 0) {
- *p_cif_mask &= (~(1 << (client_if - 1)));
- } else {
- *p_cif_mask = 0;
- }
- }
- /* no BG connection for this device, make it available */
- if (p_bg_tck->cif_mask == 0) {
- *p_bg_tck = tBTA_GATTC_BG_TCK{};
+ p_cif_set.clear();
}
}
+ /* no BG connection for this device, make it available */
+ if (p_bg_tck->cif_set.empty()) {
+ p_bg_tck->in_use = false;
+ p_bg_tck->remote_bda = RawAddress::kEmpty;
+ }
return true;
}
}
@@ -688,12 +588,7 @@ bool bta_gattc_mark_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda_ptr
p_bg_tck->in_use = true;
p_bg_tck->remote_bda = remote_bda_ptr;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- p_bg_tck->cif_set = {client_if};
- } else {
- p_cif_mask = &p_bg_tck->cif_mask;
- *p_cif_mask = ((tBTA_GATTC_CIF_MASK)1 << (client_if - 1));
- }
+ p_bg_tck->cif_set = {client_if};
return true;
}
}
@@ -719,15 +614,8 @@ bool bta_gattc_check_bg_conn(tGATT_IF client_if, const RawAddress& remote_bda, u
for (i = 0; i < ble_acceptlist_size() && !is_bg_conn; i++, p_bg_tck++) {
if (p_bg_tck->in_use &&
(p_bg_tck->remote_bda == remote_bda || p_bg_tck->remote_bda.IsEmpty())) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (p_bg_tck->cif_set.contains(client_if) && role == HCI_ROLE_CENTRAL) {
- is_bg_conn = true;
- }
- } else {
- if (((p_bg_tck->cif_mask & ((tBTA_GATTC_CIF_MASK)1 << (client_if - 1))) != 0) &&
- role == HCI_ROLE_CENTRAL) {
- is_bg_conn = true;
- }
+ if (p_bg_tck->cif_set.contains(client_if) && role == HCI_ROLE_CENTRAL) {
+ is_bg_conn = true;
}
}
}
@@ -938,58 +826,28 @@ void bta_gatt_client_dump(int fd) {
stream << " -- used: " << entry_count << "\n";
entry_count = 0;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- stream << " ->cl_rcb (dynamic)\n";
- for (auto& [i, p_cl_rcb] : bta_gattc_cb.cl_rcb_map) {
- entry_count++;
- stream << " client_if: " << +p_cl_rcb->client_if << " app uuids: " << p_cl_rcb->app_uuid
- << " clcb_num: " << +p_cl_rcb->num_clcb;
- stream << "\n";
- }
- } else {
- stream << " ->cl_rcb (BTA_GATTC_CL_MAX=" << BTA_GATTC_CL_MAX << ")\n";
- for (int i = 0; i < BTA_GATTC_CL_MAX; i++) {
- tBTA_GATTC_RCB* p_cl_rcb = &bta_gattc_cb.cl_rcb[i];
- if (!p_cl_rcb->in_use) {
- continue;
- }
- entry_count++;
- stream << " client_if: " << +p_cl_rcb->client_if << " app uuids: " << p_cl_rcb->app_uuid
- << " clcb_num: " << +p_cl_rcb->num_clcb;
- stream << "\n";
- }
+ stream << " ->cl_rcb (dynamic)\n";
+ for (auto& [i, p_cl_rcb] : bta_gattc_cb.cl_rcb_map) {
+ entry_count++;
+ stream << " client_if: " << +p_cl_rcb->client_if << " app uuids: " << p_cl_rcb->app_uuid
+ << " clcb_num: " << +p_cl_rcb->num_clcb;
+ stream << "\n";
}
stream << " -- used: " << entry_count << "\n";
entry_count = 0;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- stream << " ->clcb (dynamic)\n";
- for (auto& p_clcb : bta_gattc_cb.clcb_set) {
- if (!p_clcb->in_use) {
- continue;
- }
- entry_count++;
- stream << " conn_id: " << loghex(p_clcb->bta_conn_id)
- << " address: " << p_clcb->bda.ToRedactedStringForLogging()
- << " transport: " << bt_transport_text(p_clcb->transport)
- << " state: " << bta_clcb_state_text(p_clcb->state);
- stream << "\n";
- }
- } else {
- stream << " ->clcb (BTA_GATTC_CLCB_MAX=" << BTA_GATTC_CLCB_MAX << ")\n";
- for (size_t i = 0; i < BTA_GATTC_CLCB_MAX; i++) {
- tBTA_GATTC_CLCB* p_clcb = &bta_gattc_cb.clcb[i];
- if (!p_clcb->in_use) {
- continue;
- }
- entry_count++;
- stream << " conn_id: " << loghex(p_clcb->bta_conn_id)
- << " address: " << p_clcb->bda.ToRedactedStringForLogging()
- << " transport: " << bt_transport_text(p_clcb->transport)
- << " state: " << bta_clcb_state_text(p_clcb->state);
- stream << "\n";
+ stream << " ->clcb (dynamic)\n";
+ for (auto& p_clcb : bta_gattc_cb.clcb_set) {
+ if (!p_clcb->in_use) {
+ continue;
}
+ entry_count++;
+ stream << " conn_id: " << loghex(p_clcb->bta_conn_id)
+ << " address: " << p_clcb->bda.ToRedactedStringForLogging()
+ << " transport: " << bt_transport_text(p_clcb->transport)
+ << " state: " << bta_clcb_state_text(p_clcb->state);
+ stream << "\n";
}
stream << " -- used: " << entry_count << "\n";
diff --git a/system/bta/hearing_aid/OWNERS b/system/bta/hearing_aid/OWNERS
deleted file mode 100644
index bbaa85ddbb..0000000000
--- a/system/bta/hearing_aid/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_hearingaid
diff --git a/system/bta/hearing_aid/hearing_aid_test.cc b/system/bta/hearing_aid/hearing_aid_test.cc
new file mode 100644
index 0000000000..2090df9d81
--- /dev/null
+++ b/system/bta/hearing_aid/hearing_aid_test.cc
@@ -0,0 +1,474 @@
+/*
+ * Copyright 2025 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <base/bind_helpers.h>
+#include <base/functional/bind.h>
+#include <base/strings/string_number_conversions.h>
+#include <bluetooth/log.h>
+#include <com_android_bluetooth_flags.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <log/log.h>
+#include <osi/include/alarm.h>
+#include <string.h>
+#include <sys/socket.h>
+
+#include <variant>
+
+#include "bta/le_audio/le_audio_types.h"
+#include "bta_gatt_api_mock.h"
+#include "bta_gatt_queue_mock.h"
+#include "bta_hearing_aid_api.h"
+#include "btif_storage_mock.h"
+#include "btm_api_mock.h"
+#include "gatt/database_builder.h"
+#include "hardware/bt_gatt_types.h"
+#include "hci/controller_interface_mock.h"
+#include "stack/include/bt_uuid16.h"
+#include "stack/include/btm_status.h"
+#include "test/common/mock_functions.h"
+#include "test/mock/mock_main_shim_entry.h"
+#include "test/mock/mock_stack_gap_conn_interface.h"
+#include "test/mock/mock_stack_l2cap_interface.h"
+#include "types/bt_transport.h"
+
+static std::map<const char*, bool> fake_osi_bool_props;
+
+namespace bluetooth {
+namespace hearing_aid {
+namespace internal {
+namespace {
+
+using base::HexEncode;
+
+using namespace bluetooth::hearing_aid;
+
+using ::bluetooth::hearing_aid::ConnectionState;
+using ::bluetooth::hearing_aid::HearingAidCallbacks;
+using ::bluetooth::hearing_aid::HearingAidInterface;
+
+using ::testing::_;
+using ::testing::AnyNumber;
+using ::testing::DoAll;
+using ::testing::DoDefault;
+using ::testing::Invoke;
+using ::testing::Mock;
+using ::testing::NiceMock;
+using ::testing::NotNull;
+using ::testing::Return;
+using ::testing::SaveArg;
+using ::testing::Sequence;
+using ::testing::SetArgPointee;
+using ::testing::WithArg;
+
+RawAddress GetTestAddress(int index) {
+ CHECK_LT(index, UINT8_MAX);
+ RawAddress result = {{0xC0, 0xDE, 0xC0, 0xDE, 0x00, static_cast<uint8_t>(index)}};
+ return result;
+}
+
+static uint16_t GetTestConnId(const RawAddress& address) {
+ return address.address[RawAddress::kLength - 1];
+}
+
+class MockHearingAidCallbacks : public HearingAidCallbacks {
+public:
+ MockHearingAidCallbacks() = default;
+ MockHearingAidCallbacks(const MockHearingAidCallbacks&) = delete;
+ ~MockHearingAidCallbacks() override = default;
+
+ MOCK_METHOD((void), OnConnectionState, (ConnectionState state, const RawAddress& address),
+ (override));
+ MOCK_METHOD((void), OnDeviceAvailable,
+ (uint8_t capabilities, uint64_t hiSyncId, const RawAddress& address), (override));
+};
+
+class HearingAidTestBase : public ::testing::Test {
+protected:
+ Uuid HEARING_AID_UUID = Uuid::FromString("FDF0");
+ Uuid READ_ONLY_PROPERTIES_UUID = Uuid::FromString("6333651e-c481-4a3e-9169-7c902aad37bb");
+ Uuid AUDIO_CONTROL_POINT_UUID = Uuid::FromString("f0d4de7e-4a88-476c-9d9f-1937b0996cc0");
+ Uuid AUDIO_STATUS_UUID = Uuid::FromString("38663f1a-e711-4cac-b641-326b56404837");
+ Uuid VOLUME_UUID = Uuid::FromString("00e4ca9e-ab14-41e4-8823-f9e70c7e91df");
+ Uuid LE_PSM_UUID = Uuid::FromString("2d410339-82b6-42aa-b34e-e2e01df8cc1a");
+
+ void set_sample_database(uint16_t conn_id) {
+ static constexpr uint16_t kGapSvcStartHdl = 0x0001;
+ static constexpr uint16_t kGapDeviceNameValHdl = 0x0003;
+ static constexpr uint16_t kGapSvcEndHdl = kGapDeviceNameValHdl;
+
+ static constexpr uint16_t kSvcStartHdl = 0x0010;
+ static constexpr uint16_t kReadOnlyProperties = 0x0012;
+ static constexpr uint16_t kAudioControlPoint = 0x0015;
+ static constexpr uint16_t kAudioStatusPoint = 0x0018;
+ static constexpr uint16_t kVolume = 0x001B;
+ static constexpr uint16_t kLePsm = 0x001E;
+ static constexpr uint16_t kSvcEndHdl = kLePsm;
+
+ gatt::DatabaseBuilder bob;
+
+ /* Generic Access Service */
+ bob.AddService(kGapSvcStartHdl, kGapDeviceNameValHdl, Uuid::From16Bit(0x1800), true);
+ /* Device Name Char. */
+ bob.AddCharacteristic(kGapDeviceNameValHdl - 1, kGapDeviceNameValHdl, Uuid::From16Bit(0x2a00),
+ GATT_CHAR_PROP_BIT_READ);
+
+ /* ASHA Service */
+ bob.AddService(kSvcStartHdl, kSvcEndHdl, HEARING_AID_UUID, true);
+ bob.AddCharacteristic(kReadOnlyProperties - 1, kReadOnlyProperties, READ_ONLY_PROPERTIES_UUID,
+ GATT_CHAR_PROP_BIT_READ);
+ bob.AddCharacteristic(kAudioControlPoint - 1, kAudioControlPoint, AUDIO_CONTROL_POINT_UUID,
+ GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_WRITE_NR);
+ bob.AddCharacteristic(kAudioStatusPoint - 1, kAudioStatusPoint, AUDIO_STATUS_UUID,
+ GATT_CHAR_PROP_BIT_READ | GATT_CHAR_PROP_BIT_NOTIFY);
+ bob.AddDescriptor(kAudioStatusPoint + 1, Uuid::From16Bit(GATT_UUID_CHAR_CLIENT_CONFIG));
+ bob.AddCharacteristic(kVolume - 1, kVolume, VOLUME_UUID, GATT_CHAR_PROP_BIT_WRITE_NR);
+ bob.AddCharacteristic(kLePsm - 1, kLePsm, LE_PSM_UUID, GATT_CHAR_PROP_BIT_READ);
+
+ services_map[conn_id] = bob.Build().Services();
+
+ ON_CALL(gatt_queue, ReadCharacteristic(conn_id, _, _, _))
+ .WillByDefault(Invoke(
+ [this](uint16_t conn_id, uint16_t handle, GATT_READ_OP_CB cb, void* cb_data) {
+ auto* svc = gatt::FindService(services_map[conn_id], handle);
+ if (svc == nullptr) {
+ return;
+ }
+
+ std::vector<uint8_t> value;
+ tGATT_STATUS status = GATT_SUCCESS;
+
+ switch (handle) {
+ case kReadOnlyProperties:
+ value.resize(17);
+ value.assign(17, 0x01);
+ break;
+ case kAudioStatusPoint:
+ value.resize(1);
+ value.assign(1, 0);
+ break;
+ case kLePsm:
+ value.resize(2);
+ value.assign(2, 0x0080);
+ break;
+ /* passthrough */
+ default:
+ status = GATT_READ_NOT_PERMIT;
+ break;
+ }
+
+ if (cb) {
+ cb(conn_id, status, handle, value.size(), value.data(), cb_data);
+ }
+ }));
+
+ /* default action for GetCharacteristic function call */
+ ON_CALL(gatt_interface, GetCharacteristic(_, _))
+ .WillByDefault(
+ Invoke([&](uint16_t conn_id, uint16_t handle) -> const gatt::Characteristic* {
+ std::list<gatt::Service>& services = services_map[conn_id];
+ for (auto const& service : services) {
+ for (auto const& characteristic : service.characteristics) {
+ if (characteristic.value_handle == handle) {
+ return &characteristic;
+ }
+ }
+ }
+
+ return nullptr;
+ }));
+
+ ON_CALL(gatt_interface, ServiceSearchRequest(_, _))
+ .WillByDefault(WithArg<0>(
+ Invoke([&](uint16_t conn_id) { InjectSearchCompleteEvent(conn_id); })));
+
+ /* default action for GetServices function call */
+ ON_CALL(gatt_interface, GetServices(_))
+ .WillByDefault(WithArg<0>(Invoke([&](uint16_t conn_id) -> std::list<gatt::Service>* {
+ return &services_map[conn_id];
+ })));
+
+ /* default action for RegisterForNotifications function call */
+ ON_CALL(gatt_interface, RegisterForNotifications(gatt_if, _, _))
+ .WillByDefault(Return(GATT_SUCCESS));
+
+ /* default action for DeregisterForNotifications function call */
+ ON_CALL(gatt_interface, DeregisterForNotifications(gatt_if, _, _))
+ .WillByDefault(Return(GATT_SUCCESS));
+
+ /* default action for WriteDescriptor function call */
+ ON_CALL(gatt_queue, WriteDescriptor(_, _, _, _, _, _))
+ .WillByDefault(Invoke([](uint16_t conn_id, uint16_t handle, std::vector<uint8_t> value,
+ tGATT_WRITE_TYPE /*write_type*/, GATT_WRITE_OP_CB cb,
+ void* cb_data) -> void {
+ if (cb) {
+ cb(conn_id, GATT_SUCCESS, handle, value.size(), value.data(), cb_data);
+ }
+ }));
+ }
+
+ void SetUp(void) override {
+ fake_osi_bool_props.clear();
+ bluetooth::manager::SetMockBtmInterface(&btm_interface);
+ bluetooth::storage::SetMockBtifStorageInterface(&btif_storage_interface_);
+ gatt::SetMockBtaGattInterface(&gatt_interface);
+ gatt::SetMockBtaGattQueue(&gatt_queue);
+ callbacks.reset(new MockHearingAidCallbacks());
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
+ bluetooth::testing::stack::l2cap::set_interface(&mock_stack_l2cap_interface_);
+ bluetooth::testing::stack::gap_conn::set_interface(&mock_stack_gap_conn_interface_);
+
+ encryption_result = true;
+
+ ON_CALL(mock_stack_l2cap_interface_, L2CA_UpdateBleConnParams(_, _, _, _, _, _, _))
+ .WillByDefault(Invoke([&](const RawAddress& /*rem_bda*/, uint16_t min_int,
+ uint16_t /*max_int*/, uint16_t latency, uint16_t timeout,
+ uint16_t /*min_ce_len*/, uint16_t /*max_ce_len*/) {
+ req_int = min_int;
+ req_latency = latency;
+ req_timeout = timeout;
+ return true;
+ }));
+
+ ON_CALL(mock_stack_gap_conn_interface_, GAP_ConnOpen(_, _, _, _, _, _, _, _, _, _, _))
+ .WillByDefault(Invoke([&](const char* /* p_serv_name */, uint8_t /*service_id*/,
+ bool /*is_server*/, const RawAddress* p_rem_bda,
+ uint16_t /*psm*/, uint16_t /*le_mps*/,
+ tL2CAP_CFG_INFO* /*p_cfg*/, tL2CAP_ERTM_INFO* /*ertm_info*/,
+ uint16_t /*security*/, tGAP_CONN_CALLBACK* p_cb,
+ tBT_TRANSPORT /*transport*/) {
+ InjectConnUpdateEvent(p_rem_bda->address[5], req_int, req_latency, req_timeout);
+
+ gap_conn_cb = p_cb;
+ if (gap_conn_cb) {
+ gap_conn_cb(0xFFFF, GAP_EVT_CONN_OPENED, nullptr);
+ }
+ return 1;
+ }));
+
+ ON_CALL(mock_stack_gap_conn_interface_, GAP_ConnGetRemoteAddr(_))
+ .WillByDefault(Invoke([&](uint16_t /*gap_handle*/) { return &test_address; }));
+
+ /* by default connect only direct connection requests */
+ ON_CALL(gatt_interface, Open(_, _, _, _))
+ .WillByDefault(Invoke([&](tGATT_IF /*client_if*/, const RawAddress& remote_bda,
+ tBTM_BLE_CONN_TYPE connection_type, bool /*opportunistic*/) {
+ if (connection_type == BTM_BLE_DIRECT_CONNECTION) {
+ InjectConnectedEvent(remote_bda, GetTestConnId(remote_bda));
+ }
+ }));
+
+ ON_CALL(gatt_interface, Close(_)).WillByDefault(Invoke([&](uint16_t conn_id) {
+ /* We arrive here once, when we call Disconnect; and second time, after
+ * we send OnGattDisconnected - but device was already removed */
+ if (connected_devices.count(conn_id) > 0) {
+ InjectDisconnectedEvent(conn_id);
+ }
+ }));
+ }
+
+ void TearDown(void) override {
+ services_map.clear();
+ gatt::SetMockBtaGattQueue(nullptr);
+ gatt::SetMockBtaGattInterface(nullptr);
+ bluetooth::manager::SetMockBtmInterface(nullptr);
+ bluetooth::hci::testing::mock_controller_.reset();
+ bluetooth::testing::stack::l2cap::reset_interface();
+ bluetooth::testing::stack::gap_conn::reset_interface();
+ Mock::VerifyAndClearExpectations(&*callbacks);
+ Mock::VerifyAndClearExpectations(&gatt_queue);
+ Mock::VerifyAndClearExpectations(&gatt_interface);
+ Mock::VerifyAndClearExpectations(&btm_interface);
+ callbacks.reset();
+ }
+
+ void InjectConnectedEvent(const RawAddress& address, uint16_t conn_id,
+ tGATT_STATUS status = GATT_SUCCESS) {
+ tBTA_GATTC_OPEN event_data = {
+ .status = status,
+ .conn_id = conn_id,
+ .client_if = gatt_if,
+ .remote_bda = address,
+ .transport = BT_TRANSPORT_LE,
+ .mtu = 240,
+ };
+ connected_devices[conn_id] = address;
+ gatt_callback(BTA_GATTC_OPEN_EVT, (tBTA_GATTC*)&event_data);
+ }
+
+ void InjectConnUpdateEvent(uint16_t conn_id, uint16_t interval, uint16_t latency,
+ uint16_t timeout, tGATT_STATUS status = GATT_SUCCESS) {
+ tBTA_GATTC_CONN_UPDATE event_data = {
+ .conn_id = conn_id,
+ .interval = interval,
+ .latency = latency,
+ .timeout = timeout,
+ .status = status,
+ };
+
+ gatt_callback(BTA_GATTC_CONN_UPDATE_EVT, (tBTA_GATTC*)&event_data);
+ }
+
+ void InjectDisconnectedEvent(uint16_t conn_id,
+ tGATT_DISCONN_REASON reason = GATT_CONN_TERMINATE_LOCAL_HOST,
+ bool allow_fake_conn = false) {
+ if (!allow_fake_conn) {
+ ASSERT_NE(connected_devices.count(conn_id), 0u);
+ }
+
+ tBTA_GATTC_CLOSE event_data = {
+ .conn_id = conn_id,
+ .status = GATT_SUCCESS,
+ .client_if = gatt_if,
+ .remote_bda = connected_devices[conn_id],
+ .reason = reason,
+ };
+
+ connected_devices.erase(conn_id);
+ gatt_callback(BTA_GATTC_CLOSE_EVT, (tBTA_GATTC*)&event_data);
+ }
+
+ void InjectSearchCompleteEvent(uint16_t conn_id) {
+ tBTA_GATTC_SEARCH_CMPL event_data = {
+ .conn_id = conn_id,
+ .status = GATT_SUCCESS,
+ };
+
+ gatt_callback(BTA_GATTC_SEARCH_CMPL_EVT, (tBTA_GATTC*)&event_data);
+ }
+
+ void InjectNotificationEvent(const RawAddress& test_address, uint16_t conn_id, uint16_t handle,
+ std::vector<uint8_t> value, bool indicate = false) {
+ tBTA_GATTC_NOTIFY event_data = {
+ .conn_id = conn_id,
+ .bda = test_address,
+ .handle = handle,
+ .len = (uint8_t)value.size(),
+ .is_notify = !indicate,
+ };
+
+ ASSERT_TRUE(value.size() < GATT_MAX_ATTR_LEN);
+ std::copy(value.begin(), value.end(), event_data.value);
+ gatt_callback(BTA_GATTC_NOTIF_EVT, (tBTA_GATTC*)&event_data);
+ }
+
+ void SetEncryptionResult(const RawAddress& address, bool success) {
+ encryption_result = success;
+
+ ON_CALL(btm_interface, BTM_IsEncrypted(address, _)).WillByDefault(Return(encryption_result));
+
+ ON_CALL(btm_interface, IsDeviceBonded(address, _)).WillByDefault(Return(true));
+ }
+
+ std::unique_ptr<MockHearingAidCallbacks> callbacks;
+ bluetooth::manager::MockBtmInterface btm_interface;
+ bluetooth::storage::MockBtifStorageInterface btif_storage_interface_;
+ gatt::MockBtaGattInterface gatt_interface;
+ gatt::MockBtaGattQueue gatt_queue;
+ tBTA_GATTC_CBACK* gatt_callback;
+ const uint8_t gatt_if = 0xfe;
+ std::map<uint8_t, RawAddress> connected_devices;
+ std::map<uint16_t, std::list<gatt::Service>> services_map;
+ bluetooth::testing::stack::l2cap::Mock mock_stack_l2cap_interface_;
+ bluetooth::testing::stack::gap_conn::Mock mock_stack_gap_conn_interface_;
+ tGAP_CONN_CALLBACK* gap_conn_cb;
+ uint16_t req_int;
+ uint16_t req_latency;
+ uint16_t req_timeout;
+ bool encryption_result;
+ const RawAddress test_address = GetTestAddress(1);
+};
+
+class HearingAidTest : public HearingAidTestBase {
+ void SetUp(void) override {
+ HearingAidTestBase::SetUp();
+ BtaAppRegisterCallback app_register_callback;
+ EXPECT_CALL(gatt_interface, AppRegister(_, _, _, _))
+ .WillOnce(DoAll(SaveArg<1>(&gatt_callback), SaveArg<2>(&app_register_callback)));
+ HearingAid::Initialize(callbacks.get(), base::DoNothing());
+ ASSERT_TRUE(gatt_callback);
+ ASSERT_TRUE(app_register_callback);
+ app_register_callback.Run(gatt_if, GATT_SUCCESS);
+ ASSERT_TRUE(HearingAid::IsHearingAidRunning());
+ Mock::VerifyAndClearExpectations(&gatt_interface);
+ }
+ void TearDown(void) override {
+ EXPECT_CALL(gatt_interface, AppDeregister(gatt_if));
+ if (HearingAid::IsHearingAidRunning()) {
+ HearingAid::CleanUp();
+ }
+ ASSERT_FALSE(HearingAid::IsHearingAidRunning());
+ gatt_callback = nullptr;
+ HearingAidTestBase::TearDown();
+ }
+};
+
+/* Test that hearing aid is initialized and cleaned up */
+TEST_F(HearingAidTestBase, initialize) {
+ ASSERT_FALSE(HearingAid::IsHearingAidRunning());
+ HearingAid::Initialize(callbacks.get(), base::DoNothing());
+ ASSERT_TRUE(HearingAid::IsHearingAidRunning());
+ HearingAid::CleanUp();
+ ASSERT_FALSE(HearingAid::IsHearingAidRunning());
+}
+
+/* Test that connect cancellation works */
+TEST_F(HearingAidTest, disconnect_when_connecting) {
+ /* Override the default action to prevent us sending the connected event */
+ EXPECT_CALL(gatt_interface, Open(gatt_if, test_address, BTM_BLE_DIRECT_CONNECTION, _))
+ .WillOnce(Return());
+ EXPECT_CALL(*callbacks, OnDeviceAvailable(_, _, test_address)).Times(0);
+ HearingAid::Connect(test_address);
+
+ /* Single call from HearingAid:Disconnect*/
+ EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)).Times(1);
+ EXPECT_CALL(gatt_interface, CancelOpen(_, test_address, _)).Times(AnyNumber());
+ EXPECT_CALL(gatt_interface, Close(_)).Times(0);
+ HearingAid::Disconnect(test_address);
+}
+
+/* Test that connect works and Connected state gets reported */
+TEST_F(HearingAidTest, connect) {
+ set_sample_database(1);
+
+ EXPECT_CALL(gatt_interface, Open(gatt_if, test_address, BTM_BLE_DIRECT_CONNECTION, _));
+ EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address));
+ EXPECT_CALL(*callbacks, OnDeviceAvailable(_, _, test_address));
+ ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _)).WillByDefault(Return(true));
+
+ HearingAid::Connect(test_address);
+}
+
+/* Test that connected device can be disconnected */
+TEST_F(HearingAidTest, disconnect_when_connected) {
+ set_sample_database(1);
+
+ ON_CALL(btm_interface, BTM_IsEncrypted(test_address, _)).WillByDefault(Return(true));
+ EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::CONNECTED, test_address)).Times(1);
+ EXPECT_CALL(*callbacks, OnDeviceAvailable(_, _, test_address));
+ HearingAid::Connect(test_address);
+
+ /* First call from HearingAid:Disconnect. Second call from OnGattDisconnected*/
+ EXPECT_CALL(*callbacks, OnConnectionState(ConnectionState::DISCONNECTED, test_address)).Times(2);
+ EXPECT_CALL(gatt_interface, Close(_)).Times(2);
+ HearingAid::Disconnect(test_address);
+}
+
+} // namespace
+} // namespace internal
+} // namespace hearing_aid
+} // namespace bluetooth
diff --git a/system/bta/include/OWNERS b/system/bta/include/OWNERS
deleted file mode 100644
index 9dfb8422a1..0000000000
--- a/system/bta/include/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-per-file bta_hearing_aid_api.h=file:/OWNERS_hearingaid
diff --git a/system/bta/le_audio/OWNERS b/system/bta/le_audio/OWNERS
deleted file mode 100644
index a7d77894ba..0000000000
--- a/system/bta/le_audio/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_leaudio
diff --git a/system/bta/le_audio/broadcaster/broadcaster_test.cc b/system/bta/le_audio/broadcaster/broadcaster_test.cc
index a211a810ad..16177230d1 100644
--- a/system/bta/le_audio/broadcaster/broadcaster_test.cc
+++ b/system/bta/le_audio/broadcaster/broadcaster_test.cc
@@ -63,6 +63,8 @@ using testing::Test;
using namespace bluetooth::le_audio;
using namespace bluetooth;
+using bluetooth::hci::testing::mock_controller_;
+
using bluetooth::le_audio::DsaMode;
using bluetooth::le_audio::LeAudioCodecConfiguration;
using bluetooth::le_audio::LeAudioSourceAudioHalClient;
@@ -287,8 +289,8 @@ protected:
init_message_loop_thread();
reset_mock_function_count_map();
- bluetooth::hci::testing::mock_controller_ = &mock_controller_;
- ON_CALL(mock_controller_, SupportsBleIsochronousBroadcaster).WillByDefault(Return(true));
+ mock_controller_ = std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*mock_controller_, SupportsBleIsochronousBroadcaster).WillByDefault(Return(true));
iso_manager_ = bluetooth::hci::IsoManager::GetInstance();
ASSERT_NE(iso_manager_, nullptr);
@@ -366,7 +368,7 @@ protected:
ContentControlIdKeeper::GetInstance()->Stop();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.release();
delete mock_audio_source_;
iso_active_callback = nullptr;
delete mock_audio_source_;
@@ -436,7 +438,6 @@ protected:
protected:
MockLeAudioBroadcasterCallbacks mock_broadcaster_callbacks_;
- bluetooth::hci::testing::MockControllerInterface mock_controller_;
bluetooth::hci::IsoManager* iso_manager_;
MockIsoManager* mock_iso_manager_;
bluetooth::hci::iso_manager::BigCallbacks* big_callbacks_ = nullptr;
diff --git a/system/bta/le_audio/codec_manager_test.cc b/system/bta/le_audio/codec_manager_test.cc
index 9ac1fde07d..c69464b72e 100644
--- a/system/bta/le_audio/codec_manager_test.cc
+++ b/system/bta/le_audio/codec_manager_test.cc
@@ -300,10 +300,12 @@ public:
bluetooth::legacy::hci::testing::SetMock(legacy_hci_mock_);
- ON_CALL(controller_interface, SupportsBleIsochronousBroadcaster).WillByDefault(Return(true));
- ON_CALL(controller_interface, IsSupported(OpCode::CONFIGURE_DATA_PATH))
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsBleIsochronousBroadcaster)
+ .WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, IsSupported(OpCode::CONFIGURE_DATA_PATH))
.WillByDefault(Return(true));
- bluetooth::hci::testing::mock_controller_ = &controller_interface;
codec_manager = CodecManager::GetInstance();
@@ -311,9 +313,11 @@ public:
RegisterSinkHalClientMock();
}
- virtual void TearDown() override { codec_manager->Stop(); }
+ virtual void TearDown() override {
+ codec_manager->Stop();
+ bluetooth::hci::testing::mock_controller_.release();
+ }
- NiceMock<bluetooth::hci::testing::MockControllerInterface> controller_interface;
CodecManager* codec_manager;
bluetooth::legacy::hci::testing::MockInterface legacy_hci_mock_;
diff --git a/system/bta/le_audio/devices_test.cc b/system/bta/le_audio/devices_test.cc
index adc90e5213..cd711065c4 100644
--- a/system/bta/le_audio/devices_test.cc
+++ b/system/bta/le_audio/devices_test.cc
@@ -514,7 +514,9 @@ protected:
desired_group_size_ = -1;
bluetooth::manager::SetMockBtmInterface(&btm_interface_);
- bluetooth::hci::testing::mock_controller_ = &controller_interface_;
+
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
auto codec_location = ::bluetooth::le_audio::types::CodecLocation::HOST;
bluetooth::le_audio::AudioSetConfigurationProvider::Initialize(codec_location);
@@ -740,6 +742,8 @@ protected:
if (codec_manager_) {
codec_manager_->Stop();
}
+
+ bluetooth::hci::testing::mock_controller_.reset();
}
LeAudioDevice* AddTestDevice(int snk_ase_num, int src_ase_num, int snk_ase_num_cached = 0,
@@ -1417,7 +1421,6 @@ protected:
LeAudioDeviceGroup* group_ = nullptr;
bluetooth::manager::MockBtmInterface btm_interface_;
MockCsisClient mock_csis_client_module_;
- NiceMock<bluetooth::hci::testing::MockControllerInterface> controller_interface_;
bluetooth::le_audio::CodecManager* codec_manager_;
MockCodecManager* mock_codec_manager_;
diff --git a/system/bta/le_audio/le_audio_client_test.cc b/system/bta/le_audio/le_audio_client_test.cc
index a3c52dc9e6..02104518d2 100644
--- a/system/bta/le_audio/le_audio_client_test.cc
+++ b/system/bta/le_audio/le_audio_client_test.cc
@@ -1477,11 +1477,13 @@ protected:
init_message_loop_thread();
reset_mock_function_count_map();
- ON_CALL(controller_, SupportsBleConnectedIsochronousStreamCentral).WillByDefault(Return(true));
- ON_CALL(controller_, SupportsBleConnectedIsochronousStreamPeripheral)
+ hci::testing::mock_controller_ =
+ std::make_unique<NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
+ ON_CALL(*hci::testing::mock_controller_, SupportsBleConnectedIsochronousStreamCentral)
.WillByDefault(Return(true));
- ON_CALL(controller_, SupportsBle2mPhy).WillByDefault(Return(true));
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ ON_CALL(*hci::testing::mock_controller_, SupportsBleConnectedIsochronousStreamPeripheral)
+ .WillByDefault(Return(true));
+ ON_CALL(*hci::testing::mock_controller_, SupportsBle2mPhy).WillByDefault(Return(true));
bluetooth::manager::SetMockBtmInterface(&mock_btm_interface_);
gatt::SetMockBtaGattInterface(&mock_gatt_interface_);
gatt::SetMockBtaGattQueue(&mock_gatt_queue_);
@@ -1595,7 +1597,7 @@ protected:
}
iso_manager_->Stop();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ hci::testing::mock_controller_.reset();
}
protected:
@@ -2761,7 +2763,6 @@ protected:
/* Audio track metadata */
char* test_tags_ptr_ = nullptr;
- NiceMock<bluetooth::hci::testing::MockControllerInterface> controller_;
};
class UnicastTest : public UnicastTestNoInit {
diff --git a/system/bta/le_audio/metrics_collector.cc b/system/bta/le_audio/metrics_collector.cc
index a4fb4a353d..24da2e085c 100644
--- a/system/bta/le_audio/metrics_collector.cc
+++ b/system/bta/le_audio/metrics_collector.cc
@@ -25,9 +25,9 @@
#include <unordered_map>
#include <vector>
-#include "common/metrics.h"
#include "hardware/bt_le_audio.h"
#include "le_audio_types.h"
+#include "os/metrics.h"
#include "types/raw_address.h"
namespace bluetooth::le_audio {
@@ -199,7 +199,7 @@ public:
device_address[i] = device_metric->address_;
}
- bluetooth::common::LogLeAudioConnectionSessionReported(
+ bluetooth::os::LogMetricLeAudioConnectionSessionReported(
group_size_, group_id_, connection_duration_nanos, device_connecting_offset_nanos,
device_connected_offset_nanos, device_connection_duration_nanos,
device_connection_statuses, device_disconnection_statuses, device_address,
@@ -278,7 +278,7 @@ void MetricsCollector::OnBroadcastStateChanged(bool started) {
broadcast_beginning_timepoint_ = std::chrono::high_resolution_clock::now();
} else {
auto broadcast_ending_timepoint_ = std::chrono::high_resolution_clock::now();
- bluetooth::common::LogLeAudioBroadcastSessionReported(
+ bluetooth::os::LogMetricLeAudioBroadcastSessionReported(
get_timedelta_nanos(broadcast_beginning_timepoint_, broadcast_ending_timepoint_));
broadcast_beginning_timepoint_ = kInvalidTimePoint;
}
diff --git a/system/bta/le_audio/metrics_collector_test.cc b/system/bta/le_audio/metrics_collector_test.cc
index c94db90ad6..199199bf8a 100644
--- a/system/bta/le_audio/metrics_collector_test.cc
+++ b/system/bta/le_audio/metrics_collector_test.cc
@@ -23,7 +23,7 @@
#include <cstdint>
#include <vector>
-#include "common/metrics.h"
+#include "os/metrics.h"
#include "types/raw_address.h"
using testing::_;
@@ -57,9 +57,9 @@ std::vector<int64_t> last_streaming_duration_nanos;
std::vector<int32_t> last_streaming_context_type;
namespace bluetooth {
-namespace common {
+namespace os {
-void LogLeAudioConnectionSessionReported(
+void LogMetricLeAudioConnectionSessionReported(
int32_t group_size, int32_t group_metric_id, int64_t connection_duration_nanos,
const std::vector<int64_t>& device_connecting_offset_nanos,
const std::vector<int64_t>& device_connected_offset_nanos,
@@ -85,11 +85,11 @@ void LogLeAudioConnectionSessionReported(
last_streaming_context_type = streaming_context_type;
}
-void LogLeAudioBroadcastSessionReported(int64_t duration_nanos) {
+void LogMetricLeAudioBroadcastSessionReported(int64_t duration_nanos) {
last_broadcast_duration_nanos = duration_nanos;
}
-} // namespace common
+} // namespace os
} // namespace bluetooth
namespace bluetooth::le_audio {
diff --git a/system/bta/le_audio/state_machine_test.cc b/system/bta/le_audio/state_machine_test.cc
index d17bfda188..e0860515fb 100644
--- a/system/bta/le_audio/state_machine_test.cc
+++ b/system/bta/le_audio/state_machine_test.cc
@@ -261,7 +261,9 @@ protected:
bluetooth::manager::SetMockBtmInterface(&btm_interface);
gatt::SetMockBtaGattInterface(&gatt_interface);
gatt::SetMockBtaGattQueue(&gatt_queue);
- bluetooth::hci::testing::mock_controller_ = &controller_;
+
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
overwrite_cis_status_idx_ = 0;
use_cis_retry_cnt_ = false;
@@ -649,7 +651,7 @@ protected:
cached_remote_qos_configuration_for_ase_.clear();
LeAudioGroupStateMachine::Cleanup();
::bluetooth::le_audio::AudioSetConfigurationProvider::Cleanup();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.release();
}
std::shared_ptr<LeAudioDevice> PrepareConnectedDevice(uint8_t id,
@@ -1714,7 +1716,6 @@ protected:
std::vector<RawAddress> addresses_;
std::map<uint8_t, std::unique_ptr<LeAudioDeviceGroup>> le_audio_device_groups_;
bool group_create_command_disallowed_ = false;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class StateMachineTest : public StateMachineTestBase {
diff --git a/system/bta/test/bta_ag_sco_test.cc b/system/bta/test/bta_ag_sco_test.cc
index 16caac7665..a90198c54a 100644
--- a/system/bta/test/bta_ag_sco_test.cc
+++ b/system/bta/test/bta_ag_sco_test.cc
@@ -43,14 +43,14 @@ protected:
this->codec = codec;
return enh_esco_params_t{};
};
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
}
void TearDown() override {
test::mock::device_esco_parameters::esco_parameters_for_codec = {};
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
esco_codec_t codec;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
TEST_P(BtaAgScoParameterSelectionTest, create_sco_cvsd) {
diff --git a/system/bta/test/bta_ag_test.cc b/system/bta/test/bta_ag_test.cc
index 5fa3884669..2114f7e773 100644
--- a/system/bta/test/bta_ag_test.cc
+++ b/system/bta/test/bta_ag_test.cc
@@ -65,7 +65,8 @@ protected:
void SetUp() override {
reset_mock_function_count_map();
fake_osi_ = std::make_unique<test::fake::FakeOsi>();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
main_thread_start_up();
post_on_bt_main([]() { log::info("Main thread started up"); });
@@ -85,7 +86,7 @@ protected:
bta_sys_deregister(BTA_ID_AG);
post_on_bt_main([]() { log::info("Main thread shutting down"); });
main_thread_shut_down();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
std::unique_ptr<test::fake::FakeOsi> fake_osi_;
@@ -93,7 +94,6 @@ protected:
uint32_t tmp_num = 0xFFFF;
RawAddress addr;
esco_codec_t codec;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtaAgSwbTest : public BtaAgTest {
diff --git a/system/bta/test/bta_dm_test.cc b/system/bta/test/bta_dm_test.cc
index 90d41d5e6f..b49008b739 100644
--- a/system/bta/test/bta_dm_test.cc
+++ b/system/bta/test/bta_dm_test.cc
@@ -65,10 +65,10 @@ class BtaDmTest : public BtaWithContextTest {
protected:
void SetUp() override {
BtaWithContextTest::SetUp();
- ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
- cb(0x1234);
- });
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, LeRand)
+ .WillByDefault([](bluetooth::hci::LeRandCallback cb) { cb(0x1234); });
BTA_dm_init();
bluetooth::legacy::testing::bta_dm_init_cb();
@@ -82,9 +82,8 @@ protected:
void TearDown() override {
bluetooth::legacy::testing::bta_dm_deinit_cb();
BtaWithContextTest::TearDown();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtaDmCustomAlarmTest : public BtaDmTest {
diff --git a/system/bta/test/bta_sdp_test.cc b/system/bta/test/bta_sdp_test.cc
index 06e8ff86aa..77f1762cc0 100644
--- a/system/bta/test/bta_sdp_test.cc
+++ b/system/bta/test/bta_sdp_test.cc
@@ -30,17 +30,16 @@ class BtaSdpTest : public BtaWithHwOnTest {
protected:
void SetUp() override {
BtaWithHwOnTest::SetUp();
- ON_CALL(controller_, LeRand).WillByDefault([](bluetooth::hci::LeRandCallback cb) {
- cb(0x1234);
- });
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, LeRand)
+ .WillByDefault([](bluetooth::hci::LeRandCallback cb) { cb(0x1234); });
}
void TearDown() override {
BtaWithHwOnTest::TearDown();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtaSdpRegisteredTest : public BtaSdpTest {
diff --git a/system/bta/test/bta_test_fixtures.h b/system/bta/test/bta_test_fixtures.h
index c259d0b916..e41e64d496 100644
--- a/system/bta/test/bta_test_fixtures.h
+++ b/system/bta/test/bta_test_fixtures.h
@@ -60,7 +60,8 @@ protected:
ASSERT_NE(get_btm_client_interface().lifecycle.btm_init, nullptr);
ASSERT_NE(get_btm_client_interface().lifecycle.btm_free, nullptr);
- bluetooth::hci::testing::mock_controller_ = &mock_controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
bluetooth::testing::stack::rnr::set_interface(&mock_stack_rnr_interface_);
test::mock::stack_gatt_api::GATT_Register.body =
@@ -85,12 +86,11 @@ protected:
mock_btm_client_interface.eir.BTM_WriteEIR = {};
bluetooth::testing::stack::rnr::reset_interface();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
BtaWithFakesTest::TearDown();
}
- bluetooth::hci::testing::MockControllerInterface mock_controller_;
bluetooth::testing::stack::rnr::Mock mock_stack_rnr_interface_;
};
diff --git a/system/bta/test/common/btif_storage_mock.cc b/system/bta/test/common/btif_storage_mock.cc
index 7e4a4e5118..f5eb38939e 100644
--- a/system/bta/test/common/btif_storage_mock.cc
+++ b/system/bta/test/common/btif_storage_mock.cc
@@ -19,6 +19,7 @@
#include <bluetooth/log.h>
+#include "bta_hearing_aid_api.h"
#include "btif/include/btif_profile_storage.h"
#include "btif/include/btif_storage.h"
@@ -134,3 +135,17 @@ bt_status_t btif_storage_get_remote_device_property(const RawAddress* address,
log::assert_that(btif_storage_interface != nullptr, "Mock storage module not set!");
return btif_storage_interface->GetRemoteDeviceProperty(address, property);
}
+
+/** Get the hearing aid device properties. */
+bool btif_storage_get_hearing_aid_prop(const RawAddress& address, uint8_t* capabilities,
+ uint64_t* hi_sync_id, uint16_t* render_delay,
+ uint16_t* preparation_delay, uint16_t* codecs) {
+ log::assert_that(btif_storage_interface != nullptr, "Mock storage module not set!");
+ return btif_storage_interface->GetHearingAidProp(address, capabilities, hi_sync_id, render_delay,
+ preparation_delay, codecs);
+}
+
+void btif_storage_add_hearing_aid(const HearingDevice& dev_info) {
+ log::assert_that(btif_storage_interface != nullptr, "Mock storage module not set!");
+ return btif_storage_interface->AddHearingAid(&dev_info);
+}
diff --git a/system/bta/test/common/btif_storage_mock.h b/system/bta/test/common/btif_storage_mock.h
index 8809643f70..25f9bbdde0 100644
--- a/system/bta/test/common/btif_storage_mock.h
+++ b/system/bta/test/common/btif_storage_mock.h
@@ -21,6 +21,8 @@
#include "include/hardware/bluetooth.h"
#include "types/raw_address.h"
+struct HearingDevice;
+
namespace bluetooth {
namespace storage {
@@ -50,6 +52,11 @@ public:
virtual bt_status_t GetRemoteDeviceProperty(const RawAddress* address,
bt_property_t* property) = 0;
+ virtual bool GetHearingAidProp(const RawAddress& address, uint8_t* capabilities,
+ uint64_t* hi_sync_id, uint16_t* render_delay,
+ uint16_t* preparation_delay, uint16_t* codecs) = 0;
+ virtual void AddHearingAid(const HearingDevice* dev_info) = 0;
+
virtual ~BtifStorageInterface() = default;
};
@@ -88,6 +95,11 @@ public:
MOCK_METHOD((void), RemoveLeaudioHas, (const RawAddress& address), (override));
MOCK_METHOD((bt_status_t), GetRemoteDeviceProperty,
(const RawAddress* address, bt_property_t* property), (override));
+ MOCK_METHOD((bool), GetHearingAidProp,
+ (const RawAddress& address, uint8_t* capabilities, uint64_t* hi_sync_id,
+ uint16_t* render_delay, uint16_t* preparation_delay, uint16_t* codecs),
+ (override));
+ MOCK_METHOD((void), AddHearingAid, (const HearingDevice* dev_info), (override));
};
/**
diff --git a/system/btif/src/OWNERS b/system/btif/src/OWNERS
deleted file mode 100644
index e495e167d4..0000000000
--- a/system/btif/src/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-per-file btif_hearing_aid.cc=file:/OWNERS_hearingaid
diff --git a/system/btif/src/btif_a2dp_source.cc b/system/btif/src/btif_a2dp_source.cc
index 20805a92bd..5bf2ef0d87 100644
--- a/system/btif/src/btif_a2dp_source.cc
+++ b/system/btif/src/btif_a2dp_source.cc
@@ -48,7 +48,6 @@
#include "btif_hf.h"
#include "btm_iso_api.h"
#include "common/message_loop_thread.h"
-#include "common/metrics.h"
#include "common/repeating_timer.h"
#include "common/time_util.h"
#include "hardware/bt_av.h"
@@ -1302,8 +1301,7 @@ static void btm_read_rssi_cb(void* data) {
return;
}
- bluetooth::shim::LogMetricReadRssiResult(result->rem_bda,
- bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::shim::LogMetricReadRssiResult(result->rem_bda, bluetooth::os::kUnknownConnectionHandle,
result->hci_status, result->rssi);
log::warn("device: {}, rssi: {}", result->rem_bda, result->rssi);
@@ -1321,7 +1319,7 @@ static void btm_read_failed_contact_counter_cb(void* data) {
return;
}
bluetooth::shim::LogMetricReadFailedContactCounterResult(
- result->rem_bda, bluetooth::common::kUnknownConnectionHandle, result->hci_status,
+ result->rem_bda, bluetooth::os::kUnknownConnectionHandle, result->hci_status,
result->failed_contact_counter);
log::warn("device: {}, Failed Contact Counter: {}", result->rem_bda,
@@ -1340,7 +1338,7 @@ static void btm_read_tx_power_cb(void* data) {
return;
}
bluetooth::shim::LogMetricReadTxPowerLevelResult(result->rem_bda,
- bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::os::kUnknownConnectionHandle,
result->hci_status, result->tx_power);
log::warn("device: {}, Tx Power: {}", result->rem_bda, result->tx_power);
diff --git a/system/btif/src/btif_dm.cc b/system/btif/src/btif_dm.cc
index 44b876af4e..e10606b9dd 100644
--- a/system/btif/src/btif_dm.cc
+++ b/system/btif/src/btif_dm.cc
@@ -1486,7 +1486,7 @@ static void btif_dm_search_devices_evt(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH*
auto triple = eir_uuids_cache.try_emplace(bdaddr, std::set<Uuid>{});
uuid_iter = std::get<0>(triple);
}
- log::info("EIR UUIDs for {}:", bdaddr);
+ log::info("EIR UUIDs for {}", bdaddr);
for (int i = 0; i < num_uuids; ++i) {
Uuid uuid = Uuid::From16Bit(p_uuid16[i]);
log::info("{}", uuid.ToString());
@@ -1609,7 +1609,7 @@ static void btif_on_service_discovery_results(RawAddress bd_addr,
if (results_for_bonding_device) {
// success for SDP
bluetooth::metrics::LogSDPComplete(bd_addr, tBTA_STATUS::BTA_SUCCESS);
- log::info("SDP finished for {}:", bd_addr);
+ log::info("SDP finished for {}", bd_addr);
pairing_cb.sdp_over_classic = btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED;
}
@@ -1620,7 +1620,7 @@ static void btif_on_service_discovery_results(RawAddress bd_addr,
bt_property_t& le_prop = uuid_props[1];
if ((result == BTA_SUCCESS) && !uuids_param.empty()) {
- log::info("New UUIDs for {}:", bd_addr);
+ log::info("New UUIDs for {}", bd_addr);
for (const auto& uuid : uuids_param) {
if (btif_should_ignore_uuid(uuid)) {
continue;
@@ -1758,7 +1758,7 @@ static void btif_on_gatt_results(RawAddress bd_addr, std::vector<bluetooth::Uuid
bool lea_supported = is_le_audio_capable_during_service_discovery(bd_addr);
if (is_transport_le) {
- log::info("New GATT over LE UUIDs for {}:", bd_addr);
+ log::info("New GATT over LE UUIDs for {}", bd_addr);
BTM_LogHistory(kBtmLogTag, bd_addr, "Discovered GATT services using LE transport");
if (btif_is_gatt_service_discovery_post_pairing(bd_addr)) {
pairing_cb.gatt_over_le = btif_dm_pairing_cb_t::ServiceDiscoveryState::FINISHED;
@@ -1786,7 +1786,7 @@ static void btif_on_gatt_results(RawAddress bd_addr, std::vector<bluetooth::Uuid
}
}
} else {
- log::debug("New GATT over SDP UUIDs for {}:", bd_addr);
+ log::debug("New GATT over SDP UUIDs for {}", bd_addr);
BTM_LogHistory(kBtmLogTag, bd_addr, "Discovered GATT services using SDP transport");
}
diff --git a/system/btif/src/btif_hf.cc b/system/btif/src/btif_hf.cc
index c5dc2bca6a..178a1672e6 100644
--- a/system/btif/src/btif_hf.cc
+++ b/system/btif/src/btif_hf.cc
@@ -880,7 +880,7 @@ public:
bt_status_t DisconnectAudio(RawAddress* bd_addr) override;
bt_status_t isNoiseReductionSupported(RawAddress* bd_addr) override;
bt_status_t isVoiceRecognitionSupported(RawAddress* bd_addr) override;
- bt_status_t StartVoiceRecognition(RawAddress* bd_addr) override;
+ bt_status_t StartVoiceRecognition(RawAddress* bd_addr, bool sendResult) override;
bt_status_t StopVoiceRecognition(RawAddress* bd_addr) override;
bt_status_t VolumeControl(bthf_volume_type_t type, int volume, RawAddress* bd_addr) override;
bt_status_t DeviceStatusNotification(bthf_network_state_t ntk_state, bthf_service_type_t svc_type,
@@ -1023,7 +1023,7 @@ bt_status_t HeadsetInterface::isVoiceRecognitionSupported(RawAddress* bd_addr) {
return BT_STATUS_SUCCESS;
}
-bt_status_t HeadsetInterface::StartVoiceRecognition(RawAddress* bd_addr) {
+bt_status_t HeadsetInterface::StartVoiceRecognition(RawAddress* bd_addr, bool sendResult) {
CHECK_BTHF_INIT();
int idx = btif_hf_idx_by_bdaddr(bd_addr);
if ((idx < 0) || (idx >= BTA_AG_MAX_NUM_CLIENTS)) {
@@ -1039,9 +1039,11 @@ bt_status_t HeadsetInterface::StartVoiceRecognition(RawAddress* bd_addr) {
return BT_STATUS_UNSUPPORTED;
}
btif_hf_cb[idx].is_during_voice_recognition = true;
- tBTA_AG_RES_DATA ag_res = {};
- ag_res.state = true;
- BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_BVRA_RES, ag_res);
+ if (sendResult) {
+ tBTA_AG_RES_DATA ag_res = {};
+ ag_res.state = true;
+ BTA_AgResult(btif_hf_cb[idx].handle, BTA_AG_BVRA_RES, ag_res);
+ }
return BT_STATUS_SUCCESS;
}
diff --git a/system/btif/test/btif_core_test.cc b/system/btif/test/btif_core_test.cc
index 7342a17b99..3073bd194c 100644
--- a/system/btif/test/btif_core_test.cc
+++ b/system/btif/test/btif_core_test.cc
@@ -207,7 +207,8 @@ class BtifCoreTest : public ::testing::Test {
protected:
void SetUp() override {
callback_map_.clear();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
bluetooth::testing::set_hal_cbacks(&callbacks);
auto promise = std::promise<void>();
auto future = promise.get_future();
@@ -223,17 +224,17 @@ protected:
callback_map_["callback_thread_event"] = [&promise]() { promise.set_value(); };
CleanCoreInterface();
ASSERT_EQ(std::future_status::ready, future.wait_for(timeout_time));
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
callback_map_.erase("callback_thread_event");
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class BtifCoreWithControllerTest : public BtifCoreTest {
protected:
void SetUp() override {
BtifCoreTest::SetUp();
- ON_CALL(controller_, SupportsSniffSubrating).WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsSniffSubrating)
+ .WillByDefault(Return(true));
}
void TearDown() override { BtifCoreTest::TearDown(); }
@@ -761,12 +762,13 @@ class BtifCoreWithVendorSupportTest : public BtifCoreWithControllerTest {
protected:
void SetUp() override {
BtifCoreWithControllerTest::SetUp();
- bluetooth::hci::testing::mock_hci_layer_ = &hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
test::mock::osi_properties::osi_property_get.body = get_properties;
std::promise<void> configuration_promise;
auto configuration_done = configuration_promise.get_future();
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce(
// Replace with real PDL for 0xfc17
@@ -784,7 +786,7 @@ protected:
configuration_promise.set_value();
})
.RetiresOnSaturation();
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce([](std::unique_ptr<CommandBuilder> cmd,
ContextualOnceCallback<void(CommandCompleteView)> callback) {
@@ -798,7 +800,8 @@ protected:
callback(response);
})
.RetiresOnSaturation();
- EXPECT_CALL(hci_, RegisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT, _))
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
+ RegisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT, _))
.WillOnce(SaveArg<1>(&this->vse_callback_));
do_in_main_thread(BindOnce([]() { bluetooth::bqr::EnableBtQualityReport(get_main()); }));
ASSERT_EQ(std::future_status::ready, configuration_done.wait_for(std::chrono::seconds(1)));
@@ -808,18 +811,18 @@ protected:
std::promise<void> disable_promise;
auto disable_future = disable_promise.get_future();
auto set_promise = [&disable_promise]() { disable_promise.set_value(); };
- EXPECT_CALL(hci_, UnregisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT));
- EXPECT_CALL(hci_,
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
+ UnregisterVendorSpecificEventHandler(VseSubeventCode::BQR_EVENT));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_,
EnqueueCommand(_, Matcher<ContextualOnceCallback<void(CommandCompleteView)>>(_)))
.WillOnce(Invoke(set_promise))
.RetiresOnSaturation();
do_in_main_thread(BindOnce([]() { bluetooth::bqr::DisableBtQualityReport(); }));
ASSERT_EQ(std::future_status::ready, disable_future.wait_for(std::chrono::seconds(1)));
- bluetooth::hci::testing::mock_hci_layer_ = nullptr;
+ bluetooth::hci::testing::mock_hci_layer_.reset();
BtifCoreWithControllerTest::TearDown();
}
- bluetooth::hci::testing::MockHciLayer hci_;
ContextualCallback<void(VendorSpecificEventView)> vse_callback_;
};
diff --git a/system/common/Android.bp b/system/common/Android.bp
index c192613dbc..a22a733e75 100644
--- a/system/common/Android.bp
+++ b/system/common/Android.bp
@@ -32,17 +32,6 @@ cc_library_static {
canonical_path_from_root: false,
export_proto_headers: true,
},
- target: {
- android: {
- srcs: [
- "metrics.cc",
- ],
- static_libs: ["libstatslog_bt"],
- },
- host: {
- srcs: ["metrics_linux.cc"],
- },
- },
shared_libs: [
"libcrypto",
"libcutils",
diff --git a/system/common/BUILD.gn b/system/common/BUILD.gn
index a1884973dd..5b0852bd36 100644
--- a/system/common/BUILD.gn
+++ b/system/common/BUILD.gn
@@ -19,8 +19,6 @@ static_library("common") {
"address_obfuscator.cc",
"le_conn_params.cc",
"message_loop_thread.cc",
- "metric_id_allocator.cc",
- "metrics_linux.cc",
"os_utils.cc",
"repeating_timer.cc",
"stop_watch_legacy.cc",
@@ -30,7 +28,6 @@ static_library("common") {
include_dirs = [
"//bt/system/",
"//bt/system/stack/include",
- "//bt/system/linux_include",
]
deps = [
diff --git a/system/common/metrics.cc b/system/common/metrics.cc
deleted file mode 100644
index a3b3eea450..0000000000
--- a/system/common/metrics.cc
+++ /dev/null
@@ -1,433 +0,0 @@
-/******************************************************************************
- *
- * Copyright 2016 Google, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-#include "common/metrics.h"
-
-#include <base/base64.h>
-#include <bluetooth/log.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/le/enums.pb.h>
-#include <include/hardware/bt_av.h>
-#include <statslog_bt.h>
-#include <unistd.h>
-
-#include <algorithm>
-#include <cerrno>
-#include <cstdint>
-#include <cstring>
-#include <memory>
-#include <mutex> // NOLINT
-#include <utility>
-
-#include "common/address_obfuscator.h"
-#include "common/leaky_bonded_queue.h"
-#include "common/time_util.h"
-#include "hci/address.h"
-#include "main/shim/metric_id_api.h"
-#include "osi/include/osi.h"
-#include "types/raw_address.h"
-
-namespace std {
-template <>
-struct formatter<android::bluetooth::DirectionEnum>
- : enum_formatter<android::bluetooth::DirectionEnum> {};
-template <>
-struct formatter<android::bluetooth::SocketConnectionstateEnum>
- : enum_formatter<android::bluetooth::SocketConnectionstateEnum> {};
-template <>
-struct formatter<android::bluetooth::SocketRoleEnum>
- : enum_formatter<android::bluetooth::SocketRoleEnum> {};
-template <>
-struct formatter<android::bluetooth::AddressTypeEnum>
- : enum_formatter<android::bluetooth::AddressTypeEnum> {};
-template <>
-struct formatter<android::bluetooth::DeviceInfoSrcEnum>
- : enum_formatter<android::bluetooth::DeviceInfoSrcEnum> {};
-template <>
-struct formatter<android::bluetooth::SocketErrorEnum>
- : enum_formatter<android::bluetooth::SocketErrorEnum> {};
-} // namespace std
-
-namespace bluetooth {
-namespace common {
-
-using bluetooth::hci::Address;
-
-void LogLinkLayerConnectionEvent(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) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (address != nullptr) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(*address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(*address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address != nullptr ? obfuscated_id.c_str() : nullptr,
- address != nullptr ? obfuscated_id.size() : 0);
- int ret = stats_write(BLUETOOTH_LINK_LAYER_CONNECTION_EVENT, bytes_field, connection_handle,
- direction, link_type, hci_cmd, hci_event, hci_ble_event, cmd_status,
- reason_code, metric_id);
- if (ret < 0) {
- log::warn(
- "failed to log status 0x{:x}, reason 0x{:x} from cmd 0x{:x}, event "
- "0x{:x}, ble_event 0x{:x} for {}, handle {}, type 0x{:x}, error {}",
- cmd_status, reason_code, hci_cmd, hci_event, hci_ble_event, *address, connection_handle,
- link_type, ret);
- }
-}
-
-void LogHciTimeoutEvent(uint32_t hci_cmd) {
- int ret = stats_write(BLUETOOTH_HCI_TIMEOUT_REPORTED, static_cast<int64_t>(hci_cmd));
- if (ret < 0) {
- log::warn("failed for opcode 0x{:x}, error {}", hci_cmd, ret);
- }
-}
-
-void LogRemoteVersionInfo(uint16_t handle, uint8_t status, uint8_t version,
- uint16_t manufacturer_name, uint16_t subversion) {
- int ret = stats_write(BLUETOOTH_REMOTE_VERSION_INFO_REPORTED, handle, status, version,
- manufacturer_name, subversion);
- if (ret < 0) {
- log::warn(
- "failed for handle {}, status 0x{:x}, version 0x{:x}, "
- "manufacturer_name 0x{:x}, subversion 0x{:x}, error {}",
- handle, status, version, manufacturer_name, subversion, ret);
- }
-}
-
-void LogA2dpAudioUnderrunEvent(const RawAddress& address, uint64_t encoding_interval_millis,
- int num_missing_pcm_bytes) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int64_t encoding_interval_nanos = encoding_interval_millis * 1000000;
- int ret = stats_write(BLUETOOTH_A2DP_AUDIO_UNDERRUN_REPORTED, bytes_field,
- encoding_interval_nanos, num_missing_pcm_bytes, metric_id);
- if (ret < 0) {
- log::warn(
- "failed for {}, encoding_interval_nanos {}, num_missing_pcm_bytes {}, "
- "error {}",
- address, encoding_interval_nanos, num_missing_pcm_bytes, ret);
- }
-}
-
-void LogA2dpAudioOverrunEvent(const RawAddress& address, uint64_t encoding_interval_millis,
- int num_dropped_buffers, int num_dropped_encoded_frames,
- int num_dropped_encoded_bytes) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int64_t encoding_interval_nanos = encoding_interval_millis * 1000000;
- int ret = stats_write(BLUETOOTH_A2DP_AUDIO_OVERRUN_REPORTED, bytes_field, encoding_interval_nanos,
- num_dropped_buffers, num_dropped_encoded_frames, num_dropped_encoded_bytes,
- metric_id);
- if (ret < 0) {
- log::warn(
- "failed to log for {}, encoding_interval_nanos {}, num_dropped_buffers "
- "{}, num_dropped_encoded_frames {}, num_dropped_encoded_bytes {}, "
- "error {}",
- address, encoding_interval_nanos, num_dropped_buffers, num_dropped_encoded_frames,
- num_dropped_encoded_bytes, ret);
- }
-}
-
-void LogA2dpPlaybackEvent(const RawAddress& address, int playback_state, int audio_coding_mode) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_A2DP_PLAYBACK_STATE_CHANGED, bytes_field, playback_state,
- audio_coding_mode, metric_id);
- if (ret < 0) {
- log::warn(
- "failed to log for {}, playback_state {}, audio_coding_mode {}, error "
- "{}",
- address, playback_state, audio_coding_mode, ret);
- }
-}
-
-void LogReadRssiResult(const RawAddress& address, uint16_t handle, uint32_t cmd_status,
- int8_t rssi) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_DEVICE_RSSI_REPORTED, bytes_field, handle, cmd_status, rssi,
- metric_id);
- if (ret < 0) {
- log::warn("failed for {}, handle {}, status 0x{:x}, rssi {} dBm, error {}", address, handle,
- cmd_status, rssi, ret);
- }
-}
-
-void LogReadFailedContactCounterResult(const RawAddress& address, uint16_t handle,
- uint32_t cmd_status, int32_t failed_contact_counter) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_DEVICE_FAILED_CONTACT_COUNTER_REPORTED, bytes_field, handle,
- cmd_status, failed_contact_counter, metric_id);
- if (ret < 0) {
- log::warn(
- "failed for {}, handle {}, status 0x{:x}, failed_contact_counter {} "
- "packets, error {}",
- address, handle, cmd_status, failed_contact_counter, ret);
- }
-}
-
-void LogReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, uint32_t cmd_status,
- int32_t transmit_power_level) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField bytes_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_DEVICE_TX_POWER_LEVEL_REPORTED, bytes_field, handle, cmd_status,
- transmit_power_level, metric_id);
- if (ret < 0) {
- log::warn(
- "failed for {}, handle {}, status 0x{:x}, transmit_power_level {} "
- "packets, error {}",
- address, handle, cmd_status, transmit_power_level, ret);
- }
-}
-
-void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField obfuscated_id_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_SMP_PAIRING_EVENT_REPORTED, obfuscated_id_field, smp_cmd,
- direction, smp_fail_reason, metric_id);
- if (ret < 0) {
- log::warn(
- "failed for {}, smp_cmd 0x{:x}, direction {}, smp_fail_reason 0x{:x}, "
- "error {}",
- address, smp_cmd, direction, smp_fail_reason, ret);
- }
-}
-
-void LogClassicPairingEvent(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) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField obfuscated_id_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_CLASSIC_PAIRING_EVENT_REPORTED, obfuscated_id_field, handle,
- hci_cmd, hci_event, cmd_status, reason_code, event_value, metric_id);
- if (ret < 0) {
- log::warn(
- "failed for {}, handle {}, hci_cmd 0x{:x}, hci_event 0x{:x}, "
- "cmd_status 0x{:x}, reason 0x{:x}, event_value {}, error {}",
- address, handle, hci_cmd, hci_event, cmd_status, reason_code, event_value, ret);
- }
-}
-
-void LogSdpAttribute(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField obfuscated_id_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- BytesField attribute_field(attribute_value, attribute_size);
- int ret = stats_write(BLUETOOTH_SDP_ATTRIBUTE_REPORTED, obfuscated_id_field, protocol_uuid,
- attribute_id, attribute_field, metric_id);
- if (ret < 0) {
- log::warn("failed for {}, protocol_uuid 0x{:x}, attribute_id 0x{:x}, error {}", address,
- protocol_uuid, attribute_id, ret);
- }
-}
-
-void LogSocketConnectionState(const RawAddress& address, int port, int type,
- android::bluetooth::SocketConnectionstateEnum connection_state,
- int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
- android::bluetooth::SocketRoleEnum socket_role,
- uint64_t connection_duration_ms,
- android::bluetooth::SocketErrorEnum error_code,
- bool is_hardware_offload) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField obfuscated_id_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_SOCKET_CONNECTION_STATE_CHANGED, obfuscated_id_field, port, type,
- connection_state, tx_bytes, rx_bytes, uid, server_port, socket_role,
- metric_id, static_cast<int64_t>(connection_duration_ms), error_code,
- is_hardware_offload);
- if (ret < 0) {
- log::warn(
- "failed for {}, port {}, type {}, state {}, tx_bytes {}, rx_bytes {}, "
- "uid {}, server_port {}, socket_role {}, error {}, connection_duration_ms {}, "
- "socket_error_code {}, "
- "is_hardware_offload {}",
- address, port, type, connection_state, tx_bytes, rx_bytes, uid, server_port,
- socket_role, ret, connection_duration_ms, error_code, is_hardware_offload);
- }
-}
-
-void LogManufacturerInfo(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) {
- std::string obfuscated_id;
- int metric_id = 0;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- metric_id = bluetooth::shim::AllocateIdFromMetricIdAllocator(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField obfuscated_id_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_DEVICE_INFO_REPORTED, obfuscated_id_field, source_type,
- source_name.c_str(), manufacturer.c_str(), model.c_str(),
- hardware_version.c_str(), software_version.c_str(), metric_id, address_type,
- address.address[5], address.address[4], address.address[3]);
- if (ret < 0) {
- log::warn(
- "failed for {}, source_type {}, source_name {}, manufacturer {}, model "
- "{}, hardware_version {}, software_version {} MAC address type {} MAC "
- "address prefix {} {} {}, error {}",
- address, source_type, source_name, manufacturer, model, hardware_version,
- software_version, address_type, address.address[5], address.address[4],
- address.address[3], ret);
- }
-}
-
-void LogBluetoothHalCrashReason(const RawAddress& address, uint32_t error_code,
- uint32_t vendor_error_code) {
- std::string obfuscated_id;
- if (!address.IsEmpty()) {
- obfuscated_id = AddressObfuscator::GetInstance()->Obfuscate(address);
- }
- // nullptr and size 0 represent missing value for obfuscated_id
- BytesField obfuscated_id_field(address.IsEmpty() ? nullptr : obfuscated_id.c_str(),
- address.IsEmpty() ? 0 : obfuscated_id.size());
- int ret = stats_write(BLUETOOTH_HAL_CRASH_REASON_REPORTED, 0, obfuscated_id_field, error_code,
- vendor_error_code);
- if (ret < 0) {
- log::warn("failed for {}, error_code 0x{:x}, vendor_error_code 0x{:x}, error {}", address,
- error_code, vendor_error_code, ret);
- }
-}
-
-void LogLeAudioConnectionSessionReported(
- int32_t group_size, int32_t group_metric_id, int64_t connection_duration_nanos,
- const std::vector<int64_t>& device_connecting_offset_nanos,
- const std::vector<int64_t>& device_connected_offset_nanos,
- const std::vector<int64_t>& device_connection_duration_nanos,
- const std::vector<int32_t>& device_connection_status,
- const std::vector<int32_t>& device_disconnection_status,
- const std::vector<RawAddress>& device_address,
- const std::vector<int64_t>& streaming_offset_nanos,
- const std::vector<int64_t>& streaming_duration_nanos,
- const std::vector<int32_t>& streaming_context_type) {
- std::vector<int32_t> device_metric_id(device_address.size());
- for (uint64_t i = 0; i < device_address.size(); i++) {
- if (!device_address[i].IsEmpty()) {
- device_metric_id[i] = bluetooth::shim::AllocateIdFromMetricIdAllocator(device_address[i]);
- } else {
- device_metric_id[i] = 0;
- }
- }
- int ret = stats_write(LE_AUDIO_CONNECTION_SESSION_REPORTED, group_size, group_metric_id,
- connection_duration_nanos, device_connecting_offset_nanos,
- device_connected_offset_nanos, device_connection_duration_nanos,
- device_connection_status, device_disconnection_status, device_metric_id,
- streaming_offset_nanos, streaming_duration_nanos, streaming_context_type);
- if (ret < 0) {
- log::warn(
- "failed for group {}device_connecting_offset_nanos[{}], "
- "device_connected_offset_nanos[{}], "
- "device_connection_duration_nanos[{}], device_connection_status[{}], "
- "device_disconnection_status[{}], device_metric_id[{}], "
- "streaming_offset_nanos[{}], streaming_duration_nanos[{}], "
- "streaming_context_type[{}]",
- group_metric_id, device_connecting_offset_nanos.size(),
- device_connected_offset_nanos.size(), device_connection_duration_nanos.size(),
- device_connection_status.size(), device_disconnection_status.size(),
- device_metric_id.size(), streaming_offset_nanos.size(), streaming_duration_nanos.size(),
- streaming_context_type.size());
- }
-}
-
-void LogLeAudioBroadcastSessionReported(int64_t duration_nanos) {
- int ret = stats_write(LE_AUDIO_BROADCAST_SESSION_REPORTED, duration_nanos);
- if (ret < 0) {
- log::warn("failed for duration={}", duration_nanos);
- }
-}
-
-} // namespace common
-
-} // namespace bluetooth
diff --git a/system/common/metrics.h b/system/common/metrics.h
deleted file mode 100644
index 4ccb47f64c..0000000000
--- a/system/common/metrics.h
+++ /dev/null
@@ -1,272 +0,0 @@
-/******************************************************************************
- *
- * Copyright 2016 Google, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-#pragma once
-
-#include <bta/include/bta_api.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/le/enums.pb.h>
-#include <stdint.h>
-
-#include <memory>
-#include <string>
-#include <vector>
-
-#include "hci/address.h"
-#include "os/metrics.h"
-#include "types/raw_address.h"
-
-namespace bluetooth {
-
-namespace common {
-
-/**
- * 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, 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);
-
-/**
- * Logs when Bluetooth controller failed to reply with command status within
- * a timeout period after receiving an HCI command from the host
- *
- * @param hci_cmd opcode of HCI command that caused this timeout
- */
-void LogHciTimeoutEvent(uint32_t hci_cmd);
-
-/**
- * Logs when we receive Bluetooth Read Remote Version Information Complete
- * Event from the remote device, as documented by the Bluetooth Core HCI
- * specification
- *
- * Reference: 5.0 Core Specification, Vol 2, Part E, Page 1118
- *
- * @param handle handle of associated ACL connection
- * @param status HCI command status of this event
- * @param version version code from read remote version complete event
- * @param manufacturer_name manufacturer code from read remote version complete
- * event
- * @param subversion subversion code from read remote version complete event
- */
-void LogRemoteVersionInfo(uint16_t handle, uint8_t status, uint8_t version,
- uint16_t manufacturer_name, uint16_t subversion);
-
-/**
- * Log A2DP audio buffer underrun event
- *
- * @param address A2DP device associated with this event
- * @param encoding_interval_millis encoding interval in milliseconds
- * @param num_missing_pcm_bytes number of PCM bytes that cannot be read from
- * the source
- */
-void LogA2dpAudioUnderrunEvent(const RawAddress& address, uint64_t encoding_interval_millis,
- int num_missing_pcm_bytes);
-
-/**
- * Log A2DP audio buffer overrun event
- *
- * @param address A2DP device associated with this event
- * @param encoding_interval_millis encoding interval in milliseconds
- * @param num_dropped_buffers number of encoded buffers dropped from Tx queue
- * @param num_dropped_encoded_frames number of encoded frames dropped from Tx
- * queue
- * @param num_dropped_encoded_bytes number of encoded bytes dropped from Tx
- * queue
- */
-void LogA2dpAudioOverrunEvent(const RawAddress& address, uint64_t encoding_interval_millis,
- int num_dropped_buffers, int num_dropped_encoded_frames,
- int num_dropped_encoded_bytes);
-
-/**
- * Log A2DP playback state changed event
- *
- * @param address A2DP device associated with this event
- * @param playback_state audio playback state
- * @param audio_coding_mode audio codec encoding mode
- */
-void LogA2dpPlaybackEvent(const RawAddress& address, int playback_state, int audio_coding_mode);
-
-/**
- * Log read RSSI result
- *
- * @param address device associated with this event
- * @param handle connection handle of this event,
- * {@link kUnknownConnectionHandle} if unknown
- * @param cmd_status command status from read RSSI command
- * @param rssi rssi value in dBm
- */
-void LogReadRssiResult(const RawAddress& address, uint16_t handle, uint32_t cmd_status,
- int8_t rssi);
-
-/**
- * Log failed contact counter report
- *
- * @param address device associated with this event
- * @param handle connection handle of this event,
- * {@link kUnknownConnectionHandle} if unknown
- * @param cmd_status command status from read failed contact counter command
- * @param failed_contact_counter Number of consecutive failed contacts for a
- * connection corresponding to the Handle
- */
-void LogReadFailedContactCounterResult(const RawAddress& address, uint16_t handle,
- uint32_t cmd_status, int32_t failed_contact_counter);
-
-/**
- * Log transmit power level for a particular device after read
- *
- * @param address device associated with this event
- * @param handle connection handle of this event,
- * {@link kUnknownConnectionHandle} if unknown
- * @param cmd_status command status from read failed contact counter command
- * @param transmit_power_level transmit power level for connection to this
- * device
- */
-void LogReadTxPowerLevelResult(const RawAddress& address, uint16_t handle, uint32_t cmd_status,
- int32_t transmit_power_level);
-
-/**
- * Logs when there is an event related to Bluetooth Security Manager Protocol
- *
- * @param address address of associated device
- * @param smp_cmd SMP command code associated with this event
- * @param direction direction of this SMP command
- * @param smp_fail_reason SMP pairing failure reason code from SMP spec
- */
-void LogSmpPairingEvent(const RawAddress& address, uint8_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason);
-
-/**
- * Logs there is an event related Bluetooth classic pairing
- *
- * @param address address of associated device
- * @param handle connection handle of this event,
- * {@link kUnknownConnectionHandle} if unknown
- * @param hci_cmd HCI command associated with this event
- * @param hci_event HCI event associated with this event
- * @param cmd_status Command status associated with this event
- * @param reason_code Reason code associated with this event
- * @param event_value A status value related to this specific event
- */
-void LogClassicPairingEvent(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);
-
-/**
- * Logs when certain Bluetooth SDP attributes are discovered
- *
- * @param address address of associated device
- * @param protocol_uuid 16 bit protocol UUID from Bluetooth Assigned Numbers
- * @param attribute_id 16 bit attribute ID from Bluetooth Assigned Numbers
- * @param attribute_size size of this attribute
- * @param attribute_value pointer to the attribute data, must be larger than
- * attribute_size
- */
-void LogSdpAttribute(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value);
-
-/**
- * Logs when there is a change in Bluetooth socket connection state
- *
- * @param address address of associated device, empty if this is a server port
- * @param port port of this socket connection
- * @param type type of socket
- * @param connection_state socket connection state
- * @param tx_bytes number of bytes transmitted
- * @param rx_bytes number of bytes received
- * @param server_port server port of this socket, if any. When both
- * |server_port| and |port| fields are populated, |port| must be spawned
- * by |server_port|
- * @param socket_role role of this socket, server or connection
- * @param uid socket owner's uid
- * @param connection_duration_ms duration of socket connection in milliseconds
- * @param error_code error code of socket failures
- * @param is_hardware_offload whether this is a offload socket
- */
-void LogSocketConnectionState(const RawAddress& address, int port, int type,
- android::bluetooth::SocketConnectionstateEnum connection_state,
- int64_t tx_bytes, int64_t rx_bytes, int uid, int server_port,
- android::bluetooth::SocketRoleEnum socket_role,
- uint64_t connection_duration_ms,
- android::bluetooth::SocketErrorEnum error_code,
- bool is_hardware_offload);
-
-/**
- * Logs when a Bluetooth device's manufacturer information is learnt
- *
- * @param address address of associated device
- * @param source_type where is this device info obtained from
- * @param source_name name of the data source, internal or external
- * @param manufacturer name of the manufacturer of this device
- * @param model model of this device
- * @param hardware_version hardware version of this device
- * @param software_version software version of this device
- */
-void LogManufacturerInfo(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);
-
-/**
- * Logs when received Bluetooth HAL crash reason report.
- *
- * @param address current connected address.
- * @param error_code the crash reason from bluetooth hal
- * @param vendor_error_code the vendor crash reason from bluetooth Firmware
- */
-void LogBluetoothHalCrashReason(const RawAddress& address, uint32_t error_code,
- uint32_t vendor_error_code);
-
-void LogLeAudioConnectionSessionReported(
- int32_t group_size, int32_t group_metric_id, int64_t connection_duration_nanos,
- const std::vector<int64_t>& device_connecting_offset_nanos,
- const std::vector<int64_t>& device_connected_offset_nanos,
- const std::vector<int64_t>& device_connection_duration_nanos,
- const std::vector<int32_t>& device_connection_status,
- const std::vector<int32_t>& device_disconnection_status,
- const std::vector<RawAddress>& device_address,
- const std::vector<int64_t>& streaming_offset_nanos,
- const std::vector<int64_t>& streaming_duration_nanos,
- const std::vector<int32_t>& streaming_context_type);
-
-void LogLeAudioBroadcastSessionReported(int64_t duration_nanos);
-
-} // namespace common
-
-} // namespace bluetooth
diff --git a/system/common/metrics_linux.cc b/system/common/metrics_linux.cc
deleted file mode 100644
index 3283619415..0000000000
--- a/system/common/metrics_linux.cc
+++ /dev/null
@@ -1,111 +0,0 @@
-/******************************************************************************
- *
- * Copyright 2018 Google, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-
-#include <bluetooth/log.h>
-
-#include "common/metrics.h"
-#include "types/raw_address.h"
-
-namespace bluetooth {
-
-namespace common {
-
-void LogClassicPairingEvent(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 */) {}
-
-void LogSocketConnectionState(const RawAddress& /* address */, int /* port */, int /* type */,
- android::bluetooth::SocketConnectionstateEnum /* connection_state */,
- int64_t /* tx_bytes */, int64_t /* rx_bytes */, int /* uid */,
- int /* server_port */,
- android::bluetooth::SocketRoleEnum /* socket_role */,
- uint64_t /* connection_duration_ms */,
- android::bluetooth::SocketErrorEnum /* error_code */,
- bool /* is_hardware_offload */) {}
-
-void LogHciTimeoutEvent(uint32_t /* hci_cmd */) {}
-
-void LogA2dpAudioUnderrunEvent(const RawAddress& /* address */,
- uint64_t /* encoding_interval_millis */,
- int /* num_missing_pcm_bytes */) {}
-
-void LogA2dpAudioOverrunEvent(const RawAddress& /* address */,
- uint64_t /* encoding_interval_millis */,
- int /* num_dropped_buffers */, int /* num_dropped_encoded_frames */,
- int /* num_dropped_encoded_bytes */) {}
-
-void LogA2dpPlaybackEvent(const RawAddress& /* address */, int /* playback_state */,
- int /* audio_coding_mode */) {}
-
-void LogBluetoothHalCrashReason(const RawAddress& /* address */, uint32_t /* error_code */,
- uint32_t /* vendor_error_code */) {}
-
-void LogReadRssiResult(const RawAddress& /* address */, uint16_t /* handle */,
- uint32_t /* cmd_status */, int8_t /* rssi */) {}
-
-void LogReadFailedContactCounterResult(const RawAddress& /* address */, uint16_t /* handle */,
- uint32_t /* cmd_status */,
- int32_t /* failed_contact_counter */) {}
-
-void LogReadTxPowerLevelResult(const RawAddress& /* address */, uint16_t /* handle */,
- uint32_t /* cmd_status */, int32_t /* transmit_power_level */) {}
-
-void LogRemoteVersionInfo(uint16_t /* handle */, uint8_t /* status */, uint8_t /* version */,
- uint16_t /* manufacturer_name */, uint16_t /* subversion */) {}
-
-void LogLinkLayerConnectionEvent(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 */) {}
-
-void LogManufacturerInfo(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 */) {}
-
-void LogSdpAttribute(const RawAddress& /* address */, uint16_t /* protocol_uuid */,
- uint16_t /* attribute_id */, size_t /* attribute_size */,
- const char* /* attribute_value */) {}
-
-void LogSmpPairingEvent(const RawAddress& /* address */, uint8_t /* smp_cmd */,
- android::bluetooth::DirectionEnum /* direction */,
- uint8_t /* smp_fail_reason */) {}
-
-void LogLeAudioConnectionSessionReported(
- int32_t /* group_size */, int32_t /* group_metric_id */,
- int64_t /* connection_duration_nanos */,
- const std::vector<int64_t>& /* device_connecting_offset_nanos */,
- const std::vector<int64_t>& /* device_connected_offset_nanos */,
- const std::vector<int64_t>& /* device_connection_duration_nanos */,
- const std::vector<int32_t>& /* device_connection_status */,
- const std::vector<int32_t>& /* device_disconnection_status */,
- const std::vector<RawAddress>& /* device_address */,
- const std::vector<int64_t>& /* streaming_offset_nanos */,
- const std::vector<int64_t>& /* streaming_duration_nanos */,
- const std::vector<int32_t>& /* streaming_context_type */) {}
-
-void LogLeAudioBroadcastSessionReported(int64_t /* duration_nanos */) {}
-
-} // namespace common
-
-} // namespace bluetooth
diff --git a/system/conf/interop_database.conf b/system/conf/interop_database.conf
index ecf3da0b07..d921db421d 100644
--- a/system/conf/interop_database.conf
+++ b/system/conf/interop_database.conf
@@ -895,3 +895,8 @@ BSK10 = Name_Based
[INTEROP_DISABLE_HF_PROFILE]
JBL Flip 5 = Name_Based
JBL Flip 6 = Name_Based
+
+# Some devices don't respond to LE appearance read request.
+[INTEROP_DISABLE_READ_LE_APPEARANCE]
+L1_L = Name_Based
+L1_R = Name_Based
diff --git a/system/device/include/interop.h b/system/device/include/interop.h
index 22233bcd65..d72315d1b0 100644
--- a/system/device/include/interop.h
+++ b/system/device/include/interop.h
@@ -358,16 +358,20 @@ typedef enum {
// Peer can request proper latency based on its power state later.
INTEROP_HID_PREF_CONN_ZERO_LATENCY,
- // Some HOGP devices have the report map longer than the maximum GATT attribute value length (512
- // bytes).
+ // Some HOGP devices have the report map longer than the maximum GATT
+ // attribute value length (512 bytes).
INTEROP_HOGP_LONG_REPORT,
- // Some HOGP devices requires MTU exchange be part of the initial setup to function.
+ // Some HOGP devices requires MTU exchange be part of the initial setup to
+ // function.
INTEROP_HOGP_FORCE_MTU_EXCHANGE,
// Some devices claim to support HFP in EIR but does not actually support it.
INTEROP_DISABLE_HF_PROFILE,
+ // Some devices don't respond to LE appearance read request.
+ INTEROP_DISABLE_READ_LE_APPEARANCE,
+
END_OF_INTEROP_LIST
} interop_feature_t;
diff --git a/system/device/src/interop.cc b/system/device/src/interop.cc
index 60d90cf6d6..44313664ed 100644
--- a/system/device/src/interop.cc
+++ b/system/device/src/interop.cc
@@ -392,6 +392,7 @@ static const char* interop_feature_string_(const interop_feature_t feature) {
CASE_RETURN_STR(INTEROP_HOGP_LONG_REPORT);
CASE_RETURN_STR(INTEROP_HOGP_FORCE_MTU_EXCHANGE);
CASE_RETURN_STR(INTEROP_DISABLE_HF_PROFILE);
+ CASE_RETURN_STR(INTEROP_DISABLE_READ_LE_APPEARANCE);
}
return UNKNOWN_INTEROP_FEATURE;
}
diff --git a/system/gd/Android.bp b/system/gd/Android.bp
index 26f31f0b8e..45555f130a 100644
--- a/system/gd/Android.bp
+++ b/system/gd/Android.bp
@@ -194,7 +194,7 @@ cc_library_static {
"packages/modules/Bluetooth/system",
],
apex_available: ["com.android.bt"],
- min_sdk_version: "31",
+ min_sdk_version: "33",
static_libs: [
"bluetooth_flags_c_lib",
"libchrome",
@@ -357,8 +357,8 @@ cc_test {
srcs: [
":BluetoothPacketTestSources",
":TestCommonMockFunctions",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
- ":TestMockStackMetrics",
"common/bidi_queue_unittest.cc",
"common/blocking_queue_unittest.cc",
"common/byte_array_test.cc",
@@ -414,6 +414,9 @@ cc_test {
"storage/mutation_test.cc",
"storage/storage_module_test.cc",
],
+ cflags: [
+ "-DUSE_FAKE_TIMERS",
+ ],
static_libs: [
"bluetooth_flags_c_lib_for_test",
"libbase",
@@ -581,11 +584,12 @@ cc_fuzz {
defaults: ["gd_fuzz_defaults"],
srcs: [
":TestCommonMockFunctions",
- ":TestMockStackMetrics",
+ ":TestMockMainShim",
"hci/fuzz/acl_manager_fuzz_test.cc",
],
include_dirs: [
"packages/modules/Bluetooth/system",
+ "packages/modules/Bluetooth/system/include",
],
static_libs: [
"libbt-platform-protos-lite",
diff --git a/system/gd/common/audit_log.cc b/system/gd/common/audit_log.cc
index e83c2894f8..2e112a0c34 100644
--- a/system/gd/common/audit_log.cc
+++ b/system/gd/common/audit_log.cc
@@ -16,6 +16,8 @@
#include "common/audit_log.h"
+#include <format>
+
#ifdef __ANDROID__
#include <log/log_event_list.h>
#endif // __ANDROID__
@@ -43,8 +45,8 @@ void LogConnectionAdminAuditEvent([[maybe_unused]] const char* action,
android_log_event_list(SEC_TAG_BLUETOOTH_CONNECTION)
<< address.ToRedactedStringForLogging()
- << /* success */ int32_t(status == hci::ErrorCode::SUCCESS) << action << ": "
- << ErrorCodeText(status) << LOG_ID_SECURITY;
+ << /* success */ int32_t(status == hci::ErrorCode::SUCCESS)
+ << std::format("{}: {}", action, ErrorCodeText(status)) << LOG_ID_SECURITY;
#endif /* defined(__ANDROID__) && !defined (FUZZ_TARGET) */
}
diff --git a/system/gd/hal/hci_hal_android_test.cc b/system/gd/hal/hci_hal_android_test.cc
index 247f15745f..f128f508cf 100644
--- a/system/gd/hal/hci_hal_android_test.cc
+++ b/system/gd/hal/hci_hal_android_test.cc
@@ -20,6 +20,7 @@
#include <queue>
#include <thread>
+#include "com_android_bluetooth_flags.h"
#include "hal/hci_backend.h"
#include "hal/hci_hal.h"
#include "os/thread.h"
@@ -79,10 +80,13 @@ protected:
}
void TearDown() override {
- fake_registry_.StopAll();
handler_->Clear();
- delete thread_;
+ if (com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ handler_->WaitUntilStopped(bluetooth::kHandlerStopTimeout);
+ }
+ fake_registry_.StopAll();
delete handler_;
+ delete thread_;
}
HciHal* hal;
diff --git a/system/gd/hal/hci_hal_host_test.cc b/system/gd/hal/hci_hal_host_test.cc
index 4f4c6bc6d0..d4539d6c3b 100644
--- a/system/gd/hal/hci_hal_host_test.cc
+++ b/system/gd/hal/hci_hal_host_test.cc
@@ -32,6 +32,7 @@
#include <utility>
#include <vector>
+#include "com_android_bluetooth_flags.h"
#include "hal/hci_hal.h"
#include "hal/serialize_packet.h"
#include "os/thread.h"
@@ -155,12 +156,15 @@ protected:
void TearDown() override {
hal_->unregisterIncomingPacketCallback();
+ handler_->Clear();
+ if (com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ handler_->WaitUntilStopped(bluetooth::kHandlerStopTimeout);
+ }
fake_registry_.StopAll();
+ delete handler_;
close(fake_server_socket_);
- handler_->Clear();
delete fake_server_;
delete thread_;
- delete handler_;
}
void SetFakeServerSocketToBlocking() {
diff --git a/system/gd/hal/snoop_logger.h b/system/gd/hal/snoop_logger.h
index b009add89c..b0783442b3 100644
--- a/system/gd/hal/snoop_logger.h
+++ b/system/gd/hal/snoop_logger.h
@@ -17,6 +17,7 @@
#pragma once
#include <bluetooth/log.h>
+#include <com_android_bluetooth_flags.h>
#include <fstream>
#include <string>
@@ -195,6 +196,13 @@ public:
};
SnoopLogger(os::Handler* handler);
+ ~SnoopLogger() {
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ GetHandler()->Clear();
+ GetHandler()->WaitUntilStopped(std::chrono::milliseconds(2000));
+ delete GetHandler();
+ }
+ }
// Returns the maximum number of packets per file
// Changes to this value is only effective after restarting Bluetooth
diff --git a/system/gd/hci/acl_manager.cc b/system/gd/hci/acl_manager.cc
index 73f455f168..280cc237b4 100644
--- a/system/gd/hci/acl_manager.cc
+++ b/system/gd/hci/acl_manager.cc
@@ -260,21 +260,6 @@ void AclManager::CreateLeConnection(AddressWithType address_with_type, bool is_d
CallOn(pimpl_->le_impl_, &le_impl::create_le_connection, address_with_type, true, is_direct);
}
-void AclManager::IsOnBackgroundList(AddressWithType address_with_type, std::promise<bool> promise) {
- CallOn(pimpl_->le_impl_, &le_impl::is_on_background_connection_list, address_with_type,
- std::move(promise));
-}
-
-void AclManager::SetLeSuggestedDefaultDataParameters(uint16_t octets, uint16_t time) {
- CallOn(pimpl_->le_impl_, &le_impl::set_le_suggested_default_data_parameters, octets, time);
-}
-
-void AclManager::LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max,
- uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) {
- CallOn(pimpl_->le_impl_, &le_impl::LeSetDefaultSubrate, subrate_min, subrate_max, max_latency,
- cont_num, sup_tout);
-}
-
void AclManager::SetPrivacyPolicyForInitiatorAddress(
LeAddressManager::AddressPolicy address_policy, AddressWithType fixed_address,
std::chrono::milliseconds minimum_rotation_time,
diff --git a/system/gd/hci/acl_manager.h b/system/gd/hci/acl_manager.h
index b6932eee52..f38f1ff689 100644
--- a/system/gd/hci/acl_manager.h
+++ b/system/gd/hci/acl_manager.h
@@ -86,12 +86,6 @@ public:
// Generates OnLeConnectSuccess if connected, or OnLeConnectFail otherwise
virtual void CreateLeConnection(AddressWithType address_with_type, bool is_direct);
- // Ask the controller for specific data parameters
- virtual void SetLeSuggestedDefaultDataParameters(uint16_t octets, uint16_t time);
-
- virtual void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout);
-
virtual void SetPrivacyPolicyForInitiatorAddress(LeAddressManager::AddressPolicy address_policy,
AddressWithType fixed_address,
std::chrono::milliseconds minimum_rotation_time,
@@ -108,7 +102,6 @@ public:
// connected
virtual void CancelConnect(Address address);
virtual void RemoveFromBackgroundList(AddressWithType address_with_type);
- virtual void IsOnBackgroundList(AddressWithType address_with_type, std::promise<bool> promise);
virtual void CancelLeConnect(AddressWithType address_with_type);
diff --git a/system/gd/hci/acl_manager/le_impl.h b/system/gd/hci/acl_manager/le_impl.h
index a6761e38b7..ef5bfb0d7d 100644
--- a/system/gd/hci/acl_manager/le_impl.h
+++ b/system/gd/hci/acl_manager/le_impl.h
@@ -39,11 +39,11 @@
#include "hci/hci_packets.h"
#include "hci/le_address_manager.h"
#include "macros.h"
+#include "main/shim/metrics_api.h"
#include "os/alarm.h"
#include "os/handler.h"
#include "os/system_properties.h"
#include "stack/include/btm_ble_api_types.h"
-#include "stack/include/stack_metrics_logging.h"
namespace bluetooth {
namespace hci {
@@ -426,7 +426,7 @@ public:
return;
}
- log_le_connection_status(address, true /* is_connect */, status);
+ bluetooth::shim::LogMetricLeConnectionStatus(address, true /* is_connect */, status);
const bool in_filter_accept_list = is_device_in_accept_list(remote_address);
@@ -586,7 +586,8 @@ public:
arm_on_resume_ = true;
add_device_to_accept_list(remote_address);
}
- log_le_connection_status(remote_address.GetAddress(), false /* is_connect */, reason);
+ bluetooth::shim::LogMetricLeConnectionStatus(remote_address.GetAddress(),
+ false /* is_connect */, reason);
}
void on_le_connection_update_complete(LeMetaEventView view) {
@@ -724,7 +725,8 @@ public:
}
void add_device_to_accept_list(AddressWithType address_with_type) {
- log_le_device_in_accept_list(address_with_type.GetAddress(), true /* is_add */);
+ bluetooth::shim::LogMetricLeDeviceInAcceptList(address_with_type.GetAddress(),
+ true /* is_add */);
if (connections.alreadyConnected(address_with_type)) {
log::info("Device already connected, return");
return;
@@ -747,7 +749,8 @@ public:
}
void remove_device_from_accept_list(AddressWithType address_with_type) {
- log_le_device_in_accept_list(address_with_type.GetAddress(), false /* is_add */);
+ bluetooth::shim::LogMetricLeDeviceInAcceptList(address_with_type.GetAddress(),
+ false /* is_add */);
if (accept_list.find(address_with_type) == accept_list.end()) {
log::warn("Device not in acceptlist and cannot be removed: {}", address_with_type);
return;
@@ -1132,8 +1135,9 @@ public:
remove_device_from_accept_list(address_with_type);
}
// Temporary mapping the error code to PAGE_TIMEOUT
- log_le_connection_completion(address_with_type.GetAddress(), ErrorCode::PAGE_TIMEOUT,
- true /* is locally initiated */);
+ bluetooth::shim::LogMetricLeConnectionCompletion(address_with_type.GetAddress(),
+ ErrorCode::PAGE_TIMEOUT,
+ true /* is locally initiated */);
le_client_handler_->Post(common::BindOnce(
&LeConnectionCallbacks::OnLeConnectFail, common::Unretained(le_client_callbacks_),
address_with_type, ErrorCode::CONNECTION_ACCEPT_TIMEOUT));
@@ -1145,25 +1149,6 @@ public:
remove_device_from_accept_list(address_with_type);
}
- void set_le_suggested_default_data_parameters(uint16_t length, uint16_t time) {
- auto packet = LeWriteSuggestedDefaultDataLengthBuilder::Create(length, time);
- le_acl_connection_interface_->EnqueueCommand(
- std::move(packet), handler_->BindOnce([](CommandCompleteView /* complete */) {}));
- }
-
- void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout) {
- le_acl_connection_interface_->EnqueueCommand(
- LeSetDefaultSubrateBuilder::Create(subrate_min, subrate_max, max_latency, cont_num,
- sup_tout),
- handler_->BindOnce([](CommandCompleteView complete) {
- auto complete_view = LeSetDefaultSubrateCompleteView::Create(complete);
- log::assert_that(complete_view.IsValid(), "assert failed: complete_view.IsValid()");
- ErrorCode status = complete_view.GetStatus();
- log::assert_that(status == ErrorCode::SUCCESS, "Status = {}", ErrorCodeText(status));
- }));
- }
-
void clear_resolving_list() { le_address_manager_->ClearResolvingList(); }
void set_privacy_policy_for_initiator_address(LeAddressManager::AddressPolicy address_policy,
@@ -1249,12 +1234,6 @@ public:
background_connections_.erase(address_with_type);
}
- void is_on_background_connection_list(AddressWithType address_with_type,
- std::promise<bool> promise) {
- promise.set_value(background_connections_.find(address_with_type) !=
- background_connections_.end());
- }
-
void OnPause() override { // bluetooth::hci::LeAddressManagerCallback
if (!address_manager_registered) {
log::warn("Unregistered!");
diff --git a/system/gd/hci/acl_manager/le_impl_test.cc b/system/gd/hci/acl_manager/le_impl_test.cc
index 66bc16bbd8..274b6827c9 100644
--- a/system/gd/hci/acl_manager/le_impl_test.cc
+++ b/system/gd/hci/acl_manager/le_impl_test.cc
@@ -1475,29 +1475,6 @@ TEST_F(LeImplTest, cancel_connect) {
ASSERT_TRUE(le_impl_->create_connection_timeout_alarms_.empty());
}
-TEST_F(LeImplTest, set_le_suggested_default_data_parameters) {
- le_impl_->set_le_suggested_default_data_parameters(kLength, kTime);
- sync_handler();
- auto view = CreateLeConnectionManagementCommandView<LeWriteSuggestedDefaultDataLengthView>(
- hci_layer_->GetCommand());
- ASSERT_TRUE(view.IsValid());
- ASSERT_EQ(kLength, view.GetTxOctets());
- ASSERT_EQ(kTime, view.GetTxTime());
-}
-
-TEST_F(LeImplTest, LeSetDefaultSubrate) {
- le_impl_->LeSetDefaultSubrate(kIntervalMin, kIntervalMax, kLatency, kContinuationNumber,
- kTimeout);
- sync_handler();
- auto view = CreateAclCommandView<LeSetDefaultSubrateView>(hci_layer_->GetCommand());
- ASSERT_TRUE(view.IsValid());
- ASSERT_EQ(kIntervalMin, view.GetSubrateMin());
- ASSERT_EQ(kIntervalMax, view.GetSubrateMax());
- ASSERT_EQ(kLatency, view.GetMaxLatency());
- ASSERT_EQ(kContinuationNumber, view.GetContinuationNumber());
- ASSERT_EQ(kTimeout, view.GetSupervisionTimeout());
-}
-
enum class ConnectionCompleteType { CONNECTION_COMPLETE, ENHANCED_CONNECTION_COMPLETE };
class LeImplTestParameterizedByConnectionCompleteEventType
diff --git a/system/gd/hci/acl_manager/round_robin_scheduler.cc b/system/gd/hci/acl_manager/round_robin_scheduler.cc
index ad0e6dc621..89897a82e5 100644
--- a/system/gd/hci/acl_manager/round_robin_scheduler.cc
+++ b/system/gd/hci/acl_manager/round_robin_scheduler.cc
@@ -17,7 +17,6 @@
#include "hci/acl_manager/round_robin_scheduler.h"
#include <bluetooth/log.h>
-#include <com_android_bluetooth_flags.h>
#include <memory>
#include <utility>
@@ -65,10 +64,8 @@ void RoundRobinScheduler::Unregister(uint16_t handle) {
log::assert_that(acl_queue_handlers_.count(handle) == 1,
"assert failed: acl_queue_handlers_.count(handle) == 1");
- if (com::android::bluetooth::flags::drop_acl_fragment_on_disconnect()) {
- // Drop the pending fragments and recalculate number_of_sent_packets_
- drop_packet_fragments(handle);
- }
+ // Drop the pending fragments and recalculate number_of_sent_packets_
+ drop_packet_fragments(handle);
auto& acl_queue_handler = acl_queue_handlers_.find(handle)->second;
log::info("unregistering acl_queue handle={}, sent_packets={}", handle,
@@ -94,8 +91,7 @@ void RoundRobinScheduler::Unregister(uint16_t handle) {
starting_point_ = acl_queue_handlers_.begin();
// Restart sending packets if we got acl credits
- if (com::android::bluetooth::flags::drop_acl_fragment_on_disconnect() &&
- credits_reclaimed_from_zero) {
+ if (credits_reclaimed_from_zero) {
start_round_robin();
}
}
diff --git a/system/gd/hci/acl_manager/round_robin_scheduler_test.cc b/system/gd/hci/acl_manager/round_robin_scheduler_test.cc
index 25bd2aff80..b990332c9e 100644
--- a/system/gd/hci/acl_manager/round_robin_scheduler_test.cc
+++ b/system/gd/hci/acl_manager/round_robin_scheduler_test.cc
@@ -16,7 +16,6 @@
#include "hci/acl_manager/round_robin_scheduler.h"
-#include <com_android_bluetooth_flags.h>
#include <gtest/gtest.h>
#include "common/bidi_queue.h"
@@ -422,8 +421,6 @@ TEST_F(RoundRobinSchedulerTest, receive_le_credit_when_next_fragment_is_classic)
}
TEST_F(RoundRobinSchedulerTest, unregister_reclaim_credits) {
- com::android::bluetooth::flags::provider_->drop_acl_fragment_on_disconnect(true);
-
uint16_t handle = 0x01;
auto connection_queue = std::make_shared<AclConnection::Queue>(20);
auto new_connection_queue = std::make_shared<AclConnection::Queue>(20);
diff --git a/system/gd/hci/controller.cc b/system/gd/hci/controller.cc
index b14e434781..919643f14d 100644
--- a/system/gd/hci/controller.cc
+++ b/system/gd/hci/controller.cc
@@ -61,9 +61,7 @@ struct Controller::impl {
handler->BindOn(this, &Controller::impl::NumberOfCompletedPackets));
set_event_mask(kDefaultEventMask);
- if (com::android::bluetooth::flags::encryption_change_v2()) {
- set_event_mask_page_2(kDefaultEventMaskPage2);
- }
+ set_event_mask_page_2(kDefaultEventMaskPage2);
write_le_host_support(Enable::ENABLED, Enable::DISABLED);
hci_->EnqueueCommand(
diff --git a/system/gd/hci/distance_measurement_manager.cc b/system/gd/hci/distance_measurement_manager.cc
index 6bdfde00b9..6e57f2c9d5 100644
--- a/system/gd/hci/distance_measurement_manager.cc
+++ b/system/gd/hci/distance_measurement_manager.cc
@@ -441,6 +441,8 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
it->second.measurement_ongoing = true;
it->second.waiting_for_start_callback = true;
it->second.local_hci_role = local_hci_role;
+ it->second.retry_counter_for_create_config = 0;
+ it->second.retry_counter_for_cs_enable = 0;
return true;
}
@@ -845,6 +847,7 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
static void reset_tracker_on_stopped(CsTracker& cs_tracker) {
cs_tracker.measurement_ongoing = false;
cs_tracker.state = CsTrackerState::STOPPED;
+ cs_tracker.procedure_data_list.clear();
}
void handle_cs_setup_failure(uint16_t connection_handle, DistanceMeasurementErrorCode errorCode) {
@@ -906,7 +909,7 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
if (cs_requester_trackers_.find(connection_handle) != cs_requester_trackers_.end()) {
reset_tracker_on_stopped(cs_requester_trackers_[connection_handle]);
}
- } else if (status_view.GetStatus() != ErrorCode::SUCCESS) {
+ } else if (enable == Enable::ENABLED && status_view.GetStatus() != ErrorCode::SUCCESS) {
if (cs_requester_trackers_.count(connection_handle) == 0) {
log::error("Error code {} for connection_handle {}. No request tracker found.",
ErrorCodeText(status), connection_handle);
@@ -919,6 +922,14 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
if (cs_requester_trackers_[connection_handle].retry_counter_for_cs_enable++ >=
kMaxRetryCounterForCsEnable) {
handle_cs_setup_failure(connection_handle, REASON_INTERNAL_ERROR);
+ } else {
+ cs_requester_trackers_[connection_handle].procedure_schedule_guard_alarm->Cancel();
+ log::info("schedule next procedure enable after {} ms",
+ cs_requester_trackers_[connection_handle].interval_ms);
+ cs_requester_trackers_[connection_handle].procedure_schedule_guard_alarm->Schedule(
+ common::Bind(&impl::send_le_cs_procedure_enable, common::Unretained(this),
+ connection_handle, Enable::ENABLED),
+ std::chrono::milliseconds(cs_requester_trackers_[connection_handle].interval_ms));
}
}
}
@@ -1237,25 +1248,8 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
void on_cs_procedure_enable_complete(LeCsProcedureEnableCompleteView event_view) {
log::assert_that(event_view.IsValid(), "assert failed: event_view.IsValid()");
uint16_t connection_handle = event_view.GetConnectionHandle();
- log::debug("on cs procedure enabled complete");
- if (event_view.GetStatus() != ErrorCode::SUCCESS) {
- std::string error_code = ErrorCodeText(event_view.GetStatus());
- if (cs_requester_trackers_.count(connection_handle) == 0) {
- log::warn(
- "Received LeCsProcedureEnableCompleteView with error code {}, No request tracker "
- "found",
- error_code);
- handle_cs_setup_failure(connection_handle, REASON_INTERNAL_ERROR);
- return;
- }
- log::warn("Received LeCsProcedureEnableCompleteView with error code {}. Retry counter {}",
- error_code, cs_requester_trackers_[connection_handle].retry_counter_for_cs_enable);
- if (cs_requester_trackers_[connection_handle].retry_counter_for_cs_enable++ >=
- kMaxRetryCounterForCsEnable) {
- handle_cs_setup_failure(connection_handle, REASON_INTERNAL_ERROR);
- }
- return;
- }
+ log::debug("Procedure enabled, {}", event_view.ToString());
+
uint8_t config_id = event_view.GetConfigId();
CsTracker* live_tracker = nullptr;
@@ -1272,7 +1266,7 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
live_tracker = get_live_tracker(connection_handle, config_id, valid_requester_states,
valid_responder_states);
if (live_tracker == nullptr) {
- log::error("no tracker is available for {}", connection_handle);
+ log::error("enable - no tracker is available for {}", connection_handle);
return;
}
if (live_tracker->used_config_id != config_id) {
@@ -1280,7 +1274,22 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
live_tracker->used_config_id);
return;
}
- log::debug("Procedure enabled, {}", event_view.ToString());
+
+ if (live_tracker->local_start && event_view.GetStatus() != ErrorCode::SUCCESS) {
+ log::warn("Received LeCsProcedureEnableCompleteView with error code {}. Retry counter {}",
+ ErrorCodeText(event_view.GetStatus()), live_tracker->retry_counter_for_cs_enable);
+ if (live_tracker->retry_counter_for_cs_enable++ >= kMaxRetryCounterForCsEnable) {
+ handle_cs_setup_failure(connection_handle, REASON_INTERNAL_ERROR);
+ } else {
+ live_tracker->procedure_schedule_guard_alarm->Cancel();
+ log::info("schedule next procedure enable after {} ms", live_tracker->interval_ms);
+ live_tracker->procedure_schedule_guard_alarm->Schedule(
+ common::Bind(&impl::send_le_cs_procedure_enable, common::Unretained(this),
+ connection_handle, Enable::ENABLED),
+ std::chrono::milliseconds(live_tracker->interval_ms));
+ }
+ return;
+ }
live_tracker->state = CsTrackerState::STARTED;
live_tracker->selected_tx_power = event_view.GetSelectedTxPower();
live_tracker->n_procedure_count = event_view.GetProcedureCount();
@@ -1297,38 +1306,45 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
if (live_tracker->n_procedure_count >= 1) {
live_tracker->procedure_schedule_guard_alarm->Cancel();
log::info("schedule next procedure enable after {} ms", schedule_interval);
- cs_requester_trackers_[connection_handle].procedure_schedule_guard_alarm->Schedule(
+ live_tracker->procedure_schedule_guard_alarm->Schedule(
common::Bind(&impl::send_le_cs_procedure_enable, common::Unretained(this),
connection_handle, Enable::ENABLED),
std::chrono::milliseconds(schedule_interval));
}
- }
- if (live_tracker->local_start && live_tracker->waiting_for_start_callback) {
- live_tracker->waiting_for_start_callback = false;
- distance_measurement_callbacks_->OnDistanceMeasurementStarted(live_tracker->address,
- METHOD_CS);
- }
- if (live_tracker->local_start && is_hal_v2()) {
- // reset the procedure sequence
- live_tracker->procedure_sequence_after_enable = -1;
- ranging_hal_->UpdateProcedureEnableConfig(connection_handle, event_view);
+ if (live_tracker->waiting_for_start_callback) {
+ live_tracker->waiting_for_start_callback = false;
+ distance_measurement_callbacks_->OnDistanceMeasurementStarted(live_tracker->address,
+ METHOD_CS);
+ }
+ if (is_hal_v2()) {
+ // reset the procedure sequence
+ live_tracker->procedure_sequence_after_enable = -1;
+ ranging_hal_->UpdateProcedureEnableConfig(connection_handle, event_view);
+ }
}
} else if (event_view.GetState() == Enable::DISABLED) {
- uint8_t valid_requester_states = static_cast<uint8_t>(CsTrackerState::STARTED);
- uint8_t valid_responder_states = static_cast<uint8_t>(CsTrackerState::STARTED);
- live_tracker = get_live_tracker(connection_handle, config_id, valid_requester_states,
- valid_responder_states);
- if (live_tracker == nullptr) {
- log::error("no tracker is available for {}", connection_handle);
- return;
+ if (event_view.GetStatus() == ErrorCode::SUCCESS) {
+ // local or remote host requested it.
+ uint8_t valid_requester_states = static_cast<uint8_t>(CsTrackerState::STARTED);
+ uint8_t valid_responder_states = static_cast<uint8_t>(CsTrackerState::STARTED);
+ live_tracker = get_live_tracker(connection_handle, config_id, valid_requester_states,
+ valid_responder_states);
+ if (live_tracker == nullptr) {
+ log::error("disable - no tracker is available for {}", connection_handle);
+ return;
+ }
+ reset_tracker_on_stopped(*live_tracker);
+ } else {
+ // work around, controller may send 'DISABLE' complete with error for 'ENABLE' command
+ auto req_it = cs_requester_trackers_.find(connection_handle);
+ if (req_it != cs_requester_trackers_.end() &&
+ req_it->second.state == CsTrackerState::WAIT_FOR_PROCEDURE_ENABLED &&
+ config_id == req_it->second.used_config_id) {
+ log::warn("expect ENABLE complete, bug got DISABLE complete.");
+ handle_cs_setup_failure(connection_handle, REASON_INTERNAL_ERROR);
+ }
}
- reset_tracker_on_stopped(*live_tracker);
- }
- // reset the procedure data list.
- std::vector<CsProcedureData>& data_list = live_tracker->procedure_data_list;
- while (!data_list.empty()) {
- data_list.erase(data_list.begin());
}
}
diff --git a/system/gd/hci/distance_measurement_manager_test.cc b/system/gd/hci/distance_measurement_manager_test.cc
index 3f6e16ba99..35a629c53a 100644
--- a/system/gd/hci/distance_measurement_manager_test.cc
+++ b/system/gd/hci/distance_measurement_manager_test.cc
@@ -21,6 +21,8 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
+#include "common/bind.h"
+#include "common/strings.h"
#include "hal/ranging_hal.h"
#include "hal/ranging_hal_mock.h"
#include "hci/acl_manager_mock.h"
@@ -31,15 +33,20 @@
#include "hci/hci_layer.h"
#include "hci/hci_layer_fake.h"
#include "module.h"
+#include "os/fake_timer/fake_timerfd.h"
#include "packet/packet_view.h"
#include "ras/ras_packets.h"
+using bluetooth::os::fake_timer::fake_timerfd_advance;
+using bluetooth::os::fake_timer::fake_timerfd_reset;
using testing::_;
using testing::AtLeast;
using testing::Return;
namespace {
-constexpr auto kTimeout = std::chrono::seconds(1);
+static constexpr auto kTimeout = std::chrono::seconds(1);
+static constexpr uint8_t kMaxRetryCounterForCreateConfig = 0x03;
+static constexpr uint8_t kMaxRetryCounterForCsEnable = 0x03;
}
namespace bluetooth {
@@ -105,6 +112,53 @@ struct CsReadCapabilitiesCompleteEvent {
uint8_t tx_snr_capability = 1;
};
+struct CsConfigCompleteEvent {
+ ErrorCode status = ErrorCode::SUCCESS;
+ uint8_t config_id = 0;
+ CsAction action = CsAction::CONFIG_CREATED;
+ CsMainModeType main_mode_type = CsMainModeType::MODE_2;
+ CsSubModeType sub_mode_type = CsSubModeType::UNUSED;
+ uint8_t min_main_mode_steps = 3; // 0x02 to 0xFF
+ uint8_t max_main_mode_steps = 100; // 0x02 to 0xFF
+ uint8_t main_mode_repetition = 0; // 0x00 to 0x03
+ uint8_t mode_0_steps = 1; // 0x01 to 0x03
+ CsRole cs_role = CsRole::INITIATOR;
+ CsRttType rtt_type = CsRttType::RTT_AA_ONLY;
+ CsSyncPhy sync_phy = CsSyncPhy::LE_2M_PHY;
+ std::array<uint8_t, 10> channel_map = GetChannelMap("1FFFFFFFFFFFFC7FFFFC");
+ uint8_t channel_map_repetition = 1; // 0x01 to 0xFF
+ CsChannelSelectionType channel_selection_type = CsChannelSelectionType::TYPE_3C;
+ CsCh3cShape ch3c_shape = CsCh3cShape::HAT_SHAPE;
+ uint8_t ch3c_jump = 2; // 0x02 to 0x08
+ uint8_t t_ip1_time = 0x0A; // 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x50, or 0x91
+ uint8_t t_ip2_time = 0x0A; // 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x50, or 0x91
+ uint8_t t_fcs_time = 0x0F; // 0x0F, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x50, 0x64, 0x78, or 0x96
+ uint8_t t_pm_time = 0x0A; // 0x0A, 0x14, or 0x28
+
+ static const std::array<uint8_t, 10> GetChannelMap(const std::string& hex_string) {
+ assert(hex_stinrg.length() == 20);
+ auto channel_vector = common::FromHexString(hex_string);
+ std::array<uint8_t, 10> channel_map{};
+ std::copy(channel_vector->begin(), channel_vector->end(), channel_map.begin());
+ std::reverse(channel_map.begin(), channel_map.end());
+ return channel_map;
+ }
+};
+
+struct CsProcedureEnableCompleteEvent {
+ ErrorCode status = ErrorCode::SUCCESS;
+ uint8_t config_id = 0;
+ uint8_t tone_antenna_config_selection = 0;
+ uint8_t selected_tx_power = 0; // -127 to 20 dBm
+ uint32_t subevent_len = 2500; // 1250us to 4s
+ uint8_t subevents_per_event = 1; // 0x01 to 0x20
+ uint16_t subevent_interval = 1; // N x 0.625ms
+ uint16_t event_interval = 0; // number of acl conn interval
+ uint16_t procedure_interval = 2; // number of acl conn interval
+ uint16_t procedure_count = 5; // 0x0001 to 0xFFFF
+ uint16_t max_procedure_len = 10; // N x 0.625 ms
+};
+
struct StartMeasurementParameters {
Address remote_address = Address::FromString("12:34:56:78:9a:bc").value();
uint16_t connection_handle = 64;
@@ -130,6 +184,7 @@ protected:
EXPECT_CALL(*mock_controller_, SupportsBleChannelSounding()).WillOnce(Return(true));
EXPECT_CALL(*mock_ranging_hal_, IsBound()).Times(AtLeast(1)).WillRepeatedly(Return(true));
+ EXPECT_CALL(*mock_ranging_hal_, GetRangingHalVersion).WillRepeatedly(Return(hal::V_2));
handler_ = fake_registry_.GetTestHandler();
dm_manager_ = fake_registry_.Start<DistanceMeasurementManager>(&thread_, handler_);
@@ -149,6 +204,19 @@ protected:
return dm_session_promise_->get_future();
}
+ std::future<void> fake_timer_advance(uint64_t ms) {
+ std::promise<void> promise;
+ auto future = promise.get_future();
+ handler_->Post(common::BindOnce(
+ [](std::promise<void> promise, uint64_t ms) {
+ fake_timerfd_advance(ms);
+ promise.set_value();
+ },
+ common::Passed(std::move(promise)), ms));
+
+ return future;
+ }
+
void sync_client_handler() {
log::assert_that(thread_.GetReactor()->WaitForIdle(kTimeout),
"assert failed: thread_.GetReactor()->WaitForIdle(kTimeout)");
@@ -199,6 +267,32 @@ protected:
cs_cap_complete_event.t_sw_time_supported, cs_cap_complete_event.tx_snr_capability);
}
+ static std::unique_ptr<LeCsConfigCompleteBuilder> GetConfigCompleteEvent(
+ uint16_t connection_handle, CsConfigCompleteEvent complete_event) {
+ return LeCsConfigCompleteBuilder::Create(
+ complete_event.status, connection_handle, complete_event.config_id,
+ complete_event.action, complete_event.main_mode_type, complete_event.sub_mode_type,
+ complete_event.min_main_mode_steps, complete_event.max_main_mode_steps,
+ complete_event.main_mode_repetition, complete_event.mode_0_steps,
+ complete_event.cs_role, complete_event.rtt_type, complete_event.sync_phy,
+ complete_event.channel_map, complete_event.channel_map_repetition,
+ complete_event.channel_selection_type, complete_event.ch3c_shape,
+ complete_event.ch3c_jump, complete_event.t_ip1_time, complete_event.t_ip2_time,
+ complete_event.t_fcs_time, complete_event.t_pm_time);
+ }
+
+ static std::unique_ptr<LeCsProcedureEnableCompleteBuilder> GetProcedureEnableCompleteEvent(
+ uint16_t connection_handle, Enable enable,
+ CsProcedureEnableCompleteEvent complete_event) {
+ return LeCsProcedureEnableCompleteBuilder::Create(
+ complete_event.status, connection_handle, complete_event.config_id, enable,
+ complete_event.tone_antenna_config_selection, complete_event.selected_tx_power,
+ complete_event.subevent_len, complete_event.subevents_per_event,
+ complete_event.subevent_interval, complete_event.event_interval,
+ complete_event.procedure_interval, complete_event.procedure_count,
+ complete_event.max_procedure_len);
+ }
+
void StartMeasurement(const StartMeasurementParameters& params) {
dm_manager_->StartDistanceMeasurement(params.remote_address, params.connection_handle,
params.local_hci_role, params.interval, params.method);
@@ -227,6 +321,55 @@ protected:
/*conn_interval=*/24);
}
+ void StartMeasurementTillReadRemoteCaps(const StartMeasurementParameters& params) {
+ StartMeasurementTillRasConnectedEvent(params);
+
+ test_hci_layer_->GetCommand(OpCode::LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES);
+ CsReadCapabilitiesCompleteEvent read_cs_complete_event;
+ test_hci_layer_->IncomingEvent(LeCsReadRemoteSupportedCapabilitiesStatusBuilder::Create(
+ /*status=*/ErrorCode::SUCCESS,
+ /*num_hci_command_packets=*/0xFF));
+ test_hci_layer_->IncomingLeMetaEvent(GetRemoteSupportedCapabilitiesCompleteEvent(
+ params.connection_handle, read_cs_complete_event));
+
+ test_hci_layer_->GetCommand(OpCode::LE_CS_SET_DEFAULT_SETTINGS);
+ test_hci_layer_->IncomingEvent(LeCsSetDefaultSettingsCompleteBuilder::Create(
+ /*num_hci_command_packets=*/static_cast<uint8_t>(0xEE), ErrorCode::SUCCESS,
+ params.connection_handle));
+ }
+
+ void StartMeasurementTillCreateConfig(const StartMeasurementParameters& params) {
+ StartMeasurementTillReadRemoteCaps(params);
+
+ CsConfigCompleteEvent cs_config_complete_event;
+ test_hci_layer_->GetCommand(OpCode::LE_CS_CREATE_CONFIG);
+ test_hci_layer_->IncomingEvent(LeCsCreateConfigStatusBuilder::Create(
+ /*status=*/ErrorCode::SUCCESS,
+ /*num_hci_command_packets=*/0xFF));
+ test_hci_layer_->IncomingLeMetaEvent(
+ GetConfigCompleteEvent(params.connection_handle, cs_config_complete_event));
+ }
+
+ void StartMeasurementTillSecurityEnable(const StartMeasurementParameters& params) {
+ StartMeasurementTillCreateConfig(params);
+
+ test_hci_layer_->GetCommand(OpCode::LE_CS_SECURITY_ENABLE);
+ test_hci_layer_->IncomingEvent(LeCsSecurityEnableStatusBuilder::Create(
+ /*status=*/ErrorCode::SUCCESS,
+ /*num_hci_command_packets=*/0xFF));
+ test_hci_layer_->IncomingLeMetaEvent(LeCsSecurityEnableCompleteBuilder::Create(
+ ErrorCode::SUCCESS, params.connection_handle));
+ }
+
+ void StartMeasurementTillSetProcedureParameters(const StartMeasurementParameters& params) {
+ StartMeasurementTillSecurityEnable(params);
+
+ test_hci_layer_->GetCommand(OpCode::LE_CS_SET_PROCEDURE_PARAMETERS);
+ test_hci_layer_->IncomingEvent(LeCsSetProcedureParametersCompleteBuilder::Create(
+ /*num_hci_command_packets=*/static_cast<uint8_t>(0xEE), ErrorCode::SUCCESS,
+ params.connection_handle));
+ }
+
protected:
TestModuleRegistry fake_registry_;
HciLayerFake* test_hci_layer_ = nullptr;
@@ -315,6 +458,7 @@ TEST_F(DistanceMeasurementManagerTest, error_read_remote_cs_caps_command) {
test_hci_layer_->IncomingEvent(LeCsReadRemoteSupportedCapabilitiesStatusBuilder::Create(
/*status=*/ErrorCode::COMMAND_DISALLOWED,
/*num_hci_command_packets=*/0xff));
+ sync_client_handler();
}
TEST_F(DistanceMeasurementManagerTest, fail_read_remote_cs_caps_complete) {
@@ -338,6 +482,146 @@ TEST_F(DistanceMeasurementManagerTest, fail_read_remote_cs_caps_complete) {
read_cs_complete_event.error_code = ErrorCode::COMMAND_DISALLOWED;
test_hci_layer_->IncomingLeMetaEvent(GetRemoteSupportedCapabilitiesCompleteEvent(
params.connection_handle, read_cs_complete_event));
+ sync_client_handler();
+}
+
+TEST_F(DistanceMeasurementManagerTest, error_create_config_command) {
+ auto dm_session_future = GetDmSessionFuture();
+ StartMeasurementParameters params;
+ StartMeasurementTillReadRemoteCaps(params);
+
+ EXPECT_CALL(mock_dm_callbacks_,
+ OnDistanceMeasurementStopped(params.remote_address,
+ DistanceMeasurementErrorCode::REASON_INTERNAL_ERROR,
+ DistanceMeasurementMethod::METHOD_CS))
+ .WillOnce([this](const Address& /*address*/, DistanceMeasurementErrorCode /*error_code*/,
+ DistanceMeasurementMethod /*method*/) {
+ ASSERT_NE(dm_session_promise_, nullptr);
+ dm_session_promise_->set_value();
+ dm_session_promise_.reset();
+ });
+
+ test_hci_layer_->GetCommand(OpCode::LE_CS_CREATE_CONFIG);
+ test_hci_layer_->IncomingEvent(LeCsCreateConfigStatusBuilder::Create(
+ /*status=*/ErrorCode::COMMAND_DISALLOWED,
+ /*num_hci_command_packets=*/0xff));
+ sync_client_handler();
+}
+
+TEST_F(DistanceMeasurementManagerTest, fail_create_config_complete) {
+ auto dm_session_future = GetDmSessionFuture();
+ StartMeasurementParameters params;
+ StartMeasurementTillReadRemoteCaps(params);
+
+ EXPECT_CALL(mock_dm_callbacks_,
+ OnDistanceMeasurementStopped(params.remote_address,
+ DistanceMeasurementErrorCode::REASON_INTERNAL_ERROR,
+ DistanceMeasurementMethod::METHOD_CS))
+ .WillOnce([this](const Address& /*address*/, DistanceMeasurementErrorCode /*error_code*/,
+ DistanceMeasurementMethod /*method*/) {
+ ASSERT_NE(dm_session_promise_, nullptr);
+ dm_session_promise_->set_value();
+ dm_session_promise_.reset();
+ });
+
+ CsConfigCompleteEvent cs_config_complete_event;
+ cs_config_complete_event.status = ErrorCode::COMMAND_DISALLOWED;
+ for (int i = 0; i <= kMaxRetryCounterForCreateConfig; i++) {
+ test_hci_layer_->GetCommand(OpCode::LE_CS_CREATE_CONFIG);
+ test_hci_layer_->IncomingLeMetaEvent(
+ GetConfigCompleteEvent(params.connection_handle, cs_config_complete_event));
+ }
+ sync_client_handler();
+}
+
+TEST_F(DistanceMeasurementManagerTest, retry_fail_procedure_enable_command) {
+ auto dm_session_future = GetDmSessionFuture();
+ StartMeasurementParameters params;
+ StartMeasurementTillSetProcedureParameters(params);
+
+ EXPECT_CALL(mock_dm_callbacks_,
+ OnDistanceMeasurementStopped(params.remote_address,
+ DistanceMeasurementErrorCode::REASON_INTERNAL_ERROR,
+ DistanceMeasurementMethod::METHOD_CS))
+ .WillOnce([this](const Address& /*address*/, DistanceMeasurementErrorCode /*error_code*/,
+ DistanceMeasurementMethod /*method*/) {
+ ASSERT_NE(dm_session_promise_, nullptr);
+ dm_session_promise_->set_value();
+ dm_session_promise_.reset();
+ });
+
+ for (int i = 0; i <= kMaxRetryCounterForCsEnable; i++) {
+ test_hci_layer_->GetCommand(OpCode::LE_CS_PROCEDURE_ENABLE);
+ test_hci_layer_->IncomingEvent(LeCsProcedureEnableStatusBuilder::Create(
+ /*status=*/ErrorCode::COMMAND_DISALLOWED,
+ /*num_hci_command_packets=*/0xff));
+ auto future = fake_timer_advance(params.interval + 10);
+ future.wait_for(kTimeout);
+ sync_client_handler();
+ }
+ fake_timerfd_reset();
+ sync_client_handler();
+}
+
+TEST_F(DistanceMeasurementManagerTest, retry_fail_procedure_enable_complete) {
+ auto dm_session_future = GetDmSessionFuture();
+ StartMeasurementParameters params;
+ StartMeasurementTillSetProcedureParameters(params);
+
+ EXPECT_CALL(mock_dm_callbacks_,
+ OnDistanceMeasurementStopped(params.remote_address,
+ DistanceMeasurementErrorCode::REASON_INTERNAL_ERROR,
+ DistanceMeasurementMethod::METHOD_CS))
+ .WillOnce([this](const Address& /*address*/, DistanceMeasurementErrorCode /*error_code*/,
+ DistanceMeasurementMethod /*method*/) {
+ ASSERT_NE(dm_session_promise_, nullptr);
+ dm_session_promise_->set_value();
+ dm_session_promise_.reset();
+ });
+
+ CsProcedureEnableCompleteEvent complete_event;
+ complete_event.status = ErrorCode::LINK_LAYER_COLLISION;
+ for (int i = 0; i <= kMaxRetryCounterForCsEnable; i++) {
+ test_hci_layer_->GetCommand(OpCode::LE_CS_PROCEDURE_ENABLE);
+ test_hci_layer_->IncomingEvent(LeCsProcedureEnableStatusBuilder::Create(
+ /*status=*/ErrorCode::SUCCESS,
+ /*num_hci_command_packets=*/0xff));
+ test_hci_layer_->IncomingLeMetaEvent(GetProcedureEnableCompleteEvent(
+ params.connection_handle, Enable::ENABLED, complete_event));
+ auto future = fake_timer_advance(params.interval + 10);
+ future.wait_for(kTimeout);
+ sync_client_handler();
+ }
+ fake_timerfd_reset();
+ sync_client_handler();
+}
+
+TEST_F(DistanceMeasurementManagerTest, unexpected_procedure_enable_complete_as_disable) {
+ auto dm_session_future = GetDmSessionFuture();
+ StartMeasurementParameters params;
+ StartMeasurementTillSetProcedureParameters(params);
+
+ EXPECT_CALL(mock_dm_callbacks_,
+ OnDistanceMeasurementStopped(params.remote_address,
+ DistanceMeasurementErrorCode::REASON_INTERNAL_ERROR,
+ DistanceMeasurementMethod::METHOD_CS))
+ .WillOnce([this](const Address& /*address*/, DistanceMeasurementErrorCode /*error_code*/,
+ DistanceMeasurementMethod /*method*/) {
+ ASSERT_NE(dm_session_promise_, nullptr);
+ dm_session_promise_->set_value();
+ dm_session_promise_.reset();
+ });
+
+ test_hci_layer_->GetCommand(OpCode::LE_CS_PROCEDURE_ENABLE);
+ test_hci_layer_->IncomingEvent(LeCsProcedureEnableStatusBuilder::Create(
+ /*status=*/ErrorCode::SUCCESS,
+ /*num_hci_command_packets=*/0xff));
+ CsProcedureEnableCompleteEvent complete_event;
+ complete_event.status = ErrorCode::LINK_LAYER_COLLISION;
+ test_hci_layer_->IncomingLeMetaEvent(GetProcedureEnableCompleteEvent(
+ params.connection_handle, Enable::DISABLED, complete_event));
+
+ sync_client_handler();
}
} // namespace
diff --git a/system/gd/hci/le_address_manager.cc b/system/gd/hci/le_address_manager.cc
index 804f88985e..327ea0f0ca 100644
--- a/system/gd/hci/le_address_manager.cc
+++ b/system/gd/hci/le_address_manager.cc
@@ -165,12 +165,8 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddress(
min_seconds.count(), max_seconds.count());
enqueue_command_.Run(std::move(packet));
} else {
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) {
- address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true);
- address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false);
- } else {
- address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_);
- }
+ address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true);
+ address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false);
}
set_random_address();
break;
@@ -229,12 +225,8 @@ void LeAddressManager::SetPrivacyPolicyForInitiatorAddressForTest(
min_seconds.count(), max_seconds.count());
enqueue_command_.Run(std::move(packet));
} else {
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) {
- address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true);
- address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false);
- } else {
- address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_);
- }
+ address_rotation_wake_alarm_ = std::make_unique<os::Alarm>(handler_, true);
+ address_rotation_non_wake_alarm_ = std::make_unique<os::Alarm>(handler_, false);
set_random_address();
}
break;
@@ -422,31 +414,25 @@ void LeAddressManager::prepare_to_rotate() {
}
void LeAddressManager::schedule_rotate_random_address() {
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) {
- std::string client_name = "LeAddressManager";
- auto privateAddressIntervalRange = GetNextPrivateAddressIntervalRange(client_name);
- address_rotation_wake_alarm_->Schedule(
- common::BindOnce(
- []() { log::info("deadline wakeup in schedule_rotate_random_address"); }),
- privateAddressIntervalRange.max);
- address_rotation_non_wake_alarm_->Schedule(
- common::BindOnce(&LeAddressManager::prepare_to_rotate, common::Unretained(this)),
- privateAddressIntervalRange.min);
-
- auto now = std::chrono::system_clock::now();
- if (address_rotation_interval_min.has_value()) {
- CheckAddressRotationHappenedInExpectedTimeInterval(
- *address_rotation_interval_min, *address_rotation_interval_max, now, client_name);
- }
-
- // Update the expected range here.
- address_rotation_interval_min.emplace(now + privateAddressIntervalRange.min);
- address_rotation_interval_max.emplace(now + privateAddressIntervalRange.max);
- } else {
- address_rotation_wake_alarm_->Schedule(
- common::BindOnce(&LeAddressManager::prepare_to_rotate, common::Unretained(this)),
- GetNextPrivateAddressIntervalMs());
+ std::string client_name = "LeAddressManager";
+ auto privateAddressIntervalRange = GetNextPrivateAddressIntervalRange(client_name);
+ address_rotation_wake_alarm_->Schedule(
+ common::BindOnce(
+ []() { log::info("deadline wakeup in schedule_rotate_random_address"); }),
+ privateAddressIntervalRange.max);
+ address_rotation_non_wake_alarm_->Schedule(
+ common::BindOnce(&LeAddressManager::prepare_to_rotate, common::Unretained(this)),
+ privateAddressIntervalRange.min);
+
+ auto now = std::chrono::system_clock::now();
+ if (address_rotation_interval_min.has_value()) {
+ CheckAddressRotationHappenedInExpectedTimeInterval(
+ *address_rotation_interval_min, *address_rotation_interval_max, now, client_name);
}
+
+ // Update the expected range here.
+ address_rotation_interval_min.emplace(now + privateAddressIntervalRange.min);
+ address_rotation_interval_max.emplace(now + privateAddressIntervalRange.max);
}
void LeAddressManager::set_random_address() {
diff --git a/system/gd/hci/le_advertising_manager.cc b/system/gd/hci/le_advertising_manager.cc
index f9a80f44f8..d626b2ee15 100644
--- a/system/gd/hci/le_advertising_manager.cc
+++ b/system/gd/hci/le_advertising_manager.cc
@@ -374,39 +374,29 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
log::info("Reenable advertising");
if (was_rotating_address) {
log::info("Scheduling address rotation for advertiser_id={}", advertiser_id);
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) {
- advertising_sets_[advertiser_id].address_rotation_wake_alarm_ =
- std::make_unique<os::Alarm>(module_handler_, true);
- advertising_sets_[advertiser_id].address_rotation_non_wake_alarm_ =
- std::make_unique<os::Alarm>(module_handler_, false);
-
- std::string client_name = "advertising_set_" + std::to_string(advertiser_id);
- auto privateAddressIntervalRange =
- le_address_manager_->GetNextPrivateAddressIntervalRange(client_name);
-
- advertising_sets_[advertiser_id].address_rotation_wake_alarm_->Schedule(
- common::BindOnce(
- []() { log::info("deadline wakeup in handle_set_terminated"); }),
- privateAddressIntervalRange.max);
- advertising_sets_[advertiser_id].address_rotation_non_wake_alarm_->Schedule(
- common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
- common::Unretained(this), advertiser_id),
- privateAddressIntervalRange.min);
-
- // Update the expected range here.
- auto now = std::chrono::system_clock::now();
- advertising_sets_[advertiser_id].address_rotation_interval_min.emplace(
- now + privateAddressIntervalRange.min);
- advertising_sets_[advertiser_id].address_rotation_interval_max.emplace(
- now + privateAddressIntervalRange.max);
- } else {
- advertising_sets_[advertiser_id].address_rotation_wake_alarm_ =
- std::make_unique<os::Alarm>(module_handler_);
- advertising_sets_[advertiser_id].address_rotation_wake_alarm_->Schedule(
- common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
- common::Unretained(this), advertiser_id),
- le_address_manager_->GetNextPrivateAddressIntervalMs());
- }
+ advertising_sets_[advertiser_id].address_rotation_wake_alarm_ =
+ std::make_unique<os::Alarm>(module_handler_, true);
+ advertising_sets_[advertiser_id].address_rotation_non_wake_alarm_ =
+ std::make_unique<os::Alarm>(module_handler_, false);
+
+ std::string client_name = "advertising_set_" + std::to_string(advertiser_id);
+ auto privateAddressIntervalRange =
+ le_address_manager_->GetNextPrivateAddressIntervalRange(client_name);
+
+ advertising_sets_[advertiser_id].address_rotation_wake_alarm_->Schedule(
+ common::BindOnce([]() { log::info("deadline wakeup in handle_set_terminated"); }),
+ privateAddressIntervalRange.max);
+ advertising_sets_[advertiser_id].address_rotation_non_wake_alarm_->Schedule(
+ common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
+ common::Unretained(this), advertiser_id),
+ privateAddressIntervalRange.min);
+
+ // Update the expected range here.
+ auto now = std::chrono::system_clock::now();
+ advertising_sets_[advertiser_id].address_rotation_interval_min.emplace(
+ now + privateAddressIntervalRange.min);
+ advertising_sets_[advertiser_id].address_rotation_interval_max.emplace(
+ now + privateAddressIntervalRange.max);
}
enable_advertiser(advertiser_id, true, 0, 0);
}
@@ -673,40 +663,31 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
!leaudio_requested_nrpa && (!controller_->IsRpaGenerationSupported())) {
// start timer for random address
log::info("Scheduling address rotation for advertiser_id={}", id);
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) {
- advertising_sets_[id].address_rotation_wake_alarm_ =
- std::make_unique<os::Alarm>(module_handler_, true);
- advertising_sets_[id].address_rotation_non_wake_alarm_ =
- std::make_unique<os::Alarm>(module_handler_, false);
-
- std::string client_name = "advertising_set_" + std::to_string(id);
- auto privateAddressIntervalRange =
- le_address_manager_->GetNextPrivateAddressIntervalRange(client_name);
-
- advertising_sets_[id].address_rotation_wake_alarm_->Schedule(
- common::BindOnce([]() {
- log::info("deadline wakeup in create_extended_advertiser_with_id");
- }),
- privateAddressIntervalRange.max);
- advertising_sets_[id].address_rotation_non_wake_alarm_->Schedule(
- common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
- common::Unretained(this), id),
- privateAddressIntervalRange.min);
-
- // Update the expected range here.
- auto now = std::chrono::system_clock::now();
- advertising_sets_[id].address_rotation_interval_min.emplace(
- now + privateAddressIntervalRange.min);
- advertising_sets_[id].address_rotation_interval_max.emplace(
- now + privateAddressIntervalRange.max);
- } else {
- advertising_sets_[id].address_rotation_wake_alarm_ =
- std::make_unique<os::Alarm>(module_handler_);
- advertising_sets_[id].address_rotation_wake_alarm_->Schedule(
- common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
- common::Unretained(this), id),
- le_address_manager_->GetNextPrivateAddressIntervalMs());
- }
+ advertising_sets_[id].address_rotation_wake_alarm_ =
+ std::make_unique<os::Alarm>(module_handler_, true);
+ advertising_sets_[id].address_rotation_non_wake_alarm_ =
+ std::make_unique<os::Alarm>(module_handler_, false);
+
+ std::string client_name = "advertising_set_" + std::to_string(id);
+ auto privateAddressIntervalRange =
+ le_address_manager_->GetNextPrivateAddressIntervalRange(client_name);
+
+ advertising_sets_[id].address_rotation_wake_alarm_->Schedule(
+ common::BindOnce([]() {
+ log::info("deadline wakeup in create_extended_advertiser_with_id");
+ }),
+ privateAddressIntervalRange.max);
+ advertising_sets_[id].address_rotation_non_wake_alarm_->Schedule(
+ common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
+ common::Unretained(this), id),
+ privateAddressIntervalRange.min);
+
+ // Update the expected range here.
+ auto now = std::chrono::system_clock::now();
+ advertising_sets_[id].address_rotation_interval_min.emplace(
+ now + privateAddressIntervalRange.min);
+ advertising_sets_[id].address_rotation_interval_max.emplace(
+ now + privateAddressIntervalRange.max);
}
}
if (config.advertising_type == AdvertisingType::ADV_IND ||
@@ -859,39 +840,31 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
}
log::info("Scheduling address rotation for advertiser_id={}", advertiser_id);
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation()) {
- std::string client_name = "advertising_set_" + std::to_string(advertiser_id);
- auto privateAddressIntervalRange =
- le_address_manager_->GetNextPrivateAddressIntervalRange(client_name);
- advertising_sets_[advertiser_id].address_rotation_wake_alarm_->Schedule(
- common::BindOnce([]() {
- log::info("deadline wakeup in set_advertising_set_random_address_on_timer");
- }),
- privateAddressIntervalRange.max);
- advertising_sets_[advertiser_id].address_rotation_non_wake_alarm_->Schedule(
- common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
- common::Unretained(this), advertiser_id),
- privateAddressIntervalRange.min);
-
- auto now = std::chrono::system_clock::now();
- if (advertising_sets_[advertiser_id].address_rotation_interval_min.has_value()) {
- le_address_manager_->CheckAddressRotationHappenedInExpectedTimeInterval(
- *(advertising_sets_[advertiser_id].address_rotation_interval_min),
- *(advertising_sets_[advertiser_id].address_rotation_interval_max), now,
- client_name);
- }
-
- // Update the expected range here.
- advertising_sets_[advertiser_id].address_rotation_interval_min.emplace(
- now + privateAddressIntervalRange.min);
- advertising_sets_[advertiser_id].address_rotation_interval_max.emplace(
- now + privateAddressIntervalRange.max);
- } else {
- advertising_sets_[advertiser_id].address_rotation_wake_alarm_->Schedule(
- common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
- common::Unretained(this), advertiser_id),
- le_address_manager_->GetNextPrivateAddressIntervalMs());
+ std::string client_name = "advertising_set_" + std::to_string(advertiser_id);
+ auto privateAddressIntervalRange =
+ le_address_manager_->GetNextPrivateAddressIntervalRange(client_name);
+ advertising_sets_[advertiser_id].address_rotation_wake_alarm_->Schedule(
+ common::BindOnce([]() {
+ log::info("deadline wakeup in set_advertising_set_random_address_on_timer");
+ }),
+ privateAddressIntervalRange.max);
+ advertising_sets_[advertiser_id].address_rotation_non_wake_alarm_->Schedule(
+ common::BindOnce(&impl::set_advertising_set_random_address_on_timer,
+ common::Unretained(this), advertiser_id),
+ privateAddressIntervalRange.min);
+
+ auto now = std::chrono::system_clock::now();
+ if (advertising_sets_[advertiser_id].address_rotation_interval_min.has_value()) {
+ le_address_manager_->CheckAddressRotationHappenedInExpectedTimeInterval(
+ *(advertising_sets_[advertiser_id].address_rotation_interval_min),
+ *(advertising_sets_[advertiser_id].address_rotation_interval_max), now, client_name);
}
+
+ // Update the expected range here.
+ advertising_sets_[advertiser_id].address_rotation_interval_min.emplace(
+ now + privateAddressIntervalRange.min);
+ advertising_sets_[advertiser_id].address_rotation_interval_max.emplace(
+ now + privateAddressIntervalRange.max);
}
void register_advertiser(
diff --git a/system/gd/metrics/chromeos/OWNERS b/system/gd/metrics/chromeos/OWNERS
deleted file mode 100644
index a823e6e1dd..0000000000
--- a/system/gd/metrics/chromeos/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_chromeos
diff --git a/system/gd/metrics/counter_metrics.h b/system/gd/metrics/counter_metrics.h
index 88c7711f92..2f25f03ed0 100644
--- a/system/gd/metrics/counter_metrics.h
+++ b/system/gd/metrics/counter_metrics.h
@@ -15,6 +15,8 @@
*/
#pragma once
+#include <com_android_bluetooth_flags.h>
+
#include <unordered_map>
#include "module.h"
@@ -26,6 +28,13 @@ namespace metrics {
class CounterMetrics : public bluetooth::Module {
public:
CounterMetrics(os::Handler* handler) : Module(handler) {}
+ ~CounterMetrics() {
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ GetHandler()->Clear();
+ GetHandler()->WaitUntilStopped(std::chrono::milliseconds(2000));
+ delete GetHandler();
+ }
+ }
bool CacheCount(int32_t key, int64_t value);
virtual bool Count(int32_t key, int64_t count);
diff --git a/system/gd/metrics/linux/OWNERS b/system/gd/metrics/linux/OWNERS
deleted file mode 100644
index a823e6e1dd..0000000000
--- a/system/gd/metrics/linux/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_chromeos
diff --git a/system/gd/module.cc b/system/gd/module.cc
index 8904f0c559..76b386bbfe 100644
--- a/system/gd/module.cc
+++ b/system/gd/module.cc
@@ -128,10 +128,18 @@ void ModuleRegistry::StopAll() {
auto module = Get(*it);
last_instance_ = "stopping " + module->ToString();
- // Clear the handler before stopping the module to allow it to shut down gracefully.
- log::info("Stopping Handler of Module {}", module->ToString());
- module->handler_->Clear();
- module->handler_->WaitUntilStopped(kModuleStopTimeout);
+ /*
+ * b/393449774 since we have now shifted to a single handler for all modules, we don't need
+ * to clear the handler here, it will be done in the respective teardown.
+ * Since we have a single handler, we need to make sure that the handler instance is deleted
+ * only once, otherwise we will see a crash as a handler can only be cleared once.
+ */
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ // Clear the handler before stopping the module to allow it to shut down gracefully.
+ log::info("Stopping Handler of Module {}", module->ToString());
+ module->handler_->Clear();
+ module->handler_->WaitUntilStopped(kModuleStopTimeout);
+ }
log::info("Stopping Module {}", module->ToString());
module->Stop();
}
@@ -144,7 +152,9 @@ void ModuleRegistry::StopAll() {
auto instance = started_modules_.find(*it);
log::assert_that(instance != started_modules_.end(),
"assert failed: instance != started_modules_.end()");
- delete instance->second->handler_;
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ delete instance->second->handler_;
+ }
delete instance->second;
started_modules_.erase(instance);
}
@@ -165,4 +175,15 @@ os::Handler* ModuleRegistry::GetModuleHandler(const ModuleFactory* module) const
return nullptr;
}
+// Override the StopAll method to use the test thread and handler.
+// This function will take care of releasing the handler instances.
+void TestModuleRegistry::StopAll() {
+ os::Handler* handler = GetTestHandler();
+ handler->Clear();
+ if (com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ handler->WaitUntilStopped(kHandlerStopTimeout);
+ }
+ ModuleRegistry::StopAll(); // call the base class StopAll
+ delete handler;
+}
} // namespace bluetooth
diff --git a/system/gd/module.h b/system/gd/module.h
index 816d455482..57e4db7d16 100644
--- a/system/gd/module.h
+++ b/system/gd/module.h
@@ -32,6 +32,9 @@
#include "os/thread.h"
namespace bluetooth {
+// Timeout for waiting for a handler to stop, used in Handler::WaitUntilStopped()
+constexpr std::chrono::milliseconds kHandlerStopTimeout = std::chrono::milliseconds(2000);
+
namespace shim {
class Stack;
} // namespace shim
@@ -191,6 +194,9 @@ public:
os::Thread& GetTestThread() { return test_thread; }
os::Handler* GetTestHandler() { return test_handler_; }
+ // Override the StopAll method to use the test thread and handler.
+ void StopAll();
+
bool SynchronizeModuleHandler(const ModuleFactory* module,
std::chrono::milliseconds timeout) const {
return SynchronizeHandler(GetTestModuleHandler(module), timeout);
diff --git a/system/gd/module_unittest.cc b/system/gd/module_unittest.cc
index d1bf59ac73..8fb140c229 100644
--- a/system/gd/module_unittest.cc
+++ b/system/gd/module_unittest.cc
@@ -22,6 +22,7 @@
#include <sstream>
#include <string>
+#include "com_android_bluetooth_flags.h"
#include "gtest/gtest.h"
#include "os/handler.h"
#include "os/thread.h"
@@ -41,9 +42,12 @@ protected:
void TearDown() override {
handler_->Clear();
+ if (com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ handler_->WaitUntilStopped(kHandlerStopTimeout);
+ }
delete registry_;
- delete thread_;
delete handler_;
+ delete thread_;
}
ModuleRegistry* registry_;
diff --git a/system/gd/os/android/metrics.cc b/system/gd/os/android/metrics.cc
index 78b12c8d96..5f5b34ef2e 100644
--- a/system/gd/os/android/metrics.cc
+++ b/system/gd/os/android/metrics.cc
@@ -122,11 +122,9 @@ void LogMetricRemoteVersionInfo(uint16_t handle, uint8_t status, uint8_t version
manufacturer_name, subversion);
if (ret < 0) {
log::warn(
- "Failed for handle {}, status {}, version {}, manufacturer_name {}, subversion {}, "
- "error "
- "{}",
- handle, common::ToHexString(status), common::ToHexString(version),
- common::ToHexString(manufacturer_name), common::ToHexString(subversion), ret);
+ "failed for handle {}, status 0x{:x}, version 0x{:x}, "
+ "manufacturer_name 0x{:x}, subversion 0x{:x}, error {}",
+ handle, status, version, manufacturer_name, subversion, ret);
}
}
@@ -526,5 +524,53 @@ void LogMetricRfcommConnectionAtClose(const Address& address,
}
}
+void LogMetricLeAudioConnectionSessionReported(
+ int32_t group_size, int32_t group_metric_id, int64_t connection_duration_nanos,
+ const std::vector<int64_t>& device_connecting_offset_nanos,
+ const std::vector<int64_t>& device_connected_offset_nanos,
+ const std::vector<int64_t>& device_connection_duration_nanos,
+ const std::vector<int32_t>& device_connection_status,
+ const std::vector<int32_t>& device_disconnection_status,
+ const std::vector<RawAddress>& device_address,
+ const std::vector<int64_t>& streaming_offset_nanos,
+ const std::vector<int64_t>& streaming_duration_nanos,
+ const std::vector<int32_t>& streaming_context_type) {
+ std::vector<int32_t> device_metric_id(device_address.size());
+ for (uint64_t i = 0; i < device_address.size(); i++) {
+ if (!device_address[i].IsEmpty()) {
+ device_metric_id[i] =
+ MetricIdManager::GetInstance().AllocateId(ToGdAddress(device_address[i]));
+ } else {
+ device_metric_id[i] = 0;
+ }
+ }
+ int ret = stats_write(LE_AUDIO_CONNECTION_SESSION_REPORTED, group_size, group_metric_id,
+ connection_duration_nanos, device_connecting_offset_nanos,
+ device_connected_offset_nanos, device_connection_duration_nanos,
+ device_connection_status, device_disconnection_status, device_metric_id,
+ streaming_offset_nanos, streaming_duration_nanos, streaming_context_type);
+ if (ret < 0) {
+ log::warn(
+ "failed for group {}device_connecting_offset_nanos[{}], "
+ "device_connected_offset_nanos[{}], "
+ "device_connection_duration_nanos[{}], device_connection_status[{}], "
+ "device_disconnection_status[{}], device_metric_id[{}], "
+ "streaming_offset_nanos[{}], streaming_duration_nanos[{}], "
+ "streaming_context_type[{}]",
+ group_metric_id, device_connecting_offset_nanos.size(),
+ device_connected_offset_nanos.size(), device_connection_duration_nanos.size(),
+ device_connection_status.size(), device_disconnection_status.size(),
+ device_metric_id.size(), streaming_offset_nanos.size(), streaming_duration_nanos.size(),
+ streaming_context_type.size());
+ }
+}
+
+void LogMetricLeAudioBroadcastSessionReported(int64_t duration_nanos) {
+ int ret = stats_write(LE_AUDIO_BROADCAST_SESSION_REPORTED, duration_nanos);
+ if (ret < 0) {
+ log::warn("failed for duration={}", duration_nanos);
+ }
+}
+
} // namespace os
} // namespace bluetooth
diff --git a/system/gd/os/chromeos/metrics.cc b/system/gd/os/chromeos/metrics.cc
index b7921fe308..de36a98780 100644
--- a/system/gd/os/chromeos/metrics.cc
+++ b/system/gd/os/chromeos/metrics.cc
@@ -216,5 +216,19 @@ void LogMetricRfcommConnectionAtClose(
android::bluetooth::BtaStatus /* sdp_status */, bool /* is_server */,
bool /* sdp_initiated */, int32_t /* sdp_duration_ms */) {}
+void LogMetricLeAudioConnectionSessionReported(
+ int32_t /*group_size*/, int32_t /*group_metric_id*/, int64_t /*connection_duration_nanos*/,
+ const std::vector<int64_t>& /*device_connecting_offset_nanos*/,
+ const std::vector<int64_t>& /*device_connected_offset_nanos*/,
+ const std::vector<int64_t>& /*device_connection_duration_nanos*/,
+ const std::vector<int32_t>& /*device_connection_status*/,
+ const std::vector<int32_t>& /*device_disconnection_status*/,
+ const std::vector<RawAddress>& /*device_address*/,
+ const std::vector<int64_t>& /*streaming_offset_nanos*/,
+ const std::vector<int64_t>& /*streaming_duration_nanos*/,
+ const std::vector<int32_t>& /*streaming_context_type*/) {}
+
+void LogMetricLeAudioBroadcastSessionReported(int64_t /*duration_nanos*/) {}
+
} // namespace os
} // namespace bluetooth
diff --git a/system/gd/os/host/metrics.cc b/system/gd/os/host/metrics.cc
index a333113238..518a29ffee 100644
--- a/system/gd/os/host/metrics.cc
+++ b/system/gd/os/host/metrics.cc
@@ -135,5 +135,19 @@ void LogMetricRfcommConnectionAtClose(
android::bluetooth::BtaStatus /* sdp_status */, bool /* is_server */,
bool /* sdp_initiated */, int32_t /* sdp_duration_ms */) {}
+void LogMetricLeAudioConnectionSessionReported(
+ int32_t /*group_size*/, int32_t /*group_metric_id*/, int64_t /*connection_duration_nanos*/,
+ const std::vector<int64_t>& /*device_connecting_offset_nanos*/,
+ const std::vector<int64_t>& /*device_connected_offset_nanos*/,
+ const std::vector<int64_t>& /*device_connection_duration_nanos*/,
+ const std::vector<int32_t>& /*device_connection_status*/,
+ const std::vector<int32_t>& /*device_disconnection_status*/,
+ const std::vector<RawAddress>& /*device_address*/,
+ const std::vector<int64_t>& /*streaming_offset_nanos*/,
+ const std::vector<int64_t>& /*streaming_duration_nanos*/,
+ const std::vector<int32_t>& /*streaming_context_type*/) {}
+
+void LogMetricLeAudioBroadcastSessionReported(int64_t /*duration_nanos*/) {}
+
} // namespace os
} // namespace bluetooth
diff --git a/system/gd/os/linux/metrics.cc b/system/gd/os/linux/metrics.cc
index 7b727f38f2..f5d1555075 100644
--- a/system/gd/os/linux/metrics.cc
+++ b/system/gd/os/linux/metrics.cc
@@ -122,5 +122,20 @@ void LogMetricRfcommConnectionAtClose(const Address& raw_address,
void LogMetricBluetoothEvent(const Address& address, android::bluetooth::EventType event_type,
android::bluetooth::State state) {}
+
+void LogMetricLeAudioConnectionSessionReported(
+ int32_t /*group_size*/, int32_t /*group_metric_id*/, int64_t /*connection_duration_nanos*/,
+ const std::vector<int64_t>& /*device_connecting_offset_nanos*/,
+ const std::vector<int64_t>& /*device_connected_offset_nanos*/,
+ const std::vector<int64_t>& /*device_connection_duration_nanos*/,
+ const std::vector<int32_t>& /*device_connection_status*/,
+ const std::vector<int32_t>& /*device_disconnection_status*/,
+ const std::vector<RawAddress>& /*device_address*/,
+ const std::vector<int64_t>& /*streaming_offset_nanos*/,
+ const std::vector<int64_t>& /*streaming_duration_nanos*/,
+ const std::vector<int32_t>& /*streaming_context_type*/) {}
+
+void LogMetricLeAudioBroadcastSessionReported(int64_t /*duration_nanos*/) {}
+
} // namespace os
} // namespace bluetooth
diff --git a/system/gd/os/linux_generic/alarm.cc b/system/gd/os/linux_generic/alarm.cc
index 8846ede579..a378ca93cd 100644
--- a/system/gd/os/linux_generic/alarm.cc
+++ b/system/gd/os/linux_generic/alarm.cc
@@ -17,7 +17,6 @@
#include "os/alarm.h"
#include <bluetooth/log.h>
-#include <com_android_bluetooth_flags.h>
#include <sys/timerfd.h>
#include <unistd.h>
@@ -41,8 +40,7 @@ using common::OnceClosure;
Alarm::Alarm(Handler* handler) : Alarm(handler, true) {}
Alarm::Alarm(Handler* handler, bool isWakeAlarm) : handler_(handler) {
- int timerfd_flag =
- com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation() ? TFD_NONBLOCK : 0;
+ int timerfd_flag = TFD_NONBLOCK;
fd_ = TIMERFD_CREATE(isWakeAlarm ? ALARM_CLOCK : CLOCK_BOOTTIME, timerfd_flag);
@@ -85,7 +83,7 @@ void Alarm::on_fire() {
auto bytes_read = read(fd_, &times_invoked, sizeof(uint64_t));
lock.unlock();
- if (com::android::bluetooth::flags::non_wake_alarm_for_rpa_rotation() && bytes_read == -1) {
+ if (bytes_read == -1) {
log::debug("No data to read.");
if (errno == EAGAIN || errno == EWOULDBLOCK) {
log::debug("Alarm is already canceled or rescheduled.");
diff --git a/system/gd/os/metrics.h b/system/gd/os/metrics.h
index aab82826e6..04b5c37e84 100644
--- a/system/gd/os/metrics.h
+++ b/system/gd/os/metrics.h
@@ -29,8 +29,8 @@
#include "types/raw_address.h"
namespace bluetooth {
-
namespace os {
+
/**
* Unknown connection handle for metrics purpose
*/
@@ -379,6 +379,19 @@ void LogMetricRfcommConnectionAtClose(const hci::Address& address,
android::bluetooth::BtaStatus sdp_status, bool is_server,
bool sdp_initiated, int32_t sdp_duration_ms);
+void LogMetricLeAudioConnectionSessionReported(
+ int32_t group_size, int32_t group_metric_id, int64_t connection_duration_nanos,
+ const std::vector<int64_t>& device_connecting_offset_nanos,
+ const std::vector<int64_t>& device_connected_offset_nanos,
+ const std::vector<int64_t>& device_connection_duration_nanos,
+ const std::vector<int32_t>& device_connection_status,
+ const std::vector<int32_t>& device_disconnection_status,
+ const std::vector<RawAddress>& device_address,
+ const std::vector<int64_t>& streaming_offset_nanos,
+ const std::vector<int64_t>& streaming_duration_nanos,
+ const std::vector<int32_t>& streaming_context_type);
+
+void LogMetricLeAudioBroadcastSessionReported(int64_t duration_nanos);
+
} // namespace os
- //
} // namespace bluetooth
diff --git a/system/gd/rust/linux/OWNERS b/system/gd/rust/linux/OWNERS
deleted file mode 100644
index a823e6e1dd..0000000000
--- a/system/gd/rust/linux/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_chromeos
diff --git a/system/gd/rust/topshim/OWNERS b/system/gd/rust/topshim/OWNERS
deleted file mode 100644
index a823e6e1dd..0000000000
--- a/system/gd/rust/topshim/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_chromeos
diff --git a/system/gd/storage/storage_module.cc b/system/gd/storage/storage_module.cc
index 5e3459e109..5a81a5cf94 100644
--- a/system/gd/storage/storage_module.cc
+++ b/system/gd/storage/storage_module.cc
@@ -90,6 +90,13 @@ StorageModule::StorageModule(os::Handler* handler, std::string config_file_path,
StorageModule::~StorageModule() {
std::lock_guard<std::recursive_mutex> lock(mutex_);
+
+ if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ GetHandler()->Clear();
+ GetHandler()->WaitUntilStopped(std::chrono::milliseconds(2000));
+ delete GetHandler();
+ }
+
pimpl_.reset();
}
diff --git a/system/include/hardware/bluetooth_headset_interface.h b/system/include/hardware/bluetooth_headset_interface.h
index b2b98ffe1f..396c2b2880 100644
--- a/system/include/hardware/bluetooth_headset_interface.h
+++ b/system/include/hardware/bluetooth_headset_interface.h
@@ -97,9 +97,10 @@ public:
/**
* Start voice recognition
* @param bd_addr remote device address
+ * @param sendResult whether a BVRA response should be sent
* @return BT_STATUS_SUCCESS on success
*/
- virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr) = 0;
+ virtual bt_status_t StartVoiceRecognition(RawAddress* bd_addr, bool sendResult) = 0;
/**
* Stop voice recognition
diff --git a/system/linux_include/log/log.h b/system/linux_include/log/log.h
deleted file mode 100644
index 037649312c..0000000000
--- a/system/linux_include/log/log.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/******************************************************************************
- *
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- ******************************************************************************/
-#pragma once
-
-#ifndef __ANDROID__
-
-#include <cstdint>
-
-#endif
diff --git a/system/log/OWNERS b/system/log/OWNERS
deleted file mode 100644
index d1c75de900..0000000000
--- a/system/log/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-henrichataing@google.com
diff --git a/system/main/shim/acl.cc b/system/main/shim/acl.cc
index b2f0e23975..b01bd1f92d 100644
--- a/system/main/shim/acl.cc
+++ b/system/main/shim/acl.cc
@@ -969,11 +969,6 @@ struct shim::Acl::impl {
maximum_latency, minimum_remote_timeout, minimum_local_timeout);
}
- void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout) {
- GetAclManager()->LeSetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num, sup_tout);
- }
-
void LeSubrateRequest(HciHandle handle, uint16_t subrate_min, uint16_t subrate_max,
uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) {
if (IsLeAcl(handle)) {
@@ -1573,12 +1568,6 @@ void shim::Acl::UpdateConnectionParameters(uint16_t handle, uint16_t conn_int_mi
conn_int_max, conn_latency, conn_timeout, min_ce_len, max_ce_len);
}
-void shim::Acl::LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max,
- uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) {
- handler_->CallOn(pimpl_.get(), &Acl::impl::LeSetDefaultSubrate, subrate_min, subrate_max,
- max_latency, cont_num, sup_tout);
-}
-
void shim::Acl::LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min, uint16_t subrate_max,
uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout) {
handler_->CallOn(pimpl_.get(), &Acl::impl::LeSubrateRequest, hci_handle, subrate_min, subrate_max,
diff --git a/system/main/shim/acl.h b/system/main/shim/acl.h
index bbe15d0acf..8253faf013 100644
--- a/system/main/shim/acl.h
+++ b/system/main/shim/acl.h
@@ -80,8 +80,6 @@ public:
void RemoveFromAddressResolution(const hci::AddressWithType& address_with_type);
void ClearAddressResolution();
- void LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout);
void LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min, uint16_t subrate_max,
uint16_t max_latency, uint16_t cont_num, uint16_t sup_tout);
diff --git a/system/main/shim/acl_api.cc b/system/main/shim/acl_api.cc
index 56e63e1977..0868f40f2c 100644
--- a/system/main/shim/acl_api.cc
+++ b/system/main/shim/acl_api.cc
@@ -166,12 +166,6 @@ void bluetooth::shim::ACL_ClearAddressResolution() {
void bluetooth::shim::ACL_ClearFilterAcceptList() {
Stack::GetInstance()->GetAcl()->ClearFilterAcceptList();
}
-void bluetooth::shim::ACL_LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max,
- uint16_t max_latency, uint16_t cont_num,
- uint16_t sup_tout) {
- Stack::GetInstance()->GetAcl()->LeSetDefaultSubrate(subrate_min, subrate_max, max_latency,
- cont_num, sup_tout);
-}
void bluetooth::shim::ACL_LeSubrateRequest(uint16_t hci_handle, uint16_t subrate_min,
uint16_t subrate_max, uint16_t max_latency,
diff --git a/system/main/shim/acl_api.h b/system/main/shim/acl_api.h
index 6b28988ca6..b0bac16e02 100644
--- a/system/main/shim/acl_api.h
+++ b/system/main/shim/acl_api.h
@@ -49,8 +49,6 @@ void ACL_AddToAddressResolution(const tBLE_BD_ADDR& legacy_address_with_type,
void ACL_RemoveFromAddressResolution(const tBLE_BD_ADDR& legacy_address_with_type);
void ACL_ClearAddressResolution();
void ACL_ClearFilterAcceptList();
-void ACL_LeSetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout);
void ACL_SendConnectionParameterUpdateRequest(uint16_t handle, uint16_t conn_int_min,
uint16_t conn_int_max, uint16_t conn_latency,
uint16_t conn_timeout, uint16_t min_ce_len,
diff --git a/system/main/shim/stack.cc b/system/main/shim/stack.cc
index bb8994aee0..027361875d 100644
--- a/system/main/shim/stack.cc
+++ b/system/main/shim/stack.cc
@@ -67,9 +67,9 @@ namespace shim {
struct Stack::impl {
Acl* acl_ = nullptr;
- metrics::CounterMetrics* counter_metrics_ = nullptr;
- storage::StorageModule* storage_ = nullptr;
- hal::SnoopLogger* snoop_logger_ = nullptr;
+ std::shared_ptr<metrics::CounterMetrics> counter_metrics_ = nullptr;
+ std::shared_ptr<storage::StorageModule> storage_ = nullptr;
+ std::shared_ptr<hal::SnoopLogger> snoop_logger_ = nullptr;
};
Stack::Stack() { pimpl_ = std::make_shared<Stack::impl>(); }
@@ -89,9 +89,16 @@ void Stack::StartEverything() {
stack_thread_ = new os::Thread("gd_stack_thread", os::Thread::Priority::REAL_TIME);
stack_handler_ = new os::Handler(stack_thread_);
- pimpl_->counter_metrics_ = new metrics::CounterMetrics(new Handler(stack_thread_));
- pimpl_->storage_ = new storage::StorageModule(new Handler(stack_thread_));
- pimpl_->snoop_logger_ = new hal::SnoopLogger(new Handler(stack_thread_));
+ if (com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ pimpl_->counter_metrics_ = std::make_shared<metrics::CounterMetrics>(stack_handler_);
+ pimpl_->storage_ = std::make_shared<storage::StorageModule>(stack_handler_);
+ pimpl_->snoop_logger_ = std::make_shared<hal::SnoopLogger>(stack_handler_);
+ } else {
+ pimpl_->counter_metrics_ =
+ std::make_shared<metrics::CounterMetrics>(new Handler(stack_thread_));
+ pimpl_->storage_ = std::make_shared<storage::StorageModule>(new Handler(stack_thread_));
+ pimpl_->snoop_logger_ = std::make_shared<hal::SnoopLogger>(new Handler(stack_thread_));
+ }
#if TARGET_FLOSS
modules.add<sysprops::SyspropsModule>();
@@ -119,6 +126,7 @@ void Stack::StartEverything() {
}
is_running_ = true;
+ log::info("GD stack is running");
std::promise<void> promise;
auto future = promise.get_future();
@@ -168,12 +176,13 @@ void Stack::Stop() {
log::assert_that(is_running_, "Gd stack not running");
is_running_ = false;
+ log::info("GD stack is not running");
- if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
- // Clear the handler only if the flag is not defined, otherwise it will be cleared by the
- // registry
- stack_handler_->Clear();
+ stack_handler_->Clear();
+ if(com::android::bluetooth::flags::same_handler_for_all_modules()) {
+ stack_handler_->WaitUntilStopped(bluetooth::kHandlerStopTimeout);
}
+
WakelockManager::Get().Acquire();
std::promise<void> promise;
@@ -195,14 +204,7 @@ void Stack::Stop() {
delete management_handler_;
delete management_thread_;
- if (!com::android::bluetooth::flags::same_handler_for_all_modules()) {
- // delete the handler only if the flag is not defined, otherwise it will be deleted by the
- // registry
- delete stack_handler_;
- }
-
- // stack_handler_ is already deleted by the registry in handle_shut_down, just set it to nullptr
- // to avoid any potential use-after-free
+ delete stack_handler_;
stack_handler_ = nullptr;
stack_thread_->Stop();
@@ -227,19 +229,19 @@ Acl* Stack::GetAcl() const {
metrics::CounterMetrics* Stack::GetCounterMetrics() const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
log::assert_that(is_running_, "assert failed: is_running_");
- return pimpl_->counter_metrics_;
+ return pimpl_->counter_metrics_.get();
}
storage::StorageModule* Stack::GetStorage() const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
log::assert_that(is_running_, "assert failed: is_running_");
- return pimpl_->storage_;
+ return pimpl_->storage_.get();
}
hal::SnoopLogger* Stack::GetSnoopLogger() const {
std::lock_guard<std::recursive_mutex> lock(mutex_);
log::assert_that(is_running_, "assert failed: is_running_");
- return pimpl_->snoop_logger_;
+ return pimpl_->snoop_logger_.get();
}
os::Handler* Stack::GetHandler() {
@@ -275,9 +277,15 @@ void Stack::handle_start_up(ModuleList* modules, std::promise<void> promise) {
void Stack::handle_shut_down(std::promise<void> promise) {
registry_.StopAll();
+
pimpl_->snoop_logger_->Stop();
pimpl_->storage_->Stop();
pimpl_->counter_metrics_->Stop();
+
+ pimpl_->snoop_logger_.reset();
+ pimpl_->storage_.reset();
+ pimpl_->counter_metrics_.reset();
+
promise.set_value();
}
diff --git a/system/main/test/main_shim_test.cc b/system/main/test/main_shim_test.cc
index 2f4056a381..c66024cabb 100644
--- a/system/main/test/main_shim_test.cc
+++ b/system/main/test/main_shim_test.cc
@@ -332,8 +332,10 @@ protected:
thread_ = new os::Thread("acl_thread", os::Thread::Priority::NORMAL);
handler_ = new os::Handler(thread_);
- /* extern */ test::mock_controller_ = new bluetooth::hci::testing::MockControllerInterface();
- /* extern */ test::mock_acl_manager_ = new bluetooth::hci::testing::MockAclManager();
+ /* extern */ test::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ /* extern */ test::mock_acl_manager_ =
+ std::make_unique<bluetooth::hci::testing::MockAclManager>();
/* extern */ test::mock_le_scanning_manager_ =
new bluetooth::hci::testing::MockLeScanningManager();
/* extern */ test::mock_le_advertising_manager_ =
@@ -342,10 +344,8 @@ protected:
new bluetooth::hci::testing::MockDistanceMeasurementManager();
}
void TearDown() override {
- delete test::mock_controller_;
- test::mock_controller_ = nullptr;
- delete test::mock_acl_manager_;
- test::mock_acl_manager_ = nullptr;
+ test::mock_controller_.reset();
+ test::mock_acl_manager_.release();
delete test::mock_le_advertising_manager_;
test::mock_le_advertising_manager_ = nullptr;
delete test::mock_le_scanning_manager_;
@@ -567,7 +567,6 @@ TEST_F(MainShimTest, DISABLED_BleScannerInterfaceImpl_OnScanResult) {
bluetooth::shim::get_ble_scanner_instance());
EXPECT_CALL(*hci::testing::mock_le_scanning_manager_, RegisterScanningCallback(_)).Times(1);
- ;
bluetooth::shim::init_scanning_manager();
TestScanningCallbacks cb;
diff --git a/system/osi/BUILD.gn b/system/osi/BUILD.gn
index 5bdf04c1e9..fa47062f52 100644
--- a/system/osi/BUILD.gn
+++ b/system/osi/BUILD.gn
@@ -43,7 +43,6 @@ static_library("osi") {
include_dirs = [
"//bt/system/",
- "//bt/system/linux_include",
"//bt/system/osi/include_internal",
"//bt/system/stack/include",
]
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index ebab1ff5f4..78af467a76 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -48,7 +48,6 @@ cc_library_static {
"hid",
"include",
"l2cap",
- "metrics",
"pan",
"sdp",
"smp",
@@ -183,7 +182,6 @@ cc_library_static {
"l2cap/l2c_main.cc",
"l2cap/l2c_utils.cc",
"l2cap/l2cap_api.cc",
- "metrics/stack_metrics_logging.cc",
"pan/pan_api.cc",
"pan/pan_main.cc",
"pan/pan_utils.cc",
@@ -374,9 +372,9 @@ cc_fuzz {
":TestFakeOsi",
":TestMockBtif",
":TestMockDevice",
+ ":TestMockMainShim",
":TestMockStackBtm",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"fuzzers/sdp_fuzzer.cc",
],
static_libs: [
@@ -414,6 +412,7 @@ cc_fuzz {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockSrvcDis",
":TestMockStackAcl",
@@ -421,7 +420,6 @@ cc_fuzz {
":TestMockStackBtm",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSdp",
"fuzzers/rfcomm_fuzzer.cc",
"rfcomm/*.cc",
@@ -465,6 +463,7 @@ cc_fuzz {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockSrvcDis",
":TestMockStackAcl",
@@ -473,7 +472,6 @@ cc_fuzz {
":TestMockStackConnMgr",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSdp",
"ais/*.cc",
"eatt/*.cc",
@@ -517,12 +515,12 @@ cc_fuzz {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"fuzzers/smp_fuzzer.cc",
"smp/*.cc", // add other sources files (p256 related) under smp into this test
],
@@ -563,12 +561,12 @@ cc_fuzz {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"bnep/*.cc",
"fuzzers/bnep_fuzzer.cc",
],
@@ -601,12 +599,12 @@ cc_fuzz {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSdp",
"avct/*.cc",
"avrc/*.cc",
@@ -648,11 +646,11 @@ cc_fuzz {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackHcic",
- ":TestMockStackMetrics",
"fuzzers/l2cap_fuzzer.cc",
"l2cap/*.cc",
],
@@ -809,10 +807,10 @@ cc_test {
":TestCommonMockFunctions",
":TestMockHci",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackBtm",
":TestMockStackL2capInterface",
- ":TestMockStackMetrics",
":TestMockStackRfcommMetrics",
"rfcomm/port_api.cc",
"rfcomm/port_rfc.cc",
@@ -903,12 +901,12 @@ cc_test {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"smp/p_256_curvepara.cc",
"smp/p_256_ecc_pp.cc",
"smp/p_256_multprecision.cc",
@@ -1006,9 +1004,9 @@ cc_test {
":TestCommonMainHandler",
":TestCommonMockFunctions",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackBtm",
- ":TestMockStackMetrics",
"connection_manager/connection_manager.cc",
"test/connection_manager_test.cc",
],
@@ -1419,10 +1417,10 @@ cc_test {
":TestMockBtif",
":TestMockDevice",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockStackBtm",
":TestMockStackConnMgr",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"gatt/gatt_db.cc",
"gatt/gatt_sr_hash.cc",
"gatt/gatt_utils.cc",
@@ -1675,7 +1673,6 @@ cc_test {
"btm/hfp_msbc_decoder.cc",
"btm/hfp_msbc_encoder.cc",
"btm/security_event_parser.cc",
- "metrics/stack_metrics_logging.cc",
"test/btm/peer_packet_types_test.cc",
"test/btm/sco_hci_test.cc",
"test/btm/sco_pkt_status_test.cc",
@@ -1813,9 +1810,9 @@ cc_test {
],
srcs: [
":TestCommonMockFunctions",
+ ":TestMockMainShim",
":TestMockStackBtm",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSdp",
"hid/hidd_api.cc",
"hid/hidd_conn.cc",
@@ -1887,12 +1884,12 @@ cc_test {
":TestMockBtif",
":TestMockHci",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSmp",
"btu/btu_hcif.cc",
"btu/main_thread.cc",
@@ -1964,12 +1961,12 @@ cc_test {
":TestMockBtif",
":TestMockHci",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockSrvcDis",
":TestMockStackAcl",
":TestMockStackBtm",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSdp",
":TestMockStackSmp",
"ais/ais_ble.cc",
@@ -2165,6 +2162,7 @@ cc_test {
":TestMockHci",
":TestMockLegacyHciInterface",
":TestMockMainShim",
+ ":TestMockMainShim",
":TestMockMainShimEntry",
":TestMockStackBtm",
":TestMockStackBtu",
@@ -2172,7 +2170,6 @@ cc_test {
":TestMockStackGatt",
":TestMockStackHcic",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
":TestMockStackSdp",
":TestMockStackSmp",
"acl/*.cc",
@@ -2349,9 +2346,9 @@ cc_test {
":TestFakeOsi",
":TestMockBta",
":TestMockBtif",
+ ":TestMockMainShim",
":TestMockStackBtm",
":TestMockStackL2cap",
- ":TestMockStackMetrics",
"test/sdp/stack_sdp_api_test.cc",
"test/sdp/stack_sdp_db_test.cc",
"test/sdp/stack_sdp_parse_test.cc",
diff --git a/system/stack/BUILD.gn b/system/stack/BUILD.gn
index d078d1bc14..f06a098bd5 100644
--- a/system/stack/BUILD.gn
+++ b/system/stack/BUILD.gn
@@ -149,7 +149,6 @@ source_set("stack") {
"l2cap/l2c_main.cc",
"l2cap/l2c_utils.cc",
"l2cap/l2cap_api.cc",
- "metrics/stack_metrics_logging.cc",
"pan/pan_api.cc",
"pan/pan_main.cc",
"pan/pan_utils.cc",
@@ -210,7 +209,6 @@ source_set("stack") {
"//bt/system/ctrlr/include",
"//bt/system/gd",
"//bt/system/hcis",
- "//bt/system/linux_include",
"//bt/system/rpc/include",
"//bt/system/udrv/include",
"//bt/system/vnd/ble",
@@ -367,7 +365,6 @@ if (defined(use.android) && use.android) {
include_dirs = [
"//bt/system/",
- "//bt/system/linux_include",
"//bt/system/bta/include",
"//bt/system/bta/sys",
"//bt/system/embdrv/sbc/encoder/include",
diff --git a/system/stack/acl/btm_acl.cc b/system/stack/acl/btm_acl.cc
index 69afab3bfa..1a4c292d55 100644
--- a/system/stack/acl/btm_acl.cc
+++ b/system/stack/acl/btm_acl.cc
@@ -41,7 +41,6 @@
#include "bta/gatt/bta_gattc_int.h"
#include "bta/include/bta_dm_acl.h"
#include "bta/sys/bta_sys.h"
-#include "common/metrics.h"
#include "device/include/device_iot_config.h"
#include "device/include/interop.h"
#include "hci/controller_interface.h"
@@ -51,6 +50,7 @@
#include "main/shim/dumpsys.h"
#include "main/shim/entry.h"
#include "main/shim/helpers.h"
+#include "os/metrics.h"
#include "os/parameter_provider.h"
#include "osi/include/allocator.h"
#include "osi/include/properties.h"
@@ -785,10 +785,10 @@ static void btm_process_remote_version_complete(uint8_t status, uint16_t handle,
p_acl_cb->remote_version_info.valid = true;
BTM_update_version_info(p_acl_cb->RemoteAddress(), p_acl_cb->remote_version_info);
- bluetooth::common::LogRemoteVersionInfo(handle, status, lmp_version, manufacturer,
- lmp_subversion);
+ bluetooth::os::LogMetricRemoteVersionInfo(handle, status, lmp_version, manufacturer,
+ lmp_subversion);
} else {
- bluetooth::common::LogRemoteVersionInfo(handle, status, 0, 0, 0);
+ bluetooth::os::LogMetricRemoteVersionInfo(handle, status, 0, 0, 0);
}
}
diff --git a/system/stack/btm/btm_ble_sec.cc b/system/stack/btm/btm_ble_sec.cc
index b7db7fa130..679e937eef 100644
--- a/system/stack/btm/btm_ble_sec.cc
+++ b/system/stack/btm/btm_ble_sec.cc
@@ -1621,8 +1621,16 @@ void btm_ble_connection_established(const RawAddress& bda) {
!p_dev_rec->sec_rec.is_le_link_key_known())) {
// Unknown device
if (p_dev_rec->dev_class == kDevClassEmpty || p_dev_rec->dev_class == kDevClassUnclassified) {
- // Class of device not known, read appearance characteristic
- btm_ble_read_remote_cod(bda);
+ // Class of device not known, read appearance characteristic ...
+ // Unless it is one of those devices which don't respond to this request
+ BD_NAME remote_name = {};
+ if (p_dev_rec->sec_rec.is_name_known() && BTM_GetRemoteDeviceName(bda, remote_name) &&
+ interop_match_name(INTEROP_DISABLE_READ_LE_APPEARANCE, (const char*)remote_name)) {
+ log::warn("Name {} matches IOP database, not reading appearance for {}",
+ (const char*)remote_name, bda);
+ } else {
+ btm_ble_read_remote_cod(bda);
+ }
}
}
}
@@ -1654,6 +1662,13 @@ static bool btm_ble_complete_evt_ignore(const tBTM_SEC_DEV_REC* p_dev_rec,
p_dev_rec->bd_addr);
l2cu_start_post_bond_timer(p_dev_rec->ble_hci_handle);
return true;
+ } else if (com::android::bluetooth::flags::le_peripheral_enc_failure() &&
+ !p_dev_rec->role_central) {
+ log::warn("Peripheral encryption request failed for the bonded device {} with reason {}",
+ p_dev_rec->bd_addr, smp_status_text(p_data->complt.reason));
+ btm_sec_disconnect(p_dev_rec->ble_hci_handle, HCI_ERR_AUTH_FAILURE,
+ smp_status_text(p_data->complt.reason));
+ return true;
}
}
@@ -1694,6 +1709,11 @@ static void btm_ble_complete_evt(const RawAddress& bd_addr, tBTM_SEC_DEV_REC* p_
}
BTM_BLE_SEC_CALLBACK(BTM_LE_COMPLT_EVT, bd_addr, p_data);
+ p_dev_rec = btm_find_dev(bd_addr); // BTM_LE_COMPLT_EVT event may have removed the device
+ if (p_dev_rec == nullptr) {
+ log::warn("Device record removed {}", bd_addr);
+ return;
+ }
log::verbose("before update sec_level=0x{:x} sec_flags=0x{:x}", p_data->complt.sec_level,
p_dev_rec->sec_rec.sec_flags);
diff --git a/system/stack/btm/btm_dev.cc b/system/stack/btm/btm_dev.cc
index 92dc80e1ab..992a59236c 100644
--- a/system/stack/btm/btm_dev.cc
+++ b/system/stack/btm/btm_dev.cc
@@ -326,6 +326,10 @@ static bool is_handle_equal(void* data, void* context) {
*
******************************************************************************/
tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) {
+ if (handle == HCI_INVALID_HANDLE) {
+ return nullptr;
+ }
+
if (btm_sec_cb.sec_dev_rec == nullptr) {
return nullptr;
}
@@ -335,7 +339,7 @@ tBTM_SEC_DEV_REC* btm_find_dev_by_handle(uint16_t handle) {
return static_cast<tBTM_SEC_DEV_REC*>(list_node(n));
}
- return NULL;
+ return nullptr;
}
static bool is_not_same_identity_or_pseudo_address(void* data, void* context) {
diff --git a/system/stack/btm/btm_sco.cc b/system/stack/btm/btm_sco.cc
index c48b321448..82182135eb 100644
--- a/system/stack/btm/btm_sco.cc
+++ b/system/stack/btm/btm_sco.cc
@@ -44,6 +44,7 @@
#include "internal_include/bt_target.h"
#include "main/shim/entry.h"
#include "main/shim/helpers.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/properties.h"
#include "osi/include/stack_power_telemetry.h"
#include "stack/btm/btm_int_types.h"
@@ -60,7 +61,6 @@
#include "stack/include/main_thread.h"
#include "stack/include/sco_hci_link_interface.h"
#include "stack/include/sdpdefs.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/raw_address.h"
extern tBTM_CB btm_cb;
@@ -1298,7 +1298,8 @@ static void btm_sco_on_disconnected(uint16_t hci_handle, tHCI_REASON reason) {
if (fill_plc_stats(&num_decoded_frames, &packet_loss_ratio)) {
const int16_t codec_id = sco_codec_type_to_id(codec_type);
const std::string codec = sco_codec_type_text(codec_type);
- log_hfp_audio_packet_loss_stats(bd_addr, num_decoded_frames, packet_loss_ratio, codec_id);
+ bluetooth::shim::LogMetricHfpPacketLossStats(bd_addr, num_decoded_frames, packet_loss_ratio,
+ codec_id);
log::debug(
"Stopped SCO codec:{}, num_decoded_frames:{}, "
"packet_loss_ratio:{:f}",
diff --git a/system/stack/btm/btm_sec.cc b/system/stack/btm/btm_sec.cc
index b00b779eee..4595794cab 100644
--- a/system/stack/btm/btm_sec.cc
+++ b/system/stack/btm/btm_sec.cc
@@ -38,7 +38,6 @@
#include "bta/dm/bta_dm_act.h"
#include "bta/dm/bta_dm_sec_int.h"
#include "btif/include/btif_storage.h"
-#include "common/metrics.h"
#include "common/time_util.h"
#include "device/include/device_iot_config.h"
#include "device/include/interop.h"
@@ -47,7 +46,9 @@
#include "main/shim/acl_api.h"
#include "main/shim/entry.h"
#include "main/shim/helpers.h"
+#include "main/shim/metrics_api.h"
#include "metrics/bluetooth_event.h"
+#include "os/metrics.h"
#include "osi/include/allocator.h"
#include "osi/include/properties.h"
#include "stack/btm/btm_ble_int.h"
@@ -75,7 +76,6 @@
#include "stack/include/main_thread.h"
#include "stack/include/rnr_interface.h"
#include "stack/include/smp_api.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"
@@ -1923,10 +1923,9 @@ static void btm_sec_bond_cancel_complete(void) {
void btm_create_conn_cancel_complete(uint8_t status, const RawAddress bd_addr) {
log::verbose("btm_create_conn_cancel_complete(): in State: {} status:{}",
tBTM_SEC_CB::btm_pair_state_descr(btm_sec_cb.pairing_state), status);
- log_link_layer_connection_event(
- &bd_addr, bluetooth::common::kUnknownConnectionHandle,
- android::bluetooth::DIRECTION_OUTGOING, android::bluetooth::LINK_TYPE_ACL,
- android::bluetooth::hci::CMD_CREATE_CONNECTION_CANCEL,
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ &bd_addr, bluetooth::os::kUnknownConnectionHandle, android::bluetooth::DIRECTION_OUTGOING,
+ android::bluetooth::LINK_TYPE_ACL, android::bluetooth::hci::CMD_CREATE_CONNECTION_CANCEL,
android::bluetooth::hci::EVT_COMMAND_COMPLETE, android::bluetooth::hci::BLE_EVT_UNKNOWN,
status, android::bluetooth::hci::STATUS_UNKNOWN);
@@ -2440,8 +2439,7 @@ void btm_io_capabilities_req(RawAddress p) {
/* If device is bonded, and encrypted it's upgrading security and it's ok.
* If it's bonded and not encrypted, it's remote missing keys scenario */
- if (!p_dev_rec->sec_rec.is_device_encrypted() &&
- com::android::bluetooth::flags::key_missing_classic_device()) {
+ if (!p_dev_rec->sec_rec.is_device_encrypted()) {
log::warn("Incoming bond request, but {} is already bonded (notifying user)", p);
bta_dm_remote_key_missing(p);
btm_sec_disconnect(p_dev_rec->hci_handle, HCI_ERR_AUTH_FAILURE,
@@ -2632,8 +2630,7 @@ void btm_io_capabilities_rsp(const tBTM_SP_IO_RSP evt_data) {
/* If device is bonded, and encrypted it's upgrading security and it's ok.
* If it's bonded and not encrypted, it's remote missing keys scenario */
- if (btm_sec_is_a_bonded_dev(evt_data.bd_addr) && !p_dev_rec->sec_rec.is_device_encrypted() &&
- com::android::bluetooth::flags::key_missing_classic_device()) {
+ if (btm_sec_is_a_bonded_dev(evt_data.bd_addr) && !p_dev_rec->sec_rec.is_device_encrypted()) {
log::warn("Incoming bond request, but {} is already bonded (notifying user)", evt_data.bd_addr);
bta_dm_remote_key_missing(evt_data.bd_addr);
btm_sec_disconnect(p_dev_rec->hci_handle, HCI_ERR_AUTH_FAILURE,
@@ -3031,8 +3028,7 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) {
p_dev_rec->sec_rec.classic_link, p_dev_rec->bd_addr,
reinterpret_cast<char const*>(p_dev_rec->sec_bd_name));
- if (status == HCI_ERR_KEY_MISSING &&
- com::android::bluetooth::flags::key_missing_classic_device()) {
+ if (status == HCI_ERR_KEY_MISSING) {
log::warn("auth_complete KEY_MISSING {} is already bonded (notifying user)",
p_dev_rec->bd_addr);
bta_dm_remote_key_missing(p_dev_rec->bd_addr);
@@ -3133,12 +3129,12 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) {
p_dev_rec->sec_rec.security_required &= ~BTM_SEC_OUT_AUTHENTICATE;
if (status != HCI_SUCCESS) {
- if ((status != HCI_ERR_PEER_USER) && (status != HCI_ERR_CONN_CAUSE_LOCAL_HOST)) {
+ if (status != HCI_ERR_PEER_USER && status != HCI_ERR_CONN_CAUSE_LOCAL_HOST) {
btm_sec_send_hci_disconnect(
p_dev_rec, HCI_ERR_PEER_USER, p_dev_rec->hci_handle,
"stack::btm::btm_sec::btm_sec_auth_retry Auth fail while bonding");
}
- } else {
+ } else if (!com::android::bluetooth::flags::immediate_encryption_after_pairing()) {
BTM_LogHistory(kBtmLogTag, p_dev_rec->bd_addr, "Bonding completed",
hci_error_code_text(status));
@@ -3163,6 +3159,11 @@ void btm_sec_auth_complete(uint16_t handle, tHCI_STATUS status) {
}
l2cu_start_post_bond_timer(p_dev_rec->hci_handle);
+ } else {
+ BTM_LogHistory(kBtmLogTag, p_dev_rec->bd_addr, "Bonding completed",
+ hci_error_code_text(status));
+ BTM_SetEncryption(p_dev_rec->bd_addr, BT_TRANSPORT_BR_EDR, NULL, NULL, BTM_BLE_SEC_NONE);
+ l2cu_start_post_bond_timer(p_dev_rec->hci_handle);
}
return;
@@ -3321,10 +3322,8 @@ void btm_sec_encrypt_change(uint16_t handle, tHCI_STATUS status, uint8_t encr_en
if (status == HCI_ERR_KEY_MISSING) {
log::info("Remote key missing - will report");
bta_dm_remote_key_missing(p_dev_rec->ble.pseudo_addr);
- if (com::android::bluetooth::flags::sec_disconnect_on_le_key_missing()) {
- btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_HOST_REJECT_SECURITY,
- p_dev_rec->ble_hci_handle, "encryption_change:key_missing");
- }
+ btm_sec_send_hci_disconnect(p_dev_rec, HCI_ERR_HOST_REJECT_SECURITY,
+ p_dev_rec->ble_hci_handle, "encryption_change:key_missing");
return;
}
diff --git a/system/stack/btm/security_event_parser.cc b/system/stack/btm/security_event_parser.cc
index 84d7005d16..b107a69cb8 100644
--- a/system/stack/btm/security_event_parser.cc
+++ b/system/stack/btm/security_event_parser.cc
@@ -22,20 +22,19 @@
#include <string>
#include "btm_sec.h"
-#include "common/metrics.h"
#include "hci/hci_packets.h"
#include "main/shim/helpers.h"
+#include "main/shim/metrics_api.h"
+#include "os/metrics.h"
#include "stack/include/btm_sec_api_types.h"
#include "stack/include/hci_error_code.h"
#include "stack/include/sec_hci_link_interface.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/raw_address.h"
using namespace bluetooth;
using namespace bluetooth::hci;
using android::bluetooth::hci::CMD_UNKNOWN;
using android::bluetooth::hci::STATUS_UNKNOWN;
-using bluetooth::common::kUnknownConnectionHandle;
namespace bluetooth::stack::btm {
namespace {
@@ -44,19 +43,19 @@ static void log_address_and_status(const Address& bda, EventCode event_code,
uint32_t cmd = android::bluetooth::hci::CMD_UNKNOWN;
uint16_t status = static_cast<uint16_t>(event_status);
uint16_t reason = android::bluetooth::hci::STATUS_UNKNOWN;
- uint16_t handle = bluetooth::common::kUnknownConnectionHandle;
+ uint16_t handle = bluetooth::os::kUnknownConnectionHandle;
int64_t value = 0;
- log_classic_pairing_event(ToRawAddress(bda), handle, cmd, static_cast<uint16_t>(event_code),
- status, reason, value);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ ToRawAddress(bda), handle, cmd, static_cast<uint16_t>(event_code), status, reason, value);
}
static void log_address(const Address& bda, EventCode event_code) {
uint32_t cmd = android::bluetooth::hci::CMD_UNKNOWN;
uint16_t status = android::bluetooth::hci::STATUS_UNKNOWN;
uint16_t reason = android::bluetooth::hci::STATUS_UNKNOWN;
- uint16_t handle = bluetooth::common::kUnknownConnectionHandle;
+ uint16_t handle = bluetooth::os::kUnknownConnectionHandle;
int64_t value = 0;
- log_classic_pairing_event(ToRawAddress(bda), handle, cmd, static_cast<uint16_t>(event_code),
- status, reason, value);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ ToRawAddress(bda), handle, cmd, static_cast<uint16_t>(event_code), status, reason, value);
}
static void parse_encryption_change(const EventView event) {
auto change_opt = EncryptionChangeView::CreateOptional(event);
@@ -69,7 +68,7 @@ static void parse_encryption_change(const EventView event) {
btm_sec_encryption_change_evt(handle, static_cast<tHCI_STATUS>(status),
static_cast<uint8_t>(encr_enable), 0);
- log_classic_pairing_event(
+ bluetooth::shim::LogMetricClassicPairingEvent(
ToRawAddress(Address::kEmpty), handle, android::bluetooth::hci::CMD_UNKNOWN,
static_cast<uint32_t>(change.GetEventCode()), static_cast<uint16_t>(status),
android::bluetooth::hci::STATUS_UNKNOWN, 0);
@@ -86,7 +85,7 @@ static void parse_encryption_change_v2(const EventView event) {
btm_sec_encryption_change_evt(handle, static_cast<tHCI_STATUS>(status),
static_cast<uint8_t>(encr_enable), key_size);
- log_classic_pairing_event(
+ bluetooth::shim::LogMetricClassicPairingEvent(
ToRawAddress(Address::kEmpty), handle, android::bluetooth::hci::CMD_UNKNOWN,
static_cast<uint32_t>(change.GetEventCode()), static_cast<uint16_t>(status),
android::bluetooth::hci::STATUS_UNKNOWN, 0);
@@ -96,7 +95,7 @@ static void parse_change_connection_link_key_complete(const EventView event) {
log::assert_that(complete_opt.has_value(), "assert failed: complete_opt.has_value()");
auto complete = complete_opt.value();
- log_classic_pairing_event(
+ bluetooth::shim::LogMetricClassicPairingEvent(
ToRawAddress(Address::kEmpty), complete.GetConnectionHandle(),
android::bluetooth::hci::CMD_UNKNOWN, static_cast<uint32_t>(complete.GetEventCode()),
static_cast<uint16_t>(complete.GetStatus()), android::bluetooth::hci::STATUS_UNKNOWN, 0);
diff --git a/system/stack/btu/btu_hcif.cc b/system/stack/btu/btu_hcif.cc
index 7a4b6d1256..367c8a89c8 100644
--- a/system/stack/btu/btu_hcif.cc
+++ b/system/stack/btu/btu_hcif.cc
@@ -37,9 +37,10 @@
#include <cstdint>
#include "btm_iso_api.h"
-#include "common/metrics.h"
#include "internal_include/bt_target.h"
#include "main/shim/hci_layer.h"
+#include "main/shim/metrics_api.h"
+#include "os/metrics.h"
#include "osi/include/allocator.h"
#include "stack/include/acl_api.h"
#include "stack/include/acl_hci_link_interface.h"
@@ -59,7 +60,6 @@
#include "stack/include/sco_hci_link_interface.h"
#include "stack/include/sec_hci_link_interface.h"
#include "stack/include/smp_api.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/hci_role.h"
#include "types/raw_address.h"
@@ -110,7 +110,7 @@ static void btu_hcif_log_event_metrics(uint8_t evt_code, const uint8_t* p_event)
uint32_t cmd = android::bluetooth::hci::CMD_UNKNOWN;
uint16_t status = android::bluetooth::hci::STATUS_UNKNOWN;
uint16_t reason = android::bluetooth::hci::STATUS_UNKNOWN;
- uint16_t handle = bluetooth::common::kUnknownConnectionHandle;
+ uint16_t handle = bluetooth::os::kUnknownConnectionHandle;
int64_t value = 0;
RawAddress bda = RawAddress::kEmpty;
@@ -125,25 +125,29 @@ static void btu_hcif_log_event_metrics(uint8_t evt_code, const uint8_t* p_event)
case HCI_KEYPRESS_NOTIFY_EVT:
case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
STREAM_TO_BDADDR(bda, p_event);
- log_classic_pairing_event(bda, handle, cmd, evt_code, status, reason, value);
+ bluetooth::shim::LogMetricClassicPairingEvent(bda, handle, cmd, evt_code, status, reason,
+ value);
break;
case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
STREAM_TO_UINT8(status, p_event);
STREAM_TO_BDADDR(bda, p_event);
- log_classic_pairing_event(bda, handle, cmd, evt_code, status, reason, value);
+ bluetooth::shim::LogMetricClassicPairingEvent(bda, handle, cmd, evt_code, status, reason,
+ value);
break;
case HCI_AUTHENTICATION_COMP_EVT:
STREAM_TO_UINT8(status, p_event);
STREAM_TO_UINT16(handle, p_event);
handle = HCID_GET_HANDLE(handle);
- log_classic_pairing_event(bda, handle, cmd, evt_code, status, reason, value);
+ bluetooth::shim::LogMetricClassicPairingEvent(bda, handle, cmd, evt_code, status, reason,
+ value);
break;
case HCI_ENCRYPTION_CHANGE_EVT: {
uint8_t encryption_enabled;
STREAM_TO_UINT8(status, p_event);
STREAM_TO_UINT16(handle, p_event);
STREAM_TO_UINT8(encryption_enabled, p_event);
- log_classic_pairing_event(bda, handle, cmd, evt_code, status, reason, encryption_enabled);
+ bluetooth::shim::LogMetricClassicPairingEvent(bda, handle, cmd, evt_code, status, reason,
+ encryption_enabled);
break;
}
case HCI_ENCRYPTION_CHANGE_EVT_V2: {
@@ -153,7 +157,8 @@ static void btu_hcif_log_event_metrics(uint8_t evt_code, const uint8_t* p_event)
STREAM_TO_UINT16(handle, p_event);
STREAM_TO_UINT8(encryption_enabled, p_event);
STREAM_TO_UINT8(key_size, p_event);
- log_classic_pairing_event(bda, handle, cmd, evt_code, status, reason, encryption_enabled);
+ bluetooth::shim::LogMetricClassicPairingEvent(bda, handle, cmd, evt_code, status, reason,
+ encryption_enabled);
break;
}
case HCI_ESCO_CONNECTION_COMP_EVT: {
@@ -163,18 +168,19 @@ static void btu_hcif_log_event_metrics(uint8_t evt_code, const uint8_t* p_event)
STREAM_TO_BDADDR(bda, p_event);
STREAM_TO_UINT8(link_type, p_event);
handle = HCID_GET_HANDLE(handle);
- log_link_layer_connection_event(&bda, handle, android::bluetooth::DIRECTION_UNKNOWN,
- link_type, cmd, evt_code,
- android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ &bda, handle, android::bluetooth::DIRECTION_UNKNOWN, link_type, cmd, evt_code,
+ android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
break;
}
case HCI_ESCO_CONNECTION_CHANGED_EVT: {
STREAM_TO_UINT8(status, p_event);
STREAM_TO_UINT16(handle, p_event);
handle = HCID_GET_HANDLE(handle);
- log_link_layer_connection_event(nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
- android::bluetooth::LINK_TYPE_UNKNOWN, cmd, evt_code,
- android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
+ android::bluetooth::LINK_TYPE_UNKNOWN, cmd, evt_code,
+ android::bluetooth::hci::BLE_EVT_UNKNOWN, status, reason);
break;
}
// Ignore these events
@@ -368,32 +374,33 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, const uint8_t* p_cmd,
case HCI_CREATE_CONNECTION:
case HCI_CREATE_CONNECTION_CANCEL:
STREAM_TO_BDADDR(bd_addr, p_cmd);
- log_link_layer_connection_event(
- &bd_addr, bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ &bd_addr, bluetooth::os::kUnknownConnectionHandle,
android::bluetooth::DIRECTION_OUTGOING, android::bluetooth::LINK_TYPE_ACL, opcode,
hci_event, kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
break;
case HCI_DISCONNECT:
STREAM_TO_UINT16(handle, p_cmd);
STREAM_TO_UINT8(reason, p_cmd);
- log_link_layer_connection_event(nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
- android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
- kUnknownBleEvt, cmd_status, reason);
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ nullptr, handle, android::bluetooth::DIRECTION_UNKNOWN,
+ android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event, kUnknownBleEvt, cmd_status,
+ reason);
break;
case HCI_SETUP_ESCO_CONNECTION:
case HCI_ENH_SETUP_ESCO_CONNECTION:
STREAM_TO_UINT16(handle, p_cmd);
- log_link_layer_connection_event(nullptr, handle, android::bluetooth::DIRECTION_OUTGOING,
- android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
- kUnknownBleEvt, cmd_status,
- android::bluetooth::hci::STATUS_UNKNOWN);
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ nullptr, handle, android::bluetooth::DIRECTION_OUTGOING,
+ android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event, kUnknownBleEvt, cmd_status,
+ android::bluetooth::hci::STATUS_UNKNOWN);
break;
case HCI_ACCEPT_CONNECTION_REQUEST:
case HCI_ACCEPT_ESCO_CONNECTION:
case HCI_ENH_ACCEPT_ESCO_CONNECTION:
STREAM_TO_BDADDR(bd_addr, p_cmd);
- log_link_layer_connection_event(
- &bd_addr, bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ &bd_addr, bluetooth::os::kUnknownConnectionHandle,
android::bluetooth::DIRECTION_INCOMING, android::bluetooth::LINK_TYPE_UNKNOWN, opcode,
hci_event, kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
break;
@@ -401,10 +408,10 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, const uint8_t* p_cmd,
case HCI_REJECT_ESCO_CONNECTION:
STREAM_TO_BDADDR(bd_addr, p_cmd);
STREAM_TO_UINT8(reason, p_cmd);
- log_link_layer_connection_event(&bd_addr, bluetooth::common::kUnknownConnectionHandle,
- android::bluetooth::DIRECTION_INCOMING,
- android::bluetooth::LINK_TYPE_UNKNOWN, opcode, hci_event,
- kUnknownBleEvt, cmd_status, reason);
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ &bd_addr, bluetooth::os::kUnknownConnectionHandle,
+ android::bluetooth::DIRECTION_INCOMING, android::bluetooth::LINK_TYPE_UNKNOWN, opcode,
+ hci_event, kUnknownBleEvt, cmd_status, reason);
break;
// BLE Commands
@@ -431,8 +438,8 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, const uint8_t* p_cmd,
// Selectively log to avoid log spam due to acceptlist connections:
// - When doing non-acceptlist connection
// - When there is an error in command status
- log_link_layer_connection_event(
- bd_addr_p, bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ bd_addr_p, bluetooth::os::kUnknownConnectionHandle,
android::bluetooth::DIRECTION_OUTGOING, android::bluetooth::LINK_TYPE_ACL, opcode,
hci_event, kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
}
@@ -456,8 +463,8 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, const uint8_t* p_cmd,
// Selectively log to avoid log spam due to acceptlist connections:
// - When doing non-acceptlist connection
// - When there is an error in command status
- log_link_layer_connection_event(
- bd_addr_p, bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ bd_addr_p, bluetooth::os::kUnknownConnectionHandle,
android::bluetooth::DIRECTION_OUTGOING, android::bluetooth::LINK_TYPE_ACL, opcode,
hci_event, kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
}
@@ -466,54 +473,56 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, const uint8_t* p_cmd,
case HCI_BLE_CREATE_CONN_CANCEL:
if (cmd_status != HCI_SUCCESS && !is_cmd_status) {
// Only log errors to prevent log spam due to acceptlist connections
- log_link_layer_connection_event(
- nullptr, bluetooth::common::kUnknownConnectionHandle,
+ bluetooth::shim::LogMetricLinkLayerConnectionEvent(
+ nullptr, bluetooth::os::kUnknownConnectionHandle,
android::bluetooth::DIRECTION_OUTGOING, android::bluetooth::LINK_TYPE_ACL, opcode,
hci_event, kUnknownBleEvt, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN);
}
break;
case HCI_READ_LOCAL_OOB_DATA:
case HCI_READ_LOCAL_OOB_EXTENDED_DATA:
- log_classic_pairing_event(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
- opcode, hci_event, cmd_status,
- android::bluetooth::hci::STATUS_UNKNOWN, 0);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ RawAddress::kEmpty, bluetooth::os::kUnknownConnectionHandle, opcode, hci_event,
+ cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, 0);
break;
case HCI_WRITE_SIMPLE_PAIRING_MODE: {
uint8_t simple_pairing_mode;
STREAM_TO_UINT8(simple_pairing_mode, p_cmd);
- log_classic_pairing_event(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
- opcode, hci_event, cmd_status,
- android::bluetooth::hci::STATUS_UNKNOWN, simple_pairing_mode);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ RawAddress::kEmpty, bluetooth::os::kUnknownConnectionHandle, opcode, hci_event,
+ cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, simple_pairing_mode);
break;
}
case HCI_WRITE_SECURE_CONNS_SUPPORT: {
uint8_t secure_conn_host_support;
STREAM_TO_UINT8(secure_conn_host_support, p_cmd);
- log_classic_pairing_event(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
- opcode, hci_event, cmd_status,
- android::bluetooth::hci::STATUS_UNKNOWN, secure_conn_host_support);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ RawAddress::kEmpty, bluetooth::os::kUnknownConnectionHandle, opcode, hci_event,
+ cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, secure_conn_host_support);
break;
}
case HCI_AUTHENTICATION_REQUESTED:
STREAM_TO_UINT16(handle, p_cmd);
- log_classic_pairing_event(RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
- android::bluetooth::hci::STATUS_UNKNOWN, 0);
+ bluetooth::shim::LogMetricClassicPairingEvent(RawAddress::kEmpty, handle, opcode, hci_event,
+ cmd_status,
+ android::bluetooth::hci::STATUS_UNKNOWN, 0);
break;
case HCI_SET_CONN_ENCRYPTION: {
STREAM_TO_UINT16(handle, p_cmd);
uint8_t encryption_enable;
STREAM_TO_UINT8(encryption_enable, p_cmd);
- log_classic_pairing_event(RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
- android::bluetooth::hci::STATUS_UNKNOWN, encryption_enable);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ RawAddress::kEmpty, handle, opcode, hci_event, cmd_status,
+ android::bluetooth::hci::STATUS_UNKNOWN, encryption_enable);
break;
}
case HCI_DELETE_STORED_LINK_KEY: {
uint8_t delete_all_flag;
STREAM_TO_BDADDR(bd_addr, p_cmd);
STREAM_TO_UINT8(delete_all_flag, p_cmd);
- log_classic_pairing_event(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
- hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN,
- delete_all_flag);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ bd_addr, bluetooth::os::kUnknownConnectionHandle, opcode, hci_event, cmd_status,
+ android::bluetooth::hci::STATUS_UNKNOWN, delete_all_flag);
break;
}
case HCI_RMT_NAME_REQUEST:
@@ -528,14 +537,16 @@ static void btu_hcif_log_command_metrics(uint16_t opcode, const uint8_t* p_cmd,
case HCI_REM_OOB_DATA_REQ_REPLY:
case HCI_REM_OOB_DATA_REQ_NEG_REPLY:
STREAM_TO_BDADDR(bd_addr, p_cmd);
- log_classic_pairing_event(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
- hci_event, cmd_status, android::bluetooth::hci::STATUS_UNKNOWN, 0);
+ bluetooth::shim::LogMetricClassicPairingEvent(
+ bd_addr, bluetooth::os::kUnknownConnectionHandle, opcode, hci_event, cmd_status,
+ android::bluetooth::hci::STATUS_UNKNOWN, 0);
break;
case HCI_IO_CAP_REQ_NEG_REPLY:
STREAM_TO_BDADDR(bd_addr, p_cmd);
STREAM_TO_UINT8(reason, p_cmd);
- log_classic_pairing_event(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
- hci_event, cmd_status, reason, 0);
+ bluetooth::shim::LogMetricClassicPairingEvent(bd_addr,
+ bluetooth::os::kUnknownConnectionHandle, opcode,
+ hci_event, cmd_status, reason, 0);
break;
}
}
@@ -599,8 +610,9 @@ static void btu_hcif_log_command_complete_metrics(uint16_t opcode, const uint8_t
case HCI_WRITE_SIMPLE_PAIRING_MODE:
case HCI_WRITE_SECURE_CONNS_SUPPORT:
STREAM_TO_UINT8(status, p_return_params);
- log_classic_pairing_event(RawAddress::kEmpty, bluetooth::common::kUnknownConnectionHandle,
- opcode, hci_event, status, reason, 0);
+ bluetooth::shim::LogMetricClassicPairingEvent(RawAddress::kEmpty,
+ bluetooth::os::kUnknownConnectionHandle, opcode,
+ hci_event, status, reason, 0);
break;
case HCI_READ_ENCR_KEY_SIZE: {
uint16_t handle;
@@ -608,8 +620,8 @@ static void btu_hcif_log_command_complete_metrics(uint16_t opcode, const uint8_t
STREAM_TO_UINT8(status, p_return_params);
STREAM_TO_UINT16(handle, p_return_params);
STREAM_TO_UINT8(key_size, p_return_params);
- log_classic_pairing_event(RawAddress::kEmpty, handle, opcode, hci_event, status, reason,
- key_size);
+ bluetooth::shim::LogMetricClassicPairingEvent(RawAddress::kEmpty, handle, opcode, hci_event,
+ status, reason, key_size);
break;
}
case HCI_LINK_KEY_REQUEST_REPLY:
@@ -624,8 +636,9 @@ static void btu_hcif_log_command_complete_metrics(uint16_t opcode, const uint8_t
case HCI_REM_OOB_DATA_REQ_NEG_REPLY:
STREAM_TO_UINT8(status, p_return_params);
STREAM_TO_BDADDR(bd_addr, p_return_params);
- log_classic_pairing_event(bd_addr, bluetooth::common::kUnknownConnectionHandle, opcode,
- hci_event, status, reason, 0);
+ bluetooth::shim::LogMetricClassicPairingEvent(bd_addr,
+ bluetooth::os::kUnknownConnectionHandle, opcode,
+ hci_event, status, reason, 0);
break;
}
}
diff --git a/system/stack/fuzzers/l2cap_fuzzer.cc b/system/stack/fuzzers/l2cap_fuzzer.cc
index 6cb4d5170f..69243a67c4 100644
--- a/system/stack/fuzzers/l2cap_fuzzer.cc
+++ b/system/stack/fuzzers/l2cap_fuzzer.cc
@@ -121,26 +121,30 @@ public:
GetInterfaceToProfiles()->profileSpecific_HACK->GetHearingAidDeviceCount = []() { return 1; };
- ON_CALL(controller_, GetLeSuggestedDefaultDataLength).WillByDefault(Return(512));
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetLeSuggestedDefaultDataLength)
+ .WillByDefault(Return(512));
bluetooth::hci::LeBufferSize iso_size;
iso_size.le_data_packet_length_ = 512;
iso_size.total_num_le_packets_ = 6;
- ON_CALL(controller_, GetControllerIsoBufferSize).WillByDefault(Return(iso_size));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetControllerIsoBufferSize)
+ .WillByDefault(Return(iso_size));
bluetooth::hci::LeBufferSize le_size;
le_size.le_data_packet_length_ = 512;
le_size.total_num_le_packets_ = 6;
- ON_CALL(controller_, GetLeBufferSize).WillByDefault(Return(le_size));
- ON_CALL(controller_, SupportsBle).WillByDefault(Return(true));
- ON_CALL(controller_, GetAclPacketLength).WillByDefault(Return(512));
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetLeBufferSize)
+ .WillByDefault(Return(le_size));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsBle).WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetAclPacketLength)
+ .WillByDefault(Return(512));
}
~FakeBtStack() {
test::mock::stack_acl::acl_send_data_packet_br_edr = {};
test::mock::stack_acl::acl_send_data_packet_ble = {};
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class Fakes {
diff --git a/system/stack/gatt/gatt_api.cc b/system/stack/gatt/gatt_api.cc
index 1b60132b00..bb5641d97d 100644
--- a/system/stack/gatt/gatt_api.cc
+++ b/system/stack/gatt/gatt_api.cc
@@ -34,6 +34,7 @@
#include "internal_include/bt_target.h"
#include "internal_include/stack_config.h"
#include "main/shim/helpers.h"
+#include "main/shim/metrics_api.h"
#include "os/system_properties.h"
#include "osi/include/allocator.h"
#include "stack/arbiter/acl_arbiter.h"
@@ -48,7 +49,6 @@
#include "stack/include/l2cap_interface.h"
#include "stack/include/l2cdefs.h"
#include "stack/include/sdp_api.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/bluetooth/uuid.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"
@@ -75,8 +75,7 @@ static tGATT_HDL_LIST_ELEM& gatt_add_an_item_to_list(uint16_t s_handle) {
return *rit;
}
-static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string& name,
- tGATT_CBACK* p_cb_info, bool eatt_support);
+static tGATT_IF GATT_FindNextFreeClRcbId();
/*****************************************************************************
*
@@ -1229,63 +1228,6 @@ void GATT_SetIdleTimeout(const RawAddress& bd_addr, uint16_t idle_tout, tBT_TRAN
******************************************************************************/
tGATT_IF GATT_Register(const Uuid& app_uuid128, const std::string& name, tGATT_CBACK* p_cb_info,
bool eatt_support) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- return GATT_Register_Dynamic(app_uuid128, name, p_cb_info, eatt_support);
- }
- tGATT_REG* p_reg;
- uint8_t i_gatt_if = 0;
- tGATT_IF gatt_if = 0;
-
- for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS; i_gatt_if++, p_reg++) {
- if (p_reg->in_use && p_reg->app_uuid128 == app_uuid128) {
- log::error("Application already registered, uuid={}", app_uuid128.ToString());
- return 0;
- }
- }
-
- if (stack_config_get_interface()->get_pts_use_eatt_for_all_services()) {
- log::info("PTS: Force to use EATT for servers");
- eatt_support = true;
- }
-
- for (i_gatt_if = 0, p_reg = gatt_cb.cl_rcb; i_gatt_if < GATT_MAX_APPS; i_gatt_if++, p_reg++) {
- if (!p_reg->in_use) {
- *p_reg = {};
- i_gatt_if++; /* one based number */
- p_reg->app_uuid128 = app_uuid128;
- gatt_if = p_reg->gatt_if = (tGATT_IF)i_gatt_if;
- p_reg->app_cb = *p_cb_info;
- p_reg->in_use = true;
- p_reg->eatt_support = eatt_support;
- p_reg->name = name;
- log::info("Allocated name:{} uuid:{} gatt_if:{} eatt_support:{}", name,
- app_uuid128.ToString(), gatt_if, eatt_support);
- return gatt_if;
- }
- }
-
- log::error("Unable to register GATT client, MAX client reached: {}", GATT_MAX_APPS);
- return 0;
-}
-
-static tGATT_IF GATT_FindNextFreeClRcbId() {
- tGATT_IF gatt_if = gatt_cb.last_gatt_if;
- for (int i = 0; i < GATT_IF_MAX; i++) {
- if (++gatt_if > GATT_IF_MAX) {
- gatt_if = static_cast<tGATT_IF>(1);
- }
- if (!gatt_cb.cl_rcb_map.contains(gatt_if)) {
- gatt_cb.last_gatt_if = gatt_if;
- return gatt_if;
- }
- }
- log::error("Unable to register GATT client, MAX client reached: {}", gatt_cb.cl_rcb_map.size());
-
- return GATT_IF_INVALID;
-}
-
-static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string& name,
- tGATT_CBACK* p_cb_info, bool eatt_support) {
for (auto& [gatt_if, p_reg] : gatt_cb.cl_rcb_map) {
if (p_reg->app_uuid128 == app_uuid128) {
log::error("Application already registered, uuid={}", app_uuid128.ToString());
@@ -1322,6 +1264,22 @@ static tGATT_IF GATT_Register_Dynamic(const Uuid& app_uuid128, const std::string
return gatt_if;
}
+static tGATT_IF GATT_FindNextFreeClRcbId() {
+ tGATT_IF gatt_if = gatt_cb.last_gatt_if;
+ for (int i = 0; i < GATT_IF_MAX; i++) {
+ if (++gatt_if > GATT_IF_MAX) {
+ gatt_if = static_cast<tGATT_IF>(1);
+ }
+ if (!gatt_cb.cl_rcb_map.contains(gatt_if)) {
+ gatt_cb.last_gatt_if = gatt_if;
+ return gatt_if;
+ }
+ }
+ log::error("Unable to register GATT client, MAX client reached: {}", gatt_cb.cl_rcb_map.size());
+
+ return GATT_IF_INVALID;
+}
+
/*******************************************************************************
*
* Function GATT_Deregister
@@ -1385,11 +1343,7 @@ void GATT_Deregister(tGATT_IF gatt_if) {
connection_manager::on_app_deregistered(gatt_if);
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- gatt_cb.cl_rcb_map.erase(gatt_if);
- } else {
- *p_reg = {};
- }
+ gatt_cb.cl_rcb_map.erase(gatt_if);
}
/*******************************************************************************
@@ -1476,7 +1430,8 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, tBLE_ADDR_TYPE ad
return true;
}
- log_le_connection_lifecycle(ToGdAddress(bd_addr), true /* is_connect */, is_direct);
+ bluetooth::shim::LogMetricLeConnectionLifecycle(ToGdAddress(bd_addr), true /* is_connect */,
+ is_direct);
bool ret = false;
if (is_direct) {
@@ -1618,8 +1573,8 @@ tGATT_STATUS GATT_Disconnect(tCONN_ID conn_id) {
return GATT_ILLEGAL_PARAMETER;
}
- log_le_connection_lifecycle(ToGdAddress(p_tcb->peer_bda), true /* is_connect */,
- false /* is_direct */);
+ bluetooth::shim::LogMetricLeConnectionLifecycle(ToGdAddress(p_tcb->peer_bda),
+ true /* is_connect */, false /* is_direct */);
tGATT_IF gatt_if = gatt_get_gatt_if(conn_id);
gatt_update_app_use_link_flag(gatt_if, p_tcb, false, true);
diff --git a/system/stack/gatt/gatt_auth.cc b/system/stack/gatt/gatt_auth.cc
index 7c4b935389..34dcb4886b 100644
--- a/system/stack/gatt/gatt_auth.cc
+++ b/system/stack/gatt/gatt_auth.cc
@@ -23,7 +23,6 @@
******************************************************************************/
#include <bluetooth/log.h>
-#include <com_android_bluetooth_flags.h>
#include <string.h>
#include "gatt_api.h"
@@ -216,17 +215,9 @@ void gatt_notify_enc_cmpl(const RawAddress& bd_addr) {
return;
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_rcb] : gatt_cb.cl_rcb_map) {
- if (p_rcb->app_cb.p_enc_cmpl_cb) {
- (*p_rcb->app_cb.p_enc_cmpl_cb)(p_rcb->gatt_if, bd_addr);
- }
- }
- } else {
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- if (gatt_cb.cl_rcb[i].in_use && gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb) {
- (*gatt_cb.cl_rcb[i].app_cb.p_enc_cmpl_cb)(gatt_cb.cl_rcb[i].gatt_if, bd_addr);
- }
+ for (auto& [i, p_rcb] : gatt_cb.cl_rcb_map) {
+ if (p_rcb->app_cb.p_enc_cmpl_cb) {
+ (*p_rcb->app_cb.p_enc_cmpl_cb)(p_rcb->gatt_if, bd_addr);
}
}
diff --git a/system/stack/gatt/gatt_cl.cc b/system/stack/gatt/gatt_cl.cc
index 9a241813ae..8496d425a1 100644
--- a/system/stack/gatt/gatt_cl.cc
+++ b/system/stack/gatt/gatt_cl.cc
@@ -25,7 +25,6 @@
#define LOG_TAG "bluetooth"
#include <bluetooth/log.h>
-#include <com_android_bluetooth_flags.h>
#include <string.h>
#include "gatt_int.h"
@@ -708,17 +707,9 @@ static void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_c
// notification/indication
// Note: need to do the indication count and start timer first then do
// callback
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
- tcb.ind_count++;
- }
- }
- } else {
- for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
- if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
- tcb.ind_count++;
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
+ tcb.ind_count++;
}
}
@@ -738,19 +729,10 @@ static void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_c
gatt_cl_complete.att_value = value;
gatt_cl_complete.cid = cid;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
- conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete);
- }
- }
- } else {
- for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
- if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
- conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete);
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
+ conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete);
}
}
@@ -788,19 +770,10 @@ static void gatt_process_notification(tGATT_TCB& tcb, uint16_t cid, uint8_t op_c
gatt_cl_complete.att_value = value;
gatt_cl_complete.cid = cid;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
- conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete);
- }
- }
- } else {
- for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
- if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
- conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete);
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_cmpl_cb) {
+ conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_cmpl_cb)(conn_id, event, encrypt_status, &gatt_cl_complete);
}
}
}
diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc
index 56d268422c..19fd83990a 100644
--- a/system/stack/gatt/gatt_main.cc
+++ b/system/stack/gatt/gatt_main.cc
@@ -624,21 +624,10 @@ static void gatt_channel_congestion(tGATT_TCB* p_tcb, bool congested) {
gatt_cl_send_next_cmd_inq(*p_tcb);
}
/* notifying all applications for the connection up event */
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_congestion_cb) {
- conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_congestion_cb)(conn_id, congested);
- }
- }
- } else {
- for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
- if (p_reg->in_use) {
- if (p_reg->app_cb.p_congestion_cb) {
- conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_congestion_cb)(conn_id, congested);
- }
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_congestion_cb) {
+ conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_congestion_cb)(conn_id, congested);
}
}
}
@@ -658,20 +647,10 @@ void gatt_notify_phy_updated(tHCI_STATUS status, uint16_t handle, uint8_t tx_phy
// TODO: Clean up this status conversion.
tGATT_STATUS gatt_status = static_cast<tGATT_STATUS>(status);
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_phy_update_cb) {
- tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_phy_update_cb)(p_reg->gatt_if, conn_id, tx_phy, rx_phy, gatt_status);
- }
- }
- } else {
- for (int i = 0; i < GATT_MAX_APPS; i++) {
- tGATT_REG* p_reg = &gatt_cb.cl_rcb[i];
- if (p_reg->in_use && p_reg->app_cb.p_phy_update_cb) {
- tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_phy_update_cb)(p_reg->gatt_if, conn_id, tx_phy, rx_phy, gatt_status);
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_phy_update_cb) {
+ tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_phy_update_cb)(p_reg->gatt_if, conn_id, tx_phy, rx_phy, gatt_status);
}
}
}
@@ -684,22 +663,11 @@ void gatt_notify_conn_update(const RawAddress& remote, uint16_t interval, uint16
return;
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_conn_update_cb) {
- tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_conn_update_cb)(p_reg->gatt_if, conn_id, interval, latency, timeout,
- static_cast<tGATT_STATUS>(status));
- }
- }
- } else {
- for (int i = 0; i < GATT_MAX_APPS; i++) {
- tGATT_REG* p_reg = &gatt_cb.cl_rcb[i];
- if (p_reg->in_use && p_reg->app_cb.p_conn_update_cb) {
- tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_conn_update_cb)(p_reg->gatt_if, conn_id, interval, latency, timeout,
- static_cast<tGATT_STATUS>(status));
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_conn_update_cb) {
+ tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_conn_update_cb)(p_reg->gatt_if, conn_id, interval, latency, timeout,
+ static_cast<tGATT_STATUS>(status));
}
}
}
@@ -717,22 +685,11 @@ void gatt_notify_subrate_change(uint16_t handle, uint16_t subrate_factor, uint16
return;
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_subrate_chg_cb) {
- tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_subrate_chg_cb)(p_reg->gatt_if, conn_id, subrate_factor, latency,
- cont_num, timeout, static_cast<tGATT_STATUS>(status));
- }
- }
- } else {
- for (int i = 0; i < GATT_MAX_APPS; i++) {
- tGATT_REG* p_reg = &gatt_cb.cl_rcb[i];
- if (p_reg->in_use && p_reg->app_cb.p_subrate_chg_cb) {
- tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_subrate_chg_cb)(p_reg->gatt_if, conn_id, subrate_factor, latency,
- cont_num, timeout, static_cast<tGATT_STATUS>(status));
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_subrate_chg_cb) {
+ tCONN_ID conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_subrate_chg_cb)(p_reg->gatt_if, conn_id, subrate_factor, latency, cont_num,
+ timeout, static_cast<tGATT_STATUS>(status));
}
}
}
@@ -976,37 +933,19 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) {
/* notifying all applications for the connection up event */
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (!p_reg->in_use) {
- continue;
- }
-
- if (apps.find(p_reg->gatt_if) != apps.end()) {
- gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
- }
-
- if (p_reg->app_cb.p_conn_cb) {
- conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, kGattConnected,
- GATT_CONN_OK, p_tcb->transport);
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (!p_reg->in_use) {
+ continue;
}
- } else {
- for (i = 0, p_reg = gatt_cb.cl_rcb; i < GATT_MAX_APPS; i++, p_reg++) {
- if (!p_reg->in_use) {
- continue;
- }
- if (apps.find(p_reg->gatt_if) != apps.end()) {
- gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
- }
+ if (apps.find(p_reg->gatt_if) != apps.end()) {
+ gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
+ }
- if (p_reg->app_cb.p_conn_cb) {
- conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
- (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, kGattConnected,
- GATT_CONN_OK, p_tcb->transport);
- }
+ if (p_reg->app_cb.p_conn_cb) {
+ conn_id = gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if);
+ (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, p_tcb->peer_bda, conn_id, kGattConnected,
+ GATT_CONN_OK, p_tcb->transport);
}
}
diff --git a/system/stack/gatt/gatt_sr.cc b/system/stack/gatt/gatt_sr.cc
index 133080c1db..f23b8b5dc9 100644
--- a/system/stack/gatt/gatt_sr.cc
+++ b/system/stack/gatt/gatt_sr.cc
@@ -407,27 +407,14 @@ static void gatt_process_exec_write_req(tGATT_TCB& tcb, uint16_t cid, uint8_t op
trans_id = gatt_sr_enqueue_cmd(tcb, cid, op_code, 0);
gatt_sr_copy_prep_cnt_to_cback_cnt(tcb);
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- auto prep_cnt_it = tcb.prep_cnt_map.begin();
- while (prep_cnt_it != tcb.prep_cnt_map.end()) {
- gatt_if = prep_cnt_it->first;
- conn_id = gatt_create_conn_id(tcb.tcb_idx, gatt_if);
- tGATTS_DATA gatts_data;
- gatts_data.exec_write = flag;
- gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_WRITE_EXEC, &gatts_data);
- prep_cnt_it = tcb.prep_cnt_map.erase(prep_cnt_it);
- }
- } else {
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- if (tcb.prep_cnt[i]) {
- gatt_if = (tGATT_IF)(i + 1);
- conn_id = gatt_create_conn_id(tcb.tcb_idx, gatt_if);
- tGATTS_DATA gatts_data;
- gatts_data.exec_write = flag;
- gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_WRITE_EXEC, &gatts_data);
- tcb.prep_cnt[i] = 0;
- }
- }
+ auto prep_cnt_it = tcb.prep_cnt_map.begin();
+ while (prep_cnt_it != tcb.prep_cnt_map.end()) {
+ gatt_if = prep_cnt_it->first;
+ conn_id = gatt_create_conn_id(tcb.tcb_idx, gatt_if);
+ tGATTS_DATA gatts_data;
+ gatts_data.exec_write = flag;
+ gatt_sr_send_req_callback(conn_id, trans_id, GATTS_REQ_TYPE_WRITE_EXEC, &gatts_data);
+ prep_cnt_it = tcb.prep_cnt_map.erase(prep_cnt_it);
}
} else { /* nothing needs to be executed , send response now */
log::warn("gatt_process_exec_write_req: no prepare write pending");
@@ -911,19 +898,10 @@ static void gatts_process_mtu_req(tGATT_TCB& tcb, uint16_t cid, uint16_t len, ui
gatts_data.mtu = tcb.payload_size;
/* Notify all registered application with new MTU size. Use a transaction ID */
/* of 0, as no response is allowed from applications */
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use) {
- tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
- gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, &gatts_data);
- }
- }
- } else {
- for (int i = 0; i < GATT_MAX_APPS; i++) {
- if (gatt_cb.cl_rcb[i].in_use) {
- tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, gatt_cb.cl_rcb[i].gatt_if);
- gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, &gatts_data);
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use) {
+ tCONN_ID conn_id = gatt_create_conn_id(tcb.tcb_idx, p_reg->gatt_if);
+ gatt_sr_send_req_callback(conn_id, 0, GATTS_REQ_TYPE_MTU, &gatts_data);
}
}
}
diff --git a/system/stack/gatt/gatt_utils.cc b/system/stack/gatt/gatt_utils.cc
index f401be9285..28590330c5 100644
--- a/system/stack/gatt/gatt_utils.cc
+++ b/system/stack/gatt/gatt_utils.cc
@@ -24,7 +24,6 @@
#define LOG_TAG "gatt_utils"
#include <bluetooth/log.h>
-#include <com_android_bluetooth_flags.h>
#include <cstdint>
#include <deque>
@@ -1043,21 +1042,12 @@ tGATT_REG* gatt_get_regcb(tGATT_IF gatt_if) {
uint8_t ii = (uint8_t)gatt_if;
tGATT_REG* p_reg = NULL;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- auto it = gatt_cb.cl_rcb_map.find(gatt_if);
- if (it == gatt_cb.cl_rcb_map.end()) {
- log::warn("unknown gatt_if = {}", ii);
- return NULL;
- }
- p_reg = it->second.get();
- } else {
- // Index for cl_rcb is always 1 less than gatt_if.
- if (ii < 1 || ii > GATT_MAX_APPS) {
- log::warn("gatt_if out of range = {}", ii);
- return NULL;
- }
- p_reg = &gatt_cb.cl_rcb[ii - 1];
+ auto it = gatt_cb.cl_rcb_map.find(gatt_if);
+ if (it == gatt_cb.cl_rcb_map.end()) {
+ log::warn("unknown gatt_if = {}", ii);
+ return NULL;
}
+ p_reg = it->second.get();
if (!p_reg->in_use) {
log::warn("gatt_if found but not in use.");
@@ -1332,16 +1322,8 @@ tGATT_TCB* gatt_find_tcb_by_cid(uint16_t lcid) {
}
void gatt_sr_copy_prep_cnt_to_cback_cnt(tGATT_TCB& tcb) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, cnt] : tcb.prep_cnt_map) {
- tcb.sr_cmd.cback_cnt_map[i] = 1;
- }
- } else {
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- if (tcb.prep_cnt[i]) {
- tcb.sr_cmd.cback_cnt[i] = 1;
- }
- }
+ for (auto& [i, cnt] : tcb.prep_cnt_map) {
+ tcb.sr_cmd.cback_cnt_map[i] = 1;
}
}
@@ -1385,17 +1367,7 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb, uint16_t cid) {
sr_cmd_p = &channel->server_outstanding_cmd_;
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- return sr_cmd_p->cback_cnt_map.empty();
- }
-
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- if (sr_cmd_p->cback_cnt[i] != 0) {
- return false;
- }
- }
-
- return true;
+ return sr_cmd_p->cback_cnt_map.empty();
}
/*******************************************************************************
@@ -1407,18 +1379,7 @@ bool gatt_sr_is_cback_cnt_zero(tGATT_TCB& tcb, uint16_t cid) {
* Returns True no prepare write request
*
******************************************************************************/
-bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- return tcb.prep_cnt_map.empty();
- } else {
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- if (tcb.prep_cnt[i]) {
- return false;
- }
- }
- return true;
- }
-}
+bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) { return tcb.prep_cnt_map.empty(); }
/*******************************************************************************
*
@@ -1430,31 +1391,15 @@ bool gatt_sr_is_prep_cnt_zero(tGATT_TCB& tcb) {
*
******************************************************************************/
void gatt_sr_reset_cback_cnt(tGATT_TCB& tcb, uint16_t cid) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (cid == tcb.att_lcid) {
- tcb.sr_cmd.cback_cnt_map.clear();
- } else {
- EattChannel* channel = EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cid);
- if (channel == nullptr) {
- log::warn("{}, cid 0x{:02x} already disconnected", tcb.peer_bda, cid);
- return;
- }
- channel->server_outstanding_cmd_.cback_cnt_map.clear();
- }
+ if (cid == tcb.att_lcid) {
+ tcb.sr_cmd.cback_cnt_map.clear();
} else {
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- if (cid == tcb.att_lcid) {
- tcb.sr_cmd.cback_cnt[i] = 0;
- } else {
- EattChannel* channel =
- EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cid);
- if (channel == nullptr) {
- log::warn("{}, cid 0x{:02x} already disconnected", tcb.peer_bda, cid);
- return;
- }
- channel->server_outstanding_cmd_.cback_cnt[i] = 0;
- }
+ EattChannel* channel = EattExtension::GetInstance()->FindEattChannelByCid(tcb.peer_bda, cid);
+ if (channel == nullptr) {
+ log::warn("{}, cid 0x{:02x} already disconnected", tcb.peer_bda, cid);
+ return;
}
+ channel->server_outstanding_cmd_.cback_cnt_map.clear();
}
}
@@ -1540,25 +1485,13 @@ void gatt_sr_update_cback_cnt(tGATT_TCB& tcb, uint16_t cid, tGATT_IF gatt_if, bo
gatt_sr_reset_cback_cnt(tcb, cid);
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (is_inc) {
- sr_cmd_p->cback_cnt_map[gatt_if]++;
- } else {
- auto cback_cnt_it = sr_cmd_p->cback_cnt_map.find(gatt_if);
- if (cback_cnt_it != sr_cmd_p->cback_cnt_map.end()) {
- if ((--cback_cnt_it->second) <= 0) {
- sr_cmd_p->cback_cnt_map.erase(cback_cnt_it);
- }
- }
- }
+ if (is_inc) {
+ sr_cmd_p->cback_cnt_map[gatt_if]++;
} else {
- uint8_t idx = ((uint8_t)gatt_if) - 1;
-
- if (is_inc) {
- sr_cmd_p->cback_cnt[idx]++;
- } else {
- if (sr_cmd_p->cback_cnt[idx]) {
- sr_cmd_p->cback_cnt[idx]--;
+ auto cback_cnt_it = sr_cmd_p->cback_cnt_map.find(gatt_if);
+ if (cback_cnt_it != sr_cmd_p->cback_cnt_map.end()) {
+ if ((--cback_cnt_it->second) <= 0) {
+ sr_cmd_p->cback_cnt_map.erase(cback_cnt_it);
}
}
}
@@ -1582,23 +1515,13 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc, bool
if (is_reset_first) {
gatt_sr_reset_prep_cnt(tcb);
}
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- if (is_inc) {
- tcb.prep_cnt_map[gatt_if]++;
- } else {
- auto prep_cnt_i = tcb.prep_cnt_map.find(gatt_if);
- if (prep_cnt_i != tcb.prep_cnt_map.end()) {
- if (--prep_cnt_i->second <= 0) {
- tcb.prep_cnt_map.erase(prep_cnt_i);
- }
- }
- }
+ if (is_inc) {
+ tcb.prep_cnt_map[gatt_if]++;
} else {
- if (is_inc) {
- tcb.prep_cnt[idx]++;
- } else {
- if (tcb.prep_cnt[idx]) {
- tcb.prep_cnt[idx]--;
+ auto prep_cnt_i = tcb.prep_cnt_map.find(gatt_if);
+ if (prep_cnt_i != tcb.prep_cnt_map.end()) {
+ if (--prep_cnt_i->second <= 0) {
+ tcb.prep_cnt_map.erase(prep_cnt_i);
}
}
}
@@ -1806,24 +1729,12 @@ static void gatt_disconnect_complete_notify_user(const RawAddress& bda, tGATT_DI
tBT_TRANSPORT transport) {
tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bda, transport);
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (p_reg->in_use && p_reg->app_cb.p_conn_cb) {
- tCONN_ID conn_id =
- p_tcb ? gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID;
- (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason,
- transport);
- }
- }
- } else {
- for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
- tGATT_REG* p_reg = &gatt_cb.cl_rcb[i];
- if (p_reg->in_use && p_reg->app_cb.p_conn_cb) {
- tCONN_ID conn_id =
- p_tcb ? gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID;
- (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason,
- transport);
- }
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (p_reg->in_use && p_reg->app_cb.p_conn_cb) {
+ tCONN_ID conn_id =
+ p_tcb ? gatt_create_conn_id(p_tcb->tcb_idx, p_reg->gatt_if) : GATT_INVALID_CONN_ID;
+ (*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason,
+ transport);
}
}
}
@@ -1943,41 +1854,22 @@ uint16_t gatt_get_mtu_pref(const tGATT_REG* p_reg, const RawAddress& bda) {
uint16_t gatt_get_apps_preferred_mtu(const RawAddress& bda) {
uint16_t preferred_mtu = 0;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (!p_reg->in_use) {
- continue;
- }
-
- preferred_mtu = std::max(preferred_mtu, gatt_get_mtu_pref(p_reg.get(), bda));
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (!p_reg->in_use) {
+ continue;
}
- } else {
- for (auto& reg : gatt_cb.cl_rcb) {
- if (!reg.in_use) {
- continue;
- }
- preferred_mtu = std::max(preferred_mtu, gatt_get_mtu_pref(&reg, bda));
- }
+ preferred_mtu = std::max(preferred_mtu, gatt_get_mtu_pref(p_reg.get(), bda));
}
return preferred_mtu;
}
void gatt_remove_apps_mtu_prefs(const RawAddress& bda) {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
- if (!p_reg->in_use) {
- continue;
- }
- p_reg.get()->mtu_prefs.erase(bda);
- }
- } else {
- for (auto& reg : gatt_cb.cl_rcb) {
- if (!reg.in_use) {
- continue;
- }
- reg.mtu_prefs.erase(bda);
+ for (auto& [i, p_reg] : gatt_cb.cl_rcb_map) {
+ if (!p_reg->in_use) {
+ continue;
}
+ p_reg.get()->mtu_prefs.erase(bda);
}
}
diff --git a/system/stack/hid/hidd_api.cc b/system/stack/hid/hidd_api.cc
index 169868bbfc..58d9bdc07a 100644
--- a/system/stack/hid/hidd_api.cc
+++ b/system/stack/hid/hidd_api.cc
@@ -38,13 +38,13 @@
#include "hidd_int.h"
#include "hiddefs.h"
#include "internal_include/bt_target.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_psm_types.h"
#include "stack/include/bt_types.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/sdp_api.h"
#include "stack/include/sdpdefs.h"
-#include "stack/include/stack_metrics_logging.h"
#include "stack/sdp/sdp_discovery_db.h"
#include "types/raw_address.h"
@@ -83,12 +83,14 @@ tHID_STATUS HID_DevRegister(tHID_DEV_HOST_CALLBACK* host_cback) {
log::verbose("");
if (hd_cb.reg_flag) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_REGISTERED, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_REGISTERED, 1);
return HID_ERR_ALREADY_REGISTERED;
}
if (host_cback == NULL) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_HOST_CALLBACK_NULL, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_HOST_CALLBACK_NULL, 1);
return HID_ERR_INVALID_PARAM;
}
@@ -122,7 +124,7 @@ tHID_STATUS HID_DevDeregister(void) {
log::verbose("");
if (!hd_cb.reg_flag) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_DEREGISTER, 1);
return HID_ERR_NOT_REGISTERED;
}
@@ -263,9 +265,10 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
if (desc_len > HIDD_APP_DESCRIPTOR_LEN) {
log::error("descriptor length = {}, larger than max {}", desc_len, HIDD_APP_DESCRIPTOR_LEN);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
- HIDD_ERR_NOT_REGISTERED_DUE_TO_DESCRIPTOR_LENGTH,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::
+ HIDD_ERR_NOT_REGISTERED_DUE_TO_DESCRIPTOR_LENGTH,
+ 1);
return HID_ERR_NOT_REGISTERED;
};
@@ -273,9 +276,10 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
if (p_buf == NULL) {
log::error("Buffer allocation failure for size = {}", buf_len);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::
- HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::
+ HIDD_ERR_NOT_REGISTERED_DUE_TO_BUFFER_ALLOCATION,
+ 1);
return HID_ERR_NOT_REGISTERED;
}
@@ -346,8 +350,8 @@ tHID_STATUS HID_DevAddRecord(uint32_t handle, char* p_name, char* p_description,
if (!result) {
log::error("failed to complete SDP record");
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_SDP,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_SDP, 1);
return HID_ERR_NOT_REGISTERED;
}
@@ -376,7 +380,7 @@ tHID_STATUS HID_DevSendReport(uint8_t channel, uint8_t type, uint8_t id, uint16_
return hidd_conn_send_data(HID_CHANNEL_INTR, HID_TRANS_DATA, HID_PAR_REP_TYPE_INPUT, id, len,
p_data);
}
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_INVALID_PARAM_SEND_REPORT, 1);
return HID_ERR_INVALID_PARAM;
}
@@ -444,19 +448,20 @@ tHID_STATUS HID_DevUnplugDevice(const RawAddress& addr) {
******************************************************************************/
tHID_STATUS HID_DevConnect(void) {
if (!hd_cb.reg_flag) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_CONNECT, 1);
return HID_ERR_NOT_REGISTERED;
}
if (!hd_cb.device.in_use) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DEVICE_NOT_IN_USE_AT_CONNECT, 1);
return HID_ERR_INVALID_PARAM;
}
if (hd_cb.device.state != HIDD_DEV_NO_CONN) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_CONN, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_ALREADY_CONN, 1);
return HID_ERR_ALREADY_CONN;
}
@@ -474,13 +479,13 @@ tHID_STATUS HID_DevConnect(void) {
******************************************************************************/
tHID_STATUS HID_DevDisconnect(void) {
if (!hd_cb.reg_flag) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_DISCONNECT, 1);
return HID_ERR_NOT_REGISTERED;
}
if (!hd_cb.device.in_use) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DEVICE_NOT_IN_USE_AT_DISCONNECT,
1);
return HID_ERR_INVALID_PARAM;
@@ -492,10 +497,11 @@ tHID_STATUS HID_DevDisconnect(void) {
tHID_STATUS ret = hidd_conn_disconnect();
hd_cb.device.conn.conn_state = HID_CONN_STATE_UNUSED;
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_ERR_DISCONNECTING, NULL);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DISCONNECTING, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_DISCONNECTING, 1);
return ret;
}
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_CONNECTION_AT_DISCONNECT, 1);
return HID_ERR_NO_CONNECTION;
}
@@ -565,7 +571,7 @@ tHID_STATUS HID_DevGetDevice(RawAddress* addr) {
if (hd_cb.device.in_use) {
*addr = hd_cb.device.addr;
} else {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_GET_DEVICE, 1);
return HID_ERR_NOT_REGISTERED;
}
diff --git a/system/stack/hid/hidd_conn.cc b/system/stack/hid/hidd_conn.cc
index 7276af8acd..5f94c1c870 100644
--- a/system/stack/hid/hidd_conn.cc
+++ b/system/stack/hid/hidd_conn.cc
@@ -37,13 +37,13 @@
#include "hiddefs.h"
#include "internal_include/bt_target.h"
#include "l2cap_types.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/allocator.h"
#include "stack/hid/hidd_int.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_psm_types.h"
#include "stack/include/l2cap_interface.h"
#include "stack/include/l2cdefs.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"
@@ -300,7 +300,7 @@ static void hidd_l2cif_config_cfm(uint16_t cid, uint16_t /* initiator */, tL2CAP
log::warn("could not start L2CAP connection for INTR");
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_ERR_L2CAP_FAILED, NULL);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_NOT_STARTED_INCOMING, 1);
return;
} else {
@@ -577,8 +577,8 @@ tHID_STATUS hidd_conn_reg(void) {
HID_PSM_CONTROL, dev_reg_info, false /* enable_snoop */, nullptr, HID_DEV_MTU_SIZE, 0,
BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
log::error("HID Control (device) registration failed");
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_CONTROL,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_CONTROL, 1);
return HID_ERR_L2CAP_FAILED;
}
@@ -587,8 +587,8 @@ tHID_STATUS hidd_conn_reg(void) {
0, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
stack::l2cap::get_interface().L2CA_Deregister(HID_PSM_CONTROL);
log::error("HID Interrupt (device) registration failed");
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_INTERRUPT,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_INTERRUPT, 1);
return HID_ERR_L2CAP_FAILED;
}
@@ -627,14 +627,15 @@ tHID_STATUS hidd_conn_initiate(void) {
if (!p_dev->in_use) {
log::warn("no virtual cable established");
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NOT_REGISTERED_AT_INITIATE, 1);
return HID_ERR_NOT_REGISTERED;
}
if (p_dev->conn.conn_state != HID_CONN_STATE_UNUSED) {
log::warn("connection already in progress");
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONN_IN_PROCESS, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONN_IN_PROCESS, 1);
return HID_ERR_CONN_IN_PROCESS;
}
@@ -649,8 +650,8 @@ tHID_STATUS hidd_conn_initiate(void) {
HID_PSM_CONTROL, p_dev->addr, BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) == 0) {
log::warn("could not start L2CAP connection");
hd_cb.callback(hd_cb.device.addr, HID_DHOST_EVT_CLOSE, HID_ERR_L2CAP_FAILED, NULL);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_INITIATE,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_L2CAP_FAILED_INITIATE, 1);
} else {
p_dev->conn.conn_state = HID_CONN_STATE_CONNECTING_CTRL;
}
@@ -723,7 +724,7 @@ tHID_STATUS hidd_conn_send_data(uint8_t channel, uint8_t msg_type, uint8_t param
tHID_CONN* p_hcon = &hd_cb.device.conn;
if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONGESTED_AT_FLAG_CHECK, 1);
return HID_ERR_CONGESTED;
}
@@ -744,13 +745,15 @@ tHID_STATUS hidd_conn_send_data(uint8_t channel, uint8_t msg_type, uint8_t param
}
break;
default:
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_INVALID_PARAM, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_INVALID_PARAM, 1);
return HID_ERR_INVALID_PARAM;
}
p_buf = (BT_HDR*)osi_malloc(buf_size);
if (p_buf == NULL) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_RESOURCES, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_RESOURCES, 1);
return HID_ERR_NO_RESOURCES;
}
@@ -792,7 +795,7 @@ tHID_STATUS hidd_conn_send_data(uint8_t channel, uint8_t msg_type, uint8_t param
return HID_SUCCESS;
}
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_NO_CONNECTION_AT_SEND_DATA, 1);
return HID_ERR_NO_CONNECTION;
}
@@ -800,7 +803,7 @@ tHID_STATUS hidd_conn_send_data(uint8_t channel, uint8_t msg_type, uint8_t param
log::verbose("report sent");
if (stack::l2cap::get_interface().L2CA_DataWrite(cid, p_buf) == tL2CAP_DW_RESULT::FAILED) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDD_ERR_CONGESTED_AT_DATA_WRITE, 1);
return HID_ERR_CONGESTED;
}
diff --git a/system/stack/hid/hidh_api.cc b/system/stack/hid/hidh_api.cc
index 97d811ed5b..1ab5ba2a6a 100644
--- a/system/stack/hid/hidh_api.cc
+++ b/system/stack/hid/hidh_api.cc
@@ -37,6 +37,7 @@
#include "hiddefs.h"
#include "hidh_int.h"
#include "internal_include/bt_target.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
#include "sdp_api.h"
@@ -44,7 +45,6 @@
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/sdpdefs.h"
-#include "stack/include/stack_metrics_logging.h"
#include "stack/sdp/sdp_discovery_db.h"
#include "types/bluetooth/uuid.h"
#include "types/raw_address.h"
@@ -69,7 +69,8 @@ static void hidh_search_callback(const RawAddress& bd_addr, tSDP_RESULT sdp_resu
tHID_STATUS HID_HostGetSDPRecord(const RawAddress& addr, tSDP_DISCOVERY_DB* p_db, uint32_t db_len,
tHID_HOST_SDP_CALLBACK* sdp_cback) {
if (hh_cb.sdp_busy) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_SDP_BUSY, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_SDP_BUSY, 1);
return HID_ERR_SDP_BUSY;
}
@@ -87,7 +88,8 @@ tHID_STATUS HID_HostGetSDPRecord(const RawAddress& addr, tSDP_DISCOVERY_DB* p_db
return HID_SUCCESS;
} else {
log::warn("Unable to start SDP service search request peer:{}", addr);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_RESOURCES_SDP, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_RESOURCES_SDP, 1);
return HID_ERR_NO_RESOURCES;
}
}
@@ -289,12 +291,13 @@ tHID_STATUS HID_HostRegister(tHID_HOST_DEV_CALLBACK* dev_cback) {
tHID_STATUS st;
if (hh_cb.reg_flag) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_ALREADY_REGISTERED, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_ALREADY_REGISTERED, 1);
return HID_ERR_ALREADY_REGISTERED;
}
if (dev_cback == NULL) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_REGISTER, 1);
return HID_ERR_INVALID_PARAM;
}
@@ -392,7 +395,7 @@ tHID_STATUS HID_HostAddDev(const RawAddress& addr, uint16_t attr_mask, uint8_t*
}
if (i == HID_HOST_MAX_DEVICES) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_RESOURCES_ADD_DEVICE, 1);
return HID_ERR_NO_RESOURCES;
}
@@ -427,7 +430,7 @@ tHID_STATUS HID_HostRemoveDev(uint8_t dev_handle) {
}
if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_REMOVE_DEV,
1);
return HID_ERR_INVALID_PARAM;
@@ -457,13 +460,14 @@ tHID_STATUS HID_HostOpenDev(uint8_t dev_handle) {
}
if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_OPEN_DEV, 1);
return HID_ERR_INVALID_PARAM;
}
if (hh_cb.devices[dev_handle].state != HID_DEV_NO_CONN) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_ALREADY_CONN, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_ALREADY_CONN, 1);
return HID_ERR_ALREADY_CONN;
}
@@ -494,13 +498,13 @@ tHID_STATUS HID_HostWriteDev(uint8_t dev_handle, uint8_t t_type, uint8_t param,
if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
log::error("HID_ERR_INVALID_PARAM");
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_WRITE_DEV,
1);
status = HID_ERR_INVALID_PARAM;
} else if (hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED) {
log::error("HID_ERR_NO_CONNECTION dev_handle {}", dev_handle);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_CONNECTION_AT_HOST_WRITE_DEV,
1);
status = HID_ERR_NO_CONNECTION;
@@ -530,14 +534,14 @@ tHID_STATUS HID_HostCloseDev(uint8_t dev_handle) {
}
if ((dev_handle >= HID_HOST_MAX_DEVICES) || (!hh_cb.devices[dev_handle].in_use)) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_HOST_CLOSE_DEV,
1);
return HID_ERR_INVALID_PARAM;
}
if (hh_cb.devices[dev_handle].state != HID_DEV_CONNECTED) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_CONNECTION_AT_HOST_CLOSE_DEV,
1);
return HID_ERR_NO_CONNECTION;
diff --git a/system/stack/hid/hidh_conn.cc b/system/stack/hid/hidh_conn.cc
index cdc7906d16..71785478a1 100644
--- a/system/stack/hid/hidh_conn.cc
+++ b/system/stack/hid/hidh_conn.cc
@@ -39,6 +39,7 @@
#include "internal_include/bt_target.h"
#include "l2cap_types.h"
#include "l2cdefs.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/alarm.h"
#include "osi/include/allocator.h"
#include "osi/include/osi.h"
@@ -48,7 +49,6 @@
#include "stack/include/btm_client_interface.h"
#include "stack/include/btm_log_history.h"
#include "stack/include/l2cap_interface.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/bt_transport.h"
#include "types/raw_address.h"
@@ -119,7 +119,7 @@ tHID_STATUS hidh_conn_reg(void) {
HID_PSM_CONTROL, hst_reg_info, false /* enable_snoop */, nullptr, HID_HOST_MTU, 0,
BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
log::error("HID-Host Control Registration failed");
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_L2CAP_FAILED_AT_REGISTER_CONTROL,
1);
return HID_ERR_L2CAP_FAILED;
@@ -129,7 +129,7 @@ tHID_STATUS hidh_conn_reg(void) {
BTA_SEC_AUTHENTICATE | BTA_SEC_ENCRYPT)) {
stack::l2cap::get_interface().L2CA_Deregister(HID_PSM_CONTROL);
log::error("HID-Host Interrupt Registration failed");
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_L2CAP_FAILED_AT_REGISTER_INTERRUPT,
1);
return HID_ERR_L2CAP_FAILED;
@@ -549,7 +549,8 @@ static void hidh_l2cif_disconnect_ind(uint16_t l2cap_cid, bool ack_needed) {
(disc_res == HCI_ERR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED) ||
(disc_res == HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE) ||
(disc_res == HCI_ERR_REPEATED_ATTEMPTS)) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_AUTH_FAILED, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_AUTH_FAILED, 1);
hid_close_evt_reason = HID_ERR_AUTH_FAILED;
}
@@ -771,14 +772,14 @@ tHID_STATUS hidh_conn_snd_data(uint8_t dhandle, uint8_t trans_type, uint8_t para
if (!get_btm_client_interface().peer.BTM_IsAclConnectionUp(hh_cb.devices[dhandle].addr,
BT_TRANSPORT_BR_EDR)) {
osi_free(buf);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_NO_CONNECTION_AT_SEND_DATA, 1);
return HID_ERR_NO_CONNECTION;
}
if (p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) {
osi_free(buf);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONGESTED_AT_FLAG_CHECK, 1);
return HID_ERR_CONGESTED;
}
@@ -799,7 +800,7 @@ tHID_STATUS hidh_conn_snd_data(uint8_t dhandle, uint8_t trans_type, uint8_t para
buf_size = HID_INTERRUPT_BUF_SIZE;
break;
default:
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_INVALID_PARAM_AT_SEND_DATA, 1);
return HID_ERR_INVALID_PARAM;
}
@@ -860,7 +861,7 @@ tHID_STATUS hidh_conn_snd_data(uint8_t dhandle, uint8_t trans_type, uint8_t para
/* Send the buffer through L2CAP */
if ((p_hcon->conn_flags & HID_CONN_FLAGS_CONGESTED) ||
(stack::l2cap::get_interface().L2CA_DataWrite(cid, p_buf) == tL2CAP_DW_RESULT::FAILED)) {
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONGESTED_AT_SEND_DATA, 1);
return HID_ERR_CONGESTED;
}
@@ -889,7 +890,8 @@ tHID_STATUS hidh_conn_initiate(uint8_t dhandle) {
tHID_HOST_DEV_CTB* p_dev = &hh_cb.devices[dhandle];
if (p_dev->conn.conn_state != HID_CONN_STATE_UNUSED) {
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONN_IN_PROCESS, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_CONN_IN_PROCESS, 1);
return HID_ERR_CONN_IN_PROCESS;
}
@@ -908,7 +910,7 @@ tHID_STATUS hidh_conn_initiate(uint8_t dhandle) {
log::warn("HID-Host Originate failed");
hh_cb.callback(dhandle, hh_cb.devices[dhandle].addr, HID_HDEV_EVT_CLOSE, HID_ERR_L2CAP_FAILED,
NULL);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::HIDH_ERR_L2CAP_FAILED_AT_INITIATE, 1);
} else {
/* Transition to the next appropriate state, waiting for connection confirm
diff --git a/system/stack/include/l2cap_interface.h b/system/stack/include/l2cap_interface.h
index b1551d2a80..19f85d4d2e 100644
--- a/system/stack/include/l2cap_interface.h
+++ b/system/stack/include/l2cap_interface.h
@@ -871,21 +871,6 @@ public:
virtual void L2CA_SetEcosystemBaseInterval(uint32_t base_interval) = 0;
/*******************************************************************************
- *
- * Function L2CA_SetDefaultSubrate
- *
- * Description BLE Set Default Subrate.
- *
- * Parameters: Subrate parameters
- *
- * Return value: void
- *
- ******************************************************************************/
- virtual void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max,
- uint16_t max_latency, uint16_t cont_num,
- uint16_t timeout) = 0;
-
- /*******************************************************************************
**
** Function L2CA_SetMediaStreamChannel
**
diff --git a/system/stack/include/stack_metrics_logging.h b/system/stack/include/stack_metrics_logging.h
deleted file mode 100644
index 9a0a80baa4..0000000000
--- a/system/stack/include/stack_metrics_logging.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
-
-#include <cstdint>
-
-#include "hci/address.h"
-#include "hci/hci_packets.h"
-#include "types/raw_address.h"
-
-void 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);
-
-void 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);
-
-void log_smp_pairing_event(const RawAddress& address, uint16_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason);
-
-void log_sdp_attribute(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value);
-
-void 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);
-
-void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t value);
-
-void log_hfp_audio_packet_loss_stats(const RawAddress& address, int num_decoded_frames,
- double packet_loss_ratio, uint16_t codec_type);
-
-void log_mmc_transcode_rtt_stats(int maximum_rtt, double mean_rtt, int num_requests,
- int codec_type);
-
-void log_le_pairing_fail(const RawAddress& raw_address, uint8_t failure_reason, bool is_outgoing);
-
-void log_le_connection_status(bluetooth::hci::Address address, bool is_connect,
- bluetooth::hci::ErrorCode reason);
-
-void log_le_device_in_accept_list(bluetooth::hci::Address address, bool is_add);
-
-void log_le_connection_lifecycle(bluetooth::hci::Address address, bool is_connect, bool is_direct);
-
-void log_le_connection_completion(bluetooth::hci::Address address, bluetooth::hci::ErrorCode reason,
- bool is_locally_initiated);
diff --git a/system/stack/l2cap/internal/l2c_api.h b/system/stack/l2cap/internal/l2c_api.h
index dd1dbf52e6..989eccf50e 100644
--- a/system/stack/l2cap/internal/l2c_api.h
+++ b/system/stack/l2cap/internal/l2c_api.h
@@ -719,20 +719,6 @@ void L2CA_SetEcosystemBaseInterval(uint32_t base_interval);
/*******************************************************************************
*
- * Function L2CA_SetDefaultSubrate
- *
- * Description BLE Set Default Subrate.
- *
- * Parameters: Subrate parameters
- *
- * Return value: void
- *
- ******************************************************************************/
-void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t timeout);
-
-/*******************************************************************************
- *
* Function L2CA_SubrateRequest
*
* Description BLE Subrate request.
diff --git a/system/stack/l2cap/l2c_api.h b/system/stack/l2cap/l2c_api.h
index 1ff09ffaf5..f9eab67d55 100644
--- a/system/stack/l2cap/l2c_api.h
+++ b/system/stack/l2cap/l2c_api.h
@@ -73,8 +73,6 @@ public:
uint8_t* p_chnl_mask) override;
[[nodiscard]] bool L2CA_SetAclPriority(const RawAddress& bd_addr,
tL2CAP_PRIORITY priority) override;
- void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t timeout) override;
void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interval,
uint16_t floor_interval) override;
void L2CA_SetEcosystemBaseInterval(uint32_t base_interval) override;
diff --git a/system/stack/l2cap/l2c_ble.cc b/system/stack/l2cap/l2c_ble.cc
index 49dca969dc..d964271002 100644
--- a/system/stack/l2cap/l2c_ble.cc
+++ b/system/stack/l2cap/l2c_ble.cc
@@ -1443,7 +1443,7 @@ tL2CAP_LE_RESULT_CODE l2ble_sec_access_req(const RawAddress& bd_addr, uint16_t p
* constraints. For example, when there is at least one Hearing Aid device
* bonded, the minimum interval is raised. On return, min_interval and
* max_interval are updated. */
-void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interval,
+void L2CA_AdjustConnectionIntervals(uint16_t* /* min_interval */, uint16_t* max_interval,
uint16_t floor_interval) {
// Allow for customization by systemprops for mainline
uint16_t phone_min_interval = floor_interval;
@@ -1462,13 +1462,6 @@ void L2CA_AdjustConnectionIntervals(uint16_t* min_interval, uint16_t* max_interv
log::verbose("Have Hearing Aids. Min. interval is set to {}", phone_min_interval);
}
- if (!com::android::bluetooth::flags::l2cap_le_do_not_adjust_min_interval() &&
- *min_interval < phone_min_interval) {
- log::verbose("requested min_interval={} too small. Set to {}", *min_interval,
- phone_min_interval);
- *min_interval = phone_min_interval;
- }
-
// While this could result in connection parameters that fall
// outside fo the range requested, this will allow the connection
// to remain established.
diff --git a/system/stack/l2cap/l2c_ble_conn_params.cc b/system/stack/l2cap/l2c_ble_conn_params.cc
index 49eeb06155..392b1f5a74 100644
--- a/system/stack/l2cap/l2c_ble_conn_params.cc
+++ b/system/stack/l2cap/l2c_ble_conn_params.cc
@@ -510,26 +510,6 @@ static void l2cble_start_subrate_change(tL2C_LCB* p_lcb) {
/*******************************************************************************
*
- * Function L2CA_SetDefaultSubrate
- *
- * Description BLE Set Default Subrate
- *
- * Parameters: Subrate parameters
- *
- * Return value: void
- *
- ******************************************************************************/
-void L2CA_SetDefaultSubrate(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t timeout) {
- log::verbose("subrate_min={}, subrate_max={}, max_latency={}, cont_num={}, timeout={}",
- subrate_min, subrate_max, max_latency, cont_num, timeout);
-
- bluetooth::shim::ACL_LeSetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num,
- timeout);
-}
-
-/*******************************************************************************
- *
* Function L2CA_SubrateRequest
*
* Description BLE Subrate request.
diff --git a/system/stack/l2cap/l2cap_api.cc b/system/stack/l2cap/l2cap_api.cc
index 0752c995c0..e9ccaeaf2a 100644
--- a/system/stack/l2cap/l2cap_api.cc
+++ b/system/stack/l2cap/l2cap_api.cc
@@ -234,13 +234,6 @@ void bluetooth::stack::l2cap::Impl::L2CA_SetEcosystemBaseInterval(uint32_t base_
return ::L2CA_IsLinkEstablished(bd_addr, transport);
}
-void bluetooth::stack::l2cap::Impl::L2CA_SetDefaultSubrate(uint16_t subrate_min,
- uint16_t subrate_max,
- uint16_t max_latency, uint16_t cont_num,
- uint16_t timeout) {
- ::L2CA_SetDefaultSubrate(subrate_min, subrate_max, max_latency, cont_num, timeout);
-}
-
[[nodiscard]] bool bluetooth::stack::l2cap::Impl::L2CA_SubrateRequest(
const RawAddress& rem_bda, uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
uint16_t cont_num, uint16_t timeout) {
diff --git a/system/stack/metrics/stack_metrics_logging.cc b/system/stack/metrics/stack_metrics_logging.cc
deleted file mode 100644
index 398a72ce33..0000000000
--- a/system/stack/metrics/stack_metrics_logging.cc
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "stack/include/stack_metrics_logging.h"
-
-#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
-
-#include "common/metrics.h"
-#include "main/shim/metrics_api.h"
-#include "main/shim/shim.h"
-#include "types/raw_address.h"
-
-void 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) {
- bluetooth::shim::LogMetricClassicPairingEvent(address, handle, hci_cmd, hci_event, cmd_status,
- reason_code, event_value);
-}
-
-void 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) {
- bluetooth::shim::LogMetricLinkLayerConnectionEvent(address, connection_handle, direction,
- link_type, hci_cmd, hci_event, hci_ble_event,
- cmd_status, reason_code);
-}
-
-void log_smp_pairing_event(const RawAddress& address, uint16_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason) {
- bluetooth::shim::LogMetricSmpPairingEvent(address, smp_cmd, direction, smp_fail_reason);
-}
-
-void log_sdp_attribute(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value) {
- bluetooth::shim::LogMetricSdpAttribute(address, protocol_uuid, attribute_id, attribute_size,
- attribute_value);
-}
-
-void 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) {
- bluetooth::shim::LogMetricManufacturerInfo(address, address_type, source_type, source_name,
- manufacturer, model, hardware_version,
- software_version);
-}
-
-void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t value) {
- bluetooth::shim::CountCounterMetrics(key, value);
-}
-
-void log_hfp_audio_packet_loss_stats(const RawAddress& address, int num_decoded_frames,
- double packet_loss_ratio, uint16_t codec_type) {
- bluetooth::shim::LogMetricHfpPacketLossStats(address, num_decoded_frames, packet_loss_ratio,
- codec_type);
-}
-
-void log_mmc_transcode_rtt_stats(int maximum_rtt, double mean_rtt, int num_requests,
- int codec_type) {
- bluetooth::shim::LogMetricMmcTranscodeRttStats(maximum_rtt, mean_rtt, num_requests, codec_type);
-}
-
-void log_le_pairing_fail(const RawAddress& raw_address, uint8_t failure_reason, bool is_outgoing) {
- bluetooth::shim::LogMetricLePairingFail(raw_address, failure_reason, is_outgoing);
-}
-
-void log_le_connection_status(bluetooth::hci::Address address, bool is_connect,
- bluetooth::hci::ErrorCode reason) {
- bluetooth::shim::LogMetricLeConnectionStatus(address, is_connect, reason);
-}
-
-void log_le_device_in_accept_list(bluetooth::hci::Address address, bool is_add) {
- bluetooth::shim::LogMetricLeDeviceInAcceptList(address, is_add);
-}
-
-void log_le_connection_lifecycle(bluetooth::hci::Address address, bool is_connect, bool is_direct) {
- bluetooth::shim::LogMetricLeConnectionLifecycle(address, is_connect, is_direct);
-}
-
-void log_le_connection_completion(bluetooth::hci::Address address, bluetooth::hci::ErrorCode reason,
- bool is_locally_initiated) {
- bluetooth::shim::LogMetricLeConnectionCompletion(address, reason, is_locally_initiated);
-}
diff --git a/system/stack/mmc/OWNERS b/system/stack/mmc/OWNERS
deleted file mode 100644
index a823e6e1dd..0000000000
--- a/system/stack/mmc/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /OWNERS_chromeos
diff --git a/system/stack/mmc/metrics/mmc_rtt_logger.cc b/system/stack/mmc/metrics/mmc_rtt_logger.cc
index 761d825b44..c95566f0cb 100644
--- a/system/stack/mmc/metrics/mmc_rtt_logger.cc
+++ b/system/stack/mmc/metrics/mmc_rtt_logger.cc
@@ -20,7 +20,7 @@
#include <cmath>
#include <string>
-#include "stack/include/stack_metrics_logging.h"
+#include "main/shim/metrics_api.h"
namespace mmc {
@@ -43,7 +43,8 @@ void MmcRttLogger::UploadTranscodeRttStatics() {
if (num_requests_ == 0) {
return;
}
- log_mmc_transcode_rtt_stats(maximum_rtt_, rtt_sum_ / num_requests_, num_requests_, codec_type_);
+ bluetooth::shim::LogMetricMmcTranscodeRttStats(maximum_rtt_, rtt_sum_ / num_requests_,
+ num_requests_, codec_type_);
num_requests_ = 0;
rtt_sum_ = 0;
maximum_rtt_ = 0;
diff --git a/system/stack/rfcomm/port_rfc.cc b/system/stack/rfcomm/port_rfc.cc
index 860fdf0450..c1518665d9 100644
--- a/system/stack/rfcomm/port_rfc.cc
+++ b/system/stack/rfcomm/port_rfc.cc
@@ -36,12 +36,12 @@
#include "internal_include/bt_target.h"
#include "internal_include/bt_trace.h"
#include "main/shim/entry.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/allocator.h"
#include "osi/include/mutex.h"
#include "stack/include/bt_hdr.h"
#include "stack/include/bt_uuid16.h"
#include "stack/include/rfc_metrics.h"
-#include "stack/include/stack_metrics_logging.h"
#include "stack/l2cap/l2c_int.h"
#include "stack/rfcomm/port_int.h"
#include "stack/rfcomm/rfc_int.h"
@@ -186,7 +186,8 @@ void port_start_close(tPORT* p_port) {
* clear tPort */
if (p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_CLOSED, p_port->handle);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_CLOSE, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_CLOSE, 1);
}
port_release_port(p_port);
@@ -230,7 +231,7 @@ void PORT_StartCnf(tRFC_MCB* p_mcb, uint16_t result) {
if (p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_START_FAILED, p_port->handle);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_CNF_FAILED, 1);
}
port_release_port(p_port);
@@ -457,14 +458,14 @@ void PORT_DlcEstablishInd(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu) {
if (p_port->rfc_cfg_info.data_path != BTSOCK_DATA_PATH_HARDWARE_OFFLOAD &&
p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND, 1);
}
} else {
if (p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND, 1);
}
}
@@ -493,7 +494,8 @@ void PORT_DlcEstablishCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint16_t
if (result != RFCOMM_SUCCESS) {
log::warn("Unable to establish configuration dlci:{} result:{}", dlci, result);
port_rfc_closed(p_port, PORT_START_FAILED);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_FAILED, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_START_FAILED, 1);
return;
}
@@ -513,14 +515,14 @@ void PORT_DlcEstablishCnf(tRFC_MCB* p_mcb, uint8_t dlci, uint16_t mtu, uint16_t
if (p_port->rfc_cfg_info.data_path != BTSOCK_DATA_PATH_HARDWARE_OFFLOAD &&
p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF, 1);
}
} else {
if (p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF,
- 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF, 1);
}
}
@@ -590,7 +592,8 @@ void PORT_PortNegCnf(tRFC_MCB* p_mcb, uint8_t dlci, PortSettings* /* p_settings
RFCOMM_DlcReleaseReq(p_mcb, p_port->dlci);
port_rfc_closed(p_port, PORT_PORT_NEG_FAILED);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_NEG_FAILED, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_NEG_FAILED, 1);
return;
}
@@ -661,7 +664,7 @@ void PORT_ControlInd(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_CTRL* p_pars) {
if (p_port->rfc_cfg_info.data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) {
if (p_port->port_ctrl == PORT_CTRL_SETUP_COMPLETED && p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_IND, 1);
}
}
@@ -708,7 +711,7 @@ void PORT_ControlCnf(tRFC_MCB* p_mcb, uint8_t dlci, tPORT_CTRL* /* p_pars */) {
if (p_port->rfc_cfg_info.data_path == BTSOCK_DATA_PATH_HARDWARE_OFFLOAD) {
if (p_port->port_ctrl == PORT_CTRL_SETUP_COMPLETED && p_port->p_mgmt_callback) {
p_port->p_mgmt_callback(PORT_SUCCESS, p_port->handle);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::RFCOMM_CONNECTION_SUCCESS_CNF, 1);
}
}
@@ -767,7 +770,8 @@ void PORT_DlcReleaseInd(tRFC_MCB* p_mcb, uint8_t dlci) {
return;
}
port_rfc_closed(p_port, PORT_CLOSED);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_CLOSED, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_CLOSED, 1);
}
/*******************************************************************************
@@ -788,7 +792,7 @@ void PORT_CloseInd(tRFC_MCB* p_mcb) {
for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) {
if (p_port->rfc.p_mcb == p_mcb) {
port_rfc_closed(p_port, PORT_PEER_CONNECTION_FAILED);
- log_counter_metrics(
+ bluetooth::shim::CountCounterMetrics(
android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_PEER_CONNECTION_FAILED, 1);
}
}
@@ -813,7 +817,8 @@ void PORT_TimeOutCloseMux(tRFC_MCB* p_mcb) {
for (i = 0; i < MAX_RFC_PORTS; i++, p_port++) {
if (p_port->rfc.p_mcb == p_mcb) {
port_rfc_closed(p_port, PORT_PEER_TIMEOUT);
- log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_PEER_TIMEOUT, 1);
+ bluetooth::shim::CountCounterMetrics(
+ android::bluetooth::CodePathCounterKeyEnum::RFCOMM_PORT_PEER_TIMEOUT, 1);
}
}
}
diff --git a/system/stack/sdp/sdp_utils.cc b/system/stack/sdp/sdp_utils.cc
index 2fb4f4622b..324f4dd06e 100644
--- a/system/stack/sdp/sdp_utils.cc
+++ b/system/stack/sdp/sdp_utils.cc
@@ -39,6 +39,7 @@
#include "device/include/interop.h"
#include "internal_include/bt_target.h"
#include "internal_include/bt_trace.h"
+#include "main/shim/metrics_api.h"
#include "osi/include/allocator.h"
#include "osi/include/properties.h"
#include "stack/include/avrc_api.h"
@@ -50,7 +51,6 @@
#include "stack/include/btm_sec_api_types.h"
#include "stack/include/l2cap_interface.h"
#include "stack/include/sdpdefs.h"
-#include "stack/include/stack_metrics_logging.h"
#include "stack/sdp/internal/sdp_api.h"
#include "stack/sdp/sdpint.h"
#include "storage/config_keys.h"
@@ -184,15 +184,15 @@ void sdpu_log_attribute_metrics(const RawAddress& bda, tSDP_DISCOVERY_DB* p_db)
}
// Log the existence of a profile role
// This can be different from Bluetooth Profile Descriptor List
- log_sdp_attribute(bda, service_uuid, 0, 0, nullptr);
+ bluetooth::shim::LogMetricSdpAttribute(bda, service_uuid, 0, 0, nullptr);
// Log profile version from Bluetooth Profile Descriptor List
auto uuid_version_array = sdpu_find_profile_version(p_rec);
for (const auto& uuid_version_pair : uuid_version_array) {
uint16_t profile_uuid = uuid_version_pair.first;
uint16_t version = uuid_version_pair.second;
auto version_array = to_little_endian_array(version);
- log_sdp_attribute(bda, profile_uuid, ATTR_ID_BT_PROFILE_DESC_LIST, version_array.size(),
- version_array.data());
+ bluetooth::shim::LogMetricSdpAttribute(bda, profile_uuid, ATTR_ID_BT_PROFILE_DESC_LIST,
+ version_array.size(), version_array.data());
}
// Log protocol version from Protocol Descriptor List
uint16_t protocol_uuid = 0;
@@ -217,8 +217,8 @@ void sdpu_log_attribute_metrics(const RawAddress& bda, tSDP_DISCOVERY_DB* p_db)
if (protocol_elements.num_params >= 1) {
uint16_t version = protocol_elements.params[0];
auto version_array = to_little_endian_array(version);
- log_sdp_attribute(bda, protocol_uuid, ATTR_ID_PROTOCOL_DESC_LIST, version_array.size(),
- version_array.data());
+ bluetooth::shim::LogMetricSdpAttribute(bda, protocol_uuid, ATTR_ID_PROTOCOL_DESC_LIST,
+ version_array.size(), version_array.data());
}
}
}
@@ -238,8 +238,8 @@ void sdpu_log_attribute_metrics(const RawAddress& bda, tSDP_DISCOVERY_DB* p_db)
}
uint16_t supported_features = p_attr->attr_value.v.u16;
auto version_array = to_little_endian_array(supported_features);
- log_sdp_attribute(bda, service_uuid, ATTR_ID_SUPPORTED_FEATURES, version_array.size(),
- version_array.data());
+ bluetooth::shim::LogMetricSdpAttribute(bda, service_uuid, ATTR_ID_SUPPORTED_FEATURES,
+ version_array.size(), version_array.data());
break;
}
case UUID_SERVCLASS_MESSAGE_NOTIFICATION:
@@ -251,8 +251,8 @@ void sdpu_log_attribute_metrics(const RawAddress& bda, tSDP_DISCOVERY_DB* p_db)
}
uint32_t map_supported_features = p_attr->attr_value.v.u32;
auto features_array = to_little_endian_array(map_supported_features);
- log_sdp_attribute(bda, service_uuid, ATTR_ID_MAP_SUPPORTED_FEATURES, features_array.size(),
- features_array.data());
+ bluetooth::shim::LogMetricSdpAttribute(bda, service_uuid, ATTR_ID_MAP_SUPPORTED_FEATURES,
+ features_array.size(), features_array.data());
break;
}
case UUID_SERVCLASS_PBAP_PCE:
@@ -264,8 +264,8 @@ void sdpu_log_attribute_metrics(const RawAddress& bda, tSDP_DISCOVERY_DB* p_db)
}
uint32_t pbap_supported_features = p_attr->attr_value.v.u32;
auto features_array = to_little_endian_array(pbap_supported_features);
- log_sdp_attribute(bda, service_uuid, ATTR_ID_PBAP_SUPPORTED_FEATURES, features_array.size(),
- features_array.data());
+ bluetooth::shim::LogMetricSdpAttribute(bda, service_uuid, ATTR_ID_PBAP_SUPPORTED_FEATURES,
+ features_array.size(), features_array.data());
break;
}
}
@@ -278,15 +278,17 @@ void sdpu_log_attribute_metrics(const RawAddress& bda, tSDP_DISCOVERY_DB* p_db)
tSDP_DI_GET_RECORD di_record = {};
if (SDP_GetDiRecord(1, &di_record, p_db) == tSDP_STATUS::SDP_SUCCESS) {
auto version_array = to_little_endian_array(di_record.spec_id);
- log_sdp_attribute(bda, UUID_SERVCLASS_PNP_INFORMATION, ATTR_ID_SPECIFICATION_ID,
- version_array.size(), version_array.data());
+ bluetooth::shim::LogMetricSdpAttribute(bda, UUID_SERVCLASS_PNP_INFORMATION,
+ ATTR_ID_SPECIFICATION_ID, version_array.size(),
+ version_array.data());
std::stringstream ss;
// [N - native]::SDP::[DIP - Device ID Profile]
ss << "N:SDP::DIP::" << loghex(di_record.rec.vendor_id_source);
- log_manufacturer_info(bda, android::bluetooth::AddressTypeEnum::ADDRESS_TYPE_PUBLIC,
- android::bluetooth::DeviceInfoSrcEnum::DEVICE_INFO_INTERNAL, ss.str(),
- loghex(di_record.rec.vendor), loghex(di_record.rec.product),
- loghex(di_record.rec.version), "");
+ bluetooth::shim::LogMetricManufacturerInfo(
+ bda, android::bluetooth::AddressTypeEnum::ADDRESS_TYPE_PUBLIC,
+ android::bluetooth::DeviceInfoSrcEnum::DEVICE_INFO_INTERNAL, ss.str(),
+ loghex(di_record.rec.vendor), loghex(di_record.rec.product),
+ loghex(di_record.rec.version), "");
std::string bda_string = bda.ToString();
// write manufacturer, model, HW version to config
diff --git a/system/stack/smp/smp_l2c.cc b/system/stack/smp/smp_l2c.cc
index 219cb723f7..69591b10e5 100644
--- a/system/stack/smp/smp_l2c.cc
+++ b/system/stack/smp/smp_l2c.cc
@@ -263,13 +263,6 @@ static void smp_br_connect_callback(uint16_t /* channel */, const RawAddress& bd
log::info("BDA:{} pairing_bda:{}, connected:{}", bd_addr, p_cb->pairing_bda, connected);
if (bd_addr != p_cb->pairing_bda) {
- if (!com::android::bluetooth::flags::smp_state_machine_stuck_after_disconnection_fix()) {
- log::info(
- "If your pairing failed, get a build with "
- "smp_state_machine_stuck_after_disconnection_fix and try again :)");
- return;
- }
-
tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
/* When pairing was initiated to RPA, and connection was on LE transport first using RPA, then
* we must check record pseudo address, it might be same device */
diff --git a/system/stack/smp/smp_utils.cc b/system/stack/smp/smp_utils.cc
index e5aefe3c6a..9be3de7db1 100644
--- a/system/stack/smp/smp_utils.cc
+++ b/system/stack/smp/smp_utils.cc
@@ -35,6 +35,7 @@
#include "internal_include/stack_config.h"
#include "main/shim/entry.h"
#include "main/shim/helpers.h"
+#include "main/shim/metrics_api.h"
#include "metrics/bluetooth_event.h"
#include "osi/include/allocator.h"
#include "p_256_ecc_pp.h"
@@ -51,7 +52,6 @@
#include "stack/include/l2cap_interface.h"
#include "stack/include/l2cdefs.h"
#include "stack/include/smp_status.h"
-#include "stack/include/stack_metrics_logging.h"
#include "types/raw_address.h"
#define SMP_PAIRING_REQ_SIZE 7
@@ -320,7 +320,7 @@ void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing, const uint8_t*
uint8_t failure_reason = 0;
if (raw_cmd == SMP_OPCODE_PAIRING_FAILED && buf_len >= 1) {
STREAM_TO_UINT8(failure_reason, p_buf);
- log_le_pairing_fail(bd_addr, failure_reason, is_outgoing);
+ bluetooth::shim::LogMetricLePairingFail(bd_addr, failure_reason, is_outgoing);
}
if (smp_cb.is_pair_cancel) {
failure_reason = SMP_USER_CANCELLED; // Tracking pairing cancellations
@@ -330,7 +330,8 @@ void smp_log_metrics(const RawAddress& bd_addr, bool is_outgoing, const uint8_t*
android::bluetooth::DirectionEnum direction =
is_outgoing ? android::bluetooth::DirectionEnum::DIRECTION_OUTGOING
: android::bluetooth::DirectionEnum::DIRECTION_INCOMING;
- log_smp_pairing_event(bd_addr, metric_cmd, direction, static_cast<uint16_t>(failure_reason));
+ bluetooth::shim::LogMetricSmpPairingEvent(bd_addr, metric_cmd, direction,
+ static_cast<uint16_t>(failure_reason));
}
/*******************************************************************************
@@ -1011,7 +1012,8 @@ void smp_proc_pairing_cmpl(tSMP_CB* p_cb) {
if (metric_status > SMP_MAX_FAIL_RSN_PER_SPEC) {
metric_status |= SMP_METRIC_STATUS_INTERNAL_FLAG;
}
- log_smp_pairing_event(p_cb->pairing_bda, metric_cmd, direction, metric_status);
+ bluetooth::shim::LogMetricSmpPairingEvent(p_cb->pairing_bda, metric_cmd, direction,
+ metric_status);
}
if (p_cb->status == SMP_SUCCESS && p_cb->smp_over_br) {
diff --git a/system/stack/test/btm/stack_btm_power_mode_test.cc b/system/stack/test/btm/stack_btm_power_mode_test.cc
index a3376d8649..ad7b27a71a 100644
--- a/system/stack/test/btm/stack_btm_power_mode_test.cc
+++ b/system/stack/test/btm/stack_btm_power_mode_test.cc
@@ -49,8 +49,10 @@ std::deque<power_mode_callback> power_mode_callback_queue;
class StackBtmPowerMode : public testing::Test {
protected:
void SetUp() override {
- ON_CALL(controller_, SupportsSniffMode).WillByDefault(Return(true));
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsSniffMode)
+ .WillByDefault(Return(true));
power_mode_callback_queue.clear();
reset_mock_function_count_map();
ASSERT_EQ(tBTM_STATUS::BTM_SUCCESS,
@@ -71,10 +73,9 @@ protected:
BTM_PmRegister(BTM_PM_DEREG, &pm_id_,
[](const RawAddress& /* p_bda */, tBTM_PM_STATUS /* status */,
uint16_t /* value */, tHCI_STATUS /* hci_status */) {}));
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
uint8_t pm_id_{0};
};
diff --git a/system/stack/test/btm/stack_btm_sec_test.cc b/system/stack/test/btm/stack_btm_sec_test.cc
index 58317afc29..62226e2750 100644
--- a/system/stack/test/btm/stack_btm_sec_test.cc
+++ b/system/stack/test/btm/stack_btm_sec_test.cc
@@ -69,7 +69,8 @@ protected:
down_thread_ =
new bluetooth::os::Thread("down_thread", bluetooth::os::Thread::Priority::NORMAL);
down_handler_ = new bluetooth::os::Handler(down_thread_);
- bluetooth::hci::testing::mock_hci_layer_ = &mock_hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
bluetooth::hci::testing::mock_gd_shim_handler_ = up_handler_;
}
void TearDown() override {
@@ -79,10 +80,10 @@ protected:
down_handler_->Clear();
delete down_handler_;
delete down_thread_;
+ bluetooth::hci::testing::mock_hci_layer_.reset();
StackBtmSecTest::TearDown();
}
bluetooth::common::BidiQueue<bluetooth::hci::ScoView, bluetooth::hci::ScoBuilder> sco_queue_{10};
- bluetooth::hci::testing::MockHciLayer mock_hci_;
bluetooth::os::Thread* up_thread_;
bluetooth::os::Handler* up_handler_;
bluetooth::os::Thread* down_thread_;
diff --git a/system/stack/test/btm/stack_btm_test.cc b/system/stack/test/btm/stack_btm_test.cc
index 7471d4faca..2341b21677 100644
--- a/system/stack/test/btm/stack_btm_test.cc
+++ b/system/stack/test/btm/stack_btm_test.cc
@@ -63,13 +63,13 @@ public:
protected:
void SetUp() override {
BtmWithMocksTest::SetUp();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
}
void TearDown() override {
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
BtmWithMocksTest::TearDown();
}
- bluetooth::hci::testing::MockControllerInterface controller_;
};
class StackBtmWithQueuesTest : public StackBtmTest {
@@ -82,11 +82,12 @@ protected:
down_thread_ =
new bluetooth::os::Thread("down_thread", bluetooth::os::Thread::Priority::NORMAL);
down_handler_ = new bluetooth::os::Handler(down_thread_);
- bluetooth::hci::testing::mock_hci_layer_ = &mock_hci_;
+ bluetooth::hci::testing::mock_hci_layer_ =
+ std::make_unique<bluetooth::hci::testing::MockHciLayer>();
bluetooth::hci::testing::mock_gd_shim_handler_ = up_handler_;
bluetooth::legacy::hci::testing::SetMock(legacy_hci_mock_);
- EXPECT_CALL(mock_hci_, RegisterForScoConnectionRequests(_));
- EXPECT_CALL(mock_hci_, RegisterForDisconnects(_));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, RegisterForScoConnectionRequests(_));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, RegisterForDisconnects(_));
}
void TearDown() override {
up_handler_->Clear();
@@ -95,10 +96,10 @@ protected:
down_handler_->Clear();
delete down_handler_;
delete down_thread_;
+ bluetooth::hci::testing::mock_hci_layer_.release();
StackBtmTest::TearDown();
}
bluetooth::common::BidiQueue<bluetooth::hci::ScoView, bluetooth::hci::ScoBuilder> sco_queue_{10};
- bluetooth::hci::testing::MockHciLayer mock_hci_;
bluetooth::legacy::hci::testing::MockInterface legacy_hci_mock_;
bluetooth::os::Thread* up_thread_;
bluetooth::os::Handler* up_handler_;
@@ -111,7 +112,8 @@ public:
protected:
void SetUp() override {
StackBtmWithQueuesTest::SetUp();
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
btm_cb.Init();
btm_sec_cb.Init(BTM_SEC_MODE_SC);
}
@@ -123,7 +125,8 @@ protected:
};
TEST_F(StackBtmWithQueuesTest, GlobalLifecycle) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
get_btm_client_interface().lifecycle.btm_free();
}
@@ -134,20 +137,23 @@ TEST_F(StackBtmTest, DynamicLifecycle) {
}
TEST_F(StackBtmWithQueuesTest, InitFree) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
btm_cb.Init();
btm_cb.Free();
}
TEST_F(StackBtmWithQueuesTest, tSCO_CB) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
tSCO_CB* p_sco = &btm_cb.sco_cb;
p_sco->Init();
p_sco->Free();
}
TEST_F(StackBtmWithQueuesTest, InformClientOnConnectionSuccess) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
@@ -159,7 +165,8 @@ TEST_F(StackBtmWithQueuesTest, InformClientOnConnectionSuccess) {
}
TEST_F(StackBtmWithQueuesTest, NoInformClientOnConnectionFail) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
RawAddress bda({0x11, 0x22, 0x33, 0x44, 0x55, 0x66});
@@ -171,7 +178,8 @@ TEST_F(StackBtmWithQueuesTest, NoInformClientOnConnectionFail) {
}
TEST_F(StackBtmWithQueuesTest, default_packet_type) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
btm_cb.acl_cb_.SetDefaultPacketTypeMask(0x4321);
@@ -181,7 +189,8 @@ TEST_F(StackBtmWithQueuesTest, default_packet_type) {
}
TEST_F(StackBtmWithQueuesTest, change_packet_type) {
- EXPECT_CALL(mock_hci_, GetScoQueueEnd()).WillOnce(Return(sco_queue_.GetUpEnd()));
+ EXPECT_CALL(*bluetooth::hci::testing::mock_hci_layer_, GetScoQueueEnd())
+ .WillOnce(Return(sco_queue_.GetUpEnd()));
get_btm_client_interface().lifecycle.btm_init();
uint16_t handle = 0x123;
diff --git a/system/stack/test/btm_iso_test.cc b/system/stack/test/btm_iso_test.cc
index 40453f703d..b44f6fe094 100644
--- a/system/stack/test/btm_iso_test.cc
+++ b/system/stack/test/btm_iso_test.cc
@@ -134,7 +134,8 @@ protected:
bluetooth::shim::SetMockIsoInterface(&iso_interface_);
hcic::SetMockHcicInterface(&hcic_interface_);
bluetooth::shim::testing::hci_layer_set_interface(&bluetooth::shim::interface);
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
big_callbacks_.reset(new MockBigCallbacks());
cig_callbacks_.reset(new MockCigCallbacks());
@@ -142,7 +143,8 @@ protected:
iso_sizes_.total_num_le_packets_ = 6;
iso_sizes_.le_data_packet_length_ = 1024;
- ON_CALL(controller_, GetControllerIsoBufferSize()).WillByDefault(Return(iso_sizes_));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetControllerIsoBufferSize())
+ .WillByDefault(Return(iso_sizes_));
InitIsoManager();
}
@@ -156,7 +158,7 @@ protected:
bluetooth::shim::SetMockIsoInterface(nullptr);
hcic::SetMockHcicInterface(nullptr);
bluetooth::shim::testing::hci_layer_set_interface(nullptr);
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
virtual void InitIsoManager() {
@@ -312,7 +314,6 @@ protected:
IsoManager* manager_instance_;
bluetooth::shim::MockIsoInterface iso_interface_;
hcic::MockHcicInterface hcic_interface_;
- bluetooth::hci::testing::MockControllerInterface controller_;
bluetooth::hci::LeBufferSize iso_sizes_;
std::unique_ptr<MockBigCallbacks> big_callbacks_;
@@ -2207,7 +2208,8 @@ TEST_F(IsoManagerTest, SendIsoDataBigValid) {
}
TEST_F(IsoManagerTest, SendIsoDataNoCredits) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
std::vector<uint8_t> data_vec(108, 0);
// Check on CIG
@@ -2254,7 +2256,8 @@ TEST_F(IsoManagerTest, SendIsoDataNoCredits) {
}
TEST_F(IsoManagerTest, SendIsoDataCreditsReturned) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
std::vector<uint8_t> data_vec(108, 0);
// Check on CIG
@@ -2323,7 +2326,8 @@ TEST_F(IsoManagerTest, SendIsoDataCreditsReturned) {
}
TEST_F(IsoManagerTest, SendIsoDataCreditsReturnedByDisconnection) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
std::vector<uint8_t> data_vec(108, 0);
// Check on CIG
@@ -2542,7 +2546,8 @@ TEST_F(IsoManagerDeathTestNoCleanup, HandleLateArivingEventHandleDisconnect) {
* is already stopped.
*/
TEST_F(IsoManagerDeathTestNoCleanup, HandleLateArivingEventHandleNumComplDataPkts) {
- uint8_t num_buffers = controller_.GetControllerIsoBufferSize().total_num_le_packets_;
+ uint8_t num_buffers = bluetooth::hci::testing::mock_controller_->GetControllerIsoBufferSize()
+ .total_num_le_packets_;
IsoManager::GetInstance()->CreateCig(volatile_test_cig_create_cmpl_evt_.cig_id,
kDefaultCigParams);
diff --git a/system/stack/test/connection_manager_test.cc b/system/stack/test/connection_manager_test.cc
index 1a06158ca0..db2908c76b 100644
--- a/system/stack/test/connection_manager_test.cc
+++ b/system/stack/test/connection_manager_test.cc
@@ -70,9 +70,10 @@ namespace connection_manager {
class BleConnectionManager : public testing::Test {
void SetUp() override {
localConnTimeoutMock = std::make_unique<MockConnTimeout>();
- /* extern */ test::mock_acl_manager_ = new bluetooth::hci::testing::MockAclManager();
+ /* extern */ test::mock_acl_manager_ =
+ std::make_unique<bluetooth::hci::testing::MockAclManager>();
/* extern */ test::mock_controller_ =
- new testing::NiceMock<bluetooth::hci::testing::MockControllerInterface>();
+ std::make_unique<testing::NiceMock<bluetooth::hci::testing::MockControllerInterface>>();
ON_CALL(*test::mock_controller_, GetLeFilterAcceptListSize()).WillByDefault(Return(16));
auto alarm_mock = AlarmMock::Get();
@@ -92,8 +93,8 @@ class BleConnectionManager : public testing::Test {
void TearDown() override {
connection_manager::reset(true);
AlarmMock::Reset();
- delete test::mock_controller_;
- delete test::mock_acl_manager_;
+ test::mock_controller_.reset();
+ test::mock_acl_manager_.reset();
localConnTimeoutMock.reset();
}
};
@@ -106,7 +107,7 @@ TEST_F(BleConnectionManager, test_background_connection_add_remove) {
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
std::set<tAPP_ID> apps = get_apps_connecting_to(address1);
EXPECT_EQ(apps.size(), 1UL);
@@ -119,7 +120,7 @@ TEST_F(BleConnectionManager, test_background_connection_add_remove) {
EXPECT_EQ(get_apps_connecting_to(address1).size(), 0UL);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify that multiple clients adding same device multiple times, result in
@@ -136,7 +137,7 @@ TEST_F(BleConnectionManager, test_background_connection_multiple_clients) {
EXPECT_EQ(get_apps_connecting_to(address1).size(), 3UL);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(_, _)).Times(0);
@@ -153,7 +154,7 @@ TEST_F(BleConnectionManager, test_background_connection_multiple_clients) {
EXPECT_EQ(get_apps_connecting_to(address1).size(), 0UL);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify adding/removing device to direct connection. */
@@ -173,7 +174,7 @@ TEST_F(BleConnectionManager, test_direct_connection_client) {
// Client that don't do direct connection should fail attempt to stop it
EXPECT_FALSE(direct_connect_remove(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
@@ -183,7 +184,7 @@ TEST_F(BleConnectionManager, test_direct_connection_client) {
// acceptlist is in use, i.e. next connection attempt
EXPECT_TRUE(direct_connect_remove(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify direct connection timeout does remove device from acceptlist, and
@@ -201,7 +202,7 @@ TEST_F(BleConnectionManager, test_direct_connect_timeout) {
// Start direct connect attempt...
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_CALL(*localConnTimeoutMock, OnConnectionTimedOut(CLIENT1, address1)).Times(1);
@@ -210,7 +211,7 @@ TEST_F(BleConnectionManager, test_direct_connect_timeout) {
// simulate timeout seconds passed, alarm executing
alarm_callback(alarm_data);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify that we properly handle successfull direct connection */
@@ -222,7 +223,7 @@ TEST_F(BleConnectionManager, test_direct_connection_success) {
// Start direct connect attempt...
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(address1_hci)).Times(1);
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
@@ -230,7 +231,7 @@ TEST_F(BleConnectionManager, test_direct_connection_success) {
// successfully.
on_connection_complete(address1);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify that we properly handle application unregistration */
@@ -244,23 +245,23 @@ TEST_F(BleConnectionManager, test_app_unregister) {
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address1_hci, true)).Times(1);
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address2_hci, false)).Times(1);
EXPECT_TRUE(background_connect_add(CLIENT1, address2));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address2_hci, true)).Times(1);
EXPECT_TRUE(direct_connect_add(CLIENT2, address2));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(address1_hci)).Times(1);
on_app_deregistered(CLIENT1);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(address2_hci)).Times(1);
on_app_deregistered(CLIENT2);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
/** Verify adding device to both direct connection and background connection. */
@@ -273,7 +274,7 @@ TEST_F(BleConnectionManager, test_direct_and_background_connect) {
EXPECT_TRUE(direct_connect_add(CLIENT1, address1));
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
// not removing from acceptlist yet, as the background connection is still
@@ -284,7 +285,7 @@ TEST_F(BleConnectionManager, test_direct_and_background_connect) {
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_TRUE(background_connect_remove(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_target_announement_connect) {
@@ -302,7 +303,7 @@ TEST_F(BleConnectionManager, test_add_targeted_announement_when_allow_list_used)
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
EXPECT_TRUE(background_connect_targeted_announcement_add(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_add_background_connect_when_targeted_announcement_are_enabled) {
@@ -315,7 +316,7 @@ TEST_F(BleConnectionManager, test_add_background_connect_when_targeted_announcem
EXPECT_TRUE(background_connect_targeted_announcement_add(CLIENT2, address1));
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_re_add_background_connect_to_allow_list) {
@@ -325,7 +326,7 @@ TEST_F(BleConnectionManager, test_re_add_background_connect_to_allow_list) {
EXPECT_TRUE(background_connect_targeted_announcement_add(CLIENT2, address1));
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
/* Now remove app using targeted announcement and expect device
* to be added to white list
@@ -335,11 +336,11 @@ TEST_F(BleConnectionManager, test_re_add_background_connect_to_allow_list) {
EXPECT_CALL(*test::mock_acl_manager_, CreateLeConnection(address1_hci, false)).Times(1);
EXPECT_TRUE(background_connect_remove(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*test::mock_acl_manager_, CancelLeConnect(_)).Times(1);
EXPECT_TRUE(background_connect_remove(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multiple_clients) {
@@ -352,7 +353,7 @@ TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multip
EXPECT_TRUE(background_connect_add(CLIENT1, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
EXPECT_CALL(*AlarmMock::Get(), AlarmSetOnMloop(_, _, _, _))
.Times(1)
@@ -360,7 +361,7 @@ TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multip
// Start direct connect attempt...
EXPECT_TRUE(direct_connect_add(CLIENT2, address1));
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
// simulate timeout seconds passed, alarm executing
EXPECT_CALL(*localConnTimeoutMock, OnConnectionTimedOut(CLIENT2, address1)).Times(1);
@@ -369,7 +370,7 @@ TEST_F(BleConnectionManager, test_re_add_to_allow_list_after_timeout_with_multip
EXPECT_CALL(*AlarmMock::Get(), AlarmFree(_)).Times(1);
alarm_callback(alarm_data);
- Mock::VerifyAndClearExpectations(test::mock_acl_manager_);
+ Mock::VerifyAndClearExpectations(test::mock_acl_manager_.get());
}
} // namespace connection_manager
diff --git a/system/stack/test/eatt/eatt_test.cc b/system/stack/test/eatt/eatt_test.cc
index 130893a0a5..5d7a2eeea8 100644
--- a/system/stack/test/eatt/eatt_test.cc
+++ b/system/stack/test/eatt/eatt_test.cc
@@ -219,11 +219,13 @@ protected:
le_buffer_size_.le_data_packet_length_ = 128;
le_buffer_size_.total_num_le_packets_ = 24;
- EXPECT_CALL(controller_, GetLeBufferSize).WillRepeatedly(Return(le_buffer_size_));
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ EXPECT_CALL(*bluetooth::hci::testing::mock_controller_, GetLeBufferSize)
+ .WillRepeatedly(Return(le_buffer_size_));
bluetooth::l2cap::SetMockInterface(&l2cap_interface_);
bluetooth::manager::SetMockBtmApiInterface(&btm_api_interface_);
bluetooth::gatt::SetMockGattInterface(&gatt_interface_);
- bluetooth::hci::testing::mock_controller_ = &controller_;
// Clear the static memory for each test case
memset(&test_tcb, 0, sizeof(test_tcb));
@@ -258,7 +260,7 @@ protected:
bluetooth::l2cap::SetMockInterface(nullptr);
bluetooth::testing::stack::l2cap::reset_interface();
bluetooth::manager::SetMockBtmApiInterface(nullptr);
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
Test::TearDown();
}
@@ -269,7 +271,6 @@ protected:
bluetooth::l2cap::MockL2capInterface l2cap_interface_;
bluetooth::testing::stack::l2cap::Mock mock_stack_l2cap_interface_;
bluetooth::gatt::MockGattInterface gatt_interface_;
- bluetooth::hci::testing::MockControllerInterface controller_;
bluetooth::hci::LeBufferSize le_buffer_size_;
tL2CAP_APPL_INFO l2cap_app_info_;
diff --git a/system/stack/test/gatt/gatt_sr_test.cc b/system/stack/test/gatt/gatt_sr_test.cc
index 9c5eb868d0..4106579080 100644
--- a/system/stack/test/gatt/gatt_sr_test.cc
+++ b/system/stack/test/gatt/gatt_sr_test.cc
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#include <com_android_bluetooth_flags.h>
#include <gtest/gtest.h>
#include <cstdint>
@@ -141,25 +140,16 @@ protected:
tcb_.att_lcid = L2CAP_ATT_CID;
el_.gatt_if = 1;
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- gatt_cb.cl_rcb_map.emplace(el_.gatt_if, std::make_unique<tGATT_REG>());
- tGATT_REG* p_reg = gatt_cb.cl_rcb_map[el_.gatt_if].get();
- p_reg->in_use = true;
- p_reg->gatt_if = el_.gatt_if;
- p_reg->app_cb.p_req_cb = ApplicationRequestCallback;
- } else {
- gatt_cb.cl_rcb[el_.gatt_if - 1].in_use = true;
- gatt_cb.cl_rcb[el_.gatt_if - 1].app_cb.p_req_cb = ApplicationRequestCallback;
- }
+ gatt_cb.cl_rcb_map.emplace(el_.gatt_if, std::make_unique<tGATT_REG>());
+ tGATT_REG* p_reg = gatt_cb.cl_rcb_map[el_.gatt_if].get();
+ p_reg->in_use = true;
+ p_reg->gatt_if = el_.gatt_if;
+ p_reg->app_cb.p_req_cb = ApplicationRequestCallback;
test_state_ = TestMutables();
}
- void TearDown() override {
- if (com::android::bluetooth::flags::gatt_client_dynamic_allocation()) {
- gatt_cb.cl_rcb_map.erase(el_.gatt_if);
- }
- }
+ void TearDown() override { gatt_cb.cl_rcb_map.erase(el_.gatt_if); }
tGATT_TCB tcb_;
tGATT_SRV_LIST_ELEM el_;
diff --git a/system/stack/test/sdp/stack_sdp_test.cc b/system/stack/test/sdp/stack_sdp_test.cc
index 314ea02334..c792a5fd0d 100644
--- a/system/stack/test/sdp/stack_sdp_test.cc
+++ b/system/stack/test/sdp/stack_sdp_test.cc
@@ -62,7 +62,6 @@ protected:
fake_osi_ = std::make_unique<test::fake::FakeOsi>();
bluetooth::testing::stack::l2cap::set_interface(&mock_stack_l2cap_interface_);
- tL2CAP_APPL_INFO l2cap_callbacks{};
EXPECT_CALL(mock_stack_l2cap_interface_, L2CA_RegisterWithSecurity(_, _, _, _, _, _, _))
.WillOnce(DoAll(SaveArg<1>(&l2cap_callbacks), ::testing::ReturnArg<0>()));
EXPECT_CALL(mock_stack_l2cap_interface_, L2CA_Deregister(_));
@@ -73,6 +72,7 @@ protected:
fake_osi_.reset();
}
+ tL2CAP_APPL_INFO l2cap_callbacks{};
bluetooth::testing::stack::l2cap::Mock mock_stack_l2cap_interface_;
std::unique_ptr<test::fake::FakeOsi> fake_osi_;
};
diff --git a/system/stack/test/stack_acl_test.cc b/system/stack/test/stack_acl_test.cc
index b08a45cb80..bd0b153b9f 100644
--- a/system/stack/test/stack_acl_test.cc
+++ b/system/stack/test/stack_acl_test.cc
@@ -48,12 +48,12 @@ class StackAclTest : public testing::Test {
protected:
void SetUp() override {
reset_mock_function_count_map();
- bluetooth::hci::testing::mock_controller_ = &controller_;
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
}
- void TearDown() override { bluetooth::hci::testing::mock_controller_ = nullptr; }
+ void TearDown() override { bluetooth::hci::testing::mock_controller_.reset(); }
tBTM_SEC_DEV_REC device_record_;
- bluetooth::hci::testing::MockControllerInterface controller_;
};
TEST_F(StackAclTest, nop) {}
diff --git a/system/stack/test/stack_l2cap_test.cc b/system/stack/test/stack_l2cap_test.cc
index ffe78055bc..204900b462 100644
--- a/system/stack/test/stack_l2cap_test.cc
+++ b/system/stack/test/stack_l2cap_test.cc
@@ -49,23 +49,23 @@ constexpr uint16_t kAclBufferSizeBle = 45;
class StackL2capTest : public ::testing::Test {
protected:
void SetUp() override {
- bluetooth::hci::testing::mock_controller_ = &controller_interface_;
- ON_CALL(controller_interface_, GetNumAclPacketBuffers)
+ bluetooth::hci::testing::mock_controller_ =
+ std::make_unique<bluetooth::hci::testing::MockControllerInterface>();
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetNumAclPacketBuffers)
.WillByDefault(Return(kAclBufferCountClassic));
bluetooth::hci::LeBufferSize le_sizes;
le_sizes.total_num_le_packets_ = kAclBufferCountBle;
le_sizes.le_data_packet_length_ = kAclBufferSizeBle;
- ON_CALL(controller_interface_, GetLeBufferSize).WillByDefault(Return(le_sizes));
- ON_CALL(controller_interface_, SupportsBle).WillByDefault(Return(true));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, GetLeBufferSize)
+ .WillByDefault(Return(le_sizes));
+ ON_CALL(*bluetooth::hci::testing::mock_controller_, SupportsBle).WillByDefault(Return(true));
l2c_init();
}
void TearDown() override {
l2c_free();
- bluetooth::hci::testing::mock_controller_ = nullptr;
+ bluetooth::hci::testing::mock_controller_.reset();
}
-
- bluetooth::hci::testing::MockControllerInterface controller_interface_;
};
TEST_F(StackL2capTest, l2cble_process_data_length_change_event) {
diff --git a/system/test/Android.bp b/system/test/Android.bp
index c35931ea17..9dab01352f 100644
--- a/system/test/Android.bp
+++ b/system/test/Android.bp
@@ -88,6 +88,13 @@ filegroup {
}
filegroup {
+ name: "TestMockBtaHearingAidAudioSource",
+ srcs: [
+ "mock/mock_bta_hearing_aid_audio_source.cc",
+ ],
+}
+
+filegroup {
name: "TestMockBtaHf",
srcs: [
"mock/mock_bta_hf*.cc",
@@ -184,6 +191,7 @@ filegroup {
":TestMockBtaHas",
":TestMockBtaHd",
":TestMockBtaHearingAid",
+ ":TestMockBtaHearingAidAudioSource",
":TestMockBtaHf",
":TestMockBtaHh",
":TestMockBtaJv",
@@ -450,16 +458,16 @@ filegroup {
}
filegroup {
- name: "TestMockStackMetrics",
+ name: "TestMockStackGap",
srcs: [
- "mock/mock_stack_metrics*.cc",
+ "mock/mock_stack_gap*.cc",
],
}
filegroup {
- name: "TestMockStackGap",
+ name: "TestMockStackGapConnInterface",
srcs: [
- "mock/mock_stack_gap*.cc",
+ "mock/mock_stack_gap_conn_interface.cc",
],
}
diff --git a/system/test/README.md b/system/test/README.md
deleted file mode 100644
index 1f43e952ef..0000000000
--- a/system/test/README.md
+++ /dev/null
@@ -1,81 +0,0 @@
-# Fluoride Bluetooth Tests
-
-This document refers to the tests in the packages/modules/Bluetooth/system/test directory.
-
-The tests are designed to be run when the Android runtime is not running. From a terminal, run:
-
-## Before you run tests
-```sh
-adb shell stop
-```
-
-## After you're done
-```sh
-adb shell start
-```
-
-## Running tests
-Then see what options the test script provides:
-
-```sh
-./run_unit_tests.sh --help
-```
-
-But for the impatient, run specific groups of tests like this:
-
-```sh
-./run_unit_tests.sh net_test_bluetooth
-```
-
-a single test:
-
-```sh
-./run_unit_tests.sh net_test_bluetooth.BluetoothTest.AdapterRepeatedEnableDisable
-```
-
-## Sample Output
-
-packages/modules/Bluetooth/system/test$ ./run_unit_tests.sh net_test_bluetooth
---- net_test_bluetooth ---
-pushing...
-/tbd/aosp-master/out/target/product/bullhead/data/nativetest/n...st_bluetooth: 1 file pushed. 9.2 MB/s (211832 bytes in 0.022s)
-running...
-
-Running main() from gtest_main.cc
-[==========] Running 11 tests from 2 test cases.
-[----------] Global test environment set-up.
-[----------] 6 tests from BluetoothTest
-[ RUN ] BluetoothTest.AdapterEnableDisable
-[ OK ] BluetoothTest.AdapterEnableDisable (2538 ms)
-[ RUN ] BluetoothTest.AdapterRepeatedEnableDisable
-[ OK ] BluetoothTest.AdapterRepeatedEnableDisable (11384 ms)
-[ RUN ] BluetoothTest.AdapterSetGetName
-[ OK ] BluetoothTest.AdapterSetGetName (2378 ms)
-[ RUN ] BluetoothTest.AdapterStartDiscovery
-[ OK ] BluetoothTest.AdapterStartDiscovery (2397 ms)
-[ RUN ] BluetoothTest.AdapterCancelDiscovery
-[ OK ] BluetoothTest.AdapterCancelDiscovery (2401 ms)
-[ RUN ] BluetoothTest.AdapterDisableDuringBonding
-[ OK ] BluetoothTest.AdapterDisableDuringBonding (11689 ms)
-[----------] 6 tests from BluetoothTest (32789 ms total)
-
-[----------] 5 tests from GattTest
-[ RUN ] GattTest.GattClientRegister
-[ OK ] GattTest.GattClientRegister (2370 ms)
-[ RUN ] GattTest.GattClientScanRemoteDevice
-[ OK ] GattTest.GattClientScanRemoteDevice (2273 ms)
-[ RUN ] GattTest.GattClientAdvertise
-[ OK ] GattTest.GattClientAdvertise (2236 ms)
-[ RUN ] GattTest.GattServerRegister
-[ OK ] GattTest.GattServerRegister (2391 ms)
-[ RUN ] GattTest.GattServerBuild
-[ OK ] GattTest.GattServerBuild (2435 ms)
-[----------] 5 tests from GattTest (11706 ms total)
-
-[----------] Global test environment tear-down
-[==========] 11 tests from 2 test cases ran. (44495 ms total)
-[ PASSED ] 11 tests.
-
-## Troubleshooting: Your phone is bricked!
-Probably not. See [After you're done](#After-you're-done)
-
diff --git a/system/test/mock/mock_bta_hearing_aid_audio_source.cc b/system/test/mock/mock_bta_hearing_aid_audio_source.cc
new file mode 100644
index 0000000000..c68fad3b8d
--- /dev/null
+++ b/system/test/mock/mock_bta_hearing_aid_audio_source.cc
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * Generated mock file from original source file
+ * Functions generated:8
+ */
+
+#include <base/functional/callback.h>
+
+#include <cstdint>
+
+#include "bta/include/bta_gatt_queue.h"
+#include "bta/include/bta_hearing_aid_api.h"
+#include "test/common/mock_functions.h"
+#include "types/raw_address.h"
+
+void HearingAidAudioSource::Start(const CodecConfiguration& /*codecConfiguration*/,
+ HearingAidAudioReceiver* /*audioReceiver*/,
+ uint16_t /*remote_delay_ms*/) {
+ inc_func_call_count(__func__);
+}
+
+void HearingAidAudioSource::Stop() { inc_func_call_count(__func__); }
+
+void HearingAidAudioSource::Initialize() { inc_func_call_count(__func__); }
+
+void HearingAidAudioSource::CleanUp() { inc_func_call_count(__func__); }
+
+void HearingAidAudioSource::DebugDump(int /*fd*/) { inc_func_call_count(__func__); }
diff --git a/system/test/mock/mock_main_shim_acl.cc b/system/test/mock/mock_main_shim_acl.cc
index a98e809ad0..5f58860347 100644
--- a/system/test/mock/mock_main_shim_acl.cc
+++ b/system/test/mock/mock_main_shim_acl.cc
@@ -129,12 +129,6 @@ void shim::Acl::DisconnectLe(uint16_t /* handle */, tHCI_STATUS /* reason */,
inc_func_call_count(__func__);
}
-void shim::Acl::LeSetDefaultSubrate(uint16_t /* subrate_min */, uint16_t /* subrate_max */,
- uint16_t /* max_latency */, uint16_t /* cont_num */,
- uint16_t /* sup_tout */) {
- inc_func_call_count(__func__);
-}
-
void shim::Acl::LeSubrateRequest(uint16_t /* hci_handle */, uint16_t /* subrate_min */,
uint16_t /* subrate_max */, uint16_t /* max_latency */,
uint16_t /* cont_num */, uint16_t /* sup_tout */) {
diff --git a/system/test/mock/mock_main_shim_acl_api.cc b/system/test/mock/mock_main_shim_acl_api.cc
index 3d257f1a5a..e3a3c9d63b 100644
--- a/system/test/mock/mock_main_shim_acl_api.cc
+++ b/system/test/mock/mock_main_shim_acl_api.cc
@@ -73,12 +73,6 @@ void bluetooth::shim::ACL_RemoveFromAddressResolution(
inc_func_call_count(__func__);
}
void bluetooth::shim::ACL_ClearAddressResolution() { inc_func_call_count(__func__); }
-void bluetooth::shim::ACL_LeSetDefaultSubrate(uint16_t /* subrate_min */,
- uint16_t /* subrate_max */,
- uint16_t /* max_latency */, uint16_t /* cont_num */,
- uint16_t /* sup_tout */) {
- inc_func_call_count(__func__);
-}
void bluetooth::shim::ACL_LeSubrateRequest(uint16_t /* hci_handle */, uint16_t /* subrate_min */,
uint16_t /* subrate_max */, uint16_t /* max_latency */,
uint16_t /* cont_num */, uint16_t /* sup_tout */) {
diff --git a/system/test/mock/mock_main_shim_acl_api.h b/system/test/mock/mock_main_shim_acl_api.h
index ab891673e3..29e27dbad3 100644
--- a/system/test/mock/mock_main_shim_acl_api.h
+++ b/system/test/mock/mock_main_shim_acl_api.h
@@ -84,21 +84,6 @@ struct ACL_ClearFilterAcceptList {
};
extern struct ACL_ClearFilterAcceptList ACL_ClearFilterAcceptList;
-// Name: ACL_LeSetDefaultSubrate
-// Params:
-// Return: void
-struct ACL_LeSetDefaultSubrate {
- std::function<void(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout)>
- body{[](uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout) {}};
- void operator()(uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency,
- uint16_t cont_num, uint16_t sup_tout) {
- body(subrate_min, subrate_max, max_latency, cont_num, sup_tout);
- }
-};
-extern struct ACL_LeSetDefaultSubrate ACL_LeSetDefaultSubrate;
-
// Name: ACL_LeSubrateRequest
// Params:
// Return: void
diff --git a/system/test/mock/mock_main_shim_entry.cc b/system/test/mock/mock_main_shim_entry.cc
index 5d68f11b9d..3cdc714eaf 100644
--- a/system/test/mock/mock_main_shim_entry.cc
+++ b/system/test/mock/mock_main_shim_entry.cc
@@ -38,9 +38,9 @@ namespace bluetooth {
namespace hci {
namespace testing {
-MockAclManager* mock_acl_manager_{nullptr};
-MockControllerInterface* mock_controller_{nullptr};
-HciInterface* mock_hci_layer_{nullptr};
+std::unique_ptr<MockAclManager> mock_acl_manager_;
+std::unique_ptr<MockControllerInterface> mock_controller_;
+std::unique_ptr<MockHciLayer> mock_hci_layer_;
os::Handler* mock_gd_shim_handler_{nullptr};
MockLeAdvertisingManager* mock_le_advertising_manager_{nullptr};
MockLeScanningManager* mock_le_scanning_manager_{nullptr};
@@ -58,9 +58,9 @@ class Dumpsys;
namespace shim {
-hci::AclManager* GetAclManager() { return hci::testing::mock_acl_manager_; }
-hci::ControllerInterface* GetController() { return hci::testing::mock_controller_; }
-hci::HciInterface* GetHciLayer() { return hci::testing::mock_hci_layer_; }
+hci::AclManager* GetAclManager() { return hci::testing::mock_acl_manager_.get(); }
+hci::ControllerInterface* GetController() { return hci::testing::mock_controller_.get(); }
+hci::HciInterface* GetHciLayer() { return hci::testing::mock_hci_layer_.get(); }
hci::LeAdvertisingManager* GetAdvertising() { return hci::testing::mock_le_advertising_manager_; }
hci::LeScanningManager* GetScanning() { return hci::testing::mock_le_scanning_manager_; }
hci::DistanceMeasurementManager* GetDistanceMeasurementManager() {
diff --git a/system/test/mock/mock_main_shim_entry.h b/system/test/mock/mock_main_shim_entry.h
index ca84a27193..5d427fd963 100644
--- a/system/test/mock/mock_main_shim_entry.h
+++ b/system/test/mock/mock_main_shim_entry.h
@@ -15,11 +15,12 @@
*/
#include <functional>
+#include <memory>
#include "hci/acl_manager_mock.h"
#include "hci/controller_interface_mock.h"
#include "hci/distance_measurement_manager_mock.h"
-#include "hci/hci_interface.h"
+#include "hci/hci_layer_mock.h"
#include "hci/le_advertising_manager_mock.h"
#include "hci/le_scanning_manager_mock.h"
#include "storage/storage_module.h"
@@ -28,9 +29,9 @@ namespace bluetooth {
namespace hci {
namespace testing {
-extern MockAclManager* mock_acl_manager_;
-extern MockControllerInterface* mock_controller_;
-extern HciInterface* mock_hci_layer_;
+extern std::unique_ptr<MockAclManager> mock_acl_manager_;
+extern std::unique_ptr<MockControllerInterface> mock_controller_;
+extern std::unique_ptr<MockHciLayer> mock_hci_layer_;
extern os::Handler* mock_gd_shim_handler_;
extern MockLeAdvertisingManager* mock_le_advertising_manager_;
extern MockLeScanningManager* mock_le_scanning_manager_;
diff --git a/system/test/mock/mock_stack_gap_conn.cc b/system/test/mock/mock_stack_gap_conn_interface.cc
index 07193c9130..2ef1a3ef8f 100644
--- a/system/test/mock/mock_stack_gap_conn.cc
+++ b/system/test/mock/mock_stack_gap_conn_interface.cc
@@ -1,5 +1,5 @@
/*
- * Copyright 2021 The Android Open Source Project
+ * Copyright 2025 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,19 +14,39 @@
* limitations under the License.
*/
-/*
- * Generated mock file from original source file
- * Functions generated:13
- */
+#include "test/mock/mock_stack_gap_conn_interface.h"
-#include "gap_api.h"
-#include "stack/include/bt_hdr.h"
+#include "stack/include/gap_api.h"
#include "test/common/mock_functions.h"
-#include "types/raw_address.h"
-const RawAddress* GAP_ConnGetRemoteAddr(uint16_t /* gap_handle */) {
+namespace {
+bluetooth::testing::stack::gap_conn::Mock mock_gap_conn_interface;
+bluetooth::testing::stack::gap_conn::Interface* interface_ = &mock_gap_conn_interface;
+} // namespace
+
+void bluetooth::testing::stack::gap_conn::reset_interface() {
+ interface_ = &mock_gap_conn_interface;
+}
+
+void bluetooth::testing::stack::gap_conn::set_interface(
+ bluetooth::testing::stack::gap_conn::Interface* interface) {
+ interface_ = interface;
+}
+
+uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, bool is_server,
+ const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps,
+ tL2CAP_CFG_INFO* p_cfg, tL2CAP_ERTM_INFO* ertm_info, uint16_t security,
+ tGAP_CONN_CALLBACK* p_cb, tBT_TRANSPORT transport) {
inc_func_call_count(__func__);
- return nullptr;
+
+ return interface_->GAP_ConnOpen(p_serv_name, service_id, is_server, p_rem_bda, psm, le_mps, p_cfg,
+ ertm_info, security, p_cb, transport);
+}
+
+const RawAddress* GAP_ConnGetRemoteAddr(uint16_t gap_handle) {
+ inc_func_call_count(__func__);
+
+ return interface_->GAP_ConnGetRemoteAddr(gap_handle);
}
int GAP_GetRxQueueCnt(uint16_t /* handle */, uint32_t* /* p_rx_queue_count */) {
inc_func_call_count(__func__);
@@ -44,14 +64,6 @@ uint16_t GAP_ConnGetRemMtuSize(uint16_t /* gap_handle */) {
inc_func_call_count(__func__);
return 0;
}
-uint16_t GAP_ConnOpen(const char* /* p_serv_name */, uint8_t /* service_id */, bool /* is_server */,
- const RawAddress* /* p_rem_bda */, uint16_t /* psm */, uint16_t /* le_mps */,
- tL2CAP_CFG_INFO* /* p_cfg */, tL2CAP_ERTM_INFO* /* ertm_info */,
- uint16_t /* security */, tGAP_CONN_CALLBACK* /* p_cb */,
- tBT_TRANSPORT /* transport */) {
- inc_func_call_count(__func__);
- return 0;
-}
uint16_t GAP_ConnReadData(uint16_t /* gap_handle */, uint8_t* /* p_data */, uint16_t /* max_len */,
uint16_t* /* p_len */) {
inc_func_call_count(__func__);
@@ -74,3 +86,8 @@ bool GAP_IsTransportLe(uint16_t /* gap_handle */) {
return false;
}
void GAP_Init(void) { inc_func_call_count(__func__); }
+
+bluetooth::testing::stack::gap_conn::Interface&
+bluetooth::testing::stack::gap_conn::get_interface() {
+ return *interface_;
+}
diff --git a/system/test/mock/mock_stack_gap_conn_interface.h b/system/test/mock/mock_stack_gap_conn_interface.h
new file mode 100644
index 0000000000..c1ed7caea3
--- /dev/null
+++ b/system/test/mock/mock_stack_gap_conn_interface.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <gmock/gmock.h>
+
+#include <vector>
+
+#include "stack/include/gap_api.h"
+
+namespace bluetooth {
+namespace testing {
+namespace stack {
+namespace gap_conn {
+
+class Interface {
+public:
+ virtual ~Interface() = default;
+
+ virtual uint16_t GAP_ConnOpen(const char* p_serv_name, uint8_t service_id, bool is_server,
+ const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps,
+ tL2CAP_CFG_INFO* p_cfg, tL2CAP_ERTM_INFO* ertm_info,
+ uint16_t security, tGAP_CONN_CALLBACK* p_cb,
+ tBT_TRANSPORT transport) = 0;
+
+ virtual const RawAddress* GAP_ConnGetRemoteAddr(uint16_t gap_handle) = 0;
+};
+
+class Mock : public Interface {
+public:
+ ~Mock() = default;
+
+ MOCK_METHOD(uint16_t, GAP_ConnOpen,
+ (const char* p_serv_name, uint8_t service_id, bool is_server,
+ const RawAddress* p_rem_bda, uint16_t psm, uint16_t le_mps, tL2CAP_CFG_INFO* p_cfg,
+ tL2CAP_ERTM_INFO* ertm_info, uint16_t security, tGAP_CONN_CALLBACK* p_cb,
+ tBT_TRANSPORT transport));
+
+ MOCK_METHOD(const RawAddress*, GAP_ConnGetRemoteAddr, (uint16_t gap_handle));
+};
+
+void reset_interface();
+void set_interface(Interface* interface_);
+Interface& get_interface();
+
+} // namespace gap_conn
+} // namespace stack
+} // namespace testing
+} // namespace bluetooth
diff --git a/system/test/mock/mock_stack_l2cap_interface.h b/system/test/mock/mock_stack_l2cap_interface.h
index a5cd536777..b2fc3e0ae9 100644
--- a/system/test/mock/mock_stack_l2cap_interface.h
+++ b/system/test/mock/mock_stack_l2cap_interface.h
@@ -64,9 +64,6 @@ public:
MOCK_METHOD(bool, L2CA_GetPeerFeatures,
(const RawAddress& bd_addr, uint32_t* p_ext_feat, uint8_t* p_chnl_mask));
MOCK_METHOD(bool, L2CA_SetAclPriority, (const RawAddress& bd_addr, tL2CAP_PRIORITY priority));
- MOCK_METHOD(void, L2CA_SetDefaultSubrate,
- (uint16_t subrate_min, uint16_t subrate_max, uint16_t max_latency, uint16_t cont_num,
- uint16_t timeout));
MOCK_METHOD(void, L2CA_AdjustConnectionIntervals,
(uint16_t* min_interval, uint16_t* max_interval, uint16_t floor_interval));
MOCK_METHOD(void, L2CA_SetEcosystemBaseInterval, (uint32_t base_interval));
diff --git a/system/test/mock/mock_stack_metrics_logging.cc b/system/test/mock/mock_stack_metrics_logging.cc
deleted file mode 100644
index ff2cee4472..0000000000
--- a/system/test/mock/mock_stack_metrics_logging.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Generated mock file from original source file
- * Functions generated:5
- *
- * mockcify.pl ver 0.2
- */
-// Mock include file to share data between tests and mock
-#include "test/mock/mock_stack_metrics_logging.h"
-
-#include <string>
-
-// Original included files, if any
-#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
-
-#include "stack/include/stack_metrics_logging.h"
-#include "test/common/mock_functions.h"
-#include "types/raw_address.h"
-
-// Mocked compile conditionals, if any
-// Mocked internal structures, if any
-
-namespace test {
-namespace mock {
-namespace stack_metrics_logging {
-
-// Function state capture and return values, if needed
-struct log_classic_pairing_event log_classic_pairing_event;
-struct log_link_layer_connection_event log_link_layer_connection_event;
-struct log_smp_pairing_event log_smp_pairing_event;
-struct log_le_pairing_fail log_le_pairing_fail;
-struct log_sdp_attribute log_sdp_attribute;
-struct log_manufacturer_info log_manufacturer_info;
-struct log_counter_metrics log_counter_metrics;
-struct log_hfp_audio_packet_loss_stats log_hfp_audio_packet_loss_stats;
-struct log_mmc_transcode_rtt_stats log_mmc_transcode_rtt_stats;
-struct log_le_connection_status log_le_connection_status;
-struct log_le_device_in_accept_list log_le_device_in_accept_list;
-struct log_le_connection_lifecycle log_le_connection_lifecycle;
-struct log_le_connection_completion log_le_connection_completion;
-
-} // namespace stack_metrics_logging
-} // namespace mock
-} // namespace test
-
-// Mocked functions, if any
-void 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) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_classic_pairing_event(
- address, handle, hci_cmd, hci_event, cmd_status, reason_code, event_value);
-}
-void 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) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_link_layer_connection_event(
- address, connection_handle, direction, link_type, hci_cmd, hci_event, hci_ble_event,
- cmd_status, reason_code);
-}
-void log_smp_pairing_event(const RawAddress& address, uint16_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_smp_pairing_event(address, smp_cmd, direction,
- smp_fail_reason);
-}
-
-void log_le_pairing_fail(const RawAddress& raw_address, uint8_t failure_reason, bool is_outgoing) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_le_pairing_fail(raw_address, failure_reason, is_outgoing);
-}
-
-void log_sdp_attribute(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_sdp_attribute(address, protocol_uuid, attribute_id,
- attribute_size, attribute_value);
-}
-void 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) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_manufacturer_info(address, address_type, source_type,
- source_name, manufacturer, model,
- hardware_version, software_version);
-}
-
-void log_counter_metrics(android::bluetooth::CodePathCounterKeyEnum key, int64_t value) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_counter_metrics(key, value);
-}
-
-void log_hfp_audio_packet_loss_stats(const RawAddress& address, int num_decoded_frames,
- double packet_loss_ratio, uint16_t codec_type) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_hfp_audio_packet_loss_stats(address, num_decoded_frames,
- packet_loss_ratio, codec_type);
-}
-
-void log_mmc_transcode_rtt_stats(int maximum_rtt, double mean_rtt, int num_requests,
- int codec_type) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_mmc_transcode_rtt_stats(maximum_rtt, mean_rtt,
- num_requests, codec_type);
-}
-
-void log_le_connection_status(bluetooth::hci::Address address, bool is_connect,
- bluetooth::hci::ErrorCode reason) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_le_connection_status(address, is_connect, reason);
-}
-
-void log_le_device_in_accept_list(bluetooth::hci::Address address, bool is_add) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_le_device_in_accept_list(address, is_add);
-}
-
-void log_le_connection_lifecycle(bluetooth::hci::Address address, bool is_connect, bool is_direct) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_le_connection_lifecycle(address, is_connect, is_direct);
-}
-
-void log_le_connection_completion(bluetooth::hci::Address address, bluetooth::hci::ErrorCode reason,
- bool is_locally_initiated) {
- inc_func_call_count(__func__);
- test::mock::stack_metrics_logging::log_le_connection_completion(address, reason,
- is_locally_initiated);
-}
-// END mockcify generation
diff --git a/system/test/mock/mock_stack_metrics_logging.h b/system/test/mock/mock_stack_metrics_logging.h
deleted file mode 100644
index 40212e60ea..0000000000
--- a/system/test/mock/mock_stack_metrics_logging.h
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * Copyright 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Generated mock file from original source file
- * Functions generated:5
- *
- * mockcify.pl ver 0.2
- */
-
-#include <string>
-
-// Original included files, if any
-#include <frameworks/proto_logging/stats/enums/bluetooth/enums.pb.h>
-#include <frameworks/proto_logging/stats/enums/bluetooth/hci/enums.pb.h>
-
-#include "hci/address.h"
-#include "hci/hci_packets.h"
-#include "types/raw_address.h"
-
-// Mocked compile conditionals, if any
-
-namespace test {
-namespace mock {
-namespace stack_metrics_logging {
-
-// Shared state between mocked functions and tests
-// Name: log_classic_pairing_event
-// Params: 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 Returns: void
-struct log_classic_pairing_event {
- std::function<void(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)>
- body{[](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 */) {}};
- void operator()(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) {
- body(address, handle, hci_cmd, hci_event, cmd_status, reason_code, event_value);
- }
-};
-extern struct log_classic_pairing_event log_classic_pairing_event;
-// Name: log_link_layer_connection_event
-// Params: 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 Returns: void
-struct log_link_layer_connection_event {
- std::function<void(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)>
- body{[](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 */) {}};
- void operator()(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) {
- body(address, connection_handle, direction, link_type, hci_cmd, hci_event, hci_ble_event,
- cmd_status, reason_code);
- }
-};
-extern struct log_link_layer_connection_event log_link_layer_connection_event;
-// Name: log_smp_pairing_event
-// Params: const RawAddress& address, uint16_t smp_cmd,
-// android::bluetooth::DirectionEnum direction, uint8_t smp_fail_reason Returns:
-// void
-struct log_smp_pairing_event {
- std::function<void(const RawAddress& address, uint16_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason)>
- body{[](const RawAddress& /* address */, uint16_t /* smp_cmd */,
- android::bluetooth::DirectionEnum /* direction */,
- uint16_t /* smp_fail_reason */) {}};
- void operator()(const RawAddress& address, uint16_t smp_cmd,
- android::bluetooth::DirectionEnum direction, uint16_t smp_fail_reason) {
- body(address, smp_cmd, direction, smp_fail_reason);
- }
-};
-extern struct log_smp_pairing_event log_smp_pairing_event;
-
-// Name: log_le_pairing_fail
-// Params: const RawAddress& raw_address, uint8_t failure_reason, bool
-// is_outgoing Returns:
-// void
-// Name: log_sdp_attribute
-// Params: const RawAddress& address, uint16_t protocol_uuid, uint16_t
-// attribute_id, size_t attribute_size, const char* attribute_value Returns:
-// void
-struct log_le_pairing_fail {
- std::function<void(const RawAddress& raw_address, uint8_t failure_reason, bool is_outgoing)> body{
- [](const RawAddress& /* address */, uint8_t /* failure reason */,
- bool /* is_outgoing */) {}};
- void operator()(const RawAddress& raw_address, uint8_t failure_reason, bool is_outgoing) {
- body(raw_address, failure_reason, is_outgoing);
- }
-};
-extern struct log_le_pairing_fail log_le_pairing_fail;
-
-struct log_sdp_attribute {
- std::function<void(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value)>
- body{[](const RawAddress& /* address */, uint16_t /* protocol_uuid */,
- uint16_t /* attribute_id */, size_t /* attribute_size */,
- const char* /* attribute_value */) {}};
- void operator()(const RawAddress& address, uint16_t protocol_uuid, uint16_t attribute_id,
- size_t attribute_size, const char* attribute_value) {
- body(address, protocol_uuid, attribute_id, attribute_size, attribute_value);
- }
-};
-extern struct log_sdp_attribute log_sdp_attribute;
-// Name: log_manufacturer_info
-// Params: 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 Returns: void
-struct log_manufacturer_info {
- std::function<void(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)>
- body2{[](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 */) {}};
- void operator()(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) {
- body2(address, address_type, source_type, source_name, manufacturer, model, hardware_version,
- software_version);
- }
- std::function<void(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)>
- body{[](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 */) {}};
- void operator()(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) {
- body(address, source_type, source_name, manufacturer, model, hardware_version,
- software_version);
- }
-};
-extern struct log_manufacturer_info log_manufacturer_info;
-
-// Name: log_counter_metrics
-struct log_counter_metrics {
- std::function<void(android::bluetooth::CodePathCounterKeyEnum key, int64_t value)> body{
- [](android::bluetooth::CodePathCounterKeyEnum /* key */, int64_t /* value */) {}};
- void operator()(android::bluetooth::CodePathCounterKeyEnum key, int64_t value) {
- body(key, value);
- }
-};
-extern struct log_counter_metrics log_counter_metrics;
-
-// Name: log_hfp_audio_packet_loss_stats
-struct log_hfp_audio_packet_loss_stats {
- std::function<void(const RawAddress& address, int num_decoded_frames, double packet_loss_ratio,
- uint16_t codec_type)>
- body{[](const RawAddress& /* address */, int /* num_decoded_frames */,
- double /* packet_loss_ratio */, uint16_t /* codec_type */) {}};
- void operator()(const RawAddress& address, int num_decoded_frames, double packet_loss_ratio,
- uint16_t codec_type) {
- body(address, num_decoded_frames, packet_loss_ratio, codec_type);
- }
-};
-extern struct log_hfp_audio_packet_loss_stats log_hfp_audio_packet_loss_stats;
-
-// Name: log_mmc_transcode_rtt_stats
-struct log_mmc_transcode_rtt_stats {
- std::function<void(int maximum_rtt, double mean_rtt, int num_requests, int codec_type)> body{
- [](int /* maximum_rtt */, double /* mean_rtt */, int /* num_requests */,
- int /* codec_type */) {}};
- void operator()(int maximum_rtt, double mean_rtt, int num_requests, int codec_type) {
- body(maximum_rtt, mean_rtt, num_requests, codec_type);
- }
-};
-extern struct log_mmc_transcode_rtt_stats log_mmc_transcode_rtt_stats;
-
-// Name: log_le_connection_status
-struct log_le_connection_status {
- std::function<void(bluetooth::hci::Address address, bool is_connect,
- bluetooth::hci::ErrorCode reason)>
- body{[](bluetooth::hci::Address /* address */, bool /* is_connect */,
- bluetooth::hci::ErrorCode /* reason */) {}};
- void operator()(bluetooth::hci::Address address, bool is_connect,
- bluetooth::hci::ErrorCode reason) {
- body(address, is_connect, reason);
- }
-};
-extern struct log_le_connection_status log_le_connection_status;
-
-// Name: log_le_device_in_accept_list
-struct log_le_device_in_accept_list {
- std::function<void(bluetooth::hci::Address address, bool is_add)> body{
- [](bluetooth::hci::Address /* address */, bool /* is_add */) {}};
- void operator()(bluetooth::hci::Address address, bool is_add) { body(address, is_add); }
-};
-extern struct log_le_device_in_accept_list log_le_device_in_accept_list;
-
-// Name: log_le_connection_lifecycle
-struct log_le_connection_lifecycle {
- std::function<void(bluetooth::hci::Address address, bool is_connect, bool is_direct)> body{
- [](bluetooth::hci::Address /* address */, bool /* is_connect */, bool /* is_direct */) {
- }};
- void operator()(bluetooth::hci::Address address, bool is_connect, bool is_direct) {
- body(address, is_connect, is_direct);
- }
-};
-extern struct log_le_device_in_accept_list log_le_device_in_accept_list;
-
-// Name: log_le_connection_completion
-struct log_le_connection_completion {
- std::function<void(bluetooth::hci::Address address, bluetooth::hci::ErrorCode reason,
- bool is_locally_initiated)>
- body{[](bluetooth::hci::Address /* address */, bluetooth::hci::ErrorCode /* reason */,
- bool /* is locally initiated */) {}};
- void operator()(bluetooth::hci::Address address, bluetooth::hci::ErrorCode reason,
- bool is_locally_initiated) {
- body(address, reason, is_locally_initiated);
- }
-};
-extern struct log_le_connection_completion log_le_connection_completion;
-
-} // namespace stack_metrics_logging
-} // namespace mock
-} // namespace test
-
-// END mockcify generation