blob: 94d08c3541c109557861f79926c1e70e5f7de703 [file] [log] [blame]
Kevin Rocard4bcd67f2018-02-28 14:33:38 -08001/*
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#include <stdio.h>
18
19#define LOG_TAG "DeviceHalHidl"
20//#define LOG_NDEBUG 0
21
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080022#include <cutils/native_handle.h>
Jiabin Huangebe64102021-09-07 20:01:07 +000023#include <cutils/properties.h>
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080024#include <hwbinder/IPCThreadState.h>
jiabindaf49952019-11-22 14:10:57 -080025#include <media/AudioContainers.h>
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080026#include <utils/Log.h>
27
Mikhail Naganov247b5f92021-01-15 19:16:12 +000028#include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h)
29#include <HidlUtils.h>
Kevin Rocardb9cfbf12018-02-23 19:11:06 -080030#include <common/all-versions/VersionUtils.h>
Mikhail Naganov247b5f92021-01-15 19:16:12 +000031#include <util/CoreUtils.h>
Kevin Rocardb9cfbf12018-02-23 19:11:06 -080032
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080033#include "DeviceHalHidl.h"
Mikhail Naganov247b5f92021-01-15 19:16:12 +000034#include "ParameterUtils.h"
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080035#include "StreamHalHidl.h"
36
Mikhail Naganov6718c392022-01-27 22:17:21 +000037using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
Kevin Rocard7a9f05a2018-11-28 16:52:25 -080038using ::android::hardware::audio::common::utils::EnumBitfield;
Mikhail Naganov6718c392022-01-27 22:17:21 +000039using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080040using ::android::hardware::hidl_string;
41using ::android::hardware::hidl_vec;
42
43namespace android {
44
Mikhail Naganov6718c392022-01-27 22:17:21 +000045using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
46using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
Mikhail Naganov9ccaa162018-12-12 10:27:29 -080047
Mikhail Naganov6718c392022-01-27 22:17:21 +000048DeviceHalHidl::DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device)
49 : ConversionHelperHidl("Device"), mDevice(device) {
50}
Eric Laurentb82e6b72019-11-22 17:25:04 -080051
Mikhail Naganov6718c392022-01-27 22:17:21 +000052DeviceHalHidl::DeviceHalHidl(
53 const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& device)
54 : ConversionHelperHidl("Device"),
55#if MAJOR_VERSION <= 6 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0)
56 mDevice(device),
57#endif
58 mPrimaryDevice(device) {
59#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
60 auto getDeviceRet = mPrimaryDevice->getDevice();
61 if (getDeviceRet.isOk()) {
62 mDevice = getDeviceRet;
63 } else {
64 ALOGE("Call to IPrimaryDevice.getDevice has failed: %s",
65 getDeviceRet.description().c_str());
66 }
67#endif
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080068}
69
70DeviceHalHidl::~DeviceHalHidl() {
71 if (mDevice != 0) {
Mikhail Naganov3355e442019-11-20 14:20:01 -080072#if MAJOR_VERSION <= 5
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080073 mDevice.clear();
74 hardware::IPCThreadState::self()->flushCommands();
Mikhail Naganov3355e442019-11-20 14:20:01 -080075#elif MAJOR_VERSION >= 6
76 mDevice->close();
77#endif
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080078 }
79}
80
81status_t DeviceHalHidl::getSupportedDevices(uint32_t*) {
82 // Obsolete.
83 return INVALID_OPERATION;
84}
85
86status_t DeviceHalHidl::initCheck() {
87 if (mDevice == 0) return NO_INIT;
88 return processReturn("initCheck", mDevice->initCheck());
89}
90
91status_t DeviceHalHidl::setVoiceVolume(float volume) {
92 if (mDevice == 0) return NO_INIT;
93 if (mPrimaryDevice == 0) return INVALID_OPERATION;
94 return processReturn("setVoiceVolume", mPrimaryDevice->setVoiceVolume(volume));
95}
96
97status_t DeviceHalHidl::setMasterVolume(float volume) {
98 if (mDevice == 0) return NO_INIT;
Mikhail Naganovae1f6622019-02-21 15:20:05 -080099 return processReturn("setMasterVolume", mDevice->setMasterVolume(volume));
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800100}
101
102status_t DeviceHalHidl::getMasterVolume(float *volume) {
103 if (mDevice == 0) return NO_INIT;
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800104 Result retval;
Mikhail Naganovae1f6622019-02-21 15:20:05 -0800105 Return<void> ret = mDevice->getMasterVolume(
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800106 [&](Result r, float v) {
107 retval = r;
108 if (retval == Result::OK) {
109 *volume = v;
110 }
111 });
112 return processReturn("getMasterVolume", ret, retval);
113}
114
115status_t DeviceHalHidl::setMode(audio_mode_t mode) {
116 if (mDevice == 0) return NO_INIT;
117 if (mPrimaryDevice == 0) return INVALID_OPERATION;
118 return processReturn("setMode", mPrimaryDevice->setMode(AudioMode(mode)));
119}
120
121status_t DeviceHalHidl::setMicMute(bool state) {
122 if (mDevice == 0) return NO_INIT;
123 return processReturn("setMicMute", mDevice->setMicMute(state));
124}
125
126status_t DeviceHalHidl::getMicMute(bool *state) {
127 if (mDevice == 0) return NO_INIT;
128 Result retval;
129 Return<void> ret = mDevice->getMicMute(
130 [&](Result r, bool mute) {
131 retval = r;
132 if (retval == Result::OK) {
133 *state = mute;
134 }
135 });
136 return processReturn("getMicMute", ret, retval);
137}
138
139status_t DeviceHalHidl::setMasterMute(bool state) {
140 if (mDevice == 0) return NO_INIT;
141 return processReturn("setMasterMute", mDevice->setMasterMute(state));
142}
143
144status_t DeviceHalHidl::getMasterMute(bool *state) {
145 if (mDevice == 0) return NO_INIT;
146 Result retval;
147 Return<void> ret = mDevice->getMasterMute(
148 [&](Result r, bool mute) {
149 retval = r;
150 if (retval == Result::OK) {
151 *state = mute;
152 }
153 });
154 return processReturn("getMasterMute", ret, retval);
155}
156
157status_t DeviceHalHidl::setParameters(const String8& kvPairs) {
158 if (mDevice == 0) return NO_INIT;
159 hidl_vec<ParameterValue> hidlParams;
160 status_t status = parametersFromHal(kvPairs, &hidlParams);
161 if (status != OK) return status;
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800162 // TODO: change the API so that context and kvPairs are separated
163 return processReturn("setParameters",
164 utils::setParameters(mDevice, {} /* context */, hidlParams));
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800165}
166
167status_t DeviceHalHidl::getParameters(const String8& keys, String8 *values) {
168 values->clear();
169 if (mDevice == 0) return NO_INIT;
170 hidl_vec<hidl_string> hidlKeys;
171 status_t status = keysFromHal(keys, &hidlKeys);
172 if (status != OK) return status;
173 Result retval;
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800174 Return<void> ret = utils::getParameters(mDevice,
175 {} /* context */,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800176 hidlKeys,
177 [&](Result r, const hidl_vec<ParameterValue>& parameters) {
178 retval = r;
179 if (retval == Result::OK) {
180 parametersToHal(parameters, values);
181 }
182 });
183 return processReturn("getParameters", ret, retval);
184}
185
186status_t DeviceHalHidl::getInputBufferSize(
187 const struct audio_config *config, size_t *size) {
188 if (mDevice == 0) return NO_INIT;
189 AudioConfig hidlConfig;
Mikhail Naganov05e03192020-12-14 23:19:54 +0000190 HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800191 Result retval;
192 Return<void> ret = mDevice->getInputBufferSize(
193 hidlConfig,
194 [&](Result r, uint64_t bufferSize) {
195 retval = r;
196 if (retval == Result::OK) {
197 *size = static_cast<size_t>(bufferSize);
198 }
199 });
200 return processReturn("getInputBufferSize", ret, retval);
201}
202
203status_t DeviceHalHidl::openOutputStream(
204 audio_io_handle_t handle,
jiabin43810402019-10-24 14:58:31 -0700205 audio_devices_t deviceType,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800206 audio_output_flags_t flags,
207 struct audio_config *config,
208 const char *address,
209 sp<StreamOutHalInterface> *outStream) {
210 if (mDevice == 0) return NO_INIT;
211 DeviceAddress hidlDevice;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000212 if (status_t status = CoreUtils::deviceAddressFromHal(deviceType, address, &hidlDevice);
213 status != OK) {
214 return status;
215 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800216 AudioConfig hidlConfig;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000217 if (status_t status = HidlUtils::audioConfigFromHal(*config, false /*isInput*/, &hidlConfig);
218 status != OK) {
219 return status;
220 }
Eric Laurente28c66d2022-01-21 13:40:41 +0100221
222#if !(MAJOR_VERSION == 7 && MINOR_VERSION == 1)
223 //TODO: b/193496180 use spatializer flag at audio HAL when available
224 if ((flags & AUDIO_OUTPUT_FLAG_SPATIALIZER) != 0) {
225 flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_SPATIALIZER);
226 flags = (audio_output_flags_t)
227 (flags | AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
228 }
229#endif
230
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000231 CoreUtils::AudioOutputFlags hidlFlags;
232 if (status_t status = CoreUtils::audioOutputFlagsFromHal(flags, &hidlFlags); status != OK) {
233 return status;
234 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800235 Result retval = Result::NOT_INITIALIZED;
Mikhail Naganov6718c392022-01-27 22:17:21 +0000236#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
237 Return<void> ret = mDevice->openOutputStream_7_1(
238#else
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800239 Return<void> ret = mDevice->openOutputStream(
Mikhail Naganov6718c392022-01-27 22:17:21 +0000240#endif
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000241 handle, hidlDevice, hidlConfig, hidlFlags,
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800242#if MAJOR_VERSION >= 4
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800243 {} /* metadata */,
Kevin Rocard070e7512018-05-22 09:29:13 -0700244#endif
Mikhail Naganov6718c392022-01-27 22:17:21 +0000245 [&](Result r, const sp<::android::hardware::audio::CPP_VERSION::IStreamOut>& result,
246 const AudioConfig& suggestedConfig) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800247 retval = r;
248 if (retval == Result::OK) {
249 *outStream = new StreamOutHalHidl(result);
250 }
251 HidlUtils::audioConfigToHal(suggestedConfig, config);
252 });
253 return processReturn("openOutputStream", ret, retval);
254}
255
256status_t DeviceHalHidl::openInputStream(
257 audio_io_handle_t handle,
258 audio_devices_t devices,
259 struct audio_config *config,
260 audio_input_flags_t flags,
261 const char *address,
262 audio_source_t source,
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800263 audio_devices_t outputDevice,
264 const char *outputDeviceAddress,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800265 sp<StreamInHalInterface> *inStream) {
266 if (mDevice == 0) return NO_INIT;
267 DeviceAddress hidlDevice;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000268 if (status_t status = CoreUtils::deviceAddressFromHal(devices, address, &hidlDevice);
269 status != OK) {
270 return status;
271 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800272 AudioConfig hidlConfig;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000273 if (status_t status = HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig);
274 status != OK) {
275 return status;
276 }
277 CoreUtils::AudioInputFlags hidlFlags;
Dean Wheatleyea186342021-03-12 16:49:47 +1100278#if MAJOR_VERSION <= 5
279 // Some flags were specific to framework and must not leak to the HAL.
280 flags = static_cast<audio_input_flags_t>(flags & ~AUDIO_INPUT_FLAG_DIRECT);
281#endif
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000282 if (status_t status = CoreUtils::audioInputFlagsFromHal(flags, &hidlFlags); status != OK) {
283 return status;
284 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800285 Result retval = Result::NOT_INITIALIZED;
Kevin Rocard070e7512018-05-22 09:29:13 -0700286#if MAJOR_VERSION == 2
Mikhail Naganovd9499eb2018-12-17 16:23:22 -0800287 auto sinkMetadata = AudioSource(source);
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800288#elif MAJOR_VERSION >= 4
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800289 // TODO: correctly propagate the tracks sources and volume
290 // for now, only send the main source at 1dbfs
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000291 AudioSource hidlSource;
292 if (status_t status = HidlUtils::audioSourceFromHal(source, &hidlSource); status != OK) {
293 return status;
294 }
295 SinkMetadata sinkMetadata = {{{ .source = std::move(hidlSource), .gain = 1 }}};
Kevin Rocard070e7512018-05-22 09:29:13 -0700296#endif
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800297#if MAJOR_VERSION < 5
298 (void)outputDevice;
299 (void)outputDeviceAddress;
300#else
Mikhail Naganovc4258802021-02-08 17:14:17 -0800301#if MAJOR_VERSION >= 7
302 (void)HidlUtils::audioChannelMaskFromHal(
303 AUDIO_CHANNEL_NONE, true /*isInput*/, &sinkMetadata.tracks[0].channelMask);
304#endif
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800305 if (outputDevice != AUDIO_DEVICE_NONE) {
306 DeviceAddress hidlOutputDevice;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000307 if (status_t status = CoreUtils::deviceAddressFromHal(
308 outputDevice, outputDeviceAddress, &hidlOutputDevice); status != OK) {
309 return status;
310 }
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800311 sinkMetadata.tracks[0].destination.device(std::move(hidlOutputDevice));
312 }
313#endif
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800314 Return<void> ret = mDevice->openInputStream(
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000315 handle, hidlDevice, hidlConfig, hidlFlags, sinkMetadata,
Mikhail Naganovaccbe8a2022-02-03 23:45:36 +0000316 [&](Result r,
317 const sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStreamIn>& result,
Mikhail Naganov6718c392022-01-27 22:17:21 +0000318 const AudioConfig& suggestedConfig) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800319 retval = r;
320 if (retval == Result::OK) {
321 *inStream = new StreamInHalHidl(result);
322 }
323 HidlUtils::audioConfigToHal(suggestedConfig, config);
324 });
325 return processReturn("openInputStream", ret, retval);
326}
327
328status_t DeviceHalHidl::supportsAudioPatches(bool *supportsPatches) {
329 if (mDevice == 0) return NO_INIT;
330 return processReturn("supportsAudioPatches", mDevice->supportsAudioPatches(), supportsPatches);
331}
332
333status_t DeviceHalHidl::createAudioPatch(
334 unsigned int num_sources,
335 const struct audio_port_config *sources,
336 unsigned int num_sinks,
337 const struct audio_port_config *sinks,
338 audio_patch_handle_t *patch) {
339 if (mDevice == 0) return NO_INIT;
Eric Laurent8711cfd2019-06-10 18:06:33 -0700340 if (patch == nullptr) return BAD_VALUE;
341
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800342#if MAJOR_VERSION < 6
Eric Laurent8711cfd2019-06-10 18:06:33 -0700343 if (*patch != AUDIO_PATCH_HANDLE_NONE) {
344 status_t status = releaseAudioPatch(*patch);
345 ALOGW_IF(status != NO_ERROR, "%s error %d releasing patch handle %d",
346 __func__, status, *patch);
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800347 *patch = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent8711cfd2019-06-10 18:06:33 -0700348 }
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800349#endif
Eric Laurent8711cfd2019-06-10 18:06:33 -0700350
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800351 hidl_vec<AudioPortConfig> hidlSources, hidlSinks;
352 HidlUtils::audioPortConfigsFromHal(num_sources, sources, &hidlSources);
353 HidlUtils::audioPortConfigsFromHal(num_sinks, sinks, &hidlSinks);
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800354 Result retval = Result::OK;
355 Return<void> ret;
356 std::string methodName = "createAudioPatch";
357 if (*patch == AUDIO_PATCH_HANDLE_NONE) { // always true for MAJOR_VERSION < 6
358 ret = mDevice->createAudioPatch(
359 hidlSources, hidlSinks,
360 [&](Result r, AudioPatchHandle hidlPatch) {
361 retval = r;
362 if (retval == Result::OK) {
363 *patch = static_cast<audio_patch_handle_t>(hidlPatch);
364 }
365 });
366 } else {
367#if MAJOR_VERSION >= 6
368 ret = mDevice->updateAudioPatch(
369 *patch,
370 hidlSources, hidlSinks,
371 [&](Result r, AudioPatchHandle hidlPatch) {
372 retval = r;
373 if (retval == Result::OK) {
374 *patch = static_cast<audio_patch_handle_t>(hidlPatch);
375 }
376 });
377 methodName = "updateAudioPatch";
378#endif
379 }
380 return processReturn(methodName.c_str(), ret, retval);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800381}
382
383status_t DeviceHalHidl::releaseAudioPatch(audio_patch_handle_t patch) {
384 if (mDevice == 0) return NO_INIT;
385 return processReturn("releaseAudioPatch", mDevice->releaseAudioPatch(patch));
386}
387
Mikhail Naganov720cc432021-03-24 20:42:49 -0700388template <typename HalPort>
389status_t DeviceHalHidl::getAudioPortImpl(HalPort *port) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800390 if (mDevice == 0) return NO_INIT;
391 AudioPort hidlPort;
392 HidlUtils::audioPortFromHal(*port, &hidlPort);
393 Result retval;
394 Return<void> ret = mDevice->getAudioPort(
395 hidlPort,
396 [&](Result r, const AudioPort& p) {
397 retval = r;
398 if (retval == Result::OK) {
399 HidlUtils::audioPortToHal(p, port);
400 }
401 });
402 return processReturn("getAudioPort", ret, retval);
403}
404
Mikhail Naganov720cc432021-03-24 20:42:49 -0700405status_t DeviceHalHidl::getAudioPort(struct audio_port *port) {
406 return getAudioPortImpl(port);
407}
408
jiabinb4fed192020-09-22 14:45:40 -0700409status_t DeviceHalHidl::getAudioPort(struct audio_port_v7 *port) {
jiabinb4fed192020-09-22 14:45:40 -0700410#if MAJOR_VERSION >= 7
Mikhail Naganov720cc432021-03-24 20:42:49 -0700411 return getAudioPortImpl(port);
jiabinb4fed192020-09-22 14:45:40 -0700412#else
413 struct audio_port audioPort = {};
Mikhail Naganov720cc432021-03-24 20:42:49 -0700414 status_t result = NO_ERROR;
415 if (!audio_populate_audio_port(port, &audioPort)) {
416 ALOGE("Failed to populate legacy audio port from audio_port_v7");
417 result = BAD_VALUE;
418 }
419 status_t status = getAudioPort(&audioPort);
jiabinb4fed192020-09-22 14:45:40 -0700420 if (status == NO_ERROR) {
421 audio_populate_audio_port_v7(&audioPort, port);
Mikhail Naganov720cc432021-03-24 20:42:49 -0700422 } else {
423 result = status;
jiabinb4fed192020-09-22 14:45:40 -0700424 }
Mikhail Naganov720cc432021-03-24 20:42:49 -0700425 return result;
jiabinb4fed192020-09-22 14:45:40 -0700426#endif
jiabinb4fed192020-09-22 14:45:40 -0700427}
428
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800429status_t DeviceHalHidl::setAudioPortConfig(const struct audio_port_config *config) {
430 if (mDevice == 0) return NO_INIT;
431 AudioPortConfig hidlConfig;
432 HidlUtils::audioPortConfigFromHal(*config, &hidlConfig);
433 return processReturn("setAudioPortConfig", mDevice->setAudioPortConfig(hidlConfig));
434}
435
Kevin Rocard070e7512018-05-22 09:29:13 -0700436#if MAJOR_VERSION == 2
437status_t DeviceHalHidl::getMicrophones(
438 std::vector<media::MicrophoneInfo> *microphonesInfo __unused) {
439 if (mDevice == 0) return NO_INIT;
440 return INVALID_OPERATION;
441}
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800442#elif MAJOR_VERSION >= 4
jiabin9ff780e2018-03-19 18:19:52 -0700443status_t DeviceHalHidl::getMicrophones(std::vector<media::MicrophoneInfo> *microphonesInfo) {
444 if (mDevice == 0) return NO_INIT;
445 Result retval;
446 Return<void> ret = mDevice->getMicrophones(
447 [&](Result r, hidl_vec<MicrophoneInfo> micArrayHal) {
448 retval = r;
449 for (size_t k = 0; k < micArrayHal.size(); k++) {
450 audio_microphone_characteristic_t dst;
451 //convert
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000452 (void)CoreUtils::microphoneInfoToHal(micArrayHal[k], &dst);
jiabin9ff780e2018-03-19 18:19:52 -0700453 media::MicrophoneInfo microphone = media::MicrophoneInfo(dst);
454 microphonesInfo->push_back(microphone);
455 }
456 });
457 return processReturn("getMicrophones", ret, retval);
458}
Kevin Rocard070e7512018-05-22 09:29:13 -0700459#endif
jiabin9ff780e2018-03-19 18:19:52 -0700460
Eric Laurentb82e6b72019-11-22 17:25:04 -0800461#if MAJOR_VERSION >= 6
462status_t DeviceHalHidl::addDeviceEffect(
463 audio_port_handle_t device, sp<EffectHalInterface> effect) {
464 if (mDevice == 0) return NO_INIT;
465 return processReturn("addDeviceEffect", mDevice->addDeviceEffect(
Mikhail Naganov6718c392022-01-27 22:17:21 +0000466 static_cast<AudioPortHandle>(device), effect->effectId()));
Eric Laurentb82e6b72019-11-22 17:25:04 -0800467}
468#else
469status_t DeviceHalHidl::addDeviceEffect(
470 audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
471 return INVALID_OPERATION;
472}
473#endif
474
475#if MAJOR_VERSION >= 6
476status_t DeviceHalHidl::removeDeviceEffect(
477 audio_port_handle_t device, sp<EffectHalInterface> effect) {
478 if (mDevice == 0) return NO_INIT;
479 return processReturn("removeDeviceEffect", mDevice->removeDeviceEffect(
Mikhail Naganov6718c392022-01-27 22:17:21 +0000480 static_cast<AudioPortHandle>(device), effect->effectId()));
Eric Laurentb82e6b72019-11-22 17:25:04 -0800481}
482#else
483status_t DeviceHalHidl::removeDeviceEffect(
484 audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
485 return INVALID_OPERATION;
486}
487#endif
488
Andy Hung61589a42021-06-16 09:37:53 -0700489status_t DeviceHalHidl::dump(int fd, const Vector<String16>& args) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800490 if (mDevice == 0) return NO_INIT;
491 native_handle_t* hidlHandle = native_handle_create(1, 0);
492 hidlHandle->data[0] = fd;
Andy Hung61589a42021-06-16 09:37:53 -0700493 hidl_vec<hidl_string> hidlArgs;
494 argsFromHal(args, &hidlArgs);
495 Return<void> ret = mDevice->debug(hidlHandle, hidlArgs);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800496 native_handle_delete(hidlHandle);
Andy Hunge72ff022021-08-16 10:16:15 -0700497
498 // TODO(b/111997867, b/177271958) Workaround - remove when fixed.
499 // A Binder transmitted fd may not close immediately due to a race condition b/111997867
500 // when the remote binder thread removes the last refcount to the fd blocks in the
501 // kernel for binder activity. We send a Binder ping() command to unblock the thread
502 // and complete the fd close / release.
503 //
504 // See DeviceHalHidl::dump(), EffectHalHidl::dump(), StreamHalHidl::dump(),
505 // EffectsFactoryHalHidl::dumpEffects().
506
507 (void)mDevice->ping(); // synchronous Binder call
508
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800509 return processReturn("dump", ret);
510}
511
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800512} // namespace android