From 4f1e4824dc1b6e05df6dbcaafa1345e498cff61e Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Wed, 24 Aug 2022 20:33:33 -0400 Subject: [PATCH] gsi: sysbta: Separate audio interfaces from bluetooth This will allow us to dynamically load multiple different versions of audio interface implementation into the same sysbta hal process. Note that since we are using a weird suffix here, the default `registerPassthroughServiceImplementation` will not work, and we will have to define our own dynamic symbol for it. --- audio/hal/Android.bp | 56 ++++++++++++++++ {bluetooth/audio => audio}/hal/Device.cpp | 0 {bluetooth/audio => audio}/hal/Device.h | 0 .../audio => audio}/hal/DevicesFactory.cpp | 2 +- .../audio => audio}/hal/DevicesFactory.h | 0 .../audio => audio}/hal/ParametersUtil.cpp | 0 .../audio => audio}/hal/ParametersUtil.h | 0 .../audio => audio}/hal/PrimaryDevice.cpp | 0 .../audio => audio}/hal/PrimaryDevice.h | 0 {bluetooth/audio => audio}/hal/Stream.cpp | 0 {bluetooth/audio => audio}/hal/Stream.h | 0 {bluetooth/audio => audio}/hal/StreamIn.cpp | 0 {bluetooth/audio => audio}/hal/StreamIn.h | 0 {bluetooth/audio => audio}/hal/StreamOut.cpp | 0 {bluetooth/audio => audio}/hal/StreamOut.h | 0 {bluetooth/audio => audio}/hal/Util.h | 0 audio/hal/service.cpp | 15 +++++ bluetooth/audio/hal/Android.bp | 67 ++----------------- bluetooth/audio/hal/bluetooth_audio.xml | 7 -- bluetooth/audio/hal/service.cpp | 38 ----------- bluetooth/audio/hal/service_system.cpp | 54 ++++++++++++--- 21 files changed, 122 insertions(+), 117 deletions(-) create mode 100644 audio/hal/Android.bp rename {bluetooth/audio => audio}/hal/Device.cpp (100%) rename {bluetooth/audio => audio}/hal/Device.h (100%) rename {bluetooth/audio => audio}/hal/DevicesFactory.cpp (98%) rename {bluetooth/audio => audio}/hal/DevicesFactory.h (100%) rename {bluetooth/audio => audio}/hal/ParametersUtil.cpp (100%) rename {bluetooth/audio => audio}/hal/ParametersUtil.h (100%) rename {bluetooth/audio => audio}/hal/PrimaryDevice.cpp (100%) rename {bluetooth/audio => audio}/hal/PrimaryDevice.h (100%) rename {bluetooth/audio => audio}/hal/Stream.cpp (100%) rename {bluetooth/audio => audio}/hal/Stream.h (100%) rename {bluetooth/audio => audio}/hal/StreamIn.cpp (100%) rename {bluetooth/audio => audio}/hal/StreamIn.h (100%) rename {bluetooth/audio => audio}/hal/StreamOut.cpp (100%) rename {bluetooth/audio => audio}/hal/StreamOut.h (100%) rename {bluetooth/audio => audio}/hal/Util.h (100%) create mode 100644 audio/hal/service.cpp delete mode 100644 bluetooth/audio/hal/bluetooth_audio.xml delete mode 100644 bluetooth/audio/hal/service.cpp diff --git a/audio/hal/Android.bp b/audio/hal/Android.bp new file mode 100644 index 0000000..dbf6ac7 --- /dev/null +++ b/audio/hal/Android.bp @@ -0,0 +1,56 @@ +cc_defaults { + name: "android.hardware.audio-impl-system_default", + relative_install_path: "hw", + srcs: [ + "Device.cpp", + "DevicesFactory.cpp", + "ParametersUtil.cpp", + "PrimaryDevice.cpp", + "Stream.cpp", + "StreamIn.cpp", + "StreamOut.cpp", + "service.cpp", + ], + shared_libs: [ + "libbase", + "libcutils", + "libfmq", + "libhardware", + "libhidlbase", + "liblog", + "libmedia_helper", + "libmediautils_vendor", + "libmemunreachable", + "libutils", + "android.hardware.audio.common-util", + ], + static_libs: [ + "libaudiofoundation", + ], + header_libs: [ + "android.hardware.audio.common.util@all-versions", + "libaudioutils_headers", + "libaudio_system_headers", + "libmedia_headers", + "libmediautils_headers", + "libhardware_headers", + ] +} + +cc_library_shared { + name: "android.hardware.audio@6.0-impl-system", + defaults: ["android.hardware.audio-impl-system_default"], + shared_libs: [ + "android.hardware.audio@6.0", + "android.hardware.audio@6.0-util", + "android.hardware.audio.common@6.0", + "android.hardware.audio.common@6.0-util", + ], + cflags: [ + "-DMAJOR_VERSION=6", + "-DMINOR_VERSION=0", + "-DCOMMON_TYPES_MINOR_VERSION=0", + "-DCORE_TYPES_MINOR_VERSION=0", + "-include common/all-versions/VersionMacro.h", + ], +} diff --git a/bluetooth/audio/hal/Device.cpp b/audio/hal/Device.cpp similarity index 100% rename from bluetooth/audio/hal/Device.cpp rename to audio/hal/Device.cpp diff --git a/bluetooth/audio/hal/Device.h b/audio/hal/Device.h similarity index 100% rename from bluetooth/audio/hal/Device.h rename to audio/hal/Device.h diff --git a/bluetooth/audio/hal/DevicesFactory.cpp b/audio/hal/DevicesFactory.cpp similarity index 98% rename from bluetooth/audio/hal/DevicesFactory.cpp rename to audio/hal/DevicesFactory.cpp index cc42293..d5a4ea0 100644 --- a/bluetooth/audio/hal/DevicesFactory.cpp +++ b/audio/hal/DevicesFactory.cpp @@ -142,7 +142,7 @@ out: } IDevicesFactory* HIDL_FETCH_IDevicesFactory(const char* name) { - return strcmp(name, "default") == 0 ? new DevicesFactory() : nullptr; + return new DevicesFactory(); } } // namespace implementation diff --git a/bluetooth/audio/hal/DevicesFactory.h b/audio/hal/DevicesFactory.h similarity index 100% rename from bluetooth/audio/hal/DevicesFactory.h rename to audio/hal/DevicesFactory.h diff --git a/bluetooth/audio/hal/ParametersUtil.cpp b/audio/hal/ParametersUtil.cpp similarity index 100% rename from bluetooth/audio/hal/ParametersUtil.cpp rename to audio/hal/ParametersUtil.cpp diff --git a/bluetooth/audio/hal/ParametersUtil.h b/audio/hal/ParametersUtil.h similarity index 100% rename from bluetooth/audio/hal/ParametersUtil.h rename to audio/hal/ParametersUtil.h diff --git a/bluetooth/audio/hal/PrimaryDevice.cpp b/audio/hal/PrimaryDevice.cpp similarity index 100% rename from bluetooth/audio/hal/PrimaryDevice.cpp rename to audio/hal/PrimaryDevice.cpp diff --git a/bluetooth/audio/hal/PrimaryDevice.h b/audio/hal/PrimaryDevice.h similarity index 100% rename from bluetooth/audio/hal/PrimaryDevice.h rename to audio/hal/PrimaryDevice.h diff --git a/bluetooth/audio/hal/Stream.cpp b/audio/hal/Stream.cpp similarity index 100% rename from bluetooth/audio/hal/Stream.cpp rename to audio/hal/Stream.cpp diff --git a/bluetooth/audio/hal/Stream.h b/audio/hal/Stream.h similarity index 100% rename from bluetooth/audio/hal/Stream.h rename to audio/hal/Stream.h diff --git a/bluetooth/audio/hal/StreamIn.cpp b/audio/hal/StreamIn.cpp similarity index 100% rename from bluetooth/audio/hal/StreamIn.cpp rename to audio/hal/StreamIn.cpp diff --git a/bluetooth/audio/hal/StreamIn.h b/audio/hal/StreamIn.h similarity index 100% rename from bluetooth/audio/hal/StreamIn.h rename to audio/hal/StreamIn.h diff --git a/bluetooth/audio/hal/StreamOut.cpp b/audio/hal/StreamOut.cpp similarity index 100% rename from bluetooth/audio/hal/StreamOut.cpp rename to audio/hal/StreamOut.cpp diff --git a/bluetooth/audio/hal/StreamOut.h b/audio/hal/StreamOut.h similarity index 100% rename from bluetooth/audio/hal/StreamOut.h rename to audio/hal/StreamOut.h diff --git a/bluetooth/audio/hal/Util.h b/audio/hal/Util.h similarity index 100% rename from bluetooth/audio/hal/Util.h rename to audio/hal/Util.h diff --git a/audio/hal/service.cpp b/audio/hal/service.cpp new file mode 100644 index 0000000..0e65b05 --- /dev/null +++ b/audio/hal/service.cpp @@ -0,0 +1,15 @@ +#include "DevicesFactory.h" +#include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) + +#include + +using ::android::status_t; +using ::android::hardware::audio::CPP_VERSION::implementation::DevicesFactory; +using namespace ::android::hardware::audio::CPP_VERSION; + +extern "C" __attribute__((visibility("default"))) +status_t createIDevicesFactory(const char *instance_name) { + ::android::sp audio_factory = new DevicesFactory(); + ::android::status_t hidl_status = audio_factory->registerAsService(instance_name); + return hidl_status; +} diff --git a/bluetooth/audio/hal/Android.bp b/bluetooth/audio/hal/Android.bp index e52a6b7..72848a3 100644 --- a/bluetooth/audio/hal/Android.bp +++ b/bluetooth/audio/hal/Android.bp @@ -1,29 +1,3 @@ -cc_library_shared { - name: "android.hardware.bluetooth.audio-system-impl", - vintf_fragments: ["bluetooth_audio.xml"], - srcs: [ - "BluetoothAudioProvider.cpp", - "BluetoothAudioProviderFactory.cpp", - "A2dpOffloadAudioProvider.cpp", - "A2dpSoftwareAudioProvider.cpp", - "HearingAidAudioProvider.cpp", - "LeAudioOffloadAudioProvider.cpp", - "LeAudioSoftwareAudioProvider.cpp", - "service.cpp", - ], - export_include_dirs: ["."], - header_libs: ["libhardware_headers"], - shared_libs: [ - "libbase", - "libbinder_ndk", - "libcutils", - "libfmq", - "liblog", - "android.hardware.bluetooth.audio-V2-ndk", - "libbluetooth_audio_session_aidl_system", - ], -} - cc_binary { name: "android.hardware.bluetooth.audio-service-system", vintf_fragments: ["bluetooth_audio_system.xml"], @@ -37,22 +11,10 @@ cc_binary { "HearingAidAudioProvider.cpp", "LeAudioOffloadAudioProvider.cpp", "LeAudioSoftwareAudioProvider.cpp", - "Device.cpp", - "DevicesFactory.cpp", - "ParametersUtil.cpp", - "PrimaryDevice.cpp", - "Stream.cpp", - "StreamIn.cpp", - "StreamOut.cpp", "service_system.cpp", ], header_libs: [ "libhardware_headers", - "android.hardware.audio.common.util@all-versions", - "libaudioutils_headers", - "libaudio_system_headers", - "libmedia_headers", - "libmediautils_headers", ], shared_libs: [ "libbase", @@ -60,33 +22,14 @@ cc_binary { "libbinder_ndk", "libcutils", "libfmq", - "liblog", - "android.hardware.bluetooth.audio-V2-ndk", - "libbluetooth_audio_session_aidl_system", - "libfmq", - "libhardware", "libhidlbase", "liblog", - "libmedia_helper", - "libmediautils_vendor", - "libmemunreachable", "libutils", - "android.hardware.audio.common-util", - "android.hardware.audio@6.0", -// "android.hardware.audio@7.1", - "android.hardware.audio@6.0-util", - "android.hardware.audio.common@6.0", -// "android.hardware.audio.common@6.0-enums", - "android.hardware.audio.common@6.0-util", + "android.hardware.bluetooth.audio-V2-ndk", + "libbluetooth_audio_session_aidl_system", ], - static_libs: [ - "libaudiofoundation", - ], - cflags: [ - "-DMAJOR_VERSION=6", - "-DMINOR_VERSION=0", - "-DCOMMON_TYPES_MINOR_VERSION=0", - "-DCORE_TYPES_MINOR_VERSION=0", - "-include common/all-versions/VersionMacro.h", + required: [ + // Audio HAL impls + "android.hardware.audio@6.0-impl-system", ], } diff --git a/bluetooth/audio/hal/bluetooth_audio.xml b/bluetooth/audio/hal/bluetooth_audio.xml deleted file mode 100644 index c4b1872..0000000 --- a/bluetooth/audio/hal/bluetooth_audio.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - android.hardware.bluetooth.audio - 2 - IBluetoothAudioProviderFactory/default - - diff --git a/bluetooth/audio/hal/service.cpp b/bluetooth/audio/hal/service.cpp deleted file mode 100644 index f8f9cde..0000000 --- a/bluetooth/audio/hal/service.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "BtAudioAIDLService" - -#include -#include -#include - -#include "BluetoothAudioProviderFactory.h" - -using ::aidl::android::hardware::bluetooth::audio:: - BluetoothAudioProviderFactory; - -extern "C" __attribute__((visibility("default"))) binder_status_t -createIBluetoothAudioProviderFactory() { - auto factory = ::ndk::SharedRefBase::make(); - const std::string instance_name = - std::string() + BluetoothAudioProviderFactory::descriptor + "/default"; - binder_status_t aidl_status = AServiceManager_addService( - factory->asBinder().get(), instance_name.c_str()); - ALOGW_IF(aidl_status != STATUS_OK, "Could not register %s, status=%d", - instance_name.c_str(), aidl_status); - return aidl_status; -} \ No newline at end of file diff --git a/bluetooth/audio/hal/service_system.cpp b/bluetooth/audio/hal/service_system.cpp index 5b5ce11..11fce96 100644 --- a/bluetooth/audio/hal/service_system.cpp +++ b/bluetooth/audio/hal/service_system.cpp @@ -16,29 +16,61 @@ #define LOG_TAG "BtAudioAIDLServiceSystem" +#include #include #include #include #include #include -#include +//#include #include #include -#include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) +//#include PATH(android/hardware/audio/FILE_VERSION/IDevicesFactory.h) -#include +//#include #include "BluetoothAudioProviderFactory.h" -#include "DevicesFactory.h" +//#include "DevicesFactory.h" //using namespace android::hardware; using ::aidl::android::hardware::bluetooth::audio:: BluetoothAudioProviderFactory; -using ::android::hardware::audio::CPP_VERSION::implementation::DevicesFactory; -using namespace ::android::hardware::audio::CPP_VERSION; +//using ::android::hardware::audio::CPP_VERSION::implementation::DevicesFactory; +//using namespace ::android::hardware::audio::CPP_VERSION; + +#if defined(__LP64__) +#define HAL_LIBRARY_PATH "/system/lib64/hw" +#else +#define HAL_LIBRARY_PATH "/system/lib/hw" +#endif + +void registerAudioInterfaces() { + const char *interface_libs[] = { + "android.hardware.audio@6.0-impl-system.so", + }; + + for (auto& lib : interface_libs) { + void* handle = dlopen((std::string() + HAL_LIBRARY_PATH + "/" + lib).c_str(), RTLD_NOW); + if (handle == nullptr) { + ALOGW("Failed to load %s, skipping", lib); + continue; + } + + ::android::status_t (*entry_func)(const char*); + entry_func = reinterpret_cast<::android::status_t (*)(const char*)>(dlsym(handle, "createIDevicesFactory")); + + if (entry_func == nullptr) { + ALOGW("Cannot find entry symbol in %s, skipping", lib); + continue; + } + + ::android::status_t status = entry_func("sysbta"); + ALOGW_IF(status != STATUS_OK, "Could not register sysbta for %s, status=%d", lib, status); + } +} int main() { signal(SIGPIPE, SIG_IGN); @@ -57,9 +89,13 @@ int main() { ALOGW_IF(aidl_status != STATUS_OK, "Could not register %s, status=%d", instance_name.c_str(), aidl_status); - ::android::sp audio_factory = new DevicesFactory(); - ::android::status_t hidl_status = audio_factory->registerAsService("sysbta"); - ALOGW_IF(hidl_status != STATUS_OK, "Could not register sysbta, status=%d", hidl_status); + //::android::sp audio_factory = new DevicesFactory(); + //::android::status_t hidl_status = audio_factory->registerAsService("sysbta"); + //ALOGW_IF(hidl_status != STATUS_OK, "Could not register sysbta, status=%d", hidl_status); + + // We must also implement audio HAL interfaces in order to serve audio.sysbta.default.so + // It must be served in the *same* process to access the same libbluetooth_audio_session + registerAudioInterfaces(); ::android::hardware::joinRpcThreadpool(); }