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

Commit 2ec0d50c authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "gd HCI: Only register LeAddressRotator when connecting"

parents e6fefdbb a7126f51
Loading
Loading
Loading
Loading
+34 −16
Original line number Diff line number Diff line
@@ -60,7 +60,9 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
    for (auto subevent_code : LeConnectionManagementEvents) {
      hci_layer_->UnregisterLeEventHandler(subevent_code);
    }
    if (address_rotator_registered) {
      le_address_rotator_->Unregister(this);
    }
    delete le_address_rotator_;
    le_acl_connections_.clear();
  }
@@ -114,8 +116,12 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
        canceled_connections_.find(remote_address) != canceled_connections_.end()) {
      // connection canceled by LeAddressRotator.OnPause(), will auto reconnect by LeAddressRotator.OnResume()
      return;
    } else if (status != ErrorCode::SUCCESS) {
    } else {
      canceled_connections_.erase(remote_address);
    }

    if (status != ErrorCode::SUCCESS) {
      check_for_unregister();
      le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectFail,
                                                common::Unretained(le_client_callbacks_), remote_address, status));
      return;
@@ -157,8 +163,12 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
        canceled_connections_.find(remote_address) != canceled_connections_.end()) {
      // connection canceled by LeAddressRotator.OnPause(), will auto reconnect by LeAddressRotator.OnResume()
      return;
    } else if (status != ErrorCode::SUCCESS) {
    } else {
      canceled_connections_.erase(remote_address);
    }

    if (status != ErrorCode::SUCCESS) {
      check_for_unregister();
      le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectFail,
                                                common::Unretained(le_client_callbacks_), remote_address, status));
      return;
@@ -240,6 +250,11 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
    uint16_t supervision_timeout = 0x001f4;
    ASSERT(le_client_callbacks_ != nullptr);

    if (!address_rotator_registered) {
      le_address_rotator_->Register(this);
      address_rotator_registered = true;
    }

    if (pause_connection) {
      canceled_connections_.insert(address_with_type);
      return;
@@ -286,8 +301,6 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
                                                std::chrono::milliseconds maximum_rotation_time) {
    le_address_rotator_->SetPrivacyPolicyForInitiatorAddress(address_policy, fixed_address, rotation_irk,
                                                             minimum_rotation_time, maximum_rotation_time);
    // Policy must be set before clients are registered.
    le_address_rotator_->Register(this);
  }

  void handle_register_le_callbacks(LeConnectionCallbacks* callbacks, os::Handler* handler) {
@@ -304,20 +317,15 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
  }

  void OnPause() override {
    if (pause_connection) {
    pause_connection = true;
    if (connecting_le_.empty()) {
      le_address_rotator_->AckPause(this);
      return;
    }

    pause_connection = true;
    if (!connecting_le_.empty()) {
    canceled_connections_ = connecting_le_;
    le_acl_connection_interface_->EnqueueCommand(
        LeCreateConnectionCancelBuilder::Create(),
        handler_->BindOnce(&le_impl::on_create_connection_cancel_complete, common::Unretained(this)));
    } else {
      le_address_rotator_->AckPause(this);
    }
  }

  void on_create_connection_cancel_complete(CommandCompleteView view) {
@@ -327,6 +335,15 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
    le_address_rotator_->AckPause(this);
  }

  void check_for_unregister() {
    if (le_acl_connections_.empty() && connecting_le_.empty() && canceled_connections_.empty() &&
        address_rotator_registered) {
      le_address_rotator_->Unregister(this);
      address_rotator_registered = false;
      pause_connection = false;
    }
  }

  void OnResume() override {
    pause_connection = false;
    for (auto address_with_type : canceled_connections_) {
@@ -350,6 +367,7 @@ struct le_impl : public bluetooth::hci::LeAddressRotatorCallback {
  std::set<AddressWithType> connecting_le_;
  std::set<AddressWithType> canceled_connections_;
  DisconnectorForLe* disconnector_;
  bool address_rotator_registered = false;
  bool pause_connection = false;
};

+9 −5
Original line number Diff line number Diff line
@@ -299,12 +299,17 @@ class AclManagerNoCallbacksTest : public ::testing::Test {
    Address::FromString("A1:A2:A3:A4:A5:A6", remote);

    // Verify LE Set Random Address was sent during setup
    hci::AddressWithType address_with_type(hci::Address::kEmpty, hci::AddressType::RANDOM_DEVICE_ADDRESS);
    hci::Address address;
    Address::FromString("D0:05:04:03:02:01", address);
    hci::AddressWithType address_with_type(address, hci::AddressType::RANDOM_DEVICE_ADDRESS);
    crypto_toolbox::Octet16 irk = {};
    auto minimum_rotation_time = std::chrono::milliseconds(7 * 60 * 1000);
    auto maximum_rotation_time = std::chrono::milliseconds(15 * 60 * 1000);
    acl_manager_->SetPrivacyPolicyForInitiatorAddress(LeAddressRotator::AddressPolicy::USE_RESOLVABLE_ADDRESS,
                                                      address_with_type, irk, minimum_rotation_time,
    acl_manager_->SetPrivacyPolicyForInitiatorAddress(
        LeAddressRotator::AddressPolicy::USE_STATIC_ADDRESS,
        address_with_type,
        irk,
        minimum_rotation_time,
        maximum_rotation_time);

    auto set_random_address_packet = LeSetRandomAddressView::Create(
@@ -611,7 +616,6 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) {
  AddressWithType remote_with_type(remote, AddressType::PUBLIC_DEVICE_ADDRESS);
  test_hci_layer_->SetCommandFuture();
  acl_manager_->CreateLeConnection(remote_with_type);

  auto packet = test_hci_layer_->GetCommandPacket(OpCode::LE_CREATE_CONNECTION);
  auto le_connection_management_command_view = LeConnectionManagementCommandView::Create(packet);
  auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view);