2 // Copyright 2015 Google, Inc.
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at:
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
17 #define LOG_TAG "hal_util"
19 #include <base/logging.h>
20 #include <base/strings/stringprintf.h>
21 #include <hardware/bluetooth.h>
27 #include "btcore/include/hal_util.h"
28 #include "osi/include/log.h"
30 using base::StringPrintf;
32 #define BLUETOOTH_LIBRARY_NAME "libbluetooth.so"
34 int hal_util_load_bt_library(const bt_interface_t** interface) {
35 const char* sym = BLUETOOTH_INTERFACE_STRING;
36 bt_interface_t* itf = nullptr;
38 // Always try to load the default Bluetooth stack on GN builds.
39 void* handle = dlopen(BLUETOOTH_LIBRARY_NAME, RTLD_NOW);
41 const char* err_str = dlerror();
42 LOG(ERROR) << __func__ << ": failed to load bluetooth library, error="
43 << (err_str ? err_str : "error unknown");
47 // Get the address of the bt_interface_t.
48 itf = (bt_interface_t*)dlsym(handle, sym);
50 LOG(ERROR) << __func__ << ": failed to load symbol from Bluetooth library "
56 LOG(INFO) << __func__ << " loaded HAL path=" << BLUETOOTH_LIBRARY_NAME
57 << " btinterface=" << itf << " handle=" << handle;
64 if (handle) dlclose(handle);