From c74a4365cb724dceb39582edcd2cc7ff03266233 Mon Sep 17 00:00:00 2001 From: Myles Watson Date: Tue, 17 Nov 2020 07:30:54 -0800 Subject: [PATCH] acl: Remove DisconnectorForLe Bug: 172725986 Test: atest bluetooth_test_gd Tag: #gd-refactor Change-Id: Id9a5dcbba3f4be0490baa13d3ff538f0f2158c5c --- gd/hci/acl_manager.cc | 2 +- gd/hci/acl_manager/classic_impl.h | 3 +-- gd/hci/acl_manager/disconnector_for_le.h | 34 --------------------------- gd/hci/acl_manager/le_acl_connection.cc | 40 +++++++++++++++++++++----------- gd/hci/acl_manager/le_acl_connection.h | 10 +++++--- gd/hci/acl_manager/le_impl.h | 22 +++++------------- 6 files changed, 42 insertions(+), 69 deletions(-) delete mode 100644 gd/hci/acl_manager/disconnector_for_le.h diff --git a/gd/hci/acl_manager.cc b/gd/hci/acl_manager.cc index e0f66dbe4..d1b586bcb 100644 --- a/gd/hci/acl_manager.cc +++ b/gd/hci/acl_manager.cc @@ -61,7 +61,7 @@ struct AclManager::impl { hci_queue_end_->RegisterDequeue( handler_, common::Bind(&impl::dequeue_and_route_acl_packet_to_connection, common::Unretained(this))); classic_impl_ = new classic_impl(hci_layer_, controller_, handler_, round_robin_scheduler_); - le_impl_ = new le_impl(hci_layer_, controller_, handler_, round_robin_scheduler_, classic_impl_); + le_impl_ = new le_impl(hci_layer_, controller_, handler_, round_robin_scheduler_); } void Stop() { diff --git a/gd/hci/acl_manager/classic_impl.h b/gd/hci/acl_manager/classic_impl.h index c292d50bf..24451d8a3 100644 --- a/gd/hci/acl_manager/classic_impl.h +++ b/gd/hci/acl_manager/classic_impl.h @@ -18,7 +18,6 @@ #include "common/bind.h" #include "hci/acl_manager/assembler.h" -#include "hci/acl_manager/disconnector_for_le.h" #include "hci/acl_manager/event_checkers.h" #include "hci/acl_manager/round_robin_scheduler.h" #include "hci/controller.h" @@ -38,7 +37,7 @@ struct acl_connection { ConnectionManagementCallbacks* connection_management_callbacks_ = nullptr; }; -struct classic_impl : public DisconnectorForLe, public security::ISecurityManagerListener { +struct classic_impl : public security::ISecurityManagerListener { classic_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler, RoundRobinScheduler* round_robin_scheduler) : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler) { diff --git a/gd/hci/acl_manager/disconnector_for_le.h b/gd/hci/acl_manager/disconnector_for_le.h deleted file mode 100644 index cdb21c222..000000000 --- a/gd/hci/acl_manager/disconnector_for_le.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "hci/hci_packets.h" - -namespace bluetooth { -namespace hci { -namespace acl_manager { - -class DisconnectorForLe { - public: - DisconnectorForLe() = default; - virtual ~DisconnectorForLe() = default; - virtual void handle_disconnect(uint16_t handle, DisconnectReason reason) = 0; -}; - -} // namespace acl_manager -} // namespace hci -} // namespace bluetooth diff --git a/gd/hci/acl_manager/le_acl_connection.cc b/gd/hci/acl_manager/le_acl_connection.cc index 737c600dc..021864a34 100644 --- a/gd/hci/acl_manager/le_acl_connection.cc +++ b/gd/hci/acl_manager/le_acl_connection.cc @@ -23,9 +23,8 @@ namespace acl_manager { class LeAclConnectionTracker : public LeConnectionManagementCallbacks { public: - LeAclConnectionTracker(LeAclConnectionInterface* le_acl_connection_interface, - common::OnceCallback disconnect) - : le_acl_connection_interface_(le_acl_connection_interface), do_disconnect_(std::move(disconnect)) {} + LeAclConnectionTracker(LeAclConnectionInterface* le_acl_connection_interface) + : le_acl_connection_interface_(le_acl_connection_interface) {} ~LeAclConnectionTracker() override { ASSERT(queued_callbacks_.empty()); } @@ -66,16 +65,14 @@ class LeAclConnectionTracker : public LeConnectionManagementCallbacks { #undef SAVE_OR_CALL LeAclConnectionInterface* le_acl_connection_interface_; - common::OnceCallback do_disconnect_; os::Handler* client_handler_ = nullptr; LeConnectionManagementCallbacks* client_callbacks_ = nullptr; std::list queued_callbacks_; }; struct LeAclConnection::impl { - impl(LeAclConnectionInterface* le_acl_connection_interface, std::shared_ptr queue, - common::OnceCallback disconnect) - : queue_(std::move(queue)), tracker(le_acl_connection_interface, std::move(disconnect)) {} + impl(LeAclConnectionInterface* le_acl_connection_interface, std::shared_ptr queue) + : queue_(std::move(queue)), tracker(le_acl_connection_interface) {} LeConnectionManagementCallbacks* GetEventCallbacks() { ASSERT(!callbacks_given_); callbacks_given_ = true; @@ -91,12 +88,18 @@ LeAclConnection::LeAclConnection() : AclConnection(), local_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS), remote_address_(Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS) {} -LeAclConnection::LeAclConnection(std::shared_ptr queue, LeAclConnectionInterface* le_acl_connection_interface, - common::OnceCallback disconnect, uint16_t handle, - AddressWithType local_address, AddressWithType remote_address, Role role) - : AclConnection(queue->GetUpEnd(), handle), local_address_(local_address), remote_address_(remote_address), +LeAclConnection::LeAclConnection( + std::shared_ptr queue, + LeAclConnectionInterface* le_acl_connection_interface, + uint16_t handle, + AddressWithType local_address, + AddressWithType remote_address, + Role role) + : AclConnection(queue->GetUpEnd(), handle), + local_address_(local_address), + remote_address_(remote_address), role_(role) { - pimpl_ = new LeAclConnection::impl(le_acl_connection_interface, std::move(queue), std::move(disconnect)); + pimpl_ = new LeAclConnection::impl(le_acl_connection_interface, std::move(queue)); } LeAclConnection::~LeAclConnection() { @@ -109,7 +112,18 @@ void LeAclConnection::RegisterCallbacks(LeConnectionManagementCallbacks* callbac } void LeAclConnection::Disconnect(DisconnectReason reason) { - common::BindOnce(std::move(pimpl_->tracker.do_disconnect_), reason).Run(); + pimpl_->tracker.le_acl_connection_interface_->EnqueueCommand( + DisconnectBuilder::Create(handle_, reason), + pimpl_->tracker.client_handler_->BindOnce([](CommandStatusView status) { + ASSERT(status.IsValid()); + ASSERT(status.GetCommandOpCode() == OpCode::DISCONNECT); + auto disconnect_status = DisconnectStatusView::Create(status); + ASSERT(disconnect_status.IsValid()); + auto error_code = disconnect_status.GetStatus(); + if (error_code != ErrorCode::SUCCESS) { + LOG_INFO("Disconnect status %s", ErrorCodeText(error_code).c_str()); + } + })); } LeConnectionManagementCallbacks* LeAclConnection::GetEventCallbacks() { diff --git a/gd/hci/acl_manager/le_acl_connection.h b/gd/hci/acl_manager/le_acl_connection.h index c7640606a..05a7983ff 100644 --- a/gd/hci/acl_manager/le_acl_connection.h +++ b/gd/hci/acl_manager/le_acl_connection.h @@ -29,9 +29,13 @@ namespace acl_manager { class LeAclConnection : public AclConnection { public: LeAclConnection(); - LeAclConnection(std::shared_ptr queue, LeAclConnectionInterface* le_acl_connection_interface, - common::OnceCallback disconnect, uint16_t handle, - AddressWithType local_address, AddressWithType remote_address, Role role); + LeAclConnection( + std::shared_ptr queue, + LeAclConnectionInterface* le_acl_connection_interface, + uint16_t handle, + AddressWithType local_address, + AddressWithType remote_address, + Role role); ~LeAclConnection() override; virtual AddressWithType GetLocalAddress() const { diff --git a/gd/hci/acl_manager/le_impl.h b/gd/hci/acl_manager/le_impl.h index c0569ed44..ec921cb83 100644 --- a/gd/hci/acl_manager/le_impl.h +++ b/gd/hci/acl_manager/le_impl.h @@ -19,7 +19,6 @@ #include "common/bind.h" #include "crypto_toolbox/crypto_toolbox.h" #include "hci/acl_manager/assembler.h" -#include "hci/acl_manager/disconnector_for_le.h" #include "hci/acl_manager/round_robin_scheduler.h" #include "hci/le_address_manager.h" #include "os/alarm.h" @@ -44,10 +43,8 @@ struct le_acl_connection { }; struct le_impl : public bluetooth::hci::LeAddressManagerCallback { - le_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler, RoundRobinScheduler* round_robin_scheduler, - DisconnectorForLe* disconnector) - : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler), - disconnector_(disconnector) { + le_impl(HciLayer* hci_layer, Controller* controller, os::Handler* handler, RoundRobinScheduler* round_robin_scheduler) + : hci_layer_(hci_layer), controller_(controller), round_robin_scheduler_(round_robin_scheduler) { hci_layer_ = hci_layer; controller_ = controller; handler_ = handler; @@ -159,12 +156,9 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { le_acl_connections_.emplace(std::piecewise_construct, std::forward_as_tuple(handle), std::forward_as_tuple(remote_address, queue->GetDownEnd(), handler_)); auto& connection_proxy = check_and_get_le_connection(handle); - auto do_disconnect = - common::BindOnce(&DisconnectorForLe::handle_disconnect, common::Unretained(disconnector_), handle); round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::LE, handle, queue); - std::unique_ptr connection(new LeAclConnection(std::move(queue), le_acl_connection_interface_, - std::move(do_disconnect), handle, local_address, - remote_address, role)); + std::unique_ptr connection(new LeAclConnection( + std::move(queue), le_acl_connection_interface_, handle, local_address, remote_address, role)); connection_proxy.le_connection_management_callbacks_ = connection->GetEventCallbacks(); le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess, common::Unretained(le_client_callbacks_), remote_address, @@ -223,11 +217,8 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { std::forward_as_tuple(remote_address, queue->GetDownEnd(), handler_)); auto& connection_proxy = check_and_get_le_connection(handle); round_robin_scheduler_->Register(RoundRobinScheduler::ConnectionType::LE, handle, queue); - auto do_disconnect = - common::BindOnce(&DisconnectorForLe::handle_disconnect, common::Unretained(disconnector_), handle); - std::unique_ptr connection(new LeAclConnection(std::move(queue), le_acl_connection_interface_, - std::move(do_disconnect), handle, local_address, - remote_address, role)); + std::unique_ptr connection(new LeAclConnection( + std::move(queue), le_acl_connection_interface_, handle, local_address, remote_address, role)); connection_proxy.le_connection_management_callbacks_ = connection->GetEventCallbacks(); le_client_handler_->Post(common::BindOnce(&LeConnectionCallbacks::OnLeConnectSuccess, common::Unretained(le_client_callbacks_), remote_address, @@ -600,7 +591,6 @@ struct le_impl : public bluetooth::hci::LeAddressManagerCallback { std::map le_acl_connections_; std::set connecting_le_; std::set canceled_connections_; - DisconnectorForLe* disconnector_; bool address_manager_registered = false; bool ready_to_unregister = false; bool pause_connection = false; -- 2.11.0