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

Commit 21b4b00f authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

Merge "Invalidate acl connection callbacks when destructed" am: ab42920b

Original change: https://android-review.googlesource.com/c/platform/packages/modules/Bluetooth/+/1949156

Change-Id: I2f3603b2aaec4b2dc216fad742df6e8d8a19afdd
parents 0d507d30 ab42920b
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -336,6 +336,7 @@ struct ClassicAclConnection::impl {
  bool callbacks_given_{false};
  AclConnectionTracker tracker;
  std::shared_ptr<Queue> queue_;
  std::shared_ptr<std::atomic<bool>> is_callback_valid_;
};

ClassicAclConnection::ClassicAclConnection()
@@ -349,10 +350,13 @@ ClassicAclConnection::ClassicAclConnection(std::shared_ptr<Queue> queue,
}

ClassicAclConnection::~ClassicAclConnection() {
  if (pimpl_->is_callback_valid_) *pimpl_->is_callback_valid_ = false;
  delete pimpl_;
}

ConnectionManagementCallbacks* ClassicAclConnection::GetEventCallbacks() {
ConnectionManagementCallbacks* ClassicAclConnection::GetEventCallbacks(
    std::shared_ptr<std::atomic<bool>> is_callback_valid) {
  pimpl_->is_callback_valid_ = is_callback_valid;
  return pimpl_->GetEventCallbacks();
}

+4 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#pragma once

#include <atomic>
#include <memory>

#include "hci/acl_connection_interface.h"
#include "hci/acl_manager/acl_connection.h"
#include "hci/acl_manager/connection_management_callbacks.h"
@@ -72,7 +75,7 @@ class ClassicAclConnection : public AclConnection {
  virtual bool ReadRemoteExtendedFeatures(uint8_t page_number);

  // Called once before passing the connection to the client
  virtual ConnectionManagementCallbacks* GetEventCallbacks();
  virtual ConnectionManagementCallbacks* GetEventCallbacks(std::shared_ptr<std::atomic<bool>> is_callback_valid);

 private:
  AclConnectionInterface* acl_connection_interface_;
+9 −5
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#pragma once

#include <atomic>
#include <memory>

#include "common/bind.h"
#include "hci/acl_manager/assembler.h"
#include "hci/acl_manager/event_checkers.h"
@@ -35,6 +38,7 @@ struct acl_connection {
  struct acl_manager::assembler assembler_;
  AddressWithType address_with_type_;
  ConnectionManagementCallbacks* connection_management_callbacks_ = nullptr;
  std::shared_ptr<std::atomic<bool>> is_callback_valid_ = std::make_shared<std::atomic<bool>>(true);
};

struct classic_impl : public security::ISecurityManagerListener {
@@ -65,12 +69,11 @@ struct classic_impl : public security::ISecurityManagerListener {
  }

  ConnectionManagementCallbacks* get_callbacks(uint16_t handle) {
    auto conn = acl_connections_.find(handle);
    if (conn == acl_connections_.end()) {
    auto connection = acl_connections_.find(handle);
    if (connection == acl_connections_.end()) {
      return nullptr;
    } else {
      return conn->second.connection_management_callbacks_;
    }
    return (connection->second.is_callback_valid_) ? connection->second.connection_management_callbacks_ : nullptr;
  }

  void on_classic_event(EventView event_packet) {
@@ -274,7 +277,8 @@ struct classic_impl : public security::ISecurityManagerListener {
        new ClassicAclConnection(std::move(queue), acl_connection_interface_, handle, address));
    connection->locally_initiated_ = locally_initiated;
    auto& connection_proxy = conn_pair.first->second;
    connection_proxy.connection_management_callbacks_ = connection->GetEventCallbacks();
    connection_proxy.connection_management_callbacks_ =
        connection->GetEventCallbacks(connection_proxy.is_callback_valid_);
    if (delayed_role_change_ != nullptr) {
      if (delayed_role_change_->GetBdAddr() == address) {
        LOG_INFO("Sending delayed role change for %s", delayed_role_change_->GetBdAddr().ToString().c_str());
+5 −1
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ struct LeAclConnection::impl {
  bool callbacks_given_{false};
  std::shared_ptr<Queue> queue_;
  LeAclConnectionTracker tracker;
  std::shared_ptr<std::atomic<bool>> is_callback_valid_;
};

LeAclConnection::LeAclConnection()
@@ -115,6 +116,7 @@ LeAclConnection::LeAclConnection(
}

LeAclConnection::~LeAclConnection() {
  if (pimpl_->is_callback_valid_) *pimpl_->is_callback_valid_ = false;
  delete pimpl_;
}

@@ -137,7 +139,9 @@ void LeAclConnection::Disconnect(DisconnectReason reason) {
      }));
}

LeConnectionManagementCallbacks* LeAclConnection::GetEventCallbacks() {
LeConnectionManagementCallbacks* LeAclConnection::GetEventCallbacks(
    std::shared_ptr<std::atomic<bool>> is_callback_valid) {
  pimpl_->is_callback_valid_ = is_callback_valid;
  return pimpl_->GetEventCallbacks();
}

+4 −1
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#pragma once

#include <atomic>
#include <memory>

#include "hci/acl_manager/acl_connection.h"
#include "hci/acl_manager/le_connection_management_callbacks.h"
#include "hci/address_with_type.h"
@@ -68,7 +71,7 @@ class LeAclConnection : public AclConnection {
  // TODO implement LeRemoteConnectionParameterRequestReply, LeRemoteConnectionParameterRequestNegativeReply

  // Called once before passing the connection to the client
  virtual LeConnectionManagementCallbacks* GetEventCallbacks();
  virtual LeConnectionManagementCallbacks* GetEventCallbacks(std::shared_ptr<std::atomic<bool>> is_callback_valid);

 private:
  virtual bool check_connection_parameters(
Loading