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) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 593 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 597 | { |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 598 | status_t status; |
| 599 | AudioPolicyInterface::input_type_t inputType; |
| 600 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 601 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 602 | { |
| 603 | AutoCallerClear acc; |
| 604 | // the audio_in_acoustics_t parameter is ignored by get_input() |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 605 | status = mAudioPolicyManager->getInputForAttr(&attr, &input, riid, session, uid, |
| 606 | &config, |
| 607 | flags, &selectedDeviceId, |
| 608 | &inputType, &portId); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 609 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 610 | audioPolicyEffects = mAudioPolicyEffects; |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 611 | |
| 612 | if (status == NO_ERROR) { |
| 613 | // enforce permission (if any) required for each type of input |
| 614 | switch (inputType) { |
Kevin Rocard | 25f9b05 | 2019-02-27 15:08:54 -0800 | [diff] [blame] | 615 | case AudioPolicyInterface::API_INPUT_MIX_PUBLIC_CAPTURE_PLAYBACK: |
| 616 | // this use case has been validated in audio service with a MediaProjection token, |
| 617 | // and doesn't rely on regular permissions |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 618 | case AudioPolicyInterface::API_INPUT_LEGACY: |
| 619 | break; |
Eric Laurent | 82db269 | 2015-08-07 13:59:42 -0700 | [diff] [blame] | 620 | case AudioPolicyInterface::API_INPUT_TELEPHONY_RX: |
| 621 | // FIXME: use the same permission as for remote submix for now. |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 622 | case AudioPolicyInterface::API_INPUT_MIX_CAPTURE: |
Eric Laurent | 1ff16a7 | 2019-03-14 18:35:04 -0700 | [diff] [blame] | 623 | if (!canCaptureOutput) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 624 | ALOGE("getInputForAttr() permission denied: capture not allowed"); |
| 625 | status = PERMISSION_DENIED; |
| 626 | } |
| 627 | break; |
| 628 | case AudioPolicyInterface::API_INPUT_MIX_EXT_POLICY_REROUTE: |
Eric Laurent | 8a1095a | 2019-11-08 14:44:16 -0800 | [diff] [blame] | 629 | if (!modifyAudioRoutingAllowed(pid, uid)) { |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 630 | ALOGE("getInputForAttr() permission denied: modify audio routing not allowed"); |
| 631 | status = PERMISSION_DENIED; |
| 632 | } |
| 633 | break; |
| 634 | case AudioPolicyInterface::API_INPUT_INVALID: |
| 635 | default: |
| 636 | LOG_ALWAYS_FATAL("getInputForAttr() encountered an invalid input type %d", |
| 637 | (int)inputType); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | if (status != NO_ERROR) { |
| 642 | if (status == PERMISSION_DENIED) { |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 643 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 644 | mAudioPolicyManager->releaseInput(portId); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 645 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 646 | return binderStatusFromStatusT(status); |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 647 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 648 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 649 | sp<AudioRecordClient> client = new AudioRecordClient(attr, input, uid, pid, session, portId, |
| 650 | selectedDeviceId, opPackageName, |
Ricardo Correa | 57a3769 | 2020-03-23 17:27:25 -0700 | [diff] [blame] | 651 | canCaptureOutput, canCaptureHotword); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 652 | mAudioRecordClients.add(portId, client); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 653 | } |
Jean-Michel Trivi | 97bb33f | 2014-12-12 16:23:43 -0800 | [diff] [blame] | 654 | |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 655 | if (audioPolicyEffects != 0) { |
| 656 | // create audio pre processors according to input source |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 657 | status_t status = audioPolicyEffects->addInputEffects(input, inputSource, session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 658 | if (status != NO_ERROR && status != ALREADY_EXISTS) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 659 | ALOGW("Failed to add effects on input %d", input); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 660 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 661 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 662 | |
| 663 | _aidl_return->input = VALUE_OR_RETURN_BINDER_STATUS( |
| 664 | legacy2aidl_audio_io_handle_t_int32_t(input)); |
| 665 | _aidl_return->selectedDeviceId = VALUE_OR_RETURN_BINDER_STATUS( |
| 666 | legacy2aidl_audio_port_handle_t_int32_t(selectedDeviceId)); |
| 667 | _aidl_return->portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 668 | legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 669 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 672 | std::string AudioPolicyService::getDeviceTypeStrForPortId(audio_port_handle_t portId) { |
jiabin | 19cdba5 | 2020-11-24 11:28:58 -0800 | [diff] [blame] | 673 | struct audio_port_v7 port = {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 674 | port.id = portId; |
| 675 | status_t status = mAudioPolicyManager->getAudioPort(&port); |
| 676 | if (status == NO_ERROR && port.type == AUDIO_PORT_TYPE_DEVICE) { |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 677 | return toString(port.ext.device.type); |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 678 | } |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 679 | return {}; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 680 | } |
| 681 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 682 | Status AudioPolicyService::startInput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 683 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 684 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 685 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 686 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 687 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 688 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 689 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 690 | sp<AudioRecordClient> client; |
| 691 | { |
| 692 | Mutex::Autolock _l(mLock); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 693 | |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 694 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 695 | if (index < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 696 | return binderStatusFromStatusT(INVALID_OPERATION); |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 697 | } |
| 698 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 699 | } |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 700 | |
| 701 | // check calling permissions |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 702 | if (!(startRecording(client->opPackageName, client->pid, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 703 | client->attributes.source) |
Eric Laurent | 58a0dd8 | 2019-10-24 12:42:17 -0700 | [diff] [blame] | 704 | || client->attributes.source == AUDIO_SOURCE_FM_TUNER)) { |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 705 | ALOGE("%s permission denied: recording not allowed for uid %d pid %d", |
| 706 | __func__, client->uid, client->pid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 707 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 7dca8a8 | 2018-01-29 18:44:26 -0800 | [diff] [blame] | 708 | } |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 709 | |
Eric Laurent | df62892 | 2018-12-06 21:45:51 +0000 | [diff] [blame] | 710 | Mutex::Autolock _l(mLock); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 711 | |
| 712 | client->active = true; |
| 713 | client->startTimeNs = systemTime(); |
| 714 | updateUidStates_l(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 715 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 716 | status_t status; |
| 717 | { |
| 718 | AutoCallerClear acc; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 719 | status = mAudioPolicyManager->startInput(portId); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 720 | |
| 721 | } |
| 722 | |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 723 | // including successes gets very verbose |
Muhammad Qureshi | 087b37c | 2020-06-16 16:37:36 -0700 | [diff] [blame] | 724 | // but once we cut over to statsd, log them all. |
Ray Essick | f6a57cd | 2018-05-22 16:20:54 -0700 | [diff] [blame] | 725 | if (status != NO_ERROR) { |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 726 | |
| 727 | static constexpr char kAudioPolicy[] = "audiopolicy"; |
| 728 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 729 | static constexpr char kAudioPolicyStatus[] = "android.media.audiopolicy.status"; |
| 730 | static constexpr char kAudioPolicyRqstSrc[] = "android.media.audiopolicy.rqst.src"; |
| 731 | static constexpr char kAudioPolicyRqstPkg[] = "android.media.audiopolicy.rqst.pkg"; |
| 732 | static constexpr char kAudioPolicyRqstSession[] = "android.media.audiopolicy.rqst.session"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 733 | static constexpr char kAudioPolicyRqstDevice[] = |
| 734 | "android.media.audiopolicy.rqst.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 735 | static constexpr char kAudioPolicyActiveSrc[] = "android.media.audiopolicy.active.src"; |
| 736 | static constexpr char kAudioPolicyActivePkg[] = "android.media.audiopolicy.active.pkg"; |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 737 | static constexpr char kAudioPolicyActiveSession[] = |
| 738 | "android.media.audiopolicy.active.session"; |
| 739 | static constexpr char kAudioPolicyActiveDevice[] = |
| 740 | "android.media.audiopolicy.active.device"; |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 741 | |
Ray Essick | f27e987 | 2019-12-07 06:28:46 -0800 | [diff] [blame] | 742 | mediametrics::Item *item = mediametrics::Item::create(kAudioPolicy); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 743 | if (item != NULL) { |
| 744 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 745 | item->setInt32(kAudioPolicyStatus, status); |
| 746 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 747 | item->setCString(kAudioPolicyRqstSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 748 | toString(client->attributes.source).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 749 | item->setInt32(kAudioPolicyRqstSession, client->session); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 750 | if (client->opPackageName.size() != 0) { |
| 751 | item->setCString(kAudioPolicyRqstPkg, |
| 752 | std::string(String8(client->opPackageName).string()).c_str()); |
| 753 | } else { |
Kevin Rocard | fbdfebe | 2018-06-18 12:30:40 -0700 | [diff] [blame] | 754 | item->setCString(kAudioPolicyRqstPkg, std::to_string(client->uid).c_str()); |
Ray Essick | 5186695 | 2018-05-30 11:22:27 -0700 | [diff] [blame] | 755 | } |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 756 | item->setCString( |
| 757 | kAudioPolicyRqstDevice, getDeviceTypeStrForPortId(client->deviceId).c_str()); |
| 758 | |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 759 | int count = mAudioRecordClients.size(); |
| 760 | for (int i = 0; i < count ; i++) { |
| 761 | if (portId == mAudioRecordClients.keyAt(i)) { |
| 762 | continue; |
| 763 | } |
| 764 | sp<AudioRecordClient> other = mAudioRecordClients.valueAt(i); |
| 765 | if (other->active) { |
| 766 | // keeps the last of the clients marked active |
| 767 | item->setCString(kAudioPolicyActiveSrc, |
Andy Hung | 9b18195 | 2019-02-25 14:53:36 -0800 | [diff] [blame] | 768 | toString(other->attributes.source).c_str()); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 769 | item->setInt32(kAudioPolicyActiveSession, other->session); |
| 770 | if (other->opPackageName.size() != 0) { |
| 771 | item->setCString(kAudioPolicyActivePkg, |
| 772 | std::string(String8(other->opPackageName).string()).c_str()); |
| 773 | } else { |
| 774 | item->setCString(kAudioPolicyRqstPkg, |
| 775 | std::to_string(other->uid).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 776 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 777 | item->setCString(kAudioPolicyActiveDevice, |
| 778 | getDeviceTypeStrForPortId(other->deviceId).c_str()); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 779 | } |
| 780 | } |
| 781 | item->selfrecord(); |
| 782 | delete item; |
| 783 | item = NULL; |
| 784 | } |
Ray Essick | 6ce27e5 | 2019-02-15 10:58:05 -0800 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | if (status != NO_ERROR) { |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 788 | client->active = false; |
| 789 | client->startTimeNs = 0; |
| 790 | updateUidStates_l(); |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 791 | finishRecording(client->opPackageName, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 792 | client->attributes.source); |
Eric Laurent | fb66dd9 | 2016-01-28 18:32:03 -0800 | [diff] [blame] | 793 | } |
| 794 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 795 | return binderStatusFromStatusT(status); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 798 | Status AudioPolicyService::stopInput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 799 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 800 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 801 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 802 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 803 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 804 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 805 | } |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 806 | |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 807 | Mutex::Autolock _l(mLock); |
| 808 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 809 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 810 | if (index < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 811 | return binderStatusFromStatusT(INVALID_OPERATION); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 812 | } |
| 813 | sp<AudioRecordClient> client = mAudioRecordClients.valueAt(index); |
| 814 | |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 815 | client->active = false; |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 816 | client->startTimeNs = 0; |
| 817 | |
| 818 | updateUidStates_l(); |
Ray Essick | 84e84a5 | 2018-05-03 18:45:07 -0700 | [diff] [blame] | 819 | |
Svet Ganov | 6e64137 | 2018-03-02 09:21:30 -0800 | [diff] [blame] | 820 | // finish the recording app op |
Narayan Kamath | bf85d8b | 2020-08-20 17:19:57 +0100 | [diff] [blame] | 821 | finishRecording(client->opPackageName, client->uid, |
Nate Myren | e69cada | 2020-12-10 10:00:36 -0800 | [diff] [blame] | 822 | client->attributes.source); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 823 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 824 | return binderStatusFromStatusT(mAudioPolicyManager->stopInput(portId)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 825 | } |
| 826 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 827 | Status AudioPolicyService::releaseInput(int32_t portIdAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 828 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 829 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 830 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 831 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 832 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 833 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 834 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 835 | sp<AudioPolicyEffects>audioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 836 | sp<AudioRecordClient> client; |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 837 | { |
| 838 | Mutex::Autolock _l(mLock); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 839 | audioPolicyEffects = mAudioPolicyEffects; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 840 | ssize_t index = mAudioRecordClients.indexOfKey(portId); |
| 841 | if (index < 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 842 | return Status::ok(); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 843 | } |
| 844 | client = mAudioRecordClients.valueAt(index); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 845 | |
| 846 | if (client->active) { |
| 847 | ALOGW("%s releasing active client portId %d", __FUNCTION__, portId); |
| 848 | client->active = false; |
| 849 | client->startTimeNs = 0; |
| 850 | updateUidStates_l(); |
| 851 | } |
| 852 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 853 | mAudioRecordClients.removeItem(portId); |
| 854 | } |
| 855 | if (client == 0) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 856 | return Status::ok(); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 857 | } |
| 858 | if (audioPolicyEffects != 0) { |
| 859 | // release audio processors from the input |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 860 | status_t status = audioPolicyEffects->releaseInputEffects(client->io, client->session); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 861 | if(status != NO_ERROR) { |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 862 | ALOGW("Failed to release effects on input %d", client->io); |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 863 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 864 | } |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 865 | { |
| 866 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 867 | AutoCallerClear acc; |
Eric Laurent | 8fc147b | 2018-07-22 19:13:55 -0700 | [diff] [blame] | 868 | mAudioPolicyManager->releaseInput(portId); |
Eric Laurent | f10c709 | 2016-12-06 17:09:56 -0800 | [diff] [blame] | 869 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 870 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 871 | } |
| 872 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 873 | Status AudioPolicyService::initStreamVolume(media::AudioStreamType streamAidl, |
| 874 | int32_t indexMinAidl, |
| 875 | int32_t indexMaxAidl) { |
| 876 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 877 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 878 | int indexMin = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexMinAidl)); |
| 879 | int indexMax = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexMaxAidl)); |
| 880 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 881 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 882 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 883 | } |
| 884 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 885 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 886 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 887 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 888 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 889 | } |
| 890 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 891 | AutoCallerClear acc; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 892 | mAudioPolicyManager->initStreamVolume(stream, indexMin, indexMax); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 893 | return binderStatusFromStatusT(NO_ERROR); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 894 | } |
| 895 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 896 | Status AudioPolicyService::setStreamVolumeIndex(media::AudioStreamType streamAidl, |
| 897 | int32_t deviceAidl, int32_t indexAidl) { |
| 898 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 899 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 900 | int index = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexAidl)); |
| 901 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 902 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 903 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 904 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 905 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 906 | } |
| 907 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 908 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 909 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 910 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 911 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 912 | } |
| 913 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 914 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 915 | return binderStatusFromStatusT(mAudioPolicyManager->setStreamVolumeIndex(stream, |
| 916 | index, |
| 917 | device)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 918 | } |
| 919 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 920 | Status AudioPolicyService::getStreamVolumeIndex(media::AudioStreamType streamAidl, |
| 921 | int32_t deviceAidl, int32_t* _aidl_return) { |
| 922 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 923 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 924 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 925 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 926 | int index; |
| 927 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 928 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 929 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 930 | } |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 931 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 932 | return binderStatusFromStatusT(BAD_VALUE); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 933 | } |
| 934 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 935 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 936 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 937 | mAudioPolicyManager->getStreamVolumeIndex(stream, &index, device))); |
| 938 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 939 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 940 | } |
| 941 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 942 | Status AudioPolicyService::setVolumeIndexForAttributes( |
| 943 | const media::AudioAttributesInternal& attrAidl, int32_t deviceAidl, int32_t indexAidl) { |
| 944 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 945 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 946 | int index = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexAidl)); |
| 947 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 948 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 949 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 950 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 951 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 952 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 953 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 954 | } |
| 955 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 956 | return binderStatusFromStatusT(PERMISSION_DENIED); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 957 | } |
| 958 | Mutex::Autolock _l(mLock); |
| 959 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 960 | return binderStatusFromStatusT( |
| 961 | mAudioPolicyManager->setVolumeIndexForAttributes(attributes, index, device)); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 962 | } |
| 963 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 964 | Status AudioPolicyService::getVolumeIndexForAttributes( |
| 965 | const media::AudioAttributesInternal& attrAidl, int32_t deviceAidl, int32_t* _aidl_return) { |
| 966 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 967 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 968 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 969 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 970 | int index; |
| 971 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 972 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 973 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 974 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 975 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 976 | } |
| 977 | Mutex::Autolock _l(mLock); |
| 978 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 979 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 980 | mAudioPolicyManager->getVolumeIndexForAttributes(attributes, index, device))); |
| 981 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 982 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 983 | } |
| 984 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 985 | Status AudioPolicyService::getMinVolumeIndexForAttributes( |
| 986 | const media::AudioAttributesInternal& attrAidl, int32_t* _aidl_return) { |
| 987 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 988 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 989 | int index; |
| 990 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 991 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 992 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 993 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 994 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 995 | } |
| 996 | Mutex::Autolock _l(mLock); |
| 997 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 998 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 999 | mAudioPolicyManager->getMinVolumeIndexForAttributes(attributes, index))); |
| 1000 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 1001 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1004 | Status AudioPolicyService::getMaxVolumeIndexForAttributes( |
| 1005 | const media::AudioAttributesInternal& attrAidl, int32_t* _aidl_return) { |
| 1006 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 1007 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attrAidl)); |
| 1008 | int index; |
| 1009 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1010 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 1011 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1012 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1013 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1014 | } |
| 1015 | Mutex::Autolock _l(mLock); |
| 1016 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1017 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1018 | mAudioPolicyManager->getMaxVolumeIndexForAttributes(attributes, index))); |
| 1019 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(index)); |
| 1020 | return Status::ok(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 1021 | } |
| 1022 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1023 | Status AudioPolicyService::getStrategyForStream(media::AudioStreamType streamAidl, |
| 1024 | int32_t* _aidl_return) { |
| 1025 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1026 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1027 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1028 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1029 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1030 | convertReinterpret<int32_t>(PRODUCT_STRATEGY_NONE)); |
| 1031 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1032 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1033 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1034 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1035 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1036 | |
François Gaffie | c005e56 | 2018-11-06 15:04:49 +0100 | [diff] [blame] | 1037 | // 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] | 1038 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1039 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1040 | legacy2aidl_product_strategy_t_int32_t( |
| 1041 | mAudioPolicyManager->getStrategyForStream(stream))); |
| 1042 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | //audio policy: use audio_device_t appropriately |
| 1046 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1047 | Status AudioPolicyService::getDevicesForStream(media::AudioStreamType streamAidl, |
| 1048 | int32_t* _aidl_return) { |
| 1049 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1050 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1051 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1052 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1053 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1054 | legacy2aidl_audio_devices_t_int32_t(AUDIO_DEVICE_NONE)); |
| 1055 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1056 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1057 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1058 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1059 | } |
Haynes Mathew George | dfb9f3b | 2015-10-26 18:22:13 -0700 | [diff] [blame] | 1060 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1061 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1062 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1063 | legacy2aidl_audio_devices_t_int32_t(mAudioPolicyManager->getDevicesForStream(stream))); |
| 1064 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1065 | } |
| 1066 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1067 | Status AudioPolicyService::getDevicesForAttributes(const media::AudioAttributesEx& attrAidl, |
| 1068 | std::vector<media::AudioDevice>* _aidl_return) |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1069 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1070 | AudioAttributes aa = VALUE_OR_RETURN_BINDER_STATUS( |
| 1071 | aidl2legacy_AudioAttributesEx_AudioAttributes(attrAidl)); |
| 1072 | AudioDeviceTypeAddrVector devices; |
| 1073 | |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1074 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1075 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1076 | } |
| 1077 | Mutex::Autolock _l(mLock); |
| 1078 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1079 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1080 | mAudioPolicyManager->getDevicesForAttributes(aa.getAttributes(), &devices))); |
| 1081 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1082 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 1083 | legacy2aidl_AudioDeviceTypeAddress)); |
| 1084 | return Status::ok(); |
Jean-Michel Trivi | f41599b | 2020-01-07 14:22:08 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1087 | Status AudioPolicyService::getOutputForEffect(const media::EffectDescriptor& descAidl, |
| 1088 | int32_t* _aidl_return) { |
| 1089 | effect_descriptor_t desc = VALUE_OR_RETURN_BINDER_STATUS( |
| 1090 | aidl2legacy_EffectDescriptor_effect_descriptor_t(descAidl)); |
| 1091 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1092 | AudioValidator::validateEffectDescriptor(desc, "73126106"))); |
| 1093 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1094 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1095 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1096 | } |
| 1097 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1098 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1099 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1100 | legacy2aidl_audio_io_handle_t_int32_t(mAudioPolicyManager->getOutputForEffect(&desc))); |
| 1101 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1104 | Status AudioPolicyService::registerEffect(const media::EffectDescriptor& descAidl, int32_t ioAidl, |
| 1105 | int32_t strategyAidl, int32_t sessionAidl, |
| 1106 | int32_t idAidl) { |
| 1107 | effect_descriptor_t desc = VALUE_OR_RETURN_BINDER_STATUS( |
| 1108 | aidl2legacy_EffectDescriptor_effect_descriptor_t(descAidl)); |
| 1109 | audio_io_handle_t io = VALUE_OR_RETURN_BINDER_STATUS( |
| 1110 | aidl2legacy_int32_t_audio_io_handle_t(ioAidl)); |
| 1111 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 1112 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 1113 | audio_session_t session = VALUE_OR_RETURN_BINDER_STATUS( |
| 1114 | aidl2legacy_int32_t_audio_session_t(sessionAidl)); |
| 1115 | int id = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(idAidl)); |
| 1116 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1117 | AudioValidator::validateEffectDescriptor(desc, "73126106"))); |
| 1118 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1119 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1120 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1121 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1122 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1123 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1124 | return binderStatusFromStatusT( |
| 1125 | mAudioPolicyManager->registerEffect(&desc, io, strategy, session, id)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1126 | } |
| 1127 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1128 | Status AudioPolicyService::unregisterEffect(int32_t idAidl) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1129 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1130 | int id = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(idAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1131 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1132 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1133 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1134 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1135 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1136 | return binderStatusFromStatusT(mAudioPolicyManager->unregisterEffect(id)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1137 | } |
| 1138 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1139 | Status AudioPolicyService::setEffectEnabled(int32_t idAidl, bool enabled) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1140 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1141 | int id = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(idAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1142 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1143 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1144 | } |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1145 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1146 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1147 | return binderStatusFromStatusT(mAudioPolicyManager->setEffectEnabled(id, enabled)); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1150 | Status AudioPolicyService::moveEffectsToIo(const std::vector<int32_t>& idsAidl, int32_t ioAidl) |
| 1151 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1152 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1153 | const std::vector<int>& ids = VALUE_OR_RETURN_BINDER_STATUS( |
| 1154 | convertContainer<std::vector<int>>(idsAidl, convertReinterpret<int, int32_t>)); |
| 1155 | audio_io_handle_t io = VALUE_OR_RETURN_BINDER_STATUS( |
| 1156 | aidl2legacy_int32_t_audio_io_handle_t(ioAidl)); |
| 1157 | if (ids.size() > MAX_ITEMS_PER_LIST) { |
| 1158 | return binderStatusFromStatusT(BAD_VALUE); |
| 1159 | } |
| 1160 | |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1161 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1162 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1163 | } |
| 1164 | Mutex::Autolock _l(mLock); |
| 1165 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1166 | return binderStatusFromStatusT(mAudioPolicyManager->moveEffectsToIo(ids, io)); |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1169 | Status AudioPolicyService::isStreamActive(media::AudioStreamType streamAidl, int32_t inPastMsAidl, |
| 1170 | bool* _aidl_return) { |
| 1171 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1172 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1173 | uint32_t inPastMs = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(inPastMsAidl)); |
| 1174 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1175 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1176 | *_aidl_return = false; |
| 1177 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1178 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1179 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1180 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1181 | } |
| 1182 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1183 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1184 | *_aidl_return = mAudioPolicyManager->isStreamActive(stream, inPastMs); |
| 1185 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1186 | } |
| 1187 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1188 | Status AudioPolicyService::isStreamActiveRemotely(media::AudioStreamType streamAidl, |
| 1189 | int32_t inPastMsAidl, |
| 1190 | bool* _aidl_return) { |
| 1191 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1192 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1193 | uint32_t inPastMs = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(inPastMsAidl)); |
| 1194 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1195 | if (uint32_t(stream) >= AUDIO_STREAM_PUBLIC_CNT) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1196 | *_aidl_return = false; |
| 1197 | return Status::ok(); |
Eric Laurent | dea1541 | 2014-10-28 15:46:45 -0700 | [diff] [blame] | 1198 | } |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1199 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1200 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1201 | } |
| 1202 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1203 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1204 | *_aidl_return = mAudioPolicyManager->isStreamActiveRemotely(stream, inPastMs); |
| 1205 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1208 | Status AudioPolicyService::isSourceActive(media::AudioSourceType sourceAidl, bool* _aidl_return) { |
| 1209 | audio_source_t source = VALUE_OR_RETURN_BINDER_STATUS( |
| 1210 | aidl2legacy_AudioSourceType_audio_source_t(sourceAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1211 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1212 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1213 | } |
| 1214 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1215 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1216 | *_aidl_return = mAudioPolicyManager->isSourceActive(source); |
| 1217 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1220 | status_t AudioPolicyService::getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects) |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1221 | { |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1222 | if (mAudioPolicyManager == NULL) { |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1223 | return NO_INIT; |
| 1224 | } |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 1225 | { |
| 1226 | Mutex::Autolock _l(mLock); |
| 1227 | audioPolicyEffects = mAudioPolicyEffects; |
| 1228 | } |
| 1229 | if (audioPolicyEffects == 0) { |
Eric Laurent | 8b1e80b | 2014-10-07 09:08:47 -0700 | [diff] [blame] | 1230 | return NO_INIT; |
| 1231 | } |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1232 | |
| 1233 | return OK; |
| 1234 | } |
| 1235 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1236 | Status AudioPolicyService::queryDefaultPreProcessing( |
| 1237 | int32_t audioSessionAidl, |
| 1238 | media::Int* countAidl, |
| 1239 | std::vector<media::EffectDescriptor>* _aidl_return) { |
| 1240 | audio_session_t audioSession = VALUE_OR_RETURN_BINDER_STATUS( |
| 1241 | aidl2legacy_int32_t_audio_session_t(audioSessionAidl)); |
| 1242 | uint32_t count = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(countAidl->value)); |
| 1243 | if (count > AudioEffect::kMaxPreProcessing) { |
| 1244 | count = AudioEffect::kMaxPreProcessing; |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1245 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1246 | uint32_t countReq = count; |
| 1247 | std::unique_ptr<effect_descriptor_t[]> descriptors(new effect_descriptor_t[count]); |
| 1248 | |
| 1249 | sp<AudioPolicyEffects> audioPolicyEffects; |
| 1250 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
| 1251 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(audioPolicyEffects->queryDefaultInputEffects( |
| 1252 | (audio_session_t) audioSession, descriptors.get(), &count))); |
| 1253 | countReq = std::min(count, countReq); |
| 1254 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1255 | convertRange(descriptors.get(), descriptors.get() + countReq, |
| 1256 | std::back_inserter(*_aidl_return), |
| 1257 | legacy2aidl_effect_descriptor_t_EffectDescriptor))); |
| 1258 | countAidl->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(count)); |
| 1259 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1260 | } |
| 1261 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1262 | Status AudioPolicyService::addSourceDefaultEffect(const media::AudioUuid& typeAidl, |
| 1263 | const std::string& opPackageNameAidl, |
| 1264 | const media::AudioUuid& uuidAidl, |
| 1265 | int32_t priority, |
| 1266 | media::AudioSourceType sourceAidl, |
| 1267 | int32_t* _aidl_return) { |
| 1268 | effect_uuid_t type = VALUE_OR_RETURN_BINDER_STATUS( |
| 1269 | aidl2legacy_AudioUuid_audio_uuid_t(typeAidl)); |
| 1270 | String16 opPackageName = VALUE_OR_RETURN_BINDER_STATUS( |
| 1271 | aidl2legacy_string_view_String16(opPackageNameAidl)); |
| 1272 | effect_uuid_t uuid = VALUE_OR_RETURN_BINDER_STATUS( |
| 1273 | aidl2legacy_AudioUuid_audio_uuid_t(uuidAidl)); |
| 1274 | audio_source_t source = VALUE_OR_RETURN_BINDER_STATUS( |
| 1275 | aidl2legacy_AudioSourceType_audio_source_t(sourceAidl)); |
| 1276 | audio_unique_id_t id; |
| 1277 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1278 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1279 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1280 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1281 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1282 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1283 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(audioPolicyEffects->addSourceDefaultEffect( |
| 1284 | &type, opPackageName, &uuid, priority, source, &id))); |
| 1285 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_unique_id_t_int32_t(id)); |
| 1286 | return Status::ok(); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1287 | } |
| 1288 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1289 | Status AudioPolicyService::addStreamDefaultEffect(const media::AudioUuid& typeAidl, |
| 1290 | const std::string& opPackageNameAidl, |
| 1291 | const media::AudioUuid& uuidAidl, |
| 1292 | int32_t priority, media::AudioUsage usageAidl, |
| 1293 | int32_t* _aidl_return) { |
| 1294 | effect_uuid_t type = VALUE_OR_RETURN_BINDER_STATUS( |
| 1295 | aidl2legacy_AudioUuid_audio_uuid_t(typeAidl)); |
| 1296 | String16 opPackageName = VALUE_OR_RETURN_BINDER_STATUS( |
| 1297 | aidl2legacy_string_view_String16(opPackageNameAidl)); |
| 1298 | effect_uuid_t uuid = VALUE_OR_RETURN_BINDER_STATUS( |
| 1299 | aidl2legacy_AudioUuid_audio_uuid_t(uuidAidl)); |
| 1300 | audio_usage_t usage = VALUE_OR_RETURN_BINDER_STATUS( |
| 1301 | aidl2legacy_AudioUsage_audio_usage_t(usageAidl)); |
| 1302 | audio_unique_id_t id; |
| 1303 | |
| 1304 | sp<AudioPolicyEffects> audioPolicyEffects; |
| 1305 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1306 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1307 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1308 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1309 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(audioPolicyEffects->addStreamDefaultEffect( |
| 1310 | &type, opPackageName, &uuid, priority, usage, &id))); |
| 1311 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_unique_id_t_int32_t(id)); |
| 1312 | return Status::ok(); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1313 | } |
| 1314 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1315 | Status AudioPolicyService::removeSourceDefaultEffect(int32_t idAidl) |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1316 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1317 | audio_unique_id_t id = VALUE_OR_RETURN_BINDER_STATUS( |
| 1318 | aidl2legacy_int32_t_audio_unique_id_t(idAidl)); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1319 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1320 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1321 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1322 | return binderStatusFromStatusT(PERMISSION_DENIED); |
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 | return binderStatusFromStatusT(audioPolicyEffects->removeSourceDefaultEffect(id)); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1327 | Status AudioPolicyService::removeStreamDefaultEffect(int32_t idAidl) |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1328 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1329 | audio_unique_id_t id = VALUE_OR_RETURN_BINDER_STATUS( |
| 1330 | aidl2legacy_int32_t_audio_unique_id_t(idAidl)); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1331 | sp<AudioPolicyEffects>audioPolicyEffects; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1332 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(getAudioPolicyEffects(audioPolicyEffects))); |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 1333 | if (!modifyDefaultAudioEffectsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1334 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1335 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1336 | return binderStatusFromStatusT(audioPolicyEffects->removeStreamDefaultEffect(id)); |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 1337 | } |
| 1338 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1339 | Status AudioPolicyService::setSupportedSystemUsages( |
| 1340 | const std::vector<media::AudioUsage>& systemUsagesAidl) { |
| 1341 | size_t size = systemUsagesAidl.size(); |
| 1342 | if (size > MAX_ITEMS_PER_LIST) { |
| 1343 | size = MAX_ITEMS_PER_LIST; |
| 1344 | } |
| 1345 | std::vector<audio_usage_t> systemUsages; |
| 1346 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1347 | convertRange(systemUsagesAidl.begin(), systemUsagesAidl.begin() + size, |
| 1348 | std::back_inserter(systemUsages), aidl2legacy_AudioUsage_audio_usage_t))); |
| 1349 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1350 | Mutex::Autolock _l(mLock); |
| 1351 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1352 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | bool areAllSystemUsages = std::all_of(begin(systemUsages), end(systemUsages), |
| 1356 | [](audio_usage_t usage) { return isSystemUsage(usage); }); |
| 1357 | if (!areAllSystemUsages) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1358 | return binderStatusFromStatusT(BAD_VALUE); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | mSupportedSystemUsages = systemUsages; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1362 | return Status::ok(); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1363 | } |
| 1364 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1365 | Status AudioPolicyService::setAllowedCapturePolicy(int32_t uidAidl, int32_t capturePolicyAidl) { |
| 1366 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 1367 | audio_flags_mask_t capturePolicy = VALUE_OR_RETURN_BINDER_STATUS( |
| 1368 | aidl2legacy_int32_t_audio_flags_mask_t_mask(capturePolicyAidl)); |
| 1369 | |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1370 | Mutex::Autolock _l(mLock); |
| 1371 | if (mAudioPolicyManager == NULL) { |
| 1372 | ALOGV("%s() mAudioPolicyManager == NULL", __func__); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1373 | return binderStatusFromStatusT(NO_INIT); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1374 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1375 | return binderStatusFromStatusT( |
| 1376 | mAudioPolicyManager->setAllowedCapturePolicy(uid, capturePolicy)); |
Kevin Rocard | b99cc75 | 2019-03-21 20:52:24 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1379 | Status AudioPolicyService::getOffloadSupport(const media::AudioOffloadInfo& infoAidl, |
| 1380 | media::AudioOffloadMode* _aidl_return) { |
| 1381 | audio_offload_info_t info = VALUE_OR_RETURN_BINDER_STATUS( |
| 1382 | aidl2legacy_AudioOffloadInfo_audio_offload_info_t(infoAidl)); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1383 | if (mAudioPolicyManager == NULL) { |
| 1384 | ALOGV("mAudioPolicyManager == NULL"); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1385 | return binderStatusFromStatusT(AUDIO_OFFLOAD_NOT_SUPPORTED); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1386 | } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1387 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1388 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1389 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_offload_mode_t_AudioOffloadMode( |
| 1390 | mAudioPolicyManager->getOffloadSupport(info))); |
| 1391 | return Status::ok(); |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1394 | Status AudioPolicyService::isDirectOutputSupported( |
| 1395 | const media::AudioConfigBase& configAidl, |
| 1396 | const media::AudioAttributesInternal& attributesAidl, |
| 1397 | bool* _aidl_return) { |
| 1398 | audio_config_base_t config = VALUE_OR_RETURN_BINDER_STATUS( |
| 1399 | aidl2legacy_AudioConfigBase_audio_config_base_t(configAidl)); |
| 1400 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 1401 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attributesAidl)); |
| 1402 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1403 | AudioValidator::validateAudioAttributes(attributes, "169572641"))); |
| 1404 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1405 | if (mAudioPolicyManager == NULL) { |
| 1406 | ALOGV("mAudioPolicyManager == NULL"); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1407 | return binderStatusFromStatusT(NO_INIT); |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1408 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1409 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1410 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attributes.usage))); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1411 | |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1412 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1413 | *_aidl_return = mAudioPolicyManager->isDirectOutputSupported(config, attributes); |
| 1414 | return Status::ok(); |
Michael Chan | a94fbb2 | 2018-04-24 14:31:19 +1000 | [diff] [blame] | 1415 | } |
| 1416 | |
| 1417 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1418 | Status AudioPolicyService::listAudioPorts(media::AudioPortRole roleAidl, |
| 1419 | media::AudioPortType typeAidl, media::Int* count, |
| 1420 | std::vector<media::AudioPort>* portsAidl, |
| 1421 | int32_t* _aidl_return) { |
| 1422 | audio_port_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 1423 | aidl2legacy_AudioPortRole_audio_port_role_t(roleAidl)); |
| 1424 | audio_port_type_t type = VALUE_OR_RETURN_BINDER_STATUS( |
| 1425 | aidl2legacy_AudioPortType_audio_port_type_t(typeAidl)); |
| 1426 | unsigned int num_ports = VALUE_OR_RETURN_BINDER_STATUS( |
| 1427 | convertIntegral<unsigned int>(count->value)); |
| 1428 | if (num_ports > MAX_ITEMS_PER_LIST) { |
| 1429 | num_ports = MAX_ITEMS_PER_LIST; |
| 1430 | } |
| 1431 | unsigned int numPortsReq = num_ports; |
| 1432 | std::unique_ptr<audio_port_v7[]> ports(new audio_port_v7[num_ports]); |
| 1433 | unsigned int generation; |
| 1434 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1435 | Mutex::Autolock _l(mLock); |
| 1436 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1437 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1438 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1439 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1440 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1441 | mAudioPolicyManager->listAudioPorts(role, type, &num_ports, ports.get(), &generation))); |
| 1442 | numPortsReq = std::min(numPortsReq, num_ports); |
| 1443 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1444 | convertRange(ports.get(), ports.get() + numPortsReq, std::back_inserter(*portsAidl), |
| 1445 | legacy2aidl_audio_port_v7_AudioPort))); |
| 1446 | count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(num_ports)); |
| 1447 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(generation)); |
| 1448 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1449 | } |
| 1450 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1451 | Status AudioPolicyService::getAudioPort(const media::AudioPort& portAidl, |
| 1452 | media::AudioPort* _aidl_return) { |
| 1453 | audio_port_v7 port = VALUE_OR_RETURN_BINDER_STATUS( |
| 1454 | aidl2legacy_AudioPort_audio_port_v7(portAidl)); |
| 1455 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(AudioValidator::validateAudioPort(port))); |
| 1456 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1457 | Mutex::Autolock _l(mLock); |
| 1458 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1459 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1460 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1461 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1462 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(mAudioPolicyManager->getAudioPort(&port))); |
| 1463 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_port_v7_AudioPort(port)); |
| 1464 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1465 | } |
| 1466 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1467 | Status AudioPolicyService::createAudioPatch(const media::AudioPatch& patchAidl, int32_t handleAidl, |
| 1468 | int32_t* _aidl_return) { |
| 1469 | audio_patch patch = VALUE_OR_RETURN_BINDER_STATUS( |
| 1470 | aidl2legacy_AudioPatch_audio_patch(patchAidl)); |
| 1471 | audio_patch_handle_t handle = VALUE_OR_RETURN_BINDER_STATUS( |
| 1472 | aidl2legacy_int32_t_audio_port_handle_t(handleAidl)); |
| 1473 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(AudioValidator::validateAudioPatch(patch))); |
| 1474 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1475 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1476 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1477 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1478 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1479 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1480 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1481 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1482 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1483 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1484 | mAudioPolicyManager->createAudioPatch(&patch, &handle, |
| 1485 | IPCThreadState::self()->getCallingUid()))); |
| 1486 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_patch_handle_t_int32_t(handle)); |
| 1487 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1490 | Status AudioPolicyService::releaseAudioPatch(int32_t handleAidl) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1491 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1492 | audio_patch_handle_t handle = VALUE_OR_RETURN_BINDER_STATUS( |
| 1493 | aidl2legacy_int32_t_audio_patch_handle_t(handleAidl)); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1494 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1495 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1496 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1497 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1498 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1499 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1500 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1501 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1502 | return binderStatusFromStatusT( |
| 1503 | mAudioPolicyManager->releaseAudioPatch(handle, |
| 1504 | IPCThreadState::self()->getCallingUid())); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1505 | } |
| 1506 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1507 | Status AudioPolicyService::listAudioPatches(media::Int* count, |
| 1508 | std::vector<media::AudioPatch>* patchesAidl, |
| 1509 | int32_t* _aidl_return) { |
| 1510 | unsigned int num_patches = VALUE_OR_RETURN_BINDER_STATUS( |
| 1511 | convertIntegral<unsigned int>(count->value)); |
| 1512 | if (num_patches > MAX_ITEMS_PER_LIST) { |
| 1513 | num_patches = MAX_ITEMS_PER_LIST; |
| 1514 | } |
| 1515 | unsigned int numPatchesReq = num_patches; |
| 1516 | std::unique_ptr<audio_patch[]> patches(new audio_patch[num_patches]); |
| 1517 | unsigned int generation; |
| 1518 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1519 | Mutex::Autolock _l(mLock); |
| 1520 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1521 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1522 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1523 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1524 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1525 | mAudioPolicyManager->listAudioPatches(&num_patches, patches.get(), &generation))); |
| 1526 | numPatchesReq = std::min(numPatchesReq, num_patches); |
| 1527 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1528 | convertRange(patches.get(), patches.get() + numPatchesReq, |
| 1529 | std::back_inserter(*patchesAidl), legacy2aidl_audio_patch_AudioPatch))); |
| 1530 | count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(num_patches)); |
| 1531 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int32_t>(generation)); |
| 1532 | return Status::ok(); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1533 | } |
| 1534 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1535 | Status AudioPolicyService::setAudioPortConfig(const media::AudioPortConfig& configAidl) |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1536 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1537 | audio_port_config config = VALUE_OR_RETURN_BINDER_STATUS( |
| 1538 | aidl2legacy_AudioPortConfig_audio_port_config(configAidl)); |
| 1539 | RETURN_IF_BINDER_ERROR( |
| 1540 | binderStatusFromStatusT(AudioValidator::validateAudioPortConfig(config))); |
| 1541 | |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1542 | Mutex::Autolock _l(mLock); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1543 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1544 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | 5284ed5 | 2014-05-29 14:37:38 -0700 | [diff] [blame] | 1545 | } |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1546 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1547 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 6a94d69 | 2014-05-20 11:18:06 -0700 | [diff] [blame] | 1548 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1549 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1550 | return binderStatusFromStatusT(mAudioPolicyManager->setAudioPortConfig(&config)); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 1551 | } |
Eric Laurent | 2d388ec | 2014-03-07 13:25:54 -0800 | [diff] [blame] | 1552 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1553 | Status AudioPolicyService::acquireSoundTriggerSession(media::SoundTriggerSession* _aidl_return) |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1554 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1555 | audio_session_t session; |
| 1556 | audio_io_handle_t ioHandle; |
| 1557 | audio_devices_t device; |
| 1558 | |
| 1559 | { |
| 1560 | Mutex::Autolock _l(mLock); |
| 1561 | if (mAudioPolicyManager == NULL) { |
| 1562 | return binderStatusFromStatusT(NO_INIT); |
| 1563 | } |
| 1564 | AutoCallerClear acc; |
| 1565 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1566 | mAudioPolicyManager->acquireSoundTriggerSession(&session, &ioHandle, &device))); |
| 1567 | } |
| 1568 | |
| 1569 | _aidl_return->session = VALUE_OR_RETURN_BINDER_STATUS( |
| 1570 | legacy2aidl_audio_session_t_int32_t(session)); |
| 1571 | _aidl_return->ioHandle = VALUE_OR_RETURN_BINDER_STATUS( |
| 1572 | legacy2aidl_audio_io_handle_t_int32_t(ioHandle)); |
| 1573 | _aidl_return->device = VALUE_OR_RETURN_BINDER_STATUS( |
| 1574 | legacy2aidl_audio_devices_t_int32_t(device)); |
| 1575 | return Status::ok(); |
| 1576 | } |
| 1577 | |
| 1578 | Status AudioPolicyService::releaseSoundTriggerSession(int32_t sessionAidl) |
| 1579 | { |
| 1580 | audio_session_t session = VALUE_OR_RETURN_BINDER_STATUS( |
| 1581 | aidl2legacy_int32_t_audio_session_t(sessionAidl)); |
Andy Hung | f759b8c | 2017-08-15 12:48:54 -0700 | [diff] [blame] | 1582 | Mutex::Autolock _l(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1583 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1584 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1585 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1586 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1587 | return binderStatusFromStatusT(mAudioPolicyManager->releaseSoundTriggerSession(session)); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1590 | Status AudioPolicyService::registerPolicyMixes(const std::vector<media::AudioMix>& mixesAidl, |
| 1591 | bool registration) { |
| 1592 | size_t size = mixesAidl.size(); |
| 1593 | if (size > MAX_MIXES_PER_POLICY) { |
| 1594 | size = MAX_MIXES_PER_POLICY; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1595 | } |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1596 | Vector<AudioMix> mixes; |
| 1597 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1598 | convertRange(mixesAidl.begin(), mixesAidl.begin() + size, std::back_inserter(mixes), |
| 1599 | aidl2legacy_AudioMix))); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 1600 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1601 | Mutex::Autolock _l(mLock); |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1602 | |
| 1603 | // loopback|render only need a MediaProjection (checked in caller AudioService.java) |
| 1604 | bool needModifyAudioRouting = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
| 1605 | return !is_mix_loopback_render(mix.mRouteFlags); }); |
| 1606 | if (needModifyAudioRouting && !modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1607 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1608 | } |
Kevin Rocard | be20185 | 2019-02-20 22:33:28 -0800 | [diff] [blame] | 1609 | |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1610 | // If one of the mixes has needCaptureVoiceCommunicationOutput set to true, then we |
| 1611 | // need to verify that the caller still has CAPTURE_VOICE_COMMUNICATION_OUTPUT |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1612 | bool needCaptureVoiceCommunicationOutput = |
| 1613 | std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
Nadav Bar | 287d330 | 2020-02-05 14:55:38 +0200 | [diff] [blame] | 1614 | return mix.mVoiceCommunicationCaptureAllowed; }); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1615 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1616 | bool needCaptureMediaOutput = std::any_of(mixes.begin(), mixes.end(), [](auto& mix) { |
Eric Laurent | 5f9a645 | 2020-12-22 20:10:10 +0100 | [diff] [blame] | 1617 | return mix.mAllowPrivilegedMediaPlaybackCapture; }); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1618 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1619 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
| 1620 | const pid_t callingPid = IPCThreadState::self()->getCallingPid(); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1621 | |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1622 | if (needCaptureMediaOutput && !captureMediaOutputAllowed(callingPid, callingUid)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1623 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Kevin Rocard | 36b1755 | 2019-03-07 18:48:07 -0800 | [diff] [blame] | 1624 | } |
| 1625 | |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1626 | if (needCaptureVoiceCommunicationOutput && |
| 1627 | !captureVoiceCommunicationOutputAllowed(callingPid, callingUid)) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1628 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Nadav Bar | dbf0a2e | 2020-01-16 23:09:25 +0200 | [diff] [blame] | 1629 | } |
| 1630 | |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1631 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1632 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1633 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1634 | AutoCallerClear acc; |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1635 | if (registration) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1636 | return binderStatusFromStatusT(mAudioPolicyManager->registerPolicyMixes(mixes)); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1637 | } else { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1638 | return binderStatusFromStatusT(mAudioPolicyManager->unregisterPolicyMixes(mixes)); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 1639 | } |
| 1640 | } |
| 1641 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1642 | Status AudioPolicyService::setUidDeviceAffinities( |
| 1643 | int32_t uidAidl, |
| 1644 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 1645 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 1646 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 1647 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 1648 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1649 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1650 | Mutex::Autolock _l(mLock); |
| 1651 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1652 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1653 | } |
| 1654 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1655 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1656 | } |
| 1657 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1658 | return binderStatusFromStatusT(mAudioPolicyManager->setUidDeviceAffinities(uid, devices)); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1659 | } |
| 1660 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1661 | Status AudioPolicyService::removeUidDeviceAffinities(int32_t uidAidl) { |
| 1662 | uid_t uid = VALUE_OR_RETURN_BINDER_STATUS(aidl2legacy_int32_t_uid_t(uidAidl)); |
| 1663 | |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1664 | Mutex::Autolock _l(mLock); |
| 1665 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1666 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1667 | } |
| 1668 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1669 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1670 | } |
| 1671 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1672 | return binderStatusFromStatusT(mAudioPolicyManager->removeUidDeviceAffinities(uid)); |
Jean-Michel Trivi | bda70da | 2018-12-19 07:30:15 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1675 | Status AudioPolicyService::setUserIdDeviceAffinities( |
| 1676 | int32_t userIdAidl, |
| 1677 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 1678 | int userId = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(userIdAidl)); |
| 1679 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 1680 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 1681 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1682 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1683 | Mutex::Autolock _l(mLock); |
| 1684 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1685 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1686 | } |
| 1687 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1688 | return binderStatusFromStatusT(NO_INIT); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1689 | } |
| 1690 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1691 | return binderStatusFromStatusT(mAudioPolicyManager->setUserIdDeviceAffinities(userId, devices)); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1692 | } |
| 1693 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1694 | Status AudioPolicyService::removeUserIdDeviceAffinities(int32_t userIdAidl) { |
| 1695 | int userId = VALUE_OR_RETURN_BINDER_STATUS(convertReinterpret<int>(userIdAidl)); |
| 1696 | |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1697 | Mutex::Autolock _l(mLock); |
| 1698 | if(!modifyAudioRoutingAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1699 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1700 | } |
| 1701 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1702 | return binderStatusFromStatusT(NO_INIT); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1703 | } |
| 1704 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1705 | return binderStatusFromStatusT(mAudioPolicyManager->removeUserIdDeviceAffinities(userId)); |
Oscar Azucena | 90e7763 | 2019-11-27 17:12:28 -0800 | [diff] [blame] | 1706 | } |
| 1707 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1708 | Status AudioPolicyService::startAudioSource(const media::AudioPortConfig& sourceAidl, |
| 1709 | const media::AudioAttributesInternal& attributesAidl, |
| 1710 | int32_t* _aidl_return) { |
| 1711 | audio_port_config source = VALUE_OR_RETURN_BINDER_STATUS( |
| 1712 | aidl2legacy_AudioPortConfig_audio_port_config(sourceAidl)); |
| 1713 | audio_attributes_t attributes = VALUE_OR_RETURN_BINDER_STATUS( |
| 1714 | aidl2legacy_AudioAttributesInternal_audio_attributes_t(attributesAidl)); |
| 1715 | audio_port_handle_t portId; |
| 1716 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1717 | AudioValidator::validateAudioPortConfig(source))); |
| 1718 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1719 | AudioValidator::validateAudioAttributes(attributes, "68953950"))); |
| 1720 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1721 | Mutex::Autolock _l(mLock); |
| 1722 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1723 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1724 | } |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1725 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1726 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT(validateUsage(attributes.usage))); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1727 | |
Hongwei Wang | 5cd1f1d | 2019-03-26 15:21:11 -0700 | [diff] [blame] | 1728 | // startAudioSource should be created as the calling uid |
| 1729 | const uid_t callingUid = IPCThreadState::self()->getCallingUid(); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1730 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1731 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1732 | mAudioPolicyManager->startAudioSource(&source, &attributes, &portId, callingUid))); |
| 1733 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_audio_port_handle_t_int32_t(portId)); |
| 1734 | return Status::ok(); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1735 | } |
| 1736 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1737 | Status AudioPolicyService::stopAudioSource(int32_t portIdAidl) |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1738 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1739 | audio_port_handle_t portId = VALUE_OR_RETURN_BINDER_STATUS( |
| 1740 | aidl2legacy_int32_t_audio_port_handle_t(portIdAidl)); |
| 1741 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1742 | Mutex::Autolock _l(mLock); |
| 1743 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1744 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1745 | } |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1746 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1747 | return binderStatusFromStatusT(mAudioPolicyManager->stopAudioSource(portId)); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1750 | Status AudioPolicyService::setMasterMono(bool mono) |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1751 | { |
| 1752 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1753 | return binderStatusFromStatusT(NO_INIT); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1754 | } |
| 1755 | if (!settingsAllowed()) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1756 | return binderStatusFromStatusT(PERMISSION_DENIED); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1757 | } |
| 1758 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1759 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1760 | return binderStatusFromStatusT(mAudioPolicyManager->setMasterMono(mono)); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1761 | } |
| 1762 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1763 | Status AudioPolicyService::getMasterMono(bool* _aidl_return) |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1764 | { |
| 1765 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1766 | return binderStatusFromStatusT(NO_INIT); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1767 | } |
| 1768 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1769 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1770 | return binderStatusFromStatusT(mAudioPolicyManager->getMasterMono(_aidl_return)); |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1771 | } |
| 1772 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1773 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1774 | Status AudioPolicyService::getStreamVolumeDB(media::AudioStreamType streamAidl, int32_t indexAidl, |
| 1775 | int32_t deviceAidl, float* _aidl_return) { |
| 1776 | audio_stream_type_t stream = VALUE_OR_RETURN_BINDER_STATUS( |
| 1777 | aidl2legacy_AudioStreamType_audio_stream_type_t(streamAidl)); |
| 1778 | int index = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<int>(indexAidl)); |
| 1779 | audio_devices_t device = VALUE_OR_RETURN_BINDER_STATUS( |
| 1780 | aidl2legacy_int32_t_audio_devices_t(deviceAidl)); |
| 1781 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1782 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1783 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1784 | } |
| 1785 | Mutex::Autolock _l(mLock); |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1786 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1787 | *_aidl_return = mAudioPolicyManager->getStreamVolumeDB(stream, index, device); |
| 1788 | return Status::ok(); |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1789 | } |
| 1790 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1791 | Status AudioPolicyService::getSurroundFormats( |
| 1792 | bool reported, media::Int* count, |
| 1793 | std::vector<media::audio::common::AudioFormat>* formats, |
| 1794 | bool* _aidl_return) { |
| 1795 | unsigned int numSurroundFormats = VALUE_OR_RETURN_BINDER_STATUS( |
| 1796 | convertIntegral<unsigned int>(count->value)); |
| 1797 | if (numSurroundFormats > MAX_ITEMS_PER_LIST) { |
| 1798 | numSurroundFormats = MAX_ITEMS_PER_LIST; |
| 1799 | } |
| 1800 | unsigned int numSurroundFormatsReq = numSurroundFormats; |
| 1801 | std::unique_ptr<audio_format_t[]>surroundFormats(new audio_format_t[numSurroundFormats]); |
| 1802 | |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1803 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1804 | return binderStatusFromStatusT(NO_INIT); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1805 | } |
| 1806 | Mutex::Autolock _l(mLock); |
| 1807 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1808 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1809 | mAudioPolicyManager->getSurroundFormats(&numSurroundFormats, surroundFormats.get(), |
| 1810 | _aidl_return, reported))); |
| 1811 | numSurroundFormatsReq = std::min(numSurroundFormats, numSurroundFormatsReq); |
| 1812 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1813 | convertRange(surroundFormats.get(), surroundFormats.get() + numSurroundFormatsReq, |
| 1814 | std::back_inserter(*formats), legacy2aidl_audio_format_t_AudioFormat))); |
| 1815 | count->value = VALUE_OR_RETURN_BINDER_STATUS(convertIntegral<uint32_t>(numSurroundFormats)); |
| 1816 | return Status::ok(); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1819 | Status AudioPolicyService::getHwOffloadEncodingFormatsSupportedForA2DP( |
| 1820 | std::vector<media::audio::common::AudioFormat>* _aidl_return) { |
| 1821 | std::vector<audio_format_t> formats; |
| 1822 | |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1823 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1824 | return binderStatusFromStatusT(NO_INIT); |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1825 | } |
| 1826 | Mutex::Autolock _l(mLock); |
| 1827 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1828 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1829 | mAudioPolicyManager->getHwOffloadEncodingFormatsSupportedForA2DP(&formats))); |
| 1830 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1831 | convertContainer<std::vector<media::audio::common::AudioFormat>>( |
| 1832 | formats, |
| 1833 | legacy2aidl_audio_format_t_AudioFormat)); |
| 1834 | return Status::ok(); |
Arun Mirpuri | 11029ad | 2018-12-19 20:45:19 -0800 | [diff] [blame] | 1835 | } |
| 1836 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1837 | Status AudioPolicyService::setSurroundFormatEnabled( |
| 1838 | media::audio::common::AudioFormat audioFormatAidl, bool enabled) { |
| 1839 | audio_format_t audioFormat = VALUE_OR_RETURN_BINDER_STATUS( |
| 1840 | aidl2legacy_AudioFormat_audio_format_t(audioFormatAidl)); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1841 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1842 | return binderStatusFromStatusT(NO_INIT); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1843 | } |
| 1844 | Mutex::Autolock _l(mLock); |
| 1845 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1846 | return binderStatusFromStatusT( |
| 1847 | mAudioPolicyManager->setSurroundFormatEnabled(audioFormat, enabled)); |
jiabin | 8177290 | 2018-04-02 17:52:27 -0700 | [diff] [blame] | 1848 | } |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 1849 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1850 | Status AudioPolicyService::setAssistantUid(int32_t uidAidl) |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1851 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1852 | 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] | 1853 | Mutex::Autolock _l(mLock); |
| 1854 | mUidPolicy->setAssistantUid(uid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1855 | return Status::ok(); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1856 | } |
| 1857 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1858 | Status AudioPolicyService::setA11yServicesUids(const std::vector<int32_t>& uidsAidl) |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1859 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1860 | size_t size = uidsAidl.size(); |
| 1861 | if (size > MAX_ITEMS_PER_LIST) { |
| 1862 | size = MAX_ITEMS_PER_LIST; |
| 1863 | } |
| 1864 | std::vector<uid_t> uids; |
| 1865 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1866 | convertRange(uidsAidl.begin(), |
| 1867 | uidsAidl.begin() + size, |
| 1868 | std::back_inserter(uids), |
| 1869 | aidl2legacy_int32_t_uid_t))); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1870 | Mutex::Autolock _l(mLock); |
| 1871 | mUidPolicy->setA11yUids(uids); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1872 | return Status::ok(); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1875 | Status AudioPolicyService::setCurrentImeUid(int32_t uidAidl) |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1876 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1877 | 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] | 1878 | Mutex::Autolock _l(mLock); |
| 1879 | mUidPolicy->setCurrentImeUid(uid); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1880 | return Status::ok(); |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1883 | Status AudioPolicyService::isHapticPlaybackSupported(bool* _aidl_return) |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1884 | { |
| 1885 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1886 | return binderStatusFromStatusT(NO_INIT); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1887 | } |
| 1888 | Mutex::Autolock _l(mLock); |
| 1889 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1890 | *_aidl_return = mAudioPolicyManager->isHapticPlaybackSupported(); |
| 1891 | return Status::ok(); |
jiabin | 6012f91 | 2018-11-02 17:06:30 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1894 | Status AudioPolicyService::listAudioProductStrategies( |
| 1895 | std::vector<media::AudioProductStrategy>* _aidl_return) { |
| 1896 | AudioProductStrategyVector strategies; |
| 1897 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1898 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1899 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1900 | } |
| 1901 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1902 | RETURN_IF_BINDER_ERROR( |
| 1903 | binderStatusFromStatusT(mAudioPolicyManager->listAudioProductStrategies(strategies))); |
| 1904 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1905 | convertContainer<std::vector<media::AudioProductStrategy>>( |
| 1906 | strategies, |
| 1907 | legacy2aidl_AudioProductStrategy)); |
| 1908 | return Status::ok(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1909 | } |
| 1910 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1911 | Status AudioPolicyService::getProductStrategyFromAudioAttributes( |
| 1912 | const media::AudioAttributesEx& aaAidl, int32_t* _aidl_return) { |
| 1913 | AudioAttributes aa = VALUE_OR_RETURN_BINDER_STATUS( |
| 1914 | aidl2legacy_AudioAttributesEx_AudioAttributes(aaAidl)); |
| 1915 | product_strategy_t productStrategy; |
| 1916 | |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1917 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1918 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1919 | } |
| 1920 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1921 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 1922 | mAudioPolicyManager->getProductStrategyFromAudioAttributes(aa, |
| 1923 | productStrategy))); |
| 1924 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1925 | legacy2aidl_product_strategy_t_int32_t(productStrategy)); |
| 1926 | return Status::ok(); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1927 | } |
| 1928 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1929 | Status AudioPolicyService::listAudioVolumeGroups(std::vector<media::AudioVolumeGroup>* _aidl_return) |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1930 | { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1931 | AudioVolumeGroupVector groups; |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1932 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1933 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1934 | } |
| 1935 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1936 | RETURN_IF_BINDER_ERROR( |
| 1937 | binderStatusFromStatusT(mAudioPolicyManager->listAudioVolumeGroups(groups))); |
| 1938 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 1939 | convertContainer<std::vector<media::AudioVolumeGroup>>(groups, |
| 1940 | legacy2aidl_AudioVolumeGroup)); |
| 1941 | return Status::ok(); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1942 | } |
| 1943 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1944 | Status AudioPolicyService::getVolumeGroupFromAudioAttributes(const media::AudioAttributesEx& aaAidl, |
| 1945 | int32_t* _aidl_return) { |
| 1946 | AudioAttributes aa = VALUE_OR_RETURN_BINDER_STATUS( |
| 1947 | aidl2legacy_AudioAttributesEx_AudioAttributes(aaAidl)); |
| 1948 | volume_group_t volumeGroup; |
| 1949 | |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1950 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1951 | return binderStatusFromStatusT(NO_INIT); |
François Gaffie | 4b2018b | 2018-11-07 11:18:59 +0100 | [diff] [blame] | 1952 | } |
| 1953 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1954 | RETURN_IF_BINDER_ERROR( |
| 1955 | binderStatusFromStatusT( |
| 1956 | mAudioPolicyManager->getVolumeGroupFromAudioAttributes(aa, volumeGroup))); |
| 1957 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS(legacy2aidl_volume_group_t_int32_t(volumeGroup)); |
| 1958 | return Status::ok(); |
François Gaffie | d0ba9ed | 2018-11-05 11:50:42 +0100 | [diff] [blame] | 1959 | } |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1960 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1961 | Status AudioPolicyService::setRttEnabled(bool enabled) |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1962 | { |
| 1963 | Mutex::Autolock _l(mLock); |
| 1964 | mUidPolicy->setRttEnabled(enabled); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1965 | return Status::ok(); |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 1966 | } |
| 1967 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1968 | Status AudioPolicyService::isCallScreenModeSupported(bool* _aidl_return) |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1969 | { |
| 1970 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1971 | return binderStatusFromStatusT(NO_INIT); |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1972 | } |
| 1973 | Mutex::Autolock _l(mLock); |
| 1974 | AutoCallerClear acc; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1975 | *_aidl_return = mAudioPolicyManager->isCallScreenModeSupported(); |
| 1976 | return Status::ok(); |
Eric Laurent | 8340e67 | 2019-11-06 11:01:08 -0800 | [diff] [blame] | 1977 | } |
| 1978 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1979 | Status AudioPolicyService::setDevicesRoleForStrategy( |
| 1980 | int32_t strategyAidl, |
| 1981 | media::DeviceRole roleAidl, |
| 1982 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 1983 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 1984 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 1985 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 1986 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 1987 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 1988 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 1989 | aidl2legacy_AudioDeviceTypeAddress)); |
| 1990 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1991 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1992 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1993 | } |
| 1994 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1995 | return binderStatusFromStatusT( |
| 1996 | mAudioPolicyManager->setDevicesRoleForStrategy(strategy, role, devices)); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 1997 | } |
| 1998 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 1999 | Status AudioPolicyService::removeDevicesRoleForStrategy(int32_t strategyAidl, |
| 2000 | media::DeviceRole roleAidl) { |
| 2001 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2002 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 2003 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2004 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2005 | if (mAudioPolicyManager == NULL) { |
| 2006 | return binderStatusFromStatusT(NO_INIT); |
| 2007 | } |
| 2008 | Mutex::Autolock _l(mLock); |
| 2009 | return binderStatusFromStatusT( |
| 2010 | mAudioPolicyManager->removeDevicesRoleForStrategy(strategy, role)); |
| 2011 | } |
| 2012 | |
| 2013 | Status AudioPolicyService::getDevicesForRoleAndStrategy( |
| 2014 | int32_t strategyAidl, |
| 2015 | media::DeviceRole roleAidl, |
| 2016 | std::vector<media::AudioDevice>* _aidl_return) { |
| 2017 | product_strategy_t strategy = VALUE_OR_RETURN_BINDER_STATUS( |
| 2018 | aidl2legacy_int32_t_product_strategy_t(strategyAidl)); |
| 2019 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2020 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2021 | AudioDeviceTypeAddrVector devices; |
| 2022 | |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2023 | if (mAudioPolicyManager == NULL) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2024 | return binderStatusFromStatusT(NO_INIT); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2025 | } |
| 2026 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2027 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 2028 | mAudioPolicyManager->getDevicesForRoleAndStrategy(strategy, role, devices))); |
| 2029 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 2030 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2031 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2032 | return Status::ok(); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2033 | } |
| 2034 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2035 | Status AudioPolicyService::registerSoundTriggerCaptureStateListener( |
| 2036 | const sp<media::ICaptureStateListener>& listener, bool* _aidl_return) { |
| 2037 | *_aidl_return = mCaptureStateNotifier.RegisterListener(listener); |
| 2038 | return Status::ok(); |
Jean-Michel Trivi | 3085715 | 2019-11-01 11:04:15 -0700 | [diff] [blame] | 2039 | } |
| 2040 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2041 | Status AudioPolicyService::setDevicesRoleForCapturePreset( |
| 2042 | media::AudioSourceType audioSourceAidl, |
| 2043 | media::DeviceRole roleAidl, |
| 2044 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 2045 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2046 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2047 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2048 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2049 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 2050 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2051 | aidl2legacy_AudioDeviceTypeAddress)); |
Ytai Ben-Tsvi | 85093d5 | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 2052 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2053 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2054 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2055 | } |
| 2056 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2057 | return binderStatusFromStatusT( |
| 2058 | mAudioPolicyManager->setDevicesRoleForCapturePreset(audioSource, role, devices)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2059 | } |
| 2060 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2061 | Status AudioPolicyService::addDevicesRoleForCapturePreset( |
| 2062 | media::AudioSourceType audioSourceAidl, |
| 2063 | media::DeviceRole roleAidl, |
| 2064 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 2065 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2066 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2067 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2068 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2069 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 2070 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2071 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2072 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2073 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2074 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2075 | } |
| 2076 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2077 | return binderStatusFromStatusT( |
| 2078 | mAudioPolicyManager->addDevicesRoleForCapturePreset(audioSource, role, devices)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2079 | } |
| 2080 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2081 | Status AudioPolicyService::removeDevicesRoleForCapturePreset( |
| 2082 | media::AudioSourceType audioSourceAidl, |
| 2083 | media::DeviceRole roleAidl, |
| 2084 | const std::vector<media::AudioDevice>& devicesAidl) { |
| 2085 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2086 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2087 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2088 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2089 | AudioDeviceTypeAddrVector devices = VALUE_OR_RETURN_BINDER_STATUS( |
| 2090 | convertContainer<AudioDeviceTypeAddrVector>(devicesAidl, |
| 2091 | aidl2legacy_AudioDeviceTypeAddress)); |
| 2092 | |
| 2093 | if (mAudioPolicyManager == nullptr) { |
| 2094 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2095 | } |
| 2096 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2097 | return binderStatusFromStatusT( |
| 2098 | mAudioPolicyManager->removeDevicesRoleForCapturePreset(audioSource, role, devices)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2101 | Status AudioPolicyService::clearDevicesRoleForCapturePreset(media::AudioSourceType audioSourceAidl, |
| 2102 | media::DeviceRole roleAidl) { |
| 2103 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2104 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2105 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2106 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2107 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2108 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2109 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2110 | } |
| 2111 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2112 | return binderStatusFromStatusT( |
| 2113 | mAudioPolicyManager->clearDevicesRoleForCapturePreset(audioSource, role)); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2114 | } |
| 2115 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2116 | Status AudioPolicyService::getDevicesForRoleAndCapturePreset( |
| 2117 | media::AudioSourceType audioSourceAidl, |
| 2118 | media::DeviceRole roleAidl, |
| 2119 | std::vector<media::AudioDevice>* _aidl_return) { |
| 2120 | audio_source_t audioSource = VALUE_OR_RETURN_BINDER_STATUS( |
| 2121 | aidl2legacy_AudioSourceType_audio_source_t(audioSourceAidl)); |
| 2122 | device_role_t role = VALUE_OR_RETURN_BINDER_STATUS( |
| 2123 | aidl2legacy_DeviceRole_device_role_t(roleAidl)); |
| 2124 | AudioDeviceTypeAddrVector devices; |
| 2125 | |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2126 | if (mAudioPolicyManager == nullptr) { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2127 | return binderStatusFromStatusT(NO_INIT); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2128 | } |
| 2129 | Mutex::Autolock _l(mLock); |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame^] | 2130 | RETURN_IF_BINDER_ERROR(binderStatusFromStatusT( |
| 2131 | mAudioPolicyManager->getDevicesForRoleAndCapturePreset(audioSource, role, devices))); |
| 2132 | *_aidl_return = VALUE_OR_RETURN_BINDER_STATUS( |
| 2133 | convertContainer<std::vector<media::AudioDevice>>(devices, |
| 2134 | legacy2aidl_AudioDeviceTypeAddress)); |
| 2135 | return Status::ok(); |
Jiabin Huang | 3b98d32 | 2020-09-03 17:54:16 +0000 | [diff] [blame] | 2136 | } |
| 2137 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 2138 | } // namespace android |