blob: 209094c14b62b95a9dac234e9e7b01415d685f21 [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"
Eric Laurentb82e6b72019-11-22 17:25:04 -080034#include "EffectHalHidl.h"
Mikhail Naganov247b5f92021-01-15 19:16:12 +000035#include "ParameterUtils.h"
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080036#include "StreamHalHidl.h"
37
Mikhail Naganov9ccaa162018-12-12 10:27:29 -080038using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
Kevin Rocard7a9f05a2018-11-28 16:52:25 -080039using ::android::hardware::audio::common::utils::EnumBitfield;
Mikhail Naganov247b5f92021-01-15 19:16:12 +000040using ::android::hardware::audio::CPP_VERSION::implementation::CoreUtils;
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080041using ::android::hardware::hidl_string;
42using ::android::hardware::hidl_vec;
43
44namespace android {
Kevin Rocard070e7512018-05-22 09:29:13 -070045namespace CPP_VERSION {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080046
Mikhail Naganov9ccaa162018-12-12 10:27:29 -080047using namespace ::android::hardware::audio::common::CPP_VERSION;
48using namespace ::android::hardware::audio::CPP_VERSION;
49
Eric Laurentb82e6b72019-11-22 17:25:04 -080050using EffectHalHidl = ::android::effect::CPP_VERSION::EffectHalHidl;
51
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080052DeviceHalHidl::DeviceHalHidl(const sp<IDevice>& device)
53 : ConversionHelperHidl("Device"), mDevice(device),
54 mPrimaryDevice(IPrimaryDevice::castFrom(device)) {
55}
56
57DeviceHalHidl::~DeviceHalHidl() {
58 if (mDevice != 0) {
Mikhail Naganov3355e442019-11-20 14:20:01 -080059#if MAJOR_VERSION <= 5
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080060 mDevice.clear();
61 hardware::IPCThreadState::self()->flushCommands();
Mikhail Naganov3355e442019-11-20 14:20:01 -080062#elif MAJOR_VERSION >= 6
63 mDevice->close();
64#endif
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080065 }
66}
67
68status_t DeviceHalHidl::getSupportedDevices(uint32_t*) {
69 // Obsolete.
70 return INVALID_OPERATION;
71}
72
73status_t DeviceHalHidl::initCheck() {
74 if (mDevice == 0) return NO_INIT;
75 return processReturn("initCheck", mDevice->initCheck());
76}
77
78status_t DeviceHalHidl::setVoiceVolume(float volume) {
79 if (mDevice == 0) return NO_INIT;
80 if (mPrimaryDevice == 0) return INVALID_OPERATION;
81 return processReturn("setVoiceVolume", mPrimaryDevice->setVoiceVolume(volume));
82}
83
84status_t DeviceHalHidl::setMasterVolume(float volume) {
85 if (mDevice == 0) return NO_INIT;
Mikhail Naganovae1f6622019-02-21 15:20:05 -080086 return processReturn("setMasterVolume", mDevice->setMasterVolume(volume));
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080087}
88
89status_t DeviceHalHidl::getMasterVolume(float *volume) {
90 if (mDevice == 0) return NO_INIT;
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080091 Result retval;
Mikhail Naganovae1f6622019-02-21 15:20:05 -080092 Return<void> ret = mDevice->getMasterVolume(
Kevin Rocard4bcd67f2018-02-28 14:33:38 -080093 [&](Result r, float v) {
94 retval = r;
95 if (retval == Result::OK) {
96 *volume = v;
97 }
98 });
99 return processReturn("getMasterVolume", ret, retval);
100}
101
102status_t DeviceHalHidl::setMode(audio_mode_t mode) {
103 if (mDevice == 0) return NO_INIT;
104 if (mPrimaryDevice == 0) return INVALID_OPERATION;
105 return processReturn("setMode", mPrimaryDevice->setMode(AudioMode(mode)));
106}
107
108status_t DeviceHalHidl::setMicMute(bool state) {
109 if (mDevice == 0) return NO_INIT;
110 return processReturn("setMicMute", mDevice->setMicMute(state));
111}
112
113status_t DeviceHalHidl::getMicMute(bool *state) {
114 if (mDevice == 0) return NO_INIT;
115 Result retval;
116 Return<void> ret = mDevice->getMicMute(
117 [&](Result r, bool mute) {
118 retval = r;
119 if (retval == Result::OK) {
120 *state = mute;
121 }
122 });
123 return processReturn("getMicMute", ret, retval);
124}
125
126status_t DeviceHalHidl::setMasterMute(bool state) {
127 if (mDevice == 0) return NO_INIT;
128 return processReturn("setMasterMute", mDevice->setMasterMute(state));
129}
130
131status_t DeviceHalHidl::getMasterMute(bool *state) {
132 if (mDevice == 0) return NO_INIT;
133 Result retval;
134 Return<void> ret = mDevice->getMasterMute(
135 [&](Result r, bool mute) {
136 retval = r;
137 if (retval == Result::OK) {
138 *state = mute;
139 }
140 });
141 return processReturn("getMasterMute", ret, retval);
142}
143
144status_t DeviceHalHidl::setParameters(const String8& kvPairs) {
145 if (mDevice == 0) return NO_INIT;
146 hidl_vec<ParameterValue> hidlParams;
147 status_t status = parametersFromHal(kvPairs, &hidlParams);
148 if (status != OK) return status;
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800149 // TODO: change the API so that context and kvPairs are separated
150 return processReturn("setParameters",
151 utils::setParameters(mDevice, {} /* context */, hidlParams));
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800152}
153
154status_t DeviceHalHidl::getParameters(const String8& keys, String8 *values) {
155 values->clear();
156 if (mDevice == 0) return NO_INIT;
157 hidl_vec<hidl_string> hidlKeys;
158 status_t status = keysFromHal(keys, &hidlKeys);
159 if (status != OK) return status;
160 Result retval;
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800161 Return<void> ret = utils::getParameters(mDevice,
162 {} /* context */,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800163 hidlKeys,
164 [&](Result r, const hidl_vec<ParameterValue>& parameters) {
165 retval = r;
166 if (retval == Result::OK) {
167 parametersToHal(parameters, values);
168 }
169 });
170 return processReturn("getParameters", ret, retval);
171}
172
173status_t DeviceHalHidl::getInputBufferSize(
174 const struct audio_config *config, size_t *size) {
175 if (mDevice == 0) return NO_INIT;
176 AudioConfig hidlConfig;
Mikhail Naganov05e03192020-12-14 23:19:54 +0000177 HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800178 Result retval;
179 Return<void> ret = mDevice->getInputBufferSize(
180 hidlConfig,
181 [&](Result r, uint64_t bufferSize) {
182 retval = r;
183 if (retval == Result::OK) {
184 *size = static_cast<size_t>(bufferSize);
185 }
186 });
187 return processReturn("getInputBufferSize", ret, retval);
188}
189
190status_t DeviceHalHidl::openOutputStream(
191 audio_io_handle_t handle,
jiabin43810402019-10-24 14:58:31 -0700192 audio_devices_t deviceType,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800193 audio_output_flags_t flags,
194 struct audio_config *config,
195 const char *address,
196 sp<StreamOutHalInterface> *outStream) {
197 if (mDevice == 0) return NO_INIT;
198 DeviceAddress hidlDevice;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000199 if (status_t status = CoreUtils::deviceAddressFromHal(deviceType, address, &hidlDevice);
200 status != OK) {
201 return status;
202 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800203 AudioConfig hidlConfig;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000204 if (status_t status = HidlUtils::audioConfigFromHal(*config, false /*isInput*/, &hidlConfig);
205 status != OK) {
206 return status;
207 }
Eric Laurente28c66d2022-01-21 13:40:41 +0100208
209#if !(MAJOR_VERSION == 7 && MINOR_VERSION == 1)
210 //TODO: b/193496180 use spatializer flag at audio HAL when available
211 if ((flags & AUDIO_OUTPUT_FLAG_SPATIALIZER) != 0) {
212 flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_SPATIALIZER);
213 flags = (audio_output_flags_t)
214 (flags | AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_DEEP_BUFFER);
215 }
216#endif
217
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000218 CoreUtils::AudioOutputFlags hidlFlags;
219 if (status_t status = CoreUtils::audioOutputFlagsFromHal(flags, &hidlFlags); status != OK) {
220 return status;
221 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800222 Result retval = Result::NOT_INITIALIZED;
223 Return<void> ret = mDevice->openOutputStream(
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000224 handle, hidlDevice, hidlConfig, hidlFlags,
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800225#if MAJOR_VERSION >= 4
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800226 {} /* metadata */,
Kevin Rocard070e7512018-05-22 09:29:13 -0700227#endif
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800228 [&](Result r, const sp<IStreamOut>& result, const AudioConfig& suggestedConfig) {
229 retval = r;
230 if (retval == Result::OK) {
231 *outStream = new StreamOutHalHidl(result);
232 }
233 HidlUtils::audioConfigToHal(suggestedConfig, config);
234 });
235 return processReturn("openOutputStream", ret, retval);
236}
237
238status_t DeviceHalHidl::openInputStream(
239 audio_io_handle_t handle,
240 audio_devices_t devices,
241 struct audio_config *config,
242 audio_input_flags_t flags,
243 const char *address,
244 audio_source_t source,
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800245 audio_devices_t outputDevice,
246 const char *outputDeviceAddress,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800247 sp<StreamInHalInterface> *inStream) {
248 if (mDevice == 0) return NO_INIT;
249 DeviceAddress hidlDevice;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000250 if (status_t status = CoreUtils::deviceAddressFromHal(devices, address, &hidlDevice);
251 status != OK) {
252 return status;
253 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800254 AudioConfig hidlConfig;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000255 if (status_t status = HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig);
256 status != OK) {
257 return status;
258 }
259 CoreUtils::AudioInputFlags hidlFlags;
Dean Wheatleyea186342021-03-12 16:49:47 +1100260#if MAJOR_VERSION <= 5
261 // Some flags were specific to framework and must not leak to the HAL.
262 flags = static_cast<audio_input_flags_t>(flags & ~AUDIO_INPUT_FLAG_DIRECT);
263#endif
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000264 if (status_t status = CoreUtils::audioInputFlagsFromHal(flags, &hidlFlags); status != OK) {
265 return status;
266 }
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800267 Result retval = Result::NOT_INITIALIZED;
Kevin Rocard070e7512018-05-22 09:29:13 -0700268#if MAJOR_VERSION == 2
Mikhail Naganovd9499eb2018-12-17 16:23:22 -0800269 auto sinkMetadata = AudioSource(source);
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800270#elif MAJOR_VERSION >= 4
Kevin Rocardb9cfbf12018-02-23 19:11:06 -0800271 // TODO: correctly propagate the tracks sources and volume
272 // for now, only send the main source at 1dbfs
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000273 AudioSource hidlSource;
274 if (status_t status = HidlUtils::audioSourceFromHal(source, &hidlSource); status != OK) {
275 return status;
276 }
277 SinkMetadata sinkMetadata = {{{ .source = std::move(hidlSource), .gain = 1 }}};
Kevin Rocard070e7512018-05-22 09:29:13 -0700278#endif
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800279#if MAJOR_VERSION < 5
280 (void)outputDevice;
281 (void)outputDeviceAddress;
282#else
Mikhail Naganovc4258802021-02-08 17:14:17 -0800283#if MAJOR_VERSION >= 7
284 (void)HidlUtils::audioChannelMaskFromHal(
285 AUDIO_CHANNEL_NONE, true /*isInput*/, &sinkMetadata.tracks[0].channelMask);
286#endif
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800287 if (outputDevice != AUDIO_DEVICE_NONE) {
288 DeviceAddress hidlOutputDevice;
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000289 if (status_t status = CoreUtils::deviceAddressFromHal(
290 outputDevice, outputDeviceAddress, &hidlOutputDevice); status != OK) {
291 return status;
292 }
Mikhail Naganovb4e037e2019-01-14 15:56:33 -0800293 sinkMetadata.tracks[0].destination.device(std::move(hidlOutputDevice));
294 }
295#endif
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800296 Return<void> ret = mDevice->openInputStream(
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000297 handle, hidlDevice, hidlConfig, hidlFlags, sinkMetadata,
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800298 [&](Result r, const sp<IStreamIn>& result, const AudioConfig& suggestedConfig) {
299 retval = r;
300 if (retval == Result::OK) {
301 *inStream = new StreamInHalHidl(result);
302 }
303 HidlUtils::audioConfigToHal(suggestedConfig, config);
304 });
305 return processReturn("openInputStream", ret, retval);
306}
307
308status_t DeviceHalHidl::supportsAudioPatches(bool *supportsPatches) {
309 if (mDevice == 0) return NO_INIT;
310 return processReturn("supportsAudioPatches", mDevice->supportsAudioPatches(), supportsPatches);
311}
312
313status_t DeviceHalHidl::createAudioPatch(
314 unsigned int num_sources,
315 const struct audio_port_config *sources,
316 unsigned int num_sinks,
317 const struct audio_port_config *sinks,
318 audio_patch_handle_t *patch) {
319 if (mDevice == 0) return NO_INIT;
Eric Laurent8711cfd2019-06-10 18:06:33 -0700320 if (patch == nullptr) return BAD_VALUE;
321
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800322#if MAJOR_VERSION < 6
Eric Laurent8711cfd2019-06-10 18:06:33 -0700323 if (*patch != AUDIO_PATCH_HANDLE_NONE) {
324 status_t status = releaseAudioPatch(*patch);
325 ALOGW_IF(status != NO_ERROR, "%s error %d releasing patch handle %d",
326 __func__, status, *patch);
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800327 *patch = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent8711cfd2019-06-10 18:06:33 -0700328 }
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800329#endif
Eric Laurent8711cfd2019-06-10 18:06:33 -0700330
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800331 hidl_vec<AudioPortConfig> hidlSources, hidlSinks;
332 HidlUtils::audioPortConfigsFromHal(num_sources, sources, &hidlSources);
333 HidlUtils::audioPortConfigsFromHal(num_sinks, sinks, &hidlSinks);
Mikhail Naganov73bdf572019-12-11 12:34:15 -0800334 Result retval = Result::OK;
335 Return<void> ret;
336 std::string methodName = "createAudioPatch";
337 if (*patch == AUDIO_PATCH_HANDLE_NONE) { // always true for MAJOR_VERSION < 6
338 ret = mDevice->createAudioPatch(
339 hidlSources, hidlSinks,
340 [&](Result r, AudioPatchHandle hidlPatch) {
341 retval = r;
342 if (retval == Result::OK) {
343 *patch = static_cast<audio_patch_handle_t>(hidlPatch);
344 }
345 });
346 } else {
347#if MAJOR_VERSION >= 6
348 ret = mDevice->updateAudioPatch(
349 *patch,
350 hidlSources, hidlSinks,
351 [&](Result r, AudioPatchHandle hidlPatch) {
352 retval = r;
353 if (retval == Result::OK) {
354 *patch = static_cast<audio_patch_handle_t>(hidlPatch);
355 }
356 });
357 methodName = "updateAudioPatch";
358#endif
359 }
360 return processReturn(methodName.c_str(), ret, retval);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800361}
362
363status_t DeviceHalHidl::releaseAudioPatch(audio_patch_handle_t patch) {
364 if (mDevice == 0) return NO_INIT;
365 return processReturn("releaseAudioPatch", mDevice->releaseAudioPatch(patch));
366}
367
Mikhail Naganov720cc432021-03-24 20:42:49 -0700368template <typename HalPort>
369status_t DeviceHalHidl::getAudioPortImpl(HalPort *port) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800370 if (mDevice == 0) return NO_INIT;
371 AudioPort hidlPort;
372 HidlUtils::audioPortFromHal(*port, &hidlPort);
373 Result retval;
374 Return<void> ret = mDevice->getAudioPort(
375 hidlPort,
376 [&](Result r, const AudioPort& p) {
377 retval = r;
378 if (retval == Result::OK) {
379 HidlUtils::audioPortToHal(p, port);
380 }
381 });
382 return processReturn("getAudioPort", ret, retval);
383}
384
Mikhail Naganov720cc432021-03-24 20:42:49 -0700385status_t DeviceHalHidl::getAudioPort(struct audio_port *port) {
386 return getAudioPortImpl(port);
387}
388
jiabinb4fed192020-09-22 14:45:40 -0700389status_t DeviceHalHidl::getAudioPort(struct audio_port_v7 *port) {
jiabinb4fed192020-09-22 14:45:40 -0700390#if MAJOR_VERSION >= 7
Mikhail Naganov720cc432021-03-24 20:42:49 -0700391 return getAudioPortImpl(port);
jiabinb4fed192020-09-22 14:45:40 -0700392#else
393 struct audio_port audioPort = {};
Mikhail Naganov720cc432021-03-24 20:42:49 -0700394 status_t result = NO_ERROR;
395 if (!audio_populate_audio_port(port, &audioPort)) {
396 ALOGE("Failed to populate legacy audio port from audio_port_v7");
397 result = BAD_VALUE;
398 }
399 status_t status = getAudioPort(&audioPort);
jiabinb4fed192020-09-22 14:45:40 -0700400 if (status == NO_ERROR) {
401 audio_populate_audio_port_v7(&audioPort, port);
Mikhail Naganov720cc432021-03-24 20:42:49 -0700402 } else {
403 result = status;
jiabinb4fed192020-09-22 14:45:40 -0700404 }
Mikhail Naganov720cc432021-03-24 20:42:49 -0700405 return result;
jiabinb4fed192020-09-22 14:45:40 -0700406#endif
jiabinb4fed192020-09-22 14:45:40 -0700407}
408
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800409status_t DeviceHalHidl::setAudioPortConfig(const struct audio_port_config *config) {
410 if (mDevice == 0) return NO_INIT;
411 AudioPortConfig hidlConfig;
412 HidlUtils::audioPortConfigFromHal(*config, &hidlConfig);
413 return processReturn("setAudioPortConfig", mDevice->setAudioPortConfig(hidlConfig));
414}
415
Kevin Rocard070e7512018-05-22 09:29:13 -0700416#if MAJOR_VERSION == 2
417status_t DeviceHalHidl::getMicrophones(
418 std::vector<media::MicrophoneInfo> *microphonesInfo __unused) {
419 if (mDevice == 0) return NO_INIT;
420 return INVALID_OPERATION;
421}
Kevin Rocard3d48dce2018-11-08 17:16:57 -0800422#elif MAJOR_VERSION >= 4
jiabin9ff780e2018-03-19 18:19:52 -0700423status_t DeviceHalHidl::getMicrophones(std::vector<media::MicrophoneInfo> *microphonesInfo) {
424 if (mDevice == 0) return NO_INIT;
425 Result retval;
426 Return<void> ret = mDevice->getMicrophones(
427 [&](Result r, hidl_vec<MicrophoneInfo> micArrayHal) {
428 retval = r;
429 for (size_t k = 0; k < micArrayHal.size(); k++) {
430 audio_microphone_characteristic_t dst;
431 //convert
Mikhail Naganov247b5f92021-01-15 19:16:12 +0000432 (void)CoreUtils::microphoneInfoToHal(micArrayHal[k], &dst);
jiabin9ff780e2018-03-19 18:19:52 -0700433 media::MicrophoneInfo microphone = media::MicrophoneInfo(dst);
434 microphonesInfo->push_back(microphone);
435 }
436 });
437 return processReturn("getMicrophones", ret, retval);
438}
Kevin Rocard070e7512018-05-22 09:29:13 -0700439#endif
jiabin9ff780e2018-03-19 18:19:52 -0700440
Eric Laurentb82e6b72019-11-22 17:25:04 -0800441#if MAJOR_VERSION >= 6
442status_t DeviceHalHidl::addDeviceEffect(
443 audio_port_handle_t device, sp<EffectHalInterface> effect) {
444 if (mDevice == 0) return NO_INIT;
445 return processReturn("addDeviceEffect", mDevice->addDeviceEffect(
446 static_cast<AudioPortHandle>(device),
447 static_cast<EffectHalHidl*>(effect.get())->effectId()));
448}
449#else
450status_t DeviceHalHidl::addDeviceEffect(
451 audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
452 return INVALID_OPERATION;
453}
454#endif
455
456#if MAJOR_VERSION >= 6
457status_t DeviceHalHidl::removeDeviceEffect(
458 audio_port_handle_t device, sp<EffectHalInterface> effect) {
459 if (mDevice == 0) return NO_INIT;
460 return processReturn("removeDeviceEffect", mDevice->removeDeviceEffect(
461 static_cast<AudioPortHandle>(device),
462 static_cast<EffectHalHidl*>(effect.get())->effectId()));
463}
464#else
465status_t DeviceHalHidl::removeDeviceEffect(
466 audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) {
467 return INVALID_OPERATION;
468}
469#endif
470
Andy Hung61589a42021-06-16 09:37:53 -0700471status_t DeviceHalHidl::dump(int fd, const Vector<String16>& args) {
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800472 if (mDevice == 0) return NO_INIT;
473 native_handle_t* hidlHandle = native_handle_create(1, 0);
474 hidlHandle->data[0] = fd;
Andy Hung61589a42021-06-16 09:37:53 -0700475 hidl_vec<hidl_string> hidlArgs;
476 argsFromHal(args, &hidlArgs);
477 Return<void> ret = mDevice->debug(hidlHandle, hidlArgs);
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800478 native_handle_delete(hidlHandle);
Andy Hunge72ff022021-08-16 10:16:15 -0700479
480 // TODO(b/111997867, b/177271958) Workaround - remove when fixed.
481 // A Binder transmitted fd may not close immediately due to a race condition b/111997867
482 // when the remote binder thread removes the last refcount to the fd blocks in the
483 // kernel for binder activity. We send a Binder ping() command to unblock the thread
484 // and complete the fd close / release.
485 //
486 // See DeviceHalHidl::dump(), EffectHalHidl::dump(), StreamHalHidl::dump(),
487 // EffectsFactoryHalHidl::dumpEffects().
488
489 (void)mDevice->ping(); // synchronous Binder call
490
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800491 return processReturn("dump", ret);
492}
493
Kevin Rocard070e7512018-05-22 09:29:13 -0700494} // namespace CPP_VERSION
Kevin Rocard4bcd67f2018-02-28 14:33:38 -0800495} // namespace android