blob: 898c22db6a7d81818c37be2ff9e67d7142bbe15c [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 Naganov9a88b5b2021-06-17 19:55:16 +000019#include <signal.h>
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080020#include <string>
21#include <vector>
22
Haynes Mathew Georgea57f41d2018-02-21 14:45:20 -080023#include <binder/ProcessState.h>
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070024#include <cutils/properties.h>
Mikhail Naganov5697a9b2017-12-28 13:29:59 -080025#include <hidl/HidlTransportSupport.h>
26#include <hidl/LegacySupport.h>
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070027#include <hwbinder/ProcessState.h>
Eric Laurent27ef4d82016-10-14 15:46:06 -070028
Kevin Rocard91a73b42018-03-01 18:56:58 -080029using namespace android::hardware;
Mikhail Naganov3c256462017-02-08 16:34:22 -080030using android::OK;
31
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080032using InterfacesList = std::vector<std::string>;
33
Kevin Rocard5261dce2019-06-18 12:40:48 -070034/** Try to register the provided factories in the provided order.
35 * If any registers successfully, do not register any other and return true.
36 * If all fail, return false.
37 */
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080038template <class Iter>
39static bool registerPassthroughServiceImplementations(Iter first, Iter last) {
40 for (; first != last; ++first) {
41 if (registerPassthroughServiceImplementation(*first) == OK) {
42 return true;
43 }
44 }
45 return false;
Kevin Rocard5261dce2019-06-18 12:40:48 -070046}
47
Eric Laurent27ef4d82016-10-14 15:46:06 -070048int main(int /* argc */, char* /* argv */ []) {
Mikhail Naganov9a88b5b2021-06-17 19:55:16 +000049 signal(SIGPIPE, SIG_IGN);
50
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070051 ::android::ProcessState::initWithDriver("/dev/vndbinder");
Haynes Mathew Georgea57f41d2018-02-21 14:45:20 -080052 // start a threadpool for vndbinder interactions
Mikhail Naganov317a9ed2018-09-20 14:25:01 -070053 ::android::ProcessState::self()->startThreadPool();
54
55 const int32_t defaultValue = -1;
56 int32_t value =
57 property_get_int32("persist.vendor.audio.service.hwbinder.size_kbyte", defaultValue);
58 if (value != defaultValue) {
59 ALOGD("Configuring hwbinder with mmap size %d KBytes", value);
60 ProcessState::initWithMmapSize(static_cast<size_t>(value) * 1024);
61 }
Martijn Coenen02822372016-12-29 14:03:41 +010062 configureRpcThreadpool(16, true /*callerWillJoin*/);
Kevin Rocard91a73b42018-03-01 18:56:58 -080063
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080064 // Automatic formatting tries to compact the lines, making them less readable
Kevin Rocardc69e3e92019-06-18 15:39:17 -070065 // clang-format off
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080066 const std::vector<InterfacesList> mandatoryInterfaces = {
67 {
68 "Audio Core API",
Mikhail Naganovb4443502021-02-05 00:10:40 +000069 "android.hardware.audio@7.0::IDevicesFactory",
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080070 "android.hardware.audio@6.0::IDevicesFactory",
71 "android.hardware.audio@5.0::IDevicesFactory",
72 "android.hardware.audio@4.0::IDevicesFactory",
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080073 },
74 {
75 "Audio Effect API",
Mikhail Naganovb4443502021-02-05 00:10:40 +000076 "android.hardware.audio.effect@7.0::IEffectsFactory",
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080077 "android.hardware.audio.effect@6.0::IEffectsFactory",
78 "android.hardware.audio.effect@5.0::IEffectsFactory",
79 "android.hardware.audio.effect@4.0::IEffectsFactory",
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080080 }
81 };
Kevin Rocard91a73b42018-03-01 18:56:58 -080082
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080083 const std::vector<InterfacesList> optionalInterfaces = {
84 {
85 "Soundtrigger API",
86 "android.hardware.soundtrigger@2.3::ISoundTriggerHw",
87 "android.hardware.soundtrigger@2.2::ISoundTriggerHw",
88 "android.hardware.soundtrigger@2.1::ISoundTriggerHw",
89 "android.hardware.soundtrigger@2.0::ISoundTriggerHw",
90 },
91 {
92 "Bluetooth Audio API",
Grzegorz Kolodziejczykb5f2d232019-10-24 12:31:20 +020093 "android.hardware.bluetooth.audio@2.1::IBluetoothAudioProvidersFactory",
94 "android.hardware.bluetooth.audio@2.0::IBluetoothAudioProvidersFactory",
Mikhail Naganovf3e4d212020-01-29 15:32:24 -080095 },
96 // remove the old HIDL when Bluetooth Audio Hal V2 has offloading supported
97 {
98 "Bluetooth Audio Offload API",
Mikhail Naganov2801b032020-01-31 14:48:23 -080099 "android.hardware.bluetooth.a2dp@1.0::IBluetoothAudioOffload"
Mikhail Naganovf3e4d212020-01-29 15:32:24 -0800100 }
101 };
Kevin Rocardc69e3e92019-06-18 15:39:17 -0700102 // clang-format on
Kevin Rocard91a73b42018-03-01 18:56:58 -0800103
Mikhail Naganovf3e4d212020-01-29 15:32:24 -0800104 for (const auto& listIter : mandatoryInterfaces) {
105 auto iter = listIter.begin();
106 const std::string& interfaceFamilyName = *iter++;
107 LOG_ALWAYS_FATAL_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
108 "Could not register %s", interfaceFamilyName.c_str());
109 }
Kevin Rocard91a73b42018-03-01 18:56:58 -0800110
Mikhail Naganovf3e4d212020-01-29 15:32:24 -0800111 for (const auto& listIter : optionalInterfaces) {
112 auto iter = listIter.begin();
113 const std::string& interfaceFamilyName = *iter++;
114 ALOGW_IF(!registerPassthroughServiceImplementations(iter, listIter.end()),
115 "Could not register %s", interfaceFamilyName.c_str());
116 }
Aniket Kumar Latac5a52032018-01-31 20:17:30 -0800117
Martijn Coenen02822372016-12-29 14:03:41 +0100118 joinRpcThreadpool();
Eric Laurent27ef4d82016-10-14 15:46:06 -0700119}