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

Commit 4ed908e6 authored by Rahul Arya's avatar Rahul Arya
Browse files

[Invisalign] Add HACK_* interface for ad-hoc callbacks out of the core

We shouldn't have these, but they exist, and I don't want to touch what
isn't obviously broken.

Bug: 254063018
Test: all existing tests
Change-Id: I069bb911da4639adc83268e641718b1fbb57090c
parent bd81727d
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@
#include "bta/include/bta_api.h"
#include "bta/include/bta_dm_api.h"
#include "bta/sys/bta_sys.h"
#include "btif/include/core_callbacks.h"
#include "btif/include/stack_manager.h"
#include "device/include/controller.h"
#include "main/shim/dumpsys.h"
#include "osi/include/log.h"
@@ -863,8 +865,9 @@ static void bta_dm_pm_ssr(const RawAddress& peer_addr, const int ssr) {
    /* HH has the per connection SSR preference, already read the SSR params
     * from BTA HH */
    if (current_ssr_index == BTA_DM_PM_SSR_HH) {
      if (bta_hh_read_ssr_param(peer_addr, &p_spec_cur->max_lat,
                                &p_spec_cur->min_rmt_to) == BTA_HH_ERR) {
      if (GetInterfaceToProfiles()->profileSpecific_HACK->bta_hh_read_ssr_param(
              peer_addr, &p_spec_cur->max_lat, &p_spec_cur->min_rmt_to) ==
          BTA_HH_ERR) {
        continue;
      }
    }
+7 −2
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@
#include "bta/gatt/bta_gattc_int.h"
#include "bta/hh/bta_hh_int.h"
#include "btif/include/btif_debug_conn.h"
#include "btif/include/core_callbacks.h"
#include "btif/include/stack_manager.h"
#include "device/include/controller.h"
#include "main/shim/dumpsys.h"
#include "osi/include/allocator.h"
@@ -144,7 +146,9 @@ void bta_gattc_disable() {
    bta_gattc_cb.state = BTA_GATTC_STATE_DISABLING;
/* don't deregister HH GATT IF */
/* HH GATT IF will be deregistered by bta_hh_le_deregister when disable HH */
    if (!bta_hh_le_is_hh_gatt_if(bta_gattc_cb.cl_rcb[i].client_if)) {
    if (!GetInterfaceToProfiles()
             ->profileSpecific_HACK->bta_hh_le_is_hh_gatt_if(
                 bta_gattc_cb.cl_rcb[i].client_if)) {
      bta_gattc_deregister(&bta_gattc_cb.cl_rcb[i]);
    }
  }
@@ -224,7 +228,8 @@ void bta_gattc_register(const Uuid& app_uuid, tBTA_GATTC_CBACK* p_cback,
void bta_gattc_deregister(tBTA_GATTC_RCB* p_clreg) {
  if (!p_clreg) {
    LOG(ERROR) << __func__ << ": Deregister Failed unknown client cif";
    bta_hh_cleanup_disable(BTA_HH_OK);
    GetInterfaceToProfiles()->profileSpecific_HACK->bta_hh_cleanup_disable(
        BTA_HH_OK);
    return;
  }

+35 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#pragma once

#include "bta/include/bta_api.h"
#include "bta/include/bta_hh_api.h"
#include "include/hardware/bluetooth.h"
#include "stack/include/btm_ble_api_types.h"
#include "types/raw_address.h"
@@ -97,6 +98,33 @@ struct CodecInterface {
  virtual ~CodecInterface() = default;
};

// Please DO NOT add any more methods to this interface.
// It is a legacy violation of the abstraction
// between core and profiles: the core stack should not have any
// profile-specific functionality or call directly into profile code, as this
// makes refactoring + testing much harder. Instead, create a *generic* callback
// that profiles can register themselves to.
struct HACK_ProfileInterface {
  // HID hacks
  bt_status_t (*btif_hh_connect)(const RawAddress* bd_addr);
  bt_status_t (*btif_hh_virtual_unplug)(const RawAddress* bd_addr);
  tBTA_HH_STATUS (*bta_hh_read_ssr_param)(const RawAddress& bd_addr,
                                          uint16_t* p_max_ssr_lat,
                                          uint16_t* p_min_ssr_tout);
  bool (*bta_hh_le_is_hh_gatt_if)(tGATT_IF client_if);
  void (*bta_hh_cleanup_disable)(tBTA_HH_STATUS status);

  // AVDTP hacks
  void (*btif_av_set_dynamic_audio_buffer_size)(
      uint8_t dynamic_audio_buffer_size);

  // ASHA hacks
  int (*GetHearingAidDeviceCount)();

  HACK_ProfileInterface(const HACK_ProfileInterface&) = delete;
  HACK_ProfileInterface& operator=(const HACK_ProfileInterface&) = delete;
};

// This class defines the overall interface expected by bluetooth::core.
struct CoreInterface {
  // generic interface
@@ -106,6 +134,9 @@ struct CoreInterface {
  // codecs
  CodecInterface* msbcCodec;

  // DO NOT add any more methods here
  HACK_ProfileInterface* profileSpecific_HACK;

  virtual void onBluetoothEnabled() = 0;
  virtual bt_status_t toggleProfile(tBTA_SERVICE_ID service_id,
                                    bool enable) = 0;
@@ -113,10 +144,12 @@ struct CoreInterface {
  virtual void onLinkDown(const RawAddress& bd_addr) = 0;

  CoreInterface(EventCallbacks* eventCallbacks,
                ConfigInterface* configInterface, CodecInterface* msbcCodec)
                ConfigInterface* configInterface, CodecInterface* msbcCodec,
                HACK_ProfileInterface* profileSpecific_HACK)
      : events{eventCallbacks},
        config{configInterface},
        msbcCodec{msbcCodec} {};
        msbcCodec{msbcCodec},
        profileSpecific_HACK{profileSpecific_HACK} {};

  CoreInterface(const CoreInterface&) = delete;
  CoreInterface& operator=(const CoreInterface&) = delete;
+19 −1
Original line number Diff line number Diff line
@@ -50,6 +50,7 @@

#include "audio_hal_interface/a2dp_encoding.h"
#include "bt_utils.h"
#include "bta/hh/bta_hh_int.h"  // for HID HACK profile methods
#include "bta/include/bta_ar_api.h"
#include "bta/include/bta_csis_api.h"
#include "bta/include/bta_has_api.h"
@@ -59,6 +60,7 @@
#include "bta/include/bta_le_audio_broadcaster_api.h"
#include "bta/include/bta_vc_api.h"
#include "btif/avrcp/avrcp_service.h"
#include "btif/include/core_callbacks.h"
#include "btif/include/stack_manager.h"
#include "btif_a2dp.h"
#include "btif_activity_attribution.h"
@@ -101,6 +103,7 @@
#include "stack/include/hfp_msbc_encoder.h"
#include "stack/include/hidh_api.h"
#include "stack/include/pan_api.h"
#include "stack_config.h"
#include "types/raw_address.h"

using bluetooth::csis::CsisClientInterface;
@@ -321,8 +324,23 @@ static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() {
      .invoke_link_quality_report_cb = invoke_link_quality_report_cb};
  static auto configInterface = ConfigInterfaceImpl();
  static auto msbcCodecInterface = MSBCCodec();
  static auto profileInterface = bluetooth::core::HACK_ProfileInterface{
      // HID
      .btif_hh_connect = btif_hh_connect,
      .btif_hh_virtual_unplug = btif_hh_virtual_unplug,
      .bta_hh_read_ssr_param = bta_hh_read_ssr_param,
      .bta_hh_le_is_hh_gatt_if = bta_hh_le_is_hh_gatt_if,
      .bta_hh_cleanup_disable = bta_hh_cleanup_disable,

      // AVDTP
      .btif_av_set_dynamic_audio_buffer_size =
          btif_av_set_dynamic_audio_buffer_size,

      // ASHA
      .GetHearingAidDeviceCount = HearingAid::GetDeviceCount};
  static auto interfaceForCore =
      CoreInterfaceImpl(&eventCallbacks, &configInterface, &msbcCodecInterface);
      CoreInterfaceImpl(&eventCallbacks, &configInterface, &msbcCodecInterface,
                        &profileInterface);
  return &interfaceForCore;
}

+4 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include "btif/include/btif_profile_queue.h"
#include "btif/include/btif_sock.h"
#include "btif/include/btif_storage.h"
#include "btif/include/core_callbacks.h"
#include "btif/include/stack_manager.h"
#include "common/message_loop_thread.h"
#include "device/include/controller.h"
@@ -891,7 +892,9 @@ bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size) {
  if (!GetInterfaceToProfiles()->config->isA2DPOffloadEnabled()) {
    BTIF_TRACE_DEBUG("%s Set buffer size (%d) for A2DP software encoding",
                     __func__, size);
    btif_av_set_dynamic_audio_buffer_size((uint8_t(size)));
    GetInterfaceToProfiles()
        ->profileSpecific_HACK->btif_av_set_dynamic_audio_buffer_size(
            uint8_t(size));
  } else {
    if (cmn_vsc_cb.dynamic_audio_buffer_support != 0) {
      BTIF_TRACE_DEBUG("%s Set buffer size (%d) for A2DP offload", __func__,
Loading