Loading audio/common/all-versions/default/service/service.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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); Loading Loading @@ -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) { Loading @@ -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(); } Loading
audio/common/all-versions/default/service/service.cpp +43 −0 Original line number Diff line number Diff line Loading @@ -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> Loading @@ -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); Loading Loading @@ -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) { Loading @@ -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(); }