1 /*
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 #include <cstdlib>
18 #include <ctime>
19 #include <sstream>
20 #include <utility>
21 #include <vector>
22
23 #include <android-base/logging.h>
24 #include <android-base/properties.h>
25 #include <android/binder_ibinder_platform.h>
26 #include <android/binder_manager.h>
27 #include <android/binder_process.h>
28
29 #include "core-impl/Config.h"
30 #include "core-impl/Module.h"
31
32 using aidl::android::hardware::audio::core::Config;
33 using aidl::android::hardware::audio::core::Module;
34
main()35 int main() {
36 // Random values are used in the implementation.
37 std::srand(std::time(nullptr));
38
39 // This is a debug implementation, always enable debug logging.
40 android::base::SetMinimumLogSeverity(::android::base::DEBUG);
41 // For more logs, use VERBOSE, however this may hinder performance.
42 // android::base::SetMinimumLogSeverity(::android::base::VERBOSE);
43 ABinderProcess_setThreadPoolMaxThreadCount(16);
44
45 // Guaranteed log for b/210919187 and logd_integration_test
46 LOG(INFO) << "Init for Audio AIDL HAL";
47
48 // Make the default config service
49 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());
53 CHECK_EQ(STATUS_OK, status);
54
55 // Make modules
56 auto createModule = [](Module::Type type) {
57 auto module = Module::createInstance(type);
58 ndk::SpAIBinder moduleBinder = module->asBinder();
59 std::stringstream moduleName;
60 moduleName << Module::descriptor << "/" << type;
61 AIBinder_setMinSchedulerPolicy(moduleBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
62 binder_status_t status =
63 AServiceManager_addService(moduleBinder.get(), moduleName.str().c_str());
64 CHECK_EQ(STATUS_OK, status);
65 return std::make_pair(module, moduleBinder);
66 };
67 auto modules = {createModule(Module::Type::DEFAULT), createModule(Module::Type::R_SUBMIX),
68 createModule(Module::Type::USB), createModule(Module::Type::STUB),
69 createModule(Module::Type::BLUETOOTH)};
70 (void)modules;
71
72 ABinderProcess_joinThreadPool();
73 return EXIT_FAILURE; // should not reach
74 }
75