mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 16:23:37 +00:00
Merge "Audio: Load Bluetooth AIDL HAL" am: 9938caf08b am: ea8522964b
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1942860 Change-Id: Ia306c81cecfffbb1e0c6929a13a2daa4dc0a4285
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user