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