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