blob: 48067a2d7f241eca83026883ea44294749ebbc7c [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>
19
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000020#include <android-base/logging.h>
Shunkai Yao39bf2c32022-12-06 03:25:59 +000021#include <android/binder_ibinder_platform.h>
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000022#include <android/binder_manager.h>
23#include <android/binder_process.h>
24
Lorena Torres-Huertabc585bd2022-10-23 20:41:35 +000025#include "core-impl/Config.h"
26#include "core-impl/Module.h"
27
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000028using aidl::android::hardware::audio::core::Config;
29using aidl::android::hardware::audio::core::Module;
30
31int main() {
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000032 // Random values are used in the implementation.
33 std::srand(std::time(nullptr));
34
Mikhail Naganov16db9b72022-06-17 21:36:18 +000035 // This is a debug implementation, always enable debug logging.
36 android::base::SetMinimumLogSeverity(::android::base::DEBUG);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000037 ABinderProcess_setThreadPoolMaxThreadCount(16);
38
Mikhail Naganov16db9b72022-06-17 21:36:18 +000039 // Make the default config service
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000040 auto config = ndk::SharedRefBase::make<Config>();
41 const std::string configName = std::string() + Config::descriptor + "/default";
42 binder_status_t status =
43 AServiceManager_addService(config->asBinder().get(), configName.c_str());
Mikhail Naganov16db9b72022-06-17 21:36:18 +000044 CHECK_EQ(STATUS_OK, status);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000045
Mikhail Naganov16db9b72022-06-17 21:36:18 +000046 // Make the default module
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000047 auto moduleDefault = ndk::SharedRefBase::make<Module>();
Shunkai Yao39bf2c32022-12-06 03:25:59 +000048 AIBinder_setMinSchedulerPolicy(moduleDefault->asBinder().get(), SCHED_NORMAL,
49 ANDROID_PRIORITY_AUDIO);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000050 const std::string moduleDefaultName = std::string() + Module::descriptor + "/default";
51 status = AServiceManager_addService(moduleDefault->asBinder().get(), moduleDefaultName.c_str());
Mikhail Naganov16db9b72022-06-17 21:36:18 +000052 CHECK_EQ(STATUS_OK, status);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000053
54 ABinderProcess_joinThreadPool();
55 return EXIT_FAILURE; // should not reach
56}