Loading media/libaudiohal/impl/ConversionHelperAidl.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,10 @@ status_t parseAndGetVendorParameters( using ParameterScope = IHalAdapterVendorExtension::ParameterScope; if (parameterKeys.size() == 0) return OK; const String8 rawKeys = parameterKeys.keysToString(); if (vendorExt == nullptr) { ALOGW("%s: unknown parameters, ignored: \"%s\"", __func__, rawKeys.c_str()); return OK; } std::vector<std::string> parameterIds; RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(vendorExt->parseVendorParameterIds( Loading Loading @@ -81,6 +85,10 @@ status_t parseAndSetVendorParameters( using ParameterScope = IHalAdapterVendorExtension::ParameterScope; if (parameters.size() == 0) return OK; const String8 rawKeysAndValues = parameters.toString(); if (vendorExt == nullptr) { ALOGW("%s: unknown parameters, ignored: \"%s\"", __func__, rawKeysAndValues.c_str()); return OK; } std::vector<VendorParameter> syncParameters, asyncParameters; RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(vendorExt->parseVendorParameters( Loading media/libaudiohal/impl/DeviceHalAidl.cpp +9 −5 Original line number Diff line number Diff line Loading @@ -1024,11 +1024,15 @@ status_t DeviceHalAidl::filterAndUpdateBtA2dpParameters(AudioParameter ¶mete (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( parameters, String8(AudioParameter::keyReconfigA2dp), [&](const String8& value) -> status_t { if (mVendorExt != nullptr) { std::vector<VendorParameter> result; RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( mVendorExt->parseBluetoothA2dpReconfigureOffload( std::string(value.c_str()), &result))); reconfigureOffload = std::move(result); } else { reconfigureOffload = std::vector<VendorParameter>(); } return OK; })); if (mBluetoothA2dp != nullptr && a2dpEnabled.has_value()) { Loading media/libaudiohal/impl/DevicesFactoryHalAidl.cpp +16 −80 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ //#define LOG_NDEBUG 0 #include <aidl/android/hardware/audio/core/IModule.h> #include <aidl/android/media/audio/BnHalAdapterVendorExtension.h> #include <android/binder_manager.h> #include <media/AidlConversionNdkCpp.h> #include <media/AidlConversionUtil.h> Loading @@ -36,7 +35,6 @@ using aidl::android::aidl_utils::statusTFromBinderStatus; using aidl::android::hardware::audio::core::IConfig; using aidl::android::hardware::audio::core::IModule; using aidl::android::hardware::audio::core::SurroundSoundConfig; using aidl::android::hardware::audio::core::VendorParameter; using aidl::android::media::audio::common::AudioHalEngineConfig; using aidl::android::media::audio::IHalAdapterVendorExtension; using android::detail::AudioHalVersionInfo; Loading Loading @@ -64,86 +62,10 @@ ndk2cpp_SurroundSoundConfig(const SurroundSoundConfig& ndk) { return cpp; } class HalAdapterVendorExtensionWrapper : public ::aidl::android::media::audio::BnHalAdapterVendorExtension { private: ndk::ScopedAStatus parseVendorParameterIds(ParameterScope in_scope, const std::string& in_rawKeys, std::vector<std::string>* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->parseVendorParameterIds(in_scope, in_rawKeys, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus parseVendorParameters( ParameterScope in_scope, const std::string& in_rawKeysAndValues, std::vector<VendorParameter>* out_syncParameters, std::vector<VendorParameter>* out_asyncParameters) override { ndk::ScopedAStatus status; while (true) { status = get()->parseVendorParameters(in_scope, in_rawKeysAndValues, out_syncParameters, out_asyncParameters); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus parseBluetoothA2dpReconfigureOffload( const std::string& in_rawValue, std::vector<VendorParameter>* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->parseBluetoothA2dpReconfigureOffload(in_rawValue, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus parseBluetoothLeReconfigureOffload(const std::string& in_rawValue, std::vector<VendorParameter>* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->parseBluetoothLeReconfigureOffload(in_rawValue, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus processVendorParameters(ParameterScope in_scope, const std::vector<VendorParameter>& in_parameters, std::string* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->processVendorParameters(in_scope, in_parameters, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } std::shared_ptr<IHalAdapterVendorExtension> get() { if (!mVendorExt) { auto serviceName = std::string(IHalAdapterVendorExtension::descriptor) + "/default"; mVendorExt = IHalAdapterVendorExtension::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(serviceName.c_str()))); } return mVendorExt; } std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt; }; } // namespace DevicesFactoryHalAidl::DevicesFactoryHalAidl(std::shared_ptr<IConfig> config) : mConfig(std::move(config)), mVendorExt(ndk::SharedRefBase::make<HalAdapterVendorExtensionWrapper>()) { : mConfig(std::move(config)) { } status_t DevicesFactoryHalAidl::getDeviceNames(std::vector<std::string> *names) { Loading Loading @@ -188,7 +110,7 @@ status_t DevicesFactoryHalAidl::openDevice(const char *name, sp<DeviceHalInterfa ALOGE("%s fromBinder %s failed", __func__, serviceName.c_str()); return NO_INIT; } *device = sp<DeviceHalAidl>::make(name, service, mVendorExt); *device = sp<DeviceHalAidl>::make(name, service, getVendorExtension()); return OK; } Loading Loading @@ -227,6 +149,20 @@ status_t DevicesFactoryHalAidl::getEngineConfig( return OK; } std::shared_ptr<IHalAdapterVendorExtension> DevicesFactoryHalAidl::getVendorExtension() { if (!mVendorExt.has_value()) { auto serviceName = std::string(IHalAdapterVendorExtension::descriptor) + "/default"; if (AServiceManager_isDeclared(serviceName.c_str())) { mVendorExt = std::shared_ptr<IHalAdapterVendorExtension>( IHalAdapterVendorExtension::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(serviceName.c_str())))); } else { mVendorExt = nullptr; } } return mVendorExt.value(); } // Main entry-point to the shared library. extern "C" __attribute__((visibility("default"))) void* createIDevicesFactoryImpl() { auto serviceName = std::string(IConfig::descriptor) + "/default"; Loading media/libaudiohal/impl/DevicesFactoryHalAidl.h +4 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,10 @@ class DevicesFactoryHalAidl : public DevicesFactoryHalInterface private: const std::shared_ptr<::aidl::android::hardware::audio::core::IConfig> mConfig; const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt; std::optional<std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension>> mVendorExt; std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> getVendorExtension(); ~DevicesFactoryHalAidl() = default; }; Loading media/libaudiohal/tests/CoreAudioHalAidl_test.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -443,6 +443,21 @@ TEST_F(DeviceHalAidlTest, ScreenRotation) { EXPECT_EQ(ScreenRotation::DEG_0, mModule->getScreenRotation()); } // Without a vendor extension, any unrecognized parameters must be ignored. TEST_F(DeviceHalAidlTest, VendorParameterIgnored) { EXPECT_EQ(0UL, mModule->getAsyncParameters().size()); EXPECT_EQ(0UL, mModule->getSyncParameters().size()); EXPECT_EQ(OK, mDevice->setParameters(createParameterString("random_name", "random_value"))); EXPECT_EQ(0UL, mModule->getAsyncParameters().size()); EXPECT_EQ(0UL, mModule->getSyncParameters().size()); EXPECT_EQ(0UL, mModule->getRetrievedParameterIds().size()); String8 values; EXPECT_EQ(OK, mDevice->getParameters(String8("random_name"), &values)); EXPECT_EQ(0UL, mModule->getRetrievedParameterIds().size()); EXPECT_EQ(0UL, values.length()); } class DeviceHalAidlVendorParametersTest : public testing::Test { public: void SetUp() override { Loading Loading
media/libaudiohal/impl/ConversionHelperAidl.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,10 @@ status_t parseAndGetVendorParameters( using ParameterScope = IHalAdapterVendorExtension::ParameterScope; if (parameterKeys.size() == 0) return OK; const String8 rawKeys = parameterKeys.keysToString(); if (vendorExt == nullptr) { ALOGW("%s: unknown parameters, ignored: \"%s\"", __func__, rawKeys.c_str()); return OK; } std::vector<std::string> parameterIds; RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(vendorExt->parseVendorParameterIds( Loading Loading @@ -81,6 +85,10 @@ status_t parseAndSetVendorParameters( using ParameterScope = IHalAdapterVendorExtension::ParameterScope; if (parameters.size() == 0) return OK; const String8 rawKeysAndValues = parameters.toString(); if (vendorExt == nullptr) { ALOGW("%s: unknown parameters, ignored: \"%s\"", __func__, rawKeysAndValues.c_str()); return OK; } std::vector<VendorParameter> syncParameters, asyncParameters; RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(vendorExt->parseVendorParameters( Loading
media/libaudiohal/impl/DeviceHalAidl.cpp +9 −5 Original line number Diff line number Diff line Loading @@ -1024,11 +1024,15 @@ status_t DeviceHalAidl::filterAndUpdateBtA2dpParameters(AudioParameter ¶mete (void)VALUE_OR_RETURN_STATUS(filterOutAndProcessParameter<String8>( parameters, String8(AudioParameter::keyReconfigA2dp), [&](const String8& value) -> status_t { if (mVendorExt != nullptr) { std::vector<VendorParameter> result; RETURN_STATUS_IF_ERROR(statusTFromBinderStatus( mVendorExt->parseBluetoothA2dpReconfigureOffload( std::string(value.c_str()), &result))); reconfigureOffload = std::move(result); } else { reconfigureOffload = std::vector<VendorParameter>(); } return OK; })); if (mBluetoothA2dp != nullptr && a2dpEnabled.has_value()) { Loading
media/libaudiohal/impl/DevicesFactoryHalAidl.cpp +16 −80 Original line number Diff line number Diff line Loading @@ -23,7 +23,6 @@ //#define LOG_NDEBUG 0 #include <aidl/android/hardware/audio/core/IModule.h> #include <aidl/android/media/audio/BnHalAdapterVendorExtension.h> #include <android/binder_manager.h> #include <media/AidlConversionNdkCpp.h> #include <media/AidlConversionUtil.h> Loading @@ -36,7 +35,6 @@ using aidl::android::aidl_utils::statusTFromBinderStatus; using aidl::android::hardware::audio::core::IConfig; using aidl::android::hardware::audio::core::IModule; using aidl::android::hardware::audio::core::SurroundSoundConfig; using aidl::android::hardware::audio::core::VendorParameter; using aidl::android::media::audio::common::AudioHalEngineConfig; using aidl::android::media::audio::IHalAdapterVendorExtension; using android::detail::AudioHalVersionInfo; Loading Loading @@ -64,86 +62,10 @@ ndk2cpp_SurroundSoundConfig(const SurroundSoundConfig& ndk) { return cpp; } class HalAdapterVendorExtensionWrapper : public ::aidl::android::media::audio::BnHalAdapterVendorExtension { private: ndk::ScopedAStatus parseVendorParameterIds(ParameterScope in_scope, const std::string& in_rawKeys, std::vector<std::string>* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->parseVendorParameterIds(in_scope, in_rawKeys, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus parseVendorParameters( ParameterScope in_scope, const std::string& in_rawKeysAndValues, std::vector<VendorParameter>* out_syncParameters, std::vector<VendorParameter>* out_asyncParameters) override { ndk::ScopedAStatus status; while (true) { status = get()->parseVendorParameters(in_scope, in_rawKeysAndValues, out_syncParameters, out_asyncParameters); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus parseBluetoothA2dpReconfigureOffload( const std::string& in_rawValue, std::vector<VendorParameter>* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->parseBluetoothA2dpReconfigureOffload(in_rawValue, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus parseBluetoothLeReconfigureOffload(const std::string& in_rawValue, std::vector<VendorParameter>* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->parseBluetoothLeReconfigureOffload(in_rawValue, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } ndk::ScopedAStatus processVendorParameters(ParameterScope in_scope, const std::vector<VendorParameter>& in_parameters, std::string* _aidl_return) override { ndk::ScopedAStatus status; while (true) { status = get()->processVendorParameters(in_scope, in_parameters, _aidl_return); if (status.getStatus() != STATUS_DEAD_OBJECT) break; mVendorExt.reset(); } return status; } std::shared_ptr<IHalAdapterVendorExtension> get() { if (!mVendorExt) { auto serviceName = std::string(IHalAdapterVendorExtension::descriptor) + "/default"; mVendorExt = IHalAdapterVendorExtension::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(serviceName.c_str()))); } return mVendorExt; } std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt; }; } // namespace DevicesFactoryHalAidl::DevicesFactoryHalAidl(std::shared_ptr<IConfig> config) : mConfig(std::move(config)), mVendorExt(ndk::SharedRefBase::make<HalAdapterVendorExtensionWrapper>()) { : mConfig(std::move(config)) { } status_t DevicesFactoryHalAidl::getDeviceNames(std::vector<std::string> *names) { Loading Loading @@ -188,7 +110,7 @@ status_t DevicesFactoryHalAidl::openDevice(const char *name, sp<DeviceHalInterfa ALOGE("%s fromBinder %s failed", __func__, serviceName.c_str()); return NO_INIT; } *device = sp<DeviceHalAidl>::make(name, service, mVendorExt); *device = sp<DeviceHalAidl>::make(name, service, getVendorExtension()); return OK; } Loading Loading @@ -227,6 +149,20 @@ status_t DevicesFactoryHalAidl::getEngineConfig( return OK; } std::shared_ptr<IHalAdapterVendorExtension> DevicesFactoryHalAidl::getVendorExtension() { if (!mVendorExt.has_value()) { auto serviceName = std::string(IHalAdapterVendorExtension::descriptor) + "/default"; if (AServiceManager_isDeclared(serviceName.c_str())) { mVendorExt = std::shared_ptr<IHalAdapterVendorExtension>( IHalAdapterVendorExtension::fromBinder(ndk::SpAIBinder( AServiceManager_waitForService(serviceName.c_str())))); } else { mVendorExt = nullptr; } } return mVendorExt.value(); } // Main entry-point to the shared library. extern "C" __attribute__((visibility("default"))) void* createIDevicesFactoryImpl() { auto serviceName = std::string(IConfig::descriptor) + "/default"; Loading
media/libaudiohal/impl/DevicesFactoryHalAidl.h +4 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,10 @@ class DevicesFactoryHalAidl : public DevicesFactoryHalInterface private: const std::shared_ptr<::aidl::android::hardware::audio::core::IConfig> mConfig; const std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> mVendorExt; std::optional<std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension>> mVendorExt; std::shared_ptr<::aidl::android::media::audio::IHalAdapterVendorExtension> getVendorExtension(); ~DevicesFactoryHalAidl() = default; }; Loading
media/libaudiohal/tests/CoreAudioHalAidl_test.cpp +15 −0 Original line number Diff line number Diff line Loading @@ -443,6 +443,21 @@ TEST_F(DeviceHalAidlTest, ScreenRotation) { EXPECT_EQ(ScreenRotation::DEG_0, mModule->getScreenRotation()); } // Without a vendor extension, any unrecognized parameters must be ignored. TEST_F(DeviceHalAidlTest, VendorParameterIgnored) { EXPECT_EQ(0UL, mModule->getAsyncParameters().size()); EXPECT_EQ(0UL, mModule->getSyncParameters().size()); EXPECT_EQ(OK, mDevice->setParameters(createParameterString("random_name", "random_value"))); EXPECT_EQ(0UL, mModule->getAsyncParameters().size()); EXPECT_EQ(0UL, mModule->getSyncParameters().size()); EXPECT_EQ(0UL, mModule->getRetrievedParameterIds().size()); String8 values; EXPECT_EQ(OK, mDevice->getParameters(String8("random_name"), &values)); EXPECT_EQ(0UL, mModule->getRetrievedParameterIds().size()); EXPECT_EQ(0UL, values.length()); } class DeviceHalAidlVendorParametersTest : public testing::Test { public: void SetUp() override { Loading