blob: dceda9793e75476bf6f0cb33a1b9c7f3257c6561 [file] [log] [blame]
Eric Laurent2d388ec2014-03-07 13:25:54 -08001/*
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
Eric Laurentdce54a12014-03-10 12:19:46 -070017#define LOG_TAG "AudioPolicyIntefaceImpl"
Eric Laurent2d388ec2014-03-07 13:25:54 -080018//#define LOG_NDEBUG 0
19
20#include <utils/Log.h>
21#include "AudioPolicyService.h"
22#include "ServiceUtilities.h"
23
Eric Laurent2d388ec2014-03-07 13:25:54 -080024namespace android {
25
26
27// ----------------------------------------------------------------------------
28
29status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device,
30 audio_policy_dev_state_t state,
31 const char *device_address)
32{
Eric Laurentdce54a12014-03-10 12:19:46 -070033 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080034 return NO_INIT;
35 }
36 if (!settingsAllowed()) {
37 return PERMISSION_DENIED;
38 }
39 if (!audio_is_output_device(device) && !audio_is_input_device(device)) {
40 return BAD_VALUE;
41 }
42 if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE &&
43 state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) {
44 return BAD_VALUE;
45 }
46
47 ALOGV("setDeviceConnectionState()");
48 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -070049 return mAudioPolicyManager->setDeviceConnectionState(device,
Eric Laurent2d388ec2014-03-07 13:25:54 -080050 state, device_address);
51}
52
53audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState(
54 audio_devices_t device,
55 const char *device_address)
56{
Eric Laurentdce54a12014-03-10 12:19:46 -070057 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080058 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
59 }
Eric Laurentdce54a12014-03-10 12:19:46 -070060 return mAudioPolicyManager->getDeviceConnectionState(device,
Eric Laurent2d388ec2014-03-07 13:25:54 -080061 device_address);
62}
63
64status_t AudioPolicyService::setPhoneState(audio_mode_t state)
65{
Eric Laurentdce54a12014-03-10 12:19:46 -070066 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080067 return NO_INIT;
68 }
69 if (!settingsAllowed()) {
70 return PERMISSION_DENIED;
71 }
72 if (uint32_t(state) >= AUDIO_MODE_CNT) {
73 return BAD_VALUE;
74 }
75
76 ALOGV("setPhoneState()");
77
78 // TODO: check if it is more appropriate to do it in platform specific policy manager
79 AudioSystem::setMode(state);
80
81 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -070082 mAudioPolicyManager->setPhoneState(state);
Eric Laurentbb6c9a02014-09-25 14:11:47 -070083 mPhoneState = state;
Eric Laurent2d388ec2014-03-07 13:25:54 -080084 return NO_ERROR;
85}
86
Eric Laurentbb6c9a02014-09-25 14:11:47 -070087audio_mode_t AudioPolicyService::getPhoneState()
88{
89 Mutex::Autolock _l(mLock);
90 return mPhoneState;
91}
92
Eric Laurent2d388ec2014-03-07 13:25:54 -080093status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage,
94 audio_policy_forced_cfg_t config)
95{
Eric Laurentdce54a12014-03-10 12:19:46 -070096 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080097 return NO_INIT;
98 }
99 if (!settingsAllowed()) {
100 return PERMISSION_DENIED;
101 }
102 if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
103 return BAD_VALUE;
104 }
105 if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) {
106 return BAD_VALUE;
107 }
108 ALOGV("setForceUse()");
109 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700110 mAudioPolicyManager->setForceUse(usage, config);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800111 return NO_ERROR;
112}
113
114audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage)
115{
Eric Laurentdce54a12014-03-10 12:19:46 -0700116 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800117 return AUDIO_POLICY_FORCE_NONE;
118 }
119 if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
120 return AUDIO_POLICY_FORCE_NONE;
121 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700122 return mAudioPolicyManager->getForceUse(usage);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800123}
124
125audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream,
126 uint32_t samplingRate,
127 audio_format_t format,
128 audio_channel_mask_t channelMask,
129 audio_output_flags_t flags,
130 const audio_offload_info_t *offloadInfo)
131{
Eric Laurentdce54a12014-03-10 12:19:46 -0700132 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800133 return 0;
134 }
135 ALOGV("getOutput()");
136 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700137 return mAudioPolicyManager->getOutput(stream, samplingRate,
Eric Laurent2d388ec2014-03-07 13:25:54 -0800138 format, channelMask, flags, offloadInfo);
139}
140
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700141audio_io_handle_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr,
142 uint32_t samplingRate,
143 audio_format_t format,
144 audio_channel_mask_t channelMask,
145 audio_output_flags_t flags,
146 const audio_offload_info_t *offloadInfo)
147{
148 if (mAudioPolicyManager == NULL) {
149 return 0;
150 }
151 ALOGV("getOutput()");
152 Mutex::Autolock _l(mLock);
153 return mAudioPolicyManager->getOutputForAttr(attr, samplingRate,
154 format, channelMask, flags, offloadInfo);
155}
156
Eric Laurent2d388ec2014-03-07 13:25:54 -0800157status_t AudioPolicyService::startOutput(audio_io_handle_t output,
158 audio_stream_type_t stream,
159 int session)
160{
Eric Laurentdce54a12014-03-10 12:19:46 -0700161 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800162 return NO_INIT;
163 }
164 ALOGV("startOutput()");
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700165 sp<AudioPolicyEffects>audioPolicyEffects;
166 {
167 Mutex::Autolock _l(mLock);
168 audioPolicyEffects = mAudioPolicyEffects;
bryant_liuba2b4392014-06-11 16:49:30 +0800169 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700170 if (audioPolicyEffects != 0) {
171 // create audio processors according to stream
172 status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session);
173 if (status != NO_ERROR && status != ALREADY_EXISTS) {
174 ALOGW("Failed to add effects on session %d", session);
175 }
176 }
177 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700178 return mAudioPolicyManager->startOutput(output, stream, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800179}
180
181status_t AudioPolicyService::stopOutput(audio_io_handle_t output,
182 audio_stream_type_t stream,
183 int session)
184{
Eric Laurentdce54a12014-03-10 12:19:46 -0700185 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800186 return NO_INIT;
187 }
188 ALOGV("stopOutput()");
189 mOutputCommandThread->stopOutputCommand(output, stream, session);
190 return NO_ERROR;
191}
192
193status_t AudioPolicyService::doStopOutput(audio_io_handle_t output,
194 audio_stream_type_t stream,
195 int session)
196{
197 ALOGV("doStopOutput from tid %d", gettid());
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700198 sp<AudioPolicyEffects>audioPolicyEffects;
199 {
200 Mutex::Autolock _l(mLock);
201 audioPolicyEffects = mAudioPolicyEffects;
bryant_liuba2b4392014-06-11 16:49:30 +0800202 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700203 if (audioPolicyEffects != 0) {
204 // release audio processors from the stream
205 status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session);
206 if (status != NO_ERROR && status != ALREADY_EXISTS) {
207 ALOGW("Failed to release effects on session %d", session);
208 }
209 }
210 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700211 return mAudioPolicyManager->stopOutput(output, stream, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800212}
213
214void AudioPolicyService::releaseOutput(audio_io_handle_t output)
215{
Eric Laurentdce54a12014-03-10 12:19:46 -0700216 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800217 return;
218 }
219 ALOGV("releaseOutput()");
220 mOutputCommandThread->releaseOutputCommand(output);
221}
222
223void AudioPolicyService::doReleaseOutput(audio_io_handle_t output)
224{
225 ALOGV("doReleaseOutput from tid %d", gettid());
226 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700227 mAudioPolicyManager->releaseOutput(output);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800228}
229
230audio_io_handle_t AudioPolicyService::getInput(audio_source_t inputSource,
231 uint32_t samplingRate,
232 audio_format_t format,
233 audio_channel_mask_t channelMask,
Glenn Kastenb3b16602014-07-16 08:36:31 -0700234 int audioSession,
Glenn Kasten6a8ab052014-07-24 14:08:35 -0700235 audio_input_flags_t flags)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800236{
Eric Laurentdce54a12014-03-10 12:19:46 -0700237 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800238 return 0;
239 }
240 // already checked by client, but double-check in case the client wrapper is bypassed
Hochi Huangf53eaf42014-10-09 11:36:22 +0800241 if (inputSource >= AUDIO_SOURCE_CNT && inputSource != AUDIO_SOURCE_HOTWORD &&
242 inputSource != AUDIO_SOURCE_FM_TUNER) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800243 return 0;
244 }
245
Hochi Huangf53eaf42014-10-09 11:36:22 +0800246 if (((inputSource == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed()) ||
247 ((inputSource == AUDIO_SOURCE_FM_TUNER) && !captureFmTunerAllowed())) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800248 return 0;
249 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700250 audio_io_handle_t input;
251 sp<AudioPolicyEffects>audioPolicyEffects;
252 {
253 Mutex::Autolock _l(mLock);
254 // the audio_in_acoustics_t parameter is ignored by get_input()
255 input = mAudioPolicyManager->getInput(inputSource, samplingRate,
256 format, channelMask,
257 (audio_session_t)audioSession, flags);
258 audioPolicyEffects = mAudioPolicyEffects;
259 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800260 if (input == 0) {
261 return input;
262 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700263 if (audioPolicyEffects != 0) {
264 // create audio pre processors according to input source
265 status_t status = audioPolicyEffects->addInputEffects(input, inputSource, audioSession);
266 if (status != NO_ERROR && status != ALREADY_EXISTS) {
267 ALOGW("Failed to add effects on input %d", input);
268 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800269 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800270 return input;
271}
272
Eric Laurent4dc68062014-07-28 17:26:49 -0700273status_t AudioPolicyService::startInput(audio_io_handle_t input,
274 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800275{
Eric Laurentdce54a12014-03-10 12:19:46 -0700276 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800277 return NO_INIT;
278 }
279 Mutex::Autolock _l(mLock);
280
Eric Laurent4dc68062014-07-28 17:26:49 -0700281 return mAudioPolicyManager->startInput(input, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800282}
283
Eric Laurent4dc68062014-07-28 17:26:49 -0700284status_t AudioPolicyService::stopInput(audio_io_handle_t input,
285 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800286{
Eric Laurentdce54a12014-03-10 12:19:46 -0700287 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800288 return NO_INIT;
289 }
290 Mutex::Autolock _l(mLock);
291
Eric Laurent4dc68062014-07-28 17:26:49 -0700292 return mAudioPolicyManager->stopInput(input, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800293}
294
Eric Laurent4dc68062014-07-28 17:26:49 -0700295void AudioPolicyService::releaseInput(audio_io_handle_t input,
296 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800297{
Eric Laurentdce54a12014-03-10 12:19:46 -0700298 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800299 return;
300 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700301 sp<AudioPolicyEffects>audioPolicyEffects;
302 {
303 Mutex::Autolock _l(mLock);
304 mAudioPolicyManager->releaseInput(input, session);
305 audioPolicyEffects = mAudioPolicyEffects;
306 }
307 if (audioPolicyEffects != 0) {
308 // release audio processors from the input
309 status_t status = audioPolicyEffects->releaseInputEffects(input);
310 if(status != NO_ERROR) {
311 ALOGW("Failed to release effects on input %d", input);
312 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800313 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800314}
315
316status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream,
317 int indexMin,
318 int indexMax)
319{
Eric Laurentdce54a12014-03-10 12:19:46 -0700320 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800321 return NO_INIT;
322 }
323 if (!settingsAllowed()) {
324 return PERMISSION_DENIED;
325 }
326 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
327 return BAD_VALUE;
328 }
329 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700330 mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800331 return NO_ERROR;
332}
333
334status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream,
335 int index,
336 audio_devices_t device)
337{
Eric Laurentdce54a12014-03-10 12:19:46 -0700338 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800339 return NO_INIT;
340 }
341 if (!settingsAllowed()) {
342 return PERMISSION_DENIED;
343 }
344 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
345 return BAD_VALUE;
346 }
347 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700348 return mAudioPolicyManager->setStreamVolumeIndex(stream,
349 index,
350 device);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800351}
352
353status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream,
354 int *index,
355 audio_devices_t device)
356{
Eric Laurentdce54a12014-03-10 12:19:46 -0700357 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800358 return NO_INIT;
359 }
360 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
361 return BAD_VALUE;
362 }
363 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700364 return mAudioPolicyManager->getStreamVolumeIndex(stream,
365 index,
366 device);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800367}
368
369uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream)
370{
Eric Laurentdce54a12014-03-10 12:19:46 -0700371 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800372 return 0;
373 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700374 return mAudioPolicyManager->getStrategyForStream(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800375}
376
377//audio policy: use audio_device_t appropriately
378
379audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
380{
Eric Laurentdce54a12014-03-10 12:19:46 -0700381 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800382 return (audio_devices_t)0;
383 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700384 return mAudioPolicyManager->getDevicesForStream(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800385}
386
387audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc)
388{
389 // FIXME change return type to status_t, and return NO_INIT here
Eric Laurentdce54a12014-03-10 12:19:46 -0700390 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800391 return 0;
392 }
393 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700394 return mAudioPolicyManager->getOutputForEffect(desc);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800395}
396
397status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc,
398 audio_io_handle_t io,
399 uint32_t strategy,
400 int session,
401 int id)
402{
Eric Laurentdce54a12014-03-10 12:19:46 -0700403 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800404 return NO_INIT;
405 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700406 return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800407}
408
409status_t AudioPolicyService::unregisterEffect(int id)
410{
Eric Laurentdce54a12014-03-10 12:19:46 -0700411 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800412 return NO_INIT;
413 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700414 return mAudioPolicyManager->unregisterEffect(id);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800415}
416
417status_t AudioPolicyService::setEffectEnabled(int id, bool enabled)
418{
Eric Laurentdce54a12014-03-10 12:19:46 -0700419 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800420 return NO_INIT;
421 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700422 return mAudioPolicyManager->setEffectEnabled(id, enabled);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800423}
424
425bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
426{
Eric Laurentdce54a12014-03-10 12:19:46 -0700427 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800428 return 0;
429 }
430 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700431 return mAudioPolicyManager->isStreamActive(stream, inPastMs);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800432}
433
434bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
435{
Eric Laurentdce54a12014-03-10 12:19:46 -0700436 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800437 return 0;
438 }
439 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700440 return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800441}
442
443bool AudioPolicyService::isSourceActive(audio_source_t source) const
444{
Eric Laurentdce54a12014-03-10 12:19:46 -0700445 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800446 return false;
447 }
448 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700449 return mAudioPolicyManager->isSourceActive(source);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800450}
451
452status_t AudioPolicyService::queryDefaultPreProcessing(int audioSession,
453 effect_descriptor_t *descriptors,
454 uint32_t *count)
455{
Eric Laurentdce54a12014-03-10 12:19:46 -0700456 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800457 *count = 0;
458 return NO_INIT;
459 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700460 sp<AudioPolicyEffects>audioPolicyEffects;
461 {
462 Mutex::Autolock _l(mLock);
463 audioPolicyEffects = mAudioPolicyEffects;
464 }
465 if (audioPolicyEffects == 0) {
466 *count = 0;
467 return NO_INIT;
468 }
469 return audioPolicyEffects->queryDefaultInputEffects(audioSession, descriptors, count);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800470}
471
472bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info)
473{
Eric Laurentdce54a12014-03-10 12:19:46 -0700474 if (mAudioPolicyManager == NULL) {
475 ALOGV("mAudioPolicyManager == NULL");
Eric Laurent2d388ec2014-03-07 13:25:54 -0800476 return false;
477 }
478
Eric Laurentdce54a12014-03-10 12:19:46 -0700479 return mAudioPolicyManager->isOffloadSupported(info);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800480}
481
Eric Laurent6a94d692014-05-20 11:18:06 -0700482status_t AudioPolicyService::listAudioPorts(audio_port_role_t role,
483 audio_port_type_t type,
Eric Laurent203b1a12014-04-01 10:34:16 -0700484 unsigned int *num_ports,
Eric Laurent6a94d692014-05-20 11:18:06 -0700485 struct audio_port *ports,
486 unsigned int *generation)
Eric Laurent203b1a12014-04-01 10:34:16 -0700487{
Eric Laurent6a94d692014-05-20 11:18:06 -0700488 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700489 if(!modifyAudioRoutingAllowed()) {
490 return PERMISSION_DENIED;
491 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700492 if (mAudioPolicyManager == NULL) {
493 return NO_INIT;
494 }
495
496 return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation);
Eric Laurent203b1a12014-04-01 10:34:16 -0700497}
498
Eric Laurent6a94d692014-05-20 11:18:06 -0700499status_t AudioPolicyService::getAudioPort(struct audio_port *port)
Eric Laurent203b1a12014-04-01 10:34:16 -0700500{
Eric Laurent6a94d692014-05-20 11:18:06 -0700501 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700502 if(!modifyAudioRoutingAllowed()) {
503 return PERMISSION_DENIED;
504 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700505 if (mAudioPolicyManager == NULL) {
506 return NO_INIT;
507 }
508
509 return mAudioPolicyManager->getAudioPort(port);
Eric Laurent203b1a12014-04-01 10:34:16 -0700510}
511
Eric Laurent6a94d692014-05-20 11:18:06 -0700512status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch,
513 audio_patch_handle_t *handle)
Eric Laurent203b1a12014-04-01 10:34:16 -0700514{
Eric Laurent6a94d692014-05-20 11:18:06 -0700515 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700516 if(!modifyAudioRoutingAllowed()) {
517 return PERMISSION_DENIED;
518 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700519 if (mAudioPolicyManager == NULL) {
520 return NO_INIT;
521 }
522 return mAudioPolicyManager->createAudioPatch(patch, handle,
523 IPCThreadState::self()->getCallingUid());
Eric Laurent203b1a12014-04-01 10:34:16 -0700524}
525
Eric Laurent6a94d692014-05-20 11:18:06 -0700526status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle)
Eric Laurent203b1a12014-04-01 10:34:16 -0700527{
Eric Laurent6a94d692014-05-20 11:18:06 -0700528 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700529 if(!modifyAudioRoutingAllowed()) {
530 return PERMISSION_DENIED;
531 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700532 if (mAudioPolicyManager == NULL) {
533 return NO_INIT;
534 }
535
536 return mAudioPolicyManager->releaseAudioPatch(handle,
537 IPCThreadState::self()->getCallingUid());
Eric Laurent203b1a12014-04-01 10:34:16 -0700538}
539
540status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches,
Eric Laurent6a94d692014-05-20 11:18:06 -0700541 struct audio_patch *patches,
542 unsigned int *generation)
Eric Laurent203b1a12014-04-01 10:34:16 -0700543{
Eric Laurent6a94d692014-05-20 11:18:06 -0700544 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700545 if(!modifyAudioRoutingAllowed()) {
546 return PERMISSION_DENIED;
547 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700548 if (mAudioPolicyManager == NULL) {
549 return NO_INIT;
550 }
551
552 return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation);
Eric Laurent203b1a12014-04-01 10:34:16 -0700553}
554
Eric Laurent6a94d692014-05-20 11:18:06 -0700555status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config)
Eric Laurent203b1a12014-04-01 10:34:16 -0700556{
Eric Laurent6a94d692014-05-20 11:18:06 -0700557 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700558 if(!modifyAudioRoutingAllowed()) {
559 return PERMISSION_DENIED;
560 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700561 if (mAudioPolicyManager == NULL) {
562 return NO_INIT;
563 }
564
565 return mAudioPolicyManager->setAudioPortConfig(config);
Eric Laurent203b1a12014-04-01 10:34:16 -0700566}
Eric Laurent2d388ec2014-03-07 13:25:54 -0800567
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700568status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session,
569 audio_io_handle_t *ioHandle,
570 audio_devices_t *device)
571{
572 if (mAudioPolicyManager == NULL) {
573 return NO_INIT;
574 }
575
576 return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device);
577}
578
579status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session)
580{
581 if (mAudioPolicyManager == NULL) {
582 return NO_INIT;
583 }
584
585 return mAudioPolicyManager->releaseSoundTriggerSession(session);
586}
587
Eric Laurent2d388ec2014-03-07 13:25:54 -0800588}; // namespace android