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

Commit 897dda37 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Remove dynamic legacy module lookup aka STATIC_LIBBLUETOOTH"

parents 4a9f1e65 16230260
Loading
Loading
Loading
Loading
+0 −39
Original line number Diff line number Diff line
@@ -29,44 +29,6 @@

using base::StringPrintf;

#define BLUETOOTH_LIBRARY_NAME "libbluetooth.so"

#if !defined(STATIC_LIBBLUETOOTH)
int hal_util_load_bt_library(const bt_interface_t** interface) {
  const char* sym = BLUETOOTH_INTERFACE_STRING;
  bt_interface_t* itf = nullptr;

  // Always try to load the default Bluetooth stack on GN builds.
  void* handle = dlopen(BLUETOOTH_LIBRARY_NAME, RTLD_NOW);
  if (!handle) {
    const char* err_str = dlerror();
    LOG(ERROR) << __func__ << ": failed to load bluetooth library, error="
               << (err_str ? err_str : "error unknown");
    goto error;
  }

  // Get the address of the bt_interface_t.
  itf = (bt_interface_t*)dlsym(handle, sym);
  if (!itf) {
    LOG(ERROR) << __func__ << ": failed to load symbol from Bluetooth library "
               << sym;
    goto error;
  }

  // Success.
  LOG(INFO) << __func__ << " loaded HAL path=" << BLUETOOTH_LIBRARY_NAME
            << " btinterface=" << itf << " handle=" << handle;

  *interface = itf;
  return 0;

error:
  *interface = NULL;
  if (handle) dlclose(handle);

  return -EINVAL;
}
#else
extern bt_interface_t bluetoothInterface;

int hal_util_load_bt_library(const bt_interface_t** interface) {
@@ -74,4 +36,3 @@ int hal_util_load_bt_library(const bt_interface_t** interface) {

  return 0;
}
#endif
+7 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <map>

#include "bta/include/bta_ag_api.h"
#include "btcore/include/module.h"
#include "btif/include/btif_api.h"
#include "btif/include/btif_common.h"
#include "types/raw_address.h"
@@ -32,6 +33,12 @@ uint8_t btu_trace_level = BT_TRACE_LEVEL_DEBUG;

const tBTA_AG_RES_DATA tBTA_AG_RES_DATA::kEmpty = {};

module_t bt_utils_module;
module_t gd_controller_module;
module_t gd_idle_module;
module_t gd_shim_module;
module_t osi_module;

namespace {

auto timeout_time = std::chrono::seconds(3);
+874 −0

File added.

Preview size limit exceeded, changes collapsed.

+39 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

#include <base/logging.h>
#include <base/observer_list.h>
#include <dlfcn.h>

#include <mutex>
#include <shared_mutex>
@@ -235,6 +236,43 @@ bt_os_callouts_t bt_os_callouts = {sizeof(bt_os_callouts_t),
                                   SetWakeAlarmCallout, AcquireWakeLockCallout,
                                   ReleaseWakeLockCallout};

constexpr char kLibbluetooth[] = "libbluetooth.so";
constexpr char kBluetoothInterfaceSym[] = "bluetoothInterface";

int hal_util_load_bt_library_from_dlib(const bt_interface_t** interface) {
  bt_interface_t* itf{nullptr};

  // Always try to load the default Bluetooth stack on GN builds.
  void* handle = dlopen(kLibbluetooth, RTLD_NOW);
  if (!handle) {
    const char* err_str = dlerror();
    LOG(ERROR) << __func__ << ": failed to load bluetooth library, error="
               << (err_str ? err_str : "error unknown");
    goto error;
  }

  // Get the address of the bt_interface_t.
  itf = (bt_interface_t*)dlsym(handle, kBluetoothInterfaceSym);
  if (!itf) {
    LOG(ERROR) << __func__ << ": failed to load symbol from Bluetooth library "
               << kBluetoothInterfaceSym;
    goto error;
  }

  // Success.
  LOG(INFO) << __func__ << " loaded HAL path=" << kLibbluetooth
            << " btinterface=" << itf << " handle=" << handle;

  *interface = itf;
  return 0;

error:
  *interface = NULL;
  if (handle) dlclose(handle);

  return -EINVAL;
}

}  // namespace

// BluetoothInterface implementation for production.
@@ -266,7 +304,7 @@ class BluetoothInterfaceImpl : public BluetoothInterface {
  bool Initialize() {
    // Load the Bluetooth shared library module.
    const bt_interface_t* interface;
    int status = hal_util_load_bt_library(&interface);
    int status = hal_util_load_bt_library_from_dlib(&interface);
    if (status) {
      LOG(ERROR) << "Failed to open the Bluetooth module";
      return false;
+18 −2
Original line number Diff line number Diff line
@@ -12,8 +12,16 @@ cc_test {
    name: "net_test_bluetooth",
    test_suites: ["device-tests"],
    defaults: ["fluoride_defaults"],
    include_dirs: ["packages/modules/Bluetooth/system"],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/include",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    srcs: [
        ":TestCommonMockFunctions",
        ":TestMockBluetoothInterface",
        ":TestMockDevice",
        "adapter/adapter_unittest.cc",
        "adapter/bluetooth_test.cc",
        "gatt/gatt_test.cc",
@@ -39,8 +47,16 @@ cc_test {
cc_test {
    name: "net_test_rfcomm_suite",
    defaults: ["fluoride_defaults"],
    include_dirs: ["packages/modules/Bluetooth/system"],
    include_dirs: [
        "packages/modules/Bluetooth/system",
        "packages/modules/Bluetooth/system/gd",
        "packages/modules/Bluetooth/system/include",
        "packages/modules/Bluetooth/system/stack/include",
    ],
    srcs: [
        ":TestMockBluetoothInterface",
        ":TestMockDevice",
        ":TestCommonMockFunctions",
        "adapter/bluetooth_test.cc",
        "rfcomm/rfcomm_test.cc",
        "rfcomm/rfcomm_unittest.cc",