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