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

Commit 563b517a authored by Rahul Arya's avatar Rahul Arya
Browse files

[Invisalign] Add ConfigInterface

Add a mechanism to pass down runtime config values into the core. Also
took the opportunity to remove some minor code duplication.

Bug: 254063018
Test: all existing tests

Change-Id: I4fa447eb5f738047020e1b41ab3657d86f867dc5
parent b78e0401
Loading
Loading
Loading
Loading
+17 −1
Original line number Diff line number Diff line
@@ -69,10 +69,24 @@ struct EventCallbacks {
  EventCallbacks& operator=(const EventCallbacks&) = delete;
};

// This interface lets us query for configuration properties of the stack that
// could change at runtime
struct ConfigInterface {
  virtual bool isA2DPOffloadEnabled() = 0;
  virtual bool isAndroidTVDevice() = 0;
  virtual bool isRestrictedMode() = 0;

  explicit ConfigInterface() = default;
  ConfigInterface(const ConfigInterface&) = delete;
  ConfigInterface& operator=(const ConfigInterface&) = delete;
  virtual ~ConfigInterface() = default;
};

// This class defines the overall interface expected by bluetooth::core.
struct CoreInterface {
  // generic interface
  EventCallbacks* events;
  ConfigInterface* config;

  virtual void onBluetoothEnabled() = 0;
  virtual bt_status_t toggleProfile(tBTA_SERVICE_ID service_id,
@@ -80,7 +94,9 @@ struct CoreInterface {
  virtual void removeDeviceFromProfiles(const RawAddress& bd_addr) = 0;
  virtual void onLinkDown(const RawAddress& bd_addr) = 0;

  CoreInterface(EventCallbacks* eventCallbacks) : events{eventCallbacks} {};
  CoreInterface(EventCallbacks* eventCallbacks,
                ConfigInterface* configInterface)
      : events{eventCallbacks}, config{configInterface} {};

  CoreInterface(const CoreInterface&) = delete;
  CoreInterface& operator=(const CoreInterface&) = delete;
+25 −1
Original line number Diff line number Diff line
@@ -174,6 +174,28 @@ extern bt_status_t btif_hd_execute_service(bool b_enable);
 *  Callbacks from bluetooth::core (see go/invisalign-bt)
 ******************************************************************************/

struct ConfigInterfaceImpl : bluetooth::core::ConfigInterface {
  ConfigInterfaceImpl() : bluetooth::core::ConfigInterface(){};

  bool isRestrictedMode() override { return is_restricted_mode(); }

  bool isA2DPOffloadEnabled() override {
    char value_sup[PROPERTY_VALUE_MAX] = {'\0'};
    char value_dis[PROPERTY_VALUE_MAX] = {'\0'};

    osi_property_get("ro.bluetooth.a2dp_offload.supported", value_sup, "false");
    osi_property_get("persist.bluetooth.a2dp_offload.disabled", value_dis,
                     "false");
    auto a2dp_offload_enabled =
        (strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0);
    BTIF_TRACE_DEBUG("a2dp_offload.enable = %d", a2dp_offload_enabled);

    return a2dp_offload_enabled;
  }

  bool isAndroidTVDevice() override { return is_atv_device(); }
};

struct CoreInterfaceImpl : bluetooth::core::CoreInterface {
  using bluetooth::core::CoreInterface::CoreInterface;

@@ -272,7 +294,9 @@ static bluetooth::core::CoreInterface* CreateInterfaceToProfiles() {
      .invoke_le_test_mode_cb = invoke_le_test_mode_cb,
      .invoke_energy_info_cb = invoke_energy_info_cb,
      .invoke_link_quality_report_cb = invoke_link_quality_report_cb};
  static auto interfaceForCore = CoreInterfaceImpl(&eventCallbacks);
  static auto configInterface = ConfigInterfaceImpl();
  static auto interfaceForCore =
      CoreInterfaceImpl(&eventCallbacks, &configInterface);
  return &interfaceForCore;
}

+2 −6
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
#include "btif/include/btif_profile_queue.h"
#include "btif/include/btif_rc.h"
#include "btif/include/btif_util.h"
#include "btif/include/stack_manager.h"
#include "btif_metrics_logging.h"
#include "common/metrics.h"
#include "common/state_machine.h"
@@ -978,13 +979,8 @@ bt_status_t BtifAvSource::Init(
  max_connected_peers_ = max_connected_audio_devices;

  /* A2DP OFFLOAD */
  char value_sup[PROPERTY_VALUE_MAX] = {'\0'};
  char value_dis[PROPERTY_VALUE_MAX] = {'\0'};
  osi_property_get("ro.bluetooth.a2dp_offload.supported", value_sup, "false");
  osi_property_get("persist.bluetooth.a2dp_offload.disabled", value_dis,
                   "false");
  a2dp_offload_enabled_ =
      (strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0);
      GetInterfaceToProfiles()->config->isA2DPOffloadEnabled();
  BTIF_TRACE_DEBUG("a2dp_offload.enable = %d", a2dp_offload_enabled_);

  callbacks_ = callbacks;
+2 −17
Original line number Diff line number Diff line
@@ -253,21 +253,6 @@ bt_status_t btif_init_bluetooth() {
  return BT_STATUS_SUCCESS;
}

static bool btif_is_a2dp_offload_enabled() {
  char value_sup[PROPERTY_VALUE_MAX] = {'\0'};
  char value_dis[PROPERTY_VALUE_MAX] = {'\0'};
  bool a2dp_offload_enabled_;

  osi_property_get("ro.bluetooth.a2dp_offload.supported", value_sup, "false");
  osi_property_get("persist.bluetooth.a2dp_offload.disabled", value_dis,
                   "false");
  a2dp_offload_enabled_ =
      (strcmp(value_sup, "true") == 0) && (strcmp(value_dis, "false") == 0);
  BTIF_TRACE_DEBUG("a2dp_offload.enable = %d", a2dp_offload_enabled_);

  return a2dp_offload_enabled_;
}

/*******************************************************************************
 *
 * Function         btif_enable_bluetooth_evt
@@ -641,7 +626,7 @@ void btif_get_adapter_property(bt_property_type_t type) {
    BTM_BleGetVendorCapabilities(&cmn_vsc_cb);

    prop.len = sizeof(bt_dynamic_audio_buffer_item_t);
    if (btif_is_a2dp_offload_enabled() == false) {
    if (GetInterfaceToProfiles()->config->isA2DPOffloadEnabled() == false) {
      BTIF_TRACE_DEBUG("%s Get buffer millis for A2DP software encoding",
                       __func__);
      for (int i = 0; i < CODEC_TYPE_NUMBER; i++) {
@@ -903,7 +888,7 @@ bt_status_t btif_set_dynamic_audio_buffer_size(int codec, int size) {
  tBTM_BLE_VSC_CB cmn_vsc_cb;
  BTM_BleGetVendorCapabilities(&cmn_vsc_cb);

  if (!btif_av_is_a2dp_offload_enabled()) {
  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)));
+2 −1
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ constexpr char kPrivateAddressPrefix[] = "xx:xx:xx:xx";
#include "btif_hd.h"
#include "btif_hh.h"
#include "btif_util.h"
#include "core_callbacks.h"
#include "device/include/controller.h"
#include "gd/common/init_flags.h"
#include "osi/include/allocator.h"
@@ -921,7 +922,7 @@ bt_status_t btif_storage_add_bonded_device(RawAddress* remote_bd_addr,
  ret &=
      btif_config_set_bin(bdstr, "LinkKey", link_key.data(), link_key.size());

  if (is_restricted_mode()) {
  if (GetInterfaceToProfiles()->config->isRestrictedMode()) {
    BTIF_TRACE_WARNING("%s: '%s' pairing will be removed if unrestricted",
                       __func__, bdstr.c_str());
    btif_config_set_int(bdstr, "Restricted", 1);
Loading