Loading system/gd/hci/acl_manager/le_impl.h +34 −16 Original line number Diff line number Diff line Loading @@ -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(); } Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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) { Loading @@ -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_) { Loading @@ -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; }; Loading system/gd/hci/acl_manager_test.cc +9 −5 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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); Loading Loading
system/gd/hci/acl_manager/le_impl.h +34 −16 Original line number Diff line number Diff line Loading @@ -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(); } Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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) { Loading @@ -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) { Loading @@ -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_) { Loading @@ -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; }; Loading
system/gd/hci/acl_manager_test.cc +9 −5 Original line number Diff line number Diff line Loading @@ -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( Loading Loading @@ -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); Loading