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