1 /*
2 * Copyright (C) 2009 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 #define LOG_TAG "AudioPolicyIntefaceImpl"
18 //#define LOG_NDEBUG 0
19
20 #include <utils/Log.h>
21 #include "AudioPolicyService.h"
22 #include "ServiceUtilities.h"
23
24 namespace android {
25
26
27 // ----------------------------------------------------------------------------
28
setDeviceConnectionState(audio_devices_t device,audio_policy_dev_state_t state,const char * device_address,const char * device_name)29 status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device,
30 audio_policy_dev_state_t state,
31 const char *device_address,
32 const char *device_name)
33 {
34 if (mAudioPolicyManager == NULL) {
35 return NO_INIT;
36 }
37 if (!settingsAllowed()) {
38 return PERMISSION_DENIED;
39 }
40 if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE &&
41 state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
42 return BAD_VALUE;
43 }
44
45 ALOGV("setDeviceConnectionState()");
46 Mutex::Autolock _l(mLock);
47 return mAudioPolicyManager->setDeviceConnectionState(device, state,
48 device_address, device_name);
49 }
50
getDeviceConnectionState(audio_devices_t device,const char * device_address)51 audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState(
52 audio_devices_t device,
53 const char *device_address)
54 {
55 if (mAudioPolicyManager == NULL) {
56 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
57 }
58 return mAudioPolicyManager->getDeviceConnectionState(device,
59 device_address);
60 }
61
handleDeviceConfigChange(audio_devices_t device,const char * device_address,const char * device_name)62 status_t AudioPolicyService::handleDeviceConfigChange(audio_devices_t device,
63 const char *device_address,
64 const char *device_name)
65 {
66 if (mAudioPolicyManager == NULL) {
67 return NO_INIT;
68 }
69 if (!settingsAllowed()) {
70 return PERMISSION_DENIED;
71 }
72
73 ALOGV("handleDeviceConfigChange()");
74 Mutex::Autolock _l(mLock);
75 return mAudioPolicyManager->handleDeviceConfigChange(device, device_address,
76 device_name);
77 }
78
setPhoneState(audio_mode_t state)79 status_t AudioPolicyService::setPhoneState(audio_mode_t state)
80 {
81 if (mAudioPolicyManager == NULL) {
82 return NO_INIT;
83 }
84 if (!settingsAllowed()) {
85 return PERMISSION_DENIED;
86 }
87 if (uint32_t(state) >= AUDIO_MODE_CNT) {
88 return BAD_VALUE;
89 }
90
91 ALOGV("setPhoneState()");
92
93 // acquire lock before calling setMode() so that setMode() + setPhoneState() are an atomic
94 // operation from policy manager standpoint (no other operation (e.g track start or stop)
95 // can be interleaved).
96 Mutex::Autolock _l(mLock);
97
98 // TODO: check if it is more appropriate to do it in platform specific policy manager
99 AudioSystem::setMode(state);
100
101 mAudioPolicyManager->setPhoneState(state);
102 mPhoneState = state;
103 return NO_ERROR;
104 }
105
getPhoneState()106 audio_mode_t AudioPolicyService::getPhoneState()
107 {
108 Mutex::Autolock _l(mLock);
109 return mPhoneState;
110 }
111
setForceUse(audio_policy_force_use_t usage,audio_policy_forced_cfg_t config)112 status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage,
113 audio_policy_forced_cfg_t config)
114 {
115 if (mAudioPolicyManager == NULL) {
116 return NO_INIT;
117 }
118 if (!settingsAllowed()) {
119 return PERMISSION_DENIED;
120 }
121 if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
122 return BAD_VALUE;
123 }
124 if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) {
125 return BAD_VALUE;
126 }
127 ALOGV("setForceUse()");
128 Mutex::Autolock _l(mLock);
129 mAudioPolicyManager->setForceUse(usage, config);
130 return NO_ERROR;
131 }
132
getForceUse(audio_policy_force_use_t usage)133 audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage)
134 {
135 if (mAudioPolicyManager == NULL) {
136 return AUDIO_POLICY_FORCE_NONE;
137 }
138 if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
139 return AUDIO_POLICY_FORCE_NONE;
140 }
141 return mAudioPolicyManager->getForceUse(usage);
142 }
143
getOutput(audio_stream_type_t stream,uint32_t samplingRate,audio_format_t format,audio_channel_mask_t channelMask,audio_output_flags_t flags,const audio_offload_info_t * offloadInfo)144 audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream,
145 uint32_t samplingRate,
146 audio_format_t format,
147 audio_channel_mask_t channelMask,
148 audio_output_flags_t flags,
149 const audio_offload_info_t *offloadInfo)
150 {
151 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
152 return AUDIO_IO_HANDLE_NONE;
153 }
154 if (mAudioPolicyManager == NULL) {
155 return AUDIO_IO_HANDLE_NONE;
156 }
157 ALOGV("getOutput()");
158 Mutex::Autolock _l(mLock);
159 return mAudioPolicyManager->getOutput(stream, samplingRate,
160 format, channelMask, flags, offloadInfo);
161 }
162
getOutputForAttr(const audio_attributes_t * attr,audio_io_handle_t * output,audio_session_t session,audio_stream_type_t * stream,uid_t uid,const audio_config_t * config,audio_output_flags_t flags,audio_port_handle_t * selectedDeviceId,audio_port_handle_t * portId)163 status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr,
164 audio_io_handle_t *output,
165 audio_session_t session,
166 audio_stream_type_t *stream,
167 uid_t uid,
168 const audio_config_t *config,
169 audio_output_flags_t flags,
170 audio_port_handle_t *selectedDeviceId,
171 audio_port_handle_t *portId)
172 {
173 if (mAudioPolicyManager == NULL) {
174 return NO_INIT;
175 }
176 ALOGV("getOutput()");
177 Mutex::Autolock _l(mLock);
178
179 const uid_t callingUid = IPCThreadState::self()->getCallingUid();
180 if (!isTrustedCallingUid(callingUid) || uid == (uid_t)-1) {
181 ALOGW_IF(uid != (uid_t)-1 && uid != callingUid,
182 "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid);
183 uid = callingUid;
184 }
185 return mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid,
186 config,
187 flags, selectedDeviceId, portId);
188 }
189
startOutput(audio_io_handle_t output,audio_stream_type_t stream,audio_session_t session)190 status_t AudioPolicyService::startOutput(audio_io_handle_t output,
191 audio_stream_type_t stream,
192 audio_session_t session)
193 {
194 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
195 return BAD_VALUE;
196 }
197 if (mAudioPolicyManager == NULL) {
198 return NO_INIT;
199 }
200 ALOGV("startOutput()");
201 sp<AudioPolicyEffects>audioPolicyEffects;
202 {
203 Mutex::Autolock _l(mLock);
204 audioPolicyEffects = mAudioPolicyEffects;
205 }
206 if (audioPolicyEffects != 0) {
207 // create audio processors according to stream
208 status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session);
209 if (status != NO_ERROR && status != ALREADY_EXISTS) {
210 ALOGW("Failed to add effects on session %d", session);
211 }
212 }
213 Mutex::Autolock _l(mLock);
214 return mAudioPolicyManager->startOutput(output, stream, session);
215 }
216
stopOutput(audio_io_handle_t output,audio_stream_type_t stream,audio_session_t session)217 status_t AudioPolicyService::stopOutput(audio_io_handle_t output,
218 audio_stream_type_t stream,
219 audio_session_t session)
220 {
221 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
222 return BAD_VALUE;
223 }
224 if (mAudioPolicyManager == NULL) {
225 return NO_INIT;
226 }
227 ALOGV("stopOutput()");
228 mOutputCommandThread->stopOutputCommand(output, stream, session);
229 return NO_ERROR;
230 }
231
doStopOutput(audio_io_handle_t output,audio_stream_type_t stream,audio_session_t session)232 status_t AudioPolicyService::doStopOutput(audio_io_handle_t output,
233 audio_stream_type_t stream,
234 audio_session_t session)
235 {
236 ALOGV("doStopOutput from tid %d", gettid());
237 sp<AudioPolicyEffects>audioPolicyEffects;
238 {
239 Mutex::Autolock _l(mLock);
240 audioPolicyEffects = mAudioPolicyEffects;
241 }
242 if (audioPolicyEffects != 0) {
243 // release audio processors from the stream
244 status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session);
245 if (status != NO_ERROR && status != ALREADY_EXISTS) {
246 ALOGW("Failed to release effects on session %d", session);
247 }
248 }
249 Mutex::Autolock _l(mLock);
250 return mAudioPolicyManager->stopOutput(output, stream, session);
251 }
252
releaseOutput(audio_io_handle_t output,audio_stream_type_t stream,audio_session_t session)253 void AudioPolicyService::releaseOutput(audio_io_handle_t output,
254 audio_stream_type_t stream,
255 audio_session_t session)
256 {
257 if (mAudioPolicyManager == NULL) {
258 return;
259 }
260 ALOGV("releaseOutput()");
261 mOutputCommandThread->releaseOutputCommand(output, stream, session);
262 }
263
doReleaseOutput(audio_io_handle_t output,audio_stream_type_t stream,audio_session_t session)264 void AudioPolicyService::doReleaseOutput(audio_io_handle_t output,
265 audio_stream_type_t stream,
266 audio_session_t session)
267 {
268 ALOGV("doReleaseOutput from tid %d", gettid());
269 Mutex::Autolock _l(mLock);
270 mAudioPolicyManager->releaseOutput(output, stream, session);
271 }
272
getInputForAttr(const audio_attributes_t * attr,audio_io_handle_t * input,audio_session_t session,pid_t pid,uid_t uid,const audio_config_base_t * config,audio_input_flags_t flags,audio_port_handle_t * selectedDeviceId,audio_port_handle_t * portId)273 status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
274 audio_io_handle_t *input,
275 audio_session_t session,
276 pid_t pid,
277 uid_t uid,
278 const audio_config_base_t *config,
279 audio_input_flags_t flags,
280 audio_port_handle_t *selectedDeviceId,
281 audio_port_handle_t *portId)
282 {
283 if (mAudioPolicyManager == NULL) {
284 return NO_INIT;
285 }
286 // already checked by client, but double-check in case the client wrapper is bypassed
287 if (attr->source >= AUDIO_SOURCE_CNT && attr->source != AUDIO_SOURCE_HOTWORD &&
288 attr->source != AUDIO_SOURCE_FM_TUNER) {
289 return BAD_VALUE;
290 }
291
292 bool updatePid = (pid == -1);
293 const uid_t callingUid = IPCThreadState::self()->getCallingUid();
294 if (!isTrustedCallingUid(callingUid)) {
295 ALOGW_IF(uid != (uid_t)-1 && uid != callingUid,
296 "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid);
297 uid = callingUid;
298 updatePid = true;
299 }
300
301 if (updatePid) {
302 const pid_t callingPid = IPCThreadState::self()->getCallingPid();
303 ALOGW_IF(pid != (pid_t)-1 && pid != callingPid,
304 "%s uid %d pid %d tried to pass itself off as pid %d",
305 __func__, callingUid, callingPid, pid);
306 pid = callingPid;
307 }
308
309 if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) {
310 return BAD_VALUE;
311 }
312
313 sp<AudioPolicyEffects>audioPolicyEffects;
314 {
315 status_t status;
316 AudioPolicyInterface::input_type_t inputType;
317
318 Mutex::Autolock _l(mLock);
319 // the audio_in_acoustics_t parameter is ignored by get_input()
320 status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid,
321 config,
322 flags, selectedDeviceId,
323 &inputType, portId);
324 audioPolicyEffects = mAudioPolicyEffects;
325
326 if (status == NO_ERROR) {
327 // enforce permission (if any) required for each type of input
328 switch (inputType) {
329 case AudioPolicyInterface::API_INPUT_LEGACY:
330 break;
331 case AudioPolicyInterface::API_INPUT_TELEPHONY_RX:
332 // FIXME: use the same permission as for remote submix for now.
333 case AudioPolicyInterface::API_INPUT_MIX_CAPTURE:
334 if (!captureAudioOutputAllowed(pid, uid)) {
335 ALOGE("getInputForAttr() permission denied: capture not allowed");
336 status = PERMISSION_DENIED;
337 }
338 break;
339 case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE:
340 if (!modifyAudioRoutingAllowed()) {
341 ALOGE("getInputForAttr() permission denied: modify audio routing not allowed");
342 status = PERMISSION_DENIED;
343 }
344 break;
345 case AudioPolicyInterface::API_INPUT_INVALID:
346 default:
347 LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d",
348 (int)inputType);
349 }
350 }
351
352 if (status != NO_ERROR) {
353 if (status == PERMISSION_DENIED) {
354 mAudioPolicyManager->releaseInput(*input, session);
355 }
356 return status;
357 }
358 }
359
360 if (audioPolicyEffects != 0) {
361 // create audio pre processors according to input source
362 status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session);
363 if (status != NO_ERROR && status != ALREADY_EXISTS) {
364 ALOGW("Failed to add effects on input %d", *input);
365 }
366 }
367 return NO_ERROR;
368 }
369
startInput(audio_io_handle_t input,audio_session_t session)370 status_t AudioPolicyService::startInput(audio_io_handle_t input,
371 audio_session_t session)
372 {
373 if (mAudioPolicyManager == NULL) {
374 return NO_INIT;
375 }
376 Mutex::Autolock _l(mLock);
377 AudioPolicyInterface::concurrency_type__mask_t concurrency;
378 status_t status = mAudioPolicyManager->startInput(input, session, &concurrency);
379
380 if (status == NO_ERROR) {
381 LOG_ALWAYS_FATAL_IF(concurrency & ~AudioPolicyInterface::API_INPUT_CONCURRENCY_ALL,
382 "startInput(): invalid concurrency type %d", (int)concurrency);
383
384 // enforce permission (if any) required for each type of concurrency
385 if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CALL) {
386 //TODO: check incall capture permission
387 }
388 if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CAPTURE) {
389 //TODO: check concurrent capture permission
390 }
391 }
392
393 return status;
394 }
395
stopInput(audio_io_handle_t input,audio_session_t session)396 status_t AudioPolicyService::stopInput(audio_io_handle_t input,
397 audio_session_t session)
398 {
399 if (mAudioPolicyManager == NULL) {
400 return NO_INIT;
401 }
402 Mutex::Autolock _l(mLock);
403
404 return mAudioPolicyManager->stopInput(input, session);
405 }
406
releaseInput(audio_io_handle_t input,audio_session_t session)407 void AudioPolicyService::releaseInput(audio_io_handle_t input,
408 audio_session_t session)
409 {
410 if (mAudioPolicyManager == NULL) {
411 return;
412 }
413 sp<AudioPolicyEffects>audioPolicyEffects;
414 {
415 Mutex::Autolock _l(mLock);
416 audioPolicyEffects = mAudioPolicyEffects;
417 }
418 if (audioPolicyEffects != 0) {
419 // release audio processors from the input
420 status_t status = audioPolicyEffects->releaseInputEffects(input, session);
421 if(status != NO_ERROR) {
422 ALOGW("Failed to release effects on input %d", input);
423 }
424 }
425 {
426 Mutex::Autolock _l(mLock);
427 mAudioPolicyManager->releaseInput(input, session);
428 }
429 }
430
initStreamVolume(audio_stream_type_t stream,int indexMin,int indexMax)431 status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream,
432 int indexMin,
433 int indexMax)
434 {
435 if (mAudioPolicyManager == NULL) {
436 return NO_INIT;
437 }
438 if (!settingsAllowed()) {
439 return PERMISSION_DENIED;
440 }
441 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
442 return BAD_VALUE;
443 }
444 Mutex::Autolock _l(mLock);
445 mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax);
446 return NO_ERROR;
447 }
448
setStreamVolumeIndex(audio_stream_type_t stream,int index,audio_devices_t device)449 status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream,
450 int index,
451 audio_devices_t device)
452 {
453 if (mAudioPolicyManager == NULL) {
454 return NO_INIT;
455 }
456 if (!settingsAllowed()) {
457 return PERMISSION_DENIED;
458 }
459 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
460 return BAD_VALUE;
461 }
462 Mutex::Autolock _l(mLock);
463 return mAudioPolicyManager->setStreamVolumeIndex(stream,
464 index,
465 device);
466 }
467
getStreamVolumeIndex(audio_stream_type_t stream,int * index,audio_devices_t device)468 status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream,
469 int *index,
470 audio_devices_t device)
471 {
472 if (mAudioPolicyManager == NULL) {
473 return NO_INIT;
474 }
475 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
476 return BAD_VALUE;
477 }
478 Mutex::Autolock _l(mLock);
479 return mAudioPolicyManager->getStreamVolumeIndex(stream,
480 index,
481 device);
482 }
483
getStrategyForStream(audio_stream_type_t stream)484 uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream)
485 {
486 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
487 return 0;
488 }
489 if (mAudioPolicyManager == NULL) {
490 return 0;
491 }
492 return mAudioPolicyManager->getStrategyForStream(stream);
493 }
494
495 //audio policy: use audio_device_t appropriately
496
getDevicesForStream(audio_stream_type_t stream)497 audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
498 {
499 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
500 return AUDIO_DEVICE_NONE;
501 }
502 if (mAudioPolicyManager == NULL) {
503 return AUDIO_DEVICE_NONE;
504 }
505 Mutex::Autolock _l(mLock);
506 return mAudioPolicyManager->getDevicesForStream(stream);
507 }
508
getOutputForEffect(const effect_descriptor_t * desc)509 audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc)
510 {
511 // FIXME change return type to status_t, and return NO_INIT here
512 if (mAudioPolicyManager == NULL) {
513 return 0;
514 }
515 Mutex::Autolock _l(mLock);
516 return mAudioPolicyManager->getOutputForEffect(desc);
517 }
518
registerEffect(const effect_descriptor_t * desc,audio_io_handle_t io,uint32_t strategy,audio_session_t session,int id)519 status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc,
520 audio_io_handle_t io,
521 uint32_t strategy,
522 audio_session_t session,
523 int id)
524 {
525 if (mAudioPolicyManager == NULL) {
526 return NO_INIT;
527 }
528 Mutex::Autolock _l(mEffectsLock);
529 return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id);
530 }
531
unregisterEffect(int id)532 status_t AudioPolicyService::unregisterEffect(int id)
533 {
534 if (mAudioPolicyManager == NULL) {
535 return NO_INIT;
536 }
537 Mutex::Autolock _l(mEffectsLock);
538 return mAudioPolicyManager->unregisterEffect(id);
539 }
540
setEffectEnabled(int id,bool enabled)541 status_t AudioPolicyService::setEffectEnabled(int id, bool enabled)
542 {
543 if (mAudioPolicyManager == NULL) {
544 return NO_INIT;
545 }
546 Mutex::Autolock _l(mEffectsLock);
547 return mAudioPolicyManager->setEffectEnabled(id, enabled);
548 }
549
isStreamActive(audio_stream_type_t stream,uint32_t inPastMs) const550 bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
551 {
552 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
553 return false;
554 }
555 if (mAudioPolicyManager == NULL) {
556 return false;
557 }
558 Mutex::Autolock _l(mLock);
559 return mAudioPolicyManager->isStreamActive(stream, inPastMs);
560 }
561
isStreamActiveRemotely(audio_stream_type_t stream,uint32_t inPastMs) const562 bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
563 {
564 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
565 return false;
566 }
567 if (mAudioPolicyManager == NULL) {
568 return false;
569 }
570 Mutex::Autolock _l(mLock);
571 return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs);
572 }
573
isSourceActive(audio_source_t source) const574 bool AudioPolicyService::isSourceActive(audio_source_t source) const
575 {
576 if (mAudioPolicyManager == NULL) {
577 return false;
578 }
579 Mutex::Autolock _l(mLock);
580 return mAudioPolicyManager->isSourceActive(source);
581 }
582
queryDefaultPreProcessing(audio_session_t audioSession,effect_descriptor_t * descriptors,uint32_t * count)583 status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession,
584 effect_descriptor_t *descriptors,
585 uint32_t *count)
586 {
587 if (mAudioPolicyManager == NULL) {
588 *count = 0;
589 return NO_INIT;
590 }
591 sp<AudioPolicyEffects>audioPolicyEffects;
592 {
593 Mutex::Autolock _l(mLock);
594 audioPolicyEffects = mAudioPolicyEffects;
595 }
596 if (audioPolicyEffects == 0) {
597 *count = 0;
598 return NO_INIT;
599 }
600 return audioPolicyEffects->queryDefaultInputEffects(
601 (audio_session_t)audioSession, descriptors, count);
602 }
603
isOffloadSupported(const audio_offload_info_t & info)604 bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info)
605 {
606 if (mAudioPolicyManager == NULL) {
607 ALOGV("mAudioPolicyManager == NULL");
608 return false;
609 }
610 Mutex::Autolock _l(mLock);
611 Mutex::Autolock _le(mEffectsLock); // isOffloadSupported queries for
612 // non-offloadable effects
613 return mAudioPolicyManager->isOffloadSupported(info);
614 }
615
listAudioPorts(audio_port_role_t role,audio_port_type_t type,unsigned int * num_ports,struct audio_port * ports,unsigned int * generation)616 status_t AudioPolicyService::listAudioPorts(audio_port_role_t role,
617 audio_port_type_t type,
618 unsigned int *num_ports,
619 struct audio_port *ports,
620 unsigned int *generation)
621 {
622 Mutex::Autolock _l(mLock);
623 if (mAudioPolicyManager == NULL) {
624 return NO_INIT;
625 }
626
627 return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation);
628 }
629
getAudioPort(struct audio_port * port)630 status_t AudioPolicyService::getAudioPort(struct audio_port *port)
631 {
632 Mutex::Autolock _l(mLock);
633 if (mAudioPolicyManager == NULL) {
634 return NO_INIT;
635 }
636
637 return mAudioPolicyManager->getAudioPort(port);
638 }
639
createAudioPatch(const struct audio_patch * patch,audio_patch_handle_t * handle)640 status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch,
641 audio_patch_handle_t *handle)
642 {
643 Mutex::Autolock _l(mLock);
644 if(!modifyAudioRoutingAllowed()) {
645 return PERMISSION_DENIED;
646 }
647 if (mAudioPolicyManager == NULL) {
648 return NO_INIT;
649 }
650 return mAudioPolicyManager->createAudioPatch(patch, handle,
651 IPCThreadState::self()->getCallingUid());
652 }
653
releaseAudioPatch(audio_patch_handle_t handle)654 status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle)
655 {
656 Mutex::Autolock _l(mLock);
657 if(!modifyAudioRoutingAllowed()) {
658 return PERMISSION_DENIED;
659 }
660 if (mAudioPolicyManager == NULL) {
661 return NO_INIT;
662 }
663
664 return mAudioPolicyManager->releaseAudioPatch(handle,
665 IPCThreadState::self()->getCallingUid());
666 }
667
listAudioPatches(unsigned int * num_patches,struct audio_patch * patches,unsigned int * generation)668 status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches,
669 struct audio_patch *patches,
670 unsigned int *generation)
671 {
672 Mutex::Autolock _l(mLock);
673 if (mAudioPolicyManager == NULL) {
674 return NO_INIT;
675 }
676
677 return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation);
678 }
679
setAudioPortConfig(const struct audio_port_config * config)680 status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config)
681 {
682 Mutex::Autolock _l(mLock);
683 if(!modifyAudioRoutingAllowed()) {
684 return PERMISSION_DENIED;
685 }
686 if (mAudioPolicyManager == NULL) {
687 return NO_INIT;
688 }
689
690 return mAudioPolicyManager->setAudioPortConfig(config);
691 }
692
acquireSoundTriggerSession(audio_session_t * session,audio_io_handle_t * ioHandle,audio_devices_t * device)693 status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session,
694 audio_io_handle_t *ioHandle,
695 audio_devices_t *device)
696 {
697 Mutex::Autolock _l(mLock);
698 if (mAudioPolicyManager == NULL) {
699 return NO_INIT;
700 }
701
702 return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device);
703 }
704
releaseSoundTriggerSession(audio_session_t session)705 status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session)
706 {
707 Mutex::Autolock _l(mLock);
708 if (mAudioPolicyManager == NULL) {
709 return NO_INIT;
710 }
711
712 return mAudioPolicyManager->releaseSoundTriggerSession(session);
713 }
714
registerPolicyMixes(const Vector<AudioMix> & mixes,bool registration)715 status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
716 {
717 Mutex::Autolock _l(mLock);
718 if(!modifyAudioRoutingAllowed()) {
719 return PERMISSION_DENIED;
720 }
721 if (mAudioPolicyManager == NULL) {
722 return NO_INIT;
723 }
724 if (registration) {
725 return mAudioPolicyManager->registerPolicyMixes(mixes);
726 } else {
727 return mAudioPolicyManager->unregisterPolicyMixes(mixes);
728 }
729 }
730
startAudioSource(const struct audio_port_config * source,const audio_attributes_t * attributes,audio_patch_handle_t * handle)731 status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source,
732 const audio_attributes_t *attributes,
733 audio_patch_handle_t *handle)
734 {
735 Mutex::Autolock _l(mLock);
736 if (mAudioPolicyManager == NULL) {
737 return NO_INIT;
738 }
739
740 return mAudioPolicyManager->startAudioSource(source, attributes, handle,
741 IPCThreadState::self()->getCallingUid());
742 }
743
stopAudioSource(audio_patch_handle_t handle)744 status_t AudioPolicyService::stopAudioSource(audio_patch_handle_t handle)
745 {
746 Mutex::Autolock _l(mLock);
747 if (mAudioPolicyManager == NULL) {
748 return NO_INIT;
749 }
750
751 return mAudioPolicyManager->stopAudioSource(handle);
752 }
753
setMasterMono(bool mono)754 status_t AudioPolicyService::setMasterMono(bool mono)
755 {
756 if (mAudioPolicyManager == NULL) {
757 return NO_INIT;
758 }
759 if (!settingsAllowed()) {
760 return PERMISSION_DENIED;
761 }
762 Mutex::Autolock _l(mLock);
763 return mAudioPolicyManager->setMasterMono(mono);
764 }
765
getMasterMono(bool * mono)766 status_t AudioPolicyService::getMasterMono(bool *mono)
767 {
768 if (mAudioPolicyManager == NULL) {
769 return NO_INIT;
770 }
771 Mutex::Autolock _l(mLock);
772 return mAudioPolicyManager->getMasterMono(mono);
773 }
774
775
getStreamVolumeDB(audio_stream_type_t stream,int index,audio_devices_t device)776 float AudioPolicyService::getStreamVolumeDB(
777 audio_stream_type_t stream, int index, audio_devices_t device)
778 {
779 if (mAudioPolicyManager == NULL) {
780 return NAN;
781 }
782 Mutex::Autolock _l(mLock);
783 return mAudioPolicyManager->getStreamVolumeDB(stream, index, device);
784 }
785
786
787 }; // namespace android
788