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