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" |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 22 | #include <media/AidlConversion.h> |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 23 | #include <media/AudioPolicy.h> |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 24 | #include <media/AudioValidator.h> |
| 25 | #include <media/MediaMetricsItem.h> |
| 26 | #include <media/PolicyAidlConversion.h> |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 27 | #include <utils/Log.h> |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 28 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 29 | #define VALUE_OR_RETURN_BINDER_STATUS(x) \ |
| 30 | ({ auto _tmp = (x); \ |
| 31 | if (!_tmp.ok()) return aidl_utils::binderStatusFromStatusT(_tmp.error()); \ |
| 32 | std::move(_tmp.value()); }) |
| 33 | |
| 34 | #define RETURN_IF_BINDER_ERROR(x) \ |
| 35 | { \ |
| 36 | binder::Status _tmp = (x); \ |
| 37 | if (!_tmp.isOk()) return _tmp; \ |
| 38 | } |
| 39 | |
| 40 | #define MAX_ITEMS_PER_LIST 1024 |
| 41 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 42 | namespace android { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 43 | using binder::Status; |
| 44 | using aidl_utils::binderStatusFromStatusT; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 45 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 46 | const std::vector<audio_usage_t>& SYSTEM_USAGES = { |
| 47 | AUDIO_USAGE_CALL_ASSISTANT, |
| 48 | AUDIO_USAGE_EMERGENCY, |
| 49 | AUDIO_USAGE_SAFETY, |
| 50 | AUDIO_USAGE_VEHICLE_STATUS, |
| 51 | AUDIO_USAGE_ANNOUNCEMENT |
| 52 | }; |
| 53 | |
| 54 | bool isSystemUsage(audio_usage_t usage) { |
| 55 | return std::find(std::begin(SYSTEM_USAGES), std::end(SYSTEM_USAGES), usage) |
| 56 | != std::end(SYSTEM_USAGES); |
| 57 | } |
| 58 | |
| 59 | bool AudioPolicyService::isSupportedSystemUsage(audio_usage_t usage) { |
| 60 | return std::find(std::begin(mSupportedSystemUsages), std::end(mSupportedSystemUsages), usage) |
| 61 | != std::end(mSupportedSystemUsages); |
| 62 | } |
| 63 | |
| 64 | status_t AudioPolicyService::validateUsage(audio_usage_t usage) { |
| 65 | return validateUsage(usage, IPCThreadState::self()->getCallingPid(), |
| 66 | IPCThreadState::self()->getCallingUid()); |
| 67 | } |
| 68 | |
| 69 | status_t AudioPolicyService::validateUsage(audio_usage_t usage, pid_t pid, uid_t uid) { |
| 70 | if (isSystemUsage(usage)) { |
| 71 | if (isSupportedSystemUsage(usage)) { |
| 72 | if (!modifyAudioRoutingAllowed(pid, uid)) { |
| 73 | ALOGE("permission denied: modify audio routing not allowed for uid %d", uid); |
| 74 | return PERMISSION_DENIED; |
| 75 | } |
| 76 | } else { |
| 77 | return BAD_VALUE; |
| 78 | } |
| 79 | } |
| 80 | return NO_ERROR; |
| 81 | } |
| 82 | |
| 83 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 84 | |
| 85 | // ---------------------------------------------------------------------------- |
| 86 | |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 87 | void AudioPolicyService::doOnNewAudioModulesAvailable() |
| 88 | { |
| 89 | if (mAudioPolicyManager == NULL) return; |
| 90 | Mutex::Autolock _l(mLock); |
| 91 | AutoCallerClear acc; |
| 92 | mAudioPolicyManager->onNewAudioModulesAvailable(); |
| 93 | } |
| 94 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 95 | Status AudioPolicyService::setDeviceConnectionState( |
| 96 | const media::AudioDevice& deviceAidl, |
| 97 | media::AudioPolicyDeviceState stateAidl, |
| 98 | const std::string& deviceNameAidl, |
| 99 | media::audio::common::AudioFormat encodedFormatAidl) { |
| 100 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 101 | aidl2legacy_int32_t_audio_devices_t(deviceAidl.type)); |
| 102 | audio_policy_dev_state_t state = VALUE_OR_RETURN_BINDER_STATUS( |
| 103 | aidl2legacy_AudioPolicyDeviceState_audio_policy_dev_state_t(stateAidl)); |
| 104 | audio_format_t encodedFormat = VALUE_OR_RETURN_BINDER_STATUS( |
| 105 | aidl2legacy_AudioFormat_audio_format_t(encodedFormatAidl)); |
| 106 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 107 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 108 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 109 | } |
| 110 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 111 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 112 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 113 | if (state != AUDIO_POLICY_DEVICE_STATE_AVAILABLE && |
| 114 | state != AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 115 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | ALOGV("setDeviceConnectionState()"); |
| 119 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 120 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 121 | return binderStatusFromStatusT( |
| 122 | mAudioPolicyManager->setDeviceConnectionState(device, state, |
| 123 | deviceAidl.address.c_str(), |
| 124 | deviceNameAidl.c_str(), |
| 125 | encodedFormat)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 128 | Status AudioPolicyService::getDeviceConnectionState(const media::AudioDevice& deviceAidl, |
| 129 | media::AudioPolicyDeviceState* _aidl_return) { |
| 130 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 131 | aidl2legacy_int32_t_audio_devices_t(deviceAidl.type)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 132 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 133 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 134 | legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState( |
| 135 | AUDIO_POLICY_DEVICE_STATE_UNAVAILABLE)); |
| 136 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 137 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 138 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 139 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 140 | legacy2aidl_audio_policy_dev_state_t_AudioPolicyDeviceState( |
| 141 | mAudioPolicyManager->getDeviceConnectionState(device, |
| 142 | deviceAidl.address.c_str()))); |
| 143 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 146 | Status AudioPolicyService::handleDeviceConfigChange( |
| 147 | const media::AudioDevice& deviceAidl, |
| 148 | const std::string& deviceNameAidl, |
| 149 | media::audio::common::AudioFormat encodedFormatAidl) { |
| 150 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 151 | aidl2legacy_int32_t_audio_devices_t(deviceAidl.type)); |
| 152 | audio_format_t encodedFormat = VALUE_OR_RETURN_BINDER_STATUS( |
| 153 | aidl2legacy_AudioFormat_audio_format_t(encodedFormatAidl)); |
| 154 | |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 155 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 156 | return binderStatusFromStatusT(NO_INIT); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 157 | } |
| 158 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 159 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 160 | } |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 161 | |
| 162 | ALOGV("handleDeviceConfigChange()"); |
| 163 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 164 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 165 | return binderStatusFromStatusT( |
| 166 | mAudioPolicyManager->handleDeviceConfigChange(device, deviceAidl.address.c_str(), |
| 167 | deviceNameAidl.c_str(), encodedFormat)); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 170 | Status AudioPolicyService::setPhoneState(media::AudioMode stateAidl, int32_t uidAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 171 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 172 | audio_mode_t state = VALUE_OR_RETURN_BINDER_STATUS( |
| 173 | aidl2legacy_AudioMode_audio_mode_t(stateAidl)); |
| 174 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 175 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 176 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 177 | } |
| 178 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 179 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 180 | } |
| 181 | if (uint32_t(state) >= AUDIO_MODE_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 182 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | ALOGV("setPhoneState()"); |
| 186 | |
Eric Laurent | beb07fe | 2015-09-16 15:49:30 -0700 | [diff] [blame] | 187 | // acquire lock before calling setMode() so that setMode() + setPhoneState() are an atomic |
| 188 | // operation from policy manager standpoint (no other operation (e.g track start or stop) |
| 189 | // can be interleaved). |
| 190 | Mutex::Autolock _l(mLock); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 191 | // TODO: check if it is more appropriate to do it in platform specific policy manager |
| 192 | AudioSystem::setMode(state); |
| 193 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 194 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 195 | mAudioPolicyManager->setPhoneState(state); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 196 | mPhoneState = state; |
Eric Laurent | 00dba06 | 2020-02-11 15:52:09 -0800 | [diff] [blame] | 197 | mPhoneStateOwnerUid = uid; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 198 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 199 | } |
| 200 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 201 | Status AudioPolicyService::getPhoneState(media::AudioMode* _aidl_return) { |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 202 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 203 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_mode_t_AudioMode(mPhoneState)); |
| 204 | return Status::ok(); |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 207 | Status AudioPolicyService::setForceUse(media::AudioPolicyForceUse usageAidl, |
| 208 | media::AudioPolicyForcedConfig configAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 209 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 210 | audio_policy_force_use_t usage = VALUE_OR_RETURN_BINDER_STATUS( |
| 211 | aidl2legacy_AudioPolicyForceUse_audio_policy_force_use_t(usageAidl)); |
| 212 | audio_policy_forced_cfg_t config = VALUE_OR_RETURN_BINDER_STATUS( |
| 213 | aidl2legacy_AudioPolicyForcedConfig_audio_policy_forced_cfg_t(configAidl)); |
| 214 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 215 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 216 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 217 | } |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 218 | |
| 219 | if (!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 220 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 221 | } |
Eric Laurent | e17378d | 2018-05-09 14:43:01 -0700 | [diff] [blame] | 222 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 223 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 224 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 225 | } |
| 226 | if (config < 0 || config >= AUDIO_POLICY_FORCE_CFG_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 227 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 228 | } |
| 229 | ALOGV("setForceUse()"); |
| 230 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 231 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 232 | mAudioPolicyManager->setForceUse(usage, config); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 233 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 234 | } |
| 235 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 236 | Status AudioPolicyService::getForceUse(media::AudioPolicyForceUse usageAidl, |
| 237 | media::AudioPolicyForcedConfig* _aidl_return) { |
| 238 | audio_policy_force_use_t usage = VALUE_OR_RETURN_BINDER_STATUS( |
| 239 | aidl2legacy_AudioPolicyForceUse_audio_policy_force_use_t(usageAidl)); |
| 240 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 241 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 242 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 243 | } |
| 244 | if (usage < 0 || usage >= AUDIO_POLICY_FORCE_USE_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 245 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 246 | legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig(AUDIO_POLICY_FORCE_NONE)); |
| 247 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 248 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 249 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 250 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 251 | legacy2aidl_audio_policy_forced_cfg_t_AudioPolicyForcedConfig( |
| 252 | mAudioPolicyManager->getForceUse(usage))); |
| 253 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 254 | } |
| 255 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 256 | Status AudioPolicyService::getOutput(media::AudioStreamType streamAidl, int32_t* _aidl_return) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 257 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 258 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 259 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 260 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 261 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 262 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 263 | legacy2aidl_audio_io_handle_t_int32_t(AUDIO_IO_HANDLE_NONE)); |
| 264 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 265 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 266 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 267 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 268 | } |
| 269 | ALOGV("getOutput()"); |
| 270 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 271 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 272 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 273 | legacy2aidl_audio_io_handle_t_int32_t(mAudioPolicyManager->getOutput(stream))); |
| 274 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 277 | Status AudioPolicyService::getOutputForAttr(const media::AudioAttributesInternal& attrAidl, |
| 278 | int32_t sessionAidl, |
| 279 | int32_t pidAidl, |
| 280 | int32_t uidAidl, |
| 281 | const media::AudioConfig& configAidl, |
| 282 | int32_t flagsAidl, |
| 283 | media::GetOutputForAttrResponse* _aidl_return) |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 284 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 285 | audio_attributes_t attr = VALUE_OR_RETURN_BINDER_STATUS( |
| 286 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 287 | audio_session_t session = VALUE_OR_RETURN_BINDER_STATUS( |
| 288 | aidl2legacy_int32_t_audio_session_t(sessionAidl)); |
| 289 | audio_stream_type_t stream = AUDIO_STREAM_DEFAULT; |
| 290 | pid_t pid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_pid_t(pidAidl)); |
| 291 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 292 | audio_config_t config = VALUE_OR_RETURN_BINDER_STATUS( |
| 293 | aidl2legacy_AudioConfig_audio_config_t(configAidl)); |
| 294 | audio_output_flags_t flags = VALUE_OR_RETURN_BINDER_STATUS( |
| 295 | aidl2legacy_int32_t_audio_output_flags_t_mask(flagsAidl)); |
| 296 | audio_io_handle_t output; |
| 297 | audio_port_handle_t selectedDeviceId; |
| 298 | audio_port_handle_t portId; |
| 299 | std::vector<audio_io_handle_t> secondaryOutputs; |
| 300 | |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 301 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 302 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 303 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 304 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 305 | RETURN_IF_BINDER_ERROR( |
| 306 | binderStatusFromStatusT(AudioValidator::validateAudioAttributes(attr, "68953950"))); |
| 307 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attr.usage, pid, uid))); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 308 | |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 309 | ALOGV("%s()", __func__); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 310 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 311 | |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 312 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 313 | if (!isAudioServerOrMediaServerUid(callingUid) || uid == (uid_t)-1) { |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 314 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 315 | "%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] | 316 | uid = callingUid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 317 | } |
Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 318 | if (!mPackageManager.allowPlaybackCapture(uid)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 319 | attr.flags = static_cast<audio_flags_mask_t>(attr.flags | AUDIO_FLAG_NO_MEDIA_PROJECTION); |
Eric Laurent | 4298441 | 2019-05-09 17:57:03 -0700 | [diff] [blame] | 320 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 321 | if (((attr.flags & (AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE)) != 0) |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 322 | && !bypassInterruptionPolicyAllowed(pid, uid)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 323 | attr.flags = static_cast<audio_flags_mask_t>( |
| 324 | attr.flags & ~(AUDIO_FLAG_BYPASS_INTERRUPTION_POLICY|AUDIO_FLAG_BYPASS_MUTE)); |
Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 325 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 326 | AutoCallerClear acc; |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 327 | AudioPolicyInterface::output_type_t outputType; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 328 | status_t result = mAudioPolicyManager->getOutputForAttr(&attr, &output, session, |
| 329 | &stream, |
| 330 | uid, |
| 331 | &config, |
| 332 | &flags, &selectedDeviceId, &portId, |
| 333 | &secondaryOutputs, |
| 334 | &outputType); |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 335 | |
| 336 | // 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] | 337 | if (result == NO_ERROR) { |
| 338 | // enforce permission (if any) required for each type of input |
| 339 | switch (outputType) { |
| 340 | case AudioPolicyInterface::API_OUTPUT_LEGACY: |
| 341 | break; |
| 342 | case AudioPolicyInterface::API_OUTPUT_TELEPHONY_TX: |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 343 | if (!modifyPhoneStateAllowed(pid, uid)) { |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 344 | ALOGE("%s() permission denied: modify phone state not allowed for uid %d", |
| 345 | __func__, uid); |
| 346 | result = PERMISSION_DENIED; |
| 347 | } |
| 348 | break; |
| 349 | case AudioPolicyInterface::API_OUT_MIX_PLAYBACK: |
| 350 | if (!modifyAudioRoutingAllowed(pid, uid)) { |
| 351 | ALOGE("%s() permission denied: modify audio routing not allowed for uid %d", |
| 352 | __func__, uid); |
| 353 | result = PERMISSION_DENIED; |
| 354 | } |
| 355 | break; |
| 356 | case AudioPolicyInterface::API_OUTPUT_INVALID: |
| 357 | default: |
| 358 | LOG_ALWAYS_FATAL("%s() encountered an invalid output type %d", |
| 359 | __func__, (int)outputType); |
| 360 | } |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 361 | } |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 362 | |
| 363 | if (result == NO_ERROR) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 364 | sp<AudioPlaybackClient> client = |
| 365 | new AudioPlaybackClient(attr, output, uid, pid, session, portId, selectedDeviceId, |
| 366 | stream); |
| 367 | mAudioPlaybackClients.add(portId, client); |
| 368 | |
| 369 | _aidl_return->output = VALUE_OR_RETURN_BINDER_STATUS( |
| 370 | legacy2aidl_audio_io_handle_t_int32_t(output)); |
| 371 | _aidl_return->stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 372 | legacy2aidl_audio_stream_type_t_AudioStreamType(stream)); |
| 373 | _aidl_return->selectedDeviceId = VALUE_OR_RETURN_BINDER_STATUS( |
| 374 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 375 | _aidl_return->portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 376 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 377 | _aidl_return->secondaryOutputs = VALUE_OR_RETURN_BINDER_STATUS( |
| 378 | convertContainer<std::vector<int32_t>>(secondaryOutputs, |
| 379 | legacy2aidl_audio_io_handle_t_int32_t)); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 380 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 381 | return binderStatusFromStatusT(result); |
Jean-Michel Trivi | 5bd3f38 | 2014-06-13 16:06:54 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 384 | void AudioPolicyService::getPlaybackClientAndEffects(audio_port_handle_t portId, |
| 385 | sp<AudioPlaybackClient>& client, |
| 386 | sp<AudioPolicyEffects>& effects, |
| 387 | const char *context) |
| 388 | { |
| 389 | Mutex::Autolock _l(mLock); |
| 390 | const ssize_t index = mAudioPlaybackClients.indexOfKey(portId); |
| 391 | if (index < 0) { |
| 392 | ALOGE("%s AudioTrack client not found for portId %d", context, portId); |
| 393 | return; |
| 394 | } |
| 395 | client = mAudioPlaybackClients.valueAt(index); |
| 396 | effects = mAudioPolicyEffects; |
| 397 | } |
| 398 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 399 | Status AudioPolicyService::startOutput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 400 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 401 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 402 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 403 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 404 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 405 | } |
| 406 | ALOGV("startOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 407 | sp<AudioPlaybackClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 408 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 409 | |
| 410 | getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__); |
| 411 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 412 | if (audioPolicyEffects != 0) { |
| 413 | // create audio processors according to stream |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 414 | status_t status = audioPolicyEffects->addOutputSessionEffects( |
| 415 | client->io, client->stream, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 416 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 417 | ALOGW("Failed to add effects on session %d", client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 421 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 422 | status_t status = mAudioPolicyManager->startOutput(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 423 | if (status == NO_ERROR) { |
| 424 | client->active = true; |
| 425 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 426 | return binderStatusFromStatusT(status); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 427 | } |
| 428 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 429 | Status AudioPolicyService::stopOutput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 430 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 431 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 432 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 433 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 434 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 435 | } |
| 436 | ALOGV("stopOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 437 | mOutputCommandThread->stopOutputCommand(portId); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 438 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 439 | } |
| 440 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 441 | status_t AudioPolicyService::doStopOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 442 | { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 443 | ALOGV("doStopOutput"); |
| 444 | sp<AudioPlaybackClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 445 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 446 | |
Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 447 | getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__); |
| 448 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 449 | if (audioPolicyEffects != 0) { |
| 450 | // release audio processors from the stream |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 451 | status_t status = audioPolicyEffects->releaseOutputSessionEffects( |
| 452 | client->io, client->stream, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 453 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 454 | ALOGW("Failed to release effects on session %d", client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 458 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 459 | status_t status = mAudioPolicyManager->stopOutput(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 460 | if (status == NO_ERROR) { |
| 461 | client->active = false; |
| 462 | } |
| 463 | return status; |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 464 | } |
| 465 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 466 | Status AudioPolicyService::releaseOutput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 467 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 468 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 469 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 470 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 471 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 472 | } |
| 473 | ALOGV("releaseOutput()"); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 474 | mOutputCommandThread->releaseOutputCommand(portId); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 475 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 476 | } |
| 477 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 478 | void AudioPolicyService::doReleaseOutput(audio_port_handle_t portId) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 479 | { |
| 480 | ALOGV("doReleaseOutput from tid %d", gettid()); |
Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 481 | sp<AudioPlaybackClient> client; |
| 482 | sp<AudioPolicyEffects> audioPolicyEffects; |
| 483 | |
| 484 | getPlaybackClientAndEffects(portId, client, audioPolicyEffects, __func__); |
| 485 | |
| 486 | if (audioPolicyEffects != 0 && client->active) { |
| 487 | // clean up effects if output was not stopped before being released |
| 488 | audioPolicyEffects->releaseOutputSessionEffects( |
| 489 | client->io, client->stream, client->session); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 490 | } |
Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 491 | Mutex::Autolock _l(mLock); |
Eric Laurent | d400724 | 2019-03-27 12:42:16 -0700 | [diff] [blame] | 492 | mAudioPlaybackClients.removeItem(portId); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 493 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 494 | // called from internal thread: no need to clear caller identity |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 495 | mAudioPolicyManager->releaseOutput(portId); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 496 | } |
| 497 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 498 | Status AudioPolicyService::getInputForAttr(const media::AudioAttributesInternal& attrAidl, |
| 499 | int32_t inputAidl, |
| 500 | int32_t riidAidl, |
| 501 | int32_t sessionAidl, |
| 502 | int32_t pidAidl, |
| 503 | int32_t uidAidl, |
| 504 | const std::string& opPackageNameAidl, |
| 505 | const media::AudioConfigBase& configAidl, |
| 506 | int32_t flagsAidl, |
| 507 | media::GetInputForAttrResponse* _aidl_return) { |
| 508 | audio_attributes_t attr = VALUE_OR_RETURN_BINDER_STATUS( |
| 509 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 510 | audio_io_handle_t input = VALUE_OR_RETURN_BINDER_STATUS( |
| 511 | aidl2legacy_int32_t_audio_io_handle_t(inputAidl)); |
| 512 | audio_unique_id_t riid = VALUE_OR_RETURN_BINDER_STATUS( |
| 513 | aidl2legacy_int32_t_audio_unique_id_t(riidAidl)); |
| 514 | audio_session_t session = VALUE_OR_RETURN_BINDER_STATUS( |
| 515 | aidl2legacy_int32_t_audio_session_t(sessionAidl)); |
| 516 | pid_t pid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_pid_t(pidAidl)); |
| 517 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 518 | String16 opPackageName = VALUE_OR_RETURN_BINDER_STATUS( |
| 519 | aidl2legacy_string_view_String16(opPackageNameAidl)); |
| 520 | audio_config_base_t config = VALUE_OR_RETURN_BINDER_STATUS( |
| 521 | aidl2legacy_AudioConfigBase_audio_config_base_t(configAidl)); |
| 522 | audio_input_flags_t flags = VALUE_OR_RETURN_BINDER_STATUS( |
| 523 | aidl2legacy_int32_t_audio_input_flags_t_mask(flagsAidl)); |
| 524 | audio_port_handle_t selectedDeviceId; |
| 525 | audio_port_handle_t portId; |
| 526 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 527 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 528 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 529 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 530 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 531 | RETURN_IF_BINDER_ERROR( |
| 532 | binderStatusFromStatusT(AudioValidator::validateAudioAttributes(attr, "68953950"))); |
| 533 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attr.usage, pid, uid))); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 534 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 535 | audio_source_t inputSource = attr.source; |
Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 536 | if (inputSource == AUDIO_SOURCE_DEFAULT) { |
| 537 | inputSource = AUDIO_SOURCE_MIC; |
| 538 | } |
| 539 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 540 | // 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] | 541 | if ((inputSource < AUDIO_SOURCE_DEFAULT) |
| 542 | || (inputSource >= AUDIO_SOURCE_CNT |
| 543 | && inputSource != AUDIO_SOURCE_HOTWORD |
| 544 | && inputSource != AUDIO_SOURCE_FM_TUNER |
| 545 | && inputSource != AUDIO_SOURCE_ECHO_REFERENCE)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 546 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 549 | bool updatePid = (pid == -1); |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 550 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Andy Hung | 4ef19fa | 2018-05-15 19:35:29 -0700 | [diff] [blame] | 551 | if (!isAudioServerOrMediaServerUid(callingUid)) { |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 552 | ALOGW_IF(uid != (uid_t)-1 && uid != callingUid, |
Marco Nelissen | dcb346b | 2015-09-09 10:47:29 -0700 | [diff] [blame] | 553 | "%s uid %d tried to pass itself off as %d", __FUNCTION__, callingUid, uid); |
| 554 | uid = callingUid; |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 555 | updatePid = true; |
| 556 | } |
| 557 | |
| 558 | if (updatePid) { |
| 559 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Eric Laurent | 9f39f8d | 2016-05-25 12:34:48 -0700 | [diff] [blame] | 560 | ALOGW_IF(pid != (pid_t)-1 && pid != callingPid, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 561 | "%s uid %d pid %d tried to pass itself off as pid %d", |
| 562 | __func__, callingUid, callingPid, pid); |
| 563 | pid = callingPid; |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 566 | // check calling permissions. |
Hayden Gomes | b742992 | 2020-12-11 13:59:18 -0800 | [diff] [blame] | 567 | // Capturing from FM_TUNER source is controlled by captureTunerAudioInputAllowed() and |
| 568 | // captureAudioOutputAllowed() (deprecated) as this does not affect users privacy |
| 569 | // as does capturing from an actual microphone. |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 570 | if (!(recordingAllowed(opPackageName, pid, uid) || attr.source == AUDIO_SOURCE_FM_TUNER)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 571 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 572 | __func__, uid, pid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 573 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 576 | bool canCaptureOutput = captureAudioOutputAllowed(pid, uid); |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 577 | if ((inputSource == AUDIO_SOURCE_VOICE_UPLINK || |
| 578 | inputSource == AUDIO_SOURCE_VOICE_DOWNLINK || |
| 579 | inputSource == AUDIO_SOURCE_VOICE_CALL || |
Hayden Gomes | b742992 | 2020-12-11 13:59:18 -0800 | [diff] [blame] | 580 | inputSource == AUDIO_SOURCE_ECHO_REFERENCE) |
| 581 | && !canCaptureOutput) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 582 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Hayden Gomes | b742992 | 2020-12-11 13:59:18 -0800 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | if (inputSource == AUDIO_SOURCE_FM_TUNER |
| 586 | && !captureTunerAudioInputAllowed(pid, uid) |
| 587 | && !canCaptureOutput) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 588 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Nadav Bar | 744be48 | 2018-05-08 13:26:21 +0300 | [diff] [blame] | 589 | } |
| 590 | |
jiabin | 68e0df7 | 2019-03-18 17:55:35 -0700 | [diff] [blame] | 591 | bool canCaptureHotword = captureHotwordAllowed(opPackageName, pid, uid); |
Hiroaki Hayashi | 4de0b45 | 2019-07-18 19:50:47 +0900 | [diff] [blame] | 592 | if ((inputSource == AUDIO_SOURCE_HOTWORD) && !canCaptureHotword) { |
Bhalchandra Gajare | dea7f94 | 2021-01-27 17:28:30 -0800 | [diff] [blame^] | 593 | return binderStatusFromStatusT(PERMISSION_DENIED); |
| 594 | } |
| 595 | |
| 596 | if (((flags & AUDIO_INPUT_FLAG_HW_HOTWORD) != 0) |
| 597 | && !canCaptureHotword) { |
| 598 | ALOGE("%s: permission denied: hotword mode not allowed" |
| 599 | " for uid %d pid %d", __func__, uid, pid); |
| 600 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 604 | { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 605 | status_t status; |
| 606 | AudioPolicyInterface::input_type_t inputType; |
| 607 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 608 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 609 | { |
| 610 | AutoCallerClear acc; |
| 611 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 612 | status = mAudioPolicyManager->getInputForAttr(&attr, &input, riid, session, uid, |
| 613 | &config, |
| 614 | flags, &selectedDeviceId, |
| 615 | &inputType, &portId); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 616 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 617 | audioPolicyEffects = mAudioPolicyEffects; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 618 | |
| 619 | if (status == NO_ERROR) { |
| 620 | // enforce permission (if any) required for each type of input |
| 621 | switch (inputType) { |
Kevin Rocard | 25f9b05 | 2019-02-27 15:08:54 -0800 | [diff] [blame] | 622 | case AudioPolicyInterface::API_INPUT_MIX_PUBLIC_CAPTURE_PLAYBACK: |
| 623 | // this use case has been validated in audio service with a MediaProjection token, |
| 624 | // and doesn't rely on regular permissions |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 625 | case AudioPolicyInterface::API_INPUT_LEGACY: |
| 626 | break; |
Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 627 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: |
| 628 | // FIXME: use the same permission as for remote submix for now. |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 629 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 630 | if (!canCaptureOutput) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 631 | ALOGE("getInputForAttr() permission denied: capture not allowed"); |
| 632 | status = PERMISSION_DENIED; |
| 633 | } |
| 634 | break; |
| 635 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 636 | if (!modifyAudioRoutingAllowed(pid, uid)) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 637 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); |
| 638 | status = PERMISSION_DENIED; |
| 639 | } |
| 640 | break; |
| 641 | case AudioPolicyInterface::API_INPUT_INVALID: |
| 642 | default: |
| 643 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", |
| 644 | (int)inputType); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | if (status != NO_ERROR) { |
| 649 | if (status == PERMISSION_DENIED) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 650 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 651 | mAudioPolicyManager->releaseInput(portId); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 652 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 653 | return binderStatusFromStatusT(status); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 654 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 655 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 656 | sp<AudioRecordClient> client = new AudioRecordClient(attr, input, uid, pid, session, portId, |
| 657 | selectedDeviceId, opPackageName, |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 658 | canCaptureOutput, canCaptureHotword); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 659 | mAudioRecordClients.add(portId, client); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 660 | } |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 661 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 662 | if (audioPolicyEffects != 0) { |
| 663 | // create audio pre processors according to input source |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 664 | status_t status = audioPolicyEffects->addInputEffects(input, inputSource, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 665 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 666 | ALOGW("Failed to add effects on input %d", input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 667 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 668 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 669 | |
| 670 | _aidl_return->input = VALUE_OR_RETURN_BINDER_STATUS( |
| 671 | legacy2aidl_audio_io_handle_t_int32_t(input)); |
| 672 | _aidl_return->selectedDeviceId = VALUE_OR_RETURN_BINDER_STATUS( |
| 673 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 674 | _aidl_return->portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 675 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 676 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 679 | std::string AudioPolicyService::getDeviceTypeStrForPortId(audio_port_handle_t portId) { |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 680 | struct audio_port_v7 port = {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 681 | port.id = portId; |
| 682 | status_t status = mAudioPolicyManager->getAudioPort(&port); |
| 683 | if (status == NO_ERROR && port.type == AUDIO_PORT_TYPE_DEVICE) { |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 684 | return toString(port.ext.device.type); |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 685 | } |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 686 | return {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 689 | Status AudioPolicyService::startInput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 690 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 691 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 692 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 693 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 694 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 695 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 696 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 697 | sp<AudioRecordClient> client; |
| 698 | { |
| 699 | Mutex::Autolock _l(mLock); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 700 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 701 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 702 | if (index < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 703 | return binderStatusFromStatusT(INVALID_OPERATION); |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 704 | } |
| 705 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 706 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 707 | |
| 708 | // check calling permissions |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 709 | if (!(startRecording(client->opPackageName, client->pid, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 710 | client->attributes.source) |
Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 711 | || client->attributes.source == AUDIO_SOURCE_FM_TUNER)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 712 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 713 | __func__, client->uid, client->pid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 714 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 715 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 716 | |
Eric Laurent | df62892 | 2018-12-06 21:45:51 +0000 | [diff] [blame] | 717 | Mutex::Autolock _l(mLock); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 718 | |
| 719 | client->active = true; |
| 720 | client->startTimeNs = systemTime(); |
| 721 | updateUidStates_l(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 722 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 723 | status_t status; |
| 724 | { |
| 725 | AutoCallerClear acc; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 726 | status = mAudioPolicyManager->startInput(portId); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 727 | |
| 728 | } |
| 729 | |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 730 | // including successes gets very verbose |
Muhammad Qureshi | 087b37c | 2020-06-16 16:37:36 -0700 | [diff] [blame] | 731 | // but once we cut over to statsd, log them all. |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 732 | if (status != NO_ERROR) { |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 733 | |
| 734 | static constexpr char kAudioPolicy[] = "audiopolicy"; |
| 735 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 736 | static constexpr char kAudioPolicyStatus[] = "android.media.audiopolicy.status"; |
| 737 | static constexpr char kAudioPolicyRqstSrc[] = "android.media.audiopolicy.rqst.src"; |
| 738 | static constexpr char kAudioPolicyRqstPkg[] = "android.media.audiopolicy.rqst.pkg"; |
| 739 | static constexpr char kAudioPolicyRqstSession[] = "android.media.audiopolicy.rqst.session"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 740 | static constexpr char kAudioPolicyRqstDevice[] = |
| 741 | "android.media.audiopolicy.rqst.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 742 | static constexpr char kAudioPolicyActiveSrc[] = "android.media.audiopolicy.active.src"; |
| 743 | static constexpr char kAudioPolicyActivePkg[] = "android.media.audiopolicy.active.pkg"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 744 | static constexpr char kAudioPolicyActiveSession[] = |
| 745 | "android.media.audiopolicy.active.session"; |
| 746 | static constexpr char kAudioPolicyActiveDevice[] = |
| 747 | "android.media.audiopolicy.active.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 748 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 749 | mediametrics::Item *item = mediametrics::Item::create(kAudioPolicy); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 750 | if (item != NULL) { |
| 751 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 752 | item->setInt32(kAudioPolicyStatus, status); |
| 753 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 754 | item->setCString(kAudioPolicyRqstSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 755 | toString(client->attributes.source).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 756 | item->setInt32(kAudioPolicyRqstSession, client->session); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 757 | if (client->opPackageName.size() != 0) { |
| 758 | item->setCString(kAudioPolicyRqstPkg, |
| 759 | std::string(String8(client->opPackageName).string()).c_str()); |
| 760 | } else { |
Kevin Rocard | fbdfebe | 2018-06-18 12:30:40 -0700 | [diff] [blame] | 761 | item->setCString(kAudioPolicyRqstPkg, std::to_string(client->uid).c_str()); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 762 | } |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 763 | item->setCString( |
| 764 | kAudioPolicyRqstDevice, getDeviceTypeStrForPortId(client->deviceId).c_str()); |
| 765 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 766 | int count = mAudioRecordClients.size(); |
| 767 | for (int i = 0; i < count ; i++) { |
| 768 | if (portId == mAudioRecordClients.keyAt(i)) { |
| 769 | continue; |
| 770 | } |
| 771 | sp<AudioRecordClient> other = mAudioRecordClients.valueAt(i); |
| 772 | if (other->active) { |
| 773 | // keeps the last of the clients marked active |
| 774 | item->setCString(kAudioPolicyActiveSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 775 | toString(other->attributes.source).c_str()); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 776 | item->setInt32(kAudioPolicyActiveSession, other->session); |
| 777 | if (other->opPackageName.size() != 0) { |
| 778 | item->setCString(kAudioPolicyActivePkg, |
| 779 | std::string(String8(other->opPackageName).string()).c_str()); |
| 780 | } else { |
| 781 | item->setCString(kAudioPolicyRqstPkg, |
| 782 | std::to_string(other->uid).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 783 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 784 | item->setCString(kAudioPolicyActiveDevice, |
| 785 | getDeviceTypeStrForPortId(other->deviceId).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | item->selfrecord(); |
| 789 | delete item; |
| 790 | item = NULL; |
| 791 | } |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | if (status != NO_ERROR) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 795 | client->active = false; |
| 796 | client->startTimeNs = 0; |
| 797 | updateUidStates_l(); |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 798 | finishRecording(client->opPackageName, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 799 | client->attributes.source); |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 800 | } |
| 801 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 802 | return binderStatusFromStatusT(status); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 803 | } |
| 804 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 805 | Status AudioPolicyService::stopInput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 806 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 807 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 808 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 809 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 810 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 811 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 812 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 813 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 814 | Mutex::Autolock _l(mLock); |
| 815 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 816 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 817 | if (index < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 818 | return binderStatusFromStatusT(INVALID_OPERATION); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 819 | } |
| 820 | sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index); |
| 821 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 822 | client->active = false; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 823 | client->startTimeNs = 0; |
| 824 | |
| 825 | updateUidStates_l(); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 826 | |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 827 | // finish the recording app op |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 828 | finishRecording(client->opPackageName, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 829 | client->attributes.source); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 830 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 831 | return binderStatusFromStatusT(mAudioPolicyManager->stopInput(portId)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 834 | Status AudioPolicyService::releaseInput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 835 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 836 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 837 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 838 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 839 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 840 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 841 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 842 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 843 | sp<AudioRecordClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 844 | { |
| 845 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 846 | audioPolicyEffects = mAudioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 847 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 848 | if (index < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 849 | return Status::ok(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 850 | } |
| 851 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 852 | |
| 853 | if (client->active) { |
| 854 | ALOGW("%s releasing active client portId %d", __FUNCTION__, portId); |
| 855 | client->active = false; |
| 856 | client->startTimeNs = 0; |
| 857 | updateUidStates_l(); |
| 858 | } |
| 859 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 860 | mAudioRecordClients.removeItem(portId); |
| 861 | } |
| 862 | if (client == 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 863 | return Status::ok(); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 864 | } |
| 865 | if (audioPolicyEffects != 0) { |
| 866 | // release audio processors from the input |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 867 | status_t status = audioPolicyEffects->releaseInputEffects(client->io, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 868 | if(status != NO_ERROR) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 869 | ALOGW("Failed to release effects on input %d", client->io); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 870 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 871 | } |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 872 | { |
| 873 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 874 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 875 | mAudioPolicyManager->releaseInput(portId); |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 876 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 877 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 878 | } |
| 879 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 880 | Status AudioPolicyService::initStreamVolume(media::AudioStreamType streamAidl, |
| 881 | int32_t indexMinAidl, |
| 882 | int32_t indexMaxAidl) { |
| 883 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 884 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 885 | int indexMin = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexMinAidl)); |
| 886 | int indexMax = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexMaxAidl)); |
| 887 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 888 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 889 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 890 | } |
| 891 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 892 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 893 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 894 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 895 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 896 | } |
| 897 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 898 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 899 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 900 | return binderStatusFromStatusT(NO_ERROR); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 901 | } |
| 902 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 903 | Status AudioPolicyService::setStreamVolumeIndex(media::AudioStreamType streamAidl, |
| 904 | int32_t deviceAidl, int32_t indexAidl) { |
| 905 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 906 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 907 | int index = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexAidl)); |
| 908 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 909 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 910 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 911 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 912 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 913 | } |
| 914 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 915 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 916 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 917 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 918 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 919 | } |
| 920 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 921 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 922 | return binderStatusFromStatusT(mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 923 | index, |
| 924 | device)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 925 | } |
| 926 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 927 | Status AudioPolicyService::getStreamVolumeIndex(media::AudioStreamType streamAidl, |
| 928 | int32_t deviceAidl, int32_t* _aidl_return) { |
| 929 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 930 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 931 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 932 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 933 | int index; |
| 934 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 935 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 936 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 937 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 938 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 939 | return binderStatusFromStatusT(BAD_VALUE); |
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; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 943 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 944 | mAudioPolicyManager->getStreamVolumeIndex(stream, &index, device))); |
| 945 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 946 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 947 | } |
| 948 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 949 | Status AudioPolicyService::setVolumeIndexForAttributes( |
| 950 | const media::AudioAttributesInternal& attrAidl, int32_t deviceAidl, int32_t indexAidl) { |
| 951 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 952 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 953 | int index = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexAidl)); |
| 954 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 955 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 956 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 957 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 958 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 959 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 960 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 961 | } |
| 962 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 963 | return binderStatusFromStatusT(PERMISSION_DENIED); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 964 | } |
| 965 | Mutex::Autolock _l(mLock); |
| 966 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 967 | return binderStatusFromStatusT( |
| 968 | mAudioPolicyManager->setVolumeIndexForAttributes(attributes, index, device)); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 969 | } |
| 970 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 971 | Status AudioPolicyService::getVolumeIndexForAttributes( |
| 972 | const media::AudioAttributesInternal& attrAidl, int32_t deviceAidl, int32_t* _aidl_return) { |
| 973 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 974 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 975 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 976 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 977 | int index; |
| 978 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 979 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 980 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 981 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 982 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 983 | } |
| 984 | Mutex::Autolock _l(mLock); |
| 985 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 986 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 987 | mAudioPolicyManager->getVolumeIndexForAttributes(attributes, index, device))); |
| 988 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 989 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 990 | } |
| 991 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 992 | Status AudioPolicyService::getMinVolumeIndexForAttributes( |
| 993 | const media::AudioAttributesInternal& attrAidl, int32_t* _aidl_return) { |
| 994 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 995 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 996 | int index; |
| 997 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 998 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 999 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1000 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1001 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1002 | } |
| 1003 | Mutex::Autolock _l(mLock); |
| 1004 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1005 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1006 | mAudioPolicyManager->getMinVolumeIndexForAttributes(attributes, index))); |
| 1007 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 1008 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1011 | Status AudioPolicyService::getMaxVolumeIndexForAttributes( |
| 1012 | const media::AudioAttributesInternal& attrAidl, int32_t* _aidl_return) { |
| 1013 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 1014 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 1015 | int index; |
| 1016 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1017 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 1018 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1019 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1020 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1021 | } |
| 1022 | Mutex::Autolock _l(mLock); |
| 1023 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1024 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1025 | mAudioPolicyManager->getMaxVolumeIndexForAttributes(attributes, index))); |
| 1026 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 1027 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1030 | Status AudioPolicyService::getStrategyForStream(media::AudioStreamType streamAidl, |
| 1031 | int32_t* _aidl_return) { |
| 1032 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1033 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1034 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1035 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1036 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1037 | convertReinterpret<int32_t>(PRODUCT_STRATEGY_NONE)); |
| 1038 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1039 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1040 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1041 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1042 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1043 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1044 | // 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] | 1045 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1046 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1047 | legacy2aidl_product_strategy_t_int32_t( |
| 1048 | mAudioPolicyManager->getStrategyForStream(stream))); |
| 1049 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | //audio policy: use audio_device_t appropriately |
| 1053 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1054 | Status AudioPolicyService::getDevicesForStream(media::AudioStreamType streamAidl, |
| 1055 | int32_t* _aidl_return) { |
| 1056 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1057 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1058 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1059 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1060 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1061 | legacy2aidl_audio_devices_t_int32_t(AUDIO_DEVICE_NONE)); |
| 1062 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1063 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1064 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1065 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1066 | } |
Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 1067 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1068 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1069 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1070 | legacy2aidl_audio_devices_t_int32_t(mAudioPolicyManager->getDevicesForStream(stream))); |
| 1071 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1074 | Status AudioPolicyService::getDevicesForAttributes(const media::AudioAttributesEx& attrAidl, |
| 1075 | std::vector<media::AudioDevice>* _aidl_return) |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1076 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1077 | AudioAttributes aa = VALUE_OR_RETURN_BINDER_STATUS( |
| 1078 | aidl2legacy_AudioAttributesEx_AudioAttributes(attrAidl)); |
| 1079 | AudioDeviceTypeAddrVector devices; |
| 1080 | |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1081 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1082 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1083 | } |
| 1084 | Mutex::Autolock _l(mLock); |
| 1085 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1086 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1087 | mAudioPolicyManager->getDevicesForAttributes(aa.getAttributes(), &devices))); |
| 1088 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1089 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 1090 | legacy2aidl_AudioDeviceTypeAddress)); |
| 1091 | return Status::ok(); |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1092 | } |
| 1093 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1094 | Status AudioPolicyService::getOutputForEffect(const media::EffectDescriptor& descAidl, |
| 1095 | int32_t* _aidl_return) { |
| 1096 | effect_descriptor_t desc = VALUE_OR_RETURN_BINDER_STATUS( |
| 1097 | aidl2legacy_EffectDescriptor_effect_descriptor_t(descAidl)); |
| 1098 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1099 | AudioValidator::validateEffectDescriptor(desc, "73126106"))); |
| 1100 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1101 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1102 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1103 | } |
| 1104 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1105 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1106 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1107 | legacy2aidl_audio_io_handle_t_int32_t(mAudioPolicyManager->getOutputForEffect(&desc))); |
| 1108 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1109 | } |
| 1110 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1111 | Status AudioPolicyService::registerEffect(const media::EffectDescriptor& descAidl, int32_t ioAidl, |
| 1112 | int32_t strategyAidl, int32_t sessionAidl, |
| 1113 | int32_t idAidl) { |
| 1114 | effect_descriptor_t desc = VALUE_OR_RETURN_BINDER_STATUS( |
| 1115 | aidl2legacy_EffectDescriptor_effect_descriptor_t(descAidl)); |
| 1116 | audio_io_handle_t io = VALUE_OR_RETURN_BINDER_STATUS( |
| 1117 | aidl2legacy_int32_t_audio_io_handle_t(ioAidl)); |
| 1118 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 1119 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 1120 | audio_session_t session = VALUE_OR_RETURN_BINDER_STATUS( |
| 1121 | aidl2legacy_int32_t_audio_session_t(sessionAidl)); |
| 1122 | int id = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(idAidl)); |
| 1123 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1124 | AudioValidator::validateEffectDescriptor(desc, "73126106"))); |
| 1125 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1126 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1127 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1128 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1129 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1130 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1131 | return binderStatusFromStatusT( |
| 1132 | mAudioPolicyManager->registerEffect(&desc, io, strategy, session, id)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1133 | } |
| 1134 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1135 | Status AudioPolicyService::unregisterEffect(int32_t idAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1136 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1137 | int id = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(idAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1138 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1139 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1140 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1141 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1142 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1143 | return binderStatusFromStatusT(mAudioPolicyManager->unregisterEffect(id)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1144 | } |
| 1145 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1146 | Status AudioPolicyService::setEffectEnabled(int32_t idAidl, bool enabled) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1147 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1148 | int id = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(idAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1149 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1150 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1151 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1152 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1153 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1154 | return binderStatusFromStatusT(mAudioPolicyManager->setEffectEnabled(id, enabled)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1155 | } |
| 1156 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1157 | Status AudioPolicyService::moveEffectsToIo(const std::vector<int32_t>& idsAidl, int32_t ioAidl) |
| 1158 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1159 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1160 | const std::vector<int>& ids = VALUE_OR_RETURN_BINDER_STATUS( |
| 1161 | convertContainer<std::vector<int>>(idsAidl, convertReinterpret<int, int32_t>)); |
| 1162 | audio_io_handle_t io = VALUE_OR_RETURN_BINDER_STATUS( |
| 1163 | aidl2legacy_int32_t_audio_io_handle_t(ioAidl)); |
| 1164 | if (ids.size() > MAX_ITEMS_PER_LIST) { |
| 1165 | return binderStatusFromStatusT(BAD_VALUE); |
| 1166 | } |
| 1167 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1168 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1169 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1170 | } |
| 1171 | Mutex::Autolock _l(mLock); |
| 1172 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1173 | return binderStatusFromStatusT(mAudioPolicyManager->moveEffectsToIo(ids, io)); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1176 | Status AudioPolicyService::isStreamActive(media::AudioStreamType streamAidl, int32_t inPastMsAidl, |
| 1177 | bool* _aidl_return) { |
| 1178 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1179 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1180 | uint32_t inPastMs = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(inPastMsAidl)); |
| 1181 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1182 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1183 | *_aidl_return = false; |
| 1184 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1185 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1186 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1187 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1188 | } |
| 1189 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1190 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1191 | *_aidl_return = mAudioPolicyManager->isStreamActive(stream, inPastMs); |
| 1192 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1195 | Status AudioPolicyService::isStreamActiveRemotely(media::AudioStreamType streamAidl, |
| 1196 | int32_t inPastMsAidl, |
| 1197 | bool* _aidl_return) { |
| 1198 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1199 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1200 | uint32_t inPastMs = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(inPastMsAidl)); |
| 1201 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1202 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1203 | *_aidl_return = false; |
| 1204 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1205 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1206 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1207 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1208 | } |
| 1209 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1210 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1211 | *_aidl_return = mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
| 1212 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1213 | } |
| 1214 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1215 | Status AudioPolicyService::isSourceActive(media::AudioSourceType sourceAidl, bool* _aidl_return) { |
| 1216 | audio_source_t source = VALUE_OR_RETURN_BINDER_STATUS( |
| 1217 | aidl2legacy_AudioSourceType_audio_source_t(sourceAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1218 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1219 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1220 | } |
| 1221 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1222 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1223 | *_aidl_return = mAudioPolicyManager->isSourceActive(source); |
| 1224 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1227 | status_t AudioPolicyService::getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1228 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1229 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1230 | return NO_INIT; |
| 1231 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 1232 | { |
| 1233 | Mutex::Autolock _l(mLock); |
| 1234 | audioPolicyEffects = mAudioPolicyEffects; |
| 1235 | } |
| 1236 | if (audioPolicyEffects == 0) { |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 1237 | return NO_INIT; |
| 1238 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1239 | |
| 1240 | return OK; |
| 1241 | } |
| 1242 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1243 | Status AudioPolicyService::queryDefaultPreProcessing( |
| 1244 | int32_t audioSessionAidl, |
| 1245 | media::Int* countAidl, |
| 1246 | std::vector<media::EffectDescriptor>* _aidl_return) { |
| 1247 | audio_session_t audioSession = VALUE_OR_RETURN_BINDER_STATUS( |
| 1248 | aidl2legacy_int32_t_audio_session_t(audioSessionAidl)); |
| 1249 | uint32_t count = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(countAidl->value)); |
| 1250 | if (count > AudioEffect::kMaxPreProcessing) { |
| 1251 | count = AudioEffect::kMaxPreProcessing; |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1252 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1253 | uint32_t countReq = count; |
| 1254 | std::unique_ptr<effect_descriptor_t[]> descriptors(new effect_descriptor_t[count]); |
| 1255 | |
| 1256 | sp<AudioPolicyEffects> audioPolicyEffects; |
| 1257 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
| 1258 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(audioPolicyEffects->queryDefaultInputEffects( |
| 1259 | (audio_session_t) audioSession, descriptors.get(), &count))); |
| 1260 | countReq = std::min(count, countReq); |
| 1261 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1262 | convertRange(descriptors.get(), descriptors.get() + countReq, |
| 1263 | std::back_inserter(*_aidl_return), |
| 1264 | legacy2aidl_effect_descriptor_t_EffectDescriptor))); |
| 1265 | countAidl->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(count)); |
| 1266 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1267 | } |
| 1268 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1269 | Status AudioPolicyService::addSourceDefaultEffect(const media::AudioUuid& typeAidl, |
| 1270 | const std::string& opPackageNameAidl, |
| 1271 | const media::AudioUuid& uuidAidl, |
| 1272 | int32_t priority, |
| 1273 | media::AudioSourceType sourceAidl, |
| 1274 | int32_t* _aidl_return) { |
| 1275 | effect_uuid_t type = VALUE_OR_RETURN_BINDER_STATUS( |
| 1276 | aidl2legacy_AudioUuid_audio_uuid_t(typeAidl)); |
| 1277 | String16 opPackageName = VALUE_OR_RETURN_BINDER_STATUS( |
| 1278 | aidl2legacy_string_view_String16(opPackageNameAidl)); |
| 1279 | effect_uuid_t uuid = VALUE_OR_RETURN_BINDER_STATUS( |
| 1280 | aidl2legacy_AudioUuid_audio_uuid_t(uuidAidl)); |
| 1281 | audio_source_t source = VALUE_OR_RETURN_BINDER_STATUS( |
| 1282 | aidl2legacy_AudioSourceType_audio_source_t(sourceAidl)); |
| 1283 | audio_unique_id_t id; |
| 1284 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1285 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1286 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1287 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1288 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1289 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1290 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(audioPolicyEffects->addSourceDefaultEffect( |
| 1291 | &type, opPackageName, &uuid, priority, source, &id))); |
| 1292 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_unique_id_t_int32_t(id)); |
| 1293 | return Status::ok(); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1296 | Status AudioPolicyService::addStreamDefaultEffect(const media::AudioUuid& typeAidl, |
| 1297 | const std::string& opPackageNameAidl, |
| 1298 | const media::AudioUuid& uuidAidl, |
| 1299 | int32_t priority, media::AudioUsage usageAidl, |
| 1300 | int32_t* _aidl_return) { |
| 1301 | effect_uuid_t type = VALUE_OR_RETURN_BINDER_STATUS( |
| 1302 | aidl2legacy_AudioUuid_audio_uuid_t(typeAidl)); |
| 1303 | String16 opPackageName = VALUE_OR_RETURN_BINDER_STATUS( |
| 1304 | aidl2legacy_string_view_String16(opPackageNameAidl)); |
| 1305 | effect_uuid_t uuid = VALUE_OR_RETURN_BINDER_STATUS( |
| 1306 | aidl2legacy_AudioUuid_audio_uuid_t(uuidAidl)); |
| 1307 | audio_usage_t usage = VALUE_OR_RETURN_BINDER_STATUS( |
| 1308 | aidl2legacy_AudioUsage_audio_usage_t(usageAidl)); |
| 1309 | audio_unique_id_t id; |
| 1310 | |
| 1311 | sp<AudioPolicyEffects> audioPolicyEffects; |
| 1312 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1313 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1314 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1315 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1316 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(audioPolicyEffects->addStreamDefaultEffect( |
| 1317 | &type, opPackageName, &uuid, priority, usage, &id))); |
| 1318 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_unique_id_t_int32_t(id)); |
| 1319 | return Status::ok(); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1322 | Status AudioPolicyService::removeSourceDefaultEffect(int32_t idAidl) |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1323 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1324 | audio_unique_id_t id = VALUE_OR_RETURN_BINDER_STATUS( |
| 1325 | aidl2legacy_int32_t_audio_unique_id_t(idAidl)); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1326 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1327 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1328 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1329 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1330 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1331 | return binderStatusFromStatusT(audioPolicyEffects->removeSourceDefaultEffect(id)); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1334 | Status AudioPolicyService::removeStreamDefaultEffect(int32_t idAidl) |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1335 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1336 | audio_unique_id_t id = VALUE_OR_RETURN_BINDER_STATUS( |
| 1337 | aidl2legacy_int32_t_audio_unique_id_t(idAidl)); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1338 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1339 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1340 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1341 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1342 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1343 | return binderStatusFromStatusT(audioPolicyEffects->removeStreamDefaultEffect(id)); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1344 | } |
| 1345 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1346 | Status AudioPolicyService::setSupportedSystemUsages( |
| 1347 | const std::vector<media::AudioUsage>& systemUsagesAidl) { |
| 1348 | size_t size = systemUsagesAidl.size(); |
| 1349 | if (size > MAX_ITEMS_PER_LIST) { |
| 1350 | size = MAX_ITEMS_PER_LIST; |
| 1351 | } |
| 1352 | std::vector<audio_usage_t> systemUsages; |
| 1353 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1354 | convertRange(systemUsagesAidl.begin(), systemUsagesAidl.begin() + size, |
| 1355 | std::back_inserter(systemUsages), aidl2legacy_AudioUsage_audio_usage_t))); |
| 1356 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1357 | Mutex::Autolock _l(mLock); |
| 1358 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1359 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | bool areAllSystemUsages = std::all_of(begin(systemUsages), end(systemUsages), |
| 1363 | [](audio_usage_t usage) { return isSystemUsage(usage); }); |
| 1364 | if (!areAllSystemUsages) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1365 | return binderStatusFromStatusT(BAD_VALUE); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | mSupportedSystemUsages = systemUsages; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1369 | return Status::ok(); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1370 | } |
| 1371 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1372 | Status AudioPolicyService::setAllowedCapturePolicy(int32_t uidAidl, int32_t capturePolicyAidl) { |
| 1373 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 1374 | audio_flags_mask_t capturePolicy = VALUE_OR_RETURN_BINDER_STATUS( |
| 1375 | aidl2legacy_int32_t_audio_flags_mask_t_mask(capturePolicyAidl)); |
| 1376 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1377 | Mutex::Autolock _l(mLock); |
| 1378 | if (mAudioPolicyManager == NULL) { |
| 1379 | ALOGV("%s() mAudioPolicyManager == NULL", __func__); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1380 | return binderStatusFromStatusT(NO_INIT); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1381 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1382 | return binderStatusFromStatusT( |
| 1383 | mAudioPolicyManager->setAllowedCapturePolicy(uid, capturePolicy)); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1386 | Status AudioPolicyService::getOffloadSupport(const media::AudioOffloadInfo& infoAidl, |
| 1387 | media::AudioOffloadMode* _aidl_return) { |
| 1388 | audio_offload_info_t info = VALUE_OR_RETURN_BINDER_STATUS( |
| 1389 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(infoAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1390 | if (mAudioPolicyManager == NULL) { |
| 1391 | ALOGV("mAudioPolicyManager == NULL"); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1392 | return binderStatusFromStatusT(AUDIO_OFFLOAD_NOT_SUPPORTED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1393 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1394 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1395 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1396 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_offload_mode_t_AudioOffloadMode( |
| 1397 | mAudioPolicyManager->getOffloadSupport(info))); |
| 1398 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1401 | Status AudioPolicyService::isDirectOutputSupported( |
| 1402 | const media::AudioConfigBase& configAidl, |
| 1403 | const media::AudioAttributesInternal& attributesAidl, |
| 1404 | bool* _aidl_return) { |
| 1405 | audio_config_base_t config = VALUE_OR_RETURN_BINDER_STATUS( |
| 1406 | aidl2legacy_AudioConfigBase_audio_config_base_t(configAidl)); |
| 1407 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 1408 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attributesAidl)); |
| 1409 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1410 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 1411 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1412 | if (mAudioPolicyManager == NULL) { |
| 1413 | ALOGV("mAudioPolicyManager == NULL"); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1414 | return binderStatusFromStatusT(NO_INIT); |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1415 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1416 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1417 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attributes.usage))); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1418 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1419 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1420 | *_aidl_return = mAudioPolicyManager->isDirectOutputSupported(config, attributes); |
| 1421 | return Status::ok(); |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1425 | Status AudioPolicyService::listAudioPorts(media::AudioPortRole roleAidl, |
| 1426 | media::AudioPortType typeAidl, media::Int* count, |
| 1427 | std::vector<media::AudioPort>* portsAidl, |
| 1428 | int32_t* _aidl_return) { |
| 1429 | audio_port_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 1430 | aidl2legacy_AudioPortRole_audio_port_role_t(roleAidl)); |
| 1431 | audio_port_type_t type = VALUE_OR_RETURN_BINDER_STATUS( |
| 1432 | aidl2legacy_AudioPortType_audio_port_type_t(typeAidl)); |
| 1433 | unsigned int num_ports = VALUE_OR_RETURN_BINDER_STATUS( |
| 1434 | convertIntegral<unsigned int>(count->value)); |
| 1435 | if (num_ports > MAX_ITEMS_PER_LIST) { |
| 1436 | num_ports = MAX_ITEMS_PER_LIST; |
| 1437 | } |
| 1438 | unsigned int numPortsReq = num_ports; |
| 1439 | std::unique_ptr<audio_port_v7[]> ports(new audio_port_v7[num_ports]); |
| 1440 | unsigned int generation; |
| 1441 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1442 | Mutex::Autolock _l(mLock); |
| 1443 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1444 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1445 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1446 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1447 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1448 | mAudioPolicyManager->listAudioPorts(role, type, &num_ports, ports.get(), &generation))); |
| 1449 | numPortsReq = std::min(numPortsReq, num_ports); |
| 1450 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1451 | convertRange(ports.get(), ports.get() + numPortsReq, std::back_inserter(*portsAidl), |
| 1452 | legacy2aidl_audio_port_v7_AudioPort))); |
| 1453 | count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(num_ports)); |
| 1454 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(generation)); |
| 1455 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1458 | Status AudioPolicyService::getAudioPort(const media::AudioPort& portAidl, |
| 1459 | media::AudioPort* _aidl_return) { |
| 1460 | audio_port_v7 port = VALUE_OR_RETURN_BINDER_STATUS( |
| 1461 | aidl2legacy_AudioPort_audio_port_v7(portAidl)); |
| 1462 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(AudioValidator::validateAudioPort(port))); |
| 1463 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1464 | Mutex::Autolock _l(mLock); |
| 1465 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1466 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1467 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1468 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1469 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(mAudioPolicyManager->getAudioPort(&port))); |
| 1470 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_port_v7_AudioPort(port)); |
| 1471 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1474 | Status AudioPolicyService::createAudioPatch(const media::AudioPatch& patchAidl, int32_t handleAidl, |
| 1475 | int32_t* _aidl_return) { |
| 1476 | audio_patch patch = VALUE_OR_RETURN_BINDER_STATUS( |
| 1477 | aidl2legacy_AudioPatch_audio_patch(patchAidl)); |
| 1478 | audio_patch_handle_t handle = VALUE_OR_RETURN_BINDER_STATUS( |
| 1479 | aidl2legacy_int32_t_audio_port_handle_t(handleAidl)); |
| 1480 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(AudioValidator::validateAudioPatch(patch))); |
| 1481 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1482 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1483 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1484 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1485 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1486 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1487 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1488 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1489 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1490 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1491 | mAudioPolicyManager->createAudioPatch(&patch, &handle, |
| 1492 | IPCThreadState::self()->getCallingUid()))); |
| 1493 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle)); |
| 1494 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1495 | } |
| 1496 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1497 | Status AudioPolicyService::releaseAudioPatch(int32_t handleAidl) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1498 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1499 | audio_patch_handle_t handle = VALUE_OR_RETURN_BINDER_STATUS( |
| 1500 | aidl2legacy_int32_t_audio_patch_handle_t(handleAidl)); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1501 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1502 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1503 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1504 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1505 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1506 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1507 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1508 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1509 | return binderStatusFromStatusT( |
| 1510 | mAudioPolicyManager->releaseAudioPatch(handle, |
| 1511 | IPCThreadState::self()->getCallingUid())); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1512 | } |
| 1513 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1514 | Status AudioPolicyService::listAudioPatches(media::Int* count, |
| 1515 | std::vector<media::AudioPatch>* patchesAidl, |
| 1516 | int32_t* _aidl_return) { |
| 1517 | unsigned int num_patches = VALUE_OR_RETURN_BINDER_STATUS( |
| 1518 | convertIntegral<unsigned int>(count->value)); |
| 1519 | if (num_patches > MAX_ITEMS_PER_LIST) { |
| 1520 | num_patches = MAX_ITEMS_PER_LIST; |
| 1521 | } |
| 1522 | unsigned int numPatchesReq = num_patches; |
| 1523 | std::unique_ptr<audio_patch[]> patches(new audio_patch[num_patches]); |
| 1524 | unsigned int generation; |
| 1525 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1526 | Mutex::Autolock _l(mLock); |
| 1527 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1528 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1529 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1530 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1531 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1532 | mAudioPolicyManager->listAudioPatches(&num_patches, patches.get(), &generation))); |
| 1533 | numPatchesReq = std::min(numPatchesReq, num_patches); |
| 1534 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1535 | convertRange(patches.get(), patches.get() + numPatchesReq, |
| 1536 | std::back_inserter(*patchesAidl), legacy2aidl_audio_patch_AudioPatch))); |
| 1537 | count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(num_patches)); |
| 1538 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(generation)); |
| 1539 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1542 | Status AudioPolicyService::setAudioPortConfig(const media::AudioPortConfig& configAidl) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1543 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1544 | audio_port_config config = VALUE_OR_RETURN_BINDER_STATUS( |
| 1545 | aidl2legacy_AudioPortConfig_audio_port_config(configAidl)); |
| 1546 | RETURN_IF_BINDER_ERROR( |
| 1547 | binderStatusFromStatusT(AudioValidator::validateAudioPortConfig(config))); |
| 1548 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1549 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1550 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1551 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1552 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1553 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1554 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1555 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1556 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1557 | return binderStatusFromStatusT(mAudioPolicyManager->setAudioPortConfig(&config)); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1558 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1559 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1560 | Status AudioPolicyService::acquireSoundTriggerSession(media::SoundTriggerSession* _aidl_return) |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1561 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1562 | audio_session_t session; |
| 1563 | audio_io_handle_t ioHandle; |
| 1564 | audio_devices_t device; |
| 1565 | |
| 1566 | { |
| 1567 | Mutex::Autolock _l(mLock); |
| 1568 | if (mAudioPolicyManager == NULL) { |
| 1569 | return binderStatusFromStatusT(NO_INIT); |
| 1570 | } |
| 1571 | AutoCallerClear acc; |
| 1572 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1573 | mAudioPolicyManager->acquireSoundTriggerSession(&session, &ioHandle, &device))); |
| 1574 | } |
| 1575 | |
| 1576 | _aidl_return->session = VALUE_OR_RETURN_BINDER_STATUS( |
| 1577 | legacy2aidl_audio_session_t_int32_t(session)); |
| 1578 | _aidl_return->ioHandle = VALUE_OR_RETURN_BINDER_STATUS( |
| 1579 | legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 1580 | _aidl_return->device = VALUE_OR_RETURN_BINDER_STATUS( |
| 1581 | legacy2aidl_audio_devices_t_int32_t(device)); |
| 1582 | return Status::ok(); |
| 1583 | } |
| 1584 | |
| 1585 | Status AudioPolicyService::releaseSoundTriggerSession(int32_t sessionAidl) |
| 1586 | { |
| 1587 | audio_session_t session = VALUE_OR_RETURN_BINDER_STATUS( |
| 1588 | aidl2legacy_int32_t_audio_session_t(sessionAidl)); |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1589 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1590 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1591 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1592 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1593 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1594 | return binderStatusFromStatusT(mAudioPolicyManager->releaseSoundTriggerSession(session)); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1595 | } |
| 1596 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1597 | Status AudioPolicyService::registerPolicyMixes(const std::vector<media::AudioMix>& mixesAidl, |
| 1598 | bool registration) { |
| 1599 | size_t size = mixesAidl.size(); |
| 1600 | if (size > MAX_MIXES_PER_POLICY) { |
| 1601 | size = MAX_MIXES_PER_POLICY; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1602 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1603 | Vector<AudioMix> mixes; |
| 1604 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1605 | convertRange(mixesAidl.begin(), mixesAidl.begin() + size, std::back_inserter(mixes), |
| 1606 | aidl2legacy_AudioMix))); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1607 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1608 | Mutex::Autolock _l(mLock); |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1609 | |
| 1610 | // loopback|render only need a MediaProjection (checked in caller AudioService.java) |
| 1611 | bool needModifyAudioRouting = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
| 1612 | return !is_mix_loopback_render(mix.mRouteFlags); }); |
| 1613 | if (needModifyAudioRouting && !modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1614 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1615 | } |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1616 | |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1617 | // If one of the mixes has needCaptureVoiceCommunicationOutput set to true, then we |
| 1618 | // need to verify that the caller still has CAPTURE_VOICE_COMMUNICATION_OUTPUT |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1619 | bool needCaptureVoiceCommunicationOutput = |
| 1620 | std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1621 | return mix.mVoiceCommunicationCaptureAllowed; }); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1622 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1623 | bool needCaptureMediaOutput = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
Eric Laurent | 5f9a645 | 2020-12-22 20:10:10 +0100 | [diff] [blame] | 1624 | return mix.mAllowPrivilegedMediaPlaybackCapture; }); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1625 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1626 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
| 1627 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1628 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1629 | if (needCaptureMediaOutput && !captureMediaOutputAllowed(callingPid, callingUid)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1630 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1631 | } |
| 1632 | |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1633 | if (needCaptureVoiceCommunicationOutput && |
| 1634 | !captureVoiceCommunicationOutputAllowed(callingPid, callingUid)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1635 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1638 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1639 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1640 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1641 | AutoCallerClear acc; |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1642 | if (registration) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1643 | return binderStatusFromStatusT(mAudioPolicyManager->registerPolicyMixes(mixes)); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1644 | } else { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1645 | return binderStatusFromStatusT(mAudioPolicyManager->unregisterPolicyMixes(mixes)); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1646 | } |
| 1647 | } |
| 1648 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1649 | Status AudioPolicyService::setUidDeviceAffinities( |
| 1650 | int32_t uidAidl, |
| 1651 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 1652 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 1653 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 1654 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 1655 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1656 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1657 | Mutex::Autolock _l(mLock); |
| 1658 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1659 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1660 | } |
| 1661 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1662 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1663 | } |
| 1664 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1665 | return binderStatusFromStatusT(mAudioPolicyManager->setUidDeviceAffinities(uid, devices)); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1666 | } |
| 1667 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1668 | Status AudioPolicyService::removeUidDeviceAffinities(int32_t uidAidl) { |
| 1669 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 1670 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1671 | Mutex::Autolock _l(mLock); |
| 1672 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1673 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1674 | } |
| 1675 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1676 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1677 | } |
| 1678 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1679 | return binderStatusFromStatusT(mAudioPolicyManager->removeUidDeviceAffinities(uid)); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1680 | } |
| 1681 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1682 | Status AudioPolicyService::setUserIdDeviceAffinities( |
| 1683 | int32_t userIdAidl, |
| 1684 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 1685 | int userId = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(userIdAidl)); |
| 1686 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 1687 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 1688 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1689 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1690 | Mutex::Autolock _l(mLock); |
| 1691 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1692 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1693 | } |
| 1694 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1695 | return binderStatusFromStatusT(NO_INIT); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1696 | } |
| 1697 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1698 | return binderStatusFromStatusT(mAudioPolicyManager->setUserIdDeviceAffinities(userId, devices)); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1699 | } |
| 1700 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1701 | Status AudioPolicyService::removeUserIdDeviceAffinities(int32_t userIdAidl) { |
| 1702 | int userId = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(userIdAidl)); |
| 1703 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1704 | Mutex::Autolock _l(mLock); |
| 1705 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1706 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1707 | } |
| 1708 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1709 | return binderStatusFromStatusT(NO_INIT); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1710 | } |
| 1711 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1712 | return binderStatusFromStatusT(mAudioPolicyManager->removeUserIdDeviceAffinities(userId)); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1713 | } |
| 1714 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1715 | Status AudioPolicyService::startAudioSource(const media::AudioPortConfig& sourceAidl, |
| 1716 | const media::AudioAttributesInternal& attributesAidl, |
| 1717 | int32_t* _aidl_return) { |
| 1718 | audio_port_config source = VALUE_OR_RETURN_BINDER_STATUS( |
| 1719 | aidl2legacy_AudioPortConfig_audio_port_config(sourceAidl)); |
| 1720 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 1721 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attributesAidl)); |
| 1722 | audio_port_handle_t portId; |
| 1723 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1724 | AudioValidator::validateAudioPortConfig(source))); |
| 1725 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1726 | AudioValidator::validateAudioAttributes(attributes, "68953950"))); |
| 1727 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1728 | Mutex::Autolock _l(mLock); |
| 1729 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1730 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1731 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1732 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1733 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attributes.usage))); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1734 | |
Hongwei Wang | 5cd1f1d | 2019-03-26 15:21:11 -0700 | [diff] [blame] | 1735 | // startAudioSource should be created as the calling uid |
| 1736 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1737 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1738 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1739 | mAudioPolicyManager->startAudioSource(&source, &attributes, &portId, callingUid))); |
| 1740 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1741 | return Status::ok(); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1742 | } |
| 1743 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1744 | Status AudioPolicyService::stopAudioSource(int32_t portIdAidl) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1745 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1746 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 1747 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 1748 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1749 | Mutex::Autolock _l(mLock); |
| 1750 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1751 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1752 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1753 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1754 | return binderStatusFromStatusT(mAudioPolicyManager->stopAudioSource(portId)); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1757 | Status AudioPolicyService::setMasterMono(bool mono) |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1758 | { |
| 1759 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1760 | return binderStatusFromStatusT(NO_INIT); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1761 | } |
| 1762 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1763 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1764 | } |
| 1765 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1766 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1767 | return binderStatusFromStatusT(mAudioPolicyManager->setMasterMono(mono)); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1768 | } |
| 1769 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1770 | Status AudioPolicyService::getMasterMono(bool* _aidl_return) |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1771 | { |
| 1772 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1773 | return binderStatusFromStatusT(NO_INIT); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1774 | } |
| 1775 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1776 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1777 | return binderStatusFromStatusT(mAudioPolicyManager->getMasterMono(_aidl_return)); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1778 | } |
| 1779 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1780 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1781 | Status AudioPolicyService::getStreamVolumeDB(media::AudioStreamType streamAidl, int32_t indexAidl, |
| 1782 | int32_t deviceAidl, float* _aidl_return) { |
| 1783 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1784 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1785 | int index = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexAidl)); |
| 1786 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 1787 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 1788 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1789 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1790 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1791 | } |
| 1792 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1793 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1794 | *_aidl_return = mAudioPolicyManager->getStreamVolumeDB(stream, index, device); |
| 1795 | return Status::ok(); |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1796 | } |
| 1797 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1798 | Status AudioPolicyService::getSurroundFormats( |
| 1799 | bool reported, media::Int* count, |
| 1800 | std::vector<media::audio::common::AudioFormat>* formats, |
| 1801 | bool* _aidl_return) { |
| 1802 | unsigned int numSurroundFormats = VALUE_OR_RETURN_BINDER_STATUS( |
| 1803 | convertIntegral<unsigned int>(count->value)); |
| 1804 | if (numSurroundFormats > MAX_ITEMS_PER_LIST) { |
| 1805 | numSurroundFormats = MAX_ITEMS_PER_LIST; |
| 1806 | } |
| 1807 | unsigned int numSurroundFormatsReq = numSurroundFormats; |
| 1808 | std::unique_ptr<audio_format_t[]>surroundFormats(new audio_format_t[numSurroundFormats]); |
| 1809 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1810 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1811 | return binderStatusFromStatusT(NO_INIT); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1812 | } |
| 1813 | Mutex::Autolock _l(mLock); |
| 1814 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1815 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1816 | mAudioPolicyManager->getSurroundFormats(&numSurroundFormats, surroundFormats.get(), |
| 1817 | _aidl_return, reported))); |
| 1818 | numSurroundFormatsReq = std::min(numSurroundFormats, numSurroundFormatsReq); |
| 1819 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1820 | convertRange(surroundFormats.get(), surroundFormats.get() + numSurroundFormatsReq, |
| 1821 | std::back_inserter(*formats), legacy2aidl_audio_format_t_AudioFormat))); |
| 1822 | count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(numSurroundFormats)); |
| 1823 | return Status::ok(); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1824 | } |
| 1825 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1826 | Status AudioPolicyService::getHwOffloadEncodingFormatsSupportedForA2DP( |
| 1827 | std::vector<media::audio::common::AudioFormat>* _aidl_return) { |
| 1828 | std::vector<audio_format_t> formats; |
| 1829 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1830 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1831 | return binderStatusFromStatusT(NO_INIT); |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1832 | } |
| 1833 | Mutex::Autolock _l(mLock); |
| 1834 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1835 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1836 | mAudioPolicyManager->getHwOffloadEncodingFormatsSupportedForA2DP(&formats))); |
| 1837 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1838 | convertContainer<std::vector<media::audio::common::AudioFormat>>( |
| 1839 | formats, |
| 1840 | legacy2aidl_audio_format_t_AudioFormat)); |
| 1841 | return Status::ok(); |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1842 | } |
| 1843 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1844 | Status AudioPolicyService::setSurroundFormatEnabled( |
| 1845 | media::audio::common::AudioFormat audioFormatAidl, bool enabled) { |
| 1846 | audio_format_t audioFormat = VALUE_OR_RETURN_BINDER_STATUS( |
| 1847 | aidl2legacy_AudioFormat_audio_format_t(audioFormatAidl)); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1848 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1849 | return binderStatusFromStatusT(NO_INIT); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1850 | } |
| 1851 | Mutex::Autolock _l(mLock); |
| 1852 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1853 | return binderStatusFromStatusT( |
| 1854 | mAudioPolicyManager->setSurroundFormatEnabled(audioFormat, enabled)); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1855 | } |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1856 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1857 | Status AudioPolicyService::setAssistantUid(int32_t uidAidl) |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1858 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1859 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1860 | Mutex::Autolock _l(mLock); |
| 1861 | mUidPolicy->setAssistantUid(uid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1862 | return Status::ok(); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1865 | Status AudioPolicyService::setA11yServicesUids(const std::vector<int32_t>& uidsAidl) |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1866 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1867 | size_t size = uidsAidl.size(); |
| 1868 | if (size > MAX_ITEMS_PER_LIST) { |
| 1869 | size = MAX_ITEMS_PER_LIST; |
| 1870 | } |
| 1871 | std::vector<uid_t> uids; |
| 1872 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1873 | convertRange(uidsAidl.begin(), |
| 1874 | uidsAidl.begin() + size, |
| 1875 | std::back_inserter(uids), |
| 1876 | aidl2legacy_int32_t_uid_t))); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1877 | Mutex::Autolock _l(mLock); |
| 1878 | mUidPolicy->setA11yUids(uids); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1879 | return Status::ok(); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1882 | Status AudioPolicyService::setCurrentImeUid(int32_t uidAidl) |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1883 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1884 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1885 | Mutex::Autolock _l(mLock); |
| 1886 | mUidPolicy->setCurrentImeUid(uid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1887 | return Status::ok(); |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1888 | } |
| 1889 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1890 | Status AudioPolicyService::isHapticPlaybackSupported(bool* _aidl_return) |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1891 | { |
| 1892 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1893 | return binderStatusFromStatusT(NO_INIT); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1894 | } |
| 1895 | Mutex::Autolock _l(mLock); |
| 1896 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1897 | *_aidl_return = mAudioPolicyManager->isHapticPlaybackSupported(); |
| 1898 | return Status::ok(); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1901 | Status AudioPolicyService::listAudioProductStrategies( |
| 1902 | std::vector<media::AudioProductStrategy>* _aidl_return) { |
| 1903 | AudioProductStrategyVector strategies; |
| 1904 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1905 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1906 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1907 | } |
| 1908 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1909 | RETURN_IF_BINDER_ERROR( |
| 1910 | binderStatusFromStatusT(mAudioPolicyManager->listAudioProductStrategies(strategies))); |
| 1911 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1912 | convertContainer<std::vector<media::AudioProductStrategy>>( |
| 1913 | strategies, |
| 1914 | legacy2aidl_AudioProductStrategy)); |
| 1915 | return Status::ok(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1916 | } |
| 1917 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1918 | Status AudioPolicyService::getProductStrategyFromAudioAttributes( |
| 1919 | const media::AudioAttributesEx& aaAidl, int32_t* _aidl_return) { |
| 1920 | AudioAttributes aa = VALUE_OR_RETURN_BINDER_STATUS( |
| 1921 | aidl2legacy_AudioAttributesEx_AudioAttributes(aaAidl)); |
| 1922 | product_strategy_t productStrategy; |
| 1923 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1924 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1925 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1926 | } |
| 1927 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1928 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1929 | mAudioPolicyManager->getProductStrategyFromAudioAttributes(aa, |
| 1930 | productStrategy))); |
| 1931 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1932 | legacy2aidl_product_strategy_t_int32_t(productStrategy)); |
| 1933 | return Status::ok(); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1934 | } |
| 1935 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1936 | Status AudioPolicyService::listAudioVolumeGroups(std::vector<media::AudioVolumeGroup>* _aidl_return) |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1937 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1938 | AudioVolumeGroupVector groups; |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1939 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1940 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1941 | } |
| 1942 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1943 | RETURN_IF_BINDER_ERROR( |
| 1944 | binderStatusFromStatusT(mAudioPolicyManager->listAudioVolumeGroups(groups))); |
| 1945 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1946 | convertContainer<std::vector<media::AudioVolumeGroup>>(groups, |
| 1947 | legacy2aidl_AudioVolumeGroup)); |
| 1948 | return Status::ok(); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1949 | } |
| 1950 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1951 | Status AudioPolicyService::getVolumeGroupFromAudioAttributes(const media::AudioAttributesEx& aaAidl, |
| 1952 | int32_t* _aidl_return) { |
| 1953 | AudioAttributes aa = VALUE_OR_RETURN_BINDER_STATUS( |
| 1954 | aidl2legacy_AudioAttributesEx_AudioAttributes(aaAidl)); |
| 1955 | volume_group_t volumeGroup; |
| 1956 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1957 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1958 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1959 | } |
| 1960 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1961 | RETURN_IF_BINDER_ERROR( |
| 1962 | binderStatusFromStatusT( |
| 1963 | mAudioPolicyManager->getVolumeGroupFromAudioAttributes(aa, volumeGroup))); |
| 1964 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_volume_group_t_int32_t(volumeGroup)); |
| 1965 | return Status::ok(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1966 | } |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1967 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1968 | Status AudioPolicyService::setRttEnabled(bool enabled) |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1969 | { |
| 1970 | Mutex::Autolock _l(mLock); |
| 1971 | mUidPolicy->setRttEnabled(enabled); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1972 | return Status::ok(); |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1973 | } |
| 1974 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1975 | Status AudioPolicyService::isCallScreenModeSupported(bool* _aidl_return) |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1976 | { |
| 1977 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1978 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1979 | } |
| 1980 | Mutex::Autolock _l(mLock); |
| 1981 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1982 | *_aidl_return = mAudioPolicyManager->isCallScreenModeSupported(); |
| 1983 | return Status::ok(); |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1984 | } |
| 1985 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1986 | Status AudioPolicyService::setDevicesRoleForStrategy( |
| 1987 | int32_t strategyAidl, |
| 1988 | media::DeviceRole roleAidl, |
| 1989 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 1990 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 1991 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 1992 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 1993 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 1994 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 1995 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 1996 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1997 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1998 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 1999 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2000 | } |
| 2001 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2002 | return binderStatusFromStatusT( |
| 2003 | mAudioPolicyManager->setDevicesRoleForStrategy(strategy, role, devices)); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2006 | Status AudioPolicyService::removeDevicesRoleForStrategy(int32_t strategyAidl, |
| 2007 | media::DeviceRole roleAidl) { |
| 2008 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2009 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 2010 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2011 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2012 | if (mAudioPolicyManager == NULL) { |
| 2013 | return binderStatusFromStatusT(NO_INIT); |
| 2014 | } |
| 2015 | Mutex::Autolock _l(mLock); |
| 2016 | return binderStatusFromStatusT( |
| 2017 | mAudioPolicyManager->removeDevicesRoleForStrategy(strategy, role)); |
| 2018 | } |
| 2019 | |
| 2020 | Status AudioPolicyService::getDevicesForRoleAndStrategy( |
| 2021 | int32_t strategyAidl, |
| 2022 | media::DeviceRole roleAidl, |
| 2023 | std::vector<media::AudioDevice>* _aidl_return) { |
| 2024 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2025 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 2026 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2027 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2028 | AudioDeviceTypeAddrVector devices; |
| 2029 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2030 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2031 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2032 | } |
| 2033 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2034 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 2035 | mAudioPolicyManager->getDevicesForRoleAndStrategy(strategy, role, devices))); |
| 2036 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 2037 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2038 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2039 | return Status::ok(); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2040 | } |
| 2041 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2042 | Status AudioPolicyService::registerSoundTriggerCaptureStateListener( |
| 2043 | const sp<media::ICaptureStateListener>& listener, bool* _aidl_return) { |
| 2044 | *_aidl_return = mCaptureStateNotifier.RegisterListener(listener); |
| 2045 | return Status::ok(); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2048 | Status AudioPolicyService::setDevicesRoleForCapturePreset( |
| 2049 | media::AudioSourceType audioSourceAidl, |
| 2050 | media::DeviceRole roleAidl, |
| 2051 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 2052 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2053 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2054 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2055 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2056 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 2057 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2058 | aidl2legacy_AudioDeviceTypeAddress)); |
Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2059 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2060 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2061 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2062 | } |
| 2063 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2064 | return binderStatusFromStatusT( |
| 2065 | mAudioPolicyManager->setDevicesRoleForCapturePreset(audioSource, role, devices)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2066 | } |
| 2067 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2068 | Status AudioPolicyService::addDevicesRoleForCapturePreset( |
| 2069 | media::AudioSourceType audioSourceAidl, |
| 2070 | media::DeviceRole roleAidl, |
| 2071 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 2072 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2073 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2074 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2075 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2076 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 2077 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2078 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2079 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2080 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2081 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2082 | } |
| 2083 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2084 | return binderStatusFromStatusT( |
| 2085 | mAudioPolicyManager->addDevicesRoleForCapturePreset(audioSource, role, devices)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2086 | } |
| 2087 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2088 | Status AudioPolicyService::removeDevicesRoleForCapturePreset( |
| 2089 | media::AudioSourceType audioSourceAidl, |
| 2090 | media::DeviceRole roleAidl, |
| 2091 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 2092 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2093 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2094 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2095 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2096 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 2097 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2098 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2099 | |
| 2100 | if (mAudioPolicyManager == nullptr) { |
| 2101 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2102 | } |
| 2103 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2104 | return binderStatusFromStatusT( |
| 2105 | mAudioPolicyManager->removeDevicesRoleForCapturePreset(audioSource, role, devices)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2106 | } |
| 2107 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2108 | Status AudioPolicyService::clearDevicesRoleForCapturePreset(media::AudioSourceType audioSourceAidl, |
| 2109 | media::DeviceRole roleAidl) { |
| 2110 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2111 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2112 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2113 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2114 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2115 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2116 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2117 | } |
| 2118 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2119 | return binderStatusFromStatusT( |
| 2120 | mAudioPolicyManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2123 | Status AudioPolicyService::getDevicesForRoleAndCapturePreset( |
| 2124 | media::AudioSourceType audioSourceAidl, |
| 2125 | media::DeviceRole roleAidl, |
| 2126 | std::vector<media::AudioDevice>* _aidl_return) { |
| 2127 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2128 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2129 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2130 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2131 | AudioDeviceTypeAddrVector devices; |
| 2132 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2133 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2134 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2135 | } |
| 2136 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 2137 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 2138 | mAudioPolicyManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices))); |
| 2139 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 2140 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2141 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2142 | return Status::ok(); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 2145 | } // namespace android |