Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 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 | #include <stdio.h> |
| 18 | |
| 19 | #define LOG_TAG "DeviceHalHidl" |
| 20 | //#define LOG_NDEBUG 0 |
| 21 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 22 | #include <cutils/native_handle.h> |
Jiabin Huang | ebe6410 | 2021-09-07 20:01:07 +0000 | [diff] [blame] | 23 | #include <cutils/properties.h> |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 24 | #include <hwbinder/IPCThreadState.h> |
jiabin | daf4995 | 2019-11-22 14:10:57 -0800 | [diff] [blame] | 25 | #include <media/AudioContainers.h> |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 26 | #include <mediautils/TimeCheck.h> |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 27 | #include <utils/Log.h> |
| 28 | |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 29 | #include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h) |
| 30 | #include <HidlUtils.h> |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 31 | #include <common/all-versions/VersionUtils.h> |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 32 | #include <util/CoreUtils.h> |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 33 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 34 | #include "DeviceHalHidl.h" |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 35 | #include "ParameterUtils.h" |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 36 | #include "StreamHalHidl.h" |
| 37 | |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 38 | using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils; |
Kevin Rocard | 7a9f05a | 2018-11-28 16:52:25 -0800 | [diff] [blame] | 39 | using ::android::hardware::audio::common::utils::EnumBitfield; |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 40 | using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 41 | using ::android::hardware::hidl_string; |
| 42 | using ::android::hardware::hidl_vec; |
| 43 | |
| 44 | namespace android { |
| 45 | |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 46 | using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; |
| 47 | using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; |
Mikhail Naganov | 9ccaa16 | 2018-12-12 10:27:29 -0800 | [diff] [blame] | 48 | |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 49 | DeviceHalHidl::DeviceHalHidl(const sp<::android::hardware::audio::CPP_VERSION::IDevice>& device) |
Mikhail Naganov | 288a343 | 2022-03-25 00:29:56 +0000 | [diff] [blame] | 50 | : CoreConversionHelperHidl("DeviceHalHidl"), mDevice(device) { |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 51 | } |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 52 | |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 53 | DeviceHalHidl::DeviceHalHidl( |
| 54 | const sp<::android::hardware::audio::CPP_VERSION::IPrimaryDevice>& device) |
Mikhail Naganov | 288a343 | 2022-03-25 00:29:56 +0000 | [diff] [blame] | 55 | : CoreConversionHelperHidl("DeviceHalHidl"), |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 56 | #if MAJOR_VERSION <= 6 || (MAJOR_VERSION == 7 && MINOR_VERSION == 0) |
| 57 | mDevice(device), |
| 58 | #endif |
| 59 | mPrimaryDevice(device) { |
| 60 | #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 |
| 61 | auto getDeviceRet = mPrimaryDevice->getDevice(); |
| 62 | if (getDeviceRet.isOk()) { |
| 63 | mDevice = getDeviceRet; |
| 64 | } else { |
| 65 | ALOGE("Call to IPrimaryDevice.getDevice has failed: %s", |
| 66 | getDeviceRet.description().c_str()); |
| 67 | } |
| 68 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | DeviceHalHidl::~DeviceHalHidl() { |
| 72 | if (mDevice != 0) { |
Mikhail Naganov | 3355e44 | 2019-11-20 14:20:01 -0800 | [diff] [blame] | 73 | #if MAJOR_VERSION <= 5 |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 74 | mDevice.clear(); |
| 75 | hardware::IPCThreadState::self()->flushCommands(); |
Mikhail Naganov | 3355e44 | 2019-11-20 14:20:01 -0800 | [diff] [blame] | 76 | #elif MAJOR_VERSION >= 6 |
| 77 | mDevice->close(); |
| 78 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 82 | status_t DeviceHalHidl::getAudioPorts( |
| 83 | std::vector<media::audio::common::AudioPort> *ports __unused) { |
| 84 | return INVALID_OPERATION; |
| 85 | } |
| 86 | |
| 87 | status_t DeviceHalHidl::getAudioRoutes(std::vector<media::AudioRoute> *routes __unused) { |
| 88 | return INVALID_OPERATION; |
| 89 | } |
| 90 | |
Mikhail Naganov | 1fba38c | 2023-05-03 17:45:36 -0700 | [diff] [blame^] | 91 | status_t DeviceHalHidl::getSupportedModes( |
| 92 | std::vector<media::audio::common::AudioMode> *modes __unused) { |
| 93 | return INVALID_OPERATION; |
| 94 | } |
| 95 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 96 | status_t DeviceHalHidl::getSupportedDevices(uint32_t*) { |
| 97 | // Obsolete. |
| 98 | return INVALID_OPERATION; |
| 99 | } |
| 100 | |
| 101 | status_t DeviceHalHidl::initCheck() { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 102 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 103 | if (mDevice == 0) return NO_INIT; |
| 104 | return processReturn("initCheck", mDevice->initCheck()); |
| 105 | } |
| 106 | |
| 107 | status_t DeviceHalHidl::setVoiceVolume(float volume) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 108 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 109 | if (mDevice == 0) return NO_INIT; |
| 110 | if (mPrimaryDevice == 0) return INVALID_OPERATION; |
| 111 | return processReturn("setVoiceVolume", mPrimaryDevice->setVoiceVolume(volume)); |
| 112 | } |
| 113 | |
| 114 | status_t DeviceHalHidl::setMasterVolume(float volume) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 115 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 116 | if (mDevice == 0) return NO_INIT; |
Mikhail Naganov | ae1f662 | 2019-02-21 15:20:05 -0800 | [diff] [blame] | 117 | return processReturn("setMasterVolume", mDevice->setMasterVolume(volume)); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | status_t DeviceHalHidl::getMasterVolume(float *volume) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 121 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 122 | if (mDevice == 0) return NO_INIT; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 123 | Result retval; |
Mikhail Naganov | ae1f662 | 2019-02-21 15:20:05 -0800 | [diff] [blame] | 124 | Return<void> ret = mDevice->getMasterVolume( |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 125 | [&](Result r, float v) { |
| 126 | retval = r; |
| 127 | if (retval == Result::OK) { |
| 128 | *volume = v; |
| 129 | } |
| 130 | }); |
| 131 | return processReturn("getMasterVolume", ret, retval); |
| 132 | } |
| 133 | |
| 134 | status_t DeviceHalHidl::setMode(audio_mode_t mode) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 135 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 136 | if (mDevice == 0) return NO_INIT; |
| 137 | if (mPrimaryDevice == 0) return INVALID_OPERATION; |
| 138 | return processReturn("setMode", mPrimaryDevice->setMode(AudioMode(mode))); |
| 139 | } |
| 140 | |
| 141 | status_t DeviceHalHidl::setMicMute(bool state) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 142 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 143 | if (mDevice == 0) return NO_INIT; |
| 144 | return processReturn("setMicMute", mDevice->setMicMute(state)); |
| 145 | } |
| 146 | |
| 147 | status_t DeviceHalHidl::getMicMute(bool *state) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 148 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 149 | if (mDevice == 0) return NO_INIT; |
| 150 | Result retval; |
| 151 | Return<void> ret = mDevice->getMicMute( |
| 152 | [&](Result r, bool mute) { |
| 153 | retval = r; |
| 154 | if (retval == Result::OK) { |
| 155 | *state = mute; |
| 156 | } |
| 157 | }); |
| 158 | return processReturn("getMicMute", ret, retval); |
| 159 | } |
| 160 | |
| 161 | status_t DeviceHalHidl::setMasterMute(bool state) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 162 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 163 | if (mDevice == 0) return NO_INIT; |
| 164 | return processReturn("setMasterMute", mDevice->setMasterMute(state)); |
| 165 | } |
| 166 | |
| 167 | status_t DeviceHalHidl::getMasterMute(bool *state) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 168 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 169 | if (mDevice == 0) return NO_INIT; |
| 170 | Result retval; |
| 171 | Return<void> ret = mDevice->getMasterMute( |
| 172 | [&](Result r, bool mute) { |
| 173 | retval = r; |
| 174 | if (retval == Result::OK) { |
| 175 | *state = mute; |
| 176 | } |
| 177 | }); |
| 178 | return processReturn("getMasterMute", ret, retval); |
| 179 | } |
| 180 | |
| 181 | status_t DeviceHalHidl::setParameters(const String8& kvPairs) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 182 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 183 | if (mDevice == 0) return NO_INIT; |
| 184 | hidl_vec<ParameterValue> hidlParams; |
| 185 | status_t status = parametersFromHal(kvPairs, &hidlParams); |
| 186 | if (status != OK) return status; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 187 | // TODO: change the API so that context and kvPairs are separated |
| 188 | return processReturn("setParameters", |
| 189 | utils::setParameters(mDevice, {} /* context */, hidlParams)); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | status_t DeviceHalHidl::getParameters(const String8& keys, String8 *values) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 193 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 194 | values->clear(); |
| 195 | if (mDevice == 0) return NO_INIT; |
| 196 | hidl_vec<hidl_string> hidlKeys; |
| 197 | status_t status = keysFromHal(keys, &hidlKeys); |
| 198 | if (status != OK) return status; |
| 199 | Result retval; |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 200 | Return<void> ret = utils::getParameters(mDevice, |
| 201 | {} /* context */, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 202 | hidlKeys, |
| 203 | [&](Result r, const hidl_vec<ParameterValue>& parameters) { |
| 204 | retval = r; |
| 205 | if (retval == Result::OK) { |
| 206 | parametersToHal(parameters, values); |
| 207 | } |
| 208 | }); |
| 209 | return processReturn("getParameters", ret, retval); |
| 210 | } |
| 211 | |
| 212 | status_t DeviceHalHidl::getInputBufferSize( |
| 213 | const struct audio_config *config, size_t *size) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 214 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 215 | if (mDevice == 0) return NO_INIT; |
| 216 | AudioConfig hidlConfig; |
Mikhail Naganov | 05e0319 | 2020-12-14 23:19:54 +0000 | [diff] [blame] | 217 | HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 218 | Result retval; |
| 219 | Return<void> ret = mDevice->getInputBufferSize( |
| 220 | hidlConfig, |
| 221 | [&](Result r, uint64_t bufferSize) { |
| 222 | retval = r; |
| 223 | if (retval == Result::OK) { |
| 224 | *size = static_cast<size_t>(bufferSize); |
| 225 | } |
| 226 | }); |
| 227 | return processReturn("getInputBufferSize", ret, retval); |
| 228 | } |
| 229 | |
| 230 | status_t DeviceHalHidl::openOutputStream( |
| 231 | audio_io_handle_t handle, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 232 | audio_devices_t deviceType, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 233 | audio_output_flags_t flags, |
| 234 | struct audio_config *config, |
| 235 | const char *address, |
| 236 | sp<StreamOutHalInterface> *outStream) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 237 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 238 | if (mDevice == 0) return NO_INIT; |
| 239 | DeviceAddress hidlDevice; |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 240 | if (status_t status = CoreUtils::deviceAddressFromHal(deviceType, address, &hidlDevice); |
| 241 | status != OK) { |
| 242 | return status; |
| 243 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 244 | AudioConfig hidlConfig; |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 245 | if (status_t status = HidlUtils::audioConfigFromHal(*config, false /*isInput*/, &hidlConfig); |
| 246 | status != OK) { |
| 247 | return status; |
| 248 | } |
Eric Laurent | e28c66d | 2022-01-21 13:40:41 +0100 | [diff] [blame] | 249 | |
| 250 | #if !(MAJOR_VERSION == 7 && MINOR_VERSION == 1) |
| 251 | //TODO: b/193496180 use spatializer flag at audio HAL when available |
| 252 | if ((flags & AUDIO_OUTPUT_FLAG_SPATIALIZER) != 0) { |
| 253 | flags = (audio_output_flags_t)(flags & ~AUDIO_OUTPUT_FLAG_SPATIALIZER); |
| 254 | flags = (audio_output_flags_t) |
| 255 | (flags | AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_DEEP_BUFFER); |
| 256 | } |
| 257 | #endif |
| 258 | |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 259 | CoreUtils::AudioOutputFlags hidlFlags; |
| 260 | if (status_t status = CoreUtils::audioOutputFlagsFromHal(flags, &hidlFlags); status != OK) { |
| 261 | return status; |
| 262 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 263 | Result retval = Result::NOT_INITIALIZED; |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 264 | #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 |
| 265 | Return<void> ret = mDevice->openOutputStream_7_1( |
| 266 | #else |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 267 | Return<void> ret = mDevice->openOutputStream( |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 268 | #endif |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 269 | handle, hidlDevice, hidlConfig, hidlFlags, |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 270 | #if MAJOR_VERSION >= 4 |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 271 | {} /* metadata */, |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 272 | #endif |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 273 | [&](Result r, const sp<::android::hardware::audio::CPP_VERSION::IStreamOut>& result, |
| 274 | const AudioConfig& suggestedConfig) { |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 275 | retval = r; |
| 276 | if (retval == Result::OK) { |
| 277 | *outStream = new StreamOutHalHidl(result); |
| 278 | } |
| 279 | HidlUtils::audioConfigToHal(suggestedConfig, config); |
| 280 | }); |
| 281 | return processReturn("openOutputStream", ret, retval); |
| 282 | } |
| 283 | |
| 284 | status_t DeviceHalHidl::openInputStream( |
| 285 | audio_io_handle_t handle, |
| 286 | audio_devices_t devices, |
| 287 | struct audio_config *config, |
| 288 | audio_input_flags_t flags, |
| 289 | const char *address, |
| 290 | audio_source_t source, |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 291 | audio_devices_t outputDevice, |
| 292 | const char *outputDeviceAddress, |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 293 | sp<StreamInHalInterface> *inStream) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 294 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 295 | if (mDevice == 0) return NO_INIT; |
| 296 | DeviceAddress hidlDevice; |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 297 | if (status_t status = CoreUtils::deviceAddressFromHal(devices, address, &hidlDevice); |
| 298 | status != OK) { |
| 299 | return status; |
| 300 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 301 | AudioConfig hidlConfig; |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 302 | if (status_t status = HidlUtils::audioConfigFromHal(*config, true /*isInput*/, &hidlConfig); |
| 303 | status != OK) { |
| 304 | return status; |
| 305 | } |
| 306 | CoreUtils::AudioInputFlags hidlFlags; |
Dean Wheatley | ea18634 | 2021-03-12 16:49:47 +1100 | [diff] [blame] | 307 | #if MAJOR_VERSION <= 5 |
| 308 | // Some flags were specific to framework and must not leak to the HAL. |
| 309 | flags = static_cast<audio_input_flags_t>(flags & ~AUDIO_INPUT_FLAG_DIRECT); |
| 310 | #endif |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 311 | if (status_t status = CoreUtils::audioInputFlagsFromHal(flags, &hidlFlags); status != OK) { |
| 312 | return status; |
| 313 | } |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 314 | Result retval = Result::NOT_INITIALIZED; |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 315 | #if MAJOR_VERSION == 2 |
Mikhail Naganov | d9499eb | 2018-12-17 16:23:22 -0800 | [diff] [blame] | 316 | auto sinkMetadata = AudioSource(source); |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 317 | #elif MAJOR_VERSION >= 4 |
Kevin Rocard | b9cfbf1 | 2018-02-23 19:11:06 -0800 | [diff] [blame] | 318 | // TODO: correctly propagate the tracks sources and volume |
| 319 | // for now, only send the main source at 1dbfs |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 320 | AudioSource hidlSource; |
| 321 | if (status_t status = HidlUtils::audioSourceFromHal(source, &hidlSource); status != OK) { |
| 322 | return status; |
| 323 | } |
| 324 | SinkMetadata sinkMetadata = {{{ .source = std::move(hidlSource), .gain = 1 }}}; |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 325 | #endif |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 326 | #if MAJOR_VERSION < 5 |
| 327 | (void)outputDevice; |
| 328 | (void)outputDeviceAddress; |
| 329 | #else |
Mikhail Naganov | c425880 | 2021-02-08 17:14:17 -0800 | [diff] [blame] | 330 | #if MAJOR_VERSION >= 7 |
| 331 | (void)HidlUtils::audioChannelMaskFromHal( |
| 332 | AUDIO_CHANNEL_NONE, true /*isInput*/, &sinkMetadata.tracks[0].channelMask); |
| 333 | #endif |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 334 | if (outputDevice != AUDIO_DEVICE_NONE) { |
| 335 | DeviceAddress hidlOutputDevice; |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 336 | if (status_t status = CoreUtils::deviceAddressFromHal( |
| 337 | outputDevice, outputDeviceAddress, &hidlOutputDevice); status != OK) { |
| 338 | return status; |
| 339 | } |
Mikhail Naganov | b4e037e | 2019-01-14 15:56:33 -0800 | [diff] [blame] | 340 | sinkMetadata.tracks[0].destination.device(std::move(hidlOutputDevice)); |
| 341 | } |
| 342 | #endif |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 343 | Return<void> ret = mDevice->openInputStream( |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 344 | handle, hidlDevice, hidlConfig, hidlFlags, sinkMetadata, |
Mikhail Naganov | accbe8a | 2022-02-03 23:45:36 +0000 | [diff] [blame] | 345 | [&](Result r, |
| 346 | const sp<::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStreamIn>& result, |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 347 | const AudioConfig& suggestedConfig) { |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 348 | retval = r; |
| 349 | if (retval == Result::OK) { |
| 350 | *inStream = new StreamInHalHidl(result); |
| 351 | } |
| 352 | HidlUtils::audioConfigToHal(suggestedConfig, config); |
| 353 | }); |
| 354 | return processReturn("openInputStream", ret, retval); |
| 355 | } |
| 356 | |
| 357 | status_t DeviceHalHidl::supportsAudioPatches(bool *supportsPatches) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 358 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 359 | if (mDevice == 0) return NO_INIT; |
| 360 | return processReturn("supportsAudioPatches", mDevice->supportsAudioPatches(), supportsPatches); |
| 361 | } |
| 362 | |
| 363 | status_t DeviceHalHidl::createAudioPatch( |
| 364 | unsigned int num_sources, |
| 365 | const struct audio_port_config *sources, |
| 366 | unsigned int num_sinks, |
| 367 | const struct audio_port_config *sinks, |
| 368 | audio_patch_handle_t *patch) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 369 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 370 | if (mDevice == 0) return NO_INIT; |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 371 | if (patch == nullptr) return BAD_VALUE; |
| 372 | |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 373 | #if MAJOR_VERSION < 6 |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 374 | if (*patch != AUDIO_PATCH_HANDLE_NONE) { |
| 375 | status_t status = releaseAudioPatch(*patch); |
| 376 | ALOGW_IF(status != NO_ERROR, "%s error %d releasing patch handle %d", |
| 377 | __func__, status, *patch); |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 378 | *patch = AUDIO_PATCH_HANDLE_NONE; |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 379 | } |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 380 | #endif |
Eric Laurent | 8711cfd | 2019-06-10 18:06:33 -0700 | [diff] [blame] | 381 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 382 | hidl_vec<AudioPortConfig> hidlSources, hidlSinks; |
| 383 | HidlUtils::audioPortConfigsFromHal(num_sources, sources, &hidlSources); |
| 384 | HidlUtils::audioPortConfigsFromHal(num_sinks, sinks, &hidlSinks); |
Mikhail Naganov | 73bdf57 | 2019-12-11 12:34:15 -0800 | [diff] [blame] | 385 | Result retval = Result::OK; |
| 386 | Return<void> ret; |
| 387 | std::string methodName = "createAudioPatch"; |
| 388 | if (*patch == AUDIO_PATCH_HANDLE_NONE) { // always true for MAJOR_VERSION < 6 |
| 389 | ret = mDevice->createAudioPatch( |
| 390 | hidlSources, hidlSinks, |
| 391 | [&](Result r, AudioPatchHandle hidlPatch) { |
| 392 | retval = r; |
| 393 | if (retval == Result::OK) { |
| 394 | *patch = static_cast<audio_patch_handle_t>(hidlPatch); |
| 395 | } |
| 396 | }); |
| 397 | } else { |
| 398 | #if MAJOR_VERSION >= 6 |
| 399 | ret = mDevice->updateAudioPatch( |
| 400 | *patch, |
| 401 | hidlSources, hidlSinks, |
| 402 | [&](Result r, AudioPatchHandle hidlPatch) { |
| 403 | retval = r; |
| 404 | if (retval == Result::OK) { |
| 405 | *patch = static_cast<audio_patch_handle_t>(hidlPatch); |
| 406 | } |
| 407 | }); |
| 408 | methodName = "updateAudioPatch"; |
| 409 | #endif |
| 410 | } |
| 411 | return processReturn(methodName.c_str(), ret, retval); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | status_t DeviceHalHidl::releaseAudioPatch(audio_patch_handle_t patch) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 415 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 416 | if (mDevice == 0) return NO_INIT; |
| 417 | return processReturn("releaseAudioPatch", mDevice->releaseAudioPatch(patch)); |
| 418 | } |
| 419 | |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 420 | template <typename HalPort> |
| 421 | status_t DeviceHalHidl::getAudioPortImpl(HalPort *port) { |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 422 | using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioPort; |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 423 | if (mDevice == 0) return NO_INIT; |
| 424 | AudioPort hidlPort; |
| 425 | HidlUtils::audioPortFromHal(*port, &hidlPort); |
| 426 | Result retval; |
| 427 | Return<void> ret = mDevice->getAudioPort( |
| 428 | hidlPort, |
| 429 | [&](Result r, const AudioPort& p) { |
| 430 | retval = r; |
| 431 | if (retval == Result::OK) { |
| 432 | HidlUtils::audioPortToHal(p, port); |
| 433 | } |
| 434 | }); |
| 435 | return processReturn("getAudioPort", ret, retval); |
| 436 | } |
| 437 | |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 438 | status_t DeviceHalHidl::getAudioPort(struct audio_port *port) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 439 | TIME_CHECK(); |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 440 | return getAudioPortImpl(port); |
| 441 | } |
| 442 | |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 443 | status_t DeviceHalHidl::getAudioPort(struct audio_port_v7 *port) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 444 | TIME_CHECK(); |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 445 | #if MAJOR_VERSION >= 7 |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 446 | return getAudioPortImpl(port); |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 447 | #else |
| 448 | struct audio_port audioPort = {}; |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 449 | status_t result = NO_ERROR; |
| 450 | if (!audio_populate_audio_port(port, &audioPort)) { |
| 451 | ALOGE("Failed to populate legacy audio port from audio_port_v7"); |
| 452 | result = BAD_VALUE; |
| 453 | } |
| 454 | status_t status = getAudioPort(&audioPort); |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 455 | if (status == NO_ERROR) { |
| 456 | audio_populate_audio_port_v7(&audioPort, port); |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 457 | } else { |
| 458 | result = status; |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 459 | } |
Mikhail Naganov | 720cc43 | 2021-03-24 20:42:49 -0700 | [diff] [blame] | 460 | return result; |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 461 | #endif |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 462 | } |
| 463 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 464 | status_t DeviceHalHidl::setAudioPortConfig(const struct audio_port_config *config) { |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 465 | using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioPortConfig; |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 466 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 467 | if (mDevice == 0) return NO_INIT; |
| 468 | AudioPortConfig hidlConfig; |
| 469 | HidlUtils::audioPortConfigFromHal(*config, &hidlConfig); |
| 470 | return processReturn("setAudioPortConfig", mDevice->setAudioPortConfig(hidlConfig)); |
| 471 | } |
| 472 | |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 473 | #if MAJOR_VERSION == 2 |
| 474 | status_t DeviceHalHidl::getMicrophones( |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 475 | std::vector<audio_microphone_characteristic_t> *microphonesInfo __unused) { |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 476 | if (mDevice == 0) return NO_INIT; |
| 477 | return INVALID_OPERATION; |
| 478 | } |
Kevin Rocard | 3d48dce | 2018-11-08 17:16:57 -0800 | [diff] [blame] | 479 | #elif MAJOR_VERSION >= 4 |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 480 | status_t DeviceHalHidl::getMicrophones( |
| 481 | std::vector<audio_microphone_characteristic_t> *microphonesInfo) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 482 | TIME_CHECK(); |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 483 | if (mDevice == 0) return NO_INIT; |
| 484 | Result retval; |
| 485 | Return<void> ret = mDevice->getMicrophones( |
| 486 | [&](Result r, hidl_vec<MicrophoneInfo> micArrayHal) { |
| 487 | retval = r; |
| 488 | for (size_t k = 0; k < micArrayHal.size(); k++) { |
| 489 | audio_microphone_characteristic_t dst; |
| 490 | //convert |
Mikhail Naganov | 247b5f9 | 2021-01-15 19:16:12 +0000 | [diff] [blame] | 491 | (void)CoreUtils::microphoneInfoToHal(micArrayHal[k], &dst); |
Shunkai Yao | 5120250 | 2022-12-12 06:11:46 +0000 | [diff] [blame] | 492 | microphonesInfo->push_back(dst); |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 493 | } |
| 494 | }); |
| 495 | return processReturn("getMicrophones", ret, retval); |
| 496 | } |
Kevin Rocard | 070e751 | 2018-05-22 09:29:13 -0700 | [diff] [blame] | 497 | #endif |
jiabin | 9ff780e | 2018-03-19 18:19:52 -0700 | [diff] [blame] | 498 | |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 499 | #if MAJOR_VERSION >= 6 |
| 500 | status_t DeviceHalHidl::addDeviceEffect( |
| 501 | audio_port_handle_t device, sp<EffectHalInterface> effect) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 502 | TIME_CHECK(); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 503 | if (mDevice == 0) return NO_INIT; |
| 504 | return processReturn("addDeviceEffect", mDevice->addDeviceEffect( |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 505 | static_cast<AudioPortHandle>(device), effect->effectId())); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 506 | } |
| 507 | #else |
| 508 | status_t DeviceHalHidl::addDeviceEffect( |
| 509 | audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) { |
| 510 | return INVALID_OPERATION; |
| 511 | } |
| 512 | #endif |
| 513 | |
| 514 | #if MAJOR_VERSION >= 6 |
| 515 | status_t DeviceHalHidl::removeDeviceEffect( |
| 516 | audio_port_handle_t device, sp<EffectHalInterface> effect) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 517 | TIME_CHECK(); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 518 | if (mDevice == 0) return NO_INIT; |
| 519 | return processReturn("removeDeviceEffect", mDevice->removeDeviceEffect( |
Mikhail Naganov | 6718c39 | 2022-01-27 22:17:21 +0000 | [diff] [blame] | 520 | static_cast<AudioPortHandle>(device), effect->effectId())); |
Eric Laurent | b82e6b7 | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 521 | } |
| 522 | #else |
| 523 | status_t DeviceHalHidl::removeDeviceEffect( |
| 524 | audio_port_handle_t device __unused, sp<EffectHalInterface> effect __unused) { |
| 525 | return INVALID_OPERATION; |
| 526 | } |
| 527 | #endif |
| 528 | |
jiabin | 872de70 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 529 | status_t DeviceHalHidl::prepareToDisconnectExternalDevice(const struct audio_port_v7* port) { |
| 530 | // For HIDL HAL, there is not API to call notify the HAL to prepare for device connected |
| 531 | // state changed. Call `setConnectedState` directly. |
| 532 | const status_t status = setConnectedState(port, false /*connected*/); |
| 533 | if (status == NO_ERROR) { |
| 534 | // Cache the port id so that it won't disconnect twice. |
| 535 | mDeviceDisconnectionNotified.insert(port->id); |
| 536 | } |
| 537 | return status; |
| 538 | } |
| 539 | |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 540 | status_t DeviceHalHidl::setConnectedState(const struct audio_port_v7 *port, bool connected) { |
Mikhail Naganov | f83b974 | 2023-04-24 13:06:04 -0700 | [diff] [blame] | 541 | using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioPort; |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 542 | TIME_CHECK(); |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 543 | if (mDevice == 0) return NO_INIT; |
jiabin | 872de70 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 544 | if (!connected && mDeviceDisconnectionNotified.erase(port->id) > 0) { |
| 545 | // For device disconnection, APM will first call `prepareToDisconnectExternalDevice` and |
| 546 | // then call `setConnectedState`. However, in HIDL HAL, there is no API for |
| 547 | // `prepareToDisconnectExternalDevice`. In that case, HIDL HAL will call `setConnectedState` |
| 548 | // when calling `prepareToDisconnectExternalDevice`. Do not call to the HAL if previous |
| 549 | // call is successful. Also remove the cache here to avoid a large cache after a long run. |
| 550 | return NO_ERROR; |
| 551 | } |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 552 | #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 |
| 553 | if (supportsSetConnectedState7_1) { |
| 554 | AudioPort hidlPort; |
| 555 | if (status_t result = HidlUtils::audioPortFromHal(*port, &hidlPort); result != NO_ERROR) { |
| 556 | return result; |
| 557 | } |
| 558 | Return<Result> ret = mDevice->setConnectedState_7_1(hidlPort, connected); |
| 559 | if (!ret.isOk() || ret != Result::NOT_SUPPORTED) { |
| 560 | return processReturn("setConnectedState_7_1", ret); |
| 561 | } else if (ret == Result::OK) { |
| 562 | return NO_ERROR; |
| 563 | } |
| 564 | supportsSetConnectedState7_1 = false; |
| 565 | } |
| 566 | #endif |
| 567 | DeviceAddress hidlAddress; |
| 568 | if (status_t result = CoreUtils::deviceAddressFromHal( |
| 569 | port->ext.device.type, port->ext.device.address, &hidlAddress); |
| 570 | result != NO_ERROR) { |
| 571 | return result; |
| 572 | } |
| 573 | return processReturn("setConnectedState", mDevice->setConnectedState(hidlAddress, connected)); |
| 574 | } |
| 575 | |
Ytai Ben-Tsvi | 48287b5 | 2021-12-01 15:07:11 -0800 | [diff] [blame] | 576 | error::Result<audio_hw_sync_t> DeviceHalHidl::getHwAvSync() { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 577 | TIME_CHECK(); |
Ytai Ben-Tsvi | 48287b5 | 2021-12-01 15:07:11 -0800 | [diff] [blame] | 578 | if (mDevice == 0) return NO_INIT; |
| 579 | audio_hw_sync_t value; |
| 580 | Result result; |
| 581 | Return<void> ret = mDevice->getHwAvSync([&value, &result](Result r, audio_hw_sync_t v) { |
| 582 | value = v; |
| 583 | result = r; |
| 584 | }); |
| 585 | RETURN_IF_ERROR(processReturn("getHwAvSync", ret, result)); |
| 586 | return value; |
| 587 | } |
| 588 | |
Andy Hung | 61589a4 | 2021-06-16 09:37:53 -0700 | [diff] [blame] | 589 | status_t DeviceHalHidl::dump(int fd, const Vector<String16>& args) { |
Andy Hung | 224f82f | 2022-03-22 00:00:49 -0700 | [diff] [blame] | 590 | TIME_CHECK(); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 591 | if (mDevice == 0) return NO_INIT; |
| 592 | native_handle_t* hidlHandle = native_handle_create(1, 0); |
| 593 | hidlHandle->data[0] = fd; |
Andy Hung | 61589a4 | 2021-06-16 09:37:53 -0700 | [diff] [blame] | 594 | hidl_vec<hidl_string> hidlArgs; |
| 595 | argsFromHal(args, &hidlArgs); |
| 596 | Return<void> ret = mDevice->debug(hidlHandle, hidlArgs); |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 597 | native_handle_delete(hidlHandle); |
Andy Hung | e72ff02 | 2021-08-16 10:16:15 -0700 | [diff] [blame] | 598 | |
| 599 | // TODO(b/111997867, b/177271958) Workaround - remove when fixed. |
| 600 | // A Binder transmitted fd may not close immediately due to a race condition b/111997867 |
| 601 | // when the remote binder thread removes the last refcount to the fd blocks in the |
| 602 | // kernel for binder activity. We send a Binder ping() command to unblock the thread |
| 603 | // and complete the fd close / release. |
| 604 | // |
| 605 | // See DeviceHalHidl::dump(), EffectHalHidl::dump(), StreamHalHidl::dump(), |
| 606 | // EffectsFactoryHalHidl::dumpEffects(). |
| 607 | |
| 608 | (void)mDevice->ping(); // synchronous Binder call |
| 609 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 610 | return processReturn("dump", ret); |
| 611 | } |
| 612 | |
Kevin Rocard | 4bcd67f | 2018-02-28 14:33:38 -0800 | [diff] [blame] | 613 | } // namespace android |