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

Commit 138c2bba authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "audio: Remove dynamic dependency on HIDL interface libs from service"

parents 056ffd93 e74b5717
Loading
Loading
Loading
Loading
+0 −17
Original line number Original line Diff line number Diff line
@@ -24,23 +24,6 @@ cc_binary {
        "liblog",
        "liblog",
        "libutils",
        "libutils",
        "libhardware",
        "libhardware",
        "android.hardware.audio@2.0",
        "android.hardware.audio@4.0",
        "android.hardware.audio@5.0",
        "android.hardware.audio@6.0",
        "android.hardware.audio.common@2.0",
        "android.hardware.audio.common@4.0",
        "android.hardware.audio.common@5.0",
        "android.hardware.audio.common@6.0",
        "android.hardware.audio.effect@2.0",
        "android.hardware.audio.effect@4.0",
        "android.hardware.audio.effect@5.0",
        "android.hardware.audio.effect@6.0",
        "android.hardware.bluetooth.a2dp@1.0",
        "android.hardware.bluetooth.audio@2.0",
        "android.hardware.soundtrigger@2.0",
        "android.hardware.soundtrigger@2.1",
        "android.hardware.soundtrigger@2.2",
    ],
    ],
}
}


+59 −41
Original line number Original line Diff line number Diff line
@@ -16,19 +16,9 @@


#define LOG_TAG "audiohalservice"
#define LOG_TAG "audiohalservice"


#include <android/hardware/audio/2.0/IDevicesFactory.h>
#include <string>
#include <android/hardware/audio/4.0/IDevicesFactory.h>
#include <vector>
#include <android/hardware/audio/5.0/IDevicesFactory.h>

#include <android/hardware/audio/6.0/IDevicesFactory.h>
#include <android/hardware/audio/effect/2.0/IEffectsFactory.h>
#include <android/hardware/audio/effect/4.0/IEffectsFactory.h>
#include <android/hardware/audio/effect/5.0/IEffectsFactory.h>
#include <android/hardware/audio/effect/6.0/IEffectsFactory.h>
#include <android/hardware/bluetooth/a2dp/1.0/IBluetoothAudioOffload.h>
#include <android/hardware/bluetooth/audio/2.0/IBluetoothAudioProvidersFactory.h>
#include <android/hardware/soundtrigger/2.0/ISoundTriggerHw.h>
#include <android/hardware/soundtrigger/2.1/ISoundTriggerHw.h>
#include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h>
#include <binder/ProcessState.h>
#include <binder/ProcessState.h>
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <hidl/HidlTransportSupport.h>
#include <hidl/HidlTransportSupport.h>
@@ -38,13 +28,20 @@
using namespace android::hardware;
using namespace android::hardware;
using android::OK;
using android::OK;


using InterfacesList = std::vector<std::string>;

/** Try to register the provided factories in the provided order.
/** Try to register the provided factories in the provided order.
 *  If any registers successfully, do not register any other and return true.
 *  If any registers successfully, do not register any other and return true.
 *  If all fail, return false.
 *  If all fail, return false.
 */
 */
template <class... Factories>
template <class Iter>
bool registerPassthroughServiceImplementations() {
static bool registerPassthroughServiceImplementations(Iter first, Iter last) {
    return ((registerPassthroughServiceImplementation<Factories>() != OK) && ...);
    for (; first != last; ++first) {
        if (registerPassthroughServiceImplementation(*first) == OK) {
            return true;
        }
    }
    return false;
}
}


int main(int /* argc */, char* /* argv */ []) {
int main(int /* argc */, char* /* argv */ []) {
@@ -61,36 +58,57 @@ int main(int /* argc */, char* /* argv */ []) {
    }
    }
    configureRpcThreadpool(16, true /*callerWillJoin*/);
    configureRpcThreadpool(16, true /*callerWillJoin*/);


    // Keep versions on a separate line for easier parsing
    // Automatic formatting tries to compact the lines, making them less readable
    // clang-format off
    // clang-format off
    LOG_ALWAYS_FATAL_IF((registerPassthroughServiceImplementations<
    const std::vector<InterfacesList> mandatoryInterfaces = {
                                audio::V6_0::IDevicesFactory,
        {
                                audio::V5_0::IDevicesFactory,
            "Audio Core API",
                                audio::V4_0::IDevicesFactory,
            "android.hardware.audio@6.0::IDevicesFactory",
                                audio::V2_0::IDevicesFactory>()),
            "android.hardware.audio@5.0::IDevicesFactory",
                        "Could not register audio core API");
            "android.hardware.audio@4.0::IDevicesFactory",
            "android.hardware.audio@2.0::IDevicesFactory"
        },
        {
            "Audio Effect API",
            "android.hardware.audio.effect@6.0::IEffectsFactory",
            "android.hardware.audio.effect@5.0::IEffectsFactory",
            "android.hardware.audio.effect@4.0::IEffectsFactory",
            "android.hardware.audio.effect@2.0::IEffectsFactory",
        }
    };


    LOG_ALWAYS_FATAL_IF((registerPassthroughServiceImplementations<
    const std::vector<InterfacesList> optionalInterfaces = {
                                audio::effect::V6_0::IEffectsFactory,
        {
                                audio::effect::V5_0::IEffectsFactory,
            "Soundtrigger API",
                                audio::effect::V4_0::IEffectsFactory,
            "android.hardware.soundtrigger@2.2::ISoundTriggerHw",
                                audio::effect::V2_0::IEffectsFactory>()),
            "android.hardware.soundtrigger@2.1::ISoundTriggerHw",
                        "Could not register audio effect API");
            "android.hardware.soundtrigger@2.0::ISoundTriggerHw",
        },
        {
            "Bluetooth Audio API",
            "android.hardware.bluetooth.audio@2.0::IBluetoothAudioProvidersFactory"
        },
        // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported
        {
            "Bluetooth Audio Offload API",
            "android.hardware.bluetooth.a2dp@1.0::IBluetoothAudioOffload"
        }
    };
    // clang-format on
    // clang-format on


    ALOGW_IF((registerPassthroughServiceImplementations<soundtrigger::V2_2::ISoundTriggerHw,
    for (const auto& listIter : mandatoryInterfaces) {
                                                        soundtrigger::V2_1::ISoundTriggerHw,
        auto iter = listIter.begin();
                                                        soundtrigger::V2_0::ISoundTriggerHw>()),
        const std::string& interfaceFamilyName = *iter++;
             "Could not register soundtrigger API");
        LOG_ALWAYS_FATAL_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),

                            "Could not register %s", interfaceFamilyName.c_str());
    ALOGW_IF(registerPassthroughServiceImplementations<
    }
                     bluetooth::audio::V2_0::IBluetoothAudioProvidersFactory>(),
             "Could not register Bluetooth audio API");


    // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported
    for (const auto& listIter : optionalInterfaces) {
    ALOGW_IF(registerPassthroughServiceImplementations<
        auto iter = listIter.begin();
                     bluetooth::a2dp::V1_0::IBluetoothAudioOffload>(),
        const std::string& interfaceFamilyName = *iter++;
             "Could not register Bluetooth audio offload API");
        ALOGW_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
                 "Could not register %s", interfaceFamilyName.c_str());
    }


    joinRpcThreadpool();
    joinRpcThreadpool();
}
}