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