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