diff --git a/system/gd/hci/acl_manager/le_acceptlist_callbacks.h b/system/gd/hci/acl_manager/le_acceptlist_callbacks.h index 57780b6fae83050f1fd8e0497d422b342df4701c..90fcf7fddff9fd289c863635f941e14e5d44146d 100644 --- a/system/gd/hci/acl_manager/le_acceptlist_callbacks.h +++ b/system/gd/hci/acl_manager/le_acceptlist_callbacks.h @@ -35,12 +35,6 @@ class LeAcceptlistCallbacks { // Invoked when controller sends Connection Complete event with Success error code // AddressWithType is the address returned by the controller. virtual void OnLeConnectSuccess(AddressWithType) = 0; - // Invoked when controller sends Connection Complete event with failing error code - // AddressWithType is the address returned by the controller. - virtual void OnLeConnectFail(AddressWithType, ErrorCode reason) = 0; - // Invoked when an LE connection is disconnected. AddressWithType is the remote address - // associated with this connection at the time of connection. - virtual void OnLeDisconnection(AddressWithType) = 0; // Invoked when the resolving list has changed, so we need to re-resolve our addresses. virtual void OnResolvingListChange() = 0; }; diff --git a/system/gd/hci/acl_manager/le_impl.h b/system/gd/hci/acl_manager/le_impl.h index b6090f44579d075f6543288fc47a4a3a65f99289..55a45521e27d4ac3461fdeac04b119929078cb07 100644 --- a/system/gd/hci/acl_manager/le_impl.h +++ b/system/gd/hci/acl_manager/le_impl.h @@ -313,17 +313,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { return connections.send_packet_upward(handle, cb); } - void report_le_connection_failure(AddressWithType address, ErrorCode status) { - le_client_handler_->Post(common::BindOnce( - &LeConnectionCallbacks::OnLeConnectFail, - common::Unretained(le_client_callbacks_), - address, - status)); - if (le_acceptlist_callbacks_ != nullptr) { - le_acceptlist_callbacks_->OnLeConnectFail(address, status); - } - } - // connection canceled by LeAddressManager.OnPause(), will auto reconnect by LeAddressManager.OnResume() void on_le_connection_canceled_on_pause() { ASSERT_LOG(pause_connection, "Connection must be paused to ack the le address manager"); @@ -398,7 +387,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } if (status != ErrorCode::SUCCESS) { - report_le_connection_failure(remote_address, status); + le_client_handler_->Post(common::BindOnce( + &LeConnectionCallbacks::OnLeConnectFail, + common::Unretained(le_client_callbacks_), + remote_address, + status)); return; } } else { @@ -411,7 +404,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { if (status != ErrorCode::SUCCESS) { std::string error_code = ErrorCodeText(status); LOG_WARN("Received on_le_connection_complete with error code %s", error_code.c_str()); - report_le_connection_failure(remote_address, status); + le_client_handler_->Post(common::BindOnce( + &LeConnectionCallbacks::OnLeConnectFail, + common::Unretained(le_client_callbacks_), + remote_address, + status)); return; } @@ -546,7 +543,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { } if (status != ErrorCode::SUCCESS) { - report_le_connection_failure(remote_address, status); + le_client_handler_->Post(common::BindOnce( + &LeConnectionCallbacks::OnLeConnectFail, + common::Unretained(le_client_callbacks_), + remote_address, + status)); return; } @@ -560,7 +561,11 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { if (status != ErrorCode::SUCCESS) { std::string error_code = ErrorCodeText(status); LOG_WARN("Received on_le_enhanced_connection_complete with error code %s", error_code.c_str()); - report_le_connection_failure(remote_address, status); + le_client_handler_->Post(common::BindOnce( + &LeConnectionCallbacks::OnLeConnectFail, + common::Unretained(le_client_callbacks_), + remote_address, + status)); return; } @@ -663,9 +668,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { callbacks->OnDisconnection(reason); }, kRemoveConnectionAfterwards); - if (le_acceptlist_callbacks_ != nullptr) { - le_acceptlist_callbacks_->OnLeDisconnection(remote_address); - } connections.crash_on_unknown_handle_ = event_also_routes_to_other_receivers; if (background_connections_.count(remote_address) == 1) { diff --git a/system/gd/hci/acl_manager/le_impl_test.cc b/system/gd/hci/acl_manager/le_impl_test.cc index 2e9c4b47099e33c034b01f62f766b0618a3881fe..17e3a19ca2b9429027da8c7b1059d267dfb1f3b1 100644 --- a/system/gd/hci/acl_manager/le_impl_test.cc +++ b/system/gd/hci/acl_manager/le_impl_test.cc @@ -407,9 +407,7 @@ class MockLeConnectionCallbacks : public LeConnectionCallbacks { class MockLeAcceptlistCallbacks : public LeAcceptlistCallbacks { public: - MOCK_METHOD(void, OnLeConnectSuccess, (AddressWithType address), (override)); - MOCK_METHOD(void, OnLeConnectFail, (AddressWithType address, ErrorCode reason), (override)); - MOCK_METHOD(void, OnLeDisconnection, (AddressWithType address), (override)); + MOCK_METHOD(void, OnLeConnectSuccess, (AddressWithType address_with_type), (override)); MOCK_METHOD(void, OnResolvingListChange, (), (override)); }; @@ -1728,90 +1726,6 @@ TEST_F(LeImplTest, ResolvingListCallback) { Mock::VerifyAndClearExpectations(&callbacks); } -TEST_F(LeImplTest, ConnectionFailedAcceptlistCallback) { - // arrange - MockLeAcceptlistCallbacks callbacks; - le_impl_->handle_register_le_acceptlist_callbacks(&callbacks); - set_random_device_address_policy(); - - // expect - AddressWithType remote_address; - ErrorCode reason; - EXPECT_CALL(callbacks, OnLeConnectFail(_, _)) - .WillOnce([&](AddressWithType addr, ErrorCode error) { - remote_address = addr; - reason = error; - }); - - // act - auto command = LeEnhancedConnectionCompleteBuilder::Create( - ErrorCode::CONTROLLER_BUSY, - kHciHandle, - Role::PERIPHERAL, - AddressType::PUBLIC_DEVICE_ADDRESS, - remote_address_, - local_rpa_, - remote_rpa_, - 0x0024, - 0x0000, - 0x0011, - ClockAccuracy::PPM_30); - auto bytes = Serialize<LeEnhancedConnectionCompleteBuilder>(std::move(command)); - auto view = CreateLeEventView<hci::LeEnhancedConnectionCompleteView>(bytes); - ASSERT_TRUE(view.IsValid()); - le_impl_->on_le_event(view); - sync_handler(); - - // assert - EXPECT_EQ(remote_address, remote_public_address_with_type_); - EXPECT_EQ(reason, ErrorCode::CONTROLLER_BUSY); -} - -TEST_F(LeImplTest, DisconnectionAcceptlistCallback) { - // expect - MockLeAcceptlistCallbacks callbacks; - AddressWithType remote_address; - EXPECT_CALL(callbacks, OnLeDisconnection(_)).WillOnce([&](AddressWithType addr) { - remote_address = addr; - }); - // we need to capture the LeAclConnection so it is not immediately dropped => disconnected - std::unique_ptr<LeAclConnection> connection; - EXPECT_CALL(mock_le_connection_callbacks_, OnLeConnectSuccess(_, _)) - .WillOnce([&](AddressWithType, std::unique_ptr<LeAclConnection> conn) { - connection = std::move(conn); - connection->RegisterCallbacks(&connection_management_callbacks_, handler_); - }); - - // arrange: an active connection to a peer - le_impl_->handle_register_le_acceptlist_callbacks(&callbacks); - set_random_device_address_policy(); - auto command = LeEnhancedConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, - kHciHandle, - Role::PERIPHERAL, - AddressType::PUBLIC_DEVICE_ADDRESS, - remote_address_, - local_rpa_, - remote_rpa_, - 0x0024, - 0x0000, - 0x0011, - ClockAccuracy::PPM_30); - auto bytes = Serialize<LeEnhancedConnectionCompleteBuilder>(std::move(command)); - auto view = CreateLeEventView<hci::LeEnhancedConnectionCompleteView>(bytes); - ASSERT_TRUE(view.IsValid()); - le_impl_->on_le_event(view); - sync_handler(); - - // act - le_impl_->on_le_disconnect(kHciHandle, ErrorCode::REMOTE_USER_TERMINATED_CONNECTION); - sync_handler(); - - // assert - EXPECT_EQ(remote_public_address_with_type_, remote_address); - Mock::VerifyAndClearExpectations(&callbacks); -} - } // namespace acl_manager } // namespace hci } // namespace bluetooth diff --git a/system/rust/src/connection/ffi.rs b/system/rust/src/connection/ffi.rs index 26388d6f348091f5faf4bc80fc61e5d464915584..f9a72c2e3e6b5cb801781f04369f259500afac1e 100644 --- a/system/rust/src/connection/ffi.rs +++ b/system/rust/src/connection/ffi.rs @@ -69,7 +69,7 @@ mod inner { fn on_le_connect_success(&self, address: AddressWithType); #[cxx_name = "OnLeConnectFail"] fn on_le_connect_fail(&self, address: AddressWithType, status: u8); - #[cxx_name = "OnLeDisconnection"] + #[cxx_name = "OnDisconnect"] fn on_disconnect(&self, address: AddressWithType); } diff --git a/system/rust/src/connection/ffi/connection_shim.cc b/system/rust/src/connection/ffi/connection_shim.cc index 2c6a1c6ab978dfce9e39f488cd82d696ff198009..06bafb1b9e158aed6e1e5acb7a89fb65004ea7bb 100644 --- a/system/rust/src/connection/ffi/connection_shim.cc +++ b/system/rust/src/connection/ffi/connection_shim.cc @@ -43,7 +43,7 @@ struct LeAclManagerCallbackShim { void OnLeConnectFail(core::AddressWithType addr, uint8_t status) const { LOG_ALWAYS_FATAL("system/rust not available in Floss"); }; - void OnLeDisconnection(core::AddressWithType addr) const { + void OnDisconnect(core::AddressWithType addr) const { LOG_ALWAYS_FATAL("system/rust not available in Floss"); }; }; @@ -94,18 +94,6 @@ struct LeAclManagerShim::impl : hci::acl_manager::LeAcceptlistCallbacks { callbacks_.value()->OnLeConnectSuccess(ToRustAddress(address)); } - // hci::acl_manager::LeAcceptlistCallbacks - virtual void OnLeConnectFail(hci::AddressWithType address, - hci::ErrorCode reason) { - callbacks_.value()->OnLeConnectFail(ToRustAddress(address), - static_cast<uint8_t>(reason)); - } - - // hci::acl_manager::LeAcceptlistCallbacks - virtual void OnLeDisconnection(hci::AddressWithType address) { - callbacks_.value()->OnLeDisconnection(ToRustAddress(address)); - } - // hci::acl_manager::LeAcceptlistCallbacks virtual void OnResolvingListChange() {} diff --git a/system/rust/src/connection/le_manager.rs b/system/rust/src/connection/le_manager.rs index fa55118d08ea4055f3e986e563f534be779fd466..d86008b6e4ef48aa2fd18cf8c655715f04dd335f 100644 --- a/system/rust/src/connection/le_manager.rs +++ b/system/rust/src/connection/le_manager.rs @@ -57,7 +57,6 @@ pub trait LeAclManager: Debug { pub trait LeAclManagerConnectionCallbacks { /// Invoked when an LE connection to a given address completes fn on_le_connect(&self, address: AddressWithType, result: Result<LeConnection, ErrorCode>); - /// Invoked when a peer device disconnects from us. The address must match the address - /// supplied on the initial connection. + /// Invoked when a peer device disconnects from us fn on_disconnect(&self, address: AddressWithType); }