blob: 710ddcea1140307b025b38d03935c1b06d193d81 [file] [log] [blame]
Eric Laurent27ef4d82016-10-14 15:46:06 -07001/*
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
Mikhail Naganov10548292016-10-31 10:39:47 -070017#define LOG_TAG "audiohalservice"
Eric Laurent27ef4d82016-10-14 15:46:06 -070018
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080019#include <string>
20#include <vector>
21
Haynes Mathew Georgea57f41d2018-02-21 14:45:20 -080022#include <binder/ProcessState.h>
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070023#include <cutils/properties.h>
Mikhail Naganov5697a9b2017-12-28 13:29:59 -080024#include <hidl/HidlTransportSupport.h>
25#include <hidl/LegacySupport.h>
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070026#include <hwbinder/ProcessState.h>
Eric Laurent27ef4d82016-10-14 15:46:06 -070027
Kevin Rocard91a73b42018-03-01 18:56:58 -080028using namespace android::hardware;
Mikhail Naganov3c256462017-02-08 16:34:22 -080029using android::OK;
30
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080031using InterfacesList = std::vector<std::string>;
32
Kevin Rocard5261dce2019-06-18 12:40:48 -070033/** 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 */
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080037template <class Iter>
38static bool registerPassthroughServiceImplementations(Iter first, Iter last) {
39 for (; first != last; ++first) {
40 if (registerPassthroughServiceImplementation(*first) == OK) {
41 return true;
42 }
43 }
44 return false;
Kevin Rocard5261dce2019-06-18 12:40:48 -070045}
46
Eric Laurent27ef4d82016-10-14 15:46:06 -070047int main(int /* argc */, char* /* argv */ []) {
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070048 ::android::ProcessState::initWithDriver("/dev/vndbinder");
Haynes Mathew Georgea57f41d2018-02-21 14:45:20 -080049 // start a threadpool for vndbinder interactions
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070050 ::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 }
Martijn Coenen02822372016-12-29 14:03:41 +010059 configureRpcThreadpool(16, true /*callerWillJoin*/);
Kevin Rocard91a73b42018-03-01 18:56:58 -080060
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080061 // Automatic formatting tries to compact the lines, making them less readable
Kevin Rocardc69e3e92019-06-18 15:39:17 -070062 // clang-format off
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080063 const std::vector<InterfacesList> mandatoryInterfaces = {
64 {
65 "Audio Core API",
66 "android.hardware.audio@6.0::IDevicesFactory",
67 "android.hardware.audio@5.0::IDevicesFactory",
68 "android.hardware.audio@4.0::IDevicesFactory",
69 "android.hardware.audio@2.0::IDevicesFactory"
70 },
71 {
72 "Audio Effect API",
73 "android.hardware.audio.effect@6.0::IEffectsFactory",
74 "android.hardware.audio.effect@5.0::IEffectsFactory",
75 "android.hardware.audio.effect@4.0::IEffectsFactory",
76 "android.hardware.audio.effect@2.0::IEffectsFactory",
77 }
78 };
Kevin Rocard91a73b42018-03-01 18:56:58 -080079
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080080 const std::vector<InterfacesList> optionalInterfaces = {
81 {
82 "Soundtrigger API",
83 "android.hardware.soundtrigger@2.3::ISoundTriggerHw",
84 "android.hardware.soundtrigger@2.2::ISoundTriggerHw",
85 "android.hardware.soundtrigger@2.1::ISoundTriggerHw",
86 "android.hardware.soundtrigger@2.0::ISoundTriggerHw",
87 },
88 {
89 "Bluetooth Audio API",
Grzegorz Kolodziejczykb5f2d232019-10-24 12:31:20 +020090 "android.hardware.bluetooth.audio@2.1::IBluetoothAudioProvidersFactory",
91 "android.hardware.bluetooth.audio@2.0::IBluetoothAudioProvidersFactory",
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080092 },
93 // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported
94 {
95 "Bluetooth Audio Offload API",
Mikhail Naganov2801b032020-01-31 14:48:23 -080096 "android.hardware.bluetooth.a2dp@1.0::IBluetoothAudioOffload"
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080097 }
98 };
Kevin Rocardc69e3e92019-06-18 15:39:17 -070099 // clang-format on
Kevin Rocard91a73b42018-03-01 18:56:58 -0800100
Mikhail Naganovf3e4d212020-01-29 15:32:24 -0800101 for (const auto& listIter : mandatoryInterfaces) {
102 auto iter = listIter.begin();
103 const std::string& interfaceFamilyName = *iter++;
104 LOG_ALWAYS_FATAL_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
105 "Could not register %s", interfaceFamilyName.c_str());
106 }
Kevin Rocard91a73b42018-03-01 18:56:58 -0800107
Mikhail Naganovf3e4d212020-01-29 15:32:24 -0800108 for (const auto& listIter : optionalInterfaces) {
109 auto iter = listIter.begin();
110 const std::string& interfaceFamilyName = *iter++;
111 ALOGW_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
112 "Could not register %s", interfaceFamilyName.c_str());
113 }
Aniket Kumar Latac5a52032018-01-31 20:17:30 -0800114
Martijn Coenen02822372016-12-29 14:03:41 +0100115 joinRpcThreadpool();
Eric Laurent27ef4d82016-10-14 15:46:06 -0700116}