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