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