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

Commit ded0c10e authored by Chris Manton's avatar Chris Manton
Browse files

Execute channel fail callbacks when link not up

When a user requests a channel to a device but the link
is not up, the request sits in a pending queue until
the link is complete.

Should the link not complete successfully, the user
needs to be notified that the channel connection
failed.

Bug: 141758481
Test: Verified callback completes on real device when timeout failure
Change-Id: I6ea887db30bfe9c9762756cf3c28c68e2e088b8f
parent 0ab955fc
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -90,8 +90,10 @@ void LinkManager::ConnectDynamicChannelServices(hci::Address device,
    acl_manager_->CreateConnection(device);
    if (pending_dynamic_channels_.find(device) != pending_dynamic_channels_.end()) {
      pending_dynamic_channels_[device].push_back(psm);
      pending_dynamic_channels_callbacks_[device].push_back(std::move(pending_dynamic_channel_connection));
    } else {
      pending_dynamic_channels_[device] = {psm};
      pending_dynamic_channels_callbacks_[device].push_back(std::move(pending_dynamic_channel_connection));
    }
    return;
  }
@@ -130,6 +132,7 @@ void LinkManager::OnConnectSuccess(std::unique_ptr<hci::AclConnection> acl_conne
      link->SendConnectionRequest(psm, link->ReserveDynamicChannel());
    }
    pending_dynamic_channels_.erase(device);
    pending_dynamic_channels_callbacks_.erase(device);
  }
  // Remove device from pending links list, if any
  auto pending_link = pending_links_.find(device);
@@ -147,6 +150,16 @@ void LinkManager::OnConnectFail(hci::Address device, hci::ErrorCode reason) {
  if (pending_link == pending_links_.end()) {
    // There is no pending link, exit
    LOG_DEBUG("Connection to %s failed without a pending link", device.ToString().c_str());
    if (pending_dynamic_channels_callbacks_.find(device) != pending_dynamic_channels_callbacks_.end()) {
      for (PendingDynamicChannelConnection& callbacks : pending_dynamic_channels_callbacks_[device]) {
        callbacks.handler_->Post(common::BindOnce(std::move(callbacks.on_fail_callback_),
                                                  DynamicChannelManager::ConnectionResult{
                                                      .hci_error = hci::ErrorCode::CONNECTION_TIMEOUT,
                                                  }));
      }
      pending_dynamic_channels_.erase(device);
      pending_dynamic_channels_callbacks_.erase(device);
    }
    return;
  }
  for (auto& pending_fixed_channel_connection : pending_link->second.pending_fixed_channel_connections_) {
+1 −0
Original line number Diff line number Diff line
@@ -90,6 +90,7 @@ class LinkManager : public hci::ConnectionCallbacks {
  std::unordered_map<hci::Address, PendingLink> pending_links_;
  std::unordered_map<hci::Address, Link> links_;
  std::unordered_map<hci::Address, std::list<Psm>> pending_dynamic_channels_;
  std::unordered_map<hci::Address, std::list<PendingDynamicChannelConnection>> pending_dynamic_channels_callbacks_;
  DISALLOW_COPY_AND_ASSIGN(LinkManager);
};