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 <string>
20 #include <vector>
21
22 #include <binder/ProcessState.h>
23 #include <cutils/properties.h>
24 #include <hidl/HidlTransportSupport.h>
25 #include <hidl/LegacySupport.h>
26 #include <hwbinder/ProcessState.h>
27
28 using namespace android::hardware;
29 using android::OK;
30
31 using InterfacesList = std::vector<std::string>;
32
33 /** Try to register the provided factories in the provided order.
34 * If any registers successfully, do not register any other and return true.
35 * If all fail, return false.
36 */
37 template <class Iter>
registerPassthroughServiceImplementations(Iter first,Iter last)38 static bool registerPassthroughServiceImplementations(Iter first, Iter last) {
39 for (; first != last; ++first) {
40 if (registerPassthroughServiceImplementation(*first) == OK) {
41 return true;
42 }
43 }
44 return false;
45 }
46
main(int,char * [])47 int main(int /* argc */, char* /* argv */ []) {
48 ::android::ProcessState::initWithDriver("/dev/vndbinder");
49 // start a threadpool for vndbinder interactions
50 ::android::ProcessState::self()->startThreadPool();
51
52 const int32_t defaultValue = -1;
53 int32_t value =
54 property_get_int32("persist.vendor.audio.service.hwbinder.size_kbyte", defaultValue);
55 if (value != defaultValue) {
56 ALOGD("Configuring hwbinder with mmap size %d KBytes", value);
57 ProcessState::initWithMmapSize(static_cast<size_t>(value) * 1024);
58 }
59 configureRpcThreadpool(16, true /*callerWillJoin*/);
60
61 // Automatic formatting tries to compact the lines, making them less readable
62 // clang-format off
63 const std::vector<InterfacesList> mandatoryInterfaces = {
64 {
65 "Audio Core API",
66 "[email protected]::IDevicesFactory",
67 "[email protected]::IDevicesFactory",
68 "[email protected]::IDevicesFactory",
69 "[email protected]::IDevicesFactory"
70 },
71 {
72 "Audio Effect API",
73 "[email protected]::IEffectsFactory",
74 "[email protected]::IEffectsFactory",
75 "[email protected]::IEffectsFactory",
76 "[email protected]::IEffectsFactory",
77 }
78 };
79
80 const std::vector<InterfacesList> optionalInterfaces = {
81 {
82 "Soundtrigger API",
83 "[email protected]::ISoundTriggerHw",
84 "[email protected]::ISoundTriggerHw",
85 "[email protected]::ISoundTriggerHw",
86 "[email protected]::ISoundTriggerHw",
87 },
88 {
89 "Bluetooth Audio API",
90 "[email protected]::IBluetoothAudioProvidersFactory"
91 },
92 // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported
93 {
94 "Bluetooth Audio Offload API",
95 "[email protected]::IBluetoothAudioOffload"
96 }
97 };
98 // clang-format on
99
100 for (const auto& listIter : mandatoryInterfaces) {
101 auto iter = listIter.begin();
102 const std::string& interfaceFamilyName = *iter++;
103 LOG_ALWAYS_FATAL_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
104 "Could not register %s", interfaceFamilyName.c_str());
105 }
106
107 for (const auto& listIter : optionalInterfaces) {
108 auto iter = listIter.begin();
109 const std::string& interfaceFamilyName = *iter++;
110 ALOGW_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
111 "Could not register %s", interfaceFamilyName.c_str());
112 }
113
114 joinRpcThreadpool();
115 }
116