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

Commit 1cca469c authored by Chienyuan's avatar Chienyuan Committed by Chienyuan Huang
Browse files

Re-add device to connect list if it's in the background connect list

Tag: #gd-refactor
Bug: 220970000
Test: gd/cert/run
Change-Id: I8916be0788bd957c550fd9f8d55d33548eb17549
parent 5a930ed9
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -191,6 +191,16 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
      }
      return kIllegalConnectionHandle;
    }

    AddressWithType getAddressWithType(uint16_t handle) {
      std::unique_lock<std::mutex> lock(le_acl_connections_guard_);
      auto it = le_acl_connections_.find(handle);
      if (it != le_acl_connections_.end()) {
        return it->second.remote_address_;
      }
      AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS);
      return empty;
    }
  } connections;

 public:
@@ -359,6 +369,11 @@ 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(
@@ -369,6 +384,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
        },
        kRemoveConnectionAfterwards);
    connections.crash_on_unknown_handle_ = event_also_routes_to_other_receivers;
    if (!connect_list.empty()) {
      LOG_INFO("connect_list is not empty, send a new connection request");
      AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS);
      create_le_connection(empty, false, false);
    }
  }

  void on_le_connection_update_complete(LeMetaEventView view) {