1 /*
2 * Copyright (C) 2016 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 #define LOG_TAG "audiohalservice"
18
19 #include "AudioControl.h"
20 #include "PowerPolicyClient.h"
21
22 #include <string>
23 #include <vector>
24
25 #include <log/log.h>
26
27 #include <android-base/logging.h>
28 #include <android/binder_manager.h>
29 #include <android/binder_process.h>
30
31 #include <hidl/HidlTransportSupport.h>
32 #include <hidl/LegacySupport.h>
33
34 #include <android/hardware/audio/6.0/IDevicesFactory.h>
35 #include <android/hardware/audio/effect/6.0/IEffectsFactory.h>
36
37 using namespace android::hardware;
38 using android::OK;
39 using aidl::android::hardware::automotive::audiocontrol::AudioControl;
40 using aidl::android::hardware::automotive::audiocontrol::PowerPolicyClient;
41
42 using android::hardware::configureRpcThreadpool;
43 using android::hardware::joinRpcThreadpool;
44 using android::hardware::registerPassthroughServiceImplementation;
45
46 using android::hardware::audio::effect::V6_0::IEffectsFactory;
47 using android::hardware::audio::V6_0::IDevicesFactory;
48 using android::hardware::registerPassthroughServiceImplementation;
49
main(int,char * [])50 int main(int /* argc */, char* /* argv */ []) {
51 // Setup HIDL Audio HAL
52 configureRpcThreadpool(16, false /*callerWillJoin*/);
53 android::status_t status;
54 status = registerPassthroughServiceImplementation<IDevicesFactory>();
55 LOG_ALWAYS_FATAL_IF(status != OK, "Error while registering audio service: %d", status);
56 status = registerPassthroughServiceImplementation<IEffectsFactory>();
57 LOG_ALWAYS_FATAL_IF(status != OK, "Error while registering audio effects service: %d", status);
58
59 // Setup AudioControl HAL
60 ABinderProcess_setThreadPoolMaxThreadCount(0);
61 std::shared_ptr<AudioControl> audioControl = ::ndk::SharedRefBase::make<AudioControl>();
62
63 const std::string instance = std::string() + AudioControl::descriptor + "/default";
64 binder_status_t aidlStatus =
65 AServiceManager_addService(audioControl->asBinder().get(), instance.c_str());
66 CHECK(aidlStatus == STATUS_OK);
67
68 PowerPolicyClient powerPolicyClient = PowerPolicyClient(audioControl);
69 powerPolicyClient.init();
70
71 ABinderProcess_joinThreadPool();
72 return EXIT_FAILURE; // should not reach
73 }
74