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

Commit 68044e81 authored by Hansong Zhang's avatar Hansong Zhang Committed by Automerger Merge Worker
Browse files

Shim hack: Add SCO disconnect callback am: b1b61f90 am: aae12e0c

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1547314

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I1a9289350b030fdc365a210a4b16cb2181b6e56a
parents 3e48561b aae12e0c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -245,6 +245,10 @@ uint16_t AclManager::HACK_GetLeHandle(Address address) {
  return pimpl_->le_impl_->HACK_get_handle(address);
}

void AclManager::HACK_SetScoDisconnectCallback(std::function<void(uint16_t, uint8_t)> callback) {
  pimpl_->classic_impl_->HACK_SetScoDisconnectCallback(callback);
}

void AclManager::ListDependencies(ModuleList* list) {
  list->add<HciLayer>();
  list->add<Controller>();
+69 −62
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#pragma once

#include <functional>
#include <memory>

#include "common/bidi_queue.h"
@@ -37,12 +38,15 @@ class SecurityModule;
}
namespace shim {
class Btm;
void L2CA_UseLegacySecurityModule();
}

namespace hci {

class AclManager : public Module {
 friend class bluetooth::shim::Btm;
 friend void bluetooth::shim::L2CA_UseLegacySecurityModule();

public:
 AclManager();
 // NOTE: It is necessary to forward declare a default destructor that overrides the base class one, because
@@ -122,6 +126,9 @@ class AclManager : public Module {
 virtual uint16_t HACK_GetHandle(const Address address);
 virtual uint16_t HACK_GetLeHandle(const Address address);

 // Hack for the shim to get SCO disconnect callback.  Shim needs to post to their handler!
 virtual void HACK_SetScoDisconnectCallback(std::function<void(uint16_t /* handle */, uint8_t /* reason */)>);

 struct impl;
 std::unique_ptr<impl> pimpl_;

+11 −0
Original line number Diff line number Diff line
@@ -134,6 +134,11 @@ struct classic_impl : public security::ISecurityManagerListener {
      round_robin_scheduler_->Unregister(handle);
      callbacks->OnDisconnection(reason);
      acl_connections_.erase(handle);
    } else {
      // This handle is probably for SCO, so we use the callback workaround.
      if (sco_disconnect_callback_ != nullptr) {
        sco_disconnect_callback_(handle, static_cast<uint8_t>(reason));
      }
    }
  }

@@ -631,6 +636,10 @@ struct classic_impl : public security::ISecurityManagerListener {
    return 0xFFFF;
  }

  void HACK_SetScoDisconnectCallback(std::function<void(uint16_t, uint8_t)> callback) {
    sco_disconnect_callback_ = callback;
  }

  HciLayer* hci_layer_ = nullptr;
  Controller* controller_ = nullptr;
  RoundRobinScheduler* round_robin_scheduler_ = nullptr;
@@ -646,6 +655,8 @@ struct classic_impl : public security::ISecurityManagerListener {

  std::unique_ptr<security::SecurityManager> security_manager_;
  bool crash_on_unknown_handle_ = false;

  std::function<void(uint16_t, uint8_t)> sco_disconnect_callback_;
};

}  // namespace acl_manager
+7 −0
Original line number Diff line number Diff line
@@ -585,6 +585,11 @@ bool L2CA_ReadRemoteVersion(const RawAddress& addr, uint8_t* lmp_version,
  return true;
}

static void on_sco_disconnect(uint16_t handle, uint8_t reason) {
  GetGdShimHandler()->Post(
      base::BindOnce(base::IgnoreResult(&btm_sco_removed), handle, reason));
}

void L2CA_UseLegacySecurityModule() {
  LOG_INFO("GD L2cap is using legacy security module");
  GetL2capClassicModule()->SetLinkPropertyListener(
@@ -616,6 +621,8 @@ void L2CA_UseLegacySecurityModule() {
  GetAclManager()->SetPrivacyPolicyForInitiatorAddress(
      address_policy, empty_address_with_type, rotation_irk,
      minimum_rotation_time, maximum_rotation_time);

  GetAclManager()->HACK_SetScoDisconnectCallback(on_sco_disconnect);
}

/**