Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 77fb5af0 authored by Chienyuan's avatar Chienyuan
Browse files

Do not add connected device to accept list

Bug: 224138393
Test: gd/cert/run
Tag: #refactor
Change-Id: Ia24da9c9be7b81b5369e0b7411889c2ec081baa1
parent d16fa3a5
Loading
Loading
Loading
Loading
+26 −4
Original line number Diff line number Diff line
@@ -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);