blob: f1d7d86850ebb0374d9d45d3cd8b01c12c040107 [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 Laurent20b9ef02016-12-05 11:03:16 -0800290 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -0600291 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700292 audio_port_handle_t *selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800293 audio_port_handle_t *portId)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800294{
Eric Laurentdce54a12014-03-10 12:19:46 -0700295 if (mAudioPolicyManager == NULL) {
Eric Laurentcaf7f482014-11-25 17:50:47 -0800296 return NO_INIT;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800297 }
298 // already checked by client, but double-check in case the client wrapper is bypassed
Eric Laurentfe231122017-11-17 17:48:06 -0800299 if (attr->source < AUDIO_SOURCE_DEFAULT && attr->source >= AUDIO_SOURCE_CNT &&
300 attr->source != AUDIO_SOURCE_HOTWORD && attr->source != AUDIO_SOURCE_FM_TUNER) {
Eric Laurentcaf7f482014-11-25 17:50:47 -0800301 return BAD_VALUE;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800302 }
303
Eric Laurentb2379ba2016-05-23 17:42:12 -0700304 bool updatePid = (pid == -1);
Marco Nelissendcb346b2015-09-09 10:47:29 -0700305 const uid_t callingUid = IPCThreadState::self()->getCallingUid();
Eric Laurentb2379ba2016-05-23 17:42:12 -0700306 if (!isTrustedCallingUid(callingUid)) {
Eric Laurent9f39f8d2016-05-25 12:34:48 -0700307 ALOGW_IF(uid != (uid_t)-1 && uid != callingUid,
Marco Nelissendcb346b2015-09-09 10:47:29 -0700308 "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid);
309 uid = callingUid;
Eric Laurentb2379ba2016-05-23 17:42:12 -0700310 updatePid = true;
311 }
312
313 if (updatePid) {
314 const pid_t callingPid = IPCThreadState::self()->getCallingPid();
Eric Laurent9f39f8d2016-05-25 12:34:48 -0700315 ALOGW_IF(pid != (pid_t)-1 && pid != callingPid,
Eric Laurentb2379ba2016-05-23 17:42:12 -0700316 "%s uid %d pid %d tried to pass itself off as pid %d",
317 __func__, callingUid, callingPid, pid);
318 pid = callingPid;
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700319 }
320
Eric Laurent7504b9e2017-08-15 18:17:26 -0700321 if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) {
322 return BAD_VALUE;
323 }
324
325 sp<AudioPolicyEffects>audioPolicyEffects;
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700326 {
Eric Laurent7504b9e2017-08-15 18:17:26 -0700327 status_t status;
328 AudioPolicyInterface::input_type_t inputType;
329
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700330 Mutex::Autolock _l(mLock);
331 // the audio_in_acoustics_t parameter is ignored by get_input()
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700332 status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800333 config,
Eric Laurent8c7e6da2015-04-21 17:37:00 -0700334 flags, selectedDeviceId,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800335 &inputType, portId);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700336 audioPolicyEffects = mAudioPolicyEffects;
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800337
338 if (status == NO_ERROR) {
339 // enforce permission (if any) required for each type of input
340 switch (inputType) {
341 case AudioPolicyInterface::API_INPUT_LEGACY:
342 break;
Eric Laurent82db2692015-08-07 13:59:42 -0700343 case AudioPolicyInterface::API_INPUT_TELEPHONY_RX:
344 // FIXME: use the same permission as for remote submix for now.
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800345 case AudioPolicyInterface::API_INPUT_MIX_CAPTURE:
Eric Laurentb2379ba2016-05-23 17:42:12 -0700346 if (!captureAudioOutputAllowed(pid, uid)) {
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800347 ALOGE("getInputForAttr() permission denied: capture not allowed");
348 status = PERMISSION_DENIED;
349 }
350 break;
351 case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE:
352 if (!modifyAudioRoutingAllowed()) {
353 ALOGE("getInputForAttr() permission denied: modify audio routing not allowed");
354 status = PERMISSION_DENIED;
355 }
356 break;
357 case AudioPolicyInterface::API_INPUT_INVALID:
358 default:
359 LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d",
360 (int)inputType);
361 }
362 }
363
364 if (status != NO_ERROR) {
365 if (status == PERMISSION_DENIED) {
366 mAudioPolicyManager->releaseInput(*input, session);
367 }
368 return status;
369 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700370 }
Jean-Michel Trivi97bb33f2014-12-12 16:23:43 -0800371
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700372 if (audioPolicyEffects != 0) {
373 // create audio pre processors according to input source
Eric Laurentcaf7f482014-11-25 17:50:47 -0800374 status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700375 if (status != NO_ERROR && status != ALREADY_EXISTS) {
Eric Laurentcaf7f482014-11-25 17:50:47 -0800376 ALOGW("Failed to add effects on input %d", *input);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700377 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800378 }
Eric Laurentcaf7f482014-11-25 17:50:47 -0800379 return NO_ERROR;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800380}
381
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800382status_t AudioPolicyService::startInput(audio_io_handle_t input,
383 audio_session_t session,
384 audio_devices_t device,
385 uid_t uid,
386 bool *silenced)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800387{
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800388 // If UID inactive it records silence until becoming active
389 *silenced = !mUidPolicy->isUidActive(uid) && !is_virtual_input_device(device);
390
Eric Laurentdce54a12014-03-10 12:19:46 -0700391 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800392 return NO_INIT;
393 }
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800394
Eric Laurent67651f92018-01-29 14:27:03 -0800395 Mutex::Autolock _l(mLock);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800396 AudioPolicyInterface::concurrency_type__mask_t concurrency =
397 AudioPolicyInterface::API_INPUT_CONCURRENCY_NONE;
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800398 status_t status = mAudioPolicyManager->startInput(input, session, *silenced, &concurrency);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800399
Eric Laurentfb66dd92016-01-28 18:32:03 -0800400 if (status == NO_ERROR) {
Eric Laurent43423352016-02-05 11:57:57 -0800401 LOG_ALWAYS_FATAL_IF(concurrency & ~AudioPolicyInterface::API_INPUT_CONCURRENCY_ALL,
402 "startInput(): invalid concurrency type %d", (int)concurrency);
403
Eric Laurentfb66dd92016-01-28 18:32:03 -0800404 // enforce permission (if any) required for each type of concurrency
Eric Laurent43423352016-02-05 11:57:57 -0800405 if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CALL) {
Eric Laurentfb66dd92016-01-28 18:32:03 -0800406 //TODO: check incall capture permission
Eric Laurent43423352016-02-05 11:57:57 -0800407 }
408 if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CAPTURE) {
Eric Laurentfb66dd92016-01-28 18:32:03 -0800409 //TODO: check concurrent capture permission
Eric Laurentfb66dd92016-01-28 18:32:03 -0800410 }
411 }
412
413 return status;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800414}
415
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800416status_t AudioPolicyService::stopInput(audio_io_handle_t input,
417 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800418{
Eric Laurentdce54a12014-03-10 12:19:46 -0700419 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800420 return NO_INIT;
421 }
422 Mutex::Autolock _l(mLock);
423
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800424 return mAudioPolicyManager->stopInput(input, session);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800425}
426
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800427void AudioPolicyService::releaseInput(audio_io_handle_t input,
428 audio_session_t session)
Eric Laurent2d388ec2014-03-07 13:25:54 -0800429{
Eric Laurentdce54a12014-03-10 12:19:46 -0700430 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800431 return;
432 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700433 sp<AudioPolicyEffects>audioPolicyEffects;
434 {
435 Mutex::Autolock _l(mLock);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700436 audioPolicyEffects = mAudioPolicyEffects;
437 }
438 if (audioPolicyEffects != 0) {
439 // release audio processors from the input
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800440 status_t status = audioPolicyEffects->releaseInputEffects(input, session);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700441 if(status != NO_ERROR) {
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800442 ALOGW("Failed to release effects on input %d", input);
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700443 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800444 }
Eric Laurentf10c7092016-12-06 17:09:56 -0800445 {
446 Mutex::Autolock _l(mLock);
Eric Laurente9ebcdb2018-01-29 14:27:18 -0800447 mAudioPolicyManager->releaseInput(input, session);
Eric Laurentf10c7092016-12-06 17:09:56 -0800448 }
Eric Laurent2d388ec2014-03-07 13:25:54 -0800449}
450
451status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream,
452 int indexMin,
453 int indexMax)
454{
Eric Laurentdce54a12014-03-10 12:19:46 -0700455 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800456 return NO_INIT;
457 }
458 if (!settingsAllowed()) {
459 return PERMISSION_DENIED;
460 }
Eric Laurent223fd5c2014-11-11 13:43:36 -0800461 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800462 return BAD_VALUE;
463 }
464 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700465 mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800466 return NO_ERROR;
467}
468
469status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream,
470 int index,
471 audio_devices_t device)
472{
Eric Laurentdce54a12014-03-10 12:19:46 -0700473 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800474 return NO_INIT;
475 }
476 if (!settingsAllowed()) {
477 return PERMISSION_DENIED;
478 }
Eric Laurent223fd5c2014-11-11 13:43:36 -0800479 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800480 return BAD_VALUE;
481 }
482 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700483 return mAudioPolicyManager->setStreamVolumeIndex(stream,
484 index,
485 device);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800486}
487
488status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream,
489 int *index,
490 audio_devices_t device)
491{
Eric Laurentdce54a12014-03-10 12:19:46 -0700492 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800493 return NO_INIT;
494 }
Eric Laurent223fd5c2014-11-11 13:43:36 -0800495 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800496 return BAD_VALUE;
497 }
498 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700499 return mAudioPolicyManager->getStreamVolumeIndex(stream,
500 index,
501 device);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800502}
503
504uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream)
505{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800506 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700507 return 0;
Eric Laurentdea15412014-10-28 15:46:45 -0700508 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700509 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800510 return 0;
511 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700512 return mAudioPolicyManager->getStrategyForStream(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800513}
514
515//audio policy: use audio_device_t appropriately
516
517audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream)
518{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800519 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700520 return AUDIO_DEVICE_NONE;
Eric Laurentdea15412014-10-28 15:46:45 -0700521 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700522 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700523 return AUDIO_DEVICE_NONE;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800524 }
Haynes Mathew Georgedfb9f3b2015-10-26 18:22:13 -0700525 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700526 return mAudioPolicyManager->getDevicesForStream(stream);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800527}
528
529audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc)
530{
531 // FIXME change return type to status_t, and return NO_INIT here
Eric Laurentdce54a12014-03-10 12:19:46 -0700532 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800533 return 0;
534 }
535 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700536 return mAudioPolicyManager->getOutputForEffect(desc);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800537}
538
539status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc,
540 audio_io_handle_t io,
541 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800542 audio_session_t session,
Eric Laurent2d388ec2014-03-07 13:25:54 -0800543 int id)
544{
Eric Laurentdce54a12014-03-10 12:19:46 -0700545 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800546 return NO_INIT;
547 }
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700548 Mutex::Autolock _l(mEffectsLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700549 return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800550}
551
552status_t AudioPolicyService::unregisterEffect(int id)
553{
Eric Laurentdce54a12014-03-10 12:19:46 -0700554 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800555 return NO_INIT;
556 }
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700557 Mutex::Autolock _l(mEffectsLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700558 return mAudioPolicyManager->unregisterEffect(id);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800559}
560
561status_t AudioPolicyService::setEffectEnabled(int id, bool enabled)
562{
Eric Laurentdce54a12014-03-10 12:19:46 -0700563 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800564 return NO_INIT;
565 }
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700566 Mutex::Autolock _l(mEffectsLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700567 return mAudioPolicyManager->setEffectEnabled(id, enabled);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800568}
569
570bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const
571{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800572 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700573 return false;
Eric Laurentdea15412014-10-28 15:46:45 -0700574 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700575 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700576 return false;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800577 }
578 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700579 return mAudioPolicyManager->isStreamActive(stream, inPastMs);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800580}
581
582bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const
583{
Eric Laurent223fd5c2014-11-11 13:43:36 -0800584 if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700585 return false;
Eric Laurentdea15412014-10-28 15:46:45 -0700586 }
Eric Laurentdce54a12014-03-10 12:19:46 -0700587 if (mAudioPolicyManager == NULL) {
Eric Laurentb1322c72014-10-30 14:59:13 -0700588 return false;
Eric Laurent2d388ec2014-03-07 13:25:54 -0800589 }
590 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700591 return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800592}
593
594bool AudioPolicyService::isSourceActive(audio_source_t source) const
595{
Eric Laurentdce54a12014-03-10 12:19:46 -0700596 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800597 return false;
598 }
599 Mutex::Autolock _l(mLock);
Eric Laurentdce54a12014-03-10 12:19:46 -0700600 return mAudioPolicyManager->isSourceActive(source);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800601}
602
Glenn Kastend848eb42016-03-08 13:42:11 -0800603status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent2d388ec2014-03-07 13:25:54 -0800604 effect_descriptor_t *descriptors,
605 uint32_t *count)
606{
Eric Laurentdce54a12014-03-10 12:19:46 -0700607 if (mAudioPolicyManager == NULL) {
Eric Laurent2d388ec2014-03-07 13:25:54 -0800608 *count = 0;
609 return NO_INIT;
610 }
Eric Laurent8b1e80b2014-10-07 09:08:47 -0700611 sp<AudioPolicyEffects>audioPolicyEffects;
612 {
613 Mutex::Autolock _l(mLock);
614 audioPolicyEffects = mAudioPolicyEffects;
615 }
616 if (audioPolicyEffects == 0) {
617 *count = 0;
618 return NO_INIT;
619 }
Eric Laurentfb66dd92016-01-28 18:32:03 -0800620 return audioPolicyEffects->queryDefaultInputEffects(
621 (audio_session_t)audioSession, descriptors, count);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800622}
623
624bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info)
625{
Eric Laurentdce54a12014-03-10 12:19:46 -0700626 if (mAudioPolicyManager == NULL) {
627 ALOGV("mAudioPolicyManager == NULL");
Eric Laurent2d388ec2014-03-07 13:25:54 -0800628 return false;
629 }
Andy Hung2ddee192015-12-18 17:34:44 -0800630 Mutex::Autolock _l(mLock);
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700631 Mutex::Autolock _le(mEffectsLock); // isOffloadSupported queries for
632 // non-offloadable effects
Eric Laurentdce54a12014-03-10 12:19:46 -0700633 return mAudioPolicyManager->isOffloadSupported(info);
Eric Laurent2d388ec2014-03-07 13:25:54 -0800634}
635
Eric Laurent6a94d692014-05-20 11:18:06 -0700636status_t AudioPolicyService::listAudioPorts(audio_port_role_t role,
637 audio_port_type_t type,
Eric Laurent203b1a12014-04-01 10:34:16 -0700638 unsigned int *num_ports,
Eric Laurent6a94d692014-05-20 11:18:06 -0700639 struct audio_port *ports,
640 unsigned int *generation)
Eric Laurent203b1a12014-04-01 10:34:16 -0700641{
Eric Laurent6a94d692014-05-20 11:18:06 -0700642 Mutex::Autolock _l(mLock);
643 if (mAudioPolicyManager == NULL) {
644 return NO_INIT;
645 }
646
647 return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation);
Eric Laurent203b1a12014-04-01 10:34:16 -0700648}
649
Eric Laurent6a94d692014-05-20 11:18:06 -0700650status_t AudioPolicyService::getAudioPort(struct audio_port *port)
Eric Laurent203b1a12014-04-01 10:34:16 -0700651{
Eric Laurent6a94d692014-05-20 11:18:06 -0700652 Mutex::Autolock _l(mLock);
653 if (mAudioPolicyManager == NULL) {
654 return NO_INIT;
655 }
656
657 return mAudioPolicyManager->getAudioPort(port);
Eric Laurent203b1a12014-04-01 10:34:16 -0700658}
659
Eric Laurent6a94d692014-05-20 11:18:06 -0700660status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch,
661 audio_patch_handle_t *handle)
Eric Laurent203b1a12014-04-01 10:34:16 -0700662{
Eric Laurent6a94d692014-05-20 11:18:06 -0700663 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700664 if(!modifyAudioRoutingAllowed()) {
665 return PERMISSION_DENIED;
666 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700667 if (mAudioPolicyManager == NULL) {
668 return NO_INIT;
669 }
670 return mAudioPolicyManager->createAudioPatch(patch, handle,
671 IPCThreadState::self()->getCallingUid());
Eric Laurent203b1a12014-04-01 10:34:16 -0700672}
673
Eric Laurent6a94d692014-05-20 11:18:06 -0700674status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle)
Eric Laurent203b1a12014-04-01 10:34:16 -0700675{
Eric Laurent6a94d692014-05-20 11:18:06 -0700676 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700677 if(!modifyAudioRoutingAllowed()) {
678 return PERMISSION_DENIED;
679 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700680 if (mAudioPolicyManager == NULL) {
681 return NO_INIT;
682 }
683
684 return mAudioPolicyManager->releaseAudioPatch(handle,
685 IPCThreadState::self()->getCallingUid());
Eric Laurent203b1a12014-04-01 10:34:16 -0700686}
687
688status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches,
Eric Laurent6a94d692014-05-20 11:18:06 -0700689 struct audio_patch *patches,
690 unsigned int *generation)
Eric Laurent203b1a12014-04-01 10:34:16 -0700691{
Eric Laurent6a94d692014-05-20 11:18:06 -0700692 Mutex::Autolock _l(mLock);
693 if (mAudioPolicyManager == NULL) {
694 return NO_INIT;
695 }
696
697 return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation);
Eric Laurent203b1a12014-04-01 10:34:16 -0700698}
699
Eric Laurent6a94d692014-05-20 11:18:06 -0700700status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config)
Eric Laurent203b1a12014-04-01 10:34:16 -0700701{
Eric Laurent6a94d692014-05-20 11:18:06 -0700702 Mutex::Autolock _l(mLock);
Eric Laurent5284ed52014-05-29 14:37:38 -0700703 if(!modifyAudioRoutingAllowed()) {
704 return PERMISSION_DENIED;
705 }
Eric Laurent6a94d692014-05-20 11:18:06 -0700706 if (mAudioPolicyManager == NULL) {
707 return NO_INIT;
708 }
709
710 return mAudioPolicyManager->setAudioPortConfig(config);
Eric Laurent203b1a12014-04-01 10:34:16 -0700711}
Eric Laurent2d388ec2014-03-07 13:25:54 -0800712
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700713status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session,
714 audio_io_handle_t *ioHandle,
715 audio_devices_t *device)
716{
Andy Hungf759b8c2017-08-15 12:48:54 -0700717 Mutex::Autolock _l(mLock);
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700718 if (mAudioPolicyManager == NULL) {
719 return NO_INIT;
720 }
721
722 return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device);
723}
724
725status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session)
726{
Andy Hungf759b8c2017-08-15 12:48:54 -0700727 Mutex::Autolock _l(mLock);
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700728 if (mAudioPolicyManager == NULL) {
729 return NO_INIT;
730 }
731
732 return mAudioPolicyManager->releaseSoundTriggerSession(session);
733}
734
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700735status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration)
Eric Laurentbaac1832014-12-01 17:52:59 -0800736{
737 Mutex::Autolock _l(mLock);
738 if(!modifyAudioRoutingAllowed()) {
739 return PERMISSION_DENIED;
740 }
741 if (mAudioPolicyManager == NULL) {
742 return NO_INIT;
743 }
744 if (registration) {
745 return mAudioPolicyManager->registerPolicyMixes(mixes);
746 } else {
747 return mAudioPolicyManager->unregisterPolicyMixes(mixes);
748 }
749}
750
Eric Laurent554a2772015-04-10 11:29:24 -0700751status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source,
752 const audio_attributes_t *attributes,
Glenn Kasten559d4392016-03-29 13:42:57 -0700753 audio_patch_handle_t *handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700754{
755 Mutex::Autolock _l(mLock);
756 if (mAudioPolicyManager == NULL) {
757 return NO_INIT;
758 }
759
Eric Laurentd60560a2015-04-10 11:31:20 -0700760 return mAudioPolicyManager->startAudioSource(source, attributes, handle,
761 IPCThreadState::self()->getCallingUid());
Eric Laurent554a2772015-04-10 11:29:24 -0700762}
763
Glenn Kasten559d4392016-03-29 13:42:57 -0700764status_t AudioPolicyService::stopAudioSource(audio_patch_handle_t handle)
Eric Laurent554a2772015-04-10 11:29:24 -0700765{
766 Mutex::Autolock _l(mLock);
767 if (mAudioPolicyManager == NULL) {
768 return NO_INIT;
769 }
770
771 return mAudioPolicyManager->stopAudioSource(handle);
772}
773
Andy Hung2ddee192015-12-18 17:34:44 -0800774status_t AudioPolicyService::setMasterMono(bool mono)
775{
776 if (mAudioPolicyManager == NULL) {
777 return NO_INIT;
778 }
779 if (!settingsAllowed()) {
780 return PERMISSION_DENIED;
781 }
782 Mutex::Autolock _l(mLock);
783 return mAudioPolicyManager->setMasterMono(mono);
784}
785
786status_t AudioPolicyService::getMasterMono(bool *mono)
787{
788 if (mAudioPolicyManager == NULL) {
789 return NO_INIT;
790 }
791 Mutex::Autolock _l(mLock);
792 return mAudioPolicyManager->getMasterMono(mono);
793}
794
Eric Laurentac9cef52017-06-09 15:46:26 -0700795
796float AudioPolicyService::getStreamVolumeDB(
797 audio_stream_type_t stream, int index, audio_devices_t device)
798{
799 if (mAudioPolicyManager == NULL) {
800 return NAN;
801 }
802 Mutex::Autolock _l(mLock);
803 return mAudioPolicyManager->getStreamVolumeDB(stream, index, device);
804}
805
806
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800807} // namespace android