summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--system/gd/hci/acl_manager/le_impl.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/system/gd/hci/acl_manager/le_impl.h b/system/gd/hci/acl_manager/le_impl.h
index c1c5ff732b..a16baf76a6 100644
--- a/system/gd/hci/acl_manager/le_impl.h
+++ b/system/gd/hci/acl_manager/le_impl.h
@@ -201,6 +201,16 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS);
return empty;
}
+
+ bool alreadyConnected(AddressWithType address_with_type) {
+ for (auto it = le_acl_connections_.begin(); it != le_acl_connections_.end(); it++) {
+ if (it->second.remote_address_ == address_with_type) {
+ return true;
+ }
+ }
+ return false;
+ }
+
} connections;
public:
@@ -370,10 +380,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
static constexpr bool kRemoveConnectionAfterwards = true;
void on_le_disconnect(uint16_t handle, ErrorCode reason) {
AddressWithType remote_address = connections.getAddressWithType(handle);
- if (background_connections_.count(remote_address) == 1) {
- LOG_INFO("re-add device to connect list");
- add_device_to_connect_list(remote_address);
- }
bool event_also_routes_to_other_receivers = connections.crash_on_unknown_handle_;
connections.crash_on_unknown_handle_ = false;
connections.execute(
@@ -384,6 +390,12 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
},
kRemoveConnectionAfterwards);
connections.crash_on_unknown_handle_ = event_also_routes_to_other_receivers;
+
+ if (background_connections_.count(remote_address) == 1) {
+ LOG_INFO("re-add device to connect list");
+ add_device_to_connect_list(remote_address);
+ }
+
if (!connect_list.empty()) {
LOG_INFO("connect_list is not empty, send a new connection request");
AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS);
@@ -477,6 +489,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
}
void add_device_to_connect_list(AddressWithType address_with_type) {
+ if (connections.alreadyConnected(address_with_type)) {
+ LOG_INFO("Device already connected, return");
+ return;
+ }
+
connect_list.insert(address_with_type);
register_with_address_manager();
le_address_manager_->AddDeviceToConnectList(
@@ -528,6 +545,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
return;
}
+ if (connections.alreadyConnected(address_with_type)) {
+ LOG_INFO("Device already connected, return");
+ return;
+ }
+
// TODO: Configure default LE connection parameters?
if (add_to_connect_list) {
add_device_to_connect_list(address_with_type);