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

Commit a9cffb25 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "GD: Add background connection list for LE" am: 6071f99f am: e7b41d08 am: 8522dd6b

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1862714

Change-Id: Idff3b654546888eff229a23b9ab2c84591a43f06
parents 500971a6 8522dd6b
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -160,6 +160,9 @@ void AclManager::CreateConnection(Address address) {
}
}


void AclManager::CreateLeConnection(AddressWithType address_with_type, bool is_direct) {
void AclManager::CreateLeConnection(AddressWithType address_with_type, bool is_direct) {
  if (!is_direct) {
    CallOn(pimpl_->le_impl_, &le_impl::add_device_to_background_connection_list, address_with_type);
  }
  CallOn(pimpl_->le_impl_, &le_impl::create_le_connection, address_with_type, true, is_direct);
  CallOn(pimpl_->le_impl_, &le_impl::create_le_connection, address_with_type, true, is_direct);
}
}


@@ -209,6 +212,7 @@ void AclManager::CancelConnect(Address address) {
}
}


void AclManager::CancelLeConnect(AddressWithType address_with_type) {
void AclManager::CancelLeConnect(AddressWithType address_with_type) {
  CallOn(pimpl_->le_impl_, &le_impl::remove_device_from_background_connection_list, address_with_type);
  CallOn(pimpl_->le_impl_, &le_impl::cancel_connect, address_with_type);
  CallOn(pimpl_->le_impl_, &le_impl::cancel_connect, address_with_type);
}
}


+26 −1
Original line number Original line Diff line number Diff line
@@ -159,6 +159,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    if (status == ErrorCode::UNKNOWN_CONNECTION && pause_connection) {
    if (status == ErrorCode::UNKNOWN_CONNECTION && pause_connection) {
      // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
      // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
      return;
      return;
    } else if (status == ErrorCode::UNKNOWN_CONNECTION && remote_address.GetAddress() == Address::kEmpty) {
      // direct connect canceled due to connection timeout, start background connect
      create_le_connection(remote_address, false, false);
      return;
    } else {
    } else {
      canceled_connections_.erase(remote_address);
      canceled_connections_.erase(remote_address);
      ready_to_unregister = true;
      ready_to_unregister = true;
@@ -217,6 +221,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    if (status == ErrorCode::UNKNOWN_CONNECTION && pause_connection) {
    if (status == ErrorCode::UNKNOWN_CONNECTION && pause_connection) {
      // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
      // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume()
      return;
      return;
    } else if (status == ErrorCode::UNKNOWN_CONNECTION && remote_address.GetAddress() == Address::kEmpty) {
      // direct connect canceled due to connection timeout, start background connect
      create_le_connection(remote_address, false, false);
      return;
    } else {
    } else {
      canceled_connections_.erase(remote_address);
      canceled_connections_.erase(remote_address);
      ready_to_unregister = true;
      ready_to_unregister = true;
@@ -547,7 +555,14 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
    if (create_connection_timeout_alarms_.find(address_with_type) != create_connection_timeout_alarms_.end()) {
      create_connection_timeout_alarms_.at(address_with_type).Cancel();
      create_connection_timeout_alarms_.at(address_with_type).Cancel();
      create_connection_timeout_alarms_.erase(address_with_type);
      create_connection_timeout_alarms_.erase(address_with_type);
      if (background_connections_.find(address_with_type) != background_connections_.end()) {
        direct_connections_.erase(address_with_type);
        le_acl_connection_interface_->EnqueueCommand(
            LeCreateConnectionCancelBuilder::Create(),
            handler_->BindOnce(&le_impl::on_create_connection_cancel_complete, common::Unretained(this)));
      } else {
        cancel_connect(address_with_type);
        cancel_connect(address_with_type);
      }
      le_client_handler_->Post(common::BindOnce(
      le_client_handler_->Post(common::BindOnce(
          &LeConnectionCallbacks::OnLeConnectFail,
          &LeConnectionCallbacks::OnLeConnectFail,
          common::Unretained(le_client_callbacks_),
          common::Unretained(le_client_callbacks_),
@@ -667,6 +682,14 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
    return true;
    return true;
  }
  }


  void add_device_to_background_connection_list(AddressWithType address_with_type) {
    background_connections_.insert(address_with_type);
  }

  void remove_device_from_background_connection_list(AddressWithType address_with_type) {
    background_connections_.erase(address_with_type);
  }

  void OnPause() override {
  void OnPause() override {
    pause_connection = true;
    pause_connection = true;
    if (connecting_le_.empty()) {
    if (connecting_le_.empty()) {
@@ -743,6 +766,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback {
  std::set<AddressWithType> connecting_le_;
  std::set<AddressWithType> connecting_le_;
  std::set<AddressWithType> canceled_connections_;
  std::set<AddressWithType> canceled_connections_;
  std::set<AddressWithType> direct_connections_;
  std::set<AddressWithType> direct_connections_;
  // Set of devices that will not be removed from connect list after direct connect timeout
  std::set<AddressWithType> background_connections_;
  bool address_manager_registered = false;
  bool address_manager_registered = false;
  bool ready_to_unregister = false;
  bool ready_to_unregister = false;
  bool pause_connection = false;
  bool pause_connection = false;