| 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 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 20 | #include "AudioPolicyService.h" | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 21 | #include "TypeConverter.h" | 
| Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 22 | #include <media/MediaMetricsItem.h> | 
| Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 23 | #include <media/AudioPolicy.h> | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 24 | #include <utils/Log.h> | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 25 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 26 | namespace android { | 
|  | 27 |  | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 28 | const std::vector<audio_usage_t>& SYSTEM_USAGES = { | 
|  | 29 | AUDIO_USAGE_CALL_ASSISTANT, | 
|  | 30 | AUDIO_USAGE_EMERGENCY, | 
|  | 31 | AUDIO_USAGE_SAFETY, | 
|  | 32 | AUDIO_USAGE_VEHICLE_STATUS, | 
|  | 33 | AUDIO_USAGE_ANNOUNCEMENT | 
|  | 34 | }; | 
|  | 35 |  | 
|  | 36 | bool isSystemUsage(audio_usage_t usage) { | 
|  | 37 | return std::find(std::begin(SYSTEM_USAGES), std::end(SYSTEM_USAGES), usage) | 
|  | 38 | != std::end(SYSTEM_USAGES); | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | bool AudioPolicyService::isSupportedSystemUsage(audio_usage_t usage) { | 
|  | 42 | return std::find(std::begin(mSupportedSystemUsages), std::end(mSupportedSystemUsages), usage) | 
|  | 43 | != std::end(mSupportedSystemUsages); | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | status_t AudioPolicyService::validateUsage(audio_usage_t usage) { | 
|  | 47 | return validateUsage(usage, IPCThreadState::self()->getCallingPid(), | 
|  | 48 | IPCThreadState::self()->getCallingUid()); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | status_t AudioPolicyService::validateUsage(audio_usage_t usage, pid_t pid, uid_t uid) { | 
|  | 52 | if (isSystemUsage(usage)) { | 
|  | 53 | if (isSupportedSystemUsage(usage)) { | 
|  | 54 | if (!modifyAudioRoutingAllowed(pid, uid)) { | 
|  | 55 | ALOGE("permission denied: modify audio routing not allowed for uid %d", uid); | 
|  | 56 | return PERMISSION_DENIED; | 
|  | 57 | } | 
|  | 58 | } else { | 
|  | 59 | return BAD_VALUE; | 
|  | 60 | } | 
|  | 61 | } | 
|  | 62 | return NO_ERROR; | 
|  | 63 | } | 
|  | 64 |  | 
|  | 65 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 66 |  | 
|  | 67 | // ---------------------------------------------------------------------------- | 
|  | 68 |  | 
| Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 69 | void AudioPolicyService::doOnNewAudioModulesAvailable() | 
|  | 70 | { | 
|  | 71 | if (mAudioPolicyManager == NULL) return; | 
|  | 72 | Mutex::Autolock _l(mLock); | 
|  | 73 | AutoCallerClear acc; | 
|  | 74 | mAudioPolicyManager->onNewAudioModulesAvailable(); | 
|  | 75 | } | 
|  | 76 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 77 | status_t AudioPolicyService::setDeviceConnectionState(audio_devices_t device, | 
|  | 78 | audio_policy_dev_state_t state, | 
| Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 79 | const char *device_address, | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 80 | const char *device_name, | 
|  | 81 | audio_format_t encodedFormat) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 82 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 83 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 84 | return NO_INIT; | 
|  | 85 | } | 
|  | 86 | if (!settingsAllowed()) { | 
|  | 87 | return PERMISSION_DENIED; | 
|  | 88 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 89 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && | 
|  | 90 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { | 
|  | 91 | return BAD_VALUE; | 
|  | 92 | } | 
|  | 93 |  | 
|  | 94 | ALOGV("setDeviceConnectionState()"); | 
|  | 95 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 96 | AutoCallerClear acc; | 
| Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 97 | return mAudioPolicyManager->setDeviceConnectionState(device, state, | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 98 | device_address, device_name, encodedFormat); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | audio_policy_dev_state_t AudioPolicyService::getDeviceConnectionState( | 
|  | 102 | audio_devices_t device, | 
|  | 103 | const char *device_address) | 
|  | 104 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 105 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 106 | return AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE; | 
|  | 107 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 108 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 109 | return mAudioPolicyManager->getDeviceConnectionState(device, | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 110 | device_address); | 
|  | 111 | } | 
|  | 112 |  | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 113 | status_t AudioPolicyService::handleDeviceConfigChange(audio_devices_t device, | 
|  | 114 | const char *device_address, | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 115 | const char *device_name, | 
|  | 116 | audio_format_t encodedFormat) | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 117 | { | 
|  | 118 | if (mAudioPolicyManager == NULL) { | 
|  | 119 | return NO_INIT; | 
|  | 120 | } | 
|  | 121 | if (!settingsAllowed()) { | 
|  | 122 | return PERMISSION_DENIED; | 
|  | 123 | } | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 124 |  | 
|  | 125 | ALOGV("handleDeviceConfigChange()"); | 
|  | 126 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 127 | AutoCallerClear acc; | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 128 | return mAudioPolicyManager->handleDeviceConfigChange(device, device_address, | 
| Aniket Kumar Lata | 4e46470 | 2019-01-10 23:38:46 -0800 | [diff] [blame] | 129 | device_name, encodedFormat); | 
| Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 130 | } | 
|  | 131 |  | 
| Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 132 | status_t AudioPolicyService::setPhoneState(audio_mode_t state, uid_t uid) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 133 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 134 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 135 | return NO_INIT; | 
|  | 136 | } | 
|  | 137 | if (!settingsAllowed()) { | 
|  | 138 | return PERMISSION_DENIED; | 
|  | 139 | } | 
|  | 140 | if (uint32_t(state) >= AUDIO_MODE_CNT) { | 
|  | 141 | return BAD_VALUE; | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | ALOGV("setPhoneState()"); | 
|  | 145 |  | 
| Eric Laurent | beb07fe | 2015-09-16 15:49:30 -0700 | [diff] [blame] | 146 | // acquire lock before calling setMode() so that setMode() + setPhoneState() are an atomic | 
|  | 147 | // operation from policy manager standpoint (no other operation (e.g track start or stop) | 
|  | 148 | // can be interleaved). | 
|  | 149 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 150 | // TODO: check if it is more appropriate to do it in platform specific policy manager | 
|  | 151 | AudioSystem::setMode(state); | 
|  | 152 |  | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 153 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 154 | mAudioPolicyManager->setPhoneState(state); | 
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 155 | mPhoneState = state; | 
| Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 156 | mPhoneStateOwnerUid = uid; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 157 | return NO_ERROR; | 
|  | 158 | } | 
|  | 159 |  | 
| Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 160 | audio_mode_t AudioPolicyService::getPhoneState() | 
|  | 161 | { | 
|  | 162 | Mutex::Autolock _l(mLock); | 
|  | 163 | return mPhoneState; | 
|  | 164 | } | 
|  | 165 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 166 | status_t AudioPolicyService::setForceUse(audio_policy_force_use_t usage, | 
|  | 167 | audio_policy_forced_cfg_t config) | 
|  | 168 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 169 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 170 | return NO_INIT; | 
|  | 171 | } | 
| Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 172 |  | 
|  | 173 | if (!modifyAudioRoutingAllowed()) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 174 | return PERMISSION_DENIED; | 
|  | 175 | } | 
| Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 176 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 177 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { | 
|  | 178 | return BAD_VALUE; | 
|  | 179 | } | 
|  | 180 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { | 
|  | 181 | return BAD_VALUE; | 
|  | 182 | } | 
|  | 183 | ALOGV("setForceUse()"); | 
|  | 184 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 185 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 186 | mAudioPolicyManager->setForceUse(usage, config); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 187 | return NO_ERROR; | 
|  | 188 | } | 
|  | 189 |  | 
|  | 190 | audio_policy_forced_cfg_t AudioPolicyService::getForceUse(audio_policy_force_use_t usage) | 
|  | 191 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 192 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 193 | return AUDIO_POLICY_FORCE_NONE; | 
|  | 194 | } | 
|  | 195 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { | 
|  | 196 | return AUDIO_POLICY_FORCE_NONE; | 
|  | 197 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 198 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 199 | return mAudioPolicyManager->getForceUse(usage); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 200 | } | 
|  | 201 |  | 
| Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 202 | audio_io_handle_t AudioPolicyService::getOutput(audio_stream_type_t stream) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 203 | { | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 204 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 205 | return AUDIO_IO_HANDLE_NONE; | 
| Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 206 | } | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 207 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 208 | return AUDIO_IO_HANDLE_NONE; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 209 | } | 
|  | 210 | ALOGV("getOutput()"); | 
|  | 211 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 212 | AutoCallerClear acc; | 
| Eric Laurent | f4e6345 | 2017-11-06 19:31:46 +0000 | [diff] [blame] | 213 | return mAudioPolicyManager->getOutput(stream); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 214 | } | 
|  | 215 |  | 
| Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 216 | status_t AudioPolicyService::getOutputForAttr(audio_attributes_t *attr, | 
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 217 | audio_io_handle_t *output, | 
|  | 218 | audio_session_t session, | 
|  | 219 | audio_stream_type_t *stream, | 
| Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 220 | pid_t pid, | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 221 | uid_t uid, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 222 | const audio_config_t *config, | 
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 223 | audio_output_flags_t flags, | 
| Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 224 | audio_port_handle_t *selectedDeviceId, | 
| Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 225 | audio_port_handle_t *portId, | 
|  | 226 | std::vector<audio_io_handle_t> *secondaryOutputs) | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 227 | { | 
|  | 228 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 229 | return NO_INIT; | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 230 | } | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 231 |  | 
|  | 232 | status_t result = validateUsage(attr->usage, pid, uid); | 
|  | 233 | if (result != NO_ERROR) { | 
|  | 234 | return result; | 
|  | 235 | } | 
|  | 236 |  | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 237 | ALOGV("%s()", __func__); | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 238 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 239 |  | 
| Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 240 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); | 
| Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 241 | if (!isAudioServerOrMediaServerUid(callingUid) || uid == (uid_t)-1) { | 
| Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 242 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 243 | "%s uid %d tried to pass itself off as %d", __func__, callingUid, uid); | 
| Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 244 | uid = callingUid; | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 245 | } | 
| Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 246 | if (!mPackageManager.allowPlaybackCapture(uid)) { | 
| Mikhail Naganov | e3b59ac | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 247 | attr->flags = static_cast<audio_flags_mask_t>(attr->flags | AUDIO_FLAG_NO_MEDIA_PROJECTION); | 
| Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 248 | } | 
| Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 249 | if (((attr->flags & (AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE)) != 0) | 
|  | 250 | && !bypassInterruptionPolicyAllowed(pid, uid)) { | 
| Mikhail Naganov | e3b59ac | 2020-10-01 15:08:13 -0700 | [diff] [blame] | 251 | attr->flags = static_cast<audio_flags_mask_t>( | 
|  | 252 | attr->flags & ~(AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE)); | 
| Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 253 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 254 | AutoCallerClear acc; | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 255 | AudioPolicyInterface::output_type_t outputType; | 
| Hayden Gomes | 3e8bbb9 | 2020-01-10 13:37:05 -0800 | [diff] [blame] | 256 | result = mAudioPolicyManager->getOutputForAttr(attr, output, session, stream, uid, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 257 | config, | 
| Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 258 | &flags, selectedDeviceId, portId, | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 259 | secondaryOutputs, | 
|  | 260 | &outputType); | 
| Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 261 |  | 
|  | 262 | // FIXME: Introduce a way to check for the the telephony device before opening the output | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 263 | if (result == NO_ERROR) { | 
|  | 264 | // enforce permission (if any) required for each type of input | 
|  | 265 | switch (outputType) { | 
|  | 266 | case AudioPolicyInterface::API_OUTPUT_LEGACY: | 
|  | 267 | break; | 
|  | 268 | case AudioPolicyInterface::API_OUTPUT_TELEPHONY_TX: | 
| Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 269 | if (!modifyPhoneStateAllowed(pid, uid)) { | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 270 | ALOGE("%s() permission denied: modify phone state not allowed for uid %d", | 
|  | 271 | __func__, uid); | 
|  | 272 | result = PERMISSION_DENIED; | 
|  | 273 | } | 
|  | 274 | break; | 
|  | 275 | case AudioPolicyInterface::API_OUT_MIX_PLAYBACK: | 
|  | 276 | if (!modifyAudioRoutingAllowed(pid, uid)) { | 
|  | 277 | ALOGE("%s() permission denied: modify audio routing not allowed for uid %d", | 
|  | 278 | __func__, uid); | 
|  | 279 | result = PERMISSION_DENIED; | 
|  | 280 | } | 
|  | 281 | break; | 
|  | 282 | case AudioPolicyInterface::API_OUTPUT_INVALID: | 
|  | 283 | default: | 
|  | 284 | LOG_ALWAYS_FATAL("%s() encountered an invalid output type %d", | 
|  | 285 | __func__, (int)outputType); | 
|  | 286 | } | 
| Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 287 | } | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 288 |  | 
|  | 289 | if (result == NO_ERROR) { | 
|  | 290 | sp <AudioPlaybackClient> client = | 
| Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 291 | new AudioPlaybackClient(*attr, *output, uid, pid, session, *portId, *selectedDeviceId, *stream); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 292 | mAudioPlaybackClients.add(*portId, client); | 
|  | 293 | } | 
| Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 294 | return result; | 
| Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 295 | } | 
|  | 296 |  | 
| Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 297 | void AudioPolicyService::getPlaybackClientAndEffects(audio_port_handle_t portId, | 
|  | 298 | sp<AudioPlaybackClient>& client, | 
|  | 299 | sp<AudioPolicyEffects>& effects, | 
|  | 300 | const char *context) | 
|  | 301 | { | 
|  | 302 | Mutex::Autolock _l(mLock); | 
|  | 303 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); | 
|  | 304 | if (index < 0) { | 
|  | 305 | ALOGE("%s AudioTrack client not found for portId %d", context, portId); | 
|  | 306 | return; | 
|  | 307 | } | 
|  | 308 | client = mAudioPlaybackClients.valueAt(index); | 
|  | 309 | effects = mAudioPolicyEffects; | 
|  | 310 | } | 
|  | 311 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 312 | status_t AudioPolicyService::startOutput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 313 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 314 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 315 | return NO_INIT; | 
|  | 316 | } | 
|  | 317 | ALOGV("startOutput()"); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 318 | sp<AudioPlaybackClient> client; | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 319 | sp<AudioPolicyEffects>audioPolicyEffects; | 
| Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 320 |  | 
|  | 321 | getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__); | 
|  | 322 |  | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 323 | if (audioPolicyEffects != 0) { | 
|  | 324 | // create audio processors according to stream | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 325 | status_t status = audioPolicyEffects->addOutputSessionEffects( | 
|  | 326 | client->io, client->stream, client->session); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 327 | if (status != NO_ERROR && status != ALREADY_EXISTS) { | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 328 | ALOGW("Failed to add effects on session %d", client->session); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 329 | } | 
|  | 330 | } | 
|  | 331 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 332 | AutoCallerClear acc; | 
| Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 333 | status_t status = mAudioPolicyManager->startOutput(portId); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 334 | if (status == NO_ERROR) { | 
|  | 335 | client->active = true; | 
|  | 336 | } | 
|  | 337 | return status; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 338 | } | 
|  | 339 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 340 | status_t AudioPolicyService::stopOutput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 341 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 342 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 343 | return NO_INIT; | 
|  | 344 | } | 
|  | 345 | ALOGV("stopOutput()"); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 346 | mOutputCommandThread->stopOutputCommand(portId); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 347 | return NO_ERROR; | 
|  | 348 | } | 
|  | 349 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 350 | status_t  AudioPolicyService::doStopOutput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 351 | { | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 352 | ALOGV("doStopOutput"); | 
|  | 353 | sp<AudioPlaybackClient> client; | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 354 | sp<AudioPolicyEffects>audioPolicyEffects; | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 355 |  | 
| Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 356 | getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__); | 
|  | 357 |  | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 358 | if (audioPolicyEffects != 0) { | 
|  | 359 | // release audio processors from the stream | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 360 | status_t status = audioPolicyEffects->releaseOutputSessionEffects( | 
|  | 361 | client->io, client->stream, client->session); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 362 | if (status != NO_ERROR && status != ALREADY_EXISTS) { | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 363 | ALOGW("Failed to release effects on session %d", client->session); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 364 | } | 
|  | 365 | } | 
|  | 366 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 367 | AutoCallerClear acc; | 
| Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 368 | status_t status = mAudioPolicyManager->stopOutput(portId); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 369 | if (status == NO_ERROR) { | 
|  | 370 | client->active = false; | 
|  | 371 | } | 
|  | 372 | return status; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 373 | } | 
|  | 374 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 375 | void AudioPolicyService::releaseOutput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 376 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 377 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 378 | return; | 
|  | 379 | } | 
|  | 380 | ALOGV("releaseOutput()"); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 381 | mOutputCommandThread->releaseOutputCommand(portId); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 382 | } | 
|  | 383 |  | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 384 | void AudioPolicyService::doReleaseOutput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 385 | { | 
|  | 386 | ALOGV("doReleaseOutput from tid %d", gettid()); | 
| Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 387 | sp<AudioPlaybackClient> client; | 
|  | 388 | sp<AudioPolicyEffects> audioPolicyEffects; | 
|  | 389 |  | 
|  | 390 | getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__); | 
|  | 391 |  | 
|  | 392 | if (audioPolicyEffects != 0 && client->active) { | 
|  | 393 | // clean up effects if output was not stopped before being released | 
|  | 394 | audioPolicyEffects->releaseOutputSessionEffects( | 
|  | 395 | client->io, client->stream, client->session); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 396 | } | 
| Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 397 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | d400724 | 2019-03-27 12:42:16 -0700 | [diff] [blame] | 398 | mAudioPlaybackClients.removeItem(portId); | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 399 |  | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 400 | // called from internal thread: no need to clear caller identity | 
| Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 401 | mAudioPolicyManager->releaseOutput(portId); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 402 | } | 
|  | 403 |  | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 404 | status_t AudioPolicyService::getInputForAttr(const audio_attributes_t *attr, | 
|  | 405 | audio_io_handle_t *input, | 
| Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 406 | audio_unique_id_t riid, | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 407 | audio_session_t session, | 
| Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 408 | pid_t pid, | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 409 | uid_t uid, | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 410 | const String16& opPackageName, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 411 | const audio_config_base_t *config, | 
| Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 412 | audio_input_flags_t flags, | 
| Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 413 | audio_port_handle_t *selectedDeviceId, | 
| Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 414 | audio_port_handle_t *portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 415 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 416 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 417 | return NO_INIT; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 418 | } | 
| Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 419 |  | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 420 | status_t result = validateUsage(attr->usage, pid, uid); | 
|  | 421 | if (result != NO_ERROR) { | 
|  | 422 | return result; | 
|  | 423 | } | 
|  | 424 |  | 
| Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 425 | audio_source_t inputSource = attr->source; | 
|  | 426 | if (inputSource == AUDIO_SOURCE_DEFAULT) { | 
|  | 427 | inputSource = AUDIO_SOURCE_MIC; | 
|  | 428 | } | 
|  | 429 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 430 | // already checked by client, but double-check in case the client wrapper is bypassed | 
| Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 431 | if ((inputSource < AUDIO_SOURCE_DEFAULT) | 
|  | 432 | || (inputSource >= AUDIO_SOURCE_CNT | 
|  | 433 | && inputSource != AUDIO_SOURCE_HOTWORD | 
|  | 434 | && inputSource != AUDIO_SOURCE_FM_TUNER | 
|  | 435 | && inputSource != AUDIO_SOURCE_ECHO_REFERENCE)) { | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 436 | return BAD_VALUE; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 437 | } | 
|  | 438 |  | 
| Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 439 | bool updatePid = (pid == -1); | 
| Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 440 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); | 
| Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 441 | if (!isAudioServerOrMediaServerUid(callingUid)) { | 
| Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 442 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, | 
| Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 443 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); | 
|  | 444 | uid = callingUid; | 
| Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 445 | updatePid = true; | 
|  | 446 | } | 
|  | 447 |  | 
|  | 448 | if (updatePid) { | 
|  | 449 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); | 
| Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 450 | ALOGW_IF(pid != (pid_t)-1 && pid != callingPid, | 
| Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 451 | "%s uid %d pid %d tried to pass itself off as pid %d", | 
|  | 452 | __func__, callingUid, callingPid, pid); | 
|  | 453 | pid = callingPid; | 
| Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 454 | } | 
|  | 455 |  | 
| Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 456 | // check calling permissions. | 
|  | 457 | // Capturing from FM_TUNER source is controlled by captureAudioOutputAllowed() only as this | 
|  | 458 | // does not affect users privacy as does capturing from an actual microphone. | 
|  | 459 | if (!(recordingAllowed(opPackageName, pid, uid) || attr->source == AUDIO_SOURCE_FM_TUNER)) { | 
| Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 460 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", | 
|  | 461 | __func__, uid, pid); | 
|  | 462 | return PERMISSION_DENIED; | 
|  | 463 | } | 
|  | 464 |  | 
| Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 465 | bool canCaptureOutput = captureAudioOutputAllowed(pid, uid); | 
| Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 466 | if ((inputSource == AUDIO_SOURCE_VOICE_UPLINK || | 
|  | 467 | inputSource == AUDIO_SOURCE_VOICE_DOWNLINK || | 
|  | 468 | inputSource == AUDIO_SOURCE_VOICE_CALL || | 
|  | 469 | inputSource == AUDIO_SOURCE_ECHO_REFERENCE|| | 
|  | 470 | inputSource == AUDIO_SOURCE_FM_TUNER) && | 
| Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 471 | !canCaptureOutput) { | 
| Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 472 | return PERMISSION_DENIED; | 
|  | 473 | } | 
|  | 474 |  | 
| jiabin | 68e0df7 | 2019-03-18 17:55:35 -0700 | [diff] [blame] | 475 | bool canCaptureHotword = captureHotwordAllowed(opPackageName, pid, uid); | 
| Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 476 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !canCaptureHotword) { | 
| Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 477 | return BAD_VALUE; | 
|  | 478 | } | 
|  | 479 |  | 
|  | 480 | sp<AudioPolicyEffects>audioPolicyEffects; | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 481 | { | 
| Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 482 | status_t status; | 
|  | 483 | AudioPolicyInterface::input_type_t inputType; | 
|  | 484 |  | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 485 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 486 | { | 
|  | 487 | AutoCallerClear acc; | 
|  | 488 | // the audio_in_acoustics_t parameter is ignored by get_input() | 
| Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 489 | status = mAudioPolicyManager->getInputForAttr(attr, input, riid, session, uid, | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 490 | config, | 
|  | 491 | flags, selectedDeviceId, | 
|  | 492 | &inputType, portId); | 
|  | 493 | } | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 494 | audioPolicyEffects = mAudioPolicyEffects; | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 495 |  | 
|  | 496 | if (status == NO_ERROR) { | 
|  | 497 | // enforce permission (if any) required for each type of input | 
|  | 498 | switch (inputType) { | 
| Kevin Rocard | 25f9b05 | 2019-02-27 15:08:54 -0800 | [diff] [blame] | 499 | case AudioPolicyInterface::API_INPUT_MIX_PUBLIC_CAPTURE_PLAYBACK: | 
|  | 500 | // this use case has been validated in audio service with a MediaProjection token, | 
|  | 501 | // and doesn't rely on regular permissions | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 502 | case AudioPolicyInterface::API_INPUT_LEGACY: | 
|  | 503 | break; | 
| Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 504 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: | 
|  | 505 | // FIXME: use the same permission as for remote submix for now. | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 506 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: | 
| Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 507 | if (!canCaptureOutput) { | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 508 | ALOGE("getInputForAttr() permission denied: capture not allowed"); | 
|  | 509 | status = PERMISSION_DENIED; | 
|  | 510 | } | 
|  | 511 | break; | 
|  | 512 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: | 
| Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 513 | if (!modifyAudioRoutingAllowed(pid, uid)) { | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 514 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); | 
|  | 515 | status = PERMISSION_DENIED; | 
|  | 516 | } | 
|  | 517 | break; | 
|  | 518 | case AudioPolicyInterface::API_INPUT_INVALID: | 
|  | 519 | default: | 
|  | 520 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", | 
|  | 521 | (int)inputType); | 
|  | 522 | } | 
|  | 523 | } | 
|  | 524 |  | 
|  | 525 | if (status != NO_ERROR) { | 
|  | 526 | if (status == PERMISSION_DENIED) { | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 527 | AutoCallerClear acc; | 
| Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 528 | mAudioPolicyManager->releaseInput(*portId); | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 529 | } | 
|  | 530 | return status; | 
|  | 531 | } | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 532 |  | 
| Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 533 | sp<AudioRecordClient> client = new AudioRecordClient(*attr, *input, uid, pid, session, *portId, | 
| Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 534 | *selectedDeviceId, opPackageName, | 
| Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 535 | canCaptureOutput, canCaptureHotword); | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 536 | mAudioRecordClients.add(*portId, client); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 537 | } | 
| Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 538 |  | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 539 | if (audioPolicyEffects != 0) { | 
|  | 540 | // create audio pre processors according to input source | 
| Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 541 | status_t status = audioPolicyEffects->addInputEffects(*input, inputSource, session); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 542 | if (status != NO_ERROR && status != ALREADY_EXISTS) { | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 543 | ALOGW("Failed to add effects on input %d", *input); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 544 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 545 | } | 
| Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 546 | return NO_ERROR; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 547 | } | 
|  | 548 |  | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 549 | std::string AudioPolicyService::getDeviceTypeStrForPortId(audio_port_handle_t portId) { | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 550 | struct audio_port port = {}; | 
|  | 551 | port.id = portId; | 
|  | 552 | status_t status = mAudioPolicyManager->getAudioPort(&port); | 
|  | 553 | if (status == NO_ERROR && port.type == AUDIO_PORT_TYPE_DEVICE) { | 
| Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 554 | return toString(port.ext.device.type); | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 555 | } | 
| Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 556 | return {}; | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 557 | } | 
|  | 558 |  | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 559 | status_t AudioPolicyService::startInput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 560 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 561 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 562 | return NO_INIT; | 
|  | 563 | } | 
| Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 564 | sp<AudioRecordClient> client; | 
|  | 565 | { | 
|  | 566 | Mutex::Autolock _l(mLock); | 
| Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 567 |  | 
| Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 568 | ssize_t index = mAudioRecordClients.indexOfKey(portId); | 
|  | 569 | if (index < 0) { | 
|  | 570 | return INVALID_OPERATION; | 
|  | 571 | } | 
|  | 572 | client = mAudioRecordClients.valueAt(index); | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 573 | } | 
| Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 574 |  | 
|  | 575 | // check calling permissions | 
| Narayan Kamath | d127644 | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 576 | if (!(startRecording(client->opPackageName, client->pid, client->uid, | 
|  | 577 | client->attributes.source == AUDIO_SOURCE_HOTWORD) | 
| Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 578 | || client->attributes.source == AUDIO_SOURCE_FM_TUNER)) { | 
| Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 579 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", | 
|  | 580 | __func__, client->uid, client->pid); | 
|  | 581 | return PERMISSION_DENIED; | 
|  | 582 | } | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 583 |  | 
| Eric Laurent | df62892 | 2018-12-06 21:45:51 +0000 | [diff] [blame] | 584 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 585 |  | 
|  | 586 | client->active = true; | 
|  | 587 | client->startTimeNs = systemTime(); | 
|  | 588 | updateUidStates_l(); | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 589 |  | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 590 | status_t status; | 
|  | 591 | { | 
|  | 592 | AutoCallerClear acc; | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 593 | status = mAudioPolicyManager->startInput(portId); | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 594 |  | 
|  | 595 | } | 
|  | 596 |  | 
| Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 597 | // including successes gets very verbose | 
| Muhammad Qureshi | 087b37c | 2020-06-16 16:37:36 -0700 | [diff] [blame] | 598 | // but once we cut over to statsd, log them all. | 
| Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 599 | if (status != NO_ERROR) { | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 600 |  | 
|  | 601 | static constexpr char kAudioPolicy[] = "audiopolicy"; | 
|  | 602 |  | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 603 | static constexpr char kAudioPolicyStatus[] = "android.media.audiopolicy.status"; | 
|  | 604 | static constexpr char kAudioPolicyRqstSrc[] = "android.media.audiopolicy.rqst.src"; | 
|  | 605 | static constexpr char kAudioPolicyRqstPkg[] = "android.media.audiopolicy.rqst.pkg"; | 
|  | 606 | static constexpr char kAudioPolicyRqstSession[] = "android.media.audiopolicy.rqst.session"; | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 607 | static constexpr char kAudioPolicyRqstDevice[] = | 
|  | 608 | "android.media.audiopolicy.rqst.device"; | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 609 | static constexpr char kAudioPolicyActiveSrc[] = "android.media.audiopolicy.active.src"; | 
|  | 610 | static constexpr char kAudioPolicyActivePkg[] = "android.media.audiopolicy.active.pkg"; | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 611 | static constexpr char kAudioPolicyActiveSession[] = | 
|  | 612 | "android.media.audiopolicy.active.session"; | 
|  | 613 | static constexpr char kAudioPolicyActiveDevice[] = | 
|  | 614 | "android.media.audiopolicy.active.device"; | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 615 |  | 
| Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 616 | mediametrics::Item *item = mediametrics::Item::create(kAudioPolicy); | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 617 | if (item != NULL) { | 
|  | 618 |  | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 619 | item->setInt32(kAudioPolicyStatus, status); | 
|  | 620 |  | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 621 | item->setCString(kAudioPolicyRqstSrc, | 
| Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 622 | toString(client->attributes.source).c_str()); | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 623 | item->setInt32(kAudioPolicyRqstSession, client->session); | 
| Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 624 | if (client->opPackageName.size() != 0) { | 
|  | 625 | item->setCString(kAudioPolicyRqstPkg, | 
|  | 626 | std::string(String8(client->opPackageName).string()).c_str()); | 
|  | 627 | } else { | 
| Kevin Rocard | fbdfebe | 2018-06-18 12:30:40 -0700 | [diff] [blame] | 628 | item->setCString(kAudioPolicyRqstPkg, std::to_string(client->uid).c_str()); | 
| Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 629 | } | 
| Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 630 | item->setCString( | 
|  | 631 | kAudioPolicyRqstDevice, getDeviceTypeStrForPortId(client->deviceId).c_str()); | 
|  | 632 |  | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 633 | int count = mAudioRecordClients.size(); | 
|  | 634 | for (int i = 0; i < count ; i++) { | 
|  | 635 | if (portId == mAudioRecordClients.keyAt(i)) { | 
|  | 636 | continue; | 
|  | 637 | } | 
|  | 638 | sp<AudioRecordClient> other = mAudioRecordClients.valueAt(i); | 
|  | 639 | if (other->active) { | 
|  | 640 | // keeps the last of the clients marked active | 
|  | 641 | item->setCString(kAudioPolicyActiveSrc, | 
| Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 642 | toString(other->attributes.source).c_str()); | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 643 | item->setInt32(kAudioPolicyActiveSession, other->session); | 
|  | 644 | if (other->opPackageName.size() != 0) { | 
|  | 645 | item->setCString(kAudioPolicyActivePkg, | 
|  | 646 | std::string(String8(other->opPackageName).string()).c_str()); | 
|  | 647 | } else { | 
|  | 648 | item->setCString(kAudioPolicyRqstPkg, | 
|  | 649 | std::to_string(other->uid).c_str()); | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 650 | } | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 651 | item->setCString(kAudioPolicyActiveDevice, | 
|  | 652 | getDeviceTypeStrForPortId(other->deviceId).c_str()); | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 653 | } | 
|  | 654 | } | 
|  | 655 | item->selfrecord(); | 
|  | 656 | delete item; | 
|  | 657 | item = NULL; | 
|  | 658 | } | 
| Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 659 | } | 
|  | 660 |  | 
|  | 661 | if (status != NO_ERROR) { | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 662 | client->active = false; | 
|  | 663 | client->startTimeNs = 0; | 
|  | 664 | updateUidStates_l(); | 
| Narayan Kamath | d127644 | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 665 | finishRecording(client->opPackageName, client->uid, | 
|  | 666 | client->attributes.source == AUDIO_SOURCE_HOTWORD); | 
| Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 667 | } | 
|  | 668 |  | 
|  | 669 | return status; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 670 | } | 
|  | 671 |  | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 672 | status_t AudioPolicyService::stopInput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 673 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 674 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 675 | return NO_INIT; | 
|  | 676 | } | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 677 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 678 | Mutex::Autolock _l(mLock); | 
|  | 679 |  | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 680 | ssize_t index = mAudioRecordClients.indexOfKey(portId); | 
|  | 681 | if (index < 0) { | 
|  | 682 | return INVALID_OPERATION; | 
|  | 683 | } | 
|  | 684 | sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index); | 
|  | 685 |  | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 686 | client->active = false; | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 687 | client->startTimeNs = 0; | 
|  | 688 |  | 
|  | 689 | updateUidStates_l(); | 
| Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 690 |  | 
| Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 691 | // finish the recording app op | 
| Narayan Kamath | d127644 | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 692 | finishRecording(client->opPackageName, client->uid, | 
|  | 693 | client->attributes.source == AUDIO_SOURCE_HOTWORD); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 694 | AutoCallerClear acc; | 
| Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 695 | return mAudioPolicyManager->stopInput(portId); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 696 | } | 
|  | 697 |  | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 698 | void AudioPolicyService::releaseInput(audio_port_handle_t portId) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 699 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 700 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 701 | return; | 
|  | 702 | } | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 703 | sp<AudioPolicyEffects>audioPolicyEffects; | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 704 | sp<AudioRecordClient> client; | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 705 | { | 
|  | 706 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 707 | audioPolicyEffects = mAudioPolicyEffects; | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 708 | ssize_t index = mAudioRecordClients.indexOfKey(portId); | 
|  | 709 | if (index < 0) { | 
|  | 710 | return; | 
|  | 711 | } | 
|  | 712 | client = mAudioRecordClients.valueAt(index); | 
| Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 713 |  | 
|  | 714 | if (client->active) { | 
|  | 715 | ALOGW("%s releasing active client portId %d", __FUNCTION__, portId); | 
|  | 716 | client->active = false; | 
|  | 717 | client->startTimeNs = 0; | 
|  | 718 | updateUidStates_l(); | 
|  | 719 | } | 
|  | 720 |  | 
| Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 721 | mAudioRecordClients.removeItem(portId); | 
|  | 722 | } | 
|  | 723 | if (client == 0) { | 
|  | 724 | return; | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 725 | } | 
|  | 726 | if (audioPolicyEffects != 0) { | 
|  | 727 | // release audio processors from the input | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 728 | status_t status = audioPolicyEffects->releaseInputEffects(client->io, client->session); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 729 | if(status != NO_ERROR) { | 
| Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 730 | ALOGW("Failed to release effects on input %d", client->io); | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 731 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 732 | } | 
| Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 733 | { | 
|  | 734 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 735 | AutoCallerClear acc; | 
| Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 736 | mAudioPolicyManager->releaseInput(portId); | 
| Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 737 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 738 | } | 
|  | 739 |  | 
|  | 740 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, | 
|  | 741 | int indexMin, | 
|  | 742 | int indexMax) | 
|  | 743 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 744 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 745 | return NO_INIT; | 
|  | 746 | } | 
|  | 747 | if (!settingsAllowed()) { | 
|  | 748 | return PERMISSION_DENIED; | 
|  | 749 | } | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 750 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 751 | return BAD_VALUE; | 
|  | 752 | } | 
|  | 753 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 754 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 755 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 756 | return NO_ERROR; | 
|  | 757 | } | 
|  | 758 |  | 
|  | 759 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, | 
|  | 760 | int index, | 
|  | 761 | audio_devices_t device) | 
|  | 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 NO_INIT; | 
|  | 765 | } | 
|  | 766 | if (!settingsAllowed()) { | 
|  | 767 | return PERMISSION_DENIED; | 
|  | 768 | } | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 769 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 770 | return BAD_VALUE; | 
|  | 771 | } | 
|  | 772 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 773 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 774 | return mAudioPolicyManager->setStreamVolumeIndex(stream, | 
|  | 775 | index, | 
|  | 776 | device); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 777 | } | 
|  | 778 |  | 
|  | 779 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, | 
|  | 780 | int *index, | 
|  | 781 | audio_devices_t device) | 
|  | 782 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 783 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 784 | return NO_INIT; | 
|  | 785 | } | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 786 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 787 | return BAD_VALUE; | 
|  | 788 | } | 
|  | 789 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 790 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 791 | return mAudioPolicyManager->getStreamVolumeIndex(stream, | 
|  | 792 | index, | 
|  | 793 | device); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 794 | } | 
|  | 795 |  | 
| François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 796 | status_t AudioPolicyService::setVolumeIndexForAttributes(const audio_attributes_t &attributes, | 
|  | 797 | int index, audio_devices_t device) | 
|  | 798 | { | 
|  | 799 | if (mAudioPolicyManager == NULL) { | 
|  | 800 | return NO_INIT; | 
|  | 801 | } | 
|  | 802 | if (!settingsAllowed()) { | 
|  | 803 | return PERMISSION_DENIED; | 
|  | 804 | } | 
|  | 805 | Mutex::Autolock _l(mLock); | 
|  | 806 | AutoCallerClear acc; | 
|  | 807 | return mAudioPolicyManager->setVolumeIndexForAttributes(attributes, index, device); | 
|  | 808 | } | 
|  | 809 |  | 
|  | 810 | status_t AudioPolicyService::getVolumeIndexForAttributes(const audio_attributes_t &attributes, | 
|  | 811 | int &index, audio_devices_t device) | 
|  | 812 | { | 
|  | 813 | if (mAudioPolicyManager == NULL) { | 
|  | 814 | return NO_INIT; | 
|  | 815 | } | 
|  | 816 | Mutex::Autolock _l(mLock); | 
|  | 817 | AutoCallerClear acc; | 
|  | 818 | return mAudioPolicyManager->getVolumeIndexForAttributes(attributes, index, device); | 
|  | 819 | } | 
|  | 820 |  | 
|  | 821 | status_t AudioPolicyService::getMinVolumeIndexForAttributes(const audio_attributes_t &attributes, | 
|  | 822 | int &index) | 
|  | 823 | { | 
|  | 824 | if (mAudioPolicyManager == NULL) { | 
|  | 825 | return NO_INIT; | 
|  | 826 | } | 
|  | 827 | Mutex::Autolock _l(mLock); | 
|  | 828 | AutoCallerClear acc; | 
|  | 829 | return mAudioPolicyManager->getMinVolumeIndexForAttributes(attributes, index); | 
|  | 830 | } | 
|  | 831 |  | 
|  | 832 | status_t AudioPolicyService::getMaxVolumeIndexForAttributes(const audio_attributes_t &attributes, | 
|  | 833 | int &index) | 
|  | 834 | { | 
|  | 835 | if (mAudioPolicyManager == NULL) { | 
|  | 836 | return NO_INIT; | 
|  | 837 | } | 
|  | 838 | Mutex::Autolock _l(mLock); | 
|  | 839 | AutoCallerClear acc; | 
|  | 840 | return mAudioPolicyManager->getMaxVolumeIndexForAttributes(attributes, index); | 
|  | 841 | } | 
|  | 842 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 843 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) | 
|  | 844 | { | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 845 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 846 | return PRODUCT_STRATEGY_NONE; | 
| Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 847 | } | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 848 | if (mAudioPolicyManager == NULL) { | 
| François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 849 | return PRODUCT_STRATEGY_NONE; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 850 | } | 
| François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 851 | // DO NOT LOCK, may be called from AudioFlinger with lock held, reaching deadlock | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 852 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 853 | return mAudioPolicyManager->getStrategyForStream(stream); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 854 | } | 
|  | 855 |  | 
|  | 856 | //audio policy: use audio_device_t appropriately | 
|  | 857 |  | 
|  | 858 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) | 
|  | 859 | { | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 860 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 861 | return AUDIO_DEVICE_NONE; | 
| Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 862 | } | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 863 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 864 | return AUDIO_DEVICE_NONE; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 865 | } | 
| Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 866 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 867 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 868 | return mAudioPolicyManager->getDevicesForStream(stream); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 869 | } | 
|  | 870 |  | 
| Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 871 | status_t AudioPolicyService::getDevicesForAttributes(const AudioAttributes &aa, | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 872 | AudioDeviceTypeAddrVector *devices) const | 
| Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 873 | { | 
|  | 874 | if (mAudioPolicyManager == NULL) { | 
|  | 875 | return NO_INIT; | 
|  | 876 | } | 
|  | 877 | Mutex::Autolock _l(mLock); | 
|  | 878 | AutoCallerClear acc; | 
|  | 879 | return mAudioPolicyManager->getDevicesForAttributes(aa.getAttributes(), devices); | 
|  | 880 | } | 
|  | 881 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 882 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) | 
|  | 883 | { | 
|  | 884 | // FIXME change return type to status_t, and return NO_INIT here | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 885 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 886 | return 0; | 
|  | 887 | } | 
|  | 888 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 889 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 890 | return mAudioPolicyManager->getOutputForEffect(desc); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 891 | } | 
|  | 892 |  | 
|  | 893 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, | 
|  | 894 | audio_io_handle_t io, | 
|  | 895 | uint32_t strategy, | 
| Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 896 | audio_session_t session, | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 897 | int id) | 
|  | 898 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 899 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 900 | return NO_INIT; | 
|  | 901 | } | 
| Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 902 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 903 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 904 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 905 | } | 
|  | 906 |  | 
|  | 907 | status_t AudioPolicyService::unregisterEffect(int id) | 
|  | 908 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 909 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 910 | return NO_INIT; | 
|  | 911 | } | 
| Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 912 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 913 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 914 | return mAudioPolicyManager->unregisterEffect(id); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 915 | } | 
|  | 916 |  | 
|  | 917 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) | 
|  | 918 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 919 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 920 | return NO_INIT; | 
|  | 921 | } | 
| Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 922 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 923 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 924 | return mAudioPolicyManager->setEffectEnabled(id, enabled); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 925 | } | 
|  | 926 |  | 
| Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 927 | status_t AudioPolicyService::moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) | 
|  | 928 | { | 
|  | 929 | if (mAudioPolicyManager == NULL) { | 
|  | 930 | return NO_INIT; | 
|  | 931 | } | 
|  | 932 | Mutex::Autolock _l(mLock); | 
|  | 933 | AutoCallerClear acc; | 
|  | 934 | return mAudioPolicyManager->moveEffectsToIo(ids, io); | 
|  | 935 | } | 
|  | 936 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 937 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const | 
|  | 938 | { | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 939 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 940 | return false; | 
| Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 941 | } | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 942 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 943 | return false; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 944 | } | 
|  | 945 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 946 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 947 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 948 | } | 
|  | 949 |  | 
|  | 950 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const | 
|  | 951 | { | 
| Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 952 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 953 | return false; | 
| Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 954 | } | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 955 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 956 | return false; | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 957 | } | 
|  | 958 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 959 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 960 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 961 | } | 
|  | 962 |  | 
|  | 963 | bool AudioPolicyService::isSourceActive(audio_source_t source) const | 
|  | 964 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 965 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 966 | return false; | 
|  | 967 | } | 
|  | 968 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 969 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 970 | return mAudioPolicyManager->isSourceActive(source); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 971 | } | 
|  | 972 |  | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 973 | status_t AudioPolicyService::getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects) | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 974 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 975 | if (mAudioPolicyManager == NULL) { | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 976 | return NO_INIT; | 
|  | 977 | } | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 978 | { | 
|  | 979 | Mutex::Autolock _l(mLock); | 
|  | 980 | audioPolicyEffects = mAudioPolicyEffects; | 
|  | 981 | } | 
|  | 982 | if (audioPolicyEffects == 0) { | 
| Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 983 | return NO_INIT; | 
|  | 984 | } | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 985 |  | 
|  | 986 | return OK; | 
|  | 987 | } | 
|  | 988 |  | 
|  | 989 | status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession, | 
|  | 990 | effect_descriptor_t *descriptors, | 
|  | 991 | uint32_t *count) | 
|  | 992 | { | 
|  | 993 | sp<AudioPolicyEffects>audioPolicyEffects; | 
|  | 994 | status_t status = getAudioPolicyEffects(audioPolicyEffects); | 
|  | 995 | if (status != OK) { | 
|  | 996 | *count = 0; | 
|  | 997 | return status; | 
|  | 998 | } | 
| Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 999 | return audioPolicyEffects->queryDefaultInputEffects( | 
|  | 1000 | (audio_session_t)audioSession, descriptors, count); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1001 | } | 
|  | 1002 |  | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1003 | status_t AudioPolicyService::addSourceDefaultEffect(const effect_uuid_t *type, | 
|  | 1004 | const String16& opPackageName, | 
|  | 1005 | const effect_uuid_t *uuid, | 
|  | 1006 | int32_t priority, | 
|  | 1007 | audio_source_t source, | 
|  | 1008 | audio_unique_id_t* id) | 
|  | 1009 | { | 
|  | 1010 | sp<AudioPolicyEffects>audioPolicyEffects; | 
|  | 1011 | status_t status = getAudioPolicyEffects(audioPolicyEffects); | 
|  | 1012 | if (status != OK) { | 
|  | 1013 | return status; | 
|  | 1014 | } | 
|  | 1015 | if (!modifyDefaultAudioEffectsAllowed()) { | 
|  | 1016 | return PERMISSION_DENIED; | 
|  | 1017 | } | 
|  | 1018 | return audioPolicyEffects->addSourceDefaultEffect( | 
|  | 1019 | type, opPackageName, uuid, priority, source, id); | 
|  | 1020 | } | 
|  | 1021 |  | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1022 | status_t AudioPolicyService::addStreamDefaultEffect(const effect_uuid_t *type, | 
|  | 1023 | const String16& opPackageName, | 
|  | 1024 | const effect_uuid_t *uuid, | 
|  | 1025 | int32_t priority, | 
|  | 1026 | audio_usage_t usage, | 
|  | 1027 | audio_unique_id_t* id) | 
|  | 1028 | { | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1029 | sp<AudioPolicyEffects>audioPolicyEffects; | 
|  | 1030 | status_t status = getAudioPolicyEffects(audioPolicyEffects); | 
|  | 1031 | if (status != OK) { | 
|  | 1032 | return status; | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1033 | } | 
|  | 1034 | if (!modifyDefaultAudioEffectsAllowed()) { | 
|  | 1035 | return PERMISSION_DENIED; | 
|  | 1036 | } | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1037 | return audioPolicyEffects->addStreamDefaultEffect( | 
|  | 1038 | type, opPackageName, uuid, priority, usage, id); | 
|  | 1039 | } | 
|  | 1040 |  | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1041 | status_t AudioPolicyService::removeSourceDefaultEffect(audio_unique_id_t id) | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1042 | { | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1043 | sp<AudioPolicyEffects>audioPolicyEffects; | 
|  | 1044 | status_t status = getAudioPolicyEffects(audioPolicyEffects); | 
|  | 1045 | if (status != OK) { | 
|  | 1046 | return status; | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1047 | } | 
|  | 1048 | if (!modifyDefaultAudioEffectsAllowed()) { | 
|  | 1049 | return PERMISSION_DENIED; | 
|  | 1050 | } | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1051 | return audioPolicyEffects->removeSourceDefaultEffect(id); | 
|  | 1052 | } | 
|  | 1053 |  | 
|  | 1054 | status_t AudioPolicyService::removeStreamDefaultEffect(audio_unique_id_t id) | 
|  | 1055 | { | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1056 | sp<AudioPolicyEffects>audioPolicyEffects; | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1057 | status_t status = getAudioPolicyEffects(audioPolicyEffects); | 
|  | 1058 | if (status != OK) { | 
|  | 1059 | return status; | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1060 | } | 
| Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1061 | if (!modifyDefaultAudioEffectsAllowed()) { | 
|  | 1062 | return PERMISSION_DENIED; | 
| Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1063 | } | 
|  | 1064 | return audioPolicyEffects->removeStreamDefaultEffect(id); | 
|  | 1065 | } | 
|  | 1066 |  | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1067 | status_t AudioPolicyService::setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) { | 
|  | 1068 | Mutex::Autolock _l(mLock); | 
|  | 1069 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1070 | return PERMISSION_DENIED; | 
|  | 1071 | } | 
|  | 1072 |  | 
|  | 1073 | bool areAllSystemUsages = std::all_of(begin(systemUsages), end(systemUsages), | 
|  | 1074 | [](audio_usage_t usage) { return isSystemUsage(usage); }); | 
|  | 1075 | if (!areAllSystemUsages) { | 
|  | 1076 | return BAD_VALUE; | 
|  | 1077 | } | 
|  | 1078 |  | 
|  | 1079 | mSupportedSystemUsages = systemUsages; | 
|  | 1080 | return NO_ERROR; | 
|  | 1081 | } | 
|  | 1082 |  | 
| Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1083 | status_t AudioPolicyService::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t capturePolicy) { | 
|  | 1084 | Mutex::Autolock _l(mLock); | 
|  | 1085 | if (mAudioPolicyManager == NULL) { | 
|  | 1086 | ALOGV("%s() mAudioPolicyManager == NULL", __func__); | 
|  | 1087 | return NO_INIT; | 
|  | 1088 | } | 
| Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1089 | return mAudioPolicyManager->setAllowedCapturePolicy(uid, capturePolicy); | 
|  | 1090 | } | 
|  | 1091 |  | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1092 | bool AudioPolicyService::isOffloadSupported(const audio_offload_info_t& info) | 
|  | 1093 | { | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1094 | if (mAudioPolicyManager == NULL) { | 
|  | 1095 | ALOGV("mAudioPolicyManager == NULL"); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1096 | return false; | 
|  | 1097 | } | 
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1098 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1099 | AutoCallerClear acc; | 
| Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1100 | return mAudioPolicyManager->isOffloadSupported(info); | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1101 | } | 
|  | 1102 |  | 
| Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1103 | bool AudioPolicyService::isDirectOutputSupported(const audio_config_base_t& config, | 
|  | 1104 | const audio_attributes_t& attributes) { | 
|  | 1105 | if (mAudioPolicyManager == NULL) { | 
|  | 1106 | ALOGV("mAudioPolicyManager == NULL"); | 
|  | 1107 | return false; | 
|  | 1108 | } | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1109 |  | 
|  | 1110 | status_t result = validateUsage(attributes.usage); | 
|  | 1111 | if (result != NO_ERROR) { | 
|  | 1112 | return result; | 
|  | 1113 | } | 
|  | 1114 |  | 
| Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1115 | Mutex::Autolock _l(mLock); | 
|  | 1116 | return mAudioPolicyManager->isDirectOutputSupported(config, attributes); | 
|  | 1117 | } | 
|  | 1118 |  | 
|  | 1119 |  | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1120 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, | 
|  | 1121 | audio_port_type_t type, | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1122 | unsigned int *num_ports, | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1123 | struct audio_port *ports, | 
|  | 1124 | unsigned int *generation) | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1125 | { | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1126 | Mutex::Autolock _l(mLock); | 
|  | 1127 | if (mAudioPolicyManager == NULL) { | 
|  | 1128 | return NO_INIT; | 
|  | 1129 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1130 | AutoCallerClear acc; | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1131 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1132 | } | 
|  | 1133 |  | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1134 | status_t AudioPolicyService::getAudioPort(struct audio_port *port) | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1135 | { | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1136 | Mutex::Autolock _l(mLock); | 
|  | 1137 | if (mAudioPolicyManager == NULL) { | 
|  | 1138 | return NO_INIT; | 
|  | 1139 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1140 | AutoCallerClear acc; | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1141 | return mAudioPolicyManager->getAudioPort(port); | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1142 | } | 
|  | 1143 |  | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1144 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, | 
|  | 1145 | audio_patch_handle_t *handle) | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1146 | { | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1147 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1148 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1149 | return PERMISSION_DENIED; | 
|  | 1150 | } | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1151 | if (mAudioPolicyManager == NULL) { | 
|  | 1152 | return NO_INIT; | 
|  | 1153 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1154 | AutoCallerClear acc; | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1155 | return mAudioPolicyManager->createAudioPatch(patch, handle, | 
|  | 1156 | IPCThreadState::self()->getCallingUid()); | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1157 | } | 
|  | 1158 |  | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1159 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1160 | { | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1161 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1162 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1163 | return PERMISSION_DENIED; | 
|  | 1164 | } | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1165 | if (mAudioPolicyManager == NULL) { | 
|  | 1166 | return NO_INIT; | 
|  | 1167 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1168 | AutoCallerClear acc; | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1169 | return mAudioPolicyManager->releaseAudioPatch(handle, | 
|  | 1170 | IPCThreadState::self()->getCallingUid()); | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1171 | } | 
|  | 1172 |  | 
|  | 1173 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1174 | struct audio_patch *patches, | 
|  | 1175 | unsigned int *generation) | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1176 | { | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1177 | Mutex::Autolock _l(mLock); | 
|  | 1178 | if (mAudioPolicyManager == NULL) { | 
|  | 1179 | return NO_INIT; | 
|  | 1180 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1181 | AutoCallerClear acc; | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1182 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1183 | } | 
|  | 1184 |  | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1185 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1186 | { | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1187 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1188 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1189 | return PERMISSION_DENIED; | 
|  | 1190 | } | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1191 | if (mAudioPolicyManager == NULL) { | 
|  | 1192 | return NO_INIT; | 
|  | 1193 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1194 | AutoCallerClear acc; | 
| Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1195 | return mAudioPolicyManager->setAudioPortConfig(config); | 
| Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1196 | } | 
| Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1197 |  | 
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1198 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, | 
|  | 1199 | audio_io_handle_t *ioHandle, | 
|  | 1200 | audio_devices_t *device) | 
|  | 1201 | { | 
| Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1202 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1203 | if (mAudioPolicyManager == NULL) { | 
|  | 1204 | return NO_INIT; | 
|  | 1205 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1206 | AutoCallerClear acc; | 
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1207 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); | 
|  | 1208 | } | 
|  | 1209 |  | 
|  | 1210 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) | 
|  | 1211 | { | 
| Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1212 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1213 | if (mAudioPolicyManager == NULL) { | 
|  | 1214 | return NO_INIT; | 
|  | 1215 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1216 | AutoCallerClear acc; | 
| Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1217 | return mAudioPolicyManager->releaseSoundTriggerSession(session); | 
|  | 1218 | } | 
|  | 1219 |  | 
| Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1220 | status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) | 
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1221 | { | 
|  | 1222 | Mutex::Autolock _l(mLock); | 
| Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1223 |  | 
|  | 1224 | // loopback|render only need a MediaProjection (checked in caller AudioService.java) | 
|  | 1225 | bool needModifyAudioRouting = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { | 
|  | 1226 | return !is_mix_loopback_render(mix.mRouteFlags); }); | 
|  | 1227 | if (needModifyAudioRouting && !modifyAudioRoutingAllowed()) { | 
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1228 | return PERMISSION_DENIED; | 
|  | 1229 | } | 
| Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1230 |  | 
| Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1231 | // If one of the mixes has needCaptureVoiceCommunicationOutput set to true, then we | 
|  | 1232 | // need to verify that the caller still has CAPTURE_VOICE_COMMUNICATION_OUTPUT | 
| Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1233 | bool needCaptureVoiceCommunicationOutput = | 
|  | 1234 | std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { | 
| Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1235 | return mix.mVoiceCommunicationCaptureAllowed; }); | 
| Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1236 |  | 
| Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1237 | bool needCaptureMediaOutput = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { | 
| Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1238 | return mix.mAllowPrivilegedPlaybackCapture; }); | 
| Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1239 |  | 
| Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1240 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); | 
|  | 1241 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); | 
| Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1242 |  | 
| Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1243 | if (needCaptureMediaOutput && !captureMediaOutputAllowed(callingPid, callingUid)) { | 
|  | 1244 | return PERMISSION_DENIED; | 
|  | 1245 | } | 
|  | 1246 |  | 
| Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1247 | if (needCaptureVoiceCommunicationOutput && | 
|  | 1248 | !captureVoiceCommunicationOutputAllowed(callingPid, callingUid)) { | 
|  | 1249 | return PERMISSION_DENIED; | 
|  | 1250 | } | 
|  | 1251 |  | 
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1252 | if (mAudioPolicyManager == NULL) { | 
|  | 1253 | return NO_INIT; | 
|  | 1254 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1255 | AutoCallerClear acc; | 
| Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1256 | if (registration) { | 
|  | 1257 | return mAudioPolicyManager->registerPolicyMixes(mixes); | 
|  | 1258 | } else { | 
|  | 1259 | return mAudioPolicyManager->unregisterPolicyMixes(mixes); | 
|  | 1260 | } | 
|  | 1261 | } | 
|  | 1262 |  | 
| Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1263 | status_t AudioPolicyService::setUidDeviceAffinities(uid_t uid, | 
| jiabin | c1afe3b | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 1264 | const AudioDeviceTypeAddrVector& devices) { | 
| Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1265 | Mutex::Autolock _l(mLock); | 
|  | 1266 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1267 | return PERMISSION_DENIED; | 
|  | 1268 | } | 
|  | 1269 | if (mAudioPolicyManager == NULL) { | 
|  | 1270 | return NO_INIT; | 
|  | 1271 | } | 
|  | 1272 | AutoCallerClear acc; | 
|  | 1273 | return mAudioPolicyManager->setUidDeviceAffinities(uid, devices); | 
|  | 1274 | } | 
|  | 1275 |  | 
|  | 1276 | status_t AudioPolicyService::removeUidDeviceAffinities(uid_t uid) { | 
|  | 1277 | Mutex::Autolock _l(mLock); | 
|  | 1278 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1279 | return PERMISSION_DENIED; | 
|  | 1280 | } | 
|  | 1281 | if (mAudioPolicyManager == NULL) { | 
|  | 1282 | return NO_INIT; | 
|  | 1283 | } | 
|  | 1284 | AutoCallerClear acc; | 
|  | 1285 | return mAudioPolicyManager->removeUidDeviceAffinities(uid); | 
|  | 1286 | } | 
|  | 1287 |  | 
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1288 | status_t AudioPolicyService::setUserIdDeviceAffinities(int userId, | 
| jiabin | c1afe3b | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 1289 | const AudioDeviceTypeAddrVector& devices) { | 
| Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1290 | Mutex::Autolock _l(mLock); | 
|  | 1291 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1292 | return PERMISSION_DENIED; | 
|  | 1293 | } | 
|  | 1294 | if (mAudioPolicyManager == NULL) { | 
|  | 1295 | return NO_INIT; | 
|  | 1296 | } | 
|  | 1297 | AutoCallerClear acc; | 
|  | 1298 | return mAudioPolicyManager->setUserIdDeviceAffinities(userId, devices); | 
|  | 1299 | } | 
|  | 1300 |  | 
|  | 1301 | status_t AudioPolicyService::removeUserIdDeviceAffinities(int userId) { | 
|  | 1302 | Mutex::Autolock _l(mLock); | 
|  | 1303 | if(!modifyAudioRoutingAllowed()) { | 
|  | 1304 | return PERMISSION_DENIED; | 
|  | 1305 | } | 
|  | 1306 | if (mAudioPolicyManager == NULL) { | 
|  | 1307 | return NO_INIT; | 
|  | 1308 | } | 
|  | 1309 | AutoCallerClear acc; | 
|  | 1310 | return mAudioPolicyManager->removeUserIdDeviceAffinities(userId); | 
|  | 1311 | } | 
|  | 1312 |  | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1313 | status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source, | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1314 | const audio_attributes_t *attributes, | 
|  | 1315 | audio_port_handle_t *portId) | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1316 | { | 
|  | 1317 | Mutex::Autolock _l(mLock); | 
|  | 1318 | if (mAudioPolicyManager == NULL) { | 
|  | 1319 | return NO_INIT; | 
|  | 1320 | } | 
| Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1321 |  | 
|  | 1322 | status_t result = validateUsage(attributes->usage); | 
|  | 1323 | if (result != NO_ERROR) { | 
|  | 1324 | return result; | 
|  | 1325 | } | 
|  | 1326 |  | 
| Hongwei Wang | 5cd1f1d | 2019-03-26 15:21:11 -0700 | [diff] [blame] | 1327 | // startAudioSource should be created as the calling uid | 
|  | 1328 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1329 | AutoCallerClear acc; | 
| Hongwei Wang | 5cd1f1d | 2019-03-26 15:21:11 -0700 | [diff] [blame] | 1330 | return mAudioPolicyManager->startAudioSource(source, attributes, portId, callingUid); | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1331 | } | 
|  | 1332 |  | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1333 | status_t AudioPolicyService::stopAudioSource(audio_port_handle_t portId) | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1334 | { | 
|  | 1335 | Mutex::Autolock _l(mLock); | 
|  | 1336 | if (mAudioPolicyManager == NULL) { | 
|  | 1337 | return NO_INIT; | 
|  | 1338 | } | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1339 | AutoCallerClear acc; | 
| Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1340 | return mAudioPolicyManager->stopAudioSource(portId); | 
| Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1341 | } | 
|  | 1342 |  | 
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1343 | status_t AudioPolicyService::setMasterMono(bool mono) | 
|  | 1344 | { | 
|  | 1345 | if (mAudioPolicyManager == NULL) { | 
|  | 1346 | return NO_INIT; | 
|  | 1347 | } | 
|  | 1348 | if (!settingsAllowed()) { | 
|  | 1349 | return PERMISSION_DENIED; | 
|  | 1350 | } | 
|  | 1351 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1352 | AutoCallerClear acc; | 
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1353 | return mAudioPolicyManager->setMasterMono(mono); | 
|  | 1354 | } | 
|  | 1355 |  | 
|  | 1356 | status_t AudioPolicyService::getMasterMono(bool *mono) | 
|  | 1357 | { | 
|  | 1358 | if (mAudioPolicyManager == NULL) { | 
|  | 1359 | return NO_INIT; | 
|  | 1360 | } | 
|  | 1361 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1362 | AutoCallerClear acc; | 
| Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1363 | return mAudioPolicyManager->getMasterMono(mono); | 
|  | 1364 | } | 
|  | 1365 |  | 
| Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1366 |  | 
|  | 1367 | float AudioPolicyService::getStreamVolumeDB( | 
|  | 1368 | audio_stream_type_t stream, int index, audio_devices_t device) | 
|  | 1369 | { | 
|  | 1370 | if (mAudioPolicyManager == NULL) { | 
|  | 1371 | return NAN; | 
|  | 1372 | } | 
|  | 1373 | Mutex::Autolock _l(mLock); | 
| Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1374 | AutoCallerClear acc; | 
| Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1375 | return mAudioPolicyManager->getStreamVolumeDB(stream, index, device); | 
|  | 1376 | } | 
|  | 1377 |  | 
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1378 | status_t AudioPolicyService::getSurroundFormats(unsigned int *numSurroundFormats, | 
|  | 1379 | audio_format_t *surroundFormats, | 
|  | 1380 | bool *surroundFormatsEnabled, | 
|  | 1381 | bool reported) | 
|  | 1382 | { | 
|  | 1383 | if (mAudioPolicyManager == NULL) { | 
|  | 1384 | return NO_INIT; | 
|  | 1385 | } | 
|  | 1386 | Mutex::Autolock _l(mLock); | 
|  | 1387 | AutoCallerClear acc; | 
|  | 1388 | return mAudioPolicyManager->getSurroundFormats(numSurroundFormats, surroundFormats, | 
|  | 1389 | surroundFormatsEnabled, reported); | 
|  | 1390 | } | 
|  | 1391 |  | 
| Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1392 | status_t AudioPolicyService::getHwOffloadEncodingFormatsSupportedForA2DP( | 
|  | 1393 | std::vector<audio_format_t> *formats) | 
|  | 1394 | { | 
|  | 1395 | if (mAudioPolicyManager == NULL) { | 
|  | 1396 | return NO_INIT; | 
|  | 1397 | } | 
|  | 1398 | Mutex::Autolock _l(mLock); | 
|  | 1399 | AutoCallerClear acc; | 
|  | 1400 | return mAudioPolicyManager->getHwOffloadEncodingFormatsSupportedForA2DP(formats); | 
|  | 1401 | } | 
|  | 1402 |  | 
| jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1403 | status_t AudioPolicyService::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) | 
|  | 1404 | { | 
|  | 1405 | if (mAudioPolicyManager == NULL) { | 
|  | 1406 | return NO_INIT; | 
|  | 1407 | } | 
|  | 1408 | Mutex::Autolock _l(mLock); | 
|  | 1409 | AutoCallerClear acc; | 
|  | 1410 | return mAudioPolicyManager->setSurroundFormatEnabled(audioFormat, enabled); | 
|  | 1411 | } | 
| Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1412 |  | 
| Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1413 | status_t AudioPolicyService::setAssistantUid(uid_t uid) | 
|  | 1414 | { | 
|  | 1415 | Mutex::Autolock _l(mLock); | 
|  | 1416 | mUidPolicy->setAssistantUid(uid); | 
|  | 1417 | return NO_ERROR; | 
|  | 1418 | } | 
|  | 1419 |  | 
|  | 1420 | status_t AudioPolicyService::setA11yServicesUids(const std::vector<uid_t>& uids) | 
|  | 1421 | { | 
|  | 1422 | Mutex::Autolock _l(mLock); | 
|  | 1423 | mUidPolicy->setA11yUids(uids); | 
|  | 1424 | return NO_ERROR; | 
|  | 1425 | } | 
|  | 1426 |  | 
| Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1427 | status_t AudioPolicyService::setCurrentImeUid(uid_t uid) | 
|  | 1428 | { | 
|  | 1429 | Mutex::Autolock _l(mLock); | 
|  | 1430 | mUidPolicy->setCurrentImeUid(uid); | 
|  | 1431 | return NO_ERROR; | 
|  | 1432 | } | 
|  | 1433 |  | 
| jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1434 | bool AudioPolicyService::isHapticPlaybackSupported() | 
|  | 1435 | { | 
|  | 1436 | if (mAudioPolicyManager == NULL) { | 
|  | 1437 | ALOGW("%s, mAudioPolicyManager == NULL", __func__); | 
|  | 1438 | return false; | 
|  | 1439 | } | 
|  | 1440 | Mutex::Autolock _l(mLock); | 
|  | 1441 | AutoCallerClear acc; | 
|  | 1442 | return mAudioPolicyManager->isHapticPlaybackSupported(); | 
|  | 1443 | } | 
|  | 1444 |  | 
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1445 | status_t AudioPolicyService::listAudioProductStrategies(AudioProductStrategyVector &strategies) | 
|  | 1446 | { | 
|  | 1447 | if (mAudioPolicyManager == NULL) { | 
|  | 1448 | return NO_INIT; | 
|  | 1449 | } | 
|  | 1450 | Mutex::Autolock _l(mLock); | 
|  | 1451 | return mAudioPolicyManager->listAudioProductStrategies(strategies); | 
|  | 1452 | } | 
|  | 1453 |  | 
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1454 | status_t AudioPolicyService::getProductStrategyFromAudioAttributes( | 
|  | 1455 | const AudioAttributes &aa, product_strategy_t &productStrategy) | 
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1456 | { | 
|  | 1457 | if (mAudioPolicyManager == NULL) { | 
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1458 | return NO_INIT; | 
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1459 | } | 
|  | 1460 | Mutex::Autolock _l(mLock); | 
| François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1461 | return mAudioPolicyManager->getProductStrategyFromAudioAttributes(aa, productStrategy); | 
|  | 1462 | } | 
|  | 1463 |  | 
|  | 1464 | status_t AudioPolicyService::listAudioVolumeGroups(AudioVolumeGroupVector &groups) | 
|  | 1465 | { | 
|  | 1466 | if (mAudioPolicyManager == NULL) { | 
|  | 1467 | return NO_INIT; | 
|  | 1468 | } | 
|  | 1469 | Mutex::Autolock _l(mLock); | 
|  | 1470 | return mAudioPolicyManager->listAudioVolumeGroups(groups); | 
|  | 1471 | } | 
|  | 1472 |  | 
|  | 1473 | status_t AudioPolicyService::getVolumeGroupFromAudioAttributes(const AudioAttributes &aa, | 
|  | 1474 | volume_group_t &volumeGroup) | 
|  | 1475 | { | 
|  | 1476 | if (mAudioPolicyManager == NULL) { | 
|  | 1477 | return NO_INIT; | 
|  | 1478 | } | 
|  | 1479 | Mutex::Autolock _l(mLock); | 
|  | 1480 | return mAudioPolicyManager->getVolumeGroupFromAudioAttributes(aa, volumeGroup); | 
| François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1481 | } | 
| Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1482 |  | 
|  | 1483 | status_t AudioPolicyService::setRttEnabled(bool enabled) | 
|  | 1484 | { | 
|  | 1485 | Mutex::Autolock _l(mLock); | 
|  | 1486 | mUidPolicy->setRttEnabled(enabled); | 
|  | 1487 | return NO_ERROR; | 
|  | 1488 | } | 
|  | 1489 |  | 
| Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1490 | bool AudioPolicyService::isCallScreenModeSupported() | 
|  | 1491 | { | 
|  | 1492 | if (mAudioPolicyManager == NULL) { | 
|  | 1493 | ALOGW("%s, mAudioPolicyManager == NULL", __func__); | 
|  | 1494 | return false; | 
|  | 1495 | } | 
|  | 1496 | Mutex::Autolock _l(mLock); | 
|  | 1497 | AutoCallerClear acc; | 
|  | 1498 | return mAudioPolicyManager->isCallScreenModeSupported(); | 
|  | 1499 | } | 
|  | 1500 |  | 
| jiabin | 4e82621 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1501 | status_t AudioPolicyService::setDevicesRoleForStrategy(product_strategy_t strategy, | 
|  | 1502 | device_role_t role, | 
|  | 1503 | const AudioDeviceTypeAddrVector &devices) | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1504 | { | 
|  | 1505 | if (mAudioPolicyManager == NULL) { | 
|  | 1506 | return NO_INIT; | 
|  | 1507 | } | 
|  | 1508 | Mutex::Autolock _l(mLock); | 
| jiabin | 4e82621 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1509 | return mAudioPolicyManager->setDevicesRoleForStrategy(strategy, role, devices); | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1510 | } | 
|  | 1511 |  | 
| jiabin | 4e82621 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1512 | status_t AudioPolicyService::removeDevicesRoleForStrategy(product_strategy_t strategy, | 
|  | 1513 | device_role_t role) | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1514 | { | 
|  | 1515 | if (mAudioPolicyManager == NULL) { | 
|  | 1516 | return NO_INIT; | 
|  | 1517 | } | 
|  | 1518 | Mutex::Autolock _l(mLock); | 
| jiabin | 4e82621 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1519 | return mAudioPolicyManager->removeDevicesRoleForStrategy(strategy, role); | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1520 | } | 
|  | 1521 |  | 
| jiabin | 4e82621 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1522 | status_t AudioPolicyService::getDevicesForRoleAndStrategy(product_strategy_t strategy, | 
|  | 1523 | device_role_t role, | 
|  | 1524 | AudioDeviceTypeAddrVector &devices) | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1525 | { | 
|  | 1526 | if (mAudioPolicyManager == NULL) { | 
|  | 1527 | return NO_INIT; | 
|  | 1528 | } | 
|  | 1529 | Mutex::Autolock _l(mLock); | 
| jiabin | 4e82621 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1530 | return mAudioPolicyManager->getDevicesForRoleAndStrategy(strategy, role, devices); | 
| Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1531 | } | 
|  | 1532 |  | 
| Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 1533 | status_t AudioPolicyService::registerSoundTriggerCaptureStateListener( | 
|  | 1534 | const sp<media::ICaptureStateListener>& listener, | 
|  | 1535 | bool* result) | 
|  | 1536 | { | 
|  | 1537 | *result = mCaptureStateNotifier.RegisterListener(listener); | 
|  | 1538 | return NO_ERROR; | 
|  | 1539 | } | 
|  | 1540 |  | 
| Jiabin Huang | 6e46824 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 1541 | status_t AudioPolicyService::setDevicesRoleForCapturePreset( | 
|  | 1542 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector &devices) | 
|  | 1543 | { | 
|  | 1544 | if (mAudioPolicyManager == nullptr) { | 
|  | 1545 | return NO_INIT; | 
|  | 1546 | } | 
|  | 1547 | Mutex::Autolock _l(mLock); | 
|  | 1548 | return mAudioPolicyManager->setDevicesRoleForCapturePreset(audioSource, role, devices); | 
|  | 1549 | } | 
|  | 1550 |  | 
|  | 1551 | status_t AudioPolicyService::addDevicesRoleForCapturePreset( | 
|  | 1552 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector &devices) | 
|  | 1553 | { | 
|  | 1554 | if (mAudioPolicyManager == nullptr) { | 
|  | 1555 | return NO_INIT; | 
|  | 1556 | } | 
|  | 1557 | Mutex::Autolock _l(mLock); | 
|  | 1558 | return mAudioPolicyManager->addDevicesRoleForCapturePreset(audioSource, role, devices); | 
|  | 1559 | } | 
|  | 1560 |  | 
|  | 1561 | status_t AudioPolicyService::removeDevicesRoleForCapturePreset( | 
|  | 1562 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector& devices) | 
|  | 1563 | { | 
|  | 1564 | if (mAudioPolicyManager == nullptr) { | 
|  | 1565 | return NO_INIT; | 
|  | 1566 | } | 
|  | 1567 | Mutex::Autolock _l(mLock); | 
|  | 1568 | return mAudioPolicyManager->removeDevicesRoleForCapturePreset(audioSource, role, devices); | 
|  | 1569 | } | 
|  | 1570 |  | 
|  | 1571 | status_t AudioPolicyService::clearDevicesRoleForCapturePreset(audio_source_t audioSource, | 
|  | 1572 | device_role_t role) | 
|  | 1573 | { | 
|  | 1574 | if (mAudioPolicyManager == nullptr) { | 
|  | 1575 | return NO_INIT; | 
|  | 1576 | } | 
|  | 1577 | Mutex::Autolock _l(mLock); | 
|  | 1578 | return mAudioPolicyManager->clearDevicesRoleForCapturePreset(audioSource, role); | 
|  | 1579 | } | 
|  | 1580 |  | 
|  | 1581 | status_t AudioPolicyService::getDevicesForRoleAndCapturePreset(audio_source_t audioSource, | 
|  | 1582 | device_role_t role, | 
|  | 1583 | AudioDeviceTypeAddrVector &devices) | 
|  | 1584 | { | 
|  | 1585 | if (mAudioPolicyManager == nullptr) { | 
|  | 1586 | return NO_INIT; | 
|  | 1587 | } | 
|  | 1588 | Mutex::Autolock _l(mLock); | 
|  | 1589 | return mAudioPolicyManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices); | 
|  | 1590 | } | 
|  | 1591 |  | 
| Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 1592 | } // namespace android |