1 /*
2 * Copyright (C) 2022 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 <algorithm>
18 #include <set>
19
20 #define LOG_TAG "AHAL_Module"
21 #include <Utils.h>
22 #include <aidl/android/media/audio/common/AudioInputFlags.h>
23 #include <aidl/android/media/audio/common/AudioOutputFlags.h>
24 #include <android-base/logging.h>
25 #include <android/binder_ibinder_platform.h>
26 #include <error/expected_utils.h>
27
28 #include "core-impl/Module.h"
29 #include "core-impl/ModuleBluetooth.h"
30 #include "core-impl/ModulePrimary.h"
31 #include "core-impl/ModuleRemoteSubmix.h"
32 #include "core-impl/ModuleStub.h"
33 #include "core-impl/ModuleUsb.h"
34 #include "core-impl/SoundDose.h"
35 #include "core-impl/utils.h"
36
37 using aidl::android::hardware::audio::common::getFrameSizeInBytes;
38 using aidl::android::hardware::audio::common::isBitPositionFlagSet;
39 using aidl::android::hardware::audio::common::isValidAudioMode;
40 using aidl::android::hardware::audio::common::SinkMetadata;
41 using aidl::android::hardware::audio::common::SourceMetadata;
42 using aidl::android::hardware::audio::core::sounddose::ISoundDose;
43 using aidl::android::media::audio::common::AudioChannelLayout;
44 using aidl::android::media::audio::common::AudioDevice;
45 using aidl::android::media::audio::common::AudioFormatDescription;
46 using aidl::android::media::audio::common::AudioFormatType;
47 using aidl::android::media::audio::common::AudioInputFlags;
48 using aidl::android::media::audio::common::AudioIoFlags;
49 using aidl::android::media::audio::common::AudioMMapPolicy;
50 using aidl::android::media::audio::common::AudioMMapPolicyInfo;
51 using aidl::android::media::audio::common::AudioMMapPolicyType;
52 using aidl::android::media::audio::common::AudioMode;
53 using aidl::android::media::audio::common::AudioOffloadInfo;
54 using aidl::android::media::audio::common::AudioOutputFlags;
55 using aidl::android::media::audio::common::AudioPort;
56 using aidl::android::media::audio::common::AudioPortConfig;
57 using aidl::android::media::audio::common::AudioPortExt;
58 using aidl::android::media::audio::common::AudioProfile;
59 using aidl::android::media::audio::common::Boolean;
60 using aidl::android::media::audio::common::Int;
61 using aidl::android::media::audio::common::MicrophoneInfo;
62 using aidl::android::media::audio::common::PcmType;
63
64 namespace aidl::android::hardware::audio::core {
65
66 namespace {
67
generateDefaultPortConfig(const AudioPort & port,AudioPortConfig * config)68 bool generateDefaultPortConfig(const AudioPort& port, AudioPortConfig* config) {
69 *config = {};
70 config->portId = port.id;
71 if (port.profiles.empty()) {
72 LOG(ERROR) << __func__ << ": port " << port.id << " has no profiles";
73 return false;
74 }
75 const auto& profile = port.profiles.begin();
76 config->format = profile->format;
77 if (profile->channelMasks.empty()) {
78 LOG(ERROR) << __func__ << ": the first profile in port " << port.id
79 << " has no channel masks";
80 return false;
81 }
82 config->channelMask = *profile->channelMasks.begin();
83 if (profile->sampleRates.empty()) {
84 LOG(ERROR) << __func__ << ": the first profile in port " << port.id
85 << " has no sample rates";
86 return false;
87 }
88 Int sampleRate;
89 sampleRate.value = *profile->sampleRates.begin();
90 config->sampleRate = sampleRate;
91 config->flags = port.flags;
92 config->ext = port.ext;
93 return true;
94 }
95
findAudioProfile(const AudioPort & port,const AudioFormatDescription & format,AudioProfile * profile)96 bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& format,
97 AudioProfile* profile) {
98 if (auto profilesIt =
99 find_if(port.profiles.begin(), port.profiles.end(),
100 [&format](const auto& profile) { return profile.format == format; });
101 profilesIt != port.profiles.end()) {
102 *profile = *profilesIt;
103 return true;
104 }
105 return false;
106 }
107
108 } // namespace
109
110 // static
createInstance(Type type)111 std::shared_ptr<Module> Module::createInstance(Type type) {
112 switch (type) {
113 case Type::DEFAULT:
114 return ndk::SharedRefBase::make<ModulePrimary>();
115 case Type::R_SUBMIX:
116 return ndk::SharedRefBase::make<ModuleRemoteSubmix>();
117 case Type::STUB:
118 return ndk::SharedRefBase::make<ModuleStub>();
119 case Type::USB:
120 return ndk::SharedRefBase::make<ModuleUsb>();
121 case Type::BLUETOOTH:
122 return ndk::SharedRefBase::make<ModuleBluetooth>();
123 }
124 }
125
operator <<(std::ostream & os,Module::Type t)126 std::ostream& operator<<(std::ostream& os, Module::Type t) {
127 switch (t) {
128 case Module::Type::DEFAULT:
129 os << "default";
130 break;
131 case Module::Type::R_SUBMIX:
132 os << "r_submix";
133 break;
134 case Module::Type::STUB:
135 os << "stub";
136 break;
137 case Module::Type::USB:
138 os << "usb";
139 break;
140 case Module::Type::BLUETOOTH:
141 os << "bluetooth";
142 break;
143 }
144 return os;
145 }
146
cleanUpPatch(int32_t patchId)147 void Module::cleanUpPatch(int32_t patchId) {
148 erase_all_values(mPatches, std::set<int32_t>{patchId});
149 }
150
createStreamContext(int32_t in_portConfigId,int64_t in_bufferSizeFrames,std::shared_ptr<IStreamCallback> asyncCallback,std::shared_ptr<IStreamOutEventCallback> outEventCallback,StreamContext * out_context)151 ndk::ScopedAStatus Module::createStreamContext(
152 int32_t in_portConfigId, int64_t in_bufferSizeFrames,
153 std::shared_ptr<IStreamCallback> asyncCallback,
154 std::shared_ptr<IStreamOutEventCallback> outEventCallback, StreamContext* out_context) {
155 if (in_bufferSizeFrames <= 0) {
156 LOG(ERROR) << __func__ << ": non-positive buffer size " << in_bufferSizeFrames;
157 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
158 }
159 if (in_bufferSizeFrames < kMinimumStreamBufferSizeFrames) {
160 LOG(ERROR) << __func__ << ": insufficient buffer size " << in_bufferSizeFrames
161 << ", must be at least " << kMinimumStreamBufferSizeFrames;
162 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
163 }
164 auto& configs = getConfig().portConfigs;
165 auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId);
166 // Since this is a private method, it is assumed that
167 // validity of the portConfigId has already been checked.
168 const size_t frameSize =
169 getFrameSizeInBytes(portConfigIt->format.value(), portConfigIt->channelMask.value());
170 if (frameSize == 0) {
171 LOG(ERROR) << __func__ << ": could not calculate frame size for port config "
172 << portConfigIt->toString();
173 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
174 }
175 LOG(DEBUG) << __func__ << ": frame size " << frameSize << " bytes";
176 if (frameSize > static_cast<size_t>(kMaximumStreamBufferSizeBytes / in_bufferSizeFrames)) {
177 LOG(ERROR) << __func__ << ": buffer size " << in_bufferSizeFrames
178 << " frames is too large, maximum size is "
179 << kMaximumStreamBufferSizeBytes / frameSize;
180 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
181 }
182 const auto& flags = portConfigIt->flags.value();
183 if ((flags.getTag() == AudioIoFlags::Tag::input &&
184 !isBitPositionFlagSet(flags.get<AudioIoFlags::Tag::input>(),
185 AudioInputFlags::MMAP_NOIRQ)) ||
186 (flags.getTag() == AudioIoFlags::Tag::output &&
187 !isBitPositionFlagSet(flags.get<AudioIoFlags::Tag::output>(),
188 AudioOutputFlags::MMAP_NOIRQ))) {
189 StreamContext::DebugParameters params{mDebug.streamTransientStateDelayMs,
190 mVendorDebug.forceTransientBurst,
191 mVendorDebug.forceSynchronousDrain};
192 StreamContext temp(
193 std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/),
194 std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
195 portConfigIt->portId, portConfigIt->format.value(),
196 portConfigIt->channelMask.value(), portConfigIt->sampleRate.value().value, flags,
197 portConfigIt->ext.get<AudioPortExt::mix>().handle,
198 std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
199 asyncCallback, outEventCallback, params);
200 if (temp.isValid()) {
201 *out_context = std::move(temp);
202 } else {
203 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
204 }
205 } else {
206 // TODO: Implement simulation of MMAP buffer allocation
207 }
208 return ndk::ScopedAStatus::ok();
209 }
210
findConnectedDevices(int32_t portConfigId)211 std::vector<AudioDevice> Module::findConnectedDevices(int32_t portConfigId) {
212 std::vector<AudioDevice> result;
213 auto& ports = getConfig().ports;
214 auto portIds = portIdsFromPortConfigIds(findConnectedPortConfigIds(portConfigId));
215 for (auto it = portIds.begin(); it != portIds.end(); ++it) {
216 auto portIt = findById<AudioPort>(ports, *it);
217 if (portIt != ports.end() && portIt->ext.getTag() == AudioPortExt::Tag::device) {
218 result.push_back(portIt->ext.template get<AudioPortExt::Tag::device>().device);
219 }
220 }
221 return result;
222 }
223
findConnectedPortConfigIds(int32_t portConfigId)224 std::set<int32_t> Module::findConnectedPortConfigIds(int32_t portConfigId) {
225 std::set<int32_t> result;
226 auto patchIdsRange = mPatches.equal_range(portConfigId);
227 auto& patches = getConfig().patches;
228 for (auto it = patchIdsRange.first; it != patchIdsRange.second; ++it) {
229 auto patchIt = findById<AudioPatch>(patches, it->second);
230 if (patchIt == patches.end()) {
231 LOG(FATAL) << __func__ << ": patch with id " << it->second << " taken from mPatches "
232 << "not found in the configuration";
233 }
234 if (std::find(patchIt->sourcePortConfigIds.begin(), patchIt->sourcePortConfigIds.end(),
235 portConfigId) != patchIt->sourcePortConfigIds.end()) {
236 result.insert(patchIt->sinkPortConfigIds.begin(), patchIt->sinkPortConfigIds.end());
237 } else {
238 result.insert(patchIt->sourcePortConfigIds.begin(), patchIt->sourcePortConfigIds.end());
239 }
240 }
241 return result;
242 }
243
findPortIdForNewStream(int32_t in_portConfigId,AudioPort ** port)244 ndk::ScopedAStatus Module::findPortIdForNewStream(int32_t in_portConfigId, AudioPort** port) {
245 auto& configs = getConfig().portConfigs;
246 auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId);
247 if (portConfigIt == configs.end()) {
248 LOG(ERROR) << __func__ << ": existing port config id " << in_portConfigId << " not found";
249 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
250 }
251 const int32_t portId = portConfigIt->portId;
252 // In our implementation, configs of mix ports always have unique IDs.
253 CHECK(portId != in_portConfigId);
254 auto& ports = getConfig().ports;
255 auto portIt = findById<AudioPort>(ports, portId);
256 if (portIt == ports.end()) {
257 LOG(ERROR) << __func__ << ": port id " << portId << " used by port config id "
258 << in_portConfigId << " not found";
259 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
260 }
261 if (mStreams.count(in_portConfigId) != 0) {
262 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
263 << " already has a stream opened on it";
264 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
265 }
266 if (portIt->ext.getTag() != AudioPortExt::Tag::mix) {
267 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
268 << " does not correspond to a mix port";
269 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
270 }
271 const size_t maxOpenStreamCount = portIt->ext.get<AudioPortExt::Tag::mix>().maxOpenStreamCount;
272 if (maxOpenStreamCount != 0 && mStreams.count(portId) >= maxOpenStreamCount) {
273 LOG(ERROR) << __func__ << ": port id " << portId
274 << " has already reached maximum allowed opened stream count: "
275 << maxOpenStreamCount;
276 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
277 }
278 *port = &(*portIt);
279 return ndk::ScopedAStatus::ok();
280 }
281
282 template <typename C>
portIdsFromPortConfigIds(C portConfigIds)283 std::set<int32_t> Module::portIdsFromPortConfigIds(C portConfigIds) {
284 std::set<int32_t> result;
285 auto& portConfigs = getConfig().portConfigs;
286 for (auto it = portConfigIds.begin(); it != portConfigIds.end(); ++it) {
287 auto portConfigIt = findById<AudioPortConfig>(portConfigs, *it);
288 if (portConfigIt != portConfigs.end()) {
289 result.insert(portConfigIt->portId);
290 }
291 }
292 return result;
293 }
294
initializeConfig()295 std::unique_ptr<internal::Configuration> Module::initializeConfig() {
296 std::unique_ptr<internal::Configuration> config;
297 switch (getType()) {
298 case Type::DEFAULT:
299 config = std::move(internal::getPrimaryConfiguration());
300 break;
301 case Type::R_SUBMIX:
302 config = std::move(internal::getRSubmixConfiguration());
303 break;
304 case Type::STUB:
305 config = std::move(internal::getStubConfiguration());
306 break;
307 case Type::USB:
308 config = std::move(internal::getUsbConfiguration());
309 break;
310 case Type::BLUETOOTH:
311 config = std::move(internal::getBluetoothConfiguration());
312 break;
313 }
314 return config;
315 }
316
getConfig()317 internal::Configuration& Module::getConfig() {
318 if (!mConfig) {
319 mConfig = std::move(initializeConfig());
320 }
321 return *mConfig;
322 }
323
registerPatch(const AudioPatch & patch)324 void Module::registerPatch(const AudioPatch& patch) {
325 auto& configs = getConfig().portConfigs;
326 auto do_insert = [&](const std::vector<int32_t>& portConfigIds) {
327 for (auto portConfigId : portConfigIds) {
328 auto configIt = findById<AudioPortConfig>(configs, portConfigId);
329 if (configIt != configs.end()) {
330 mPatches.insert(std::pair{portConfigId, patch.id});
331 if (configIt->portId != portConfigId) {
332 mPatches.insert(std::pair{configIt->portId, patch.id});
333 }
334 }
335 };
336 };
337 do_insert(patch.sourcePortConfigIds);
338 do_insert(patch.sinkPortConfigIds);
339 }
340
updateStreamsConnectedState(const AudioPatch & oldPatch,const AudioPatch & newPatch)341 ndk::ScopedAStatus Module::updateStreamsConnectedState(const AudioPatch& oldPatch,
342 const AudioPatch& newPatch) {
343 // Streams from the old patch need to be disconnected, streams from the new
344 // patch need to be connected. If the stream belongs to both patches, no need
345 // to update it.
346 auto maybeFailure = ndk::ScopedAStatus::ok();
347 std::set<int32_t> idsToDisconnect, idsToConnect, idsToDisconnectOnFailure;
348 idsToDisconnect.insert(oldPatch.sourcePortConfigIds.begin(),
349 oldPatch.sourcePortConfigIds.end());
350 idsToDisconnect.insert(oldPatch.sinkPortConfigIds.begin(), oldPatch.sinkPortConfigIds.end());
351 idsToConnect.insert(newPatch.sourcePortConfigIds.begin(), newPatch.sourcePortConfigIds.end());
352 idsToConnect.insert(newPatch.sinkPortConfigIds.begin(), newPatch.sinkPortConfigIds.end());
353 std::for_each(idsToDisconnect.begin(), idsToDisconnect.end(), [&](const auto& portConfigId) {
354 if (idsToConnect.count(portConfigId) == 0 && mStreams.count(portConfigId) != 0) {
355 if (auto status = mStreams.setStreamConnectedDevices(portConfigId, {}); status.isOk()) {
356 LOG(DEBUG) << "updateStreamsConnectedState: The stream on port config id "
357 << portConfigId << " has been disconnected";
358 } else {
359 // Disconnection is tricky to roll back, just register a failure.
360 maybeFailure = std::move(status);
361 }
362 }
363 });
364 if (!maybeFailure.isOk()) return maybeFailure;
365 std::for_each(idsToConnect.begin(), idsToConnect.end(), [&](const auto& portConfigId) {
366 if (idsToDisconnect.count(portConfigId) == 0 && mStreams.count(portConfigId) != 0) {
367 const auto connectedDevices = findConnectedDevices(portConfigId);
368 if (connectedDevices.empty()) {
369 // This is important as workers use the vector size to derive the connection status.
370 LOG(FATAL) << "updateStreamsConnectedState: No connected devices found for port "
371 "config id "
372 << portConfigId;
373 }
374 if (auto status = mStreams.setStreamConnectedDevices(portConfigId, connectedDevices);
375 status.isOk()) {
376 LOG(DEBUG) << "updateStreamsConnectedState: The stream on port config id "
377 << portConfigId << " has been connected to: "
378 << ::android::internal::ToString(connectedDevices);
379 } else {
380 maybeFailure = std::move(status);
381 idsToDisconnectOnFailure.insert(portConfigId);
382 }
383 }
384 });
385 if (!maybeFailure.isOk()) {
386 LOG(WARNING) << __func__ << ": Due to a failure, disconnecting streams on port config ids "
387 << ::android::internal::ToString(idsToDisconnectOnFailure);
388 std::for_each(idsToDisconnectOnFailure.begin(), idsToDisconnectOnFailure.end(),
389 [&](const auto& portConfigId) {
390 auto status = mStreams.setStreamConnectedDevices(portConfigId, {});
391 (void)status.isOk(); // Can't do much about a failure here.
392 });
393 return maybeFailure;
394 }
395 return ndk::ScopedAStatus::ok();
396 }
397
setModuleDebug(const::aidl::android::hardware::audio::core::ModuleDebug & in_debug)398 ndk::ScopedAStatus Module::setModuleDebug(
399 const ::aidl::android::hardware::audio::core::ModuleDebug& in_debug) {
400 LOG(DEBUG) << __func__ << ": " << mType << ": old flags:" << mDebug.toString()
401 << ", new flags: " << in_debug.toString();
402 if (mDebug.simulateDeviceConnections != in_debug.simulateDeviceConnections &&
403 !mConnectedDevicePorts.empty()) {
404 LOG(ERROR) << __func__ << ": " << mType
405 << ": attempting to change device connections simulation while having external "
406 << "devices connected";
407 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
408 }
409 if (in_debug.streamTransientStateDelayMs < 0) {
410 LOG(ERROR) << __func__ << ": " << mType << ": streamTransientStateDelayMs is negative: "
411 << in_debug.streamTransientStateDelayMs;
412 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
413 }
414 mDebug = in_debug;
415 return ndk::ScopedAStatus::ok();
416 }
417
getTelephony(std::shared_ptr<ITelephony> * _aidl_return)418 ndk::ScopedAStatus Module::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) {
419 *_aidl_return = nullptr;
420 LOG(DEBUG) << __func__ << ": returning null";
421 return ndk::ScopedAStatus::ok();
422 }
423
getBluetooth(std::shared_ptr<IBluetooth> * _aidl_return)424 ndk::ScopedAStatus Module::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) {
425 *_aidl_return = nullptr;
426 LOG(DEBUG) << __func__ << ": returning null";
427 return ndk::ScopedAStatus::ok();
428 }
429
getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp> * _aidl_return)430 ndk::ScopedAStatus Module::getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp>* _aidl_return) {
431 *_aidl_return = nullptr;
432 LOG(DEBUG) << __func__ << ": returning null";
433 return ndk::ScopedAStatus::ok();
434 }
435
getBluetoothLe(std::shared_ptr<IBluetoothLe> * _aidl_return)436 ndk::ScopedAStatus Module::getBluetoothLe(std::shared_ptr<IBluetoothLe>* _aidl_return) {
437 *_aidl_return = nullptr;
438 LOG(DEBUG) << __func__ << ": returning null";
439 return ndk::ScopedAStatus::ok();
440 }
441
connectExternalDevice(const AudioPort & in_templateIdAndAdditionalData,AudioPort * _aidl_return)442 ndk::ScopedAStatus Module::connectExternalDevice(const AudioPort& in_templateIdAndAdditionalData,
443 AudioPort* _aidl_return) {
444 const int32_t templateId = in_templateIdAndAdditionalData.id;
445 auto& ports = getConfig().ports;
446 AudioPort connectedPort;
447 { // Scope the template port so that we don't accidentally modify it.
448 auto templateIt = findById<AudioPort>(ports, templateId);
449 if (templateIt == ports.end()) {
450 LOG(ERROR) << __func__ << ": port id " << templateId << " not found";
451 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
452 }
453 if (templateIt->ext.getTag() != AudioPortExt::Tag::device) {
454 LOG(ERROR) << __func__ << ": port id " << templateId << " is not a device port";
455 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
456 }
457 auto& templateDevicePort = templateIt->ext.get<AudioPortExt::Tag::device>();
458 if (templateDevicePort.device.type.connection.empty()) {
459 LOG(ERROR) << __func__ << ": port id " << templateId << " is permanently attached";
460 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
461 }
462 if (mConnectedDevicePorts.find(templateId) != mConnectedDevicePorts.end()) {
463 LOG(ERROR) << __func__ << ": port id " << templateId << " is a connected device port";
464 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
465 }
466 // Postpone id allocation until we ensure that there are no client errors.
467 connectedPort = *templateIt;
468 connectedPort.extraAudioDescriptors = in_templateIdAndAdditionalData.extraAudioDescriptors;
469 const auto& inputDevicePort =
470 in_templateIdAndAdditionalData.ext.get<AudioPortExt::Tag::device>();
471 auto& connectedDevicePort = connectedPort.ext.get<AudioPortExt::Tag::device>();
472 connectedDevicePort.device.address = inputDevicePort.device.address;
473 LOG(DEBUG) << __func__ << ": device port " << connectedPort.id << " device set to "
474 << connectedDevicePort.device.toString();
475 // Check if there is already a connected port with for the same external device.
476 for (auto connectedPortPair : mConnectedDevicePorts) {
477 auto connectedPortIt = findById<AudioPort>(ports, connectedPortPair.first);
478 if (connectedPortIt->ext.get<AudioPortExt::Tag::device>().device ==
479 connectedDevicePort.device) {
480 LOG(ERROR) << __func__ << ": device " << connectedDevicePort.device.toString()
481 << " is already connected at the device port id "
482 << connectedPortPair.first;
483 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
484 }
485 }
486 }
487
488 if (connectedPort.profiles.empty()) {
489 if (!mDebug.simulateDeviceConnections) {
490 RETURN_STATUS_IF_ERROR(populateConnectedDevicePort(&connectedPort));
491 } else {
492 auto& connectedProfiles = getConfig().connectedProfiles;
493 if (auto connectedProfilesIt = connectedProfiles.find(templateId);
494 connectedProfilesIt != connectedProfiles.end()) {
495 connectedPort.profiles = connectedProfilesIt->second;
496 }
497 }
498 if (connectedPort.profiles.empty()) {
499 LOG(ERROR) << __func__
500 << ": profiles of a connected port still empty after connecting external "
501 "device "
502 << connectedPort.toString();
503 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
504 }
505 }
506
507 for (auto profile : connectedPort.profiles) {
508 if (profile.channelMasks.empty()) {
509 LOG(ERROR) << __func__ << ": the profile " << profile.name << " has no channel masks";
510 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
511 }
512 if (profile.sampleRates.empty()) {
513 LOG(ERROR) << __func__ << ": the profile " << profile.name << " has no sample rates";
514 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
515 }
516 }
517
518 connectedPort.id = ++getConfig().nextPortId;
519 auto [connectedPortsIt, _] =
520 mConnectedDevicePorts.insert(std::pair(connectedPort.id, std::vector<int32_t>()));
521 LOG(DEBUG) << __func__ << ": template port " << templateId << " external device connected, "
522 << "connected port ID " << connectedPort.id;
523 ports.push_back(connectedPort);
524 onExternalDeviceConnectionChanged(connectedPort, true /*connected*/);
525
526 std::vector<int32_t> routablePortIds;
527 std::vector<AudioRoute> newRoutes;
528 auto& routes = getConfig().routes;
529 for (auto& r : routes) {
530 if (r.sinkPortId == templateId) {
531 AudioRoute newRoute;
532 newRoute.sourcePortIds = r.sourcePortIds;
533 newRoute.sinkPortId = connectedPort.id;
534 newRoute.isExclusive = r.isExclusive;
535 newRoutes.push_back(std::move(newRoute));
536 routablePortIds.insert(routablePortIds.end(), r.sourcePortIds.begin(),
537 r.sourcePortIds.end());
538 } else {
539 auto& srcs = r.sourcePortIds;
540 if (std::find(srcs.begin(), srcs.end(), templateId) != srcs.end()) {
541 srcs.push_back(connectedPort.id);
542 routablePortIds.push_back(r.sinkPortId);
543 }
544 }
545 }
546 routes.insert(routes.end(), newRoutes.begin(), newRoutes.end());
547
548 // Note: this is a simplistic approach assuming that a mix port can only be populated
549 // from a single device port. Implementing support for stuffing dynamic profiles with a superset
550 // of all profiles from all routable dynamic device ports would be more involved.
551 for (const auto mixPortId : routablePortIds) {
552 auto portsIt = findById<AudioPort>(ports, mixPortId);
553 if (portsIt != ports.end() && portsIt->profiles.empty()) {
554 portsIt->profiles = connectedPort.profiles;
555 connectedPortsIt->second.push_back(portsIt->id);
556 }
557 }
558 *_aidl_return = std::move(connectedPort);
559
560 return ndk::ScopedAStatus::ok();
561 }
562
disconnectExternalDevice(int32_t in_portId)563 ndk::ScopedAStatus Module::disconnectExternalDevice(int32_t in_portId) {
564 auto& ports = getConfig().ports;
565 auto portIt = findById<AudioPort>(ports, in_portId);
566 if (portIt == ports.end()) {
567 LOG(ERROR) << __func__ << ": port id " << in_portId << " not found";
568 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
569 }
570 if (portIt->ext.getTag() != AudioPortExt::Tag::device) {
571 LOG(ERROR) << __func__ << ": port id " << in_portId << " is not a device port";
572 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
573 }
574 auto connectedPortsIt = mConnectedDevicePorts.find(in_portId);
575 if (connectedPortsIt == mConnectedDevicePorts.end()) {
576 LOG(ERROR) << __func__ << ": port id " << in_portId << " is not a connected device port";
577 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
578 }
579 auto& configs = getConfig().portConfigs;
580 auto& initials = getConfig().initialConfigs;
581 auto configIt = std::find_if(configs.begin(), configs.end(), [&](const auto& config) {
582 if (config.portId == in_portId) {
583 // Check if the configuration was provided by the client.
584 const auto& initialIt = findById<AudioPortConfig>(initials, config.id);
585 return initialIt == initials.end() || config != *initialIt;
586 }
587 return false;
588 });
589 if (configIt != configs.end()) {
590 LOG(ERROR) << __func__ << ": port id " << in_portId << " has a non-default config with id "
591 << configIt->id;
592 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
593 }
594 onExternalDeviceConnectionChanged(*portIt, false /*connected*/);
595 ports.erase(portIt);
596 LOG(DEBUG) << __func__ << ": connected device port " << in_portId << " released";
597
598 auto& routes = getConfig().routes;
599 for (auto routesIt = routes.begin(); routesIt != routes.end();) {
600 if (routesIt->sinkPortId == in_portId) {
601 routesIt = routes.erase(routesIt);
602 } else {
603 // Note: the list of sourcePortIds can't become empty because there must
604 // be the id of the template port in the route.
605 erase_if(routesIt->sourcePortIds, [in_portId](auto src) { return src == in_portId; });
606 ++routesIt;
607 }
608 }
609
610 for (const auto mixPortId : connectedPortsIt->second) {
611 auto mixPortIt = findById<AudioPort>(ports, mixPortId);
612 if (mixPortIt != ports.end()) {
613 mixPortIt->profiles = {};
614 }
615 }
616 mConnectedDevicePorts.erase(connectedPortsIt);
617
618 return ndk::ScopedAStatus::ok();
619 }
620
getAudioPatches(std::vector<AudioPatch> * _aidl_return)621 ndk::ScopedAStatus Module::getAudioPatches(std::vector<AudioPatch>* _aidl_return) {
622 *_aidl_return = getConfig().patches;
623 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " patches";
624 return ndk::ScopedAStatus::ok();
625 }
626
getAudioPort(int32_t in_portId,AudioPort * _aidl_return)627 ndk::ScopedAStatus Module::getAudioPort(int32_t in_portId, AudioPort* _aidl_return) {
628 auto& ports = getConfig().ports;
629 auto portIt = findById<AudioPort>(ports, in_portId);
630 if (portIt != ports.end()) {
631 *_aidl_return = *portIt;
632 LOG(DEBUG) << __func__ << ": returning port by id " << in_portId;
633 return ndk::ScopedAStatus::ok();
634 }
635 LOG(ERROR) << __func__ << ": port id " << in_portId << " not found";
636 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
637 }
638
getAudioPortConfigs(std::vector<AudioPortConfig> * _aidl_return)639 ndk::ScopedAStatus Module::getAudioPortConfigs(std::vector<AudioPortConfig>* _aidl_return) {
640 *_aidl_return = getConfig().portConfigs;
641 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " port configs";
642 return ndk::ScopedAStatus::ok();
643 }
644
getAudioPorts(std::vector<AudioPort> * _aidl_return)645 ndk::ScopedAStatus Module::getAudioPorts(std::vector<AudioPort>* _aidl_return) {
646 *_aidl_return = getConfig().ports;
647 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " ports";
648 return ndk::ScopedAStatus::ok();
649 }
650
getAudioRoutes(std::vector<AudioRoute> * _aidl_return)651 ndk::ScopedAStatus Module::getAudioRoutes(std::vector<AudioRoute>* _aidl_return) {
652 *_aidl_return = getConfig().routes;
653 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " routes";
654 return ndk::ScopedAStatus::ok();
655 }
656
getAudioRoutesForAudioPort(int32_t in_portId,std::vector<AudioRoute> * _aidl_return)657 ndk::ScopedAStatus Module::getAudioRoutesForAudioPort(int32_t in_portId,
658 std::vector<AudioRoute>* _aidl_return) {
659 auto& ports = getConfig().ports;
660 if (auto portIt = findById<AudioPort>(ports, in_portId); portIt == ports.end()) {
661 LOG(ERROR) << __func__ << ": port id " << in_portId << " not found";
662 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
663 }
664 auto& routes = getConfig().routes;
665 std::copy_if(routes.begin(), routes.end(), std::back_inserter(*_aidl_return),
666 [&](const auto& r) {
667 const auto& srcs = r.sourcePortIds;
668 return r.sinkPortId == in_portId ||
669 std::find(srcs.begin(), srcs.end(), in_portId) != srcs.end();
670 });
671 return ndk::ScopedAStatus::ok();
672 }
673
openInputStream(const OpenInputStreamArguments & in_args,OpenInputStreamReturn * _aidl_return)674 ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_args,
675 OpenInputStreamReturn* _aidl_return) {
676 LOG(DEBUG) << __func__ << ": port config id " << in_args.portConfigId << ", buffer size "
677 << in_args.bufferSizeFrames << " frames";
678 AudioPort* port = nullptr;
679 RETURN_STATUS_IF_ERROR(findPortIdForNewStream(in_args.portConfigId, &port));
680 if (port->flags.getTag() != AudioIoFlags::Tag::input) {
681 LOG(ERROR) << __func__ << ": port config id " << in_args.portConfigId
682 << " does not correspond to an input mix port";
683 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
684 }
685 StreamContext context;
686 RETURN_STATUS_IF_ERROR(createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames,
687 nullptr, nullptr, &context));
688 context.fillDescriptor(&_aidl_return->desc);
689 std::shared_ptr<StreamIn> stream;
690 RETURN_STATUS_IF_ERROR(createInputStream(std::move(context), in_args.sinkMetadata,
691 mConfig->microphones, &stream));
692 StreamWrapper streamWrapper(stream);
693 if (auto patchIt = mPatches.find(in_args.portConfigId); patchIt != mPatches.end()) {
694 RETURN_STATUS_IF_ERROR(
695 streamWrapper.setConnectedDevices(findConnectedDevices(in_args.portConfigId)));
696 }
697 AIBinder_setMinSchedulerPolicy(streamWrapper.getBinder().get(), SCHED_NORMAL,
698 ANDROID_PRIORITY_AUDIO);
699 mStreams.insert(port->id, in_args.portConfigId, std::move(streamWrapper));
700 _aidl_return->stream = std::move(stream);
701 return ndk::ScopedAStatus::ok();
702 }
703
openOutputStream(const OpenOutputStreamArguments & in_args,OpenOutputStreamReturn * _aidl_return)704 ndk::ScopedAStatus Module::openOutputStream(const OpenOutputStreamArguments& in_args,
705 OpenOutputStreamReturn* _aidl_return) {
706 LOG(DEBUG) << __func__ << ": port config id " << in_args.portConfigId << ", has offload info? "
707 << (in_args.offloadInfo.has_value()) << ", buffer size " << in_args.bufferSizeFrames
708 << " frames";
709 AudioPort* port = nullptr;
710 RETURN_STATUS_IF_ERROR(findPortIdForNewStream(in_args.portConfigId, &port));
711 if (port->flags.getTag() != AudioIoFlags::Tag::output) {
712 LOG(ERROR) << __func__ << ": port config id " << in_args.portConfigId
713 << " does not correspond to an output mix port";
714 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
715 }
716 const bool isOffload = isBitPositionFlagSet(port->flags.get<AudioIoFlags::Tag::output>(),
717 AudioOutputFlags::COMPRESS_OFFLOAD);
718 if (isOffload && !in_args.offloadInfo.has_value()) {
719 LOG(ERROR) << __func__ << ": port id " << port->id
720 << " has COMPRESS_OFFLOAD flag set, requires offload info";
721 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
722 }
723 const bool isNonBlocking = isBitPositionFlagSet(port->flags.get<AudioIoFlags::Tag::output>(),
724 AudioOutputFlags::NON_BLOCKING);
725 if (isNonBlocking && in_args.callback == nullptr) {
726 LOG(ERROR) << __func__ << ": port id " << port->id
727 << " has NON_BLOCKING flag set, requires async callback";
728 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
729 }
730 StreamContext context;
731 RETURN_STATUS_IF_ERROR(createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames,
732 isNonBlocking ? in_args.callback : nullptr,
733 in_args.eventCallback, &context));
734 context.fillDescriptor(&_aidl_return->desc);
735 std::shared_ptr<StreamOut> stream;
736 RETURN_STATUS_IF_ERROR(createOutputStream(std::move(context), in_args.sourceMetadata,
737 in_args.offloadInfo, &stream));
738 StreamWrapper streamWrapper(stream);
739 if (auto patchIt = mPatches.find(in_args.portConfigId); patchIt != mPatches.end()) {
740 RETURN_STATUS_IF_ERROR(
741 streamWrapper.setConnectedDevices(findConnectedDevices(in_args.portConfigId)));
742 }
743 AIBinder_setMinSchedulerPolicy(streamWrapper.getBinder().get(), SCHED_NORMAL,
744 ANDROID_PRIORITY_AUDIO);
745 mStreams.insert(port->id, in_args.portConfigId, std::move(streamWrapper));
746 _aidl_return->stream = std::move(stream);
747 return ndk::ScopedAStatus::ok();
748 }
749
getSupportedPlaybackRateFactors(SupportedPlaybackRateFactors * _aidl_return)750 ndk::ScopedAStatus Module::getSupportedPlaybackRateFactors(
751 SupportedPlaybackRateFactors* _aidl_return) {
752 LOG(DEBUG) << __func__;
753 (void)_aidl_return;
754 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
755 }
756
setAudioPatch(const AudioPatch & in_requested,AudioPatch * _aidl_return)757 ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPatch* _aidl_return) {
758 LOG(DEBUG) << __func__ << ": requested patch " << in_requested.toString();
759 if (in_requested.sourcePortConfigIds.empty()) {
760 LOG(ERROR) << __func__ << ": requested patch has empty sources list";
761 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
762 }
763 if (!all_unique<int32_t>(in_requested.sourcePortConfigIds)) {
764 LOG(ERROR) << __func__ << ": requested patch has duplicate ids in the sources list";
765 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
766 }
767 if (in_requested.sinkPortConfigIds.empty()) {
768 LOG(ERROR) << __func__ << ": requested patch has empty sinks list";
769 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
770 }
771 if (!all_unique<int32_t>(in_requested.sinkPortConfigIds)) {
772 LOG(ERROR) << __func__ << ": requested patch has duplicate ids in the sinks list";
773 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
774 }
775
776 auto& configs = getConfig().portConfigs;
777 std::vector<int32_t> missingIds;
778 auto sources =
779 selectByIds<AudioPortConfig>(configs, in_requested.sourcePortConfigIds, &missingIds);
780 if (!missingIds.empty()) {
781 LOG(ERROR) << __func__ << ": following source port config ids not found: "
782 << ::android::internal::ToString(missingIds);
783 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
784 }
785 auto sinks = selectByIds<AudioPortConfig>(configs, in_requested.sinkPortConfigIds, &missingIds);
786 if (!missingIds.empty()) {
787 LOG(ERROR) << __func__ << ": following sink port config ids not found: "
788 << ::android::internal::ToString(missingIds);
789 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
790 }
791 // bool indicates whether a non-exclusive route is available.
792 // If only an exclusive route is available, that means the patch can not be
793 // established if there is any other patch which currently uses the sink port.
794 std::map<int32_t, bool> allowedSinkPorts;
795 auto& routes = getConfig().routes;
796 for (auto src : sources) {
797 for (const auto& r : routes) {
798 const auto& srcs = r.sourcePortIds;
799 if (std::find(srcs.begin(), srcs.end(), src->portId) != srcs.end()) {
800 if (!allowedSinkPorts[r.sinkPortId]) { // prefer non-exclusive
801 allowedSinkPorts[r.sinkPortId] = !r.isExclusive;
802 }
803 }
804 }
805 }
806 for (auto sink : sinks) {
807 if (allowedSinkPorts.count(sink->portId) == 0) {
808 LOG(ERROR) << __func__ << ": there is no route to the sink port id " << sink->portId;
809 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
810 }
811 }
812 RETURN_STATUS_IF_ERROR(checkAudioPatchEndpointsMatch(sources, sinks));
813
814 auto& patches = getConfig().patches;
815 auto existing = patches.end();
816 std::optional<decltype(mPatches)> patchesBackup;
817 if (in_requested.id != 0) {
818 existing = findById<AudioPatch>(patches, in_requested.id);
819 if (existing != patches.end()) {
820 patchesBackup = mPatches;
821 cleanUpPatch(existing->id);
822 } else {
823 LOG(ERROR) << __func__ << ": not found existing patch id " << in_requested.id;
824 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
825 }
826 }
827 // Validate the requested patch.
828 for (const auto& [sinkPortId, nonExclusive] : allowedSinkPorts) {
829 if (!nonExclusive && mPatches.count(sinkPortId) != 0) {
830 LOG(ERROR) << __func__ << ": sink port id " << sinkPortId
831 << "is exclusive and is already used by some other patch";
832 if (patchesBackup.has_value()) {
833 mPatches = std::move(*patchesBackup);
834 }
835 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
836 }
837 }
838 *_aidl_return = in_requested;
839 _aidl_return->minimumStreamBufferSizeFrames = kMinimumStreamBufferSizeFrames;
840 _aidl_return->latenciesMs.clear();
841 _aidl_return->latenciesMs.insert(_aidl_return->latenciesMs.end(),
842 _aidl_return->sinkPortConfigIds.size(), kLatencyMs);
843 AudioPatch oldPatch{};
844 if (existing == patches.end()) {
845 _aidl_return->id = getConfig().nextPatchId++;
846 patches.push_back(*_aidl_return);
847 } else {
848 oldPatch = *existing;
849 }
850 patchesBackup = mPatches;
851 registerPatch(*_aidl_return);
852 if (auto status = updateStreamsConnectedState(oldPatch, *_aidl_return); !status.isOk()) {
853 mPatches = std::move(*patchesBackup);
854 if (existing == patches.end()) {
855 patches.pop_back();
856 } else {
857 *existing = oldPatch;
858 }
859 return status;
860 }
861
862 LOG(DEBUG) << __func__ << ": " << (oldPatch.id == 0 ? "created" : "updated") << " patch "
863 << _aidl_return->toString();
864 return ndk::ScopedAStatus::ok();
865 }
866
setAudioPortConfig(const AudioPortConfig & in_requested,AudioPortConfig * out_suggested,bool * _aidl_return)867 ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requested,
868 AudioPortConfig* out_suggested, bool* _aidl_return) {
869 LOG(DEBUG) << __func__ << ": requested " << in_requested.toString();
870 auto& configs = getConfig().portConfigs;
871 auto existing = configs.end();
872 if (in_requested.id != 0) {
873 if (existing = findById<AudioPortConfig>(configs, in_requested.id);
874 existing == configs.end()) {
875 LOG(ERROR) << __func__ << ": existing port config id " << in_requested.id
876 << " not found";
877 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
878 }
879 }
880
881 const int portId = existing != configs.end() ? existing->portId : in_requested.portId;
882 if (portId == 0) {
883 LOG(ERROR) << __func__ << ": input port config does not specify portId";
884 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
885 }
886 auto& ports = getConfig().ports;
887 auto portIt = findById<AudioPort>(ports, portId);
888 if (portIt == ports.end()) {
889 LOG(ERROR) << __func__ << ": input port config points to non-existent portId " << portId;
890 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
891 }
892 if (existing != configs.end()) {
893 *out_suggested = *existing;
894 } else {
895 AudioPortConfig newConfig;
896 if (generateDefaultPortConfig(*portIt, &newConfig)) {
897 *out_suggested = newConfig;
898 } else {
899 LOG(ERROR) << __func__ << ": unable generate a default config for port " << portId;
900 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
901 }
902 }
903 // From this moment, 'out_suggested' is either an existing port config,
904 // or a new generated config. Now attempt to update it according to the specified
905 // fields of 'in_requested'.
906
907 bool requestedIsValid = true, requestedIsFullySpecified = true;
908
909 AudioIoFlags portFlags = portIt->flags;
910 if (in_requested.flags.has_value()) {
911 if (in_requested.flags.value() != portFlags) {
912 LOG(WARNING) << __func__ << ": requested flags "
913 << in_requested.flags.value().toString() << " do not match port's "
914 << portId << " flags " << portFlags.toString();
915 requestedIsValid = false;
916 }
917 } else {
918 requestedIsFullySpecified = false;
919 }
920
921 AudioProfile portProfile;
922 if (in_requested.format.has_value()) {
923 const auto& format = in_requested.format.value();
924 if (findAudioProfile(*portIt, format, &portProfile)) {
925 out_suggested->format = format;
926 } else {
927 LOG(WARNING) << __func__ << ": requested format " << format.toString()
928 << " is not found in port's " << portId << " profiles";
929 requestedIsValid = false;
930 }
931 } else {
932 requestedIsFullySpecified = false;
933 }
934 if (!findAudioProfile(*portIt, out_suggested->format.value(), &portProfile)) {
935 LOG(ERROR) << __func__ << ": port " << portId << " does not support format "
936 << out_suggested->format.value().toString() << " anymore";
937 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
938 }
939
940 if (in_requested.channelMask.has_value()) {
941 const auto& channelMask = in_requested.channelMask.value();
942 if (find(portProfile.channelMasks.begin(), portProfile.channelMasks.end(), channelMask) !=
943 portProfile.channelMasks.end()) {
944 out_suggested->channelMask = channelMask;
945 } else {
946 LOG(WARNING) << __func__ << ": requested channel mask " << channelMask.toString()
947 << " is not supported for the format " << portProfile.format.toString()
948 << " by the port " << portId;
949 requestedIsValid = false;
950 }
951 } else {
952 requestedIsFullySpecified = false;
953 }
954
955 if (in_requested.sampleRate.has_value()) {
956 const auto& sampleRate = in_requested.sampleRate.value();
957 if (find(portProfile.sampleRates.begin(), portProfile.sampleRates.end(),
958 sampleRate.value) != portProfile.sampleRates.end()) {
959 out_suggested->sampleRate = sampleRate;
960 } else {
961 LOG(WARNING) << __func__ << ": requested sample rate " << sampleRate.value
962 << " is not supported for the format " << portProfile.format.toString()
963 << " by the port " << portId;
964 requestedIsValid = false;
965 }
966 } else {
967 requestedIsFullySpecified = false;
968 }
969
970 if (in_requested.gain.has_value()) {
971 // Let's pretend that gain can always be applied.
972 out_suggested->gain = in_requested.gain.value();
973 }
974
975 if (in_requested.ext.getTag() != AudioPortExt::Tag::unspecified) {
976 if (in_requested.ext.getTag() == out_suggested->ext.getTag()) {
977 if (out_suggested->ext.getTag() == AudioPortExt::Tag::mix) {
978 // 'AudioMixPortExt.handle' is set by the client, copy from in_requested
979 out_suggested->ext.get<AudioPortExt::Tag::mix>().handle =
980 in_requested.ext.get<AudioPortExt::Tag::mix>().handle;
981 }
982 } else {
983 LOG(WARNING) << __func__ << ": requested ext tag "
984 << toString(in_requested.ext.getTag()) << " do not match port's tag "
985 << toString(out_suggested->ext.getTag());
986 requestedIsValid = false;
987 }
988 }
989
990 if (existing == configs.end() && requestedIsValid && requestedIsFullySpecified) {
991 out_suggested->id = getConfig().nextPortId++;
992 configs.push_back(*out_suggested);
993 *_aidl_return = true;
994 LOG(DEBUG) << __func__ << ": created new port config " << out_suggested->toString();
995 } else if (existing != configs.end() && requestedIsValid) {
996 *existing = *out_suggested;
997 *_aidl_return = true;
998 LOG(DEBUG) << __func__ << ": updated port config " << out_suggested->toString();
999 } else {
1000 LOG(DEBUG) << __func__ << ": not applied; existing config ? " << (existing != configs.end())
1001 << "; requested is valid? " << requestedIsValid << ", fully specified? "
1002 << requestedIsFullySpecified;
1003 *_aidl_return = false;
1004 }
1005 return ndk::ScopedAStatus::ok();
1006 }
1007
resetAudioPatch(int32_t in_patchId)1008 ndk::ScopedAStatus Module::resetAudioPatch(int32_t in_patchId) {
1009 auto& patches = getConfig().patches;
1010 auto patchIt = findById<AudioPatch>(patches, in_patchId);
1011 if (patchIt != patches.end()) {
1012 auto patchesBackup = mPatches;
1013 cleanUpPatch(patchIt->id);
1014 if (auto status = updateStreamsConnectedState(*patchIt, AudioPatch{}); !status.isOk()) {
1015 mPatches = std::move(patchesBackup);
1016 return status;
1017 }
1018 patches.erase(patchIt);
1019 LOG(DEBUG) << __func__ << ": erased patch " << in_patchId;
1020 return ndk::ScopedAStatus::ok();
1021 }
1022 LOG(ERROR) << __func__ << ": patch id " << in_patchId << " not found";
1023 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1024 }
1025
resetAudioPortConfig(int32_t in_portConfigId)1026 ndk::ScopedAStatus Module::resetAudioPortConfig(int32_t in_portConfigId) {
1027 auto& configs = getConfig().portConfigs;
1028 auto configIt = findById<AudioPortConfig>(configs, in_portConfigId);
1029 if (configIt != configs.end()) {
1030 if (mStreams.count(in_portConfigId) != 0) {
1031 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
1032 << " has a stream opened on it";
1033 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
1034 }
1035 auto patchIt = mPatches.find(in_portConfigId);
1036 if (patchIt != mPatches.end()) {
1037 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
1038 << " is used by the patch with id " << patchIt->second;
1039 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
1040 }
1041 auto& initials = getConfig().initialConfigs;
1042 auto initialIt = findById<AudioPortConfig>(initials, in_portConfigId);
1043 if (initialIt == initials.end()) {
1044 configs.erase(configIt);
1045 LOG(DEBUG) << __func__ << ": erased port config " << in_portConfigId;
1046 } else if (*configIt != *initialIt) {
1047 *configIt = *initialIt;
1048 LOG(DEBUG) << __func__ << ": reset port config " << in_portConfigId;
1049 }
1050 return ndk::ScopedAStatus::ok();
1051 }
1052 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId << " not found";
1053 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1054 }
1055
getMasterMute(bool * _aidl_return)1056 ndk::ScopedAStatus Module::getMasterMute(bool* _aidl_return) {
1057 *_aidl_return = mMasterMute;
1058 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1059 return ndk::ScopedAStatus::ok();
1060 }
1061
setMasterMute(bool in_mute)1062 ndk::ScopedAStatus Module::setMasterMute(bool in_mute) {
1063 LOG(DEBUG) << __func__ << ": " << in_mute;
1064 auto result = mDebug.simulateDeviceConnections ? ndk::ScopedAStatus::ok()
1065 : onMasterMuteChanged(in_mute);
1066 if (result.isOk()) {
1067 mMasterMute = in_mute;
1068 } else {
1069 LOG(ERROR) << __func__ << ": failed calling onMasterMuteChanged(" << in_mute
1070 << "), error=" << result;
1071 // Reset master mute if it failed.
1072 onMasterMuteChanged(mMasterMute);
1073 }
1074 return std::move(result);
1075 }
1076
getMasterVolume(float * _aidl_return)1077 ndk::ScopedAStatus Module::getMasterVolume(float* _aidl_return) {
1078 *_aidl_return = mMasterVolume;
1079 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1080 return ndk::ScopedAStatus::ok();
1081 }
1082
setMasterVolume(float in_volume)1083 ndk::ScopedAStatus Module::setMasterVolume(float in_volume) {
1084 LOG(DEBUG) << __func__ << ": " << in_volume;
1085 if (in_volume >= 0.0f && in_volume <= 1.0f) {
1086 auto result = mDebug.simulateDeviceConnections ? ndk::ScopedAStatus::ok()
1087 : onMasterVolumeChanged(in_volume);
1088 if (result.isOk()) {
1089 mMasterVolume = in_volume;
1090 } else {
1091 // Reset master volume if it failed.
1092 LOG(ERROR) << __func__ << ": failed calling onMasterVolumeChanged(" << in_volume
1093 << "), error=" << result;
1094 onMasterVolumeChanged(mMasterVolume);
1095 }
1096 return std::move(result);
1097 }
1098 LOG(ERROR) << __func__ << ": invalid master volume value: " << in_volume;
1099 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1100 }
1101
getMicMute(bool * _aidl_return)1102 ndk::ScopedAStatus Module::getMicMute(bool* _aidl_return) {
1103 *_aidl_return = mMicMute;
1104 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1105 return ndk::ScopedAStatus::ok();
1106 }
1107
setMicMute(bool in_mute)1108 ndk::ScopedAStatus Module::setMicMute(bool in_mute) {
1109 LOG(DEBUG) << __func__ << ": " << in_mute;
1110 mMicMute = in_mute;
1111 return ndk::ScopedAStatus::ok();
1112 }
1113
getMicrophones(std::vector<MicrophoneInfo> * _aidl_return)1114 ndk::ScopedAStatus Module::getMicrophones(std::vector<MicrophoneInfo>* _aidl_return) {
1115 *_aidl_return = getConfig().microphones;
1116 LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return);
1117 return ndk::ScopedAStatus::ok();
1118 }
1119
updateAudioMode(AudioMode in_mode)1120 ndk::ScopedAStatus Module::updateAudioMode(AudioMode in_mode) {
1121 if (!isValidAudioMode(in_mode)) {
1122 LOG(ERROR) << __func__ << ": invalid mode " << toString(in_mode);
1123 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1124 }
1125 // No checks for supported audio modes here, it's an informative notification.
1126 LOG(DEBUG) << __func__ << ": " << toString(in_mode);
1127 return ndk::ScopedAStatus::ok();
1128 }
1129
updateScreenRotation(ScreenRotation in_rotation)1130 ndk::ScopedAStatus Module::updateScreenRotation(ScreenRotation in_rotation) {
1131 LOG(DEBUG) << __func__ << ": " << toString(in_rotation);
1132 return ndk::ScopedAStatus::ok();
1133 }
1134
updateScreenState(bool in_isTurnedOn)1135 ndk::ScopedAStatus Module::updateScreenState(bool in_isTurnedOn) {
1136 LOG(DEBUG) << __func__ << ": " << in_isTurnedOn;
1137 return ndk::ScopedAStatus::ok();
1138 }
1139
getSoundDose(std::shared_ptr<ISoundDose> * _aidl_return)1140 ndk::ScopedAStatus Module::getSoundDose(std::shared_ptr<ISoundDose>* _aidl_return) {
1141 if (!mSoundDose) {
1142 mSoundDose = ndk::SharedRefBase::make<sounddose::SoundDose>();
1143 }
1144 *_aidl_return = mSoundDose.getInstance();
1145 LOG(DEBUG) << __func__ << ": returning instance of ISoundDose: " << _aidl_return->get();
1146 return ndk::ScopedAStatus::ok();
1147 }
1148
generateHwAvSyncId(int32_t * _aidl_return)1149 ndk::ScopedAStatus Module::generateHwAvSyncId(int32_t* _aidl_return) {
1150 LOG(DEBUG) << __func__;
1151 (void)_aidl_return;
1152 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1153 }
1154
1155 const std::string Module::VendorDebug::kForceTransientBurstName = "aosp.forceTransientBurst";
1156 const std::string Module::VendorDebug::kForceSynchronousDrainName = "aosp.forceSynchronousDrain";
1157
getVendorParameters(const std::vector<std::string> & in_ids,std::vector<VendorParameter> * _aidl_return)1158 ndk::ScopedAStatus Module::getVendorParameters(const std::vector<std::string>& in_ids,
1159 std::vector<VendorParameter>* _aidl_return) {
1160 LOG(DEBUG) << __func__ << ": id count: " << in_ids.size();
1161 bool allParametersKnown = true;
1162 for (const auto& id : in_ids) {
1163 if (id == VendorDebug::kForceTransientBurstName) {
1164 VendorParameter forceTransientBurst{.id = id};
1165 forceTransientBurst.ext.setParcelable(Boolean{mVendorDebug.forceTransientBurst});
1166 _aidl_return->push_back(std::move(forceTransientBurst));
1167 } else if (id == VendorDebug::kForceSynchronousDrainName) {
1168 VendorParameter forceSynchronousDrain{.id = id};
1169 forceSynchronousDrain.ext.setParcelable(Boolean{mVendorDebug.forceSynchronousDrain});
1170 _aidl_return->push_back(std::move(forceSynchronousDrain));
1171 } else {
1172 allParametersKnown = false;
1173 LOG(ERROR) << __func__ << ": unrecognized parameter \"" << id << "\"";
1174 }
1175 }
1176 if (allParametersKnown) return ndk::ScopedAStatus::ok();
1177 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1178 }
1179
1180 namespace {
1181
1182 template <typename W>
extractParameter(const VendorParameter & p,decltype(W::value) * v)1183 bool extractParameter(const VendorParameter& p, decltype(W::value)* v) {
1184 std::optional<W> value;
1185 binder_status_t result = p.ext.getParcelable(&value);
1186 if (result == STATUS_OK && value.has_value()) {
1187 *v = value.value().value;
1188 return true;
1189 }
1190 LOG(ERROR) << __func__ << ": failed to read the value of the parameter \"" << p.id
1191 << "\": " << result;
1192 return false;
1193 }
1194
1195 } // namespace
1196
setVendorParameters(const std::vector<VendorParameter> & in_parameters,bool in_async)1197 ndk::ScopedAStatus Module::setVendorParameters(const std::vector<VendorParameter>& in_parameters,
1198 bool in_async) {
1199 LOG(DEBUG) << __func__ << ": parameter count " << in_parameters.size()
1200 << ", async: " << in_async;
1201 bool allParametersKnown = true;
1202 for (const auto& p : in_parameters) {
1203 if (p.id == VendorDebug::kForceTransientBurstName) {
1204 if (!extractParameter<Boolean>(p, &mVendorDebug.forceTransientBurst)) {
1205 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1206 }
1207 } else if (p.id == VendorDebug::kForceSynchronousDrainName) {
1208 if (!extractParameter<Boolean>(p, &mVendorDebug.forceSynchronousDrain)) {
1209 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1210 }
1211 } else {
1212 allParametersKnown = false;
1213 LOG(ERROR) << __func__ << ": unrecognized parameter \"" << p.id << "\"";
1214 }
1215 }
1216 if (allParametersKnown) return ndk::ScopedAStatus::ok();
1217 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1218 }
1219
addDeviceEffect(int32_t in_portConfigId,const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> & in_effect)1220 ndk::ScopedAStatus Module::addDeviceEffect(
1221 int32_t in_portConfigId,
1222 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_effect) {
1223 if (in_effect == nullptr) {
1224 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", null effect";
1225 } else {
1226 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", effect Binder "
1227 << in_effect->asBinder().get();
1228 }
1229 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1230 }
1231
removeDeviceEffect(int32_t in_portConfigId,const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> & in_effect)1232 ndk::ScopedAStatus Module::removeDeviceEffect(
1233 int32_t in_portConfigId,
1234 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_effect) {
1235 if (in_effect == nullptr) {
1236 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", null effect";
1237 } else {
1238 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", effect Binder "
1239 << in_effect->asBinder().get();
1240 }
1241 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1242 }
1243
getMmapPolicyInfos(AudioMMapPolicyType mmapPolicyType,std::vector<AudioMMapPolicyInfo> * _aidl_return)1244 ndk::ScopedAStatus Module::getMmapPolicyInfos(AudioMMapPolicyType mmapPolicyType,
1245 std::vector<AudioMMapPolicyInfo>* _aidl_return) {
1246 LOG(DEBUG) << __func__ << ": mmap policy type " << toString(mmapPolicyType);
1247 std::set<int32_t> mmapSinks;
1248 std::set<int32_t> mmapSources;
1249 auto& ports = getConfig().ports;
1250 for (const auto& port : ports) {
1251 if (port.flags.getTag() == AudioIoFlags::Tag::input &&
1252 isBitPositionFlagSet(port.flags.get<AudioIoFlags::Tag::input>(),
1253 AudioInputFlags::MMAP_NOIRQ)) {
1254 mmapSinks.insert(port.id);
1255 } else if (port.flags.getTag() == AudioIoFlags::Tag::output &&
1256 isBitPositionFlagSet(port.flags.get<AudioIoFlags::Tag::output>(),
1257 AudioOutputFlags::MMAP_NOIRQ)) {
1258 mmapSources.insert(port.id);
1259 }
1260 }
1261 for (const auto& route : getConfig().routes) {
1262 if (mmapSinks.count(route.sinkPortId) != 0) {
1263 // The sink is a mix port, add the sources if they are device ports.
1264 for (int sourcePortId : route.sourcePortIds) {
1265 auto sourcePortIt = findById<AudioPort>(ports, sourcePortId);
1266 if (sourcePortIt == ports.end()) {
1267 // This must not happen
1268 LOG(ERROR) << __func__ << ": port id " << sourcePortId << " cannot be found";
1269 continue;
1270 }
1271 if (sourcePortIt->ext.getTag() != AudioPortExt::Tag::device) {
1272 // The source is not a device port, skip
1273 continue;
1274 }
1275 AudioMMapPolicyInfo policyInfo;
1276 policyInfo.device = sourcePortIt->ext.get<AudioPortExt::Tag::device>().device;
1277 // Always return AudioMMapPolicy.AUTO if the device supports mmap for
1278 // default implementation.
1279 policyInfo.mmapPolicy = AudioMMapPolicy::AUTO;
1280 _aidl_return->push_back(policyInfo);
1281 }
1282 } else {
1283 auto sinkPortIt = findById<AudioPort>(ports, route.sinkPortId);
1284 if (sinkPortIt == ports.end()) {
1285 // This must not happen
1286 LOG(ERROR) << __func__ << ": port id " << route.sinkPortId << " cannot be found";
1287 continue;
1288 }
1289 if (sinkPortIt->ext.getTag() != AudioPortExt::Tag::device) {
1290 // The sink is not a device port, skip
1291 continue;
1292 }
1293 if (count_any(mmapSources, route.sourcePortIds)) {
1294 AudioMMapPolicyInfo policyInfo;
1295 policyInfo.device = sinkPortIt->ext.get<AudioPortExt::Tag::device>().device;
1296 // Always return AudioMMapPolicy.AUTO if the device supports mmap for
1297 // default implementation.
1298 policyInfo.mmapPolicy = AudioMMapPolicy::AUTO;
1299 _aidl_return->push_back(policyInfo);
1300 }
1301 }
1302 }
1303 return ndk::ScopedAStatus::ok();
1304 }
1305
supportsVariableLatency(bool * _aidl_return)1306 ndk::ScopedAStatus Module::supportsVariableLatency(bool* _aidl_return) {
1307 LOG(DEBUG) << __func__;
1308 *_aidl_return = false;
1309 return ndk::ScopedAStatus::ok();
1310 }
1311
getAAudioMixerBurstCount(int32_t * _aidl_return)1312 ndk::ScopedAStatus Module::getAAudioMixerBurstCount(int32_t* _aidl_return) {
1313 if (!isMmapSupported()) {
1314 LOG(DEBUG) << __func__ << ": mmap is not supported ";
1315 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1316 }
1317 *_aidl_return = DEFAULT_AAUDIO_MIXER_BURST_COUNT;
1318 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1319 return ndk::ScopedAStatus::ok();
1320 }
1321
getAAudioHardwareBurstMinUsec(int32_t * _aidl_return)1322 ndk::ScopedAStatus Module::getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) {
1323 if (!isMmapSupported()) {
1324 LOG(DEBUG) << __func__ << ": mmap is not supported ";
1325 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1326 }
1327 *_aidl_return = DEFAULT_AAUDIO_HARDWARE_BURST_MIN_DURATION_US;
1328 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1329 return ndk::ScopedAStatus::ok();
1330 }
1331
isMmapSupported()1332 bool Module::isMmapSupported() {
1333 if (mIsMmapSupported.has_value()) {
1334 return mIsMmapSupported.value();
1335 }
1336 std::vector<AudioMMapPolicyInfo> mmapPolicyInfos;
1337 if (!getMmapPolicyInfos(AudioMMapPolicyType::DEFAULT, &mmapPolicyInfos).isOk()) {
1338 mIsMmapSupported = false;
1339 } else {
1340 mIsMmapSupported =
1341 std::find_if(mmapPolicyInfos.begin(), mmapPolicyInfos.end(), [](const auto& info) {
1342 return info.mmapPolicy == AudioMMapPolicy::AUTO ||
1343 info.mmapPolicy == AudioMMapPolicy::ALWAYS;
1344 }) != mmapPolicyInfos.end();
1345 }
1346 return mIsMmapSupported.value();
1347 }
1348
populateConnectedDevicePort(AudioPort * audioPort __unused)1349 ndk::ScopedAStatus Module::populateConnectedDevicePort(AudioPort* audioPort __unused) {
1350 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
1351 return ndk::ScopedAStatus::ok();
1352 }
1353
checkAudioPatchEndpointsMatch(const std::vector<AudioPortConfig * > & sources __unused,const std::vector<AudioPortConfig * > & sinks __unused)1354 ndk::ScopedAStatus Module::checkAudioPatchEndpointsMatch(
1355 const std::vector<AudioPortConfig*>& sources __unused,
1356 const std::vector<AudioPortConfig*>& sinks __unused) {
1357 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
1358 return ndk::ScopedAStatus::ok();
1359 }
1360
onExternalDeviceConnectionChanged(const::aidl::android::media::audio::common::AudioPort & audioPort __unused,bool connected __unused)1361 void Module::onExternalDeviceConnectionChanged(
1362 const ::aidl::android::media::audio::common::AudioPort& audioPort __unused,
1363 bool connected __unused) {
1364 LOG(DEBUG) << __func__ << ": do nothing and return";
1365 }
1366
onMasterMuteChanged(bool mute __unused)1367 ndk::ScopedAStatus Module::onMasterMuteChanged(bool mute __unused) {
1368 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
1369 return ndk::ScopedAStatus::ok();
1370 }
1371
onMasterVolumeChanged(float volume __unused)1372 ndk::ScopedAStatus Module::onMasterVolumeChanged(float volume __unused) {
1373 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
1374 return ndk::ScopedAStatus::ok();
1375 }
1376
getBtProfileManagerHandles()1377 Module::BtProfileHandles Module::getBtProfileManagerHandles() {
1378 return std::make_tuple(std::weak_ptr<IBluetooth>(), std::weak_ptr<IBluetoothA2dp>(),
1379 std::weak_ptr<IBluetoothLe>());
1380 }
1381
bluetoothParametersUpdated()1382 ndk::ScopedAStatus Module::bluetoothParametersUpdated() {
1383 return mStreams.bluetoothParametersUpdated();
1384 }
1385
1386 } // namespace aidl::android::hardware::audio::core
1387