blob: 93fb36607e77b93e4380bbb73beee3e93b6f0065 [file] [log] [blame]
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +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
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000017#include <cstdlib>
18#include <ctime>
Mikhail Naganov521fc492023-07-11 17:24:08 -070019#include <sstream>
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000020#include <utility>
Mikhail Naganov521fc492023-07-11 17:24:08 -070021#include <vector>
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000022
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000023#include <android-base/logging.h>
Mikhail Naganov521fc492023-07-11 17:24:08 -070024#include <android-base/properties.h>
Shunkai Yao39bf2c32022-12-06 03:25:59 +000025#include <android/binder_ibinder_platform.h>
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000026#include <android/binder_manager.h>
27#include <android/binder_process.h>
28
Lorena Torres-Huertabc585bd2022-10-23 20:41:35 +000029#include "core-impl/Config.h"
30#include "core-impl/Module.h"
31
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000032using aidl::android::hardware::audio::core::Config;
33using aidl::android::hardware::audio::core::Module;
34
35int main() {
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000036 // Random values are used in the implementation.
37 std::srand(std::time(nullptr));
38
Mikhail Naganov16db9b72022-06-17 21:36:18 +000039 // This is a debug implementation, always enable debug logging.
40 android::base::SetMinimumLogSeverity(::android::base::DEBUG);
Mikhail Naganov1f72fd42023-02-02 15:26:04 -080041 // For more logs, use VERBOSE, however this may hinder performance.
42 // android::base::SetMinimumLogSeverity(::android::base::VERBOSE);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000043 ABinderProcess_setThreadPoolMaxThreadCount(16);
44
Steven Moreland705c39b2023-03-06 14:30:15 +000045 // Guaranteed log for b/210919187 and logd_integration_test
46 LOG(INFO) << "Init for Audio AIDL HAL";
47
Mikhail Naganov16db9b72022-06-17 21:36:18 +000048 // Make the default config service
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000049 auto config = ndk::SharedRefBase::make<Config>();
50 const std::string configName = std::string() + Config::descriptor + "/default";
51 binder_status_t status =
52 AServiceManager_addService(config->asBinder().get(), configName.c_str());
Mikhail Naganov16db9b72022-06-17 21:36:18 +000053 CHECK_EQ(STATUS_OK, status);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000054
Mikhail Naganovc8e43122022-12-09 00:33:47 +000055 // Make modules
Mikhail Naganov521fc492023-07-11 17:24:08 -070056 auto createModule = [](Module::Type type) {
jiabin253bd322023-01-25 23:57:31 +000057 auto module = Module::createInstance(type);
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000058 ndk::SpAIBinder moduleBinder = module->asBinder();
Mikhail Naganov521fc492023-07-11 17:24:08 -070059 std::stringstream moduleName;
60 moduleName << Module::descriptor << "/" << type;
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000061 AIBinder_setMinSchedulerPolicy(moduleBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
Mikhail Naganov521fc492023-07-11 17:24:08 -070062 binder_status_t status =
63 AServiceManager_addService(moduleBinder.get(), moduleName.str().c_str());
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000064 CHECK_EQ(STATUS_OK, status);
65 return std::make_pair(module, moduleBinder);
66 };
Mikhail Naganov521fc492023-07-11 17:24:08 -070067 auto modules = {createModule(Module::Type::DEFAULT), createModule(Module::Type::R_SUBMIX),
68 createModule(Module::Type::USB), createModule(Module::Type::STUB)};
Lorena Torres-Huertaaa8f76a2022-12-12 18:17:10 +000069 (void)modules;
Mikhail Naganovc8e43122022-12-09 00:33:47 +000070
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000071 ABinderProcess_joinThreadPool();
72 return EXIT_FAILURE; // should not reach
73}