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