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

Commit 350ce298 authored by Kevin Rocard's avatar Kevin Rocard Committed by Mikhail Naganov
Browse files

Audio service: Refactor register interface



Remove all per interface version boilerplate.
Adding a new version now requires only including the file
and adding the version name to the list.

Bug: 134940862
Test: adb shell lshal
Change-Id: Ib6b99d7a2c2079d914970fbe804aaf3c78c143ce
Merged-In: Ib6b99d7a2c2079d914970fbe804aaf3c78c143ce
Signed-off-by: default avatarKevin Rocard <krocard@google.com>
parent c581b415
Loading
Loading
Loading
Loading
+28 −19
Original line number Diff line number Diff line
@@ -36,6 +36,15 @@
using namespace android::hardware;
using android::OK;

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

int main(int /* argc */, char* /* argv */ []) {
    ::android::ProcessState::initWithDriver("/dev/vndbinder");
    // start a threadpool for vndbinder interactions
@@ -50,30 +59,30 @@ int main(int /* argc */, char* /* argv */ []) {
    }
    configureRpcThreadpool(16, true /*callerWillJoin*/);

    bool fail = registerPassthroughServiceImplementation<audio::V5_0::IDevicesFactory>() != OK &&
                registerPassthroughServiceImplementation<audio::V4_0::IDevicesFactory>() != OK &&
                registerPassthroughServiceImplementation<audio::V2_0::IDevicesFactory>() != OK;
    LOG_ALWAYS_FATAL_IF(fail, "Could not register audio core API 2, 4 nor 5");
    LOG_ALWAYS_FATAL_IF((registerPassthroughServiceImplementations<audio::V5_0::IDevicesFactory,
                                                                   audio::V4_0::IDevicesFactory,
                                                                   audio::V2_0::IDevicesFactory>()),
                        "Could not register audio core API");

    fail = registerPassthroughServiceImplementation<audio::effect::V5_0::IEffectsFactory>() != OK &&
           registerPassthroughServiceImplementation<audio::effect::V4_0::IEffectsFactory>() != OK &&
           registerPassthroughServiceImplementation<audio::effect::V2_0::IEffectsFactory>() != OK,
    LOG_ALWAYS_FATAL_IF(fail, "Could not register audio effect API 2, 4 nor 5");
    LOG_ALWAYS_FATAL_IF(
            (registerPassthroughServiceImplementations<audio::effect::V5_0::IEffectsFactory,
                                                       audio::effect::V4_0::IEffectsFactory,
                                                       audio::effect::V2_0::IEffectsFactory>()),
            "Could not register audio effect API");

    fail = registerPassthroughServiceImplementation<soundtrigger::V2_2::ISoundTriggerHw>() != OK &&
           registerPassthroughServiceImplementation<soundtrigger::V2_1::ISoundTriggerHw>() != OK &&
           registerPassthroughServiceImplementation<soundtrigger::V2_0::ISoundTriggerHw>() != OK,
    ALOGW_IF(fail, "Could not register soundtrigger API 2.0, 2.1 nor 2.2");
    ALOGW_IF((registerPassthroughServiceImplementations<soundtrigger::V2_2::ISoundTriggerHw,
                                                        soundtrigger::V2_1::ISoundTriggerHw,
                                                        soundtrigger::V2_0::ISoundTriggerHw>()),
             "Could not register soundtrigger API");

    fail = registerPassthroughServiceImplementation<
                   bluetooth::audio::V2_0::IBluetoothAudioProvidersFactory>() != OK;
    ALOGW_IF(fail, "Could not register Bluetooth Audio API 2.0");
    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
    fail =
        registerPassthroughServiceImplementation<bluetooth::a2dp::V1_0::IBluetoothAudioOffload>() !=
        OK;
    ALOGW_IF(fail, "Could not register Bluetooth audio offload 1.0");
    ALOGW_IF(registerPassthroughServiceImplementations<
                     bluetooth::a2dp::V1_0::IBluetoothAudioOffload>(),
             "Could not register Bluetooth audio offload API");

    joinRpcThreadpool();
}