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. |
Hayden Gomes | b742992 | 2020-12-11 13:59:18 -0800 | [diff] [blame] | 457 | // Capturing from FM_TUNER source is controlled by captureTunerAudioInputAllowed() and |
| 458 | // captureAudioOutputAllowed() (deprecated) as this does not affect users privacy |
| 459 | // as does capturing from an actual microphone. |
Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 460 | if (!(recordingAllowed(opPackageName, pid, uid) || attr->source == AUDIO_SOURCE_FM_TUNER)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 461 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 462 | __func__, uid, pid); |
| 463 | return PERMISSION_DENIED; |
| 464 | } |
| 465 | |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 466 | bool canCaptureOutput = captureAudioOutputAllowed(pid, uid); |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 467 | if ((inputSource == AUDIO_SOURCE_VOICE_UPLINK || |
| 468 | inputSource == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 469 | inputSource == AUDIO_SOURCE_VOICE_CALL || |
Hayden Gomes | b742992 | 2020-12-11 13:59:18 -0800 | [diff] [blame] | 470 | inputSource == AUDIO_SOURCE_ECHO_REFERENCE) |
| 471 | && !canCaptureOutput) { |
| 472 | return PERMISSION_DENIED; |
| 473 | } |
| 474 | |
| 475 | if (inputSource == AUDIO_SOURCE_FM_TUNER |
| 476 | && !captureTunerAudioInputAllowed(pid, uid) |
| 477 | && !canCaptureOutput) { |
Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 478 | return PERMISSION_DENIED; |
| 479 | } |
| 480 | |
jiabin | 68e0df7 | 2019-03-18 17:55:35 -0700 | [diff] [blame] | 481 | bool canCaptureHotword = captureHotwordAllowed(opPackageName, pid, uid); |
Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 482 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !canCaptureHotword) { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 483 | return BAD_VALUE; |
| 484 | } |
| 485 | |
| 486 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 487 | { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 488 | status_t status; |
| 489 | AudioPolicyInterface::input_type_t inputType; |
| 490 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 491 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 492 | { |
| 493 | AutoCallerClear acc; |
| 494 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Mikhail Naganov | 2996f67 | 2019-04-18 12:29:59 -0700 | [diff] [blame] | 495 | status = mAudioPolicyManager->getInputForAttr(attr, input, riid, session, uid, |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 496 | config, |
| 497 | flags, selectedDeviceId, |
| 498 | &inputType, portId); |
| 499 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 500 | audioPolicyEffects = mAudioPolicyEffects; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 501 | |
| 502 | if (status == NO_ERROR) { |
| 503 | // enforce permission (if any) required for each type of input |
| 504 | switch (inputType) { |
Kevin Rocard | 25f9b05 | 2019-02-27 15:08:54 -0800 | [diff] [blame] | 505 | case AudioPolicyInterface::API_INPUT_MIX_PUBLIC_CAPTURE_PLAYBACK: |
| 506 | // this use case has been validated in audio service with a MediaProjection token, |
| 507 | // and doesn't rely on regular permissions |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 508 | case AudioPolicyInterface::API_INPUT_LEGACY: |
| 509 | break; |
Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 510 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: |
| 511 | // FIXME: use the same permission as for remote submix for now. |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 512 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 513 | if (!canCaptureOutput) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 514 | ALOGE("getInputForAttr() permission denied: capture not allowed"); |
| 515 | status = PERMISSION_DENIED; |
| 516 | } |
| 517 | break; |
| 518 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 519 | if (!modifyAudioRoutingAllowed(pid, uid)) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 520 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); |
| 521 | status = PERMISSION_DENIED; |
| 522 | } |
| 523 | break; |
| 524 | case AudioPolicyInterface::API_INPUT_INVALID: |
| 525 | default: |
| 526 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", |
| 527 | (int)inputType); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | if (status != NO_ERROR) { |
| 532 | if (status == PERMISSION_DENIED) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 533 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 534 | mAudioPolicyManager->releaseInput(*portId); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 535 | } |
| 536 | return status; |
| 537 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 538 | |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 539 | sp<AudioRecordClient> client = new AudioRecordClient(*attr, *input, uid, pid, session, *portId, |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 540 | *selectedDeviceId, opPackageName, |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 541 | canCaptureOutput, canCaptureHotword); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 542 | mAudioRecordClients.add(*portId, client); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 543 | } |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 544 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 545 | if (audioPolicyEffects != 0) { |
| 546 | // create audio pre processors according to input source |
Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 547 | status_t status = audioPolicyEffects->addInputEffects(*input, inputSource, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 548 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 549 | ALOGW("Failed to add effects on input %d", *input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 550 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 551 | } |
Eric Laurent | caf7f48 | 2014-11-25 17:50:47 -0800 | [diff] [blame] | 552 | return NO_ERROR; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 555 | std::string AudioPolicyService::getDeviceTypeStrForPortId(audio_port_handle_t portId) { |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 556 | struct audio_port_v7 port = {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 557 | port.id = portId; |
| 558 | status_t status = mAudioPolicyManager->getAudioPort(&port); |
| 559 | if (status == NO_ERROR && port.type == AUDIO_PORT_TYPE_DEVICE) { |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 560 | return toString(port.ext.device.type); |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 561 | } |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 562 | return {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 565 | status_t AudioPolicyService::startInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 566 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 567 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 568 | return NO_INIT; |
| 569 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 570 | sp<AudioRecordClient> client; |
| 571 | { |
| 572 | Mutex::Autolock _l(mLock); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 573 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 574 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 575 | if (index < 0) { |
| 576 | return INVALID_OPERATION; |
| 577 | } |
| 578 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 579 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 580 | |
| 581 | // check calling permissions |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 582 | if (!(startRecording(client->opPackageName, client->pid, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 583 | client->attributes.source) |
Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 584 | || client->attributes.source == AUDIO_SOURCE_FM_TUNER)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 585 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 586 | __func__, client->uid, client->pid); |
| 587 | return PERMISSION_DENIED; |
| 588 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 589 | |
Eric Laurent | df62892 | 2018-12-06 21:45:51 +0000 | [diff] [blame] | 590 | Mutex::Autolock _l(mLock); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 591 | |
| 592 | client->active = true; |
| 593 | client->startTimeNs = systemTime(); |
| 594 | updateUidStates_l(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 595 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 596 | status_t status; |
| 597 | { |
| 598 | AutoCallerClear acc; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 599 | status = mAudioPolicyManager->startInput(portId); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 600 | |
| 601 | } |
| 602 | |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 603 | // including successes gets very verbose |
Muhammad Qureshi | 087b37c | 2020-06-16 16:37:36 -0700 | [diff] [blame] | 604 | // but once we cut over to statsd, log them all. |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 605 | if (status != NO_ERROR) { |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 606 | |
| 607 | static constexpr char kAudioPolicy[] = "audiopolicy"; |
| 608 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 609 | static constexpr char kAudioPolicyStatus[] = "android.media.audiopolicy.status"; |
| 610 | static constexpr char kAudioPolicyRqstSrc[] = "android.media.audiopolicy.rqst.src"; |
| 611 | static constexpr char kAudioPolicyRqstPkg[] = "android.media.audiopolicy.rqst.pkg"; |
| 612 | static constexpr char kAudioPolicyRqstSession[] = "android.media.audiopolicy.rqst.session"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 613 | static constexpr char kAudioPolicyRqstDevice[] = |
| 614 | "android.media.audiopolicy.rqst.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 615 | static constexpr char kAudioPolicyActiveSrc[] = "android.media.audiopolicy.active.src"; |
| 616 | static constexpr char kAudioPolicyActivePkg[] = "android.media.audiopolicy.active.pkg"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 617 | static constexpr char kAudioPolicyActiveSession[] = |
| 618 | "android.media.audiopolicy.active.session"; |
| 619 | static constexpr char kAudioPolicyActiveDevice[] = |
| 620 | "android.media.audiopolicy.active.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 621 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 622 | mediametrics::Item *item = mediametrics::Item::create(kAudioPolicy); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 623 | if (item != NULL) { |
| 624 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 625 | item->setInt32(kAudioPolicyStatus, status); |
| 626 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 627 | item->setCString(kAudioPolicyRqstSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 628 | toString(client->attributes.source).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 629 | item->setInt32(kAudioPolicyRqstSession, client->session); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 630 | if (client->opPackageName.size() != 0) { |
| 631 | item->setCString(kAudioPolicyRqstPkg, |
| 632 | std::string(String8(client->opPackageName).string()).c_str()); |
| 633 | } else { |
Kevin Rocard | fbdfebe | 2018-06-18 12:30:40 -0700 | [diff] [blame] | 634 | item->setCString(kAudioPolicyRqstPkg, std::to_string(client->uid).c_str()); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 635 | } |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 636 | item->setCString( |
| 637 | kAudioPolicyRqstDevice, getDeviceTypeStrForPortId(client->deviceId).c_str()); |
| 638 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 639 | int count = mAudioRecordClients.size(); |
| 640 | for (int i = 0; i < count ; i++) { |
| 641 | if (portId == mAudioRecordClients.keyAt(i)) { |
| 642 | continue; |
| 643 | } |
| 644 | sp<AudioRecordClient> other = mAudioRecordClients.valueAt(i); |
| 645 | if (other->active) { |
| 646 | // keeps the last of the clients marked active |
| 647 | item->setCString(kAudioPolicyActiveSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 648 | toString(other->attributes.source).c_str()); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 649 | item->setInt32(kAudioPolicyActiveSession, other->session); |
| 650 | if (other->opPackageName.size() != 0) { |
| 651 | item->setCString(kAudioPolicyActivePkg, |
| 652 | std::string(String8(other->opPackageName).string()).c_str()); |
| 653 | } else { |
| 654 | item->setCString(kAudioPolicyRqstPkg, |
| 655 | std::to_string(other->uid).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 656 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 657 | item->setCString(kAudioPolicyActiveDevice, |
| 658 | getDeviceTypeStrForPortId(other->deviceId).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 659 | } |
| 660 | } |
| 661 | item->selfrecord(); |
| 662 | delete item; |
| 663 | item = NULL; |
| 664 | } |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | if (status != NO_ERROR) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 668 | client->active = false; |
| 669 | client->startTimeNs = 0; |
| 670 | updateUidStates_l(); |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 671 | finishRecording(client->opPackageName, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 672 | client->attributes.source); |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 678 | status_t AudioPolicyService::stopInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 679 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 680 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 681 | return NO_INIT; |
| 682 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 683 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 684 | Mutex::Autolock _l(mLock); |
| 685 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 686 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 687 | if (index < 0) { |
| 688 | return INVALID_OPERATION; |
| 689 | } |
| 690 | sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index); |
| 691 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 692 | client->active = false; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 693 | client->startTimeNs = 0; |
| 694 | |
| 695 | updateUidStates_l(); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 696 | |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 697 | // finish the recording app op |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 698 | finishRecording(client->opPackageName, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 699 | client->attributes.source); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 700 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 701 | return mAudioPolicyManager->stopInput(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 702 | } |
| 703 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 704 | void AudioPolicyService::releaseInput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 705 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 706 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 707 | return; |
| 708 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 709 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 710 | sp<AudioRecordClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 711 | { |
| 712 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 713 | audioPolicyEffects = mAudioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 714 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 715 | if (index < 0) { |
| 716 | return; |
| 717 | } |
| 718 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 719 | |
| 720 | if (client->active) { |
| 721 | ALOGW("%s releasing active client portId %d", __FUNCTION__, portId); |
| 722 | client->active = false; |
| 723 | client->startTimeNs = 0; |
| 724 | updateUidStates_l(); |
| 725 | } |
| 726 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 727 | mAudioRecordClients.removeItem(portId); |
| 728 | } |
| 729 | if (client == 0) { |
| 730 | return; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 731 | } |
| 732 | if (audioPolicyEffects != 0) { |
| 733 | // release audio processors from the input |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 734 | status_t status = audioPolicyEffects->releaseInputEffects(client->io, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 735 | if(status != NO_ERROR) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 736 | ALOGW("Failed to release effects on input %d", client->io); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 737 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 738 | } |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 739 | { |
| 740 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 741 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 742 | mAudioPolicyManager->releaseInput(portId); |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 743 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | status_t AudioPolicyService::initStreamVolume(audio_stream_type_t stream, |
| 747 | int indexMin, |
| 748 | int indexMax) |
| 749 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 750 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 751 | return NO_INIT; |
| 752 | } |
| 753 | if (!settingsAllowed()) { |
| 754 | return PERMISSION_DENIED; |
| 755 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 756 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 757 | return BAD_VALUE; |
| 758 | } |
| 759 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 760 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 761 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 762 | return NO_ERROR; |
| 763 | } |
| 764 | |
| 765 | status_t AudioPolicyService::setStreamVolumeIndex(audio_stream_type_t stream, |
| 766 | int index, |
| 767 | audio_devices_t device) |
| 768 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 769 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 770 | return NO_INIT; |
| 771 | } |
| 772 | if (!settingsAllowed()) { |
| 773 | return PERMISSION_DENIED; |
| 774 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 775 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 776 | return BAD_VALUE; |
| 777 | } |
| 778 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 779 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 780 | return mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 781 | index, |
| 782 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | status_t AudioPolicyService::getStreamVolumeIndex(audio_stream_type_t stream, |
| 786 | int *index, |
| 787 | audio_devices_t device) |
| 788 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 789 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 790 | return NO_INIT; |
| 791 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 792 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 793 | return BAD_VALUE; |
| 794 | } |
| 795 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 796 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 797 | return mAudioPolicyManager->getStreamVolumeIndex(stream, |
| 798 | index, |
| 799 | device); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 800 | } |
| 801 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 802 | status_t AudioPolicyService::setVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 803 | int index, audio_devices_t device) |
| 804 | { |
| 805 | if (mAudioPolicyManager == NULL) { |
| 806 | return NO_INIT; |
| 807 | } |
| 808 | if (!settingsAllowed()) { |
| 809 | return PERMISSION_DENIED; |
| 810 | } |
| 811 | Mutex::Autolock _l(mLock); |
| 812 | AutoCallerClear acc; |
| 813 | return mAudioPolicyManager->setVolumeIndexForAttributes(attributes, index, device); |
| 814 | } |
| 815 | |
| 816 | status_t AudioPolicyService::getVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 817 | int &index, audio_devices_t device) |
| 818 | { |
| 819 | if (mAudioPolicyManager == NULL) { |
| 820 | return NO_INIT; |
| 821 | } |
| 822 | Mutex::Autolock _l(mLock); |
| 823 | AutoCallerClear acc; |
| 824 | return mAudioPolicyManager->getVolumeIndexForAttributes(attributes, index, device); |
| 825 | } |
| 826 | |
| 827 | status_t AudioPolicyService::getMinVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 828 | int &index) |
| 829 | { |
| 830 | if (mAudioPolicyManager == NULL) { |
| 831 | return NO_INIT; |
| 832 | } |
| 833 | Mutex::Autolock _l(mLock); |
| 834 | AutoCallerClear acc; |
| 835 | return mAudioPolicyManager->getMinVolumeIndexForAttributes(attributes, index); |
| 836 | } |
| 837 | |
| 838 | status_t AudioPolicyService::getMaxVolumeIndexForAttributes(const audio_attributes_t &attributes, |
| 839 | int &index) |
| 840 | { |
| 841 | if (mAudioPolicyManager == NULL) { |
| 842 | return NO_INIT; |
| 843 | } |
| 844 | Mutex::Autolock _l(mLock); |
| 845 | AutoCallerClear acc; |
| 846 | return mAudioPolicyManager->getMaxVolumeIndexForAttributes(attributes, index); |
| 847 | } |
| 848 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 849 | uint32_t AudioPolicyService::getStrategyForStream(audio_stream_type_t stream) |
| 850 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 851 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 852 | return PRODUCT_STRATEGY_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 853 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 854 | if (mAudioPolicyManager == NULL) { |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 855 | return PRODUCT_STRATEGY_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 856 | } |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 857 | // 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] | 858 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 859 | return mAudioPolicyManager->getStrategyForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | //audio policy: use audio_device_t appropriately |
| 863 | |
| 864 | audio_devices_t AudioPolicyService::getDevicesForStream(audio_stream_type_t stream) |
| 865 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 866 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 867 | return AUDIO_DEVICE_NONE; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 868 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 869 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 870 | return AUDIO_DEVICE_NONE; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 871 | } |
Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 872 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 873 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 874 | return mAudioPolicyManager->getDevicesForStream(stream); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 877 | status_t AudioPolicyService::getDevicesForAttributes(const AudioAttributes &aa, |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 878 | AudioDeviceTypeAddrVector *devices) const |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 879 | { |
| 880 | if (mAudioPolicyManager == NULL) { |
| 881 | return NO_INIT; |
| 882 | } |
| 883 | Mutex::Autolock _l(mLock); |
| 884 | AutoCallerClear acc; |
| 885 | return mAudioPolicyManager->getDevicesForAttributes(aa.getAttributes(), devices); |
| 886 | } |
| 887 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 888 | audio_io_handle_t AudioPolicyService::getOutputForEffect(const effect_descriptor_t *desc) |
| 889 | { |
| 890 | // FIXME change return type to status_t, and return NO_INIT here |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 891 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 892 | return 0; |
| 893 | } |
| 894 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 895 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 896 | return mAudioPolicyManager->getOutputForEffect(desc); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | status_t AudioPolicyService::registerEffect(const effect_descriptor_t *desc, |
| 900 | audio_io_handle_t io, |
| 901 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 902 | audio_session_t session, |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 903 | int id) |
| 904 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 905 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 906 | return NO_INIT; |
| 907 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 908 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 909 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 910 | return mAudioPolicyManager->registerEffect(desc, io, strategy, session, id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | status_t AudioPolicyService::unregisterEffect(int id) |
| 914 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 915 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 916 | return NO_INIT; |
| 917 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 918 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 919 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 920 | return mAudioPolicyManager->unregisterEffect(id); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | status_t AudioPolicyService::setEffectEnabled(int id, bool enabled) |
| 924 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 925 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 926 | return NO_INIT; |
| 927 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 928 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 929 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 930 | return mAudioPolicyManager->setEffectEnabled(id, enabled); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 931 | } |
| 932 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 933 | status_t AudioPolicyService::moveEffectsToIo(const std::vector<int>& ids, audio_io_handle_t io) |
| 934 | { |
| 935 | if (mAudioPolicyManager == NULL) { |
| 936 | return NO_INIT; |
| 937 | } |
| 938 | Mutex::Autolock _l(mLock); |
| 939 | AutoCallerClear acc; |
| 940 | return mAudioPolicyManager->moveEffectsToIo(ids, io); |
| 941 | } |
| 942 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 943 | bool AudioPolicyService::isStreamActive(audio_stream_type_t stream, uint32_t inPastMs) const |
| 944 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 945 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 946 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 947 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 948 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 949 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 950 | } |
| 951 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 952 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 953 | return mAudioPolicyManager->isStreamActive(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | bool AudioPolicyService::isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs) const |
| 957 | { |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 958 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 959 | return false; |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 960 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 961 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | b1322c7 | 2014-10-30 14:59:13 -0700 | [diff] [blame] | 962 | return false; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 963 | } |
| 964 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 965 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 966 | return mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | bool AudioPolicyService::isSourceActive(audio_source_t source) const |
| 970 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 971 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 972 | return false; |
| 973 | } |
| 974 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 975 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 976 | return mAudioPolicyManager->isSourceActive(source); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 977 | } |
| 978 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 979 | status_t AudioPolicyService::getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 980 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 981 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 982 | return NO_INIT; |
| 983 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 984 | { |
| 985 | Mutex::Autolock _l(mLock); |
| 986 | audioPolicyEffects = mAudioPolicyEffects; |
| 987 | } |
| 988 | if (audioPolicyEffects == 0) { |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 989 | return NO_INIT; |
| 990 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 991 | |
| 992 | return OK; |
| 993 | } |
| 994 | |
| 995 | status_t AudioPolicyService::queryDefaultPreProcessing(audio_session_t audioSession, |
| 996 | effect_descriptor_t *descriptors, |
| 997 | uint32_t *count) |
| 998 | { |
| 999 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 1000 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 1001 | if (status != OK) { |
| 1002 | *count = 0; |
| 1003 | return status; |
| 1004 | } |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 1005 | return audioPolicyEffects->queryDefaultInputEffects( |
| 1006 | (audio_session_t)audioSession, descriptors, count); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1009 | status_t AudioPolicyService::addSourceDefaultEffect(const effect_uuid_t *type, |
| 1010 | const String16& opPackageName, |
| 1011 | const effect_uuid_t *uuid, |
| 1012 | int32_t priority, |
| 1013 | audio_source_t source, |
| 1014 | audio_unique_id_t* id) |
| 1015 | { |
| 1016 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 1017 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 1018 | if (status != OK) { |
| 1019 | return status; |
| 1020 | } |
| 1021 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 1022 | return PERMISSION_DENIED; |
| 1023 | } |
| 1024 | return audioPolicyEffects->addSourceDefaultEffect( |
| 1025 | type, opPackageName, uuid, priority, source, id); |
| 1026 | } |
| 1027 | |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1028 | status_t AudioPolicyService::addStreamDefaultEffect(const effect_uuid_t *type, |
| 1029 | const String16& opPackageName, |
| 1030 | const effect_uuid_t *uuid, |
| 1031 | int32_t priority, |
| 1032 | audio_usage_t usage, |
| 1033 | audio_unique_id_t* id) |
| 1034 | { |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1035 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 1036 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 1037 | if (status != OK) { |
| 1038 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1039 | } |
| 1040 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 1041 | return PERMISSION_DENIED; |
| 1042 | } |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1043 | return audioPolicyEffects->addStreamDefaultEffect( |
| 1044 | type, opPackageName, uuid, priority, usage, id); |
| 1045 | } |
| 1046 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1047 | status_t AudioPolicyService::removeSourceDefaultEffect(audio_unique_id_t id) |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1048 | { |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1049 | sp<AudioPolicyEffects>audioPolicyEffects; |
| 1050 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 1051 | if (status != OK) { |
| 1052 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1053 | } |
| 1054 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 1055 | return PERMISSION_DENIED; |
| 1056 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1057 | return audioPolicyEffects->removeSourceDefaultEffect(id); |
| 1058 | } |
| 1059 | |
| 1060 | status_t AudioPolicyService::removeStreamDefaultEffect(audio_unique_id_t id) |
| 1061 | { |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1062 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1063 | status_t status = getAudioPolicyEffects(audioPolicyEffects); |
| 1064 | if (status != OK) { |
| 1065 | return status; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1066 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1067 | if (!modifyDefaultAudioEffectsAllowed()) { |
| 1068 | return PERMISSION_DENIED; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1069 | } |
| 1070 | return audioPolicyEffects->removeStreamDefaultEffect(id); |
| 1071 | } |
| 1072 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1073 | status_t AudioPolicyService::setSupportedSystemUsages(const std::vector<audio_usage_t>& systemUsages) { |
| 1074 | Mutex::Autolock _l(mLock); |
| 1075 | if(!modifyAudioRoutingAllowed()) { |
| 1076 | return PERMISSION_DENIED; |
| 1077 | } |
| 1078 | |
| 1079 | bool areAllSystemUsages = std::all_of(begin(systemUsages), end(systemUsages), |
| 1080 | [](audio_usage_t usage) { return isSystemUsage(usage); }); |
| 1081 | if (!areAllSystemUsages) { |
| 1082 | return BAD_VALUE; |
| 1083 | } |
| 1084 | |
| 1085 | mSupportedSystemUsages = systemUsages; |
| 1086 | return NO_ERROR; |
| 1087 | } |
| 1088 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1089 | status_t AudioPolicyService::setAllowedCapturePolicy(uid_t uid, audio_flags_mask_t capturePolicy) { |
| 1090 | Mutex::Autolock _l(mLock); |
| 1091 | if (mAudioPolicyManager == NULL) { |
| 1092 | ALOGV("%s() mAudioPolicyManager == NULL", __func__); |
| 1093 | return NO_INIT; |
| 1094 | } |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1095 | return mAudioPolicyManager->setAllowedCapturePolicy(uid, capturePolicy); |
| 1096 | } |
| 1097 | |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1098 | audio_offload_mode_t AudioPolicyService::getOffloadSupport(const audio_offload_info_t& info) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1099 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1100 | if (mAudioPolicyManager == NULL) { |
| 1101 | ALOGV("mAudioPolicyManager == NULL"); |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1102 | return AUDIO_OFFLOAD_NOT_SUPPORTED; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1103 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1104 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1105 | AutoCallerClear acc; |
Eric Laurent | 90fe31c | 2020-11-26 20:06:35 +0100 | [diff] [blame] | 1106 | return mAudioPolicyManager->getOffloadSupport(info); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1109 | bool AudioPolicyService::isDirectOutputSupported(const audio_config_base_t& config, |
| 1110 | const audio_attributes_t& attributes) { |
| 1111 | if (mAudioPolicyManager == NULL) { |
| 1112 | ALOGV("mAudioPolicyManager == NULL"); |
| 1113 | return false; |
| 1114 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1115 | |
| 1116 | status_t result = validateUsage(attributes.usage); |
| 1117 | if (result != NO_ERROR) { |
| 1118 | return result; |
| 1119 | } |
| 1120 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1121 | Mutex::Autolock _l(mLock); |
| 1122 | return mAudioPolicyManager->isDirectOutputSupported(config, attributes); |
| 1123 | } |
| 1124 | |
| 1125 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1126 | status_t AudioPolicyService::listAudioPorts(audio_port_role_t role, |
| 1127 | audio_port_type_t type, |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1128 | unsigned int *num_ports, |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1129 | struct audio_port_v7 *ports, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1130 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1131 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1132 | Mutex::Autolock _l(mLock); |
| 1133 | if (mAudioPolicyManager == NULL) { |
| 1134 | return NO_INIT; |
| 1135 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1136 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1137 | return mAudioPolicyManager->listAudioPorts(role, type, num_ports, ports, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 1140 | status_t AudioPolicyService::getAudioPort(struct audio_port_v7 *port) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1141 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1142 | Mutex::Autolock _l(mLock); |
| 1143 | if (mAudioPolicyManager == NULL) { |
| 1144 | return NO_INIT; |
| 1145 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1146 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1147 | return mAudioPolicyManager->getAudioPort(port); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1150 | status_t AudioPolicyService::createAudioPatch(const struct audio_patch *patch, |
| 1151 | audio_patch_handle_t *handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1152 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1153 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1154 | if(!modifyAudioRoutingAllowed()) { |
| 1155 | return PERMISSION_DENIED; |
| 1156 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1157 | if (mAudioPolicyManager == NULL) { |
| 1158 | return NO_INIT; |
| 1159 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1160 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1161 | return mAudioPolicyManager->createAudioPatch(patch, handle, |
| 1162 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1163 | } |
| 1164 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1165 | status_t AudioPolicyService::releaseAudioPatch(audio_patch_handle_t handle) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1166 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1167 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1168 | if(!modifyAudioRoutingAllowed()) { |
| 1169 | return PERMISSION_DENIED; |
| 1170 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1171 | if (mAudioPolicyManager == NULL) { |
| 1172 | return NO_INIT; |
| 1173 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1174 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1175 | return mAudioPolicyManager->releaseAudioPatch(handle, |
| 1176 | IPCThreadState::self()->getCallingUid()); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1177 | } |
| 1178 | |
| 1179 | status_t AudioPolicyService::listAudioPatches(unsigned int *num_patches, |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1180 | struct audio_patch *patches, |
| 1181 | unsigned int *generation) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1182 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1183 | Mutex::Autolock _l(mLock); |
| 1184 | if (mAudioPolicyManager == NULL) { |
| 1185 | return NO_INIT; |
| 1186 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1187 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1188 | return mAudioPolicyManager->listAudioPatches(num_patches, patches, generation); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1189 | } |
| 1190 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1191 | status_t AudioPolicyService::setAudioPortConfig(const struct audio_port_config *config) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1192 | { |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1193 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1194 | if(!modifyAudioRoutingAllowed()) { |
| 1195 | return PERMISSION_DENIED; |
| 1196 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1197 | if (mAudioPolicyManager == NULL) { |
| 1198 | return NO_INIT; |
| 1199 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1200 | AutoCallerClear acc; |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1201 | return mAudioPolicyManager->setAudioPortConfig(config); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1202 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1203 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1204 | status_t AudioPolicyService::acquireSoundTriggerSession(audio_session_t *session, |
| 1205 | audio_io_handle_t *ioHandle, |
| 1206 | audio_devices_t *device) |
| 1207 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1208 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1209 | if (mAudioPolicyManager == NULL) { |
| 1210 | return NO_INIT; |
| 1211 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1212 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1213 | return mAudioPolicyManager->acquireSoundTriggerSession(session, ioHandle, device); |
| 1214 | } |
| 1215 | |
| 1216 | status_t AudioPolicyService::releaseSoundTriggerSession(audio_session_t session) |
| 1217 | { |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1218 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1219 | if (mAudioPolicyManager == NULL) { |
| 1220 | return NO_INIT; |
| 1221 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1222 | AutoCallerClear acc; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1223 | return mAudioPolicyManager->releaseSoundTriggerSession(session); |
| 1224 | } |
| 1225 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1226 | status_t AudioPolicyService::registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration) |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1227 | { |
| 1228 | Mutex::Autolock _l(mLock); |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1229 | |
| 1230 | // loopback|render only need a MediaProjection (checked in caller AudioService.java) |
| 1231 | bool needModifyAudioRouting = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
| 1232 | return !is_mix_loopback_render(mix.mRouteFlags); }); |
| 1233 | if (needModifyAudioRouting && !modifyAudioRoutingAllowed()) { |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1234 | return PERMISSION_DENIED; |
| 1235 | } |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1236 | |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1237 | // If one of the mixes has needCaptureVoiceCommunicationOutput set to true, then we |
| 1238 | // need to verify that the caller still has CAPTURE_VOICE_COMMUNICATION_OUTPUT |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1239 | bool needCaptureVoiceCommunicationOutput = |
| 1240 | std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1241 | return mix.mVoiceCommunicationCaptureAllowed; }); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1242 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1243 | bool needCaptureMediaOutput = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1244 | return mix.mAllowPrivilegedPlaybackCapture; }); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1245 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1246 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
| 1247 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1248 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1249 | if (needCaptureMediaOutput && !captureMediaOutputAllowed(callingPid, callingUid)) { |
| 1250 | return PERMISSION_DENIED; |
| 1251 | } |
| 1252 | |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1253 | if (needCaptureVoiceCommunicationOutput && |
| 1254 | !captureVoiceCommunicationOutputAllowed(callingPid, callingUid)) { |
| 1255 | return PERMISSION_DENIED; |
| 1256 | } |
| 1257 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1258 | if (mAudioPolicyManager == NULL) { |
| 1259 | return NO_INIT; |
| 1260 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1261 | AutoCallerClear acc; |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1262 | if (registration) { |
| 1263 | return mAudioPolicyManager->registerPolicyMixes(mixes); |
| 1264 | } else { |
| 1265 | return mAudioPolicyManager->unregisterPolicyMixes(mixes); |
| 1266 | } |
| 1267 | } |
| 1268 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1269 | status_t AudioPolicyService::setUidDeviceAffinities(uid_t uid, |
jiabin | 6a02d53 | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 1270 | const AudioDeviceTypeAddrVector& devices) { |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1271 | Mutex::Autolock _l(mLock); |
| 1272 | if(!modifyAudioRoutingAllowed()) { |
| 1273 | return PERMISSION_DENIED; |
| 1274 | } |
| 1275 | if (mAudioPolicyManager == NULL) { |
| 1276 | return NO_INIT; |
| 1277 | } |
| 1278 | AutoCallerClear acc; |
| 1279 | return mAudioPolicyManager->setUidDeviceAffinities(uid, devices); |
| 1280 | } |
| 1281 | |
| 1282 | status_t AudioPolicyService::removeUidDeviceAffinities(uid_t uid) { |
| 1283 | Mutex::Autolock _l(mLock); |
| 1284 | if(!modifyAudioRoutingAllowed()) { |
| 1285 | return PERMISSION_DENIED; |
| 1286 | } |
| 1287 | if (mAudioPolicyManager == NULL) { |
| 1288 | return NO_INIT; |
| 1289 | } |
| 1290 | AutoCallerClear acc; |
| 1291 | return mAudioPolicyManager->removeUidDeviceAffinities(uid); |
| 1292 | } |
| 1293 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1294 | status_t AudioPolicyService::setUserIdDeviceAffinities(int userId, |
jiabin | 6a02d53 | 2020-08-07 11:56:38 -0700 | [diff] [blame] | 1295 | const AudioDeviceTypeAddrVector& devices) { |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1296 | Mutex::Autolock _l(mLock); |
| 1297 | if(!modifyAudioRoutingAllowed()) { |
| 1298 | return PERMISSION_DENIED; |
| 1299 | } |
| 1300 | if (mAudioPolicyManager == NULL) { |
| 1301 | return NO_INIT; |
| 1302 | } |
| 1303 | AutoCallerClear acc; |
| 1304 | return mAudioPolicyManager->setUserIdDeviceAffinities(userId, devices); |
| 1305 | } |
| 1306 | |
| 1307 | status_t AudioPolicyService::removeUserIdDeviceAffinities(int userId) { |
| 1308 | Mutex::Autolock _l(mLock); |
| 1309 | if(!modifyAudioRoutingAllowed()) { |
| 1310 | return PERMISSION_DENIED; |
| 1311 | } |
| 1312 | if (mAudioPolicyManager == NULL) { |
| 1313 | return NO_INIT; |
| 1314 | } |
| 1315 | AutoCallerClear acc; |
| 1316 | return mAudioPolicyManager->removeUserIdDeviceAffinities(userId); |
| 1317 | } |
| 1318 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1319 | status_t AudioPolicyService::startAudioSource(const struct audio_port_config *source, |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1320 | const audio_attributes_t *attributes, |
| 1321 | audio_port_handle_t *portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1322 | { |
| 1323 | Mutex::Autolock _l(mLock); |
| 1324 | if (mAudioPolicyManager == NULL) { |
| 1325 | return NO_INIT; |
| 1326 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1327 | |
| 1328 | status_t result = validateUsage(attributes->usage); |
| 1329 | if (result != NO_ERROR) { |
| 1330 | return result; |
| 1331 | } |
| 1332 | |
Hongwei Wang | 5cd1f1d | 2019-03-26 15:21:11 -0700 | [diff] [blame] | 1333 | // startAudioSource should be created as the calling uid |
| 1334 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1335 | AutoCallerClear acc; |
Hongwei Wang | 5cd1f1d | 2019-03-26 15:21:11 -0700 | [diff] [blame] | 1336 | return mAudioPolicyManager->startAudioSource(source, attributes, portId, callingUid); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1339 | status_t AudioPolicyService::stopAudioSource(audio_port_handle_t portId) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1340 | { |
| 1341 | Mutex::Autolock _l(mLock); |
| 1342 | if (mAudioPolicyManager == NULL) { |
| 1343 | return NO_INIT; |
| 1344 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1345 | AutoCallerClear acc; |
Eric Laurent | 3e6c7e1 | 2018-07-27 17:09:23 -0700 | [diff] [blame] | 1346 | return mAudioPolicyManager->stopAudioSource(portId); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1347 | } |
| 1348 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1349 | status_t AudioPolicyService::setMasterMono(bool mono) |
| 1350 | { |
| 1351 | if (mAudioPolicyManager == NULL) { |
| 1352 | return NO_INIT; |
| 1353 | } |
| 1354 | if (!settingsAllowed()) { |
| 1355 | return PERMISSION_DENIED; |
| 1356 | } |
| 1357 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1358 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1359 | return mAudioPolicyManager->setMasterMono(mono); |
| 1360 | } |
| 1361 | |
| 1362 | status_t AudioPolicyService::getMasterMono(bool *mono) |
| 1363 | { |
| 1364 | if (mAudioPolicyManager == NULL) { |
| 1365 | return NO_INIT; |
| 1366 | } |
| 1367 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1368 | AutoCallerClear acc; |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1369 | return mAudioPolicyManager->getMasterMono(mono); |
| 1370 | } |
| 1371 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1372 | |
| 1373 | float AudioPolicyService::getStreamVolumeDB( |
| 1374 | audio_stream_type_t stream, int index, audio_devices_t device) |
| 1375 | { |
| 1376 | if (mAudioPolicyManager == NULL) { |
| 1377 | return NAN; |
| 1378 | } |
| 1379 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1380 | AutoCallerClear acc; |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1381 | return mAudioPolicyManager->getStreamVolumeDB(stream, index, device); |
| 1382 | } |
| 1383 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1384 | status_t AudioPolicyService::getSurroundFormats(unsigned int *numSurroundFormats, |
| 1385 | audio_format_t *surroundFormats, |
| 1386 | bool *surroundFormatsEnabled, |
| 1387 | bool reported) |
| 1388 | { |
| 1389 | if (mAudioPolicyManager == NULL) { |
| 1390 | return NO_INIT; |
| 1391 | } |
| 1392 | Mutex::Autolock _l(mLock); |
| 1393 | AutoCallerClear acc; |
| 1394 | return mAudioPolicyManager->getSurroundFormats(numSurroundFormats, surroundFormats, |
| 1395 | surroundFormatsEnabled, reported); |
| 1396 | } |
| 1397 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1398 | status_t AudioPolicyService::getHwOffloadEncodingFormatsSupportedForA2DP( |
| 1399 | std::vector<audio_format_t> *formats) |
| 1400 | { |
| 1401 | if (mAudioPolicyManager == NULL) { |
| 1402 | return NO_INIT; |
| 1403 | } |
| 1404 | Mutex::Autolock _l(mLock); |
| 1405 | AutoCallerClear acc; |
| 1406 | return mAudioPolicyManager->getHwOffloadEncodingFormatsSupportedForA2DP(formats); |
| 1407 | } |
| 1408 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1409 | status_t AudioPolicyService::setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled) |
| 1410 | { |
| 1411 | if (mAudioPolicyManager == NULL) { |
| 1412 | return NO_INIT; |
| 1413 | } |
| 1414 | Mutex::Autolock _l(mLock); |
| 1415 | AutoCallerClear acc; |
| 1416 | return mAudioPolicyManager->setSurroundFormatEnabled(audioFormat, enabled); |
| 1417 | } |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1418 | |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1419 | status_t AudioPolicyService::setAssistantUid(uid_t uid) |
| 1420 | { |
| 1421 | Mutex::Autolock _l(mLock); |
| 1422 | mUidPolicy->setAssistantUid(uid); |
| 1423 | return NO_ERROR; |
| 1424 | } |
| 1425 | |
| 1426 | status_t AudioPolicyService::setA11yServicesUids(const std::vector<uid_t>& uids) |
| 1427 | { |
| 1428 | Mutex::Autolock _l(mLock); |
| 1429 | mUidPolicy->setA11yUids(uids); |
| 1430 | return NO_ERROR; |
| 1431 | } |
| 1432 | |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1433 | status_t AudioPolicyService::setCurrentImeUid(uid_t uid) |
| 1434 | { |
| 1435 | Mutex::Autolock _l(mLock); |
| 1436 | mUidPolicy->setCurrentImeUid(uid); |
| 1437 | return NO_ERROR; |
| 1438 | } |
| 1439 | |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1440 | bool AudioPolicyService::isHapticPlaybackSupported() |
| 1441 | { |
| 1442 | if (mAudioPolicyManager == NULL) { |
| 1443 | ALOGW("%s, mAudioPolicyManager == NULL", __func__); |
| 1444 | return false; |
| 1445 | } |
| 1446 | Mutex::Autolock _l(mLock); |
| 1447 | AutoCallerClear acc; |
| 1448 | return mAudioPolicyManager->isHapticPlaybackSupported(); |
| 1449 | } |
| 1450 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1451 | status_t AudioPolicyService::listAudioProductStrategies(AudioProductStrategyVector &strategies) |
| 1452 | { |
| 1453 | if (mAudioPolicyManager == NULL) { |
| 1454 | return NO_INIT; |
| 1455 | } |
| 1456 | Mutex::Autolock _l(mLock); |
| 1457 | return mAudioPolicyManager->listAudioProductStrategies(strategies); |
| 1458 | } |
| 1459 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1460 | status_t AudioPolicyService::getProductStrategyFromAudioAttributes( |
| 1461 | const AudioAttributes &aa, product_strategy_t &productStrategy) |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1462 | { |
| 1463 | if (mAudioPolicyManager == NULL) { |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1464 | return NO_INIT; |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1465 | } |
| 1466 | Mutex::Autolock _l(mLock); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1467 | return mAudioPolicyManager->getProductStrategyFromAudioAttributes(aa, productStrategy); |
| 1468 | } |
| 1469 | |
| 1470 | status_t AudioPolicyService::listAudioVolumeGroups(AudioVolumeGroupVector &groups) |
| 1471 | { |
| 1472 | if (mAudioPolicyManager == NULL) { |
| 1473 | return NO_INIT; |
| 1474 | } |
| 1475 | Mutex::Autolock _l(mLock); |
| 1476 | return mAudioPolicyManager->listAudioVolumeGroups(groups); |
| 1477 | } |
| 1478 | |
| 1479 | status_t AudioPolicyService::getVolumeGroupFromAudioAttributes(const AudioAttributes &aa, |
| 1480 | volume_group_t &volumeGroup) |
| 1481 | { |
| 1482 | if (mAudioPolicyManager == NULL) { |
| 1483 | return NO_INIT; |
| 1484 | } |
| 1485 | Mutex::Autolock _l(mLock); |
| 1486 | return mAudioPolicyManager->getVolumeGroupFromAudioAttributes(aa, volumeGroup); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1487 | } |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1488 | |
| 1489 | status_t AudioPolicyService::setRttEnabled(bool enabled) |
| 1490 | { |
| 1491 | Mutex::Autolock _l(mLock); |
| 1492 | mUidPolicy->setRttEnabled(enabled); |
| 1493 | return NO_ERROR; |
| 1494 | } |
| 1495 | |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1496 | bool AudioPolicyService::isCallScreenModeSupported() |
| 1497 | { |
| 1498 | if (mAudioPolicyManager == NULL) { |
| 1499 | ALOGW("%s, mAudioPolicyManager == NULL", __func__); |
| 1500 | return false; |
| 1501 | } |
| 1502 | Mutex::Autolock _l(mLock); |
| 1503 | AutoCallerClear acc; |
| 1504 | return mAudioPolicyManager->isCallScreenModeSupported(); |
| 1505 | } |
| 1506 | |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1507 | status_t AudioPolicyService::setDevicesRoleForStrategy(product_strategy_t strategy, |
| 1508 | device_role_t role, |
| 1509 | const AudioDeviceTypeAddrVector &devices) |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1510 | { |
| 1511 | if (mAudioPolicyManager == NULL) { |
| 1512 | return NO_INIT; |
| 1513 | } |
| 1514 | Mutex::Autolock _l(mLock); |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1515 | return mAudioPolicyManager->setDevicesRoleForStrategy(strategy, role, devices); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1516 | } |
| 1517 | |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1518 | status_t AudioPolicyService::removeDevicesRoleForStrategy(product_strategy_t strategy, |
| 1519 | device_role_t role) |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1520 | { |
| 1521 | if (mAudioPolicyManager == NULL) { |
| 1522 | return NO_INIT; |
| 1523 | } |
| 1524 | Mutex::Autolock _l(mLock); |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1525 | return mAudioPolicyManager->removeDevicesRoleForStrategy(strategy, role); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1528 | status_t AudioPolicyService::getDevicesForRoleAndStrategy(product_strategy_t strategy, |
| 1529 | device_role_t role, |
| 1530 | AudioDeviceTypeAddrVector &devices) |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1531 | { |
| 1532 | if (mAudioPolicyManager == NULL) { |
| 1533 | return NO_INIT; |
| 1534 | } |
| 1535 | Mutex::Autolock _l(mLock); |
jiabin | 0a48893 | 2020-08-07 17:32:40 -0700 | [diff] [blame] | 1536 | return mAudioPolicyManager->getDevicesForRoleAndStrategy(strategy, role, devices); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 1539 | status_t AudioPolicyService::registerSoundTriggerCaptureStateListener( |
| 1540 | const sp<media::ICaptureStateListener>& listener, |
| 1541 | bool* result) |
| 1542 | { |
| 1543 | *result = mCaptureStateNotifier.RegisterListener(listener); |
| 1544 | return NO_ERROR; |
| 1545 | } |
| 1546 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 1547 | status_t AudioPolicyService::setDevicesRoleForCapturePreset( |
| 1548 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector &devices) |
| 1549 | { |
| 1550 | if (mAudioPolicyManager == nullptr) { |
| 1551 | return NO_INIT; |
| 1552 | } |
| 1553 | Mutex::Autolock _l(mLock); |
| 1554 | return mAudioPolicyManager->setDevicesRoleForCapturePreset(audioSource, role, devices); |
| 1555 | } |
| 1556 | |
| 1557 | status_t AudioPolicyService::addDevicesRoleForCapturePreset( |
| 1558 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector &devices) |
| 1559 | { |
| 1560 | if (mAudioPolicyManager == nullptr) { |
| 1561 | return NO_INIT; |
| 1562 | } |
| 1563 | Mutex::Autolock _l(mLock); |
| 1564 | return mAudioPolicyManager->addDevicesRoleForCapturePreset(audioSource, role, devices); |
| 1565 | } |
| 1566 | |
| 1567 | status_t AudioPolicyService::removeDevicesRoleForCapturePreset( |
| 1568 | audio_source_t audioSource, device_role_t role, const AudioDeviceTypeAddrVector& devices) |
| 1569 | { |
| 1570 | if (mAudioPolicyManager == nullptr) { |
| 1571 | return NO_INIT; |
| 1572 | } |
| 1573 | Mutex::Autolock _l(mLock); |
| 1574 | return mAudioPolicyManager->removeDevicesRoleForCapturePreset(audioSource, role, devices); |
| 1575 | } |
| 1576 | |
| 1577 | status_t AudioPolicyService::clearDevicesRoleForCapturePreset(audio_source_t audioSource, |
| 1578 | device_role_t role) |
| 1579 | { |
| 1580 | if (mAudioPolicyManager == nullptr) { |
| 1581 | return NO_INIT; |
| 1582 | } |
| 1583 | Mutex::Autolock _l(mLock); |
| 1584 | return mAudioPolicyManager->clearDevicesRoleForCapturePreset(audioSource, role); |
| 1585 | } |
| 1586 | |
| 1587 | status_t AudioPolicyService::getDevicesForRoleAndCapturePreset(audio_source_t audioSource, |
| 1588 | device_role_t role, |
| 1589 | AudioDeviceTypeAddrVector &devices) |
| 1590 | { |
| 1591 | if (mAudioPolicyManager == nullptr) { |
| 1592 | return NO_INIT; |
| 1593 | } |
| 1594 | Mutex::Autolock _l(mLock); |
| 1595 | return mAudioPolicyManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices); |
| 1596 | } |
| 1597 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 1598 | } // namespace android |