blob: cad239f161bfc3b01ad47779adee5aa28133ad22 [file] [log] [blame]
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001/*
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"
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000021#include <Utils.h>
22#include <aidl/android/media/audio/common/AudioInputFlags.h>
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000023#include <aidl/android/media/audio/common/AudioOutputFlags.h>
Mikhail Naganov26dc9ad2023-06-23 13:55:37 -070024#include <android-base/logging.h>
25#include <android/binder_ibinder_platform.h>
26#include <error/expected_utils.h>
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000027
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +000028#include "core-impl/Configuration.h"
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000029#include "core-impl/Module.h"
Mikhail Naganovb03b5c42023-07-26 13:13:35 -070030#include "core-impl/ModuleBluetooth.h"
Mikhail Naganov521fc492023-07-11 17:24:08 -070031#include "core-impl/ModulePrimary.h"
Shraddha Basantwani6bb69632023-04-25 15:26:38 +053032#include "core-impl/ModuleRemoteSubmix.h"
Mikhail Naganov521fc492023-07-11 17:24:08 -070033#include "core-impl/ModuleStub.h"
jiabin253bd322023-01-25 23:57:31 +000034#include "core-impl/ModuleUsb.h"
Vlad Popa943b7e22022-12-08 14:24:12 +010035#include "core-impl/SoundDose.h"
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000036#include "core-impl/utils.h"
37
Mikhail Naganov872d4a62023-03-09 18:19:01 -080038using aidl::android::hardware::audio::common::getFrameSizeInBytes;
39using aidl::android::hardware::audio::common::isBitPositionFlagSet;
40using aidl::android::hardware::audio::common::isValidAudioMode;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000041using aidl::android::hardware::audio::common::SinkMetadata;
42using aidl::android::hardware::audio::common::SourceMetadata;
Vlad Popa2afbd1e2022-12-28 17:04:58 +010043using aidl::android::hardware::audio::core::sounddose::ISoundDose;
Mikhail Naganov6a4872d2022-06-15 21:39:04 +000044using aidl::android::media::audio::common::AudioChannelLayout;
Mikhail Naganovef6bc742022-10-06 00:14:19 +000045using aidl::android::media::audio::common::AudioDevice;
Lorena Torres-Huertadc9d1a42023-01-18 00:11:48 +000046using aidl::android::media::audio::common::AudioDeviceType;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000047using aidl::android::media::audio::common::AudioFormatDescription;
Mikhail Naganov6a4872d2022-06-15 21:39:04 +000048using aidl::android::media::audio::common::AudioFormatType;
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000049using aidl::android::media::audio::common::AudioInputFlags;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000050using aidl::android::media::audio::common::AudioIoFlags;
jiabin9a8e6862023-01-12 23:06:37 +000051using aidl::android::media::audio::common::AudioMMapPolicy;
52using aidl::android::media::audio::common::AudioMMapPolicyInfo;
53using aidl::android::media::audio::common::AudioMMapPolicyType;
Mikhail Naganov04ae8222023-01-11 15:48:10 -080054using aidl::android::media::audio::common::AudioMode;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000055using aidl::android::media::audio::common::AudioOffloadInfo;
56using aidl::android::media::audio::common::AudioOutputFlags;
57using aidl::android::media::audio::common::AudioPort;
58using aidl::android::media::audio::common::AudioPortConfig;
59using aidl::android::media::audio::common::AudioPortExt;
60using aidl::android::media::audio::common::AudioProfile;
Mikhail Naganov20047bc2023-01-05 20:16:07 +000061using aidl::android::media::audio::common::Boolean;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000062using aidl::android::media::audio::common::Int;
Mikhail Naganov6725ef52023-02-09 17:52:50 -080063using aidl::android::media::audio::common::MicrophoneInfo;
Mikhail Naganov6a4872d2022-06-15 21:39:04 +000064using aidl::android::media::audio::common::PcmType;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000065
66namespace aidl::android::hardware::audio::core {
67
68namespace {
69
Mikhail Naganov84bcc042023-10-05 17:36:57 -070070inline bool hasDynamicChannelMasks(const std::vector<AudioChannelLayout>& channelMasks) {
71 return channelMasks.empty() ||
72 std::all_of(channelMasks.begin(), channelMasks.end(),
73 [](const auto& channelMask) { return channelMask == AudioChannelLayout{}; });
74}
75
76inline bool hasDynamicFormat(const AudioFormatDescription& format) {
77 return format == AudioFormatDescription{};
78}
79
80inline bool hasDynamicSampleRates(const std::vector<int32_t>& sampleRates) {
81 return sampleRates.empty() ||
82 std::all_of(sampleRates.begin(), sampleRates.end(),
83 [](const auto& sampleRate) { return sampleRate == 0; });
84}
85
86inline bool isDynamicProfile(const AudioProfile& profile) {
87 return hasDynamicFormat(profile.format) || hasDynamicChannelMasks(profile.channelMasks) ||
88 hasDynamicSampleRates(profile.sampleRates);
89}
90
91bool hasDynamicProfilesOnly(const std::vector<AudioProfile>& profiles) {
92 if (profiles.empty()) return true;
93 return std::all_of(profiles.begin(), profiles.end(), isDynamicProfile);
94}
95
96// Note: does not assign an ID to the config.
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000097bool generateDefaultPortConfig(const AudioPort& port, AudioPortConfig* config) {
Mikhail Naganov84bcc042023-10-05 17:36:57 -070098 const bool allowDynamicConfig = port.ext.getTag() == AudioPortExt::device;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000099 *config = {};
100 config->portId = port.id;
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700101 for (const auto& profile : port.profiles) {
102 if (isDynamicProfile(profile)) continue;
103 config->format = profile.format;
104 config->channelMask = *profile.channelMasks.begin();
105 config->sampleRate = Int{.value = *profile.sampleRates.begin()};
106 config->flags = port.flags;
107 config->ext = port.ext;
108 return true;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000109 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700110 if (allowDynamicConfig) {
111 config->format = AudioFormatDescription{};
112 config->channelMask = AudioChannelLayout{};
113 config->sampleRate = Int{.value = 0};
114 config->flags = port.flags;
115 config->ext = port.ext;
116 return true;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000117 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700118 LOG(ERROR) << __func__ << ": port " << port.id << " only has dynamic profiles";
119 return false;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000120}
121
122bool findAudioProfile(const AudioPort& port, const AudioFormatDescription& format,
123 AudioProfile* profile) {
124 if (auto profilesIt =
125 find_if(port.profiles.begin(), port.profiles.end(),
126 [&format](const auto& profile) { return profile.format == format; });
127 profilesIt != port.profiles.end()) {
128 *profile = *profilesIt;
129 return true;
130 }
131 return false;
132}
Mikhail Naganov00603d12022-05-02 22:52:13 +0000133
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000134} // namespace
135
jiabin253bd322023-01-25 23:57:31 +0000136// static
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000137std::shared_ptr<Module> Module::createInstance(Type type, std::unique_ptr<Configuration>&& config) {
jiabin253bd322023-01-25 23:57:31 +0000138 switch (type) {
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530139 case Type::DEFAULT:
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000140 return ndk::SharedRefBase::make<ModulePrimary>(std::move(config));
Mikhail Naganov521fc492023-07-11 17:24:08 -0700141 case Type::R_SUBMIX:
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000142 return ndk::SharedRefBase::make<ModuleRemoteSubmix>(std::move(config));
Mikhail Naganov521fc492023-07-11 17:24:08 -0700143 case Type::STUB:
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000144 return ndk::SharedRefBase::make<ModuleStub>(std::move(config));
Mikhail Naganov521fc492023-07-11 17:24:08 -0700145 case Type::USB:
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000146 return ndk::SharedRefBase::make<ModuleUsb>(std::move(config));
Mikhail Naganovb03b5c42023-07-26 13:13:35 -0700147 case Type::BLUETOOTH:
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000148 return ndk::SharedRefBase::make<ModuleBluetooth>(std::move(config));
jiabin253bd322023-01-25 23:57:31 +0000149 }
150}
151
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000152// static
153std::optional<Module::Type> Module::typeFromString(const std::string& type) {
154 if (type == "default")
155 return Module::Type::DEFAULT;
156 else if (type == "r_submix")
157 return Module::Type::R_SUBMIX;
158 else if (type == "stub")
159 return Module::Type::STUB;
160 else if (type == "usb")
161 return Module::Type::USB;
162 else if (type == "bluetooth")
163 return Module::Type::BLUETOOTH;
164 return {};
165}
166
Mikhail Naganovd5536d92023-03-24 18:27:58 -0700167std::ostream& operator<<(std::ostream& os, Module::Type t) {
168 switch (t) {
169 case Module::Type::DEFAULT:
170 os << "default";
171 break;
172 case Module::Type::R_SUBMIX:
173 os << "r_submix";
174 break;
Mikhail Naganov521fc492023-07-11 17:24:08 -0700175 case Module::Type::STUB:
176 os << "stub";
177 break;
Mikhail Naganovd5536d92023-03-24 18:27:58 -0700178 case Module::Type::USB:
179 os << "usb";
180 break;
Mikhail Naganovb03b5c42023-07-26 13:13:35 -0700181 case Module::Type::BLUETOOTH:
182 os << "bluetooth";
183 break;
Mikhail Naganovd5536d92023-03-24 18:27:58 -0700184 }
185 return os;
186}
187
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000188void Module::cleanUpPatch(int32_t patchId) {
189 erase_all_values(mPatches, std::set<int32_t>{patchId});
190}
191
Mikhail Naganov8651b362023-01-06 23:15:27 +0000192ndk::ScopedAStatus Module::createStreamContext(
193 int32_t in_portConfigId, int64_t in_bufferSizeFrames,
194 std::shared_ptr<IStreamCallback> asyncCallback,
195 std::shared_ptr<IStreamOutEventCallback> outEventCallback, StreamContext* out_context) {
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000196 if (in_bufferSizeFrames <= 0) {
197 LOG(ERROR) << __func__ << ": non-positive buffer size " << in_bufferSizeFrames;
198 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
199 }
200 if (in_bufferSizeFrames < kMinimumStreamBufferSizeFrames) {
201 LOG(ERROR) << __func__ << ": insufficient buffer size " << in_bufferSizeFrames
202 << ", must be at least " << kMinimumStreamBufferSizeFrames;
203 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
204 }
205 auto& configs = getConfig().portConfigs;
206 auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId);
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000207 // Since this is a private method, it is assumed that
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000208 // validity of the portConfigId has already been checked.
209 const size_t frameSize =
210 getFrameSizeInBytes(portConfigIt->format.value(), portConfigIt->channelMask.value());
211 if (frameSize == 0) {
212 LOG(ERROR) << __func__ << ": could not calculate frame size for port config "
213 << portConfigIt->toString();
214 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
215 }
216 LOG(DEBUG) << __func__ << ": frame size " << frameSize << " bytes";
Mikhail Naganovb511b8a2023-05-15 14:35:24 -0700217 if (frameSize > static_cast<size_t>(kMaximumStreamBufferSizeBytes / in_bufferSizeFrames)) {
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000218 LOG(ERROR) << __func__ << ": buffer size " << in_bufferSizeFrames
219 << " frames is too large, maximum size is "
220 << kMaximumStreamBufferSizeBytes / frameSize;
221 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
222 }
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000223 const auto& flags = portConfigIt->flags.value();
224 if ((flags.getTag() == AudioIoFlags::Tag::input &&
Mikhail Naganova2c5ddf2022-09-12 22:57:14 +0000225 !isBitPositionFlagSet(flags.get<AudioIoFlags::Tag::input>(),
226 AudioInputFlags::MMAP_NOIRQ)) ||
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000227 (flags.getTag() == AudioIoFlags::Tag::output &&
Mikhail Naganova2c5ddf2022-09-12 22:57:14 +0000228 !isBitPositionFlagSet(flags.get<AudioIoFlags::Tag::output>(),
229 AudioOutputFlags::MMAP_NOIRQ))) {
Mikhail Naganov20047bc2023-01-05 20:16:07 +0000230 StreamContext::DebugParameters params{mDebug.streamTransientStateDelayMs,
Mikhail Naganov194daaa2023-01-05 22:34:20 +0000231 mVendorDebug.forceTransientBurst,
232 mVendorDebug.forceSynchronousDrain};
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000233 StreamContext temp(
234 std::make_unique<StreamContext::CommandMQ>(1, true /*configureEventFlagWord*/),
235 std::make_unique<StreamContext::ReplyMQ>(1, true /*configureEventFlagWord*/),
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530236 portConfigIt->portId, portConfigIt->format.value(),
237 portConfigIt->channelMask.value(), portConfigIt->sampleRate.value().value, flags,
Mikhail Naganovb42a69e2023-06-16 12:38:25 -0700238 portConfigIt->ext.get<AudioPortExt::mix>().handle,
Mikhail Naganovef6bc742022-10-06 00:14:19 +0000239 std::make_unique<StreamContext::DataMQ>(frameSize * in_bufferSizeFrames),
Mikhail Naganov8651b362023-01-06 23:15:27 +0000240 asyncCallback, outEventCallback, params);
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000241 if (temp.isValid()) {
242 *out_context = std::move(temp);
243 } else {
244 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
245 }
246 } else {
247 // TODO: Implement simulation of MMAP buffer allocation
248 }
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000249 return ndk::ScopedAStatus::ok();
250}
251
Mikhail Naganovef6bc742022-10-06 00:14:19 +0000252std::vector<AudioDevice> Module::findConnectedDevices(int32_t portConfigId) {
253 std::vector<AudioDevice> result;
254 auto& ports = getConfig().ports;
255 auto portIds = portIdsFromPortConfigIds(findConnectedPortConfigIds(portConfigId));
256 for (auto it = portIds.begin(); it != portIds.end(); ++it) {
257 auto portIt = findById<AudioPort>(ports, *it);
258 if (portIt != ports.end() && portIt->ext.getTag() == AudioPortExt::Tag::device) {
259 result.push_back(portIt->ext.template get<AudioPortExt::Tag::device>().device);
260 }
261 }
262 return result;
263}
264
265std::set<int32_t> Module::findConnectedPortConfigIds(int32_t portConfigId) {
266 std::set<int32_t> result;
267 auto patchIdsRange = mPatches.equal_range(portConfigId);
268 auto& patches = getConfig().patches;
269 for (auto it = patchIdsRange.first; it != patchIdsRange.second; ++it) {
270 auto patchIt = findById<AudioPatch>(patches, it->second);
271 if (patchIt == patches.end()) {
272 LOG(FATAL) << __func__ << ": patch with id " << it->second << " taken from mPatches "
273 << "not found in the configuration";
274 }
275 if (std::find(patchIt->sourcePortConfigIds.begin(), patchIt->sourcePortConfigIds.end(),
276 portConfigId) != patchIt->sourcePortConfigIds.end()) {
277 result.insert(patchIt->sinkPortConfigIds.begin(), patchIt->sinkPortConfigIds.end());
278 } else {
279 result.insert(patchIt->sourcePortConfigIds.begin(), patchIt->sourcePortConfigIds.end());
280 }
281 }
282 return result;
283}
284
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000285ndk::ScopedAStatus Module::findPortIdForNewStream(int32_t in_portConfigId, AudioPort** port) {
286 auto& configs = getConfig().portConfigs;
287 auto portConfigIt = findById<AudioPortConfig>(configs, in_portConfigId);
288 if (portConfigIt == configs.end()) {
289 LOG(ERROR) << __func__ << ": existing port config id " << in_portConfigId << " not found";
290 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
291 }
292 const int32_t portId = portConfigIt->portId;
293 // In our implementation, configs of mix ports always have unique IDs.
294 CHECK(portId != in_portConfigId);
295 auto& ports = getConfig().ports;
296 auto portIt = findById<AudioPort>(ports, portId);
297 if (portIt == ports.end()) {
298 LOG(ERROR) << __func__ << ": port id " << portId << " used by port config id "
299 << in_portConfigId << " not found";
300 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
301 }
302 if (mStreams.count(in_portConfigId) != 0) {
303 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
304 << " already has a stream opened on it";
305 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
306 }
307 if (portIt->ext.getTag() != AudioPortExt::Tag::mix) {
308 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
309 << " does not correspond to a mix port";
310 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
311 }
Mikhail Naganovb511b8a2023-05-15 14:35:24 -0700312 const size_t maxOpenStreamCount = portIt->ext.get<AudioPortExt::Tag::mix>().maxOpenStreamCount;
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000313 if (maxOpenStreamCount != 0 && mStreams.count(portId) >= maxOpenStreamCount) {
314 LOG(ERROR) << __func__ << ": port id " << portId
315 << " has already reached maximum allowed opened stream count: "
316 << maxOpenStreamCount;
317 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
318 }
319 *port = &(*portIt);
320 return ndk::ScopedAStatus::ok();
321}
322
Mikhail Naganovef6bc742022-10-06 00:14:19 +0000323template <typename C>
324std::set<int32_t> Module::portIdsFromPortConfigIds(C portConfigIds) {
325 std::set<int32_t> result;
326 auto& portConfigs = getConfig().portConfigs;
327 for (auto it = portConfigIds.begin(); it != portConfigIds.end(); ++it) {
328 auto portConfigIt = findById<AudioPortConfig>(portConfigs, *it);
329 if (portConfigIt != portConfigs.end()) {
330 result.insert(portConfigIt->portId);
331 }
332 }
333 return result;
334}
335
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000336std::unique_ptr<Module::Configuration> Module::initializeConfig() {
337 return internal::getConfiguration(getType());
Peter Yoon918a6a52023-07-13 17:04:37 +0900338}
339
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700340std::vector<AudioRoute*> Module::getAudioRoutesForAudioPortImpl(int32_t portId) {
341 std::vector<AudioRoute*> result;
342 auto& routes = getConfig().routes;
343 for (auto& r : routes) {
344 const auto& srcs = r.sourcePortIds;
345 if (r.sinkPortId == portId || std::find(srcs.begin(), srcs.end(), portId) != srcs.end()) {
346 result.push_back(&r);
347 }
348 }
349 return result;
350}
351
Lorena Torres-Huerta00a73072022-12-20 02:21:41 +0000352Module::Configuration& Module::getConfig() {
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000353 if (!mConfig) {
Peter Yoon918a6a52023-07-13 17:04:37 +0900354 mConfig = std::move(initializeConfig());
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000355 }
356 return *mConfig;
357}
358
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700359std::set<int32_t> Module::getRoutableAudioPortIds(int32_t portId,
360 std::vector<AudioRoute*>* routes) {
361 std::vector<AudioRoute*> routesStorage;
362 if (routes == nullptr) {
363 routesStorage = getAudioRoutesForAudioPortImpl(portId);
364 routes = &routesStorage;
365 }
366 std::set<int32_t> result;
367 for (AudioRoute* r : *routes) {
368 if (r->sinkPortId == portId) {
369 result.insert(r->sourcePortIds.begin(), r->sourcePortIds.end());
370 } else {
371 result.insert(r->sinkPortId);
372 }
373 }
374 return result;
375}
376
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000377void Module::registerPatch(const AudioPatch& patch) {
378 auto& configs = getConfig().portConfigs;
379 auto do_insert = [&](const std::vector<int32_t>& portConfigIds) {
380 for (auto portConfigId : portConfigIds) {
381 auto configIt = findById<AudioPortConfig>(configs, portConfigId);
382 if (configIt != configs.end()) {
383 mPatches.insert(std::pair{portConfigId, patch.id});
384 if (configIt->portId != portConfigId) {
385 mPatches.insert(std::pair{configIt->portId, patch.id});
386 }
387 }
388 };
389 };
390 do_insert(patch.sourcePortConfigIds);
391 do_insert(patch.sinkPortConfigIds);
392}
393
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700394ndk::ScopedAStatus Module::updateStreamsConnectedState(const AudioPatch& oldPatch,
395 const AudioPatch& newPatch) {
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700396 // Notify streams about the new set of devices they are connected to.
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700397 auto maybeFailure = ndk::ScopedAStatus::ok();
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700398 using Connections =
399 std::map<int32_t /*mixPortConfigId*/, std::set<int32_t /*devicePortConfigId*/>>;
400 Connections oldConnections, newConnections;
401 auto fillConnectionsHelper = [&](Connections& connections,
402 const std::vector<int32_t>& mixPortCfgIds,
403 const std::vector<int32_t>& devicePortCfgIds) {
404 for (int32_t mixPortCfgId : mixPortCfgIds) {
405 connections[mixPortCfgId].insert(devicePortCfgIds.begin(), devicePortCfgIds.end());
406 }
407 };
408 auto fillConnections = [&](Connections& connections, const AudioPatch& patch) {
409 if (std::find_if(patch.sourcePortConfigIds.begin(), patch.sourcePortConfigIds.end(),
410 [&](int32_t portConfigId) { return mStreams.count(portConfigId) > 0; }) !=
411 patch.sourcePortConfigIds.end()) {
412 // Sources are mix ports.
413 fillConnectionsHelper(connections, patch.sourcePortConfigIds, patch.sinkPortConfigIds);
414 } else if (std::find_if(patch.sinkPortConfigIds.begin(), patch.sinkPortConfigIds.end(),
415 [&](int32_t portConfigId) {
416 return mStreams.count(portConfigId) > 0;
417 }) != patch.sinkPortConfigIds.end()) {
418 // Sources are device ports.
419 fillConnectionsHelper(connections, patch.sinkPortConfigIds, patch.sourcePortConfigIds);
420 } // Otherwise, there are no streams to notify.
421 };
422 fillConnections(oldConnections, oldPatch);
423 fillConnections(newConnections, newPatch);
424
425 std::for_each(oldConnections.begin(), oldConnections.end(), [&](const auto& connectionPair) {
426 const int32_t mixPortConfigId = connectionPair.first;
427 if (auto it = newConnections.find(mixPortConfigId);
428 it == newConnections.end() || it->second != connectionPair.second) {
429 if (auto status = mStreams.setStreamConnectedDevices(mixPortConfigId, {});
430 status.isOk()) {
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700431 LOG(DEBUG) << "updateStreamsConnectedState: The stream on port config id "
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700432 << mixPortConfigId << " has been disconnected";
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700433 } else {
434 // Disconnection is tricky to roll back, just register a failure.
435 maybeFailure = std::move(status);
436 }
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000437 }
438 });
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700439 if (!maybeFailure.isOk()) return maybeFailure;
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700440 std::set<int32_t> idsToDisconnectOnFailure;
441 std::for_each(newConnections.begin(), newConnections.end(), [&](const auto& connectionPair) {
442 const int32_t mixPortConfigId = connectionPair.first;
443 if (auto it = oldConnections.find(mixPortConfigId);
444 it == oldConnections.end() || it->second != connectionPair.second) {
445 const auto connectedDevices = findConnectedDevices(mixPortConfigId);
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700446 if (connectedDevices.empty()) {
447 // This is important as workers use the vector size to derive the connection status.
448 LOG(FATAL) << "updateStreamsConnectedState: No connected devices found for port "
449 "config id "
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700450 << mixPortConfigId;
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700451 }
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700452 if (auto status = mStreams.setStreamConnectedDevices(mixPortConfigId, connectedDevices);
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700453 status.isOk()) {
454 LOG(DEBUG) << "updateStreamsConnectedState: The stream on port config id "
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700455 << mixPortConfigId << " has been connected to: "
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700456 << ::android::internal::ToString(connectedDevices);
457 } else {
458 maybeFailure = std::move(status);
Mikhail Naganov89a8ea92023-09-29 17:02:12 -0700459 idsToDisconnectOnFailure.insert(mixPortConfigId);
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700460 }
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000461 }
462 });
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700463 if (!maybeFailure.isOk()) {
464 LOG(WARNING) << __func__ << ": Due to a failure, disconnecting streams on port config ids "
465 << ::android::internal::ToString(idsToDisconnectOnFailure);
466 std::for_each(idsToDisconnectOnFailure.begin(), idsToDisconnectOnFailure.end(),
467 [&](const auto& portConfigId) {
468 auto status = mStreams.setStreamConnectedDevices(portConfigId, {});
469 (void)status.isOk(); // Can't do much about a failure here.
470 });
471 return maybeFailure;
472 }
473 return ndk::ScopedAStatus::ok();
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000474}
475
Mikhail Naganov00603d12022-05-02 22:52:13 +0000476ndk::ScopedAStatus Module::setModuleDebug(
477 const ::aidl::android::hardware::audio::core::ModuleDebug& in_debug) {
Mikhail Naganovd5536d92023-03-24 18:27:58 -0700478 LOG(DEBUG) << __func__ << ": " << mType << ": old flags:" << mDebug.toString()
Mikhail Naganov00603d12022-05-02 22:52:13 +0000479 << ", new flags: " << in_debug.toString();
480 if (mDebug.simulateDeviceConnections != in_debug.simulateDeviceConnections &&
481 !mConnectedDevicePorts.empty()) {
Mikhail Naganovd5536d92023-03-24 18:27:58 -0700482 LOG(ERROR) << __func__ << ": " << mType
483 << ": attempting to change device connections simulation while having external "
484 << "devices connected";
Mikhail Naganov00603d12022-05-02 22:52:13 +0000485 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
486 }
Mikhail Naganovbd483c02022-11-17 20:33:39 +0000487 if (in_debug.streamTransientStateDelayMs < 0) {
Mikhail Naganovd5536d92023-03-24 18:27:58 -0700488 LOG(ERROR) << __func__ << ": " << mType << ": streamTransientStateDelayMs is negative: "
Mikhail Naganovbd483c02022-11-17 20:33:39 +0000489 << in_debug.streamTransientStateDelayMs;
490 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
491 }
Mikhail Naganov00603d12022-05-02 22:52:13 +0000492 mDebug = in_debug;
493 return ndk::ScopedAStatus::ok();
494}
495
Mikhail Naganov3b125b72022-10-05 02:12:39 +0000496ndk::ScopedAStatus Module::getTelephony(std::shared_ptr<ITelephony>* _aidl_return) {
Mikhail Naganov521fc492023-07-11 17:24:08 -0700497 *_aidl_return = nullptr;
498 LOG(DEBUG) << __func__ << ": returning null";
Mikhail Naganov3b125b72022-10-05 02:12:39 +0000499 return ndk::ScopedAStatus::ok();
500}
501
Mikhail Naganov10c6fe22022-09-30 23:49:17 +0000502ndk::ScopedAStatus Module::getBluetooth(std::shared_ptr<IBluetooth>* _aidl_return) {
Mikhail Naganov521fc492023-07-11 17:24:08 -0700503 *_aidl_return = nullptr;
504 LOG(DEBUG) << __func__ << ": returning null";
Mikhail Naganov10c6fe22022-09-30 23:49:17 +0000505 return ndk::ScopedAStatus::ok();
506}
507
Mikhail Naganov7499a002023-02-27 18:51:44 -0800508ndk::ScopedAStatus Module::getBluetoothA2dp(std::shared_ptr<IBluetoothA2dp>* _aidl_return) {
Mikhail Naganov521fc492023-07-11 17:24:08 -0700509 *_aidl_return = nullptr;
510 LOG(DEBUG) << __func__ << ": returning null";
Mikhail Naganov7499a002023-02-27 18:51:44 -0800511 return ndk::ScopedAStatus::ok();
512}
513
Mikhail Naganovb5647da2023-03-06 14:37:38 -0800514ndk::ScopedAStatus Module::getBluetoothLe(std::shared_ptr<IBluetoothLe>* _aidl_return) {
Mikhail Naganov521fc492023-07-11 17:24:08 -0700515 *_aidl_return = nullptr;
516 LOG(DEBUG) << __func__ << ": returning null";
Mikhail Naganovb5647da2023-03-06 14:37:38 -0800517 return ndk::ScopedAStatus::ok();
518}
519
Mikhail Naganov00603d12022-05-02 22:52:13 +0000520ndk::ScopedAStatus Module::connectExternalDevice(const AudioPort& in_templateIdAndAdditionalData,
521 AudioPort* _aidl_return) {
522 const int32_t templateId = in_templateIdAndAdditionalData.id;
523 auto& ports = getConfig().ports;
524 AudioPort connectedPort;
525 { // Scope the template port so that we don't accidentally modify it.
526 auto templateIt = findById<AudioPort>(ports, templateId);
527 if (templateIt == ports.end()) {
528 LOG(ERROR) << __func__ << ": port id " << templateId << " not found";
529 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
530 }
531 if (templateIt->ext.getTag() != AudioPortExt::Tag::device) {
532 LOG(ERROR) << __func__ << ": port id " << templateId << " is not a device port";
533 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
534 }
Mikhail Naganov00603d12022-05-02 22:52:13 +0000535 auto& templateDevicePort = templateIt->ext.get<AudioPortExt::Tag::device>();
536 if (templateDevicePort.device.type.connection.empty()) {
537 LOG(ERROR) << __func__ << ": port id " << templateId << " is permanently attached";
538 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
539 }
Mikhail Naganovfcf980e2023-09-07 16:30:11 -0700540 if (mConnectedDevicePorts.find(templateId) != mConnectedDevicePorts.end()) {
541 LOG(ERROR) << __func__ << ": port id " << templateId << " is a connected device port";
542 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
543 }
Mikhail Naganov00603d12022-05-02 22:52:13 +0000544 // Postpone id allocation until we ensure that there are no client errors.
545 connectedPort = *templateIt;
546 connectedPort.extraAudioDescriptors = in_templateIdAndAdditionalData.extraAudioDescriptors;
547 const auto& inputDevicePort =
548 in_templateIdAndAdditionalData.ext.get<AudioPortExt::Tag::device>();
549 auto& connectedDevicePort = connectedPort.ext.get<AudioPortExt::Tag::device>();
550 connectedDevicePort.device.address = inputDevicePort.device.address;
551 LOG(DEBUG) << __func__ << ": device port " << connectedPort.id << " device set to "
552 << connectedDevicePort.device.toString();
553 // Check if there is already a connected port with for the same external device.
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700554 for (auto connectedPortPair : mConnectedDevicePorts) {
555 auto connectedPortIt = findById<AudioPort>(ports, connectedPortPair.first);
Mikhail Naganov00603d12022-05-02 22:52:13 +0000556 if (connectedPortIt->ext.get<AudioPortExt::Tag::device>().device ==
557 connectedDevicePort.device) {
558 LOG(ERROR) << __func__ << ": device " << connectedDevicePort.device.toString()
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700559 << " is already connected at the device port id "
560 << connectedPortPair.first;
Mikhail Naganov00603d12022-05-02 22:52:13 +0000561 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
562 }
563 }
564 }
565
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700566 // Two main cases are considered with regard to the profiles of the connected device port:
567 //
568 // 1. If the template device port has dynamic profiles, and at least one routable mix
569 // port also has dynamic profiles, it means that after connecting the device, the
570 // connected device port must have profiles populated with actual capabilities of
571 // the connected device, and dynamic of routable mix ports will be filled
572 // according to these capabilities. An example of this case is connection of an
573 // HDMI or USB device. For USB handled by ADSP, there can be mix ports with static
574 // profiles, and one dedicated mix port for "hi-fi" playback. The latter is left with
575 // dynamic profiles so that they can be populated with actual capabilities of
576 // the connected device.
577 //
578 // 2. If the template device port has dynamic profiles, while all routable mix ports
579 // have static profiles, it means that after connecting the device, the connected
580 // device port can be left with dynamic profiles, and profiles of mix ports are
581 // left untouched. An example of this case is connection of an analog wired
582 // headset, it should be treated in the same way as a speaker.
583 //
584 // Yet another possible case is when both the template device port and all routable
585 // mix ports have static profiles. This is allowed and handled correctly, however, it
586 // is not very practical, since these profiles are likely duplicates of each other.
587
588 std::vector<AudioRoute*> routesToMixPorts = getAudioRoutesForAudioPortImpl(templateId);
589 std::set<int32_t> routableMixPortIds = getRoutableAudioPortIds(templateId, &routesToMixPorts);
590 if (hasDynamicProfilesOnly(connectedPort.profiles)) {
Mikhail Naganovfcf980e2023-09-07 16:30:11 -0700591 if (!mDebug.simulateDeviceConnections) {
592 RETURN_STATUS_IF_ERROR(populateConnectedDevicePort(&connectedPort));
593 } else {
594 auto& connectedProfiles = getConfig().connectedProfiles;
595 if (auto connectedProfilesIt = connectedProfiles.find(templateId);
596 connectedProfilesIt != connectedProfiles.end()) {
597 connectedPort.profiles = connectedProfilesIt->second;
598 }
599 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700600 if (hasDynamicProfilesOnly(connectedPort.profiles)) {
601 // Possible case 2. Check if all routable mix ports have static profiles.
602 if (auto dynamicMixPortIt = std::find_if(ports.begin(), ports.end(),
603 [&routableMixPortIds](const auto& p) {
604 return routableMixPortIds.count(p.id) >
605 0 &&
606 hasDynamicProfilesOnly(p.profiles);
607 });
608 dynamicMixPortIt != ports.end()) {
609 LOG(ERROR) << __func__
610 << ": connected port only has dynamic profiles after connecting "
611 << "external device " << connectedPort.toString() << ", and there exist "
612 << "a routable mix port with dynamic profiles: "
613 << dynamicMixPortIt->toString();
614 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
615 }
Shraddha Basantwani6bb69632023-04-25 15:26:38 +0530616 }
617 }
618
Mikhail Naganovdc417732023-09-29 15:49:35 -0700619 connectedPort.id = getConfig().nextPortId++;
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700620 auto [connectedPortsIt, _] =
Mikhail Naganov0e128dd2023-09-13 18:01:18 -0700621 mConnectedDevicePorts.insert(std::pair(connectedPort.id, std::set<int32_t>()));
Mikhail Naganov00603d12022-05-02 22:52:13 +0000622 LOG(DEBUG) << __func__ << ": template port " << templateId << " external device connected, "
623 << "connected port ID " << connectedPort.id;
Mikhail Naganov00603d12022-05-02 22:52:13 +0000624 ports.push_back(connectedPort);
jiabin783c48b2023-02-28 18:28:06 +0000625 onExternalDeviceConnectionChanged(connectedPort, true /*connected*/);
Mikhail Naganov00603d12022-05-02 22:52:13 +0000626
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700627 // For routes where the template port is a source, add the connected port to sources,
628 // otherwise, create a new route by copying from the route for the template port.
Mikhail Naganov00603d12022-05-02 22:52:13 +0000629 std::vector<AudioRoute> newRoutes;
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700630 for (AudioRoute* r : routesToMixPorts) {
631 if (r->sinkPortId == templateId) {
632 newRoutes.push_back(AudioRoute{.sourcePortIds = r->sourcePortIds,
633 .sinkPortId = connectedPort.id,
634 .isExclusive = r->isExclusive});
Mikhail Naganov00603d12022-05-02 22:52:13 +0000635 } else {
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700636 r->sourcePortIds.push_back(connectedPort.id);
Mikhail Naganov00603d12022-05-02 22:52:13 +0000637 }
638 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700639 auto& routes = getConfig().routes;
Mikhail Naganov00603d12022-05-02 22:52:13 +0000640 routes.insert(routes.end(), newRoutes.begin(), newRoutes.end());
641
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700642 if (!hasDynamicProfilesOnly(connectedPort.profiles) && !routableMixPortIds.empty()) {
643 // Note: this is a simplistic approach assuming that a mix port can only be populated
644 // from a single device port. Implementing support for stuffing dynamic profiles with
645 // a superset of all profiles from all routable dynamic device ports would be more involved.
646 for (auto& port : ports) {
647 if (routableMixPortIds.count(port.id) == 0) continue;
648 if (hasDynamicProfilesOnly(port.profiles)) {
649 port.profiles = connectedPort.profiles;
650 connectedPortsIt->second.insert(port.id);
Mikhail Naganov0e128dd2023-09-13 18:01:18 -0700651 } else {
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700652 // Check if profiles are not all dynamic because they were populated by
653 // a previous connection. Otherwise, it means that they are actually static.
654 for (const auto& cp : mConnectedDevicePorts) {
655 if (cp.second.count(port.id) > 0) {
656 connectedPortsIt->second.insert(port.id);
Mikhail Naganov0e128dd2023-09-13 18:01:18 -0700657 break;
658 }
659 }
660 }
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700661 }
662 }
663 *_aidl_return = std::move(connectedPort);
664
Mikhail Naganov00603d12022-05-02 22:52:13 +0000665 return ndk::ScopedAStatus::ok();
666}
667
668ndk::ScopedAStatus Module::disconnectExternalDevice(int32_t in_portId) {
669 auto& ports = getConfig().ports;
670 auto portIt = findById<AudioPort>(ports, in_portId);
671 if (portIt == ports.end()) {
672 LOG(ERROR) << __func__ << ": port id " << in_portId << " not found";
673 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
674 }
675 if (portIt->ext.getTag() != AudioPortExt::Tag::device) {
676 LOG(ERROR) << __func__ << ": port id " << in_portId << " is not a device port";
677 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
678 }
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700679 auto connectedPortsIt = mConnectedDevicePorts.find(in_portId);
680 if (connectedPortsIt == mConnectedDevicePorts.end()) {
Mikhail Naganov00603d12022-05-02 22:52:13 +0000681 LOG(ERROR) << __func__ << ": port id " << in_portId << " is not a connected device port";
682 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
683 }
684 auto& configs = getConfig().portConfigs;
685 auto& initials = getConfig().initialConfigs;
686 auto configIt = std::find_if(configs.begin(), configs.end(), [&](const auto& config) {
687 if (config.portId == in_portId) {
688 // Check if the configuration was provided by the client.
689 const auto& initialIt = findById<AudioPortConfig>(initials, config.id);
690 return initialIt == initials.end() || config != *initialIt;
691 }
692 return false;
693 });
694 if (configIt != configs.end()) {
695 LOG(ERROR) << __func__ << ": port id " << in_portId << " has a non-default config with id "
696 << configIt->id;
697 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
698 }
jiabin783c48b2023-02-28 18:28:06 +0000699 onExternalDeviceConnectionChanged(*portIt, false /*connected*/);
Mikhail Naganov00603d12022-05-02 22:52:13 +0000700 ports.erase(portIt);
Mikhail Naganov00603d12022-05-02 22:52:13 +0000701 LOG(DEBUG) << __func__ << ": connected device port " << in_portId << " released";
702
703 auto& routes = getConfig().routes;
704 for (auto routesIt = routes.begin(); routesIt != routes.end();) {
705 if (routesIt->sinkPortId == in_portId) {
706 routesIt = routes.erase(routesIt);
707 } else {
708 // Note: the list of sourcePortIds can't become empty because there must
709 // be the id of the template port in the route.
710 erase_if(routesIt->sourcePortIds, [in_portId](auto src) { return src == in_portId; });
711 ++routesIt;
712 }
713 }
714
Mikhail Naganov0e128dd2023-09-13 18:01:18 -0700715 // Clear profiles for mix ports that are not connected to any other ports.
716 std::set<int32_t> mixPortsToClear = std::move(connectedPortsIt->second);
717 mConnectedDevicePorts.erase(connectedPortsIt);
718 for (const auto& connectedPort : mConnectedDevicePorts) {
719 for (int32_t mixPortId : connectedPort.second) {
720 mixPortsToClear.erase(mixPortId);
721 }
722 }
723 for (int32_t mixPortId : mixPortsToClear) {
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700724 auto mixPortIt = findById<AudioPort>(ports, mixPortId);
725 if (mixPortIt != ports.end()) {
726 mixPortIt->profiles = {};
727 }
728 }
Mikhail Naganov7b2d12b2023-03-24 18:29:14 -0700729
Mikhail Naganov00603d12022-05-02 22:52:13 +0000730 return ndk::ScopedAStatus::ok();
731}
732
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000733ndk::ScopedAStatus Module::getAudioPatches(std::vector<AudioPatch>* _aidl_return) {
734 *_aidl_return = getConfig().patches;
735 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " patches";
736 return ndk::ScopedAStatus::ok();
737}
738
739ndk::ScopedAStatus Module::getAudioPort(int32_t in_portId, AudioPort* _aidl_return) {
740 auto& ports = getConfig().ports;
741 auto portIt = findById<AudioPort>(ports, in_portId);
742 if (portIt != ports.end()) {
743 *_aidl_return = *portIt;
744 LOG(DEBUG) << __func__ << ": returning port by id " << in_portId;
745 return ndk::ScopedAStatus::ok();
746 }
747 LOG(ERROR) << __func__ << ": port id " << in_portId << " not found";
748 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
749}
750
751ndk::ScopedAStatus Module::getAudioPortConfigs(std::vector<AudioPortConfig>* _aidl_return) {
752 *_aidl_return = getConfig().portConfigs;
753 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " port configs";
754 return ndk::ScopedAStatus::ok();
755}
756
757ndk::ScopedAStatus Module::getAudioPorts(std::vector<AudioPort>* _aidl_return) {
758 *_aidl_return = getConfig().ports;
759 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " ports";
760 return ndk::ScopedAStatus::ok();
761}
762
763ndk::ScopedAStatus Module::getAudioRoutes(std::vector<AudioRoute>* _aidl_return) {
764 *_aidl_return = getConfig().routes;
765 LOG(DEBUG) << __func__ << ": returning " << _aidl_return->size() << " routes";
766 return ndk::ScopedAStatus::ok();
767}
768
Mikhail Naganov00603d12022-05-02 22:52:13 +0000769ndk::ScopedAStatus Module::getAudioRoutesForAudioPort(int32_t in_portId,
770 std::vector<AudioRoute>* _aidl_return) {
771 auto& ports = getConfig().ports;
772 if (auto portIt = findById<AudioPort>(ports, in_portId); portIt == ports.end()) {
773 LOG(ERROR) << __func__ << ": port id " << in_portId << " not found";
774 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
775 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700776 std::vector<AudioRoute*> routes = getAudioRoutesForAudioPortImpl(in_portId);
777 std::transform(routes.begin(), routes.end(), std::back_inserter(*_aidl_return),
778 [](auto rptr) { return *rptr; });
Mikhail Naganov00603d12022-05-02 22:52:13 +0000779 return ndk::ScopedAStatus::ok();
780}
781
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000782ndk::ScopedAStatus Module::openInputStream(const OpenInputStreamArguments& in_args,
783 OpenInputStreamReturn* _aidl_return) {
784 LOG(DEBUG) << __func__ << ": port config id " << in_args.portConfigId << ", buffer size "
785 << in_args.bufferSizeFrames << " frames";
786 AudioPort* port = nullptr;
Mikhail Naganov26dc9ad2023-06-23 13:55:37 -0700787 RETURN_STATUS_IF_ERROR(findPortIdForNewStream(in_args.portConfigId, &port));
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000788 if (port->flags.getTag() != AudioIoFlags::Tag::input) {
789 LOG(ERROR) << __func__ << ": port config id " << in_args.portConfigId
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000790 << " does not correspond to an input mix port";
791 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
792 }
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000793 StreamContext context;
Mikhail Naganov26dc9ad2023-06-23 13:55:37 -0700794 RETURN_STATUS_IF_ERROR(createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames,
795 nullptr, nullptr, &context));
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000796 context.fillDescriptor(&_aidl_return->desc);
Mikhail Naganove9f10fc2022-10-14 23:31:52 +0000797 std::shared_ptr<StreamIn> stream;
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700798 RETURN_STATUS_IF_ERROR(createInputStream(std::move(context), in_args.sinkMetadata,
Lorena Torres-Huertadc9d1a42023-01-18 00:11:48 +0000799 getMicrophoneInfos(), &stream));
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000800 StreamWrapper streamWrapper(stream);
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700801 if (auto patchIt = mPatches.find(in_args.portConfigId); patchIt != mPatches.end()) {
802 RETURN_STATUS_IF_ERROR(
803 streamWrapper.setConnectedDevices(findConnectedDevices(in_args.portConfigId)));
804 }
Mikhail Naganovdf5feba2022-12-15 00:11:14 +0000805 AIBinder_setMinSchedulerPolicy(streamWrapper.getBinder().get(), SCHED_NORMAL,
806 ANDROID_PRIORITY_AUDIO);
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000807 mStreams.insert(port->id, in_args.portConfigId, std::move(streamWrapper));
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000808 _aidl_return->stream = std::move(stream);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000809 return ndk::ScopedAStatus::ok();
810}
811
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000812ndk::ScopedAStatus Module::openOutputStream(const OpenOutputStreamArguments& in_args,
813 OpenOutputStreamReturn* _aidl_return) {
814 LOG(DEBUG) << __func__ << ": port config id " << in_args.portConfigId << ", has offload info? "
815 << (in_args.offloadInfo.has_value()) << ", buffer size " << in_args.bufferSizeFrames
816 << " frames";
817 AudioPort* port = nullptr;
Mikhail Naganov26dc9ad2023-06-23 13:55:37 -0700818 RETURN_STATUS_IF_ERROR(findPortIdForNewStream(in_args.portConfigId, &port));
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000819 if (port->flags.getTag() != AudioIoFlags::Tag::output) {
820 LOG(ERROR) << __func__ << ": port config id " << in_args.portConfigId
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000821 << " does not correspond to an output mix port";
822 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
823 }
Mikhail Naganova2c5ddf2022-09-12 22:57:14 +0000824 const bool isOffload = isBitPositionFlagSet(port->flags.get<AudioIoFlags::Tag::output>(),
825 AudioOutputFlags::COMPRESS_OFFLOAD);
826 if (isOffload && !in_args.offloadInfo.has_value()) {
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000827 LOG(ERROR) << __func__ << ": port id " << port->id
Mikhail Naganov111e0ce2022-06-17 21:41:19 +0000828 << " has COMPRESS_OFFLOAD flag set, requires offload info";
829 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
830 }
Mikhail Naganov30301a42022-09-13 01:20:45 +0000831 const bool isNonBlocking = isBitPositionFlagSet(port->flags.get<AudioIoFlags::Tag::output>(),
832 AudioOutputFlags::NON_BLOCKING);
833 if (isNonBlocking && in_args.callback == nullptr) {
834 LOG(ERROR) << __func__ << ": port id " << port->id
835 << " has NON_BLOCKING flag set, requires async callback";
836 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
837 }
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000838 StreamContext context;
Mikhail Naganov26dc9ad2023-06-23 13:55:37 -0700839 RETURN_STATUS_IF_ERROR(createStreamContext(in_args.portConfigId, in_args.bufferSizeFrames,
840 isNonBlocking ? in_args.callback : nullptr,
841 in_args.eventCallback, &context));
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000842 context.fillDescriptor(&_aidl_return->desc);
Mikhail Naganove9f10fc2022-10-14 23:31:52 +0000843 std::shared_ptr<StreamOut> stream;
Mikhail Naganov6ddefdb2023-07-19 17:30:06 -0700844 RETURN_STATUS_IF_ERROR(createOutputStream(std::move(context), in_args.sourceMetadata,
Mikhail Naganov9d16a6a2023-06-26 17:21:04 -0700845 in_args.offloadInfo, &stream));
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000846 StreamWrapper streamWrapper(stream);
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700847 if (auto patchIt = mPatches.find(in_args.portConfigId); patchIt != mPatches.end()) {
848 RETURN_STATUS_IF_ERROR(
849 streamWrapper.setConnectedDevices(findConnectedDevices(in_args.portConfigId)));
850 }
Mikhail Naganovdf5feba2022-12-15 00:11:14 +0000851 AIBinder_setMinSchedulerPolicy(streamWrapper.getBinder().get(), SCHED_NORMAL,
852 ANDROID_PRIORITY_AUDIO);
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000853 mStreams.insert(port->id, in_args.portConfigId, std::move(streamWrapper));
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000854 _aidl_return->stream = std::move(stream);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000855 return ndk::ScopedAStatus::ok();
856}
857
Mikhail Naganov74927202022-12-19 16:37:14 +0000858ndk::ScopedAStatus Module::getSupportedPlaybackRateFactors(
859 SupportedPlaybackRateFactors* _aidl_return) {
860 LOG(DEBUG) << __func__;
861 (void)_aidl_return;
862 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
863}
864
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000865ndk::ScopedAStatus Module::setAudioPatch(const AudioPatch& in_requested, AudioPatch* _aidl_return) {
Mikhail Naganov16db9b72022-06-17 21:36:18 +0000866 LOG(DEBUG) << __func__ << ": requested patch " << in_requested.toString();
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000867 if (in_requested.sourcePortConfigIds.empty()) {
868 LOG(ERROR) << __func__ << ": requested patch has empty sources list";
869 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
870 }
871 if (!all_unique<int32_t>(in_requested.sourcePortConfigIds)) {
872 LOG(ERROR) << __func__ << ": requested patch has duplicate ids in the sources list";
873 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
874 }
875 if (in_requested.sinkPortConfigIds.empty()) {
876 LOG(ERROR) << __func__ << ": requested patch has empty sinks list";
877 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
878 }
879 if (!all_unique<int32_t>(in_requested.sinkPortConfigIds)) {
880 LOG(ERROR) << __func__ << ": requested patch has duplicate ids in the sinks list";
881 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
882 }
883
884 auto& configs = getConfig().portConfigs;
885 std::vector<int32_t> missingIds;
886 auto sources =
887 selectByIds<AudioPortConfig>(configs, in_requested.sourcePortConfigIds, &missingIds);
888 if (!missingIds.empty()) {
889 LOG(ERROR) << __func__ << ": following source port config ids not found: "
890 << ::android::internal::ToString(missingIds);
891 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
892 }
893 auto sinks = selectByIds<AudioPortConfig>(configs, in_requested.sinkPortConfigIds, &missingIds);
894 if (!missingIds.empty()) {
895 LOG(ERROR) << __func__ << ": following sink port config ids not found: "
896 << ::android::internal::ToString(missingIds);
897 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
898 }
899 // bool indicates whether a non-exclusive route is available.
900 // If only an exclusive route is available, that means the patch can not be
901 // established if there is any other patch which currently uses the sink port.
902 std::map<int32_t, bool> allowedSinkPorts;
903 auto& routes = getConfig().routes;
904 for (auto src : sources) {
905 for (const auto& r : routes) {
906 const auto& srcs = r.sourcePortIds;
907 if (std::find(srcs.begin(), srcs.end(), src->portId) != srcs.end()) {
908 if (!allowedSinkPorts[r.sinkPortId]) { // prefer non-exclusive
909 allowedSinkPorts[r.sinkPortId] = !r.isExclusive;
910 }
911 }
912 }
913 }
914 for (auto sink : sinks) {
915 if (allowedSinkPorts.count(sink->portId) == 0) {
916 LOG(ERROR) << __func__ << ": there is no route to the sink port id " << sink->portId;
917 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
918 }
919 }
Mikhail Naganov26dc9ad2023-06-23 13:55:37 -0700920 RETURN_STATUS_IF_ERROR(checkAudioPatchEndpointsMatch(sources, sinks));
jiabin253bd322023-01-25 23:57:31 +0000921
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000922 auto& patches = getConfig().patches;
923 auto existing = patches.end();
924 std::optional<decltype(mPatches)> patchesBackup;
925 if (in_requested.id != 0) {
926 existing = findById<AudioPatch>(patches, in_requested.id);
927 if (existing != patches.end()) {
928 patchesBackup = mPatches;
929 cleanUpPatch(existing->id);
930 } else {
931 LOG(ERROR) << __func__ << ": not found existing patch id " << in_requested.id;
932 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
933 }
934 }
935 // Validate the requested patch.
936 for (const auto& [sinkPortId, nonExclusive] : allowedSinkPorts) {
937 if (!nonExclusive && mPatches.count(sinkPortId) != 0) {
938 LOG(ERROR) << __func__ << ": sink port id " << sinkPortId
939 << "is exclusive and is already used by some other patch";
940 if (patchesBackup.has_value()) {
941 mPatches = std::move(*patchesBackup);
942 }
943 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
944 }
945 }
946 *_aidl_return = in_requested;
Mikhail Naganov6a4872d2022-06-15 21:39:04 +0000947 _aidl_return->minimumStreamBufferSizeFrames = kMinimumStreamBufferSizeFrames;
948 _aidl_return->latenciesMs.clear();
949 _aidl_return->latenciesMs.insert(_aidl_return->latenciesMs.end(),
950 _aidl_return->sinkPortConfigIds.size(), kLatencyMs);
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000951 AudioPatch oldPatch{};
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000952 if (existing == patches.end()) {
953 _aidl_return->id = getConfig().nextPatchId++;
954 patches.push_back(*_aidl_return);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000955 } else {
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000956 oldPatch = *existing;
Mikhail Naganovdc417732023-09-29 15:49:35 -0700957 *existing = *_aidl_return;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000958 }
Mikhail Naganov75b59df2023-06-23 13:39:40 -0700959 patchesBackup = mPatches;
960 registerPatch(*_aidl_return);
961 if (auto status = updateStreamsConnectedState(oldPatch, *_aidl_return); !status.isOk()) {
962 mPatches = std::move(*patchesBackup);
963 if (existing == patches.end()) {
964 patches.pop_back();
965 } else {
966 *existing = oldPatch;
967 }
968 return status;
969 }
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +0000970
971 LOG(DEBUG) << __func__ << ": " << (oldPatch.id == 0 ? "created" : "updated") << " patch "
972 << _aidl_return->toString();
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000973 return ndk::ScopedAStatus::ok();
974}
975
976ndk::ScopedAStatus Module::setAudioPortConfig(const AudioPortConfig& in_requested,
977 AudioPortConfig* out_suggested, bool* _aidl_return) {
978 LOG(DEBUG) << __func__ << ": requested " << in_requested.toString();
979 auto& configs = getConfig().portConfigs;
980 auto existing = configs.end();
981 if (in_requested.id != 0) {
982 if (existing = findById<AudioPortConfig>(configs, in_requested.id);
983 existing == configs.end()) {
984 LOG(ERROR) << __func__ << ": existing port config id " << in_requested.id
985 << " not found";
986 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
987 }
988 }
989
990 const int portId = existing != configs.end() ? existing->portId : in_requested.portId;
991 if (portId == 0) {
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700992 LOG(ERROR) << __func__ << ": requested port config does not specify portId";
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +0000993 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
994 }
995 auto& ports = getConfig().ports;
996 auto portIt = findById<AudioPort>(ports, portId);
997 if (portIt == ports.end()) {
Mikhail Naganov84bcc042023-10-05 17:36:57 -0700998 LOG(ERROR) << __func__ << ": requested port config points to non-existent portId "
999 << portId;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001000 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1001 }
1002 if (existing != configs.end()) {
1003 *out_suggested = *existing;
1004 } else {
1005 AudioPortConfig newConfig;
1006 if (generateDefaultPortConfig(*portIt, &newConfig)) {
1007 *out_suggested = newConfig;
1008 } else {
1009 LOG(ERROR) << __func__ << ": unable generate a default config for port " << portId;
1010 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1011 }
1012 }
1013 // From this moment, 'out_suggested' is either an existing port config,
1014 // or a new generated config. Now attempt to update it according to the specified
1015 // fields of 'in_requested'.
1016
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001017 // Device ports with only dynamic profiles are used for devices that are connected via ADSP,
1018 // which takes care of their actual configuration automatically.
1019 const bool allowDynamicConfig = portIt->ext.getTag() == AudioPortExt::device &&
1020 hasDynamicProfilesOnly(portIt->profiles);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001021 bool requestedIsValid = true, requestedIsFullySpecified = true;
1022
1023 AudioIoFlags portFlags = portIt->flags;
1024 if (in_requested.flags.has_value()) {
1025 if (in_requested.flags.value() != portFlags) {
1026 LOG(WARNING) << __func__ << ": requested flags "
1027 << in_requested.flags.value().toString() << " do not match port's "
1028 << portId << " flags " << portFlags.toString();
1029 requestedIsValid = false;
1030 }
1031 } else {
1032 requestedIsFullySpecified = false;
1033 }
1034
1035 AudioProfile portProfile;
1036 if (in_requested.format.has_value()) {
1037 const auto& format = in_requested.format.value();
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001038 if ((format == AudioFormatDescription{} && allowDynamicConfig) ||
1039 findAudioProfile(*portIt, format, &portProfile)) {
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001040 out_suggested->format = format;
1041 } else {
1042 LOG(WARNING) << __func__ << ": requested format " << format.toString()
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001043 << " is not found in the profiles of port " << portId;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001044 requestedIsValid = false;
1045 }
1046 } else {
1047 requestedIsFullySpecified = false;
1048 }
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001049 if (!(out_suggested->format.value() == AudioFormatDescription{} && allowDynamicConfig) &&
1050 !findAudioProfile(*portIt, out_suggested->format.value(), &portProfile)) {
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001051 LOG(ERROR) << __func__ << ": port " << portId << " does not support format "
1052 << out_suggested->format.value().toString() << " anymore";
1053 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1054 }
1055
1056 if (in_requested.channelMask.has_value()) {
1057 const auto& channelMask = in_requested.channelMask.value();
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001058 if ((channelMask == AudioChannelLayout{} && allowDynamicConfig) ||
1059 find(portProfile.channelMasks.begin(), portProfile.channelMasks.end(), channelMask) !=
1060 portProfile.channelMasks.end()) {
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001061 out_suggested->channelMask = channelMask;
1062 } else {
1063 LOG(WARNING) << __func__ << ": requested channel mask " << channelMask.toString()
1064 << " is not supported for the format " << portProfile.format.toString()
1065 << " by the port " << portId;
1066 requestedIsValid = false;
1067 }
1068 } else {
1069 requestedIsFullySpecified = false;
1070 }
1071
1072 if (in_requested.sampleRate.has_value()) {
1073 const auto& sampleRate = in_requested.sampleRate.value();
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001074 if ((sampleRate.value == 0 && allowDynamicConfig) ||
1075 find(portProfile.sampleRates.begin(), portProfile.sampleRates.end(),
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001076 sampleRate.value) != portProfile.sampleRates.end()) {
1077 out_suggested->sampleRate = sampleRate;
1078 } else {
1079 LOG(WARNING) << __func__ << ": requested sample rate " << sampleRate.value
1080 << " is not supported for the format " << portProfile.format.toString()
1081 << " by the port " << portId;
1082 requestedIsValid = false;
1083 }
1084 } else {
1085 requestedIsFullySpecified = false;
1086 }
1087
1088 if (in_requested.gain.has_value()) {
1089 // Let's pretend that gain can always be applied.
1090 out_suggested->gain = in_requested.gain.value();
1091 }
1092
Mikhail Naganov248e9502023-02-21 16:32:40 -08001093 if (in_requested.ext.getTag() != AudioPortExt::Tag::unspecified) {
1094 if (in_requested.ext.getTag() == out_suggested->ext.getTag()) {
1095 if (out_suggested->ext.getTag() == AudioPortExt::Tag::mix) {
1096 // 'AudioMixPortExt.handle' is set by the client, copy from in_requested
1097 out_suggested->ext.get<AudioPortExt::Tag::mix>().handle =
1098 in_requested.ext.get<AudioPortExt::Tag::mix>().handle;
1099 }
1100 } else {
1101 LOG(WARNING) << __func__ << ": requested ext tag "
1102 << toString(in_requested.ext.getTag()) << " do not match port's tag "
1103 << toString(out_suggested->ext.getTag());
1104 requestedIsValid = false;
1105 }
1106 }
1107
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001108 if (existing == configs.end() && requestedIsValid && requestedIsFullySpecified) {
1109 out_suggested->id = getConfig().nextPortId++;
1110 configs.push_back(*out_suggested);
1111 *_aidl_return = true;
1112 LOG(DEBUG) << __func__ << ": created new port config " << out_suggested->toString();
1113 } else if (existing != configs.end() && requestedIsValid) {
1114 *existing = *out_suggested;
1115 *_aidl_return = true;
1116 LOG(DEBUG) << __func__ << ": updated port config " << out_suggested->toString();
1117 } else {
1118 LOG(DEBUG) << __func__ << ": not applied; existing config ? " << (existing != configs.end())
1119 << "; requested is valid? " << requestedIsValid << ", fully specified? "
1120 << requestedIsFullySpecified;
1121 *_aidl_return = false;
1122 }
1123 return ndk::ScopedAStatus::ok();
1124}
1125
1126ndk::ScopedAStatus Module::resetAudioPatch(int32_t in_patchId) {
1127 auto& patches = getConfig().patches;
1128 auto patchIt = findById<AudioPatch>(patches, in_patchId);
1129 if (patchIt != patches.end()) {
Mikhail Naganov75b59df2023-06-23 13:39:40 -07001130 auto patchesBackup = mPatches;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001131 cleanUpPatch(patchIt->id);
Mikhail Naganov75b59df2023-06-23 13:39:40 -07001132 if (auto status = updateStreamsConnectedState(*patchIt, AudioPatch{}); !status.isOk()) {
1133 mPatches = std::move(patchesBackup);
1134 return status;
1135 }
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001136 patches.erase(patchIt);
1137 LOG(DEBUG) << __func__ << ": erased patch " << in_patchId;
1138 return ndk::ScopedAStatus::ok();
1139 }
1140 LOG(ERROR) << __func__ << ": patch id " << in_patchId << " not found";
1141 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1142}
1143
1144ndk::ScopedAStatus Module::resetAudioPortConfig(int32_t in_portConfigId) {
1145 auto& configs = getConfig().portConfigs;
1146 auto configIt = findById<AudioPortConfig>(configs, in_portConfigId);
1147 if (configIt != configs.end()) {
1148 if (mStreams.count(in_portConfigId) != 0) {
1149 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
1150 << " has a stream opened on it";
1151 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
1152 }
1153 auto patchIt = mPatches.find(in_portConfigId);
1154 if (patchIt != mPatches.end()) {
1155 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId
1156 << " is used by the patch with id " << patchIt->second;
1157 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
1158 }
1159 auto& initials = getConfig().initialConfigs;
1160 auto initialIt = findById<AudioPortConfig>(initials, in_portConfigId);
1161 if (initialIt == initials.end()) {
1162 configs.erase(configIt);
1163 LOG(DEBUG) << __func__ << ": erased port config " << in_portConfigId;
1164 } else if (*configIt != *initialIt) {
1165 *configIt = *initialIt;
1166 LOG(DEBUG) << __func__ << ": reset port config " << in_portConfigId;
1167 }
1168 return ndk::ScopedAStatus::ok();
1169 }
1170 LOG(ERROR) << __func__ << ": port config id " << in_portConfigId << " not found";
1171 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1172}
1173
Mikhail Naganov3b125b72022-10-05 02:12:39 +00001174ndk::ScopedAStatus Module::getMasterMute(bool* _aidl_return) {
1175 *_aidl_return = mMasterMute;
1176 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1177 return ndk::ScopedAStatus::ok();
1178}
1179
1180ndk::ScopedAStatus Module::setMasterMute(bool in_mute) {
1181 LOG(DEBUG) << __func__ << ": " << in_mute;
jiabin783c48b2023-02-28 18:28:06 +00001182 auto result = mDebug.simulateDeviceConnections ? ndk::ScopedAStatus::ok()
1183 : onMasterMuteChanged(in_mute);
1184 if (result.isOk()) {
1185 mMasterMute = in_mute;
1186 } else {
1187 LOG(ERROR) << __func__ << ": failed calling onMasterMuteChanged(" << in_mute
1188 << "), error=" << result;
1189 // Reset master mute if it failed.
1190 onMasterMuteChanged(mMasterMute);
1191 }
1192 return std::move(result);
Mikhail Naganov3b125b72022-10-05 02:12:39 +00001193}
1194
1195ndk::ScopedAStatus Module::getMasterVolume(float* _aidl_return) {
1196 *_aidl_return = mMasterVolume;
1197 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1198 return ndk::ScopedAStatus::ok();
1199}
1200
1201ndk::ScopedAStatus Module::setMasterVolume(float in_volume) {
1202 LOG(DEBUG) << __func__ << ": " << in_volume;
1203 if (in_volume >= 0.0f && in_volume <= 1.0f) {
jiabin783c48b2023-02-28 18:28:06 +00001204 auto result = mDebug.simulateDeviceConnections ? ndk::ScopedAStatus::ok()
1205 : onMasterVolumeChanged(in_volume);
1206 if (result.isOk()) {
1207 mMasterVolume = in_volume;
1208 } else {
1209 // Reset master volume if it failed.
1210 LOG(ERROR) << __func__ << ": failed calling onMasterVolumeChanged(" << in_volume
1211 << "), error=" << result;
1212 onMasterVolumeChanged(mMasterVolume);
1213 }
1214 return std::move(result);
Mikhail Naganov3b125b72022-10-05 02:12:39 +00001215 }
1216 LOG(ERROR) << __func__ << ": invalid master volume value: " << in_volume;
1217 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1218}
1219
1220ndk::ScopedAStatus Module::getMicMute(bool* _aidl_return) {
1221 *_aidl_return = mMicMute;
1222 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1223 return ndk::ScopedAStatus::ok();
1224}
1225
1226ndk::ScopedAStatus Module::setMicMute(bool in_mute) {
1227 LOG(DEBUG) << __func__ << ": " << in_mute;
1228 mMicMute = in_mute;
1229 return ndk::ScopedAStatus::ok();
1230}
1231
Mikhail Naganovef6bc742022-10-06 00:14:19 +00001232ndk::ScopedAStatus Module::getMicrophones(std::vector<MicrophoneInfo>* _aidl_return) {
Lorena Torres-Huertadc9d1a42023-01-18 00:11:48 +00001233 *_aidl_return = getMicrophoneInfos();
Mikhail Naganovef6bc742022-10-06 00:14:19 +00001234 LOG(DEBUG) << __func__ << ": returning " << ::android::internal::ToString(*_aidl_return);
1235 return ndk::ScopedAStatus::ok();
1236}
1237
Mikhail Naganov3b125b72022-10-05 02:12:39 +00001238ndk::ScopedAStatus Module::updateAudioMode(AudioMode in_mode) {
Mikhail Naganov04ae8222023-01-11 15:48:10 -08001239 if (!isValidAudioMode(in_mode)) {
1240 LOG(ERROR) << __func__ << ": invalid mode " << toString(in_mode);
1241 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1242 }
Mikhail Naganov3b125b72022-10-05 02:12:39 +00001243 // No checks for supported audio modes here, it's an informative notification.
1244 LOG(DEBUG) << __func__ << ": " << toString(in_mode);
1245 return ndk::ScopedAStatus::ok();
1246}
1247
1248ndk::ScopedAStatus Module::updateScreenRotation(ScreenRotation in_rotation) {
1249 LOG(DEBUG) << __func__ << ": " << toString(in_rotation);
1250 return ndk::ScopedAStatus::ok();
1251}
1252
1253ndk::ScopedAStatus Module::updateScreenState(bool in_isTurnedOn) {
1254 LOG(DEBUG) << __func__ << ": " << in_isTurnedOn;
1255 return ndk::ScopedAStatus::ok();
1256}
1257
Vlad Popa83a6d822022-11-07 13:53:57 +01001258ndk::ScopedAStatus Module::getSoundDose(std::shared_ptr<ISoundDose>* _aidl_return) {
Mikhail Naganov7499a002023-02-27 18:51:44 -08001259 if (!mSoundDose) {
Vlad Popa2afbd1e2022-12-28 17:04:58 +01001260 mSoundDose = ndk::SharedRefBase::make<sounddose::SoundDose>();
Vlad Popa943b7e22022-12-08 14:24:12 +01001261 }
Mikhail Naganov780fefb2023-07-21 17:01:38 -07001262 *_aidl_return = mSoundDose.getInstance();
Vlad Popa943b7e22022-12-08 14:24:12 +01001263 LOG(DEBUG) << __func__ << ": returning instance of ISoundDose: " << _aidl_return->get();
Vlad Popa83a6d822022-11-07 13:53:57 +01001264 return ndk::ScopedAStatus::ok();
1265}
1266
Mikhail Naganove9f10fc2022-10-14 23:31:52 +00001267ndk::ScopedAStatus Module::generateHwAvSyncId(int32_t* _aidl_return) {
1268 LOG(DEBUG) << __func__;
1269 (void)_aidl_return;
1270 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1271}
1272
Mikhail Naganov20047bc2023-01-05 20:16:07 +00001273const std::string Module::VendorDebug::kForceTransientBurstName = "aosp.forceTransientBurst";
Mikhail Naganov194daaa2023-01-05 22:34:20 +00001274const std::string Module::VendorDebug::kForceSynchronousDrainName = "aosp.forceSynchronousDrain";
Mikhail Naganov20047bc2023-01-05 20:16:07 +00001275
Mikhail Naganove9f10fc2022-10-14 23:31:52 +00001276ndk::ScopedAStatus Module::getVendorParameters(const std::vector<std::string>& in_ids,
1277 std::vector<VendorParameter>* _aidl_return) {
1278 LOG(DEBUG) << __func__ << ": id count: " << in_ids.size();
Mikhail Naganov20047bc2023-01-05 20:16:07 +00001279 bool allParametersKnown = true;
1280 for (const auto& id : in_ids) {
1281 if (id == VendorDebug::kForceTransientBurstName) {
1282 VendorParameter forceTransientBurst{.id = id};
1283 forceTransientBurst.ext.setParcelable(Boolean{mVendorDebug.forceTransientBurst});
1284 _aidl_return->push_back(std::move(forceTransientBurst));
Mikhail Naganov194daaa2023-01-05 22:34:20 +00001285 } else if (id == VendorDebug::kForceSynchronousDrainName) {
1286 VendorParameter forceSynchronousDrain{.id = id};
1287 forceSynchronousDrain.ext.setParcelable(Boolean{mVendorDebug.forceSynchronousDrain});
1288 _aidl_return->push_back(std::move(forceSynchronousDrain));
Mikhail Naganov20047bc2023-01-05 20:16:07 +00001289 } else {
1290 allParametersKnown = false;
1291 LOG(ERROR) << __func__ << ": unrecognized parameter \"" << id << "\"";
1292 }
1293 }
1294 if (allParametersKnown) return ndk::ScopedAStatus::ok();
1295 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Mikhail Naganove9f10fc2022-10-14 23:31:52 +00001296}
1297
Mikhail Naganov194daaa2023-01-05 22:34:20 +00001298namespace {
1299
1300template <typename W>
1301bool extractParameter(const VendorParameter& p, decltype(W::value)* v) {
1302 std::optional<W> value;
1303 binder_status_t result = p.ext.getParcelable(&value);
1304 if (result == STATUS_OK && value.has_value()) {
1305 *v = value.value().value;
1306 return true;
1307 }
1308 LOG(ERROR) << __func__ << ": failed to read the value of the parameter \"" << p.id
1309 << "\": " << result;
1310 return false;
1311}
1312
1313} // namespace
1314
Mikhail Naganove9f10fc2022-10-14 23:31:52 +00001315ndk::ScopedAStatus Module::setVendorParameters(const std::vector<VendorParameter>& in_parameters,
1316 bool in_async) {
1317 LOG(DEBUG) << __func__ << ": parameter count " << in_parameters.size()
1318 << ", async: " << in_async;
Mikhail Naganov20047bc2023-01-05 20:16:07 +00001319 bool allParametersKnown = true;
1320 for (const auto& p : in_parameters) {
1321 if (p.id == VendorDebug::kForceTransientBurstName) {
Mikhail Naganov194daaa2023-01-05 22:34:20 +00001322 if (!extractParameter<Boolean>(p, &mVendorDebug.forceTransientBurst)) {
1323 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1324 }
1325 } else if (p.id == VendorDebug::kForceSynchronousDrainName) {
1326 if (!extractParameter<Boolean>(p, &mVendorDebug.forceSynchronousDrain)) {
Mikhail Naganov20047bc2023-01-05 20:16:07 +00001327 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1328 }
1329 } else {
1330 allParametersKnown = false;
1331 LOG(ERROR) << __func__ << ": unrecognized parameter \"" << p.id << "\"";
1332 }
1333 }
1334 if (allParametersKnown) return ndk::ScopedAStatus::ok();
1335 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
Mikhail Naganove9f10fc2022-10-14 23:31:52 +00001336}
1337
Mikhail Naganovfb1acde2022-12-12 18:57:36 +00001338ndk::ScopedAStatus Module::addDeviceEffect(
1339 int32_t in_portConfigId,
1340 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_effect) {
1341 if (in_effect == nullptr) {
1342 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", null effect";
1343 } else {
1344 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", effect Binder "
1345 << in_effect->asBinder().get();
1346 }
1347 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1348}
1349
1350ndk::ScopedAStatus Module::removeDeviceEffect(
1351 int32_t in_portConfigId,
1352 const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& in_effect) {
1353 if (in_effect == nullptr) {
1354 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", null effect";
1355 } else {
1356 LOG(DEBUG) << __func__ << ": port id " << in_portConfigId << ", effect Binder "
1357 << in_effect->asBinder().get();
1358 }
1359 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1360}
1361
jiabin9a8e6862023-01-12 23:06:37 +00001362ndk::ScopedAStatus Module::getMmapPolicyInfos(AudioMMapPolicyType mmapPolicyType,
1363 std::vector<AudioMMapPolicyInfo>* _aidl_return) {
1364 LOG(DEBUG) << __func__ << ": mmap policy type " << toString(mmapPolicyType);
1365 std::set<int32_t> mmapSinks;
1366 std::set<int32_t> mmapSources;
1367 auto& ports = getConfig().ports;
1368 for (const auto& port : ports) {
1369 if (port.flags.getTag() == AudioIoFlags::Tag::input &&
1370 isBitPositionFlagSet(port.flags.get<AudioIoFlags::Tag::input>(),
1371 AudioInputFlags::MMAP_NOIRQ)) {
1372 mmapSinks.insert(port.id);
1373 } else if (port.flags.getTag() == AudioIoFlags::Tag::output &&
1374 isBitPositionFlagSet(port.flags.get<AudioIoFlags::Tag::output>(),
1375 AudioOutputFlags::MMAP_NOIRQ)) {
1376 mmapSources.insert(port.id);
1377 }
1378 }
Mikhail Naganov85064912023-09-26 17:10:08 -07001379 if (mmapSources.empty() && mmapSinks.empty()) {
1380 AudioMMapPolicyInfo never;
1381 never.mmapPolicy = AudioMMapPolicy::NEVER;
1382 _aidl_return->push_back(never);
1383 return ndk::ScopedAStatus::ok();
1384 }
jiabin9a8e6862023-01-12 23:06:37 +00001385 for (const auto& route : getConfig().routes) {
1386 if (mmapSinks.count(route.sinkPortId) != 0) {
1387 // The sink is a mix port, add the sources if they are device ports.
1388 for (int sourcePortId : route.sourcePortIds) {
1389 auto sourcePortIt = findById<AudioPort>(ports, sourcePortId);
1390 if (sourcePortIt == ports.end()) {
1391 // This must not happen
1392 LOG(ERROR) << __func__ << ": port id " << sourcePortId << " cannot be found";
1393 continue;
1394 }
1395 if (sourcePortIt->ext.getTag() != AudioPortExt::Tag::device) {
1396 // The source is not a device port, skip
1397 continue;
1398 }
1399 AudioMMapPolicyInfo policyInfo;
1400 policyInfo.device = sourcePortIt->ext.get<AudioPortExt::Tag::device>().device;
1401 // Always return AudioMMapPolicy.AUTO if the device supports mmap for
1402 // default implementation.
1403 policyInfo.mmapPolicy = AudioMMapPolicy::AUTO;
1404 _aidl_return->push_back(policyInfo);
1405 }
1406 } else {
1407 auto sinkPortIt = findById<AudioPort>(ports, route.sinkPortId);
1408 if (sinkPortIt == ports.end()) {
1409 // This must not happen
1410 LOG(ERROR) << __func__ << ": port id " << route.sinkPortId << " cannot be found";
1411 continue;
1412 }
1413 if (sinkPortIt->ext.getTag() != AudioPortExt::Tag::device) {
1414 // The sink is not a device port, skip
1415 continue;
1416 }
1417 if (count_any(mmapSources, route.sourcePortIds)) {
1418 AudioMMapPolicyInfo policyInfo;
1419 policyInfo.device = sinkPortIt->ext.get<AudioPortExt::Tag::device>().device;
1420 // Always return AudioMMapPolicy.AUTO if the device supports mmap for
1421 // default implementation.
1422 policyInfo.mmapPolicy = AudioMMapPolicy::AUTO;
1423 _aidl_return->push_back(policyInfo);
1424 }
1425 }
1426 }
1427 return ndk::ScopedAStatus::ok();
1428}
1429
Eric Laurente2432ea2023-01-12 17:47:31 +01001430ndk::ScopedAStatus Module::supportsVariableLatency(bool* _aidl_return) {
1431 LOG(DEBUG) << __func__;
1432 *_aidl_return = false;
1433 return ndk::ScopedAStatus::ok();
1434}
1435
jiabinb76981e2023-01-18 00:58:30 +00001436ndk::ScopedAStatus Module::getAAudioMixerBurstCount(int32_t* _aidl_return) {
1437 if (!isMmapSupported()) {
1438 LOG(DEBUG) << __func__ << ": mmap is not supported ";
1439 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1440 }
1441 *_aidl_return = DEFAULT_AAUDIO_MIXER_BURST_COUNT;
1442 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1443 return ndk::ScopedAStatus::ok();
1444}
1445
1446ndk::ScopedAStatus Module::getAAudioHardwareBurstMinUsec(int32_t* _aidl_return) {
1447 if (!isMmapSupported()) {
1448 LOG(DEBUG) << __func__ << ": mmap is not supported ";
1449 return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
1450 }
1451 *_aidl_return = DEFAULT_AAUDIO_HARDWARE_BURST_MIN_DURATION_US;
1452 LOG(DEBUG) << __func__ << ": returning " << *_aidl_return;
1453 return ndk::ScopedAStatus::ok();
1454}
1455
1456bool Module::isMmapSupported() {
1457 if (mIsMmapSupported.has_value()) {
1458 return mIsMmapSupported.value();
1459 }
1460 std::vector<AudioMMapPolicyInfo> mmapPolicyInfos;
1461 if (!getMmapPolicyInfos(AudioMMapPolicyType::DEFAULT, &mmapPolicyInfos).isOk()) {
1462 mIsMmapSupported = false;
1463 } else {
1464 mIsMmapSupported =
1465 std::find_if(mmapPolicyInfos.begin(), mmapPolicyInfos.end(), [](const auto& info) {
1466 return info.mmapPolicy == AudioMMapPolicy::AUTO ||
1467 info.mmapPolicy == AudioMMapPolicy::ALWAYS;
1468 }) != mmapPolicyInfos.end();
1469 }
1470 return mIsMmapSupported.value();
1471}
1472
Mikhail Naganov84bcc042023-10-05 17:36:57 -07001473ndk::ScopedAStatus Module::populateConnectedDevicePort(AudioPort* audioPort) {
1474 if (audioPort->ext.getTag() != AudioPortExt::device) {
1475 LOG(ERROR) << __func__ << ": not a device port: " << audioPort->toString();
1476 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_ARGUMENT);
1477 }
1478 const auto& devicePort = audioPort->ext.get<AudioPortExt::device>();
1479 if (!devicePort.device.type.connection.empty()) {
1480 LOG(ERROR) << __func__
1481 << ": module implementation must override 'populateConnectedDevicePort' "
1482 << "to handle connection of external devices.";
1483 return ndk::ScopedAStatus::fromExceptionCode(EX_ILLEGAL_STATE);
1484 }
jiabin116d8392023-03-01 22:52:57 +00001485 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
jiabin253bd322023-01-25 23:57:31 +00001486 return ndk::ScopedAStatus::ok();
1487}
1488
1489ndk::ScopedAStatus Module::checkAudioPatchEndpointsMatch(
1490 const std::vector<AudioPortConfig*>& sources __unused,
1491 const std::vector<AudioPortConfig*>& sinks __unused) {
jiabin116d8392023-03-01 22:52:57 +00001492 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
jiabin253bd322023-01-25 23:57:31 +00001493 return ndk::ScopedAStatus::ok();
1494}
1495
jiabin783c48b2023-02-28 18:28:06 +00001496void Module::onExternalDeviceConnectionChanged(
1497 const ::aidl::android::media::audio::common::AudioPort& audioPort __unused,
1498 bool connected __unused) {
1499 LOG(DEBUG) << __func__ << ": do nothing and return";
1500}
1501
1502ndk::ScopedAStatus Module::onMasterMuteChanged(bool mute __unused) {
1503 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
1504 return ndk::ScopedAStatus::ok();
1505}
1506
1507ndk::ScopedAStatus Module::onMasterVolumeChanged(float volume __unused) {
1508 LOG(VERBOSE) << __func__ << ": do nothing and return ok";
1509 return ndk::ScopedAStatus::ok();
1510}
1511
Lorena Torres-Huertadc9d1a42023-01-18 00:11:48 +00001512std::vector<MicrophoneInfo> Module::getMicrophoneInfos() {
1513 std::vector<MicrophoneInfo> result;
1514 Configuration& config = getConfig();
1515 for (const AudioPort& port : config.ports) {
1516 if (port.ext.getTag() == AudioPortExt::Tag::device) {
1517 const AudioDeviceType deviceType =
1518 port.ext.get<AudioPortExt::Tag::device>().device.type.type;
1519 if (deviceType == AudioDeviceType::IN_MICROPHONE ||
1520 deviceType == AudioDeviceType::IN_MICROPHONE_BACK) {
1521 // Placeholder values. Vendor implementations must populate MicrophoneInfo
1522 // accordingly based on their physical microphone parameters.
1523 result.push_back(MicrophoneInfo{
1524 .id = port.name,
1525 .device = port.ext.get<AudioPortExt::Tag::device>().device,
1526 .group = 0,
1527 .indexInTheGroup = 0,
1528 });
1529 }
1530 }
1531 }
1532 return result;
1533}
1534
Ram Mohan18f0d512023-07-01 00:47:09 +05301535Module::BtProfileHandles Module::getBtProfileManagerHandles() {
1536 return std::make_tuple(std::weak_ptr<IBluetooth>(), std::weak_ptr<IBluetoothA2dp>(),
1537 std::weak_ptr<IBluetoothLe>());
1538}
1539
1540ndk::ScopedAStatus Module::bluetoothParametersUpdated() {
1541 return mStreams.bluetoothParametersUpdated();
1542}
1543
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001544} // namespace aidl::android::hardware::audio::core