/* * 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. */ #pragma once #include #include #include #include #include #include #include #include "AudioHalBinderServiceUtil.h" #include "TestUtils.h" using namespace android; using aidl::android::hardware::audio::effect::Descriptor; using aidl::android::hardware::audio::effect::IFactory; using aidl::android::media::audio::common::AudioUuid; class EffectFactoryHelper { public: static std::vector, Descriptor>> getAllEffectDescriptors( std::string serviceName, std::optional type = std::nullopt) { AudioHalBinderServiceUtil util; auto names = android::getAidlHalInstanceNames(serviceName); std::vector, Descriptor>> result; for (const auto& name : names) { auto factory = IFactory::fromBinder(util.connectToService(name)); if (factory) { if (std::vector descs; factory->queryEffects(std::nullopt, std::nullopt, std::nullopt, &descs) .isOk()) { for (const auto& desc : descs) { if (type.has_value() && desc.common.id.type != type.value()) { continue; } result.emplace_back(factory, desc); } } } } return result; } static int getHalVersion(const std::shared_ptr& factory) { int version = 0; return (factory && factory->getInterfaceVersion(&version).isOk()) ? version : 0; } static bool isReopenSupported(const std::shared_ptr& factory) { return EffectFactoryHelper::getHalVersion(factory) >= aidl::android::hardware::audio::effect::kReopenSupportedVersion; } };