1 /*
2  * Copyright (C) 2018 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 <log/log.h>
18 #include <system/audio.h>
19 #include PATH(APM_XSD_ENUMS_H_FILENAME)
20 #include "primary_device.h"
21 #include "stream_in.h"
22 #include "stream_out.h"
23 #include "talsa.h"
24 #include "util.h"
25 #include "debug.h"
26 
27 namespace xsd {
28 using namespace ::android::audio::policy::configuration::CPP_VERSION;
29 }
30 
31 namespace android {
32 namespace hardware {
33 namespace audio {
34 namespace CPP_VERSION {
35 namespace implementation {
36 
37 constexpr size_t kInBufferDurationMs = 15;
38 constexpr size_t kOutBufferDurationMs = 22;
39 
40 using ::android::hardware::Void;
41 
Device()42 Device::Device() {}
43 
initCheck()44 Return<Result> Device::initCheck() {
45     return Result::OK;
46 }
47 
setMasterVolume(float volume)48 Return<Result> Device::setMasterVolume(float volume) {
49     if (isnan(volume) || volume < 0 || volume > 1.0) {
50         return FAILURE(Result::INVALID_ARGUMENTS);
51     }
52 
53     mMasterVolume = volume;
54     updateOutputStreamVolume(mMasterMute ? 0.0f : volume);
55     return Result::OK;
56 }
57 
getMasterVolume(getMasterVolume_cb _hidl_cb)58 Return<void> Device::getMasterVolume(getMasterVolume_cb _hidl_cb) {
59     _hidl_cb(Result::OK, mMasterVolume);
60     return Void();
61 }
62 
setMicMute(bool mute)63 Return<Result> Device::setMicMute(bool mute) {
64     mMicMute = mute;
65     updateInputStreamMicMute(mute);
66     return Result::OK;
67 }
68 
getMicMute(getMicMute_cb _hidl_cb)69 Return<void> Device::getMicMute(getMicMute_cb _hidl_cb) {
70     _hidl_cb(Result::OK, mMicMute);
71     return Void();
72 }
73 
setMasterMute(bool mute)74 Return<Result> Device::setMasterMute(bool mute) {
75     mMasterMute = mute;
76     updateOutputStreamVolume(mute ? 0.0f : mMasterVolume);
77     return Result::OK;
78 }
79 
getMasterMute(getMasterMute_cb _hidl_cb)80 Return<void> Device::getMasterMute(getMasterMute_cb _hidl_cb) {
81     _hidl_cb(Result::OK, mMasterMute);
82     return Void();
83 }
84 
getInputBufferSize(const AudioConfig & config,getInputBufferSize_cb _hidl_cb)85 Return<void> Device::getInputBufferSize(const AudioConfig& config, getInputBufferSize_cb _hidl_cb) {
86     AudioConfig suggestedConfig;
87     if (util::checkAudioConfig(false, kInBufferDurationMs,
88                                talsa::pcmGetPcmPeriodSettings().periodCount,
89                                config, suggestedConfig)) {
90         const size_t sz =
91             suggestedConfig.frameCount
92             * util::countChannels(suggestedConfig.base.channelMask)
93             * util::getBytesPerSample(suggestedConfig.base.format);
94 
95         _hidl_cb(Result::OK, sz);
96     } else {
97         _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), 0);
98     }
99 
100     return Void();
101 }
102 
openOutputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SourceMetadata & sourceMetadata,openOutputStream_cb _hidl_cb)103 Return<void> Device::openOutputStream(int32_t ioHandle,
104                                       const DeviceAddress& device,
105                                       const AudioConfig& config,
106                                       const hidl_vec<AudioInOutFlag>& flags,
107                                       const SourceMetadata& sourceMetadata,
108                                       openOutputStream_cb _hidl_cb) {
109     auto [result, stream, cfg] = openOutputStreamImpl(ioHandle, device,
110             config, flags, sourceMetadata);
111     _hidl_cb(result, stream, cfg);
112     return Void();
113 }
114 
openInputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SinkMetadata & sinkMetadata,openInputStream_cb _hidl_cb)115 Return<void> Device::openInputStream(int32_t ioHandle,
116                                      const DeviceAddress& device,
117                                      const AudioConfig& config,
118                                      const hidl_vec<AudioInOutFlag>& flags,
119                                      const SinkMetadata& sinkMetadata,
120                                      openInputStream_cb _hidl_cb) {
121     auto [result, stream, cfg] = openInputStreamImpl(ioHandle, device,
122             config, flags, sinkMetadata);
123     _hidl_cb(result, stream, cfg);
124     return Void();
125 }
126 
supportsAudioPatches()127 Return<bool> Device::supportsAudioPatches() {
128     return true;
129 }
130 
createAudioPatch(const hidl_vec<AudioPortConfig> & sources,const hidl_vec<AudioPortConfig> & sinks,createAudioPatch_cb _hidl_cb)131 Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
132                                       const hidl_vec<AudioPortConfig>& sinks,
133                                       createAudioPatch_cb _hidl_cb) {
134     if (sources.size() == 1 && sinks.size() == 1) {
135         AudioPatch patch;
136         if (!util::checkAudioPortConfig(sources[0]) || !util::checkAudioPortConfig(sinks[0])) {
137             _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), 0);
138             return Void();
139         }
140         patch.source = sources[0];
141         patch.sink = sinks[0];
142 
143         AudioPatchHandle handle;
144         while (true) {
145             handle = mNextAudioPatchHandle;
146             mNextAudioPatchHandle = std::max(handle + 1, 0);
147             if (mAudioPatches.insert({handle, patch}).second) {
148                 break;
149             }
150         }
151 
152         _hidl_cb(Result::OK, handle);
153     } else {
154         _hidl_cb(FAILURE(Result::NOT_SUPPORTED), 0);
155     }
156 
157     return Void();
158 }
159 
updateAudioPatch(AudioPatchHandle previousPatchHandle,const hidl_vec<AudioPortConfig> & sources,const hidl_vec<AudioPortConfig> & sinks,updateAudioPatch_cb _hidl_cb)160 Return<void> Device::updateAudioPatch(AudioPatchHandle previousPatchHandle,
161                                       const hidl_vec<AudioPortConfig>& sources,
162                                       const hidl_vec<AudioPortConfig>& sinks,
163                                       updateAudioPatch_cb _hidl_cb) {
164     const auto i = mAudioPatches.find(previousPatchHandle);
165     if (i == mAudioPatches.end()) {
166         _hidl_cb(FAILURE(Result::INVALID_ARGUMENTS), previousPatchHandle);
167     } else {
168         if (sources.size() == 1 && sinks.size() == 1) {
169             AudioPatch patch;
170             patch.source = sources[0];
171             patch.sink = sinks[0];
172             i->second = patch;
173 
174             _hidl_cb(Result::OK, previousPatchHandle);
175         } else {
176             _hidl_cb(Result::NOT_SUPPORTED, previousPatchHandle);
177         }
178     }
179 
180     return Void();
181 }
182 
releaseAudioPatch(AudioPatchHandle patchHandle)183 Return<Result> Device::releaseAudioPatch(AudioPatchHandle patchHandle) {
184     return (mAudioPatches.erase(patchHandle) == 1) ? Result::OK : FAILURE(Result::INVALID_ARGUMENTS);
185 }
186 
getAudioPort(const AudioPort & port,getAudioPort_cb _hidl_cb)187 Return<void> Device::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) {
188     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), port);
189     return Void();
190 }
191 
setAudioPortConfig(const AudioPortConfig & config)192 Return<Result> Device::setAudioPortConfig(const AudioPortConfig& config) {
193     (void)config;
194     return FAILURE(Result::NOT_SUPPORTED);
195 }
196 
setScreenState(bool turnedOn)197 Return<Result> Device::setScreenState(bool turnedOn) {
198     (void)turnedOn;
199     return Result::OK;
200 }
201 
getHwAvSync(getHwAvSync_cb _hidl_cb)202 Return<void> Device::getHwAvSync(getHwAvSync_cb _hidl_cb) {
203     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), {});
204     return Void();
205 }
206 
getParameters(const hidl_vec<ParameterValue> & context,const hidl_vec<hidl_string> & keys,getParameters_cb _hidl_cb)207 Return<void> Device::getParameters(const hidl_vec<ParameterValue>& context,
208                                    const hidl_vec<hidl_string>& keys,
209                                    getParameters_cb _hidl_cb) {
210     (void)context;
211     if (keys.size() == 0) {
212         _hidl_cb(Result::OK, {});
213     } else {
214         _hidl_cb(Result::NOT_SUPPORTED, {});
215     }
216     return Void();
217 }
218 
setParameters(const hidl_vec<ParameterValue> & context,const hidl_vec<ParameterValue> & parameters)219 Return<Result> Device::setParameters(const hidl_vec<ParameterValue>& context,
220                                      const hidl_vec<ParameterValue>& parameters) {
221     (void)context;
222     (void)parameters;
223     return Result::OK;
224 }
225 
getMicrophones(getMicrophones_cb _hidl_cb)226 Return<void> Device::getMicrophones(getMicrophones_cb _hidl_cb) {
227     _hidl_cb(Result::OK, {util::getMicrophoneInfo()});
228     return Void();
229 }
230 
setConnectedState(const DeviceAddress & dev_addr,bool connected)231 Return<Result> Device::setConnectedState(const DeviceAddress& dev_addr, bool connected) {
232     (void)dev_addr;
233     (void)connected;
234     return FAILURE(Result::NOT_SUPPORTED);
235 }
236 
close()237 Return<Result> Device::close() {
238     std::lock_guard<std::mutex> guard(mMutex);
239 
240     return (mInputStreams.empty() && mOutputStreams.empty())
241         ? Result::OK : FAILURE(Result::INVALID_STATE);
242 }
243 
addDeviceEffect(AudioPortHandle device,uint64_t effectId)244 Return<Result> Device::addDeviceEffect(AudioPortHandle device, uint64_t effectId) {
245     (void)device;
246     (void)effectId;
247     return FAILURE(Result::NOT_SUPPORTED);
248 }
249 
removeDeviceEffect(AudioPortHandle device,uint64_t effectId)250 Return<Result> Device::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) {
251     (void)device;
252     (void)effectId;
253     return FAILURE(Result::NOT_SUPPORTED);
254 }
255 
unrefDevice(StreamIn * sin)256 void Device::unrefDevice(StreamIn *sin) {
257     std::lock_guard<std::mutex> guard(mMutex);
258     LOG_ALWAYS_FATAL_IF(mInputStreams.erase(sin) < 1);
259 }
260 
unrefDevice(StreamOut * sout)261 void Device::unrefDevice(StreamOut *sout) {
262     std::lock_guard<std::mutex> guard(mMutex);
263     LOG_ALWAYS_FATAL_IF(mOutputStreams.erase(sout) < 1);
264 }
265 
updateOutputStreamVolume(float masterVolume) const266 void Device::updateOutputStreamVolume(float masterVolume) const {
267     std::lock_guard<std::mutex> guard(mMutex);
268     for (StreamOut *stream : mOutputStreams) {
269         stream->setMasterVolume(masterVolume);
270     }
271 }
272 
updateInputStreamMicMute(bool micMute) const273 void Device::updateInputStreamMicMute(bool micMute) const {
274     std::lock_guard<std::mutex> guard(mMutex);
275     for (StreamIn *stream : mInputStreams) {
276         stream->setMicMute(micMute);
277     }
278 }
279 
openOutputStreamImpl(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SourceMetadata & sourceMetadata)280 std::tuple<Result, sp<IStreamOut>, AudioConfig> Device::openOutputStreamImpl(
281         int32_t ioHandle, const DeviceAddress& device,
282         const AudioConfig& config, const hidl_vec<AudioInOutFlag>& flags,
283         const SourceMetadata& sourceMetadata) {
284     if (!StreamOut::validateDeviceAddress(device)
285             || !util::checkAudioConfig(config)
286             || !StreamOut::validateFlags(flags)
287             || !StreamOut::validateSourceMetadata(sourceMetadata)) {
288         return {FAILURE(Result::INVALID_ARGUMENTS), {}, {}};
289     }
290 
291     AudioConfig suggestedConfig;
292     if (util::checkAudioConfig(true, kOutBufferDurationMs,
293                                talsa::pcmGetPcmPeriodSettings().periodCount,
294                                config, suggestedConfig)) {
295         auto stream = std::make_unique<StreamOut>(
296             this, ioHandle, device, suggestedConfig, flags, sourceMetadata);
297 
298         stream->setMasterVolume(mMasterMute ? 0.0f : mMasterVolume);
299 
300         {
301             std::lock_guard<std::mutex> guard(mMutex);
302             LOG_ALWAYS_FATAL_IF(!mOutputStreams.insert(stream.get()).second);
303         }
304 
305         return {Result::OK, stream.release(), suggestedConfig};
306     }
307     return {FAILURE(Result::INVALID_ARGUMENTS), {}, suggestedConfig};
308 }
309 
openInputStreamImpl(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SinkMetadata & sinkMetadata)310 std::tuple<Result, sp<IStreamIn>, AudioConfig> Device::openInputStreamImpl(
311         int32_t ioHandle, const DeviceAddress& device,
312         const AudioConfig& config, const hidl_vec<AudioInOutFlag>& flags,
313         const SinkMetadata& sinkMetadata) {
314     if (!StreamIn::validateDeviceAddress(device)
315             || !util::checkAudioConfig(config)
316             || !StreamIn::validateFlags(flags)
317             || !StreamIn::validateSinkMetadata(sinkMetadata)) {
318         return {FAILURE(Result::INVALID_ARGUMENTS), {}, {}};
319     }
320 
321     AudioConfig suggestedConfig;
322     if (util::checkAudioConfig(false, kInBufferDurationMs,
323                                talsa::pcmGetPcmPeriodSettings().periodCount,
324                                config, suggestedConfig)) {
325         auto stream = std::make_unique<StreamIn>(
326             this, ioHandle, device, suggestedConfig, flags, sinkMetadata);
327 
328         stream->setMicMute(mMicMute);
329 
330         {
331             std::lock_guard<std::mutex> guard(mMutex);
332             LOG_ALWAYS_FATAL_IF(!mInputStreams.insert(stream.get()).second);
333         }
334 
335         return {Result::OK, stream.release(), suggestedConfig};
336     }
337     return {FAILURE(Result::INVALID_ARGUMENTS), {}, suggestedConfig};
338 }
339 
340 #if MAJOR_VERSION == 7 && MINOR_VERSION == 1
openOutputStream_7_1(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SourceMetadata & sourceMetadata,openOutputStream_7_1_cb _hidl_cb)341 Return<void> Device::openOutputStream_7_1(int32_t ioHandle, const DeviceAddress& device,
342         const AudioConfig& config, const hidl_vec<AudioInOutFlag>& flags,
343         const SourceMetadata& sourceMetadata, openOutputStream_7_1_cb _hidl_cb) {
344     auto [result, stream, cfg] = openOutputStreamImpl(ioHandle, device,
345             config, flags, sourceMetadata);
346     _hidl_cb(result, stream, cfg);
347     return Void();
348 }
349 
setConnectedState_7_1(const AudioPort & devicePort,bool connected)350 Return<Result> Device::setConnectedState_7_1(const AudioPort& devicePort,
351                                              bool connected) {
352     (void)devicePort;
353     (void)connected;
354     return FAILURE(Result::NOT_SUPPORTED);
355 }
356 #endif
357 
358 // ==================
359 
PrimaryDevice()360 PrimaryDevice::PrimaryDevice() : mDevice(sp<Device>::make()) {
361 }
362 
initCheck()363 Return<Result> PrimaryDevice::initCheck() {
364     return mDevice->initCheck();
365 }
366 
setMasterVolume(float volume)367 Return<Result> PrimaryDevice::setMasterVolume(float volume) {
368     return mDevice->setMasterVolume(volume);
369 }
370 
getMasterVolume(getMasterVolume_cb _hidl_cb)371 Return<void> PrimaryDevice::getMasterVolume(getMasterVolume_cb _hidl_cb) {
372     return mDevice->getMasterVolume(_hidl_cb);
373 }
374 
setMicMute(bool mute)375 Return<Result> PrimaryDevice::setMicMute(bool mute) {
376     return mDevice->setMicMute(mute);
377 }
378 
getMicMute(getMicMute_cb _hidl_cb)379 Return<void> PrimaryDevice::getMicMute(getMicMute_cb _hidl_cb) {
380     return mDevice->getMicMute(_hidl_cb);
381 }
382 
setMasterMute(bool mute)383 Return<Result> PrimaryDevice::setMasterMute(bool mute) {
384     return mDevice->setMasterMute(mute);
385 }
386 
getMasterMute(getMasterMute_cb _hidl_cb)387 Return<void> PrimaryDevice::getMasterMute(getMasterMute_cb _hidl_cb) {
388     return mDevice->getMasterMute(_hidl_cb);
389 }
390 
getInputBufferSize(const AudioConfig & config,getInputBufferSize_cb _hidl_cb)391 Return<void> PrimaryDevice::getInputBufferSize(const AudioConfig& config,
392                                                getInputBufferSize_cb _hidl_cb) {
393     return mDevice->getInputBufferSize(config, _hidl_cb);
394 }
395 
openOutputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SourceMetadata & sourceMetadata,openOutputStream_cb _hidl_cb)396 Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle,
397                                              const DeviceAddress& device,
398                                              const AudioConfig& config,
399                                              const hidl_vec<AudioInOutFlag>& flags,
400                                              const SourceMetadata& sourceMetadata,
401                                              openOutputStream_cb _hidl_cb) {
402     return mDevice->openOutputStream(ioHandle, device, config, flags, sourceMetadata, _hidl_cb);
403 }
404 
openInputStream(int32_t ioHandle,const DeviceAddress & device,const AudioConfig & config,const hidl_vec<AudioInOutFlag> & flags,const SinkMetadata & sinkMetadata,openInputStream_cb _hidl_cb)405 Return<void> PrimaryDevice::openInputStream(int32_t ioHandle,
406                                             const DeviceAddress& device,
407                                             const AudioConfig& config,
408                                             const hidl_vec<AudioInOutFlag>& flags,
409                                             const SinkMetadata& sinkMetadata,
410                                             openInputStream_cb _hidl_cb) {
411     return mDevice->openInputStream(ioHandle, device, config, flags, sinkMetadata, _hidl_cb);
412 }
413 
supportsAudioPatches()414 Return<bool> PrimaryDevice::supportsAudioPatches() {
415     return mDevice->supportsAudioPatches();
416 }
417 
createAudioPatch(const hidl_vec<AudioPortConfig> & sources,const hidl_vec<AudioPortConfig> & sinks,createAudioPatch_cb _hidl_cb)418 Return<void> PrimaryDevice::createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
419                                              const hidl_vec<AudioPortConfig>& sinks,
420                                              createAudioPatch_cb _hidl_cb) {
421     return mDevice->createAudioPatch(sources, sinks, _hidl_cb);
422 }
423 
updateAudioPatch(int32_t previousPatch,const hidl_vec<AudioPortConfig> & sources,const hidl_vec<AudioPortConfig> & sinks,updateAudioPatch_cb _hidl_cb)424 Return<void> PrimaryDevice::updateAudioPatch(int32_t previousPatch,
425                                              const hidl_vec<AudioPortConfig>& sources,
426                                              const hidl_vec<AudioPortConfig>& sinks,
427                                              updateAudioPatch_cb _hidl_cb) {
428     return mDevice->updateAudioPatch(previousPatch, sources, sinks, _hidl_cb);
429 }
430 
releaseAudioPatch(int32_t patch)431 Return<Result> PrimaryDevice::releaseAudioPatch(int32_t patch) {
432     return mDevice->releaseAudioPatch(patch);
433 }
434 
getAudioPort(const AudioPort & port,getAudioPort_cb _hidl_cb)435 Return<void> PrimaryDevice::getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) {
436     return mDevice->getAudioPort(port, _hidl_cb);
437 }
438 
setAudioPortConfig(const AudioPortConfig & config)439 Return<Result> PrimaryDevice::setAudioPortConfig(const AudioPortConfig& config) {
440     return mDevice->setAudioPortConfig(config);
441 }
442 
setScreenState(bool turnedOn)443 Return<Result> PrimaryDevice::setScreenState(bool turnedOn) {
444     return mDevice->setScreenState(turnedOn);
445 }
446 
getHwAvSync(getHwAvSync_cb _hidl_cb)447 Return<void> PrimaryDevice::getHwAvSync(getHwAvSync_cb _hidl_cb) {
448     return mDevice->getHwAvSync(_hidl_cb);
449 }
450 
getParameters(const hidl_vec<ParameterValue> & context,const hidl_vec<hidl_string> & keys,getParameters_cb _hidl_cb)451 Return<void> PrimaryDevice::getParameters(const hidl_vec<ParameterValue>& context,
452                                           const hidl_vec<hidl_string>& keys,
453                                           getParameters_cb _hidl_cb) {
454     return mDevice->getParameters(context, keys, _hidl_cb);
455 }
456 
setParameters(const hidl_vec<ParameterValue> & context,const hidl_vec<ParameterValue> & parameters)457 Return<Result> PrimaryDevice::setParameters(const hidl_vec<ParameterValue>& context,
458                                             const hidl_vec<ParameterValue>& parameters) {
459     return mDevice->setParameters(context, parameters);
460 }
461 
getMicrophones(getMicrophones_cb _hidl_cb)462 Return<void> PrimaryDevice::getMicrophones(getMicrophones_cb _hidl_cb) {
463     return mDevice->getMicrophones(_hidl_cb);
464 }
465 
setConnectedState(const DeviceAddress & dev_addr,bool connected)466 Return<Result> PrimaryDevice::setConnectedState(const DeviceAddress& dev_addr, bool connected) {
467     return mDevice->setConnectedState(dev_addr, connected);
468 }
469 
close()470 Return<Result> PrimaryDevice::close() {
471     return mDevice->close();
472 }
473 
addDeviceEffect(AudioPortHandle device,uint64_t effectId)474 Return<Result> PrimaryDevice::addDeviceEffect(AudioPortHandle device, uint64_t effectId) {
475     return mDevice->addDeviceEffect(device, effectId);
476 }
477 
removeDeviceEffect(AudioPortHandle device,uint64_t effectId)478 Return<Result> PrimaryDevice::removeDeviceEffect(AudioPortHandle device, uint64_t effectId) {
479     return mDevice->removeDeviceEffect(device, effectId);
480 }
481 
setVoiceVolume(float volume)482 Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
483     return (volume >= 0 && volume <= 1.0) ? Result::OK : FAILURE(Result::INVALID_ARGUMENTS);
484 }
485 
setMode(AudioMode mode)486 Return<Result> PrimaryDevice::setMode(AudioMode mode) {
487     switch (mode) {
488     case AudioMode::NORMAL:
489     case AudioMode::RINGTONE:
490     case AudioMode::IN_CALL:
491     case AudioMode::IN_COMMUNICATION:
492         return Result::OK;
493 
494     default:
495         return FAILURE(Result::INVALID_ARGUMENTS);
496     }
497 }
498 
setBtScoHeadsetDebugName(const hidl_string & name)499 Return<Result> PrimaryDevice::setBtScoHeadsetDebugName(const hidl_string& name) {
500     (void)name;
501     return FAILURE(Result::NOT_SUPPORTED);
502 }
503 
getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb)504 Return<void> PrimaryDevice::getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) {
505     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), false);
506     return Void();
507 }
508 
setBtScoNrecEnabled(bool enabled)509 Return<Result> PrimaryDevice::setBtScoNrecEnabled(bool enabled) {
510     (void)enabled;
511     return FAILURE(Result::NOT_SUPPORTED);
512 }
513 
getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb)514 Return<void> PrimaryDevice::getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) {
515     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), false);
516     return Void();
517 }
518 
setBtScoWidebandEnabled(bool enabled)519 Return<Result> PrimaryDevice::setBtScoWidebandEnabled(bool enabled) {
520     (void)enabled;
521     return FAILURE(Result::NOT_SUPPORTED);
522 }
523 
getTtyMode(getTtyMode_cb _hidl_cb)524 Return<void> PrimaryDevice::getTtyMode(getTtyMode_cb _hidl_cb) {
525     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), TtyMode::OFF);
526     return Void();
527 }
528 
setTtyMode(IPrimaryDevice::TtyMode mode)529 Return<Result> PrimaryDevice::setTtyMode(IPrimaryDevice::TtyMode mode) {
530     (void)mode;
531     return FAILURE(Result::NOT_SUPPORTED);
532 }
533 
getHacEnabled(getHacEnabled_cb _hidl_cb)534 Return<void> PrimaryDevice::getHacEnabled(getHacEnabled_cb _hidl_cb) {
535     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), false);
536     return Void();
537 }
538 
setHacEnabled(bool enabled)539 Return<Result> PrimaryDevice::setHacEnabled(bool enabled) {
540     (void)enabled;
541     return FAILURE(Result::NOT_SUPPORTED);
542 }
543 
getBtHfpEnabled(getBtHfpEnabled_cb _hidl_cb)544 Return<void> PrimaryDevice::getBtHfpEnabled(getBtHfpEnabled_cb _hidl_cb) {
545     _hidl_cb(FAILURE(Result::NOT_SUPPORTED), false);
546     return Void();
547 }
548 
setBtHfpEnabled(bool enabled)549 Return<Result> PrimaryDevice::setBtHfpEnabled(bool enabled) {
550     (void)enabled;
551     return FAILURE(Result::NOT_SUPPORTED);
552 }
553 
setBtHfpSampleRate(uint32_t sampleRateHz)554 Return<Result> PrimaryDevice::setBtHfpSampleRate(uint32_t sampleRateHz) {
555     (void)sampleRateHz;
556     return FAILURE(Result::NOT_SUPPORTED);
557 }
558 
setBtHfpVolume(float volume)559 Return<Result> PrimaryDevice::setBtHfpVolume(float volume) {
560     (void)volume;
561     return FAILURE(Result::NOT_SUPPORTED);
562 }
563 
updateRotation(IPrimaryDevice::Rotation rotation)564 Return<Result> PrimaryDevice::updateRotation(IPrimaryDevice::Rotation rotation) {
565     (void)rotation;
566     return FAILURE(Result::NOT_SUPPORTED);
567 }
568 
569 }  // namespace implementation
570 }  // namespace CPP_VERSION
571 }  // namespace audio
572 }  // namespace hardware
573 }  // namespace android
574