Loading system/gd/hci/acl_manager.cc +5 −5 Original line number Diff line number Diff line Loading @@ -443,7 +443,7 @@ AclManager::~AclManager() = default; void AclManager::impl::Dump( std::promise<flatbuffers::Offset<AclManagerData>> promise, flatbuffers::FlatBufferBuilder* fb_builder) const { const std::lock_guard<std::mutex> lock(dumpsys_mutex_); const auto connect_list = (le_impl_ != nullptr) ? le_impl_->connect_list : std::unordered_set<AddressWithType>(); const auto accept_list = (le_impl_ != nullptr) ? le_impl_->accept_list : std::unordered_set<AddressWithType>(); const auto le_connectability_state_text = (le_impl_ != nullptr) ? connectability_state_machine_text(le_impl_->connectability_state_) : "INDETERMINATE"; const auto le_create_connection_timeout_alarms_count = Loading @@ -452,17 +452,17 @@ void AclManager::impl::Dump( auto title = fb_builder->CreateString("----- Acl Manager Dumpsys -----"); auto le_connectability_state = fb_builder->CreateString(le_connectability_state_text); flatbuffers::Offset<flatbuffers::String> strings[connect_list.size()]; flatbuffers::Offset<flatbuffers::String> strings[accept_list.size()]; size_t cnt = 0; for (const auto& it : connect_list) { for (const auto& it : accept_list) { strings[cnt++] = fb_builder->CreateString(it.ToString()); } auto vecofstrings = fb_builder->CreateVector(strings, connect_list.size()); auto vecofstrings = fb_builder->CreateVector(strings, accept_list.size()); AclManagerDataBuilder builder(*fb_builder); builder.add_title(title); builder.add_le_filter_accept_list_count(connect_list.size()); builder.add_le_filter_accept_list_count(accept_list.size()); builder.add_le_filter_accept_list(vecofstrings); builder.add_le_connectability_state(le_connectability_state); builder.add_le_create_connection_timeout_alarms_count(le_create_connection_timeout_alarms_count); Loading system/gd/hci/acl_manager/le_impl.h +32 −31 Original line number Diff line number Diff line Loading @@ -345,7 +345,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { auto role = connection_complete.GetRole(); AddressWithType remote_address(address, peer_address_type); AddressWithType local_address = le_address_manager_->GetInitiatorAddress(); const bool in_filter_accept_list = is_device_in_connect_list(remote_address); const bool in_filter_accept_list = is_device_in_accept_list(remote_address); if (role == hci::Role::CENTRAL) { connectability_state_ = ConnectabilityState::DISARMED; Loading @@ -371,9 +371,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { arm_on_resume_ = false; ready_to_unregister = true; remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (!connect_list.empty()) { if (!accept_list.empty()) { AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS); handler_->Post(common::BindOnce(&le_impl::create_le_connection, common::Unretained(this), empty, false, false)); } Loading Loading @@ -405,7 +405,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { LOG_INFO( "Received incoming connection of device in filter accept_list, %s", ADDRESS_TO_LOGGABLE_CSTR(remote_address)); remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(remote_address).Cancel(); create_connection_timeout_alarms_.erase(remote_address); Loading Loading @@ -486,7 +486,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { break; } AddressWithType remote_address(address, remote_address_type); const bool in_filter_accept_list = is_device_in_connect_list(remote_address); const bool in_filter_accept_list = is_device_in_accept_list(remote_address); if (role == hci::Role::CENTRAL) { Loading @@ -510,9 +510,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { arm_on_resume_ = false; ready_to_unregister = true; remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (!connect_list.empty()) { if (!accept_list.empty()) { AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS); handler_->Post(common::BindOnce(&le_impl::create_le_connection, common::Unretained(this), empty, false, false)); } Loading Loading @@ -545,7 +545,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { LOG_INFO( "Received incoming connection of device in filter accept_list, %s", ADDRESS_TO_LOGGABLE_CSTR(remote_address)); remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(remote_address).Cancel(); create_connection_timeout_alarms_.erase(remote_address); Loading Loading @@ -646,9 +646,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { connections.crash_on_unknown_handle_ = event_also_routes_to_other_receivers; if (background_connections_.count(remote_address) == 1) { LOG_INFO("re-add device to connect list"); LOG_INFO("re-add device to accept list"); arm_on_resume_ = true; add_device_to_connect_list(remote_address); add_device_to_accept_list(remote_address); } } Loading Loading @@ -768,37 +768,37 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } } void add_device_to_connect_list(AddressWithType address_with_type) { void add_device_to_accept_list(AddressWithType address_with_type) { if (connections.alreadyConnected(address_with_type)) { LOG_INFO("Device already connected, return"); return; } if (connect_list.find(address_with_type) != connect_list.end()) { if (accept_list.find(address_with_type) != accept_list.end()) { LOG_WARN( "Device already exists in acceptlist and cannot be added: %s", ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } connect_list.insert(address_with_type); accept_list.insert(address_with_type); register_with_address_manager(); le_address_manager_->AddDeviceToFilterAcceptList( address_with_type.ToFilterAcceptListAddressType(), address_with_type.GetAddress()); } bool is_device_in_connect_list(AddressWithType address_with_type) { return (connect_list.find(address_with_type) != connect_list.end()); bool is_device_in_accept_list(AddressWithType address_with_type) { return (accept_list.find(address_with_type) != accept_list.end()); } void remove_device_from_connect_list(AddressWithType address_with_type) { if (connect_list.find(address_with_type) == connect_list.end()) { void remove_device_from_accept_list(AddressWithType address_with_type) { if (accept_list.find(address_with_type) == accept_list.end()) { LOG_WARN( "Device not in acceptlist and cannot be removed: %s", ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } connect_list.erase(address_with_type); accept_list.erase(address_with_type); connecting_le_.erase(address_with_type); direct_connections_.erase(address_with_type); register_with_address_manager(); Loading @@ -807,7 +807,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } void clear_filter_accept_list() { connect_list.clear(); accept_list.clear(); register_with_address_manager(); le_address_manager_->ClearFilterAcceptList(); } Loading Loading @@ -879,13 +879,13 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { connectability_state_machine_text(connectability_state_).c_str()); return; } if (connect_list.empty()) { if (accept_list.empty()) { LOG_INFO("Ignored request to re-arm le connection state machine when filter accept list is empty"); return; } AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS); connectability_state_ = ConnectabilityState::ARMING; connecting_le_ = connect_list; connecting_le_ = accept_list; uint16_t le_scan_interval = os::GetSystemPropertyUint32(kPropertyConnScanIntervalSlow, kScanIntervalSlow); uint16_t le_scan_window = os::GetSystemPropertyUint32(kPropertyConnScanWindowSlow, kScanWindowSlow); Loading Loading @@ -1014,7 +1014,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } } void create_le_connection(AddressWithType address_with_type, bool add_to_connect_list, bool is_direct) { void create_le_connection(AddressWithType address_with_type, bool add_to_accept_list, bool is_direct) { if (le_client_callbacks_ == nullptr) { LOG_ERROR("No callbacks to call"); return; Loading @@ -1025,11 +1025,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { return; } bool already_in_connect_list = connect_list.find(address_with_type) != connect_list.end(); bool already_in_accept_list = accept_list.find(address_with_type) != accept_list.end(); // TODO: Configure default LE connection parameters? if (add_to_connect_list) { if (!already_in_connect_list) { add_device_to_connect_list(address_with_type); if (add_to_accept_list) { if (!already_in_accept_list) { add_device_to_accept_list(address_with_type); } if (is_direct) { Loading Loading @@ -1068,7 +1068,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { switch (connectability_state_) { case ConnectabilityState::ARMED: case ConnectabilityState::ARMING: if (already_in_connect_list) { if (already_in_accept_list) { arm_on_disarm_ = true; disarm_connectability(); } else { Loading @@ -1082,7 +1082,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { default: // If we added to filter accept list then the arming of the le state machine // must wait until the filter accept list command as completed if (add_to_connect_list) { if (add_to_accept_list) { arm_on_resume_ = true; LOG_DEBUG("Deferred until filter accept list has completed"); } else { Loading Loading @@ -1120,7 +1120,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { create_connection_timeout_alarms_.erase(address_with_type); } // the connection will be canceled by LeAddressManager.OnPause() remove_device_from_connect_list(address_with_type); remove_device_from_accept_list(address_with_type); } void set_le_suggested_default_data_parameters(uint16_t length, uint16_t time) { Loading Loading @@ -1315,9 +1315,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { bool arm_on_resume_{}; bool arm_on_disarm_{}; std::unordered_set<AddressWithType> direct_connections_{}; // Set of devices that will not be removed from connect list after direct connect timeout // Set of devices that will not be removed from accept list after direct connect timeout std::unordered_set<AddressWithType> background_connections_; std::unordered_set<AddressWithType> connect_list; /* This is content of controller "Filter Accept List"*/ std::unordered_set<AddressWithType> accept_list; AddressWithType connection_peer_address_with_type_; // Direct peer address UNSUPPORTEDD bool address_manager_registered = false; bool ready_to_unregister = false; Loading system/gd/hci/acl_manager/le_impl_test.cc +26 −26 Original line number Diff line number Diff line Loading @@ -461,42 +461,42 @@ class LeImplWithConnectionTest : public LeImplTest { std::unique_ptr<LeAclConnection> connection_; }; TEST_F(LeImplTest, add_device_to_connect_list) { le_impl_->add_device_to_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(1UL, le_impl_->connect_list.size()); TEST_F(LeImplTest, add_device_to_accept_list) { le_impl_->add_device_to_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(1UL, le_impl_->accept_list.size()); le_impl_->add_device_to_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->add_device_to_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->add_device_to_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->add_device_to_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->add_device_to_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->add_device_to_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); } TEST_F(LeImplTest, remove_device_from_connect_list) { le_impl_->add_device_to_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_connect_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_connect_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(4UL, le_impl_->connect_list.size()); TEST_F(LeImplTest, remove_device_from_accept_list) { le_impl_->add_device_to_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_accept_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_accept_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(4UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(3UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(3UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->remove_device_from_connect_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(0UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->remove_device_from_accept_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(0UL, le_impl_->accept_list.size()); } TEST_F(LeImplTest, connection_complete_with_periperal_role) { Loading system/gd/hci/acl_manager_test.cc +5 −5 Original line number Diff line number Diff line Loading @@ -177,7 +177,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test { os::Handler* client_handler_ = nullptr; Address remote; AddressWithType my_initiating_address; const bool use_connect_list_ = true; // gd currently only supports connect list const bool use_accept_list_ = true; // gd currently only supports connect list std::future<void> GetConnectionFuture() { ASSERT_LOG(connection_promise_ == nullptr, "Promises promises ... Only one at a time"); Loading Loading @@ -364,7 +364,7 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), empty_address_with_type.GetAddress()); ASSERT_EQ(command_view.GetPeerAddressType(), empty_address_with_type.GetAddressType()); } else { Loading Loading @@ -455,7 +455,7 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty); } else { ASSERT_EQ(command_view.GetPeerAddress(), remote); Loading Loading @@ -1289,7 +1289,7 @@ TEST_F(AclManagerLifeCycleTest, unregister_le_before_connection_complete) { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty); } else { ASSERT_EQ(command_view.GetPeerAddress(), remote); Loading Loading @@ -1330,7 +1330,7 @@ TEST_F(AclManagerLifeCycleTest, unregister_le_before_enhanced_connection_complet LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty); } else { ASSERT_EQ(command_view.GetPeerAddress(), remote); Loading system/gd/hci/acl_manager_unittest.cc +2 −2 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ class AclManagerNoCallbacksTest : public AclManagerBaseTest { } AddressWithType local_address_with_type_; const bool use_connect_list_ = true; // gd currently only supports connect list const bool use_accept_list_ = true; // gd currently only supports connect list void SendAclData(uint16_t handle, AclConnection::QueueUpEnd* queue_end) { std::promise<void> promise; Loading Loading @@ -412,7 +412,7 @@ class AclManagerWithLeConnectionTest : public AclManagerWithCallbacksTest { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), empty_address_with_type.GetAddress()); ASSERT_EQ(command_view.GetPeerAddressType(), empty_address_with_type.GetAddressType()); } else { Loading Loading
system/gd/hci/acl_manager.cc +5 −5 Original line number Diff line number Diff line Loading @@ -443,7 +443,7 @@ AclManager::~AclManager() = default; void AclManager::impl::Dump( std::promise<flatbuffers::Offset<AclManagerData>> promise, flatbuffers::FlatBufferBuilder* fb_builder) const { const std::lock_guard<std::mutex> lock(dumpsys_mutex_); const auto connect_list = (le_impl_ != nullptr) ? le_impl_->connect_list : std::unordered_set<AddressWithType>(); const auto accept_list = (le_impl_ != nullptr) ? le_impl_->accept_list : std::unordered_set<AddressWithType>(); const auto le_connectability_state_text = (le_impl_ != nullptr) ? connectability_state_machine_text(le_impl_->connectability_state_) : "INDETERMINATE"; const auto le_create_connection_timeout_alarms_count = Loading @@ -452,17 +452,17 @@ void AclManager::impl::Dump( auto title = fb_builder->CreateString("----- Acl Manager Dumpsys -----"); auto le_connectability_state = fb_builder->CreateString(le_connectability_state_text); flatbuffers::Offset<flatbuffers::String> strings[connect_list.size()]; flatbuffers::Offset<flatbuffers::String> strings[accept_list.size()]; size_t cnt = 0; for (const auto& it : connect_list) { for (const auto& it : accept_list) { strings[cnt++] = fb_builder->CreateString(it.ToString()); } auto vecofstrings = fb_builder->CreateVector(strings, connect_list.size()); auto vecofstrings = fb_builder->CreateVector(strings, accept_list.size()); AclManagerDataBuilder builder(*fb_builder); builder.add_title(title); builder.add_le_filter_accept_list_count(connect_list.size()); builder.add_le_filter_accept_list_count(accept_list.size()); builder.add_le_filter_accept_list(vecofstrings); builder.add_le_connectability_state(le_connectability_state); builder.add_le_create_connection_timeout_alarms_count(le_create_connection_timeout_alarms_count); Loading
system/gd/hci/acl_manager/le_impl.h +32 −31 Original line number Diff line number Diff line Loading @@ -345,7 +345,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { auto role = connection_complete.GetRole(); AddressWithType remote_address(address, peer_address_type); AddressWithType local_address = le_address_manager_->GetInitiatorAddress(); const bool in_filter_accept_list = is_device_in_connect_list(remote_address); const bool in_filter_accept_list = is_device_in_accept_list(remote_address); if (role == hci::Role::CENTRAL) { connectability_state_ = ConnectabilityState::DISARMED; Loading @@ -371,9 +371,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { arm_on_resume_ = false; ready_to_unregister = true; remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (!connect_list.empty()) { if (!accept_list.empty()) { AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS); handler_->Post(common::BindOnce(&le_impl::create_le_connection, common::Unretained(this), empty, false, false)); } Loading Loading @@ -405,7 +405,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { LOG_INFO( "Received incoming connection of device in filter accept_list, %s", ADDRESS_TO_LOGGABLE_CSTR(remote_address)); remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(remote_address).Cancel(); create_connection_timeout_alarms_.erase(remote_address); Loading Loading @@ -486,7 +486,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { break; } AddressWithType remote_address(address, remote_address_type); const bool in_filter_accept_list = is_device_in_connect_list(remote_address); const bool in_filter_accept_list = is_device_in_accept_list(remote_address); if (role == hci::Role::CENTRAL) { Loading @@ -510,9 +510,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { arm_on_resume_ = false; ready_to_unregister = true; remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (!connect_list.empty()) { if (!accept_list.empty()) { AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS); handler_->Post(common::BindOnce(&le_impl::create_le_connection, common::Unretained(this), empty, false, false)); } Loading Loading @@ -545,7 +545,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { LOG_INFO( "Received incoming connection of device in filter accept_list, %s", ADDRESS_TO_LOGGABLE_CSTR(remote_address)); remove_device_from_connect_list(remote_address); remove_device_from_accept_list(remote_address); if (create_connection_timeout_alarms_.find(remote_address) != create_connection_timeout_alarms_.end()) { create_connection_timeout_alarms_.at(remote_address).Cancel(); create_connection_timeout_alarms_.erase(remote_address); Loading Loading @@ -646,9 +646,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { connections.crash_on_unknown_handle_ = event_also_routes_to_other_receivers; if (background_connections_.count(remote_address) == 1) { LOG_INFO("re-add device to connect list"); LOG_INFO("re-add device to accept list"); arm_on_resume_ = true; add_device_to_connect_list(remote_address); add_device_to_accept_list(remote_address); } } Loading Loading @@ -768,37 +768,37 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } } void add_device_to_connect_list(AddressWithType address_with_type) { void add_device_to_accept_list(AddressWithType address_with_type) { if (connections.alreadyConnected(address_with_type)) { LOG_INFO("Device already connected, return"); return; } if (connect_list.find(address_with_type) != connect_list.end()) { if (accept_list.find(address_with_type) != accept_list.end()) { LOG_WARN( "Device already exists in acceptlist and cannot be added: %s", ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } connect_list.insert(address_with_type); accept_list.insert(address_with_type); register_with_address_manager(); le_address_manager_->AddDeviceToFilterAcceptList( address_with_type.ToFilterAcceptListAddressType(), address_with_type.GetAddress()); } bool is_device_in_connect_list(AddressWithType address_with_type) { return (connect_list.find(address_with_type) != connect_list.end()); bool is_device_in_accept_list(AddressWithType address_with_type) { return (accept_list.find(address_with_type) != accept_list.end()); } void remove_device_from_connect_list(AddressWithType address_with_type) { if (connect_list.find(address_with_type) == connect_list.end()) { void remove_device_from_accept_list(AddressWithType address_with_type) { if (accept_list.find(address_with_type) == accept_list.end()) { LOG_WARN( "Device not in acceptlist and cannot be removed: %s", ADDRESS_TO_LOGGABLE_CSTR(address_with_type)); return; } connect_list.erase(address_with_type); accept_list.erase(address_with_type); connecting_le_.erase(address_with_type); direct_connections_.erase(address_with_type); register_with_address_manager(); Loading @@ -807,7 +807,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } void clear_filter_accept_list() { connect_list.clear(); accept_list.clear(); register_with_address_manager(); le_address_manager_->ClearFilterAcceptList(); } Loading Loading @@ -879,13 +879,13 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { connectability_state_machine_text(connectability_state_).c_str()); return; } if (connect_list.empty()) { if (accept_list.empty()) { LOG_INFO("Ignored request to re-arm le connection state machine when filter accept list is empty"); return; } AddressWithType empty(Address::kEmpty, AddressType::RANDOM_DEVICE_ADDRESS); connectability_state_ = ConnectabilityState::ARMING; connecting_le_ = connect_list; connecting_le_ = accept_list; uint16_t le_scan_interval = os::GetSystemPropertyUint32(kPropertyConnScanIntervalSlow, kScanIntervalSlow); uint16_t le_scan_window = os::GetSystemPropertyUint32(kPropertyConnScanWindowSlow, kScanWindowSlow); Loading Loading @@ -1014,7 +1014,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } } void create_le_connection(AddressWithType address_with_type, bool add_to_connect_list, bool is_direct) { void create_le_connection(AddressWithType address_with_type, bool add_to_accept_list, bool is_direct) { if (le_client_callbacks_ == nullptr) { LOG_ERROR("No callbacks to call"); return; Loading @@ -1025,11 +1025,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { return; } bool already_in_connect_list = connect_list.find(address_with_type) != connect_list.end(); bool already_in_accept_list = accept_list.find(address_with_type) != accept_list.end(); // TODO: Configure default LE connection parameters? if (add_to_connect_list) { if (!already_in_connect_list) { add_device_to_connect_list(address_with_type); if (add_to_accept_list) { if (!already_in_accept_list) { add_device_to_accept_list(address_with_type); } if (is_direct) { Loading Loading @@ -1068,7 +1068,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { switch (connectability_state_) { case ConnectabilityState::ARMED: case ConnectabilityState::ARMING: if (already_in_connect_list) { if (already_in_accept_list) { arm_on_disarm_ = true; disarm_connectability(); } else { Loading @@ -1082,7 +1082,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { default: // If we added to filter accept list then the arming of the le state machine // must wait until the filter accept list command as completed if (add_to_connect_list) { if (add_to_accept_list) { arm_on_resume_ = true; LOG_DEBUG("Deferred until filter accept list has completed"); } else { Loading Loading @@ -1120,7 +1120,7 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { create_connection_timeout_alarms_.erase(address_with_type); } // the connection will be canceled by LeAddressManager.OnPause() remove_device_from_connect_list(address_with_type); remove_device_from_accept_list(address_with_type); } void set_le_suggested_default_data_parameters(uint16_t length, uint16_t time) { Loading Loading @@ -1315,9 +1315,10 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { bool arm_on_resume_{}; bool arm_on_disarm_{}; std::unordered_set<AddressWithType> direct_connections_{}; // Set of devices that will not be removed from connect list after direct connect timeout // Set of devices that will not be removed from accept list after direct connect timeout std::unordered_set<AddressWithType> background_connections_; std::unordered_set<AddressWithType> connect_list; /* This is content of controller "Filter Accept List"*/ std::unordered_set<AddressWithType> accept_list; AddressWithType connection_peer_address_with_type_; // Direct peer address UNSUPPORTEDD bool address_manager_registered = false; bool ready_to_unregister = false; Loading
system/gd/hci/acl_manager/le_impl_test.cc +26 −26 Original line number Diff line number Diff line Loading @@ -461,42 +461,42 @@ class LeImplWithConnectionTest : public LeImplTest { std::unique_ptr<LeAclConnection> connection_; }; TEST_F(LeImplTest, add_device_to_connect_list) { le_impl_->add_device_to_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(1UL, le_impl_->connect_list.size()); TEST_F(LeImplTest, add_device_to_accept_list) { le_impl_->add_device_to_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(1UL, le_impl_->accept_list.size()); le_impl_->add_device_to_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->add_device_to_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->add_device_to_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->add_device_to_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->add_device_to_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->add_device_to_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); } TEST_F(LeImplTest, remove_device_from_connect_list) { le_impl_->add_device_to_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_connect_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_connect_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(4UL, le_impl_->connect_list.size()); TEST_F(LeImplTest, remove_device_from_accept_list) { le_impl_->add_device_to_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_accept_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->add_device_to_accept_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(4UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(3UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(3UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(2UL, le_impl_->accept_list.size()); le_impl_->remove_device_from_connect_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->remove_device_from_connect_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(0UL, le_impl_->connect_list.size()); le_impl_->remove_device_from_accept_list({{0x21, 0x22, 0x23, 0x24, 0x25, 0x26}, AddressType::PUBLIC_DEVICE_ADDRESS}); le_impl_->remove_device_from_accept_list({{0x31, 0x32, 0x33, 0x34, 0x35, 0x36}, AddressType::PUBLIC_DEVICE_ADDRESS}); ASSERT_EQ(0UL, le_impl_->accept_list.size()); } TEST_F(LeImplTest, connection_complete_with_periperal_role) { Loading
system/gd/hci/acl_manager_test.cc +5 −5 Original line number Diff line number Diff line Loading @@ -177,7 +177,7 @@ class AclManagerNoCallbacksTest : public ::testing::Test { os::Handler* client_handler_ = nullptr; Address remote; AddressWithType my_initiating_address; const bool use_connect_list_ = true; // gd currently only supports connect list const bool use_accept_list_ = true; // gd currently only supports connect list std::future<void> GetConnectionFuture() { ASSERT_LOG(connection_promise_ == nullptr, "Promises promises ... Only one at a time"); Loading Loading @@ -364,7 +364,7 @@ class AclManagerWithLeConnectionTest : public AclManagerTest { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), empty_address_with_type.GetAddress()); ASSERT_EQ(command_view.GetPeerAddressType(), empty_address_with_type.GetAddressType()); } else { Loading Loading @@ -455,7 +455,7 @@ TEST_F(AclManagerTest, invoke_registered_callback_le_connection_complete_fail) { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty); } else { ASSERT_EQ(command_view.GetPeerAddress(), remote); Loading Loading @@ -1289,7 +1289,7 @@ TEST_F(AclManagerLifeCycleTest, unregister_le_before_connection_complete) { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty); } else { ASSERT_EQ(command_view.GetPeerAddress(), remote); Loading Loading @@ -1330,7 +1330,7 @@ TEST_F(AclManagerLifeCycleTest, unregister_le_before_enhanced_connection_complet LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), hci::Address::kEmpty); } else { ASSERT_EQ(command_view.GetPeerAddress(), remote); Loading
system/gd/hci/acl_manager_unittest.cc +2 −2 Original line number Diff line number Diff line Loading @@ -218,7 +218,7 @@ class AclManagerNoCallbacksTest : public AclManagerBaseTest { } AddressWithType local_address_with_type_; const bool use_connect_list_ = true; // gd currently only supports connect list const bool use_accept_list_ = true; // gd currently only supports connect list void SendAclData(uint16_t handle, AclConnection::QueueUpEnd* queue_end) { std::promise<void> promise; Loading Loading @@ -412,7 +412,7 @@ class AclManagerWithLeConnectionTest : public AclManagerWithCallbacksTest { LeConnectionManagementCommandView::Create(AclCommandView::Create(packet)); auto command_view = LeCreateConnectionView::Create(le_connection_management_command_view); ASSERT_TRUE(command_view.IsValid()); if (use_connect_list_) { if (use_accept_list_) { ASSERT_EQ(command_view.GetPeerAddress(), empty_address_with_type.GetAddress()); ASSERT_EQ(command_view.GetPeerAddressType(), empty_address_with_type.GetAddressType()); } else { Loading