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

Commit 07bfede0 authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Gerrit Code Review
Browse files

Merge "Remove hw_module_t dependency in Bluetooth (3/3)"

parents 81283257 d47f2d8d
Loading
Loading
Loading
Loading
+11 −34
Original line number Diff line number Diff line
@@ -593,10 +593,9 @@ static bt_os_callouts_t sBluetoothOsCallouts = {
#define BLUETOOTH_LIBRARY_NAME "/system/lib/hw/bluetooth.default.so"
#endif

int hal_util_load_bt_library(const struct hw_module_t** module) {
  const char* id = BT_STACK_MODULE_ID;
  const char* sym = HAL_MODULE_INFO_SYM_AS_STR;
  struct hw_module_t* hmi = nullptr;
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.
  const char* path = BLUETOOTH_LIBRARY_NAME;
@@ -608,32 +607,22 @@ int hal_util_load_bt_library(const struct hw_module_t** module) {
    goto error;
  }

  // Get the address of the struct hal_module_info.
  hmi = (struct hw_module_t*)dlsym(handle, sym);
  if (!hmi) {
  // 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;
  }

  // Check that the id matches.
  if (strcmp(id, hmi->id) != 0) {
    LOG(ERROR) << StringPrintf("%s: id=%s does not match HAL module ID: %s",
                               __func__, id, hmi->id);
    goto error;
  }

  hmi->dso = handle;

  // Success.
  LOG(INFO) << StringPrintf("%s: loaded HAL id=%s path=%s hmi=%p handle=%p",
                            __func__, id, path, hmi, handle);

  *module = hmi;
  LOG(INFO) << __func__ << " loaded HAL: btinterface=" << itf
            << ", handle=" << handle;
  *interface = itf;
  return 0;

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

  return -EINVAL;
@@ -680,19 +669,7 @@ static void classInitNative(JNIEnv* env, jclass clazz) {
  method_energyInfo = env->GetMethodID(
      clazz, "energyInfoCallback", "(IIJJJJ[Landroid/bluetooth/UidTraffic;)V");

  hw_module_t* module;
  int err = hal_util_load_bt_library((hw_module_t const**)&module);

  if (err == 0) {
    hw_device_t* abstraction;
    err = module->methods->open(module, BT_STACK_MODULE_ID, &abstraction);
    if (err == 0) {
      bluetooth_module_t* btStack = (bluetooth_module_t*)abstraction;
      sBluetoothInterface = btStack->get_bluetooth_interface();
    } else {
      ALOGE("Error while opening Bluetooth library");
    }
  } else {
  if (hal_util_load_bt_library((bt_interface_t const**)&sBluetoothInterface)) {
    ALOGE("No Bluetooth Library found");
  }
}