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