blob: 54b82d3705c2f7f54a3ba25621726e97a1044c0d [file] [log] [blame]
Shunkai Yaoea24c1a2022-09-28 17:39:23 +00001/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <memory>
20#include <string>
21#include <unordered_map>
22#include <vector>
23
Shunkai Yao12836852023-12-13 01:07:52 +000024#include <aidl/Vintf.h>
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000025#include <android/binder_auto_utils.h>
Shunkai Yao9f9fe922024-03-04 21:23:04 +000026#include <system/audio_effects/aidl_effects_utils.h>
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000027
Bart Van Assche5e7fcb42023-11-08 07:00:22 -080028#include "AudioHalBinderServiceUtil.h"
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000029#include "TestUtils.h"
30
31using namespace android;
32
33using aidl::android::hardware::audio::effect::Descriptor;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000034using aidl::android::hardware::audio::effect::IFactory;
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000035using aidl::android::media::audio::common::AudioUuid;
36
37class EffectFactoryHelper {
38 public:
Shunkai Yaocb0fc412022-12-15 20:34:32 +000039 static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> getAllEffectDescriptors(
40 std::string serviceName, std::optional<AudioUuid> type = std::nullopt) {
Shunkai Yao812d5b42022-11-16 18:08:50 +000041 AudioHalBinderServiceUtil util;
42 auto names = android::getAidlHalInstanceNames(serviceName);
Shunkai Yaocb0fc412022-12-15 20:34:32 +000043 std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> result;
Shunkai Yao08b687d2022-10-13 21:11:11 +000044
Shunkai Yao812d5b42022-11-16 18:08:50 +000045 for (const auto& name : names) {
46 auto factory = IFactory::fromBinder(util.connectToService(name));
47 if (factory) {
Shunkai Yaoc12e0822022-12-12 07:13:58 +000048 if (std::vector<Descriptor> descs;
49 factory->queryEffects(std::nullopt, std::nullopt, std::nullopt, &descs)
50 .isOk()) {
51 for (const auto& desc : descs) {
Shunkai Yaocb0fc412022-12-15 20:34:32 +000052 if (type.has_value() && desc.common.id.type != type.value()) {
Shunkai Yao812d5b42022-11-16 18:08:50 +000053 continue;
54 }
Shunkai Yaocb0fc412022-12-15 20:34:32 +000055 result.emplace_back(factory, desc);
Shunkai Yao812d5b42022-11-16 18:08:50 +000056 }
57 }
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000058 }
59 }
Shunkai Yao812d5b42022-11-16 18:08:50 +000060 return result;
Shunkai Yaoa4ab38c2022-10-14 01:07:47 +000061 }
62
Shunkai Yao9f9fe922024-03-04 21:23:04 +000063 static int getHalVersion(const std::shared_ptr<IFactory>& factory) {
64 int version = 0;
65 return (factory && factory->getInterfaceVersion(&version).isOk()) ? version : 0;
66 }
67
68 static bool isReopenSupported(const std::shared_ptr<IFactory>& factory) {
69 return EffectFactoryHelper::getHalVersion(factory) >=
70 aidl::android::hardware::audio::effect::kReopenSupportedVersion;
71 }
Shunkai Yaoea24c1a2022-09-28 17:39:23 +000072};