summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jakub Pawlowski <jpawlowski@google.com> 2024-10-24 17:25:57 +0200
committer Jakub Pawlowski <jpawlowski@google.com> 2025-01-09 21:56:57 +0100
commit994c4ad8cedd73588fe5b8f8ae480d068dbe5c13 (patch)
tree267ed3083a9006f64ea288ff46f11cfae5d9de6f
parent4bb6652a5ee2c8f14211c4f47eea26055feb9a99 (diff)
Get rid of direct_connect_request
connection_manager.cc after aosp/3315277 keeps accurate list of all direct connections, so there is no need to keep a separate list. This effectively reverts aosp/3029225 , which is no longer needed. Test: atest net_test_conn_multiplexing Bug: 372202918 Flag: EXEMPT, covered under unittests Change-Id: I62c44f2dca31b9cfbd0464ba680528571a5c32dd
-rw-r--r--system/stack/Android.bp1
-rw-r--r--system/stack/connection_manager/connection_manager.cc2
-rw-r--r--system/stack/gatt/gatt_api.cc9
-rw-r--r--system/stack/gatt/gatt_int.h1
-rw-r--r--system/stack/gatt/gatt_main.cc14
-rw-r--r--system/stack/gatt/gatt_utils.cc69
-rw-r--r--system/stack/test/gatt/gatt_sr_test.cc10
-rw-r--r--system/stack/test/gatt/stack_gatt_test.cc1
8 files changed, 12 insertions, 95 deletions
diff --git a/system/stack/Android.bp b/system/stack/Android.bp
index dd004567a3..347f3af442 100644
--- a/system/stack/Android.bp
+++ b/system/stack/Android.bp
@@ -1105,6 +1105,7 @@ cc_test {
":TestMockRustFfi",
":TestMockStackArbiter",
":TestMockStackBtm",
+ ":TestMockStackConnMgr",
":TestMockStackSdp",
"gatt/gatt_utils.cc",
"test/common/mock_eatt.cc",
diff --git a/system/stack/connection_manager/connection_manager.cc b/system/stack/connection_manager/connection_manager.cc
index 25c9ee57ac..502bf8747b 100644
--- a/system/stack/connection_manager/connection_manager.cc
+++ b/system/stack/connection_manager/connection_manager.cc
@@ -367,7 +367,7 @@ bool background_connect_remove(uint8_t app_id, const RawAddress& address) {
}
if (is_anyone_connecting(it)) {
- log::debug("some device is still connecting, app_id={}, address={}", static_cast<int>(app_id),
+ log::debug("some app is still connecting, app_id={}, address={}", static_cast<int>(app_id),
address);
/* Check which method should be used now.*/
if (!accept_list_enabled) {
diff --git a/system/stack/gatt/gatt_api.cc b/system/stack/gatt/gatt_api.cc
index 19ea3a3090..3e10a8b660 100644
--- a/system/stack/gatt/gatt_api.cc
+++ b/system/stack/gatt/gatt_api.cc
@@ -1486,14 +1486,7 @@ bool GATT_Connect(tGATT_IF gatt_if, const RawAddress& bd_addr, tBLE_ADDR_TYPE ad
/* Consider to remove gatt_act_connect at all */
ret = gatt_act_connect(p_reg, bd_addr, addr_type, transport, initiating_phys);
} else {
- log::verbose("Connecting without tcb address: {}", bd_addr);
-
- if (p_reg->direct_connect_request.count(bd_addr) == 0) {
- p_reg->direct_connect_request.insert(bd_addr);
- } else {
- log::warn("{} already added to gatt_if {} direct conn list", bd_addr, gatt_if);
- }
-
+ log::verbose("Connecting without tcb to: {}", bd_addr);
ret = connection_manager::direct_connect_add(gatt_if, bd_addr, addr_type);
}
diff --git a/system/stack/gatt/gatt_int.h b/system/stack/gatt/gatt_int.h
index 70ff37546f..c366c7aca8 100644
--- a/system/stack/gatt/gatt_int.h
+++ b/system/stack/gatt/gatt_int.h
@@ -193,7 +193,6 @@ typedef struct {
uint8_t listening{0}; /* if adv for all has been enabled */
bool eatt_support{false};
std::string name;
- std::set<RawAddress> direct_connect_request;
std::map<RawAddress, uint16_t> mtu_prefs;
} tGATT_REG;
diff --git a/system/stack/gatt/gatt_main.cc b/system/stack/gatt/gatt_main.cc
index 0d8d51d846..b7b9b15bd4 100644
--- a/system/stack/gatt/gatt_main.cc
+++ b/system/stack/gatt/gatt_main.cc
@@ -1004,13 +1004,6 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) {
gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
}
- if (p_reg->direct_connect_request.count(p_tcb->peer_bda) > 0) {
- gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
- log::info("Removing device {} from the direct connect list of gatt_if {}", p_tcb->peer_bda,
- p_reg->gatt_if);
- p_reg->direct_connect_request.erase(p_tcb->peer_bda);
- }
-
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,
@@ -1027,13 +1020,6 @@ static void gatt_send_conn_cback(tGATT_TCB* p_tcb) {
gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
}
- if (p_reg->direct_connect_request.count(p_tcb->peer_bda) > 0) {
- gatt_update_app_use_link_flag(p_reg->gatt_if, p_tcb, true, true);
- log::info("Removing device {} from the direct connect list of gatt_if {}", p_tcb->peer_bda,
- p_reg->gatt_if);
- p_reg->direct_connect_request.erase(p_tcb->peer_bda);
- }
-
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,
diff --git a/system/stack/gatt/gatt_utils.cc b/system/stack/gatt/gatt_utils.cc
index 88ecfe2d53..7ff819a5e0 100644
--- a/system/stack/gatt/gatt_utils.cc
+++ b/system/stack/gatt/gatt_utils.cc
@@ -1581,46 +1581,25 @@ void gatt_sr_update_prep_cnt(tGATT_TCB& tcb, tGATT_IF gatt_if, bool is_inc, bool
}
}
-static bool gatt_is_anybody_interested_in_connection(const RawAddress& bda) {
- if (connection_manager::is_background_connection(bda)) {
- log::debug("{} is in background connection", bda);
- return true;
+/** Cancel LE Create Connection request */
+bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {
+ if (connection_manager::direct_connect_remove(gatt_if, bda)) {
+ log::info("{} was doing direct connect to {}, canceled", gatt_if, bda);
}
-
- for (size_t i = 1; i <= GATT_MAX_APPS; i++) {
- tGATT_REG* p_reg = &gatt_cb.cl_rcb[i - 1];
- if (p_reg->in_use && p_reg->direct_connect_request.count(bda) > 0) {
- log::debug("gatt_if {} interested in connection to {}", i, bda);
- return true;
- }
+ if (connection_manager::background_connect_remove(gatt_if, bda)) {
+ log::info("{} was doing background connect to {}, canceled", gatt_if, bda);
}
- return false;
-}
-/** Cancel LE Create Connection request */
-bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {
tGATT_TCB* p_tcb = gatt_find_tcb_by_addr(bda, BT_TRANSPORT_LE);
if (!p_tcb) {
- /* TCB is not allocated when trying to connect under this flag.
- * but device address is storred in the tGATT_REG. Make sure to remove
- * the address from the list when cancel is called.
- */
-
- tGATT_REG* p_reg = gatt_get_regcb(gatt_if);
- if (!p_reg) {
- log::error("Unable to find registered app gatt_if={}", gatt_if);
- } else {
- log::info("Removing {} from direct list", bda);
- p_reg->direct_connect_request.erase(bda);
- }
- if (!gatt_is_anybody_interested_in_connection(bda)) {
- gatt_cancel_connect(bda, static_cast<tBT_TRANSPORT>(BT_TRANSPORT_LE));
+ if (connection_manager::get_apps_connecting_to(bda).empty()) {
+ gatt_cleanup_upon_disc(bda, GATT_CONN_TERMINATE_LOCAL_HOST, BT_TRANSPORT_LE);
}
return true;
}
if (gatt_get_ch_state(p_tcb) == GATT_CH_OPEN) {
- log::error("link connected Too late to cancel");
+ log::error("link connected too late to cancel {}", bda);
return false;
}
@@ -1632,24 +1611,6 @@ bool gatt_cancel_open(tGATT_IF gatt_if, const RawAddress& bda) {
gatt_disconnect(p_tcb);
}
- if (!connection_manager::direct_connect_remove(gatt_if, bda)) {
- if (!connection_manager::is_background_connection(bda)) {
- if (!com::android::bluetooth::flags::gatt_fix_multiple_direct_connect() ||
- p_tcb->app_hold_link.empty()) {
- bluetooth::shim::ACL_IgnoreLeConnectionFrom(BTM_Sec_GetAddressWithType(bda));
- }
- log::info(
- "Gatt connection manager has no background record but removed "
- "filter acceptlist gatt_if:{} peer:{}",
- gatt_if, bda);
- } else {
- log::info(
- "Gatt connection manager maintains a background record preserving "
- "filter acceptlist gatt_if:{} peer:{}",
- gatt_if, bda);
- }
- }
-
return true;
}
@@ -1830,12 +1791,6 @@ static void gatt_disconnect_complete_notify_user(const RawAddress& bda, tGATT_DI
(*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason,
transport);
}
-
- if (p_reg->direct_connect_request.count(bda) > 0) {
- log::info("Removing device {} from the direct connect list of gatt_if {}", bda,
- p_reg->gatt_if);
- p_reg->direct_connect_request.erase(bda);
- }
}
} else {
for (uint8_t i = 0; i < GATT_MAX_APPS; i++) {
@@ -1846,12 +1801,6 @@ static void gatt_disconnect_complete_notify_user(const RawAddress& bda, tGATT_DI
(*p_reg->app_cb.p_conn_cb)(p_reg->gatt_if, bda, conn_id, kGattDisconnected, reason,
transport);
}
-
- if (p_reg->direct_connect_request.count(bda) > 0) {
- log::info("Removing device {} from the direct connect list of gatt_if {}", bda,
- p_reg->gatt_if);
- p_reg->direct_connect_request.erase(bda);
- }
}
}
}
diff --git a/system/stack/test/gatt/gatt_sr_test.cc b/system/stack/test/gatt/gatt_sr_test.cc
index 285aa23ea8..f61df0833e 100644
--- a/system/stack/test/gatt/gatt_sr_test.cc
+++ b/system/stack/test/gatt/gatt_sr_test.cc
@@ -53,16 +53,6 @@ struct TestMutables {
TestMutables test_state_;
} // namespace
-namespace connection_manager {
-bool background_connect_remove(uint8_t /*app_id*/, const RawAddress& /*address*/) { return false; }
-bool direct_connect_remove(uint8_t /*app_id*/, const RawAddress& /*address*/,
- bool /*connection_timeout*/) {
- return false;
-}
-bool is_background_connection(const RawAddress& /*address*/) { return false; }
-
-} // namespace connection_manager
-
BT_HDR* attp_build_sr_msg(tGATT_TCB& /*tcb*/, uint8_t op_code, tGATT_SR_MSG* /*p_msg*/,
uint16_t /*payload_size*/) {
test_state_.attp_build_sr_msg.op_code_ = op_code;
diff --git a/system/stack/test/gatt/stack_gatt_test.cc b/system/stack/test/gatt/stack_gatt_test.cc
index 71928440a4..9f0cacf48a 100644
--- a/system/stack/test/gatt/stack_gatt_test.cc
+++ b/system/stack/test/gatt/stack_gatt_test.cc
@@ -124,7 +124,6 @@ TEST_F(StackGattTest, lifecycle_tGATT_REG) {
memset(reg0.get(), 0, sizeof(tGATT_REG));
// Restore the complex structure after memset
memset(&reg1.name, 0, sizeof(std::string));
- memset(&reg1.direct_connect_request, 0, sizeof(std::set<RawAddress>));
memset(&reg1.mtu_prefs, 0, sizeof(std::map<RawAddress, uint16_t>));
reg1 = {};
ASSERT_EQ(0, memcmp(reg0.get(), &reg1, actual_sizeof_tGATT_REG()));