diff options
author | Josh Wu <joshwu@google.com> | 2022-01-18 03:01:19 -0800 |
---|---|---|
committer | Josh Wu <joshwu@google.com> | 2022-02-16 12:01:59 -0800 |
commit | 3f8f5997ada49bcc7be7f5bccfddf024684faef1 (patch) | |
tree | 9e62f3c3742ce9ab9a527fc53890111742436f93 | |
parent | 0f7d41913658132823980112d6f704b6489396d2 (diff) |
Audio: Load Bluetooth AIDL HAL
Test: m android.hardware.audio.service
Bug: 203490261
Change-Id: If518ed69331489bd9aeb2a0c58e17c2917e3c0cf
-rw-r--r-- | audio/common/all-versions/default/service/service.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/audio/common/all-versions/default/service/service.cpp b/audio/common/all-versions/default/service/service.cpp index 3472af134e..fbf616563d 100644 --- a/audio/common/all-versions/default/service/service.cpp +++ b/audio/common/all-versions/default/service/service.cpp @@ -23,6 +23,7 @@ #include <android/binder_process.h> #include <binder/ProcessState.h> #include <cutils/properties.h> +#include <dlfcn.h> #include <hidl/HidlTransportSupport.h> #include <hidl/LegacySupport.h> #include <hwbinder/ProcessState.h> @@ -46,6 +47,31 @@ static bool registerPassthroughServiceImplementations(Iter first, Iter last) { return false; } +static bool registerExternalServiceImplementation(const std::string& libName, + const std::string& funcName) { + constexpr int dlMode = RTLD_LAZY; + void* handle = nullptr; + dlerror(); // clear + auto libPath = libName + ".so"; + handle = dlopen(libPath.c_str(), dlMode); + if (handle == nullptr) { + const char* error = dlerror(); + ALOGE("Failed to dlopen %s: %s", libPath.c_str(), + error != nullptr ? error : "unknown error"); + return false; + } + binder_status_t (*factoryFunction)(); + *(void**)(&factoryFunction) = dlsym(handle, funcName.c_str()); + if (!factoryFunction) { + const char* error = dlerror(); + ALOGE("Factory function %s not found in libName %s: %s", funcName.c_str(), libPath.c_str(), + error != nullptr ? error : "unknown error"); + dlclose(handle); + return false; + } + return ((*factoryFunction)() == STATUS_OK); +} + int main(int /* argc */, char* /* argv */ []) { signal(SIGPIPE, SIG_IGN); @@ -105,6 +131,13 @@ int main(int /* argc */, char* /* argv */ []) { "android.hardware.bluetooth.a2dp@1.0::IBluetoothAudioOffload" } }; + + const std::vector<std::pair<std::string,std::string>> optionalInterfaceSharedLibs = { + { + "android.hardware.bluetooth.audio-impl", + "createIBluetoothAudioProviderFactory", + }, + }; // clang-format on for (const auto& listIter : mandatoryInterfaces) { @@ -121,5 +154,15 @@ int main(int /* argc */, char* /* argv */ []) { "Could not register %s", interfaceFamilyName.c_str()); } + for (const auto& interfacePair : optionalInterfaceSharedLibs) { + const std::string& libraryName = interfacePair.first; + const std::string& interfaceLoaderFuncName = interfacePair.second; + if (registerExternalServiceImplementation(libraryName, interfaceLoaderFuncName)) { + ALOGI("%s() from %s success", interfaceLoaderFuncName.c_str(), libraryName.c_str()); + } else { + ALOGW("%s() from %s failed", interfaceLoaderFuncName.c_str(), libraryName.c_str()); + } + } + joinRpcThreadpool(); } |