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