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