audio: Remove dynamic dependency on HIDL interface libs from service

This is intended to reduce memory footprint of the default HAL
service. The inteface libraries were only used to retrieve
interface descriptors and use generated code to register as
service. This code was replaced with static code from
HIDL transport library.

Bug: 148115870
Test: check audio on devices
Change-Id: Ie8713d513cfbde64120546ba0db1cf80fd366138
This commit is contained in:
Mikhail Naganov 2020-01-29 15:32:24 -08:00
parent 740d72685e
commit f3e4d217ee
2 changed files with 60 additions and 60 deletions

View file

@ -24,24 +24,6 @@ cc_binary {
"liblog",
"libutils",
"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",
"android.hardware.soundtrigger@2.3",
],
}

View file

@ -16,20 +16,9 @@
#define LOG_TAG "audiohalservice"
#include <android/hardware/audio/2.0/IDevicesFactory.h>
#include <android/hardware/audio/4.0/IDevicesFactory.h>
#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 <android/hardware/soundtrigger/2.3/ISoundTriggerHw.h>
#include <string>
#include <vector>
#include <binder/ProcessState.h>
#include <cutils/properties.h>
#include <hidl/HidlTransportSupport.h>
@ -39,13 +28,20 @@
using namespace android::hardware;
using android::OK;
using InterfacesList = std::vector<std::string>;
/** 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) && ...);
template <class Iter>
static bool registerPassthroughServiceImplementations(Iter first, Iter last) {
for (; first != last; ++first) {
if (registerPassthroughServiceImplementation(*first) == OK) {
return true;
}
}
return false;
}
int main(int /* argc */, char* /* argv */ []) {
@ -62,36 +58,58 @@ int main(int /* argc */, char* /* argv */ []) {
}
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
LOG_ALWAYS_FATAL_IF((registerPassthroughServiceImplementations<
audio::V6_0::IDevicesFactory,
audio::V5_0::IDevicesFactory,
audio::V4_0::IDevicesFactory,
audio::V2_0::IDevicesFactory>()),
"Could not register audio core API");
const std::vector<InterfacesList> mandatoryInterfaces = {
{
"Audio Core API",
"android.hardware.audio@6.0::IDevicesFactory",
"android.hardware.audio@5.0::IDevicesFactory",
"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<
audio::effect::V6_0::IEffectsFactory,
audio::effect::V5_0::IEffectsFactory,
audio::effect::V4_0::IEffectsFactory,
audio::effect::V2_0::IEffectsFactory>()),
"Could not register audio effect API");
const std::vector<InterfacesList> optionalInterfaces = {
{
"Soundtrigger API",
"android.hardware.soundtrigger@2.3::ISoundTriggerHw",
"android.hardware.soundtrigger@2.2::ISoundTriggerHw",
"android.hardware.soundtrigger@2.1::ISoundTriggerHw",
"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.a2dp@1.0::IBluetoothAudioOffload"
}
};
// clang-format on
ALOGW_IF((registerPassthroughServiceImplementations<
soundtrigger::V2_3::ISoundTriggerHw, soundtrigger::V2_2::ISoundTriggerHw,
soundtrigger::V2_1::ISoundTriggerHw, soundtrigger::V2_0::ISoundTriggerHw>()),
"Could not register soundtrigger API");
for (const auto& listIter : mandatoryInterfaces) {
auto iter = listIter.begin();
const std::string& interfaceFamilyName = *iter++;
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
ALOGW_IF(registerPassthroughServiceImplementations<
bluetooth::a2dp::V1_0::IBluetoothAudioOffload>(),
"Could not register Bluetooth audio offload API");
for (const auto& listIter : optionalInterfaces) {
auto iter = listIter.begin();
const std::string& interfaceFamilyName = *iter++;
ALOGW_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
"Could not register %s", interfaceFamilyName.c_str());
}
joinRpcThreadpool();
}