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