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

Commit d83e8199 authored by Abhishek Pandit-Subedi's avatar Abhishek Pandit-Subedi
Browse files

floss: Trigger OnDisconnection during suspend

When suspending, we do ACL disconnection of all devices. Depending on
the firmware implementation, the actual HCI Disconnection event can be
emitted immediately afterwards or after the link layer disconnects. To
speed up suspend, we will mask out the HCI Disconnection event and
simply run the `OnDisconnection` method right away.

Bug: 231435700
Tag: #floss
Test: Manual test on ChromeOS
Change-Id: If74b15562e224850aeac02a22e5a24b4d25a9a88
parent 5457ff2c
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -842,10 +842,26 @@ struct shim::legacy::Acl::impl {

  void DisconnectClassicConnections(std::promise<void> promise) {
    LOG_INFO("Disconnect gd acl shim classic connections");
    std::vector<HciHandle> disconnect_handles;
    for (auto& connection : handle_to_classic_connection_map_) {
      disconnect_classic(connection.first, HCI_ERR_REMOTE_POWER_OFF,
                         "Suspend disconnect");
      disconnect_handles.push_back(connection.first);
    }

    // Since this is a suspend disconnect, we immediately also call
    // |OnDisconnection| without waiting for it to happen. We want the stack
    // to clean up ahead of the link layer (since we will mask away that
    // event). The reason we do this in a separate loop is that this will also
    // remove the handle from the connection map.
    for (auto& handle : disconnect_handles) {
      auto found = handle_to_classic_connection_map_.find(handle);
      if (found != handle_to_classic_connection_map_.end()) {
        found->second->OnDisconnection(
            hci::ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST);
      }
    }

    promise.set_value();
  }

@@ -860,9 +876,24 @@ struct shim::legacy::Acl::impl {

  void DisconnectLeConnections(std::promise<void> promise) {
    LOG_INFO("Disconnect gd acl shim le connections");
    std::vector<HciHandle> disconnect_handles;
    for (auto& connection : handle_to_le_connection_map_) {
      disconnect_le(connection.first, HCI_ERR_REMOTE_POWER_OFF,
                    "Suspend disconnect");
      disconnect_handles.push_back(connection.first);
    }

    // Since this is a suspend disconnect, we immediately also call
    // |OnDisconnection| without waiting for it to happen. We want the stack
    // to clean up ahead of the link layer (since we will mask away that
    // event). The reason we do this in a separate loop is that this will also
    // remove the handle from the connection map.
    for (auto& handle : disconnect_handles) {
      auto found = handle_to_le_connection_map_.find(handle);
      if (found != handle_to_le_connection_map_.end()) {
        found->second->OnDisconnection(
            hci::ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST);
      }
    }
    promise.set_value();
  }