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

Commit c43c0bcb authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Audio: Load Bluetooth AIDL HAL" am: 9938caf0 am: ea852296

Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1942860

Change-Id: Ia306c81cecfffbb1e0c6929a13a2daa4dc0a4285
parents 6f876987 ea852296
Loading
Loading
Loading
Loading
+43 −0
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@
#include <android/binder_process.h>
#include <android/binder_process.h>
#include <binder/ProcessState.h>
#include <binder/ProcessState.h>
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <dlfcn.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/LegacySupport.h>
#include <hidl/LegacySupport.h>
#include <hwbinder/ProcessState.h>
#include <hwbinder/ProcessState.h>
@@ -46,6 +47,31 @@ static bool registerPassthroughServiceImplementations(Iter first, Iter last) {
    return false;
    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 */ []) {
int main(int /* argc */, char* /* argv */ []) {
    signal(SIGPIPE, SIG_IGN);
    signal(SIGPIPE, SIG_IGN);


@@ -105,6 +131,13 @@ int main(int /* argc */, char* /* argv */ []) {
            "android.hardware.bluetooth.a2dp@1.0::IBluetoothAudioOffload"
            "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
    // clang-format on


    for (const auto& listIter : mandatoryInterfaces) {
    for (const auto& listIter : mandatoryInterfaces) {
@@ -121,5 +154,15 @@ int main(int /* argc */, char* /* argv */ []) {
                 "Could not register %s", interfaceFamilyName.c_str());
                 "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();
    joinRpcThreadpool();
}
}