Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 17 | #define LOG_TAG "AudioPolicyIntefaceImpl" |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <utils/Log.h> |
| 21 | #include "AudioPolicyService.h" |
| 22 | #include "ServiceUtilities.h" |
| 23 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 24 | namespace android { |
| 25 | |
| 26 | |
| 27 | // ---------------------------------------------------------------------------- |
| 28 | |
| 29 | status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, |
| 30 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 31 | const char *device_address, |
| 32 | const char *device_name) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 33 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 34 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 35 | return NO_INIT; |
| 36 | } |
| 37 | if (!settingsAllowed()) { |
| 38 | return PERMISSION_DENIED; |
| 39 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 40 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && |
| 41 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
| 42 | return BAD_VALUE; |
| 43 | } |
| 44 | |
| 45 | ALOGV("setDeviceConnectionState()"); |
| 46 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 47 | AutoCallerClear acc; |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 48 | return mAudioPolicyManager->setDeviceConnectionState(device, state, |
| 49 | device_address, device_name); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( |
| 53 | audio_devices_t device, |
| 54 | const char *device_address) |
| 55 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 56 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 57 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; |
| 58 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 59 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 60 | return mAudioPolicyManager->getDeviceConnectionState(device, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 61 | device_address); |
| 62 | } |
| 63 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 64 | status_t AudioPolicyService::handleDeviceConfigChange(audio_devices_t device, |
| 65 | const char *device_address, |
| 66 | const char *device_name) |
| 67 | { |
| 68 | if (mAudioPolicyManager == NULL) { |
| 69 | return NO_INIT; |
| 70 | } |
| 71 | if (!settingsAllowed()) { |
| 72 | return PERMISSION_DENIED; |
| 73 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 74 | |
| 75 | ALOGV("handleDeviceConfigChange()"); |
| 76 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 77 | AutoCallerClear acc; |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 78 | return mAudioPolicyManager->handleDeviceConfigChange(device, device_address, |
| 79 | device_name); |
| 80 | } |
| 81 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 82 | status_t AudioPolicyService::setPhoneState(audio_mode_t state) |
| 83 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 84 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 85 | return NO_INIT; |
| 86 | } |
| 87 | if (!settingsAllowed()) { |
| 88 | return PERMISSION_DENIED; |
| 89 | } |
| 90 | if (uint32_t(state) >= AUDIO_MODE_CNT) { |
| 91 | return BAD_VALUE; |
| 92 | } |
| 93 | |
| 94 | ALOGV("setPhoneState()"); |
| 95 | |
Eric Laurent | beb07fe | 2015-09-16 15:49:30 -0700 | [diff] [blame] | 96 | // acquire lock before calling setMode() so that setMode() + setPhoneState() are an atomic |
| 97 | // operation from policy manager standpoint (no other operation (e.g track start or stop) |
| 98 | // can be interleaved). |
| 99 | Mutex::Autolock _l(mLock); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 100 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 101 | AudioSystem::setMode(state); |
| 102 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 103 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 104 | mAudioPolicyManager->setPhoneState(state); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 105 | mPhoneState = state; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 106 | return NO_ERROR; |
| 107 | } |
| 108 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 109 | audio_mode_t AudioPolicyService::getPhoneState() |
| 110 | { |
| 111 | Mutex::Autolock _l(mLock); |
| 112 | return mPhoneState; |
| 113 | } |
| 114 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 115 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, |
| 116 | audio_policy_forced_cfg_t config) |
| 117 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 118 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 119 | return NO_INIT; |
| 120 | } |
| 121 | if (!settingsAllowed()) { |
| 122 | return PERMISSION_DENIED; |
| 123 | } |
| 124 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 125 | return BAD_VALUE; |
| 126 | } |
| 127 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
| 128 | return BAD_VALUE; |
| 129 | } |
| 130 | ALOGV("setForceUse()"); |
| 131 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 132 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 133 | mAudioPolicyManager->setForceUse(usage, config); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 134 | return NO_ERROR; |
| 135 | } |
| 136 | |
| 137 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) |
| 138 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 139 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 140 | return AUDIO_POLICY_FORCE_NONE; |
| 141 | } |
| 142 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
| 143 | return AUDIO_POLICY_FORCE_NONE; |
| 144 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 145 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 146 | return mAudioPolicyManager->getForceUse(usage); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 147 | } |
| 148 | |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 149 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 150 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 151 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 152 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 153 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 154 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 155 | return AUDIO_IO_HANDLE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 156 | } |
| 157 | ALOGV("getOutput()"); |
| 158 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 159 | AutoCallerClear acc; |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 160 | return mAudioPolicyManager->getOutput(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 161 | } |
| 162 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 163 | status_t AudioPolicyService::getOutputForAttr(const audio_attributes_t *attr, |
| 164 | audio_io_handle_t *output, |
| 165 | audio_session_t session, |
| 166 | audio_stream_type_t *stream, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 167 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 168 | uid_t uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 169 | const audio_config_t *config, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 170 | audio_output_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 171 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 172 | audio_port_handle_t *portId) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 173 | { |
| 174 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 175 | return NO_INIT; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 176 | } |
Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 177 | ALOGV("getOutputForAttr()"); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 178 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 179 | |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 180 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
| 181 | if (!isTrustedCallingUid(callingUid) || uid == (uid_t)-1) { |
| 182 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
| 183 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 184 | uid = callingUid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 185 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 186 | audio_output_flags_t originalFlags = flags; |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 187 | AutoCallerClear acc; |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 188 | status_t result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 189 | config, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 190 | &flags, selectedDeviceId, portId); |
| 191 | |
| 192 | // FIXME: Introduce a way to check for the the telephony device before opening the output |
| 193 | if ((result == NO_ERROR) && |
| 194 | (flags & AUDIO_OUTPUT_FLAG_INCALL_MUSIC) && |
| 195 | !modifyPhoneStateAllowed(pid, uid)) { |
| 196 | // If the app tries to play music through the telephony device and doesn't have permission |
| 197 | // the fallback to the default output device. |
| 198 | mAudioPolicyManager->releaseOutput(*output, *stream, session); |
| 199 | flags = originalFlags; |
| 200 | *selectedDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 201 | *portId = AUDIO_PORT_HANDLE_NONE; |
| 202 | result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, |
| 203 | config, |
| 204 | &flags, selectedDeviceId, portId); |
| 205 | } |
| 206 | return result; |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 209 | status_t AudioPolicyService::startOutput(audio_io_handle_t output, |
| 210 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 211 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 212 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 213 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 214 | return BAD_VALUE; |
| 215 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 216 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 217 | return NO_INIT; |
| 218 | } |
| 219 | ALOGV("startOutput()"); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 220 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 221 | { |
| 222 | Mutex::Autolock _l(mLock); |
| 223 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 224 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 225 | if (audioPolicyEffects != 0) { |
| 226 | // create audio processors according to stream |
| 227 | status_t status = audioPolicyEffects->addOutputSessionEffects(output, stream, session); |
| 228 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 229 | ALOGW("Failed to add effects on session %d", session); |
| 230 | } |
| 231 | } |
| 232 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 233 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 234 | return mAudioPolicyManager->startOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | status_t AudioPolicyService::stopOutput(audio_io_handle_t output, |
| 238 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 239 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 240 | { |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 241 | if (uint32_t(stream) >= AUDIO_STREAM_CNT) { |
| 242 | return BAD_VALUE; |
| 243 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 244 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 245 | return NO_INIT; |
| 246 | } |
| 247 | ALOGV("stopOutput()"); |
| 248 | mOutputCommandThread->stopOutputCommand(output, stream, session); |
| 249 | return NO_ERROR; |
| 250 | } |
| 251 | |
| 252 | status_t AudioPolicyService::doStopOutput(audio_io_handle_t output, |
| 253 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 254 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 255 | { |
| 256 | ALOGV("doStopOutput from tid %d", gettid()); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 257 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 258 | { |
| 259 | Mutex::Autolock _l(mLock); |
| 260 | audioPolicyEffects = mAudioPolicyEffects; |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 261 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 262 | if (audioPolicyEffects != 0) { |
| 263 | // release audio processors from the stream |
| 264 | status_t status = audioPolicyEffects->releaseOutputSessionEffects(output, stream, session); |
| 265 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
| 266 | ALOGW("Failed to release effects on session %d", session); |
| 267 | } |
| 268 | } |
| 269 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 270 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 271 | return mAudioPolicyManager->stopOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 272 | } |
| 273 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 274 | void AudioPolicyService::releaseOutput(audio_io_handle_t output, |
| 275 | audio_stream_type_t stream, |
| 276 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 277 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 278 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 279 | return; |
| 280 | } |
| 281 | ALOGV("releaseOutput()"); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 282 | mOutputCommandThread->releaseOutputCommand(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 283 | } |
| 284 | |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 285 | void AudioPolicyService::doReleaseOutput(audio_io_handle_t output, |
| 286 | audio_stream_type_t stream, |
| 287 | audio_session_t session) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 288 | { |
| 289 | ALOGV("doReleaseOutput from tid %d", gettid()); |
| 290 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 291 | // called from internal thread: no need to clear caller identity |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 292 | mAudioPolicyManager->releaseOutput(output, stream, session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 293 | } |
| 294 | |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 295 | status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr, |
| 296 | audio_io_handle_t *input, |
| 297 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 298 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 299 | uid_t uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 300 | const String16& opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 301 | const audio_config_base_t *config, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 302 | audio_input_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 303 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 304 | audio_port_handle_t *portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 305 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 306 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 307 | return NO_INIT; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 308 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 309 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 310 | // already checked by client, but double-check in case the client wrapper is bypassed |
Eric Laurent | fe23112 | 2017-11-17 17:48:06 -0800 | [diff] [blame] | 311 | if (attr->source < AUDIO_SOURCE_DEFAULT && attr->source >= AUDIO_SOURCE_CNT && |
| 312 | attr->source != AUDIO_SOURCE_HOTWORD && attr->source != AUDIO_SOURCE_FM_TUNER) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 313 | return BAD_VALUE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 316 | bool updatePid = (pid == -1); |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 317 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 318 | if (!isTrustedCallingUid(callingUid)) { |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 319 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 320 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 321 | uid = callingUid; |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 322 | updatePid = true; |
| 323 | } |
| 324 | |
| 325 | if (updatePid) { |
| 326 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 327 | ALOGW_IF(pid != (pid_t)-1 && pid != callingPid, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 328 | "%s uid %d pid %d tried to pass itself off as pid %d", |
| 329 | __func__, callingUid, callingPid, pid); |
| 330 | pid = callingPid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 333 | // check calling permissions |
| 334 | if (!recordingAllowed(opPackageName, pid, uid)) { |
| 335 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 336 | __func__, uid, pid); |
| 337 | return PERMISSION_DENIED; |
| 338 | } |
| 339 | |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 340 | if ((attr->source == AUDIO_SOURCE_HOTWORD) && !captureHotwordAllowed(pid, uid)) { |
| 341 | return BAD_VALUE; |
| 342 | } |
| 343 | |
| 344 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 345 | { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 346 | status_t status; |
| 347 | AudioPolicyInterface::input_type_t inputType; |
| 348 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 349 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 350 | { |
| 351 | AutoCallerClear acc; |
| 352 | // the audio_in_acoustics_t parameter is ignored by get_input() |
| 353 | status = mAudioPolicyManager->getInputForAttr(attr, input, session, uid, |
| 354 | config, |
| 355 | flags, selectedDeviceId, |
| 356 | &inputType, portId); |
| 357 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 358 | audioPolicyEffects = mAudioPolicyEffects; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 359 | |
| 360 | if (status == NO_ERROR) { |
| 361 | // enforce permission (if any) required for each type of input |
| 362 | switch (inputType) { |
| 363 | case AudioPolicyInterface::API_INPUT_LEGACY: |
| 364 | break; |
Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 365 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: |
| 366 | // FIXME: use the same permission as for remote submix for now. |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 367 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 368 | if (!captureAudioOutputAllowed(pid, uid)) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 369 | ALOGE("getInputForAttr() permission denied: capture not allowed"); |
| 370 | status = PERMISSION_DENIED; |
| 371 | } |
| 372 | break; |
| 373 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: |
| 374 | if (!modifyAudioRoutingAllowed()) { |
| 375 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); |
| 376 | status = PERMISSION_DENIED; |
| 377 | } |
| 378 | break; |
| 379 | case AudioPolicyInterface::API_INPUT_INVALID: |
| 380 | default: |
| 381 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", |
| 382 | (int)inputType); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | if (status != NO_ERROR) { |
| 387 | if (status == PERMISSION_DENIED) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 388 | AutoCallerClear acc; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 389 | mAudioPolicyManager->releaseInput(*input, session); |
| 390 | } |
| 391 | return status; |
| 392 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 393 | |
| 394 | sp<AudioRecordClient> client = |
| 395 | new AudioRecordClient(*attr, *input, uid, pid, opPackageName, session); |
| 396 | client->active = false; |
| 397 | client->isConcurrent = false; |
| 398 | client->isVirtualDevice = false; //TODO : update from APM->getInputForAttr() |
| 399 | mAudioRecordClients.add(*portId, client); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 400 | } |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 401 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 402 | if (audioPolicyEffects != 0) { |
| 403 | // create audio pre processors according to input source |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 404 | status_t status = audioPolicyEffects->addInputEffects(*input, attr->source, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 405 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 406 | ALOGW("Failed to add effects on input %d", *input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 407 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 408 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 409 | return NO_ERROR; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 410 | } |
| 411 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 412 | status_t AudioPolicyService::startInput(audio_port_handle_t portId, bool *silenced) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 413 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 414 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 415 | return NO_INIT; |
| 416 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 417 | sp<AudioRecordClient> client; |
| 418 | { |
| 419 | Mutex::Autolock _l(mLock); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 420 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 421 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 422 | if (index < 0) { |
| 423 | return INVALID_OPERATION; |
| 424 | } |
| 425 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 426 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 427 | |
| 428 | // check calling permissions |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 429 | if (!startRecording(client->opPackageName, client->pid, client->uid)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 430 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 431 | __func__, client->uid, client->pid); |
| 432 | return PERMISSION_DENIED; |
| 433 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 434 | |
| 435 | // If UID inactive it records silence until becoming active |
| 436 | *silenced = !mUidPolicy->isUidActive(client->uid) && !client->isVirtualDevice; |
| 437 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 438 | Mutex::Autolock _l(mLock); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 439 | AudioPolicyInterface::concurrency_type__mask_t concurrency = |
| 440 | AudioPolicyInterface::API_INPUT_CONCURRENCY_NONE; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 441 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 442 | status_t status; |
| 443 | { |
| 444 | AutoCallerClear acc; |
| 445 | status = mAudioPolicyManager->startInput( |
| 446 | client->input, client->session, *silenced, &concurrency); |
| 447 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 448 | |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 449 | if (status == NO_ERROR) { |
Eric Laurent | 4342335 | 2016-02-05 11:57:57 -0800 | [diff] [blame] | 450 | LOG_ALWAYS_FATAL_IF(concurrency & ~AudioPolicyInterface::API_INPUT_CONCURRENCY_ALL, |
| 451 | "startInput(): invalid concurrency type %d", (int)concurrency); |
| 452 | |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 453 | // enforce permission (if any) required for each type of concurrency |
Eric Laurent | 4342335 | 2016-02-05 11:57:57 -0800 | [diff] [blame] | 454 | if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CALL) { |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 455 | //TODO: check incall capture permission |
Eric Laurent | 4342335 | 2016-02-05 11:57:57 -0800 | [diff] [blame] | 456 | } |
| 457 | if (concurrency & AudioPolicyInterface::API_INPUT_CONCURRENCY_CAPTURE) { |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 458 | //TODO: check concurrent capture permission |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 459 | } |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 460 | } else { |
| 461 | finishRecording(client->opPackageName, client->uid); |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 467 | status_t AudioPolicyService::stopInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 468 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 469 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 470 | return NO_INIT; |
| 471 | } |
| 472 | Mutex::Autolock _l(mLock); |
| 473 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 474 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 475 | if (index < 0) { |
| 476 | return INVALID_OPERATION; |
| 477 | } |
| 478 | sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index); |
| 479 | |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 480 | // finish the recording app op |
| 481 | finishRecording(client->opPackageName, client->uid); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 482 | AutoCallerClear acc; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 483 | return mAudioPolicyManager->stopInput(client->input, client->session); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 486 | void AudioPolicyService::releaseInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 487 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 488 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 489 | return; |
| 490 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 491 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 492 | sp<AudioRecordClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 493 | { |
| 494 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 495 | audioPolicyEffects = mAudioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 496 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 497 | if (index < 0) { |
| 498 | return; |
| 499 | } |
| 500 | client = mAudioRecordClients.valueAt(index); |
| 501 | mAudioRecordClients.removeItem(portId); |
| 502 | } |
| 503 | if (client == 0) { |
| 504 | return; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 505 | } |
| 506 | if (audioPolicyEffects != 0) { |
| 507 | // release audio processors from the input |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 508 | status_t status = audioPolicyEffects->releaseInputEffects(client->input, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 509 | if(status != NO_ERROR) { |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 510 | ALOGW("Failed to release effects on input %d", client->input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 511 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 512 | } |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 513 | { |
| 514 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 515 | AutoCallerClear acc; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 516 | mAudioPolicyManager->releaseInput(client->input, client->session); |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 517 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 521 | int indexMin, |
| 522 | int indexMax) |
| 523 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 524 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 525 | return NO_INIT; |
| 526 | } |
| 527 | if (!settingsAllowed()) { |
| 528 | return PERMISSION_DENIED; |
| 529 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 530 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 531 | return BAD_VALUE; |
| 532 | } |
| 533 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 534 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 535 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 536 | return NO_ERROR; |
| 537 | } |
| 538 | |
| 539 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 540 | int index, |
| 541 | audio_devices_t device) |
| 542 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 543 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 544 | return NO_INIT; |
| 545 | } |
| 546 | if (!settingsAllowed()) { |
| 547 | return PERMISSION_DENIED; |
| 548 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 549 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 550 | return BAD_VALUE; |
| 551 | } |
| 552 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 553 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 554 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 555 | index, |
| 556 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 560 | int *index, |
| 561 | audio_devices_t device) |
| 562 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 563 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 564 | return NO_INIT; |
| 565 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 566 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 567 | return BAD_VALUE; |
| 568 | } |
| 569 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 570 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 571 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 572 | index, |
| 573 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 577 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 578 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 579 | return 0; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 580 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 581 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 582 | return 0; |
| 583 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 584 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 585 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | //audio policy: use audio_device_t appropriately |
| 589 | |
| 590 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 591 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 592 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 593 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 594 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 595 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 596 | return AUDIO_DEVICE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 597 | } |
Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 598 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 599 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 600 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 604 | { |
| 605 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 606 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 607 | return 0; |
| 608 | } |
| 609 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 610 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 611 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 615 | audio_io_handle_t io, |
| 616 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 617 | audio_session_t session, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 618 | int id) |
| 619 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 620 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 621 | return NO_INIT; |
| 622 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 623 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 624 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 625 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | status_t AudioPolicyService::unregisterEffect(int id) |
| 629 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 630 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 631 | return NO_INIT; |
| 632 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 633 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 634 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 635 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 639 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 640 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 641 | return NO_INIT; |
| 642 | } |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 643 | Mutex::Autolock _l(mEffectsLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 644 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 645 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 649 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 650 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 651 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 652 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 653 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 654 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 655 | } |
| 656 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 657 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 658 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 662 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 663 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 664 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 665 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 666 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 667 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 668 | } |
| 669 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 670 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 671 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 675 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 676 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 677 | return false; |
| 678 | } |
| 679 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 680 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 681 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 682 | } |
| 683 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 684 | status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 685 | effect_descriptor_t *descriptors, |
| 686 | uint32_t *count) |
| 687 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 688 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 689 | *count = 0; |
| 690 | return NO_INIT; |
| 691 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 692 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 693 | { |
| 694 | Mutex::Autolock _l(mLock); |
| 695 | audioPolicyEffects = mAudioPolicyEffects; |
| 696 | } |
| 697 | if (audioPolicyEffects == 0) { |
| 698 | *count = 0; |
| 699 | return NO_INIT; |
| 700 | } |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 701 | return audioPolicyEffects->queryDefaultInputEffects( |
| 702 | (audio_session_t)audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) |
| 706 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 707 | if (mAudioPolicyManager == NULL) { |
| 708 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 709 | return false; |
| 710 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 711 | Mutex::Autolock _l(mLock); |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 712 | Mutex::Autolock _le(mEffectsLock); // isOffloadSupported queries for |
| 713 | // non-offloadable effects |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 714 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 715 | return mAudioPolicyManager->isOffloadSupported(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 716 | } |
| 717 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 718 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 719 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 720 | unsigned int *num_ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 721 | struct audio_port *ports, |
| 722 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 723 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 724 | Mutex::Autolock _l(mLock); |
| 725 | if (mAudioPolicyManager == NULL) { |
| 726 | return NO_INIT; |
| 727 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 728 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 729 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 732 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 733 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 734 | Mutex::Autolock _l(mLock); |
| 735 | if (mAudioPolicyManager == NULL) { |
| 736 | return NO_INIT; |
| 737 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 738 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 739 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 742 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 743 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 744 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 745 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 746 | if(!modifyAudioRoutingAllowed()) { |
| 747 | return PERMISSION_DENIED; |
| 748 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 749 | if (mAudioPolicyManager == NULL) { |
| 750 | return NO_INIT; |
| 751 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 752 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 753 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 754 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 757 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 758 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 759 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 760 | if(!modifyAudioRoutingAllowed()) { |
| 761 | return PERMISSION_DENIED; |
| 762 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 763 | if (mAudioPolicyManager == NULL) { |
| 764 | return NO_INIT; |
| 765 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 766 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 767 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 768 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 772 | struct audio_patch *patches, |
| 773 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 774 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 775 | Mutex::Autolock _l(mLock); |
| 776 | if (mAudioPolicyManager == NULL) { |
| 777 | return NO_INIT; |
| 778 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 779 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 780 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 781 | } |
| 782 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 783 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 784 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 785 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 786 | if(!modifyAudioRoutingAllowed()) { |
| 787 | return PERMISSION_DENIED; |
| 788 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 789 | if (mAudioPolicyManager == NULL) { |
| 790 | return NO_INIT; |
| 791 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 792 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 793 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 794 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 795 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 796 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 797 | audio_io_handle_t *ioHandle, |
| 798 | audio_devices_t *device) |
| 799 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 800 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 801 | if (mAudioPolicyManager == NULL) { |
| 802 | return NO_INIT; |
| 803 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 804 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 805 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); |
| 806 | } |
| 807 | |
| 808 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 809 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 810 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 811 | if (mAudioPolicyManager == NULL) { |
| 812 | return NO_INIT; |
| 813 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 814 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 815 | return mAudioPolicyManager->releaseSoundTriggerSession(session); |
| 816 | } |
| 817 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 818 | status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 819 | { |
| 820 | Mutex::Autolock _l(mLock); |
| 821 | if(!modifyAudioRoutingAllowed()) { |
| 822 | return PERMISSION_DENIED; |
| 823 | } |
| 824 | if (mAudioPolicyManager == NULL) { |
| 825 | return NO_INIT; |
| 826 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 827 | AutoCallerClear acc; |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 828 | if (registration) { |
| 829 | return mAudioPolicyManager->registerPolicyMixes(mixes); |
| 830 | } else { |
| 831 | return mAudioPolicyManager->unregisterPolicyMixes(mixes); |
| 832 | } |
| 833 | } |
| 834 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 835 | status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source, |
| 836 | const audio_attributes_t *attributes, |
Glenn Kasten | 559d439 | 2016-03-29 13:42:57 -0700 | [diff] [blame] | 837 | audio_patch_handle_t *handle) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 838 | { |
| 839 | Mutex::Autolock _l(mLock); |
| 840 | if (mAudioPolicyManager == NULL) { |
| 841 | return NO_INIT; |
| 842 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 843 | AutoCallerClear acc; |
Eric Laurent | d60560a | 2015-04-10 11:31:20 -0700 | [diff] [blame] | 844 | return mAudioPolicyManager->startAudioSource(source, attributes, handle, |
| 845 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Glenn Kasten | 559d439 | 2016-03-29 13:42:57 -0700 | [diff] [blame] | 848 | status_t AudioPolicyService::stopAudioSource(audio_patch_handle_t handle) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 849 | { |
| 850 | Mutex::Autolock _l(mLock); |
| 851 | if (mAudioPolicyManager == NULL) { |
| 852 | return NO_INIT; |
| 853 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 854 | AutoCallerClear acc; |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 855 | return mAudioPolicyManager->stopAudioSource(handle); |
| 856 | } |
| 857 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 858 | status_t AudioPolicyService::setMasterMono(bool mono) |
| 859 | { |
| 860 | if (mAudioPolicyManager == NULL) { |
| 861 | return NO_INIT; |
| 862 | } |
| 863 | if (!settingsAllowed()) { |
| 864 | return PERMISSION_DENIED; |
| 865 | } |
| 866 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 867 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 868 | return mAudioPolicyManager->setMasterMono(mono); |
| 869 | } |
| 870 | |
| 871 | status_t AudioPolicyService::getMasterMono(bool *mono) |
| 872 | { |
| 873 | if (mAudioPolicyManager == NULL) { |
| 874 | return NO_INIT; |
| 875 | } |
| 876 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 877 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 878 | return mAudioPolicyManager->getMasterMono(mono); |
| 879 | } |
| 880 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 881 | |
| 882 | float AudioPolicyService::getStreamVolumeDB( |
| 883 | audio_stream_type_t stream, int index, audio_devices_t device) |
| 884 | { |
| 885 | if (mAudioPolicyManager == NULL) { |
| 886 | return NAN; |
| 887 | } |
| 888 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame^] | 889 | AutoCallerClear acc; |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 890 | return mAudioPolicyManager->getStreamVolumeDB(stream, index, device); |
| 891 | } |
| 892 | |
| 893 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 894 | } // namespace android |