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