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

Commit db85eae2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Race condition handling when connection happens after cancel" into tm-dev

parents 8162a915 e344bb42
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -78,6 +78,12 @@ class LeAclConnection : public AclConnection {
  // Time Range: 100 ms to 32 s
  uint16_t supervision_timeout_;

  // True if connection address was in the filter accept list, false otherwise
  bool in_filter_accept_list_;
  bool IsInFilterAcceptList() const {
    return in_filter_accept_list_;
  }

  Address local_resolvable_private_address_ = Address::kEmpty;
  Address peer_resolvable_private_address_ = Address::kEmpty;

+4 −0
Original line number Diff line number Diff line
@@ -308,6 +308,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {

    arm_on_resume_ = false;
    ready_to_unregister = true;
    const bool in_filter_accept_list = is_device_in_connect_list(remote_address);
    remove_device_from_connect_list(remote_address);

    if (!connect_list.empty()) {
@@ -345,6 +346,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    connection->interval_ = conn_interval;
    connection->latency_ = conn_latency;
    connection->supervision_timeout_ = supervision_timeout;
    connection->in_filter_accept_list_ = in_filter_accept_list;
    connections.add(
        handle, remote_address, queue_down_end, handler_, connection->GetEventCallbacks([this](uint16_t handle) {
          this->connections.invalidate(handle);
@@ -393,6 +395,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {

    arm_on_resume_ = false;
    ready_to_unregister = true;
    const bool in_filter_accept_list = is_device_in_connect_list(remote_address);
    remove_device_from_connect_list(remote_address);

    if (!connect_list.empty()) {
@@ -440,6 +443,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    connection->supervision_timeout_ = supervision_timeout;
    connection->local_resolvable_private_address_ = connection_complete.GetLocalResolvablePrivateAddress();
    connection->peer_resolvable_private_address_ = connection_complete.GetPeerResolvablePrivateAddress();
    connection->in_filter_accept_list_ = in_filter_accept_list;
    connections.add(
        handle, remote_address, queue_down_end, handler_, connection->GetEventCallbacks([this](uint16_t handle) {
          this->connections.invalidate(handle);
+20 −6
Original line number Diff line number Diff line
@@ -779,6 +779,10 @@ class LeShimAclConnection
    return connection_->locally_initiated_;
  }

  bool IsInFilterAcceptList() const {
    return connection_->IsInFilterAcceptList();
  }

 private:
  OnDisconnect on_disconnect_;
  const shim::legacy::acl_le_link_interface_t interface_;
@@ -1522,12 +1526,6 @@ void shim::legacy::Acl::OnLeConnectSuccess(
                  std::chrono::system_clock::now()));
  pimpl_->handle_to_le_connection_map_[handle]->RegisterCallbacks();

  pimpl_->handle_to_le_connection_map_[handle]
      ->ReadRemoteControllerInformation();

  tBLE_BD_ADDR legacy_address_with_type =
      ToLegacyAddressWithType(address_with_type);

  // Once an le connection has successfully been established
  // the device address is removed from the controller accept list.

@@ -1542,6 +1540,22 @@ void shim::legacy::Acl::OnLeConnectSuccess(
    pimpl_->shadow_acceptlist_.Remove(address_with_type);
  }

  if (!pimpl_->handle_to_le_connection_map_[handle]->IsInFilterAcceptList() &&
      connection_role == hci::Role::CENTRAL) {
    pimpl_->handle_to_le_connection_map_[handle]->InitiateDisconnect(
        hci::DisconnectReason::REMOTE_USER_TERMINATED_CONNECTION);
    LOG_INFO("Disconnected ACL after connection canceled");
    BTM_LogHistory(kBtmLogTag, ToLegacyAddressWithType(address_with_type),
                   "Connection canceled", "Le");
    return;
  }

  pimpl_->handle_to_le_connection_map_[handle]
      ->ReadRemoteControllerInformation();

  tBLE_BD_ADDR legacy_address_with_type =
      ToLegacyAddressWithType(address_with_type);

  TRY_POSTING_ON_MAIN(
      acl_interface_.connection.le.on_connected, legacy_address_with_type,
      handle, ToLegacyRole(connection_role), conn_interval, conn_latency,