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