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

Commit 5b45b964 authored by Chris Manton's avatar Chris Manton
Browse files

Allow link to receive acl manager events

Bug: 146086425
Test: bluetooth_test_gd
Change-Id: I479374d345ec5e9173dc684f5df5b8d98dad8e98
parent 69a5f3c5
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ struct AclManager::acl_connection {
  ErrorCode disconnect_reason_;
  os::Handler* command_complete_handler_ = nullptr;
  os::Handler* disconnect_handler_ = nullptr;
  ConnectionManagementCallbacks* command_complete_callbacks_;
  ConnectionManagementCallbacks* command_complete_callbacks_ = nullptr;
  common::OnceCallback<void(ErrorCode)> on_disconnect_callback_;
  // For LE Connection parameter update from L2CAP
  common::OnceCallback<void(ErrorCode)> on_connection_update_complete_callback_;
@@ -208,6 +208,9 @@ struct AclManager::impl {
    hci_layer_->RegisterEventHandler(EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE,
                                     Bind(&impl::on_read_remote_version_information_complete, common::Unretained(this)),
                                     handler_);
    hci_layer_->RegisterEventHandler(EventCode::ENCRYPTION_CHANGE,
                                     Bind(&impl::on_read_remote_version_information_complete, common::Unretained(this)),
                                     handler_);
    hci_mtu_ = controller_->GetControllerAclPacketLength();
  }

@@ -1502,10 +1505,17 @@ struct AclManager::impl {

  void RegisterCallbacks(uint16_t handle, ConnectionManagementCallbacks* callbacks, os::Handler* handler) {
    auto& connection = check_and_get_connection(handle);
    ASSERT(connection.command_complete_callbacks_ == nullptr);
    connection.command_complete_callbacks_ = callbacks;
    connection.command_complete_handler_ = handler;
  }

  void UnregisterCallbacks(uint16_t handle, ConnectionManagementCallbacks* callbacks) {
    auto& connection = check_and_get_connection(handle);
    ASSERT(connection.command_complete_callbacks_ == callbacks);
    connection.command_complete_callbacks_ = nullptr;
  }

  void RegisterDisconnectCallback(uint16_t handle, common::OnceCallback<void(ErrorCode)> on_disconnect,
                                  os::Handler* handler) {
    auto& connection = check_and_get_connection(handle);
@@ -1899,6 +1909,10 @@ void AclConnection::RegisterCallbacks(ConnectionManagementCallbacks* callbacks,
  return manager_->pimpl_->RegisterCallbacks(handle_, callbacks, handler);
}

void AclConnection::UnregisterCallbacks(ConnectionManagementCallbacks* callbacks) {
  return manager_->pimpl_->UnregisterCallbacks(handle_, callbacks);
}

void AclConnection::RegisterDisconnectCallback(common::OnceCallback<void(ErrorCode)> on_disconnect,
                                               os::Handler* handler) {
  return manager_->pimpl_->RegisterDisconnectCallback(handle_, std::move(on_disconnect), handler);
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ class AclConnection {
  using QueueDownEnd = common::BidiQueueEnd<PacketView<kLittleEndian>, BasePacketBuilder>;
  virtual QueueUpEnd* GetAclQueueEnd() const;
  virtual void RegisterCallbacks(ConnectionManagementCallbacks* callbacks, os::Handler* handler);
  virtual void UnregisterCallbacks(ConnectionManagementCallbacks* callbacks);
  virtual void RegisterDisconnectCallback(common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler);
  virtual bool Disconnect(DisconnectReason reason);
  virtual bool ChangeConnectionPacketType(uint16_t packet_type);
+4 −1
Original line number Diff line number Diff line
@@ -32,6 +32,9 @@ class MockAclConnection : public AclConnection {
              (common::OnceCallback<void(ErrorCode)> on_disconnect, os::Handler* handler), (override));
  MOCK_METHOD(bool, Disconnect, (DisconnectReason reason), (override));
  MOCK_METHOD(void, Finish, (), (override));
  MOCK_METHOD(void, RegisterCallbacks, (ConnectionManagementCallbacks * callbacks, os::Handler* handler), (override));
  MOCK_METHOD(void, UnregisterCallbacks, (ConnectionManagementCallbacks * callbacks), (override));

  QueueUpEnd* GetAclQueueEnd() const override {
    return acl_queue_.GetUpEnd();
  }
+9 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ Link::Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_c
  ASSERT(parameter_provider_ != nullptr);
  link_idle_disconnect_alarm_.Schedule(common::BindOnce(&Link::Disconnect, common::Unretained(this)),
                                       parameter_provider_->GetClassicLinkIdleDisconnectTimeout());
  acl_connection_->RegisterCallbacks(this, l2cap_handler_);
}

Link::~Link() {
  acl_connection_->UnregisterCallbacks(this);
}

void Link::OnAclDisconnected(hci::ErrorCode status) {
@@ -73,6 +78,10 @@ void Link::Authenticate() {
  acl_connection_->AuthenticationRequested();
}

bool Link::IsAuthenticated() const {
  return encryption_enabled_ != hci::EncryptionEnabled::OFF;
}

void Link::ReadRemoteVersionInformation() {
  acl_connection_->ReadRemoteVersionInformation();
}
+31 −3
Original line number Diff line number Diff line
@@ -39,14 +39,13 @@ namespace l2cap {
namespace classic {
namespace internal {

class Link : public l2cap::internal::ILink {
class Link : public l2cap::internal::ILink, public hci::ConnectionManagementCallbacks {
 public:
  Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_connection,
       l2cap::internal::ParameterProvider* parameter_provider,
       DynamicChannelServiceManagerImpl* dynamic_service_manager,
       FixedChannelServiceManagerImpl* fixed_service_manager);

  ~Link() override = default;
  ~Link();

  hci::AddressWithType GetDevice() override {
    return {acl_connection_->GetAddress(), acl_connection_->GetAddressType()};
@@ -69,6 +68,8 @@ class Link : public l2cap::internal::ILink {

  virtual void Authenticate();

  virtual bool IsAuthenticated() const;

  virtual void ReadRemoteVersionInformation();

  virtual void ReadRemoteSupportedFeatures();
@@ -128,6 +129,32 @@ class Link : public l2cap::internal::ILink {

  void SendLeCredit(Cid local_cid, uint16_t credit) override {}

  // ConnectionManagementCallbacks
  virtual void OnConnectionPacketTypeChanged(uint16_t packet_type) override {}
  virtual void OnAuthenticationComplete() override {}
  virtual void OnEncryptionChange(hci::EncryptionEnabled enabled) override {
    encryption_enabled_ = enabled;
  }
  virtual void OnChangeConnectionLinkKeyComplete() override {}
  virtual void OnReadClockOffsetComplete(uint16_t clock_offset) override {}
  virtual void OnModeChange(hci::Mode current_mode, uint16_t interval) override {}
  virtual void OnQosSetupComplete(hci::ServiceType service_type, uint32_t token_rate, uint32_t peak_bandwidth,
                                  uint32_t latency, uint32_t delay_variation) override {}
  virtual void OnFlowSpecificationComplete(hci::FlowDirection flow_direction, hci::ServiceType service_type,
                                           uint32_t token_rate, uint32_t token_bucket_size, uint32_t peak_bandwidth,
                                           uint32_t access_latency) override {}
  virtual void OnFlushOccurred() override {}
  virtual void OnRoleDiscoveryComplete(hci::Role current_role) override {}
  virtual void OnReadLinkPolicySettingsComplete(uint16_t link_policy_settings) override {}
  virtual void OnReadAutomaticFlushTimeoutComplete(uint16_t flush_timeout) override {}
  virtual void OnReadTransmitPowerLevelComplete(uint8_t transmit_power_level) override {}
  virtual void OnReadLinkSupervisionTimeoutComplete(uint16_t link_supervision_timeout) override {}
  virtual void OnReadFailedContactCounterComplete(uint16_t failed_contact_counter) override {}
  virtual void OnReadLinkQualityComplete(uint8_t link_quality) override {}
  virtual void OnReadAfhChannelMapComplete(hci::AfhMode afh_mode, std::array<uint8_t, 10> afh_channel_map) override {}
  virtual void OnReadRssiComplete(uint8_t rssi) override {}
  virtual void OnReadClockComplete(uint32_t clock, uint16_t accuracy) override {}

 private:
  os::Handler* l2cap_handler_;
  l2cap::internal::FixedChannelAllocator<FixedChannelImpl, Link> fixed_channel_allocator_{this, l2cap_handler_};
@@ -143,6 +170,7 @@ class Link : public l2cap::internal::ILink {
  Mtu remote_connectionless_mtu_ = kMinimumClassicMtu;
  bool remote_supports_ertm_ = false;
  bool remote_supports_fcs_ = false;
  hci::EncryptionEnabled encryption_enabled_ = hci::EncryptionEnabled::OFF;
  DISALLOW_COPY_AND_ASSIGN(Link);
};