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

Commit dcf03f76 authored by Myles Watson's avatar Myles Watson
Browse files

acl: Remove DisconnectorForLe

Bug: 172725986
Test: atest bluetooth_test_gd
Tag: #gd-refactor
Change-Id: Id9a5dcbba3f4be0490baa13d3ff538f0f2158c5c
parent 2e32c537
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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() {
+1 −2
Original line number Diff line number Diff line
@@ -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) {
+0 −34
Original line number Diff line number Diff line
/*
 * 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
+27 −13
Original line number Diff line number Diff line
@@ -23,9 +23,8 @@ namespace acl_manager {

class LeAclConnectionTracker : public LeConnectionManagementCallbacks {
 public:
  LeAclConnectionTracker(LeAclConnectionInterface* le_acl_connection_interface,
                         common::OnceCallback<void(DisconnectReason reason)> 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<void(DisconnectReason)> do_disconnect_;
  os::Handler* client_handler_ = nullptr;
  LeConnectionManagementCallbacks* client_callbacks_ = nullptr;
  std::list<common::OnceClosure> queued_callbacks_;
};

struct LeAclConnection::impl {
  impl(LeAclConnectionInterface* le_acl_connection_interface, std::shared_ptr<Queue> queue,
       common::OnceCallback<void(DisconnectReason)> disconnect)
      : queue_(std::move(queue)), tracker(le_acl_connection_interface, std::move(disconnect)) {}
  impl(LeAclConnectionInterface* le_acl_connection_interface, std::shared_ptr<Queue> 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> queue, LeAclConnectionInterface* le_acl_connection_interface,
                                 common::OnceCallback<void(DisconnectReason)> 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> 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() {
+7 −3
Original line number Diff line number Diff line
@@ -29,9 +29,13 @@ namespace acl_manager {
class LeAclConnection : public AclConnection {
 public:
  LeAclConnection();
  LeAclConnection(std::shared_ptr<Queue> queue, LeAclConnectionInterface* le_acl_connection_interface,
                  common::OnceCallback<void(DisconnectReason)> disconnect, uint16_t handle,
                  AddressWithType local_address, AddressWithType remote_address, Role role);
  LeAclConnection(
      std::shared_ptr<Queue> queue,
      LeAclConnectionInterface* le_acl_connection_interface,
      uint16_t handle,
      AddressWithType local_address,
      AddressWithType remote_address,
      Role role);
  ~LeAclConnection() override;

  virtual AddressWithType GetLocalAddress() const {
Loading