blob: 306de3f1230bf5899c4d12777c6bea768d39a6d4 [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,
Paul McLeane743a472015-01-28 11:07:31 -080031 const char *device_address,
32 const char *device_name)
Eric Laurent2d388ec2014-03-07 13:25:54 -080033{
Eric Laurentdce54a12014-03-10 12:19:46 -070034 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080035 return NO_INIT;
36 }
37 if (!settingsAllowed()) {
38 return PERMISSION_DENIED;
39 }
Eric Laurent2d388ec2014-03-07 13:25:54 -080040 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);
Paul McLeane743a472015-01-28 11:07:31 -080047 return mAudioPolicyManager->setDeviceConnectionState(device, state,
48 device_address, device_name);
Eric Laurent2d388ec2014-03-07 13:25:54 -080049}
50
51audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState(
52 audio_devices_t device,
53 const char *device_address)
54{
Eric Laurentdce54a12014-03-10 12:19:46 -070055 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080056 return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE;
57 }
Eric Laurentdce54a12014-03-10 12:19:46 -070058 return mAudioPolicyManager->getDeviceConnectionState(device,
Eric Laurent2d388ec2014-03-07 13:25:54 -080059 device_address);
60}
61
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080062status_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 }
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080072
73 ALOGV("handleDeviceConfigChange()");
74 Mutex::Autolock _l(mLock);
75 return mAudioPolicyManager->handleDeviceConfigChange(device, device_address,
76 device_name);
77}
78
Eric Laurent2d388ec2014-03-07 13:25:54 -080079status_t AudioPolicyService::setPhoneState(audio_mode_t state)
80{
Eric Laurentdce54a12014-03-10 12:19:46 -070081 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -080082 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
Eric Laurentbeb07fe2015-09-16 15:49:30 -070093 // 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
Eric Laurent2d388ec2014-03-07 13:25:54 -080098 // TODO: check if it is more appropriate to do it in platform specific policy manager
99 AudioSystem::setMode(state);
100
Eric Laurentdce54a12014-03-10 12:19:46 -0700101 mAudioPolicyManager->setPhoneState(state);
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700102 mPhoneState = state;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800103 return NO_ERROR;
104}
105
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700106audio_mode_t AudioPolicyService::getPhoneState()
107{
108 Mutex::Autolock _l(mLock);
109 return mPhoneState;
110}
111
Eric Laurent2d388ec2014-03-07 13:25:54 -0800112status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage,
113 audio_policy_forced_cfg_t config)
114{
Eric Laurentdce54a12014-03-10 12:19:46 -0700115 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800116 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);
Eric Laurentdce54a12014-03-10 12:19:46 -0700129 mAudioPolicyManager->setForceUse(usage, config);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800130 return NO_ERROR;
131}
132
133audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage)
134{
Eric Laurentdce54a12014-03-10 12:19:46 -0700135 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800136 return AUDIO_POLICY_FORCE_NONE;
137 }
138 if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) {
139 return AUDIO_POLICY_FORCE_NONE;
140 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700141 return mAudioPolicyManager->getForceUse(usage);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800142}
143
Eric Laurentf4e63452017-11-06 19:31:46 +0000144audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800145{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800146 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700147 return AUDIO_IO_HANDLE_NONE;
Eric Laurentdea15412014-10-28 15:46:45 -0700148 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700149 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700150 return AUDIO_IO_HANDLE_NONE;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800151 }
152 ALOGV("getOutput()");
153 Mutex::Autolock _l(mLock);
Eric Laurentf4e63452017-11-06 19:31:46 +0000154 return mAudioPolicyManager->getOutput(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800155}
156
Eric Laurente83b55d2014-11-14 10:06:21 -0800157status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr,
158 audio_io_handle_t *output,
159 audio_session_t session,
160 audio_stream_type_t *stream,
Nadav Bar766fb022018-01-07 12:18:03 +0200161 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700162 uid_t uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800163 const audio_config_t *config,
Eric Laurente83b55d2014-11-14 10:06:21 -0800164 audio_output_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700165 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800166 audio_port_handle_t *portId)
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700167{
168 if (mAudioPolicyManager == NULL) {
Eric Laurente83b55d2014-11-14 10:06:21 -0800169 return NO_INIT;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700170 }
Eric Laurentf4e63452017-11-06 19:31:46 +0000171 ALOGV("getOutputForAttr()");
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700172 Mutex::Autolock _l(mLock);
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700173
Marco Nelissendcb346b2015-09-09 10:47:29 -0700174 const uid_t callingUid = IPCThreadState::self()->getCallingUid();
175 if (!isTrustedCallingUid(callingUid) || uid == (uid_t)-1) {
176 ALOGW_IF(uid != (uid_t)-1 && uid != callingUid,
177 "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid);
178 uid = callingUid;
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700179 }
Nadav Bar766fb022018-01-07 12:18:03 +0200180 audio_output_flags_t originalFlags = flags;
181 status_t result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800182 config,
Nadav Bar766fb022018-01-07 12:18:03 +0200183 &flags, selectedDeviceId, portId);
184
185 // FIXME: Introduce a way to check for the the telephony device before opening the output
186 if ((result == NO_ERROR) &&
187 (flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) &&
188 !modifyPhoneStateAllowed(pid, uid)) {
189 // If the app tries to play music through the telephony device and doesn't have permission
190 // the fallback to the default output device.
191 mAudioPolicyManager->releaseOutput(*output, *stream, session);
192 flags = originalFlags;
193 *selectedDeviceId = AUDIO_PORT_HANDLE_NONE;
194 *portId = AUDIO_PORT_HANDLE_NONE;
195 result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid,
196 config,
197 &flags, selectedDeviceId, portId);
198 }
199 return result;
Jean-Michel Trivi5bd3f382014-06-13 16:06:54 -0700200}
201
Eric Laurent2d388ec2014-03-07 13:25:54 -0800202status_t AudioPolicyService::startOutput(audio_io_handle_t output,
203 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800204 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800205{
Eric Laurentdea15412014-10-28 15:46:45 -0700206 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
207 return BAD_VALUE;
208 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700209 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800210 return NO_INIT;
211 }
212 ALOGV("startOutput()");
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700213 sp<AudioPolicyEffects>audioPolicyEffects;
214 {
215 Mutex::Autolock _l(mLock);
216 audioPolicyEffects = mAudioPolicyEffects;
bryant_liuba2b4392014-06-11 16:49:30 +0800217 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700218 if (audioPolicyEffects != 0) {
219 // create audio processors according to stream
220 status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session);
221 if (status != NO_ERROR && status != ALREADY_EXISTS) {
222 ALOGW("Failed to add effects on session %d", session);
223 }
224 }
225 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700226 return mAudioPolicyManager->startOutput(output, stream, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800227}
228
229status_t AudioPolicyService::stopOutput(audio_io_handle_t output,
230 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800231 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800232{
Eric Laurentdea15412014-10-28 15:46:45 -0700233 if (uint32_t(stream) >= AUDIO_STREAM_CNT) {
234 return BAD_VALUE;
235 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700236 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800237 return NO_INIT;
238 }
239 ALOGV("stopOutput()");
240 mOutputCommandThread->stopOutputCommand(output, stream, session);
241 return NO_ERROR;
242}
243
244status_t AudioPolicyService::doStopOutput(audio_io_handle_t output,
245 audio_stream_type_t stream,
Eric Laurente83b55d2014-11-14 10:06:21 -0800246 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800247{
248 ALOGV("doStopOutput from tid %d", gettid());
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700249 sp<AudioPolicyEffects>audioPolicyEffects;
250 {
251 Mutex::Autolock _l(mLock);
252 audioPolicyEffects = mAudioPolicyEffects;
bryant_liuba2b4392014-06-11 16:49:30 +0800253 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700254 if (audioPolicyEffects != 0) {
255 // release audio processors from the stream
256 status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session);
257 if (status != NO_ERROR && status != ALREADY_EXISTS) {
258 ALOGW("Failed to release effects on session %d", session);
259 }
260 }
261 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700262 return mAudioPolicyManager->stopOutput(output, stream, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800263}
264
Eric Laurente83b55d2014-11-14 10:06:21 -0800265void AudioPolicyService::releaseOutput(audio_io_handle_t output,
266 audio_stream_type_t stream,
267 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800268{
Eric Laurentdce54a12014-03-10 12:19:46 -0700269 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800270 return;
271 }
272 ALOGV("releaseOutput()");
Eric Laurente83b55d2014-11-14 10:06:21 -0800273 mOutputCommandThread->releaseOutputCommand(output, stream, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800274}
275
Eric Laurente83b55d2014-11-14 10:06:21 -0800276void AudioPolicyService::doReleaseOutput(audio_io_handle_t output,
277 audio_stream_type_t stream,
278 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800279{
280 ALOGV("doReleaseOutput from tid %d", gettid());
281 Mutex::Autolock _l(mLock);
Eric Laurente83b55d2014-11-14 10:06:21 -0800282 mAudioPolicyManager->releaseOutput(output, stream, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800283}
284
Eric Laurentcaf7f482014-11-25 17:50:47 -0800285status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr,
286 audio_io_handle_t *input,
287 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700288 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700289 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -0800290 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800291 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600292 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700293 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800294 audio_port_handle_t *portId)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800295{
Eric Laurentdce54a12014-03-10 12:19:46 -0700296 if (mAudioPolicyManager == NULL) {
Eric Laurentcaf7f482014-11-25 17:50:47 -0800297 return NO_INIT;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800298 }
Eric Laurent7dca8a82018-01-29 18:44:26 -0800299
Eric Laurent2d388ec2014-03-07 13:25:54 -0800300 // already checked by client, but double-check in case the client wrapper is bypassed
Eric Laurentfe231122017-11-17 17:48:06 -0800301 if (attr->source < AUDIO_SOURCE_DEFAULT && attr->source >= AUDIO_SOURCE_CNT &&
302 attr->source != AUDIO_SOURCE_HOTWORD && attr->source != AUDIO_SOURCE_FM_TUNER) {
Eric Laurentcaf7f482014-11-25 17:50:47 -0800303 return BAD_VALUE;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800304 }
305
Eric Laurentb2379ba2016-05-23 17:42:12 -0700306 bool updatePid = (pid == -1);
Marco Nelissendcb346b2015-09-09 10:47:29 -0700307 const uid_t callingUid = IPCThreadState::self()->getCallingUid();
Eric Laurentb2379ba2016-05-23 17:42:12 -0700308 if (!isTrustedCallingUid(callingUid)) {
Eric Laurent9f39f8d2016-05-25 12:34:48 -0700309 ALOGW_IF(uid != (uid_t)-1 && uid != callingUid,
Marco Nelissendcb346b2015-09-09 10:47:29 -0700310 "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid);
311 uid = callingUid;
Eric Laurentb2379ba2016-05-23 17:42:12 -0700312 updatePid = true;
313 }
314
315 if (updatePid) {
316 const pid_t callingPid = IPCThreadState::self()->getCallingPid();
Eric Laurent9f39f8d2016-05-25 12:34:48 -0700317 ALOGW_IF(pid != (pid_t)-1 && pid != callingPid,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700318 "%s uid %d pid %d tried to pass itself off as pid %d",
319 __func__, callingUid, callingPid, pid);
320 pid = callingPid;
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700321 }
322
Eric Laurent7dca8a82018-01-29 18:44:26 -0800323 // check calling permissions
324 if (!recordingAllowed(opPackageName, pid, uid)) {
325 ALOGE("%s permission denied: recording not allowed for uid %d pid %d",
326 __func__, uid, pid);
327 return PERMISSION_DENIED;
328 }
329
Eric Laurent7504b9e2017-08-15 18:17:26 -0700330 if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) {
331 return BAD_VALUE;
332 }
333
334 sp<AudioPolicyEffects>audioPolicyEffects;
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700335 {
Eric Laurent7504b9e2017-08-15 18:17:26 -0700336 status_t status;
337 AudioPolicyInterface::input_type_t inputType;
338
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700339 Mutex::Autolock _l(mLock);
340 // the audio_in_acoustics_t parameter is ignored by get_input()
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700341 status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800342 config,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700343 flags, selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800344 &inputType, portId);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700345 audioPolicyEffects = mAudioPolicyEffects;
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800346
347 if (status == NO_ERROR) {
348 // enforce permission (if any) required for each type of input
349 switch (inputType) {
350 case AudioPolicyInterface::API_INPUT_LEGACY:
351 break;
Eric Laurent82db2692015-08-07 13:59:42 -0700352 case AudioPolicyInterface::API_INPUT_TELEPHONY_RX:
353 // FIXME: use the same permission as for remote submix for now.
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800354 case AudioPolicyInterface::API_INPUT_MIX_CAPTURE:
Eric Laurentb2379ba2016-05-23 17:42:12 -0700355 if (!captureAudioOutputAllowed(pid, uid)) {
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800356 ALOGE("getInputForAttr() permission denied: capture not allowed");
357 status = PERMISSION_DENIED;
358 }
359 break;
360 case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE:
361 if (!modifyAudioRoutingAllowed()) {
362 ALOGE("getInputForAttr() permission denied: modify audio routing not allowed");
363 status = PERMISSION_DENIED;
364 }
365 break;
366 case AudioPolicyInterface::API_INPUT_INVALID:
367 default:
368 LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d",
369 (int)inputType);
370 }
371 }
372
373 if (status != NO_ERROR) {
374 if (status == PERMISSION_DENIED) {
375 mAudioPolicyManager->releaseInput(*input, session);
376 }
377 return status;
378 }
Eric Laurentfee19762018-01-29 18:44:13 -0800379
380 sp<AudioRecordClient> client =
381 new AudioRecordClient(*attr, *input, uid, pid, opPackageName, session);
382 client->active = false;
383 client->isConcurrent = false;
384 client->isVirtualDevice = false; //TODO : update from APM->getInputForAttr()
385 mAudioRecordClients.add(*portId, client);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700386 }
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800387
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700388 if (audioPolicyEffects != 0) {
389 // create audio pre processors according to input source
Eric Laurentcaf7f482014-11-25 17:50:47 -0800390 status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700391 if (status != NO_ERROR && status != ALREADY_EXISTS) {
Eric Laurentcaf7f482014-11-25 17:50:47 -0800392 ALOGW("Failed to add effects on input %d", *input);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700393 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800394 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800395 return NO_ERROR;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800396}
397
Eric Laurentfee19762018-01-29 18:44:13 -0800398status_t AudioPolicyService::startInput(audio_port_handle_t portId, bool *silenced)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800399{
Eric Laurentdce54a12014-03-10 12:19:46 -0700400 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800401 return NO_INIT;
402 }
Eric Laurent7dca8a82018-01-29 18:44:26 -0800403 sp<AudioRecordClient> client;
404 {
405 Mutex::Autolock _l(mLock);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800406
Eric Laurent7dca8a82018-01-29 18:44:26 -0800407 ssize_t index = mAudioRecordClients.indexOfKey(portId);
408 if (index < 0) {
409 return INVALID_OPERATION;
410 }
411 client = mAudioRecordClients.valueAt(index);
Eric Laurentfee19762018-01-29 18:44:13 -0800412 }
Eric Laurent7dca8a82018-01-29 18:44:26 -0800413
414 // check calling permissions
415 if (!recordingAllowed(client->opPackageName, client->pid, client->uid)) {
416 ALOGE("%s permission denied: recording not allowed for uid %d pid %d",
417 __func__, client->uid, client->pid);
418 return PERMISSION_DENIED;
419 }
Eric Laurentfee19762018-01-29 18:44:13 -0800420
421 // If UID inactive it records silence until becoming active
422 *silenced = !mUidPolicy->isUidActive(client->uid) && !client->isVirtualDevice;
423
Eric Laurent7dca8a82018-01-29 18:44:26 -0800424 Mutex::Autolock _l(mLock);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800425 AudioPolicyInterface::concurrency_type__mask_t concurrency =
426 AudioPolicyInterface::API_INPUT_CONCURRENCY_NONE;
Eric Laurentfee19762018-01-29 18:44:13 -0800427
428 status_t status = mAudioPolicyManager->startInput(
429 client->input, client->session, *silenced, &concurrency);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800430
Eric Laurentfb66dd92016-01-28 18:32:03 -0800431 if (status == NO_ERROR) {
Eric Laurent43423352016-02-05 11:57:57 -0800432 LOG_ALWAYS_FATAL_IF(concurrency & ~AudioPolicyInterface::API_INPUT_CONCURRENCY_ALL,
433 "startInput(): invalid concurrency type %d", (int)concurrency);
434
Eric Laurentfb66dd92016-01-28 18:32:03 -0800435 // enforce permission (if any) required for each type of concurrency
Eric Laurent43423352016-02-05 11:57:57 -0800436 if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CALL) {
Eric Laurentfb66dd92016-01-28 18:32:03 -0800437 //TODO: check incall capture permission
Eric Laurent43423352016-02-05 11:57:57 -0800438 }
439 if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CAPTURE) {
Eric Laurentfb66dd92016-01-28 18:32:03 -0800440 //TODO: check concurrent capture permission
Eric Laurentfb66dd92016-01-28 18:32:03 -0800441 }
442 }
443
444 return status;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800445}
446
Eric Laurentfee19762018-01-29 18:44:13 -0800447status_t AudioPolicyService::stopInput(audio_port_handle_t portId)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800448{
Eric Laurentdce54a12014-03-10 12:19:46 -0700449 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800450 return NO_INIT;
451 }
452 Mutex::Autolock _l(mLock);
453
Eric Laurentfee19762018-01-29 18:44:13 -0800454 ssize_t index = mAudioRecordClients.indexOfKey(portId);
455 if (index < 0) {
456 return INVALID_OPERATION;
457 }
458 sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index);
459
460 return mAudioPolicyManager->stopInput(client->input, client->session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800461}
462
Eric Laurentfee19762018-01-29 18:44:13 -0800463void AudioPolicyService::releaseInput(audio_port_handle_t portId)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800464{
Eric Laurentdce54a12014-03-10 12:19:46 -0700465 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800466 return;
467 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700468 sp<AudioPolicyEffects>audioPolicyEffects;
Eric Laurentfee19762018-01-29 18:44:13 -0800469 sp<AudioRecordClient> client;
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700470 {
471 Mutex::Autolock _l(mLock);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700472 audioPolicyEffects = mAudioPolicyEffects;
Eric Laurentfee19762018-01-29 18:44:13 -0800473 ssize_t index = mAudioRecordClients.indexOfKey(portId);
474 if (index < 0) {
475 return;
476 }
477 client = mAudioRecordClients.valueAt(index);
478 mAudioRecordClients.removeItem(portId);
479 }
480 if (client == 0) {
481 return;
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700482 }
483 if (audioPolicyEffects != 0) {
484 // release audio processors from the input
Eric Laurentfee19762018-01-29 18:44:13 -0800485 status_t status = audioPolicyEffects->releaseInputEffects(client->input, client->session);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700486 if(status != NO_ERROR) {
Eric Laurentfee19762018-01-29 18:44:13 -0800487 ALOGW("Failed to release effects on input %d", client->input);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700488 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800489 }
Eric Laurentf10c7092016-12-06 17:09:56 -0800490 {
491 Mutex::Autolock _l(mLock);
Eric Laurentfee19762018-01-29 18:44:13 -0800492 mAudioPolicyManager->releaseInput(client->input, client->session);
Eric Laurentf10c7092016-12-06 17:09:56 -0800493 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800494}
495
496status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream,
497 int indexMin,
498 int indexMax)
499{
Eric Laurentdce54a12014-03-10 12:19:46 -0700500 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800501 return NO_INIT;
502 }
503 if (!settingsAllowed()) {
504 return PERMISSION_DENIED;
505 }
Eric Laurent223fd5c2014-11-11 13:43:36 -0800506 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800507 return BAD_VALUE;
508 }
509 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700510 mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800511 return NO_ERROR;
512}
513
514status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream,
515 int index,
516 audio_devices_t device)
517{
Eric Laurentdce54a12014-03-10 12:19:46 -0700518 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800519 return NO_INIT;
520 }
521 if (!settingsAllowed()) {
522 return PERMISSION_DENIED;
523 }
Eric Laurent223fd5c2014-11-11 13:43:36 -0800524 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800525 return BAD_VALUE;
526 }
527 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700528 return mAudioPolicyManager->setStreamVolumeIndex(stream,
529 index,
530 device);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800531}
532
533status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream,
534 int *index,
535 audio_devices_t device)
536{
Eric Laurentdce54a12014-03-10 12:19:46 -0700537 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800538 return NO_INIT;
539 }
Eric Laurent223fd5c2014-11-11 13:43:36 -0800540 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800541 return BAD_VALUE;
542 }
543 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700544 return mAudioPolicyManager->getStreamVolumeIndex(stream,
545 index,
546 device);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800547}
548
549uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream)
550{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800551 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700552 return 0;
Eric Laurentdea15412014-10-28 15:46:45 -0700553 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700554 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800555 return 0;
556 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700557 return mAudioPolicyManager->getStrategyForStream(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800558}
559
560//audio policy: use audio_device_t appropriately
561
562audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
563{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800564 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700565 return AUDIO_DEVICE_NONE;
Eric Laurentdea15412014-10-28 15:46:45 -0700566 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700567 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700568 return AUDIO_DEVICE_NONE;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800569 }
Haynes Mathew Georgedfb9f3b2015-10-26 18:22:13 -0700570 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700571 return mAudioPolicyManager->getDevicesForStream(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800572}
573
574audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc)
575{
576 // FIXME change return type to status_t, and return NO_INIT here
Eric Laurentdce54a12014-03-10 12:19:46 -0700577 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800578 return 0;
579 }
580 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700581 return mAudioPolicyManager->getOutputForEffect(desc);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800582}
583
584status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc,
585 audio_io_handle_t io,
586 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800587 audio_session_t session,
Eric Laurent2d388ec2014-03-07 13:25:54 -0800588 int id)
589{
Eric Laurentdce54a12014-03-10 12:19:46 -0700590 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800591 return NO_INIT;
592 }
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700593 Mutex::Autolock _l(mEffectsLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700594 return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800595}
596
597status_t AudioPolicyService::unregisterEffect(int id)
598{
Eric Laurentdce54a12014-03-10 12:19:46 -0700599 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800600 return NO_INIT;
601 }
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700602 Mutex::Autolock _l(mEffectsLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700603 return mAudioPolicyManager->unregisterEffect(id);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800604}
605
606status_t AudioPolicyService::setEffectEnabled(int id, bool enabled)
607{
Eric Laurentdce54a12014-03-10 12:19:46 -0700608 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800609 return NO_INIT;
610 }
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700611 Mutex::Autolock _l(mEffectsLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700612 return mAudioPolicyManager->setEffectEnabled(id, enabled);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800613}
614
615bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
616{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800617 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700618 return false;
Eric Laurentdea15412014-10-28 15:46:45 -0700619 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700620 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700621 return false;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800622 }
623 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700624 return mAudioPolicyManager->isStreamActive(stream, inPastMs);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800625}
626
627bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
628{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800629 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700630 return false;
Eric Laurentdea15412014-10-28 15:46:45 -0700631 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700632 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700633 return false;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800634 }
635 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700636 return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800637}
638
639bool AudioPolicyService::isSourceActive(audio_source_t source) const
640{
Eric Laurentdce54a12014-03-10 12:19:46 -0700641 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800642 return false;
643 }
644 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700645 return mAudioPolicyManager->isSourceActive(source);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800646}
647
Glenn Kastend848eb42016-03-08 13:42:11 -0800648status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent2d388ec2014-03-07 13:25:54 -0800649 effect_descriptor_t *descriptors,
650 uint32_t *count)
651{
Eric Laurentdce54a12014-03-10 12:19:46 -0700652 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800653 *count = 0;
654 return NO_INIT;
655 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700656 sp<AudioPolicyEffects>audioPolicyEffects;
657 {
658 Mutex::Autolock _l(mLock);
659 audioPolicyEffects = mAudioPolicyEffects;
660 }
661 if (audioPolicyEffects == 0) {
662 *count = 0;
663 return NO_INIT;
664 }
Eric Laurentfb66dd92016-01-28 18:32:03 -0800665 return audioPolicyEffects->queryDefaultInputEffects(
666 (audio_session_t)audioSession, descriptors, count);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800667}
668
669bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info)
670{
Eric Laurentdce54a12014-03-10 12:19:46 -0700671 if (mAudioPolicyManager == NULL) {
672 ALOGV("mAudioPolicyManager == NULL");
Eric Laurent2d388ec2014-03-07 13:25:54 -0800673 return false;
674 }
Andy Hung2ddee192015-12-18 17:34:44 -0800675 Mutex::Autolock _l(mLock);
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700676 Mutex::Autolock _le(mEffectsLock); // isOffloadSupported queries for
677 // non-offloadable effects
Eric Laurentdce54a12014-03-10 12:19:46 -0700678 return mAudioPolicyManager->isOffloadSupported(info);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800679}
680
Eric Laurent6a94d692014-05-20 11:18:06 -0700681status_t AudioPolicyService::listAudioPorts(audio_port_role_t role,
682 audio_port_type_t type,
Eric Laurent203b1a12014-04-01 10:34:16 -0700683 unsigned int *num_ports,
Eric Laurent6a94d692014-05-20 11:18:06 -0700684 struct audio_port *ports,
685 unsigned int *generation)
Eric Laurent203b1a12014-04-01 10:34:16 -0700686{
Eric Laurent6a94d692014-05-20 11:18:06 -0700687 Mutex::Autolock _l(mLock);
688 if (mAudioPolicyManager == NULL) {
689 return NO_INIT;
690 }
691
692 return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation);
Eric Laurent203b1a12014-04-01 10:34:16 -0700693}
694
Eric Laurent6a94d692014-05-20 11:18:06 -0700695status_t AudioPolicyService::getAudioPort(struct audio_port *port)
Eric Laurent203b1a12014-04-01 10:34:16 -0700696{
Eric Laurent6a94d692014-05-20 11:18:06 -0700697 Mutex::Autolock _l(mLock);
698 if (mAudioPolicyManager == NULL) {
699 return NO_INIT;
700 }
701
702 return mAudioPolicyManager->getAudioPort(port);
Eric Laurent203b1a12014-04-01 10:34:16 -0700703}
704
Eric Laurent6a94d692014-05-20 11:18:06 -0700705status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch,
706 audio_patch_handle_t *handle)
Eric Laurent203b1a12014-04-01 10:34:16 -0700707{
Eric Laurent6a94d692014-05-20 11:18:06 -0700708 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700709 if(!modifyAudioRoutingAllowed()) {
710 return PERMISSION_DENIED;
711 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700712 if (mAudioPolicyManager == NULL) {
713 return NO_INIT;
714 }
715 return mAudioPolicyManager->createAudioPatch(patch, handle,
716 IPCThreadState::self()->getCallingUid());
Eric Laurent203b1a12014-04-01 10:34:16 -0700717}
718
Eric Laurent6a94d692014-05-20 11:18:06 -0700719status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle)
Eric Laurent203b1a12014-04-01 10:34:16 -0700720{
Eric Laurent6a94d692014-05-20 11:18:06 -0700721 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700722 if(!modifyAudioRoutingAllowed()) {
723 return PERMISSION_DENIED;
724 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700725 if (mAudioPolicyManager == NULL) {
726 return NO_INIT;
727 }
728
729 return mAudioPolicyManager->releaseAudioPatch(handle,
730 IPCThreadState::self()->getCallingUid());
Eric Laurent203b1a12014-04-01 10:34:16 -0700731}
732
733status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches,
Eric Laurent6a94d692014-05-20 11:18:06 -0700734 struct audio_patch *patches,
735 unsigned int *generation)
Eric Laurent203b1a12014-04-01 10:34:16 -0700736{
Eric Laurent6a94d692014-05-20 11:18:06 -0700737 Mutex::Autolock _l(mLock);
738 if (mAudioPolicyManager == NULL) {
739 return NO_INIT;
740 }
741
742 return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation);
Eric Laurent203b1a12014-04-01 10:34:16 -0700743}
744
Eric Laurent6a94d692014-05-20 11:18:06 -0700745status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config)
Eric Laurent203b1a12014-04-01 10:34:16 -0700746{
Eric Laurent6a94d692014-05-20 11:18:06 -0700747 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700748 if(!modifyAudioRoutingAllowed()) {
749 return PERMISSION_DENIED;
750 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700751 if (mAudioPolicyManager == NULL) {
752 return NO_INIT;
753 }
754
755 return mAudioPolicyManager->setAudioPortConfig(config);
Eric Laurent203b1a12014-04-01 10:34:16 -0700756}
Eric Laurent2d388ec2014-03-07 13:25:54 -0800757
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700758status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session,
759 audio_io_handle_t *ioHandle,
760 audio_devices_t *device)
761{
Andy Hungf759b8c2017-08-15 12:48:54 -0700762 Mutex::Autolock _l(mLock);
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700763 if (mAudioPolicyManager == NULL) {
764 return NO_INIT;
765 }
766
767 return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device);
768}
769
770status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session)
771{
Andy Hungf759b8c2017-08-15 12:48:54 -0700772 Mutex::Autolock _l(mLock);
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700773 if (mAudioPolicyManager == NULL) {
774 return NO_INIT;
775 }
776
777 return mAudioPolicyManager->releaseSoundTriggerSession(session);
778}
779
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700780status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800781{
782 Mutex::Autolock _l(mLock);
783 if(!modifyAudioRoutingAllowed()) {
784 return PERMISSION_DENIED;
785 }
786 if (mAudioPolicyManager == NULL) {
787 return NO_INIT;
788 }
789 if (registration) {
790 return mAudioPolicyManager->registerPolicyMixes(mixes);
791 } else {
792 return mAudioPolicyManager->unregisterPolicyMixes(mixes);
793 }
794}
795
Eric Laurent554a2772015-04-10 11:29:24 -0700796status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source,
797 const audio_attributes_t *attributes,
Glenn Kasten559d4392016-03-29 13:42:57 -0700798 audio_patch_handle_t *handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700799{
800 Mutex::Autolock _l(mLock);
801 if (mAudioPolicyManager == NULL) {
802 return NO_INIT;
803 }
804
Eric Laurentd60560a2015-04-10 11:31:20 -0700805 return mAudioPolicyManager->startAudioSource(source, attributes, handle,
806 IPCThreadState::self()->getCallingUid());
Eric Laurent554a2772015-04-10 11:29:24 -0700807}
808
Glenn Kasten559d4392016-03-29 13:42:57 -0700809status_t AudioPolicyService::stopAudioSource(audio_patch_handle_t handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700810{
811 Mutex::Autolock _l(mLock);
812 if (mAudioPolicyManager == NULL) {
813 return NO_INIT;
814 }
815
816 return mAudioPolicyManager->stopAudioSource(handle);
817}
818
Andy Hung2ddee192015-12-18 17:34:44 -0800819status_t AudioPolicyService::setMasterMono(bool mono)
820{
821 if (mAudioPolicyManager == NULL) {
822 return NO_INIT;
823 }
824 if (!settingsAllowed()) {
825 return PERMISSION_DENIED;
826 }
827 Mutex::Autolock _l(mLock);
828 return mAudioPolicyManager->setMasterMono(mono);
829}
830
831status_t AudioPolicyService::getMasterMono(bool *mono)
832{
833 if (mAudioPolicyManager == NULL) {
834 return NO_INIT;
835 }
836 Mutex::Autolock _l(mLock);
837 return mAudioPolicyManager->getMasterMono(mono);
838}
839
Eric Laurentac9cef52017-06-09 15:46:26 -0700840
841float AudioPolicyService::getStreamVolumeDB(
842 audio_stream_type_t stream, int index, audio_devices_t device)
843{
844 if (mAudioPolicyManager == NULL) {
845 return NAN;
846 }
847 Mutex::Autolock _l(mLock);
848 return mAudioPolicyManager->getStreamVolumeDB(stream, index, device);
849}
850
851
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800852} // namespace android