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