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