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

Commit cb040141 authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

Only send connect request if one is not outstanding am: bb41eac3 am: f2719774

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1971443

Change-Id: Ic9cb94fcfbbe8823de87e8a30cc2712dd9209996
parents fdaed25c f2719774
Loading
Loading
Loading
Loading
+50 −44
Original line number Diff line number Diff line
@@ -301,31 +301,33 @@ struct classic_impl : public security::ISecurityManagerListener {
    ASSERT(connection_complete.IsValid());
    auto status = connection_complete.GetStatus();
    auto address = connection_complete.GetBdAddr();
    if (client_callbacks_ == nullptr) {
      LOG_WARN("No client callbacks registered for connection");
      return;
    }
    Role current_role = Role::CENTRAL;
    bool locally_initiated = true;
    if (outgoing_connecting_address_ == address) {
      outgoing_connecting_address_ = Address::kEmpty;
    } else {
      locally_initiated = false;
      if (incoming_connecting_address_ != address && status == ErrorCode::UNKNOWN_CONNECTION) {
        LOG_WARN("No matching connection to %s (%s)", address.ToString().c_str(), ErrorCodeText(status).c_str());
        LOG_WARN("Firmware error after RemoteNameRequestCancel?");
        return;
      }
      ASSERT_LOG(incoming_connecting_address_ == address, "No prior connection request for %s",
                 address.ToString().c_str());
      ASSERT_LOG(
          incoming_connecting_address_ == address,
          "No prior connection request for %s expecting:%s",
          address.ToString().c_str(),
          incoming_connecting_address_.ToString().c_str());
      incoming_connecting_address_ = Address::kEmpty;
      current_role = Role::PERIPHERAL;
    }
    if (client_callbacks_ == nullptr) {
      LOG_WARN("No client callbacks registered for connection");
      return;
      locally_initiated = false;
    }
    if (status != ErrorCode::SUCCESS) {
      client_handler_->Post(common::BindOnce(&ConnectionCallbacks::OnConnectFail, common::Unretained(client_callbacks_),
                                             address, status));
      return;
    }
    } else {
      uint16_t handle = connection_complete.GetConnectionHandle();
      auto queue = std::make_shared<AclConnection::Queue>(10);
      auto queue_down_end = queue->GetDownEnd();
@@ -348,15 +350,18 @@ struct classic_impl : public security::ISecurityManagerListener {
          delayed_role_change_.reset();
        }
      });
    client_handler_->Post(common::BindOnce(&ConnectionCallbacks::OnConnectSuccess,
                                           common::Unretained(client_callbacks_), std::move(connection)));
      client_handler_->Post(common::BindOnce(
          &ConnectionCallbacks::OnConnectSuccess, common::Unretained(client_callbacks_), std::move(connection)));
    }
    if (outgoing_connecting_address_.IsEmpty()) {
      while (!pending_outgoing_connections_.empty()) {
        LOG_INFO("Pending connections is not empty; so sending next connection");
        auto create_connection_packet_and_address = std::move(pending_outgoing_connections_.front());
        pending_outgoing_connections_.pop();
        if (!is_classic_link_already_connected(create_connection_packet_and_address.first)) {
          outgoing_connecting_address_ = create_connection_packet_and_address.first;
        acl_connection_interface_->EnqueueCommand(std::move(create_connection_packet_and_address.second),
                                                  handler_->BindOnce([](CommandStatusView status) {
          acl_connection_interface_->EnqueueCommand(
              std::move(create_connection_packet_and_address.second), handler_->BindOnce([](CommandStatusView status) {
                ASSERT(status.IsValid());
                ASSERT(status.GetCommandOpCode() == OpCode::CREATE_CONNECTION);
              }));
@@ -364,6 +369,7 @@ struct classic_impl : public security::ISecurityManagerListener {
        }
      }
    }
  }

  void cancel_connect(Address address) {
    if (outgoing_connecting_address_ == address) {