Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [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 | |
| 17 | #ifndef ANDROID_AUDIOPOLICYSERVICE_H |
| 18 | #define ANDROID_AUDIOPOLICYSERVICE_H |
| 19 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 20 | #include <android/media/BnAudioPolicyService.h> |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 21 | #include <android/media/GetSpatializerResponse.h> |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 22 | #include <android-base/thread_annotations.h> |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 23 | #include <audio_utils/mutex.h> |
Atneya Nair | 9f91a5e | 2024-05-09 16:25:05 -0700 | [diff] [blame] | 24 | #include <com/android/media/permission/INativePermissionController.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 25 | #include <cutils/misc.h> |
| 26 | #include <cutils/config_utils.h> |
Mathias Agopian | e762be9 | 2013-05-09 16:26:45 -0700 | [diff] [blame] | 27 | #include <cutils/compiler.h> |
Glenn Kasten | d1d8f23 | 2011-07-08 09:34:50 -0700 | [diff] [blame] | 28 | #include <utils/String8.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 29 | #include <utils/Vector.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 30 | #include <utils/SortedVector.h> |
Steven Moreland | 2f34814 | 2019-07-02 15:59:07 -0700 | [diff] [blame] | 31 | #include <binder/ActivityManager.h> |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 32 | #include <binder/BinderService.h> |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 33 | #include <binder/IUidObserver.h> |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 34 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 35 | #include <system/audio_policy.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 36 | #include <media/ToneGenerator.h> |
| 37 | #include <media/AudioEffect.h> |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 38 | #include <media/AudioPolicy.h> |
Atneya Nair | 87818d3 | 2024-05-23 10:59:30 -0700 | [diff] [blame] | 39 | #include <media/IAudioPolicyServiceLocal.h> |
Atneya Nair | 9f91a5e | 2024-05-09 16:25:05 -0700 | [diff] [blame] | 40 | #include <media/NativePermissionController.h> |
Eric Laurent | 0d13fea | 2022-11-04 17:12:08 +0100 | [diff] [blame] | 41 | #include <media/UsecaseValidator.h> |
Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 42 | #include <mediautils/ServiceUtilities.h> |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 43 | #include "AudioPolicyEffects.h" |
Ytai Ben-Tsvi | 1ef846b | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 44 | #include "CaptureStateNotifier.h" |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 45 | #include "Spatializer.h" |
François Gaffie | 962ba21 | 2019-04-03 16:21:39 +0200 | [diff] [blame] | 46 | #include <AudioPolicyInterface.h> |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 47 | #include <android/hardware/BnSensorPrivacyListener.h> |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 48 | #include <android/content/AttributionSourceState.h> |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 49 | |
Andy Hung | 6b137d1 | 2024-08-27 22:35:17 +0000 | [diff] [blame^] | 50 | #include <numeric> |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 51 | #include <unordered_map> |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 52 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 53 | namespace android { |
| 54 | |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 55 | using content::AttributionSourceState; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 56 | using media::audio::common::AudioConfig; |
| 57 | using media::audio::common::AudioConfigBase; |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 58 | using media::audio::common::AudioDevice; |
| 59 | using media::audio::common::AudioDeviceDescription; |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 60 | using media::audio::common::AudioFormatDescription; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 61 | using media::audio::common::AudioMode; |
| 62 | using media::audio::common::AudioSource; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 63 | using media::audio::common::AudioStreamType; |
| 64 | using media::audio::common::AudioUsage; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 65 | using media::audio::common::AudioUuid; |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 66 | using media::audio::common::Int; |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 67 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 68 | // ---------------------------------------------------------------------------- |
| 69 | |
Atneya Nair | 5b1ed64 | 2023-06-23 14:43:37 -0700 | [diff] [blame] | 70 | namespace media::audiopolicy { |
| 71 | class AudioRecordClient; |
| 72 | } |
| 73 | |
| 74 | using ::android::media::audiopolicy::AudioRecordClient; |
Atneya Nair | 9f91a5e | 2024-05-09 16:25:05 -0700 | [diff] [blame] | 75 | using ::com::android::media::permission::INativePermissionController; |
| 76 | using ::com::android::media::permission::NativePermissionController; |
Atneya Nair | 87818d3 | 2024-05-23 10:59:30 -0700 | [diff] [blame] | 77 | using ::com::android::media::permission::IPermissionProvider; |
Atneya Nair | 5b1ed64 | 2023-06-23 14:43:37 -0700 | [diff] [blame] | 78 | |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 79 | class AudioPolicyService : |
| 80 | public BinderService<AudioPolicyService>, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 81 | public media::BnAudioPolicyService, |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 82 | public IBinder::DeathRecipient, |
Atneya Nair | 87818d3 | 2024-05-23 10:59:30 -0700 | [diff] [blame] | 83 | public SpatializerPolicyCallback, |
| 84 | public media::IAudioPolicyServiceLocal |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 85 | { |
Andy Hung | 1d312b9 | 2023-01-03 16:12:50 -0800 | [diff] [blame] | 86 | friend class sp<AudioPolicyService>; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 87 | |
| 88 | public: |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 89 | // for BinderService |
Mathias Agopian | e762be9 | 2013-05-09 16:26:45 -0700 | [diff] [blame] | 90 | static const char *getServiceName() ANDROID_API { return "media.audio_policy"; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 91 | |
| 92 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 93 | |
| 94 | // |
| 95 | // BnAudioPolicyService (see AudioPolicyInterface for method descriptions) |
| 96 | // |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 97 | binder::Status onNewAudioModulesAvailable() override; |
| 98 | binder::Status setDeviceConnectionState( |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 99 | media::AudioPolicyDeviceState state, |
Nathalie Le Clair | 88fa275 | 2021-11-23 13:03:41 +0100 | [diff] [blame] | 100 | const android::media::audio::common::AudioPort& port, |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 101 | const AudioFormatDescription& encodedFormat) override; |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 102 | binder::Status getDeviceConnectionState(const AudioDevice& device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 103 | media::AudioPolicyDeviceState* _aidl_return) override; |
| 104 | binder::Status handleDeviceConfigChange( |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 105 | const AudioDevice& device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 106 | const std::string& deviceName, |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 107 | const AudioFormatDescription& encodedFormat) override; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 108 | binder::Status setPhoneState(AudioMode state, int32_t uid) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 109 | binder::Status setForceUse(media::AudioPolicyForceUse usage, |
| 110 | media::AudioPolicyForcedConfig config) override; |
| 111 | binder::Status getForceUse(media::AudioPolicyForceUse usage, |
| 112 | media::AudioPolicyForcedConfig* _aidl_return) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 113 | binder::Status getOutput(AudioStreamType stream, int32_t* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 114 | binder::Status getOutputForAttr(const media::audio::common::AudioAttributes& attr, |
| 115 | int32_t session, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 116 | const AttributionSourceState &attributionSource, |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 117 | const AudioConfig& config, |
Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 118 | int32_t flags, int32_t selectedDeviceId, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 119 | media::GetOutputForAttrResponse* _aidl_return) override; |
| 120 | binder::Status startOutput(int32_t portId) override; |
| 121 | binder::Status stopOutput(int32_t portId) override; |
| 122 | binder::Status releaseOutput(int32_t portId) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 123 | binder::Status getInputForAttr(const media::audio::common::AudioAttributes& attr, int32_t input, |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 124 | int32_t riid, int32_t session, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 125 | const AttributionSourceState &attributionSource, |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 126 | const AudioConfigBase& config, int32_t flags, |
Eric Laurent | f99edd3 | 2021-02-01 15:57:33 +0100 | [diff] [blame] | 127 | int32_t selectedDeviceId, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 128 | media::GetInputForAttrResponse* _aidl_return) override; |
| 129 | binder::Status startInput(int32_t portId) override; |
| 130 | binder::Status stopInput(int32_t portId) override; |
| 131 | binder::Status releaseInput(int32_t portId) override; |
Vlad Popa | 87e0e58 | 2024-05-20 18:49:20 -0700 | [diff] [blame] | 132 | binder::Status setDeviceAbsoluteVolumeEnabled(const AudioDevice& device, |
| 133 | bool enabled, |
| 134 | AudioStreamType streamToDriveAbs) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 135 | binder::Status initStreamVolume(AudioStreamType stream, int32_t indexMin, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 136 | int32_t indexMax) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 137 | binder::Status setStreamVolumeIndex(AudioStreamType stream, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 138 | const AudioDeviceDescription& device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 139 | int32_t index) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 140 | binder::Status getStreamVolumeIndex(AudioStreamType stream, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 141 | const AudioDeviceDescription& device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 142 | int32_t* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 143 | binder::Status setVolumeIndexForAttributes(const media::audio::common::AudioAttributes& attr, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 144 | const AudioDeviceDescription& device, |
Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 145 | int32_t index) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 146 | binder::Status getVolumeIndexForAttributes(const media::audio::common::AudioAttributes& attr, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 147 | const AudioDeviceDescription& device, |
Mikhail Naganov | 21a32ec | 2021-07-08 14:40:12 -0700 | [diff] [blame] | 148 | int32_t* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 149 | binder::Status getMaxVolumeIndexForAttributes(const media::audio::common::AudioAttributes& attr, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 150 | int32_t* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 151 | binder::Status getMinVolumeIndexForAttributes(const media::audio::common::AudioAttributes& attr, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 152 | int32_t* _aidl_return) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 153 | binder::Status getStrategyForStream(AudioStreamType stream, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 154 | int32_t* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 155 | binder::Status getDevicesForAttributes(const media::audio::common::AudioAttributes& attr, |
Andy Hung | 6d23c0f | 2022-02-16 09:37:15 -0800 | [diff] [blame] | 156 | bool forVolume, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 157 | std::vector<AudioDevice>* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 158 | binder::Status getOutputForEffect(const media::EffectDescriptor& desc, |
| 159 | int32_t* _aidl_return) override; |
| 160 | binder::Status registerEffect(const media::EffectDescriptor& desc, int32_t io, int32_t strategy, |
| 161 | int32_t session, int32_t id) override; |
| 162 | binder::Status unregisterEffect(int32_t id) override; |
| 163 | binder::Status setEffectEnabled(int32_t id, bool enabled) override; |
| 164 | binder::Status moveEffectsToIo(const std::vector<int32_t>& ids, int32_t io) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 165 | binder::Status isStreamActive(AudioStreamType stream, int32_t inPastMs, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 166 | bool* _aidl_return) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 167 | binder::Status isStreamActiveRemotely(AudioStreamType stream, int32_t inPastMs, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 168 | bool* _aidl_return) override; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 169 | binder::Status isSourceActive(AudioSource source, bool* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 170 | binder::Status queryDefaultPreProcessing( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 171 | int32_t audioSession, Int* count, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 172 | std::vector<media::EffectDescriptor>* _aidl_return) override; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 173 | binder::Status addSourceDefaultEffect(const AudioUuid& type, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 174 | const std::string& opPackageName, |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 175 | const AudioUuid& uuid, int32_t priority, |
| 176 | AudioSource source, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 177 | int32_t* _aidl_return) override; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 178 | binder::Status addStreamDefaultEffect(const AudioUuid& type, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 179 | const std::string& opPackageName, |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 180 | const AudioUuid& uuid, int32_t priority, |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 181 | AudioUsage usage, int32_t* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 182 | binder::Status removeSourceDefaultEffect(int32_t id) override; |
| 183 | binder::Status removeStreamDefaultEffect(int32_t id) override; |
| 184 | binder::Status setSupportedSystemUsages( |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 185 | const std::vector<AudioUsage>& systemUsages) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 186 | binder::Status setAllowedCapturePolicy(int32_t uid, int32_t capturePolicy) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 187 | binder::Status getOffloadSupport(const media::audio::common::AudioOffloadInfo& info, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 188 | media::AudioOffloadMode* _aidl_return) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 189 | binder::Status isDirectOutputSupported(const AudioConfigBase& config, |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 190 | const media::audio::common::AudioAttributes& attributes, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 191 | bool* _aidl_return) override; |
| 192 | binder::Status listAudioPorts(media::AudioPortRole role, media::AudioPortType type, |
Atneya Nair | 638a6e4 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 193 | Int* count, std::vector<media::AudioPortFw>* ports, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 194 | int32_t* _aidl_return) override; |
Mikhail Naganov | 5edc5ed | 2023-03-23 14:52:15 -0700 | [diff] [blame] | 195 | binder::Status listDeclaredDevicePorts(media::AudioPortRole role, |
| 196 | std::vector<media::AudioPortFw>* _aidl_return) override; |
Mikhail Naganov | 1703156 | 2022-02-23 23:00:27 +0000 | [diff] [blame] | 197 | binder::Status getAudioPort(int portId, |
Atneya Nair | 638a6e4 | 2022-12-18 16:45:15 -0800 | [diff] [blame] | 198 | media::AudioPortFw* _aidl_return) override; |
Atneya Nair | 3afdbd1 | 2022-12-18 16:14:18 -0800 | [diff] [blame] | 199 | binder::Status createAudioPatch(const media::AudioPatchFw& patch, int32_t handle, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 200 | int32_t* _aidl_return) override; |
| 201 | binder::Status releaseAudioPatch(int32_t handle) override; |
Atneya Nair | 3afdbd1 | 2022-12-18 16:14:18 -0800 | [diff] [blame] | 202 | binder::Status listAudioPatches(Int* count, std::vector<media::AudioPatchFw>* patches, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 203 | int32_t* _aidl_return) override; |
Atneya Nair | 7a9594f | 2022-12-18 17:26:26 -0800 | [diff] [blame] | 204 | binder::Status setAudioPortConfig(const media::AudioPortConfigFw& config) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 205 | binder::Status registerClient(const sp<media::IAudioPolicyServiceClient>& client) override; |
| 206 | binder::Status setAudioPortCallbacksEnabled(bool enabled) override; |
| 207 | binder::Status setAudioVolumeGroupCallbacksEnabled(bool enabled) override; |
| 208 | binder::Status acquireSoundTriggerSession(media::SoundTriggerSession* _aidl_return) override; |
| 209 | binder::Status releaseSoundTriggerSession(int32_t session) override; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 210 | binder::Status getPhoneState(AudioMode* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 211 | binder::Status registerPolicyMixes(const std::vector<media::AudioMix>& mixes, |
| 212 | bool registration) override; |
Jan Sebechlebsky | 0af8e87 | 2023-08-11 14:45:08 +0200 | [diff] [blame] | 213 | binder::Status updatePolicyMixes( |
| 214 | const ::std::vector<::android::media::AudioMixUpdate>& updates) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 215 | binder::Status setUidDeviceAffinities(int32_t uid, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 216 | const std::vector<AudioDevice>& devices) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 217 | binder::Status removeUidDeviceAffinities(int32_t uid) override; |
| 218 | binder::Status setUserIdDeviceAffinities( |
| 219 | int32_t userId, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 220 | const std::vector<AudioDevice>& devices) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 221 | binder::Status removeUserIdDeviceAffinities(int32_t userId) override; |
Atneya Nair | 7a9594f | 2022-12-18 17:26:26 -0800 | [diff] [blame] | 222 | binder::Status startAudioSource(const media::AudioPortConfigFw& source, |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 223 | const media::audio::common::AudioAttributes& attributes, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 224 | int32_t* _aidl_return) override; |
| 225 | binder::Status stopAudioSource(int32_t portId) override; |
| 226 | binder::Status setMasterMono(bool mono) override; |
| 227 | binder::Status getMasterMono(bool* _aidl_return) override; |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 228 | binder::Status getStreamVolumeDB(AudioStreamType stream, int32_t index, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 229 | const AudioDeviceDescription& device, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 230 | float* _aidl_return) override; |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 231 | binder::Status getSurroundFormats(Int* count, |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 232 | std::vector<AudioFormatDescription>* formats, |
Kriti Dang | 877b27e | 2021-02-02 12:10:40 +0100 | [diff] [blame] | 233 | std::vector<bool>* formatsEnabled) override; |
Kriti Dang | 6537def | 2021-03-02 13:46:59 +0100 | [diff] [blame] | 234 | binder::Status getReportedSurroundFormats( |
Mikhail Naganov | 0078ee5 | 2021-09-30 23:06:20 +0000 | [diff] [blame] | 235 | Int* count, std::vector<AudioFormatDescription>* formats) override; |
Patty | dd80758 | 2021-11-04 21:01:03 +0800 | [diff] [blame] | 236 | binder::Status getHwOffloadFormatsSupportedForBluetoothMedia( |
| 237 | const AudioDeviceDescription& device, |
Mikhail Naganov | 57bd06f | 2021-08-10 16:41:54 -0700 | [diff] [blame] | 238 | std::vector<AudioFormatDescription>* _aidl_return) override; |
| 239 | binder::Status setSurroundFormatEnabled(const AudioFormatDescription& audioFormat, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 240 | bool enabled) override; |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 241 | binder::Status setAssistantServicesUids(const std::vector<int32_t>& uids) override; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 242 | binder::Status setActiveAssistantServicesUids(const std::vector<int32_t>& activeUids) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 243 | binder::Status setA11yServicesUids(const std::vector<int32_t>& uids) override; |
| 244 | binder::Status setCurrentImeUid(int32_t uid) override; |
| 245 | binder::Status isHapticPlaybackSupported(bool* _aidl_return) override; |
Carter Hsu | 325a8eb | 2022-01-19 19:56:51 +0800 | [diff] [blame] | 246 | binder::Status isUltrasoundSupported(bool* _aidl_return) override; |
Atneya Nair | 698f5ef | 2022-12-15 16:15:09 -0800 | [diff] [blame] | 247 | binder::Status isHotwordStreamSupported(bool lookbackAudio, bool* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 248 | binder::Status listAudioProductStrategies( |
| 249 | std::vector<media::AudioProductStrategy>* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 250 | binder::Status getProductStrategyFromAudioAttributes( |
| 251 | const media::audio::common::AudioAttributes& aa, |
| 252 | bool fallbackOnDefault, |
| 253 | int32_t* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 254 | binder::Status listAudioVolumeGroups( |
| 255 | std::vector<media::AudioVolumeGroup>* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 256 | binder::Status getVolumeGroupFromAudioAttributes( |
| 257 | const media::audio::common::AudioAttributes& aa, |
| 258 | bool fallbackOnDefault, |
| 259 | int32_t* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 260 | binder::Status setRttEnabled(bool enabled) override; |
| 261 | binder::Status isCallScreenModeSupported(bool* _aidl_return) override; |
| 262 | binder::Status setDevicesRoleForStrategy( |
| 263 | int32_t strategy, media::DeviceRole role, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 264 | const std::vector<AudioDevice>& devices) override; |
Paul Wang | 5d7cdb5 | 2022-11-22 09:45:06 +0000 | [diff] [blame] | 265 | binder::Status removeDevicesRoleForStrategy( |
| 266 | int32_t strategy, media::DeviceRole role, |
| 267 | const std::vector<AudioDevice>& devices) override; |
| 268 | binder::Status clearDevicesRoleForStrategy( |
| 269 | int32_t strategy, |
| 270 | media::DeviceRole role) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 271 | binder::Status getDevicesForRoleAndStrategy( |
| 272 | int32_t strategy, media::DeviceRole role, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 273 | std::vector<AudioDevice>* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 274 | binder::Status setDevicesRoleForCapturePreset( |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 275 | AudioSource audioSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 276 | media::DeviceRole role, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 277 | const std::vector<AudioDevice>& devices) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 278 | binder::Status addDevicesRoleForCapturePreset( |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 279 | AudioSource audioSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 280 | media::DeviceRole role, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 281 | const std::vector<AudioDevice>& devices) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 282 | binder::Status removeDevicesRoleForCapturePreset( |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 283 | AudioSource audioSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 284 | media::DeviceRole role, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 285 | const std::vector<AudioDevice>& devices) override; |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 286 | binder::Status clearDevicesRoleForCapturePreset(AudioSource audioSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 287 | media::DeviceRole role) override; |
| 288 | binder::Status getDevicesForRoleAndCapturePreset( |
Mikhail Naganov | ddceecc | 2021-09-03 13:58:56 -0700 | [diff] [blame] | 289 | AudioSource audioSource, |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 290 | media::DeviceRole role, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 291 | std::vector<AudioDevice>* _aidl_return) override; |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 292 | binder::Status registerSoundTriggerCaptureStateListener( |
| 293 | const sp<media::ICaptureStateListener>& listener, bool* _aidl_return) override; |
Ari Hausman-Cohen | 433722e | 2018-04-24 14:25:22 -0700 | [diff] [blame] | 294 | |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 295 | binder::Status getSpatializer(const sp<media::INativeSpatializerCallback>& callback, |
| 296 | media::GetSpatializerResponse* _aidl_return) override; |
| 297 | binder::Status canBeSpatialized( |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 298 | const std::optional<media::audio::common::AudioAttributes>& attr, |
Mikhail Naganov | dbf0364 | 2021-08-25 18:15:32 -0700 | [diff] [blame] | 299 | const std::optional<AudioConfig>& config, |
Mikhail Naganov | f4a7536 | 2021-09-16 00:02:54 +0000 | [diff] [blame] | 300 | const std::vector<AudioDevice>& devices, |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 301 | bool* _aidl_return) override; |
| 302 | |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 303 | binder::Status getDirectPlaybackSupport(const media::audio::common::AudioAttributes& attr, |
jiabin | 2b9d5a1 | 2021-12-10 01:06:29 +0000 | [diff] [blame] | 304 | const AudioConfig& config, |
| 305 | media::AudioDirectMode* _aidl_return) override; |
| 306 | |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 307 | binder::Status getDirectProfilesForAttributes(const media::audio::common::AudioAttributes& attr, |
Dorin Drimus | f2196d8 | 2022-01-03 12:11:18 +0100 | [diff] [blame] | 308 | std::vector<media::audio::common::AudioProfile>* _aidl_return) override; |
| 309 | |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 310 | binder::Status getSupportedMixerAttributes( |
| 311 | int32_t portId, |
| 312 | std::vector<media::AudioMixerAttributesInternal>* _aidl_return) override; |
| 313 | binder::Status setPreferredMixerAttributes( |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 314 | const media::audio::common::AudioAttributes& attr, |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 315 | int32_t portId, |
| 316 | int32_t uid, |
| 317 | const media::AudioMixerAttributesInternal& mixerAttr) override; |
| 318 | binder::Status getPreferredMixerAttributes( |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 319 | const media::audio::common::AudioAttributes& attr, |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 320 | int32_t portId, |
| 321 | std::optional<media::AudioMixerAttributesInternal>* _aidl_return) override; |
Mikhail Naganov | 1c40090 | 2023-05-17 11:48:43 -0700 | [diff] [blame] | 322 | binder::Status clearPreferredMixerAttributes(const media::audio::common::AudioAttributes& attr, |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 323 | int32_t portId, |
| 324 | int32_t uid) override; |
Marvin Ramin | bdefaf0 | 2023-11-01 09:10:32 +0100 | [diff] [blame] | 325 | binder::Status getRegisteredPolicyMixes( |
| 326 | std::vector <::android::media::AudioMix>* mixes) override; |
jiabin | a84c3d3 | 2022-12-02 18:59:55 +0000 | [diff] [blame] | 327 | |
Atneya Nair | 9f91a5e | 2024-05-09 16:25:05 -0700 | [diff] [blame] | 328 | // Should only be called by AudioService to push permission data down to audioserver |
| 329 | binder::Status getPermissionController(sp<INativePermissionController>* out) override; |
| 330 | |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 331 | status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) override; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 332 | |
Atneya Nair | 87818d3 | 2024-05-23 10:59:30 -0700 | [diff] [blame] | 333 | // -- IAudioPolicyLocal methods |
| 334 | const IPermissionProvider& getPermissionProvider() const override; |
| 335 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 336 | // IBinder::DeathRecipient |
| 337 | virtual void binderDied(const wp<IBinder>& who); |
| 338 | |
Eric Laurent | f5ada6e | 2014-10-09 17:49:00 -0700 | [diff] [blame] | 339 | // RefBase |
| 340 | virtual void onFirstRef(); |
| 341 | |
Andy Hung | b08b375 | 2024-01-09 19:05:23 -0800 | [diff] [blame] | 342 | // Commence initialization when AudioSystem is ready. |
| 343 | void onAudioSystemReady(); |
| 344 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 345 | // |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 346 | // Helpers for the struct audio_policy_service_ops implementation. |
| 347 | // This is used by the audio policy manager for certain operations that |
| 348 | // are implemented by the policy service. |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 349 | // |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 350 | virtual void setParameters(audio_io_handle_t ioHandle, |
| 351 | const char *keyValuePairs, |
| 352 | int delayMs); |
| 353 | |
| 354 | virtual status_t setStreamVolume(audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 355 | float volume, |
| 356 | audio_io_handle_t output, |
| 357 | int delayMs = 0); |
Andy Hung | 6b137d1 | 2024-08-27 22:35:17 +0000 | [diff] [blame^] | 358 | |
| 359 | /** |
| 360 | * Set a volume on AudioTrack port id(s) for a particular output. |
| 361 | * For the same user setting, a volume group (and associated given port of the |
| 362 | * client's track) can have different volumes for each output destination device |
| 363 | * it is attached to. |
| 364 | * |
| 365 | * @param ports to consider |
| 366 | * @param volume to set |
| 367 | * @param output to consider |
| 368 | * @param delayMs to use |
| 369 | * @return NO_ERROR if successful |
| 370 | */ |
| 371 | virtual status_t setPortsVolume(const std::vector<audio_port_handle_t> &ports, float volume, |
| 372 | audio_io_handle_t output, int delayMs = 0); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 373 | virtual status_t setVoiceVolume(float volume, int delayMs = 0); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 374 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 375 | void doOnNewAudioModulesAvailable(); |
| 376 | status_t doStopOutput(audio_port_handle_t portId); |
| 377 | void doReleaseOutput(audio_port_handle_t portId); |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 378 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 379 | status_t clientCreateAudioPatch(const struct audio_patch *patch, |
| 380 | audio_patch_handle_t *handle, |
| 381 | int delayMs); |
| 382 | status_t clientReleaseAudioPatch(audio_patch_handle_t handle, |
| 383 | int delayMs); |
| 384 | virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config, |
| 385 | int delayMs); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 386 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 387 | void removeNotificationClient(uid_t uid, pid_t pid); |
| 388 | void onAudioPortListUpdate(); |
| 389 | void doOnAudioPortListUpdate(); |
| 390 | void onAudioPatchListUpdate(); |
| 391 | void doOnAudioPatchListUpdate(); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 392 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 393 | void onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state); |
| 394 | void doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state); |
| 395 | void onRecordingConfigurationUpdate(int event, |
| 396 | const record_client_info_t *clientInfo, |
| 397 | const audio_config_base_t *clientConfig, |
| 398 | std::vector<effect_descriptor_t> clientEffects, |
| 399 | const audio_config_base_t *deviceConfig, |
| 400 | std::vector<effect_descriptor_t> effects, |
| 401 | audio_patch_handle_t patchHandle, |
| 402 | audio_source_t source); |
| 403 | void doOnRecordingConfigurationUpdate(int event, |
| 404 | const record_client_info_t *clientInfo, |
| 405 | const audio_config_base_t *clientConfig, |
| 406 | std::vector<effect_descriptor_t> clientEffects, |
| 407 | const audio_config_base_t *deviceConfig, |
| 408 | std::vector<effect_descriptor_t> effects, |
| 409 | audio_patch_handle_t patchHandle, |
| 410 | audio_source_t source); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 411 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 412 | void onAudioVolumeGroupChanged(volume_group_t group, int flags); |
| 413 | void doOnAudioVolumeGroupChanged(volume_group_t group, int flags); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 414 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 415 | void onRoutingUpdated(); |
| 416 | void doOnRoutingUpdated(); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 417 | |
Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 418 | void onVolumeRangeInitRequest(); |
| 419 | void doOnVolumeRangeInitRequest(); |
| 420 | |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 421 | /** |
| 422 | * Spatializer SpatializerPolicyCallback implementation. |
| 423 | * onCheckSpatializer() sends an event on mOutputCommandThread which executes |
| 424 | * doOnCheckSpatializer() to check if a Spatializer output must be opened or closed |
| 425 | * by audio policy manager and attach/detach the spatializer effect accordingly. |
| 426 | */ |
| 427 | void onCheckSpatializer() override; |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 428 | void onCheckSpatializer_l() REQUIRES(mMutex); |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 429 | void doOnCheckSpatializer(); |
| 430 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 431 | void onUpdateActiveSpatializerTracks_l() REQUIRES(mMutex); |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 432 | void doOnUpdateActiveSpatializerTracks(); |
| 433 | |
| 434 | |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 435 | void setEffectSuspended(int effectId, |
| 436 | audio_session_t sessionId, |
| 437 | bool suspended); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 438 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 439 | private: |
Mathias Agopian | e762be9 | 2013-05-09 16:26:45 -0700 | [diff] [blame] | 440 | AudioPolicyService() ANDROID_API; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 441 | virtual ~AudioPolicyService(); |
| 442 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 443 | status_t dumpInternals(int fd) REQUIRES(mMutex); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 444 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 445 | // Handles binder shell commands |
| 446 | virtual status_t shellCommand(int in, int out, int err, Vector<String16>& args); |
| 447 | |
Eric Laurent | 8c7ef89 | 2021-06-10 13:32:16 +0200 | [diff] [blame] | 448 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 449 | // Sets whether the given UID records only silence |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 450 | virtual void setAppState_l(sp<AudioRecordClient> client, app_state_t state) REQUIRES(mMutex); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 451 | |
| 452 | // Overrides the UID state as if it is idle |
| 453 | status_t handleSetUidState(Vector<String16>& args, int err); |
| 454 | |
| 455 | // Clears the override for the UID state |
| 456 | status_t handleResetUidState(Vector<String16>& args, int err); |
| 457 | |
| 458 | // Gets the UID state |
| 459 | status_t handleGetUidState(Vector<String16>& args, int out, int err); |
| 460 | |
| 461 | // Prints the shell command help |
| 462 | status_t printHelp(int out); |
| 463 | |
Eric Laurent | 99fcae4 | 2018-05-17 16:59:18 -0700 | [diff] [blame] | 464 | std::string getDeviceTypeStrForPortId(audio_port_handle_t portId); |
| 465 | |
Ari Hausman-Cohen | 2462831 | 2018-08-13 15:01:09 -0700 | [diff] [blame] | 466 | status_t getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects); |
| 467 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 468 | app_state_t apmStatFromAmState(int amState); |
| 469 | |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 470 | bool isSupportedSystemUsage(audio_usage_t usage); |
Atneya Nair | 09859fe | 2024-07-15 16:38:02 -0700 | [diff] [blame] | 471 | binder::Status validateUsage(const audio_attributes_t& attr); |
| 472 | binder::Status validateUsage(const audio_attributes_t& attr, |
Eric Laurent | b0eff0f | 2021-11-09 16:05:49 +0100 | [diff] [blame] | 473 | const AttributionSourceState& attributionSource); |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 474 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 475 | void updateUidStates(); |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 476 | void updateUidStates_l() REQUIRES(mMutex); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 477 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 478 | void silenceAllRecordings_l() REQUIRES(mMutex); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 479 | |
Eric Laurent | 2dc962b | 2019-03-01 08:25:25 -0800 | [diff] [blame] | 480 | static bool isVirtualSource(audio_source_t source); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 481 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 482 | /** returns true if the audio source must be silenced when the corresponding app op is denied. |
| 483 | * false if the audio source does not actually capture from the microphone while still |
| 484 | * being mapped to app op OP_RECORD_AUDIO and not a specialized op tracked separately. |
| 485 | * See getOpForSource(). |
| 486 | */ |
| 487 | static bool isAppOpSource(audio_source_t source); |
| 488 | |
Eric Laurent | 0d13fea | 2022-11-04 17:12:08 +0100 | [diff] [blame] | 489 | status_t registerOutput(audio_io_handle_t output, |
| 490 | const audio_config_base_t& config, |
| 491 | const audio_output_flags_t flags); |
| 492 | status_t unregisterOutput(audio_io_handle_t output); |
| 493 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 494 | // If recording we need to make sure the UID is allowed to do that. If the UID is idle |
| 495 | // then it cannot record and gets buffers with zeros - silence. As soon as the UID |
| 496 | // transitions to an active state we will start reporting buffers with data. This approach |
| 497 | // transparently handles recording while the UID transitions between idle/active state |
| 498 | // avoiding to get stuck in a state receiving non-empty buffers while idle or in a state |
| 499 | // receiving empty buffers while active. |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 500 | class UidPolicy : public BnUidObserver, public virtual IBinder::DeathRecipient { |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 501 | public: |
| 502 | explicit UidPolicy(wp<AudioPolicyService> service) |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 503 | : mService(service), mObserverRegistered(false), |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 504 | mCurrentImeUid(0), |
Ahaan Ugale | f51ce00 | 2021-08-04 16:34:20 -0700 | [diff] [blame] | 505 | mRttEnabled(false) {} |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 506 | |
| 507 | void registerSelf(); |
| 508 | void unregisterSelf(); |
| 509 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 510 | // IBinder::DeathRecipient implementation |
| 511 | void binderDied(const wp<IBinder> &who) override; |
| 512 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 513 | bool isUidActive(uid_t uid); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 514 | int getUidState(uid_t uid); |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 515 | void setAssistantUids(const std::vector<uid_t>& uids); |
| 516 | bool isAssistantUid(uid_t uid); |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 517 | void setActiveAssistantUids(const std::vector<uid_t>& activeUids); |
| 518 | bool isActiveAssistantUid(uid_t uid); |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 519 | void setA11yUids(const std::vector<uid_t>& uids) { mA11yUids.clear(); mA11yUids = uids; } |
| 520 | bool isA11yUid(uid_t uid); |
Eric Laurent | 4eb58f1 | 2018-12-07 16:41:02 -0800 | [diff] [blame] | 521 | bool isA11yOnTop(); |
Kohsuke Yatoh | a623a13 | 2020-03-24 20:10:26 -0700 | [diff] [blame] | 522 | void setCurrentImeUid(uid_t uid) { mCurrentImeUid = uid; } |
| 523 | bool isCurrentImeUid(uid_t uid) { return uid == mCurrentImeUid; } |
Eric Laurent | 6ede98f | 2019-06-11 14:50:30 -0700 | [diff] [blame] | 524 | void setRttEnabled(bool enabled) { mRttEnabled = enabled; } |
| 525 | bool isRttEnabled() { return mRttEnabled; } |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 526 | |
Mikhail Naganov | eae73eb | 2018-04-03 16:57:36 -0700 | [diff] [blame] | 527 | // BnUidObserver implementation |
| 528 | void onUidActive(uid_t uid) override; |
| 529 | void onUidGone(uid_t uid, bool disabled) override; |
| 530 | void onUidIdle(uid_t uid, bool disabled) override; |
Hui Yu | 13ad0eb | 2019-09-09 10:27:07 -0700 | [diff] [blame] | 531 | void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq, |
Austin Borger | 6557768 | 2022-02-17 00:25:43 +0000 | [diff] [blame] | 532 | int32_t capability) override; |
Austin Borger | dddb755 | 2023-03-30 17:53:01 -0700 | [diff] [blame] | 533 | void onUidProcAdjChanged(uid_t uid, int32_t adj) override; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 534 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 535 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 536 | void updateUid(std::unordered_map<uid_t, std::pair<bool, int>> *uids, |
| 537 | uid_t uid, bool active, int state, bool insert); |
| 538 | |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 539 | void dumpInternals(int fd); |
| 540 | |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 541 | private: |
| 542 | void notifyService(); |
Eric Laurent | e8c8b43 | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 543 | void updateUidLocked(std::unordered_map<uid_t, std::pair<bool, int>> *uids, |
| 544 | uid_t uid, bool active, int state, bool insert); |
| 545 | void checkRegistered(); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 546 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 547 | wp<AudioPolicyService> mService; |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 548 | audio_utils::mutex mMutex{audio_utils::MutexOrder::kUidPolicy_Mutex}; |
Steven Moreland | 2f34814 | 2019-07-02 15:59:07 -0700 | [diff] [blame] | 549 | ActivityManager mAm; |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 550 | bool mObserverRegistered = false; |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 551 | std::unordered_map<uid_t, std::pair<bool, int>> mCachedUids GUARDED_BY(mMutex); |
Oscar Azucena | 829d90d | 2022-01-28 17:17:56 -0800 | [diff] [blame] | 552 | std::vector<uid_t> mAssistantUids; |
Oscar Azucena | c2cdda3 | 2022-01-31 19:10:39 -0800 | [diff] [blame] | 553 | std::vector<uid_t> mActiveAssistantUids; |
Eric Laurent | b78763e | 2018-10-17 10:08:02 -0700 | [diff] [blame] | 554 | std::vector<uid_t> mA11yUids; |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 555 | uid_t mCurrentImeUid = -1; |
| 556 | bool mRttEnabled = false; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 557 | }; |
| 558 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 559 | // If sensor privacy is enabled then all apps, including those that are active, should be |
| 560 | // prevented from recording. This is handled similar to idle UIDs, any app that attempts |
| 561 | // to record while sensor privacy is enabled will receive buffers with zeros. As soon as |
| 562 | // sensor privacy is disabled active apps will receive the expected data when recording. |
| 563 | class SensorPrivacyPolicy : public hardware::BnSensorPrivacyListener { |
| 564 | public: |
| 565 | explicit SensorPrivacyPolicy(wp<AudioPolicyService> service) |
| 566 | : mService(service) {} |
| 567 | |
| 568 | void registerSelf(); |
| 569 | void unregisterSelf(); |
| 570 | |
| 571 | bool isSensorPrivacyEnabled(); |
| 572 | |
Evan Severson | d8dc683 | 2022-01-27 10:47:03 -0800 | [diff] [blame] | 573 | binder::Status onSensorPrivacyChanged(int toggleType, int sensor, |
| 574 | bool enabled); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 575 | |
Jyoti Bhayana | c05a119 | 2024-02-11 13:19:29 +0000 | [diff] [blame] | 576 | binder::Status onSensorPrivacyStateChanged(int, int, int) { |
| 577 | return binder::Status::ok(); |
| 578 | } |
| 579 | |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 580 | private: |
| 581 | wp<AudioPolicyService> mService; |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 582 | std::atomic_bool mSensorPrivacyEnabled = false; |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 583 | }; |
| 584 | |
Eric Laurent | dcd4ab1 | 2018-06-29 17:45:13 -0700 | [diff] [blame] | 585 | // Thread used to send audio config commands to audio flinger |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 586 | // For audio config commands, it is necessary because audio flinger requires that the calling |
| 587 | // process (user) has permission to modify audio settings. |
Atneya Nair | 5b1ed64 | 2023-06-23 14:43:37 -0700 | [diff] [blame] | 588 | public: |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 589 | class AudioCommandThread : public Thread { |
| 590 | class AudioCommand; |
| 591 | public: |
| 592 | |
| 593 | // commands for tone AudioCommand |
| 594 | enum { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 595 | SET_VOLUME, |
Andy Hung | 6b137d1 | 2024-08-27 22:35:17 +0000 | [diff] [blame^] | 596 | SET_PORTS_VOLUME, |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 597 | SET_PARAMETERS, |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 598 | SET_VOICE_VOLUME, |
| 599 | STOP_OUTPUT, |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 600 | RELEASE_OUTPUT, |
| 601 | CREATE_AUDIO_PATCH, |
| 602 | RELEASE_AUDIO_PATCH, |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 603 | UPDATE_AUDIOPORT_LIST, |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 604 | UPDATE_AUDIOPATCH_LIST, |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 605 | CHANGED_AUDIOVOLUMEGROUP, |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 606 | SET_AUDIOPORT_CONFIG, |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 607 | DYN_POLICY_MIX_STATE_UPDATE, |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 608 | RECORDING_CONFIGURATION_UPDATE, |
| 609 | SET_EFFECT_SUSPENDED, |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 610 | AUDIO_MODULES_UPDATE, |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 611 | ROUTING_UPDATED, |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 612 | UPDATE_UID_STATES, |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 613 | CHECK_SPATIALIZER_OUTPUT, // verify if spatializer effect should be created or moved |
Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 614 | UPDATE_ACTIVE_SPATIALIZER_TRACKS, // Update active track counts on spalializer output |
| 615 | VOL_RANGE_INIT_REQUEST, // request to reset the volume range indices |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 616 | }; |
| 617 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 618 | AudioCommandThread (String8 name, const wp<AudioPolicyService>& service); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 619 | virtual ~AudioCommandThread(); |
| 620 | |
| 621 | status_t dump(int fd); |
| 622 | |
| 623 | // Thread virtuals |
| 624 | virtual void onFirstRef(); |
| 625 | virtual bool threadLoop(); |
| 626 | |
| 627 | void exit(); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 628 | status_t volumeCommand(audio_stream_type_t stream, float volume, |
| 629 | audio_io_handle_t output, int delayMs = 0); |
Andy Hung | 6b137d1 | 2024-08-27 22:35:17 +0000 | [diff] [blame^] | 630 | status_t volumePortsCommand(const std::vector<audio_port_handle_t> &ports, |
| 631 | float volume, audio_io_handle_t output, int delayMs = 0); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 632 | status_t parametersCommand(audio_io_handle_t ioHandle, |
| 633 | const char *keyValuePairs, int delayMs = 0); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 634 | status_t voiceVolumeCommand(float volume, int delayMs = 0); |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 635 | void stopOutputCommand(audio_port_handle_t portId); |
| 636 | void releaseOutputCommand(audio_port_handle_t portId); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 637 | status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0); |
| 638 | void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 639 | status_t createAudioPatchCommand(const struct audio_patch *patch, |
| 640 | audio_patch_handle_t *handle, |
| 641 | int delayMs); |
| 642 | status_t releaseAudioPatchCommand(audio_patch_handle_t handle, |
| 643 | int delayMs); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 644 | void updateAudioPortListCommand(); |
| 645 | void updateAudioPatchListCommand(); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 646 | void changeAudioVolumeGroupCommand(volume_group_t group, int flags); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 647 | status_t setAudioPortConfigCommand(const struct audio_port_config *config, |
| 648 | int delayMs); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 649 | void dynamicPolicyMixStateUpdateCommand(const String8& regId, |
| 650 | int32_t state); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 651 | void recordingConfigurationUpdateCommand( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 652 | int event, |
| 653 | const record_client_info_t *clientInfo, |
| 654 | const audio_config_base_t *clientConfig, |
| 655 | std::vector<effect_descriptor_t> clientEffects, |
| 656 | const audio_config_base_t *deviceConfig, |
| 657 | std::vector<effect_descriptor_t> effects, |
| 658 | audio_patch_handle_t patchHandle, |
| 659 | audio_source_t source); |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 660 | void setEffectSuspendedCommand(int effectId, |
| 661 | audio_session_t sessionId, |
| 662 | bool suspended); |
Mikhail Naganov | 88b30d2 | 2020-03-09 19:43:13 +0000 | [diff] [blame] | 663 | void audioModulesUpdateCommand(); |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 664 | void routingChangedCommand(); |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 665 | void updateUidStatesCommand(); |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 666 | void checkSpatializerCommand(); |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 667 | void updateActiveSpatializerTracksCommand(); |
Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 668 | void volRangeInitReqCommand(); |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 669 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 670 | void insertCommand_l(AudioCommand *command, int delayMs = 0); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 671 | private: |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 672 | class AudioCommandData; |
| 673 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 674 | // descriptor for requested tone playback event |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 675 | class AudioCommand: public RefBase { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 676 | |
| 677 | public: |
| 678 | AudioCommand() |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 679 | : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {} |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 680 | |
| 681 | void dump(char* buffer, size_t size); |
| 682 | |
Eric Laurent | dcd4ab1 | 2018-06-29 17:45:13 -0700 | [diff] [blame] | 683 | int mCommand; // SET_VOLUME, SET_PARAMETERS... |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 684 | nsecs_t mTime; // time stamp |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 685 | audio_utils::mutex mMutex{audio_utils::MutexOrder::kAudioCommand_Mutex}; |
| 686 | audio_utils::condition_variable mCond; // condition for status return |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 687 | status_t mStatus; // command status |
| 688 | bool mWaitStatus; // true if caller is waiting for status |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 689 | sp<AudioCommandData> mParam; // command specific parameter data |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 690 | }; |
| 691 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 692 | class AudioCommandData: public RefBase { |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 693 | public: |
| 694 | virtual ~AudioCommandData() {} |
| 695 | protected: |
| 696 | AudioCommandData() {} |
| 697 | }; |
| 698 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 699 | class VolumeData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 700 | public: |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 701 | audio_stream_type_t mStream; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 702 | float mVolume; |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 703 | audio_io_handle_t mIO; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 704 | }; |
| 705 | |
Andy Hung | 6b137d1 | 2024-08-27 22:35:17 +0000 | [diff] [blame^] | 706 | class VolumePortsData : public AudioCommandData { |
| 707 | public: |
| 708 | std::vector<audio_port_handle_t> mPorts; |
| 709 | float mVolume; |
| 710 | audio_io_handle_t mIO; |
| 711 | std::string dumpPorts() { |
| 712 | return std::string("volume ") + std::to_string(mVolume) + " on IO " + |
| 713 | std::to_string(mIO) + " and ports " + |
| 714 | std::accumulate(std::begin(mPorts), std::end(mPorts), std::string{}, |
| 715 | [] (const std::string& ls, int rs) { |
| 716 | return ls + std::to_string(rs) + " "; }); |
| 717 | } |
| 718 | }; |
| 719 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 720 | class ParametersData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 721 | public: |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 722 | audio_io_handle_t mIO; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 723 | String8 mKeyValuePairs; |
| 724 | }; |
| 725 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 726 | class VoiceVolumeData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 727 | public: |
| 728 | float mVolume; |
| 729 | }; |
| 730 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 731 | class StopOutputData : public AudioCommandData { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 732 | public: |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 733 | audio_port_handle_t mPortId; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 734 | }; |
| 735 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 736 | class ReleaseOutputData : public AudioCommandData { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 737 | public: |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 738 | audio_port_handle_t mPortId; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 739 | }; |
| 740 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 741 | class CreateAudioPatchData : public AudioCommandData { |
| 742 | public: |
| 743 | struct audio_patch mPatch; |
| 744 | audio_patch_handle_t mHandle; |
| 745 | }; |
| 746 | |
| 747 | class ReleaseAudioPatchData : public AudioCommandData { |
| 748 | public: |
| 749 | audio_patch_handle_t mHandle; |
| 750 | }; |
| 751 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 752 | class AudioVolumeGroupData : public AudioCommandData { |
| 753 | public: |
| 754 | volume_group_t mGroup; |
| 755 | int mFlags; |
| 756 | }; |
| 757 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 758 | class SetAudioPortConfigData : public AudioCommandData { |
| 759 | public: |
| 760 | struct audio_port_config mConfig; |
| 761 | }; |
| 762 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 763 | class DynPolicyMixStateUpdateData : public AudioCommandData { |
| 764 | public: |
| 765 | String8 mRegId; |
| 766 | int32_t mState; |
| 767 | }; |
| 768 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 769 | class RecordingConfigurationUpdateData : public AudioCommandData { |
| 770 | public: |
| 771 | int mEvent; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 772 | record_client_info_t mClientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 773 | struct audio_config_base mClientConfig; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 774 | std::vector<effect_descriptor_t> mClientEffects; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 775 | struct audio_config_base mDeviceConfig; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 776 | std::vector<effect_descriptor_t> mEffects; |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 777 | audio_patch_handle_t mPatchHandle; |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 778 | audio_source_t mSource; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 779 | }; |
| 780 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 781 | class SetEffectSuspendedData : public AudioCommandData { |
| 782 | public: |
| 783 | int mEffectId; |
| 784 | audio_session_t mSessionId; |
| 785 | bool mSuspended; |
| 786 | }; |
| 787 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 788 | mutable audio_utils::mutex mMutex{audio_utils::MutexOrder::kCommandThread_Mutex}; |
| 789 | audio_utils::condition_variable mWaitWorkCV; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 790 | Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 791 | sp<AudioCommand> mLastCommand; // last processed command (used by dump) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 792 | String8 mName; // string used by wake lock fo delayed commands |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 793 | wp<AudioPolicyService> mService; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 794 | }; |
| 795 | |
Atneya Nair | 5b1ed64 | 2023-06-23 14:43:37 -0700 | [diff] [blame] | 796 | private: |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 797 | class AudioPolicyClient : public AudioPolicyClientInterface |
| 798 | { |
| 799 | public: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 800 | explicit AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {} |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 801 | virtual ~AudioPolicyClient() {} |
| 802 | |
Mikhail Naganov | ffd9771 | 2023-05-03 17:45:36 -0700 | [diff] [blame] | 803 | virtual status_t getAudioPolicyConfig(media::AudioPolicyConfig *config); |
| 804 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 805 | // |
| 806 | // Audio HW module functions |
| 807 | // |
| 808 | |
| 809 | // loads a HW module. |
| 810 | virtual audio_module_handle_t loadHwModule(const char *name); |
| 811 | |
| 812 | // |
| 813 | // Audio output Control functions |
| 814 | // |
| 815 | |
| 816 | // opens an audio output with the requested parameters. The parameter values can indicate to use the default values |
| 817 | // in case the audio policy manager has no specific requirements for the output being opened. |
| 818 | // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. |
| 819 | // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly. |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 820 | virtual status_t openOutput(audio_module_handle_t module, |
| 821 | audio_io_handle_t *output, |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 822 | audio_config_t *halConfig, |
| 823 | audio_config_base_t *mixerConfig, |
jiabin | 4381040 | 2019-10-24 14:58:31 -0700 | [diff] [blame] | 824 | const sp<DeviceDescriptorBase>& device, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 825 | uint32_t *latencyMs, |
Haofan Wang | f6e304f | 2024-07-09 23:06:58 -0700 | [diff] [blame] | 826 | audio_output_flags_t flags, |
| 827 | audio_attributes_t attributes); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 828 | // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by |
| 829 | // a special mixer thread in the AudioFlinger. |
| 830 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2); |
| 831 | // closes the output stream |
| 832 | virtual status_t closeOutput(audio_io_handle_t output); |
| 833 | // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in |
| 834 | // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded. |
| 835 | virtual status_t suspendOutput(audio_io_handle_t output); |
| 836 | // restores a suspended output. |
| 837 | virtual status_t restoreOutput(audio_io_handle_t output); |
| 838 | |
| 839 | // |
| 840 | // Audio input Control functions |
| 841 | // |
| 842 | |
| 843 | // opens an audio input |
| 844 | virtual audio_io_handle_t openInput(audio_module_handle_t module, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 845 | audio_io_handle_t *input, |
| 846 | audio_config_t *config, |
| 847 | audio_devices_t *devices, |
| 848 | const String8& address, |
| 849 | audio_source_t source, |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame] | 850 | audio_input_flags_t flags); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 851 | // closes an audio input |
| 852 | virtual status_t closeInput(audio_io_handle_t input); |
| 853 | // |
| 854 | // misc control functions |
| 855 | // |
| 856 | |
| 857 | // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes |
| 858 | // for each output (destination device) it is attached to. |
| 859 | virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0); |
Andy Hung | 6b137d1 | 2024-08-27 22:35:17 +0000 | [diff] [blame^] | 860 | /** |
| 861 | * Set a volume on port(s) for a particular output. For the same user setting, a volume |
| 862 | * group (and associated given port of the client's track) can have different volumes for |
| 863 | * each output (destination device) it is attached to. |
| 864 | * |
| 865 | * @param ports to consider |
| 866 | * @param volume to set |
| 867 | * @param output to consider |
| 868 | * @param delayMs to use |
| 869 | * @return NO_ERROR if successful |
| 870 | */ |
| 871 | status_t setPortsVolume(const std::vector<audio_port_handle_t> &ports, float volume, |
| 872 | audio_io_handle_t output, int delayMs = 0) override; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 873 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 874 | // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface. |
| 875 | virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0); |
| 876 | // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager. |
| 877 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys); |
| 878 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 879 | // set down link audio volume. |
| 880 | virtual status_t setVoiceVolume(float volume, int delayMs = 0); |
| 881 | |
| 882 | // move effect to the specified output |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 883 | virtual status_t moveEffects(audio_session_t session, |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 884 | audio_io_handle_t srcOutput, |
| 885 | audio_io_handle_t dstOutput); |
| 886 | |
Eric Laurent | b20cf7d | 2019-04-05 19:37:34 -0700 | [diff] [blame] | 887 | void setEffectSuspended(int effectId, |
| 888 | audio_session_t sessionId, |
| 889 | bool suspended) override; |
| 890 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 891 | /* Create a patch between several source and sink ports */ |
| 892 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 893 | audio_patch_handle_t *handle, |
| 894 | int delayMs); |
| 895 | |
| 896 | /* Release a patch */ |
| 897 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 898 | int delayMs); |
| 899 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 900 | /* Set audio port configuration */ |
| 901 | virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs); |
| 902 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 903 | virtual void onAudioPortListUpdate(); |
| 904 | virtual void onAudioPatchListUpdate(); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 905 | virtual void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 906 | virtual void onRecordingConfigurationUpdate(int event, |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 907 | const record_client_info_t *clientInfo, |
| 908 | const audio_config_base_t *clientConfig, |
| 909 | std::vector<effect_descriptor_t> clientEffects, |
| 910 | const audio_config_base_t *deviceConfig, |
| 911 | std::vector<effect_descriptor_t> effects, |
| 912 | audio_patch_handle_t patchHandle, |
| 913 | audio_source_t source); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 914 | |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 915 | virtual void onAudioVolumeGroupChanged(volume_group_t group, int flags); |
| 916 | |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 917 | virtual void onRoutingUpdated(); |
| 918 | |
Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 919 | virtual void onVolumeRangeInitRequest(); |
| 920 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 921 | virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use); |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 922 | |
Ytai Ben-Tsvi | 74cd6b0 | 2019-10-25 10:06:40 -0700 | [diff] [blame] | 923 | void setSoundTriggerCaptureState(bool active) override; |
| 924 | |
jiabin | b4fed19 | 2020-09-22 14:45:40 -0700 | [diff] [blame] | 925 | status_t getAudioPort(struct audio_port_v7 *port) override; |
| 926 | |
jiabin | 10a03f1 | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 927 | status_t updateSecondaryOutputs( |
| 928 | const TrackSecondaryOutputsMap& trackSecondaryOutputs) override; |
| 929 | |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 930 | status_t setDeviceConnectedState( |
jiabin | c004863 | 2023-04-27 22:04:31 +0000 | [diff] [blame] | 931 | const struct audio_port_v7 *port, media::DeviceConnectedState state) override; |
Mikhail Naganov | 516d398 | 2022-02-01 23:53:59 +0000 | [diff] [blame] | 932 | |
jiabin | c44b346 | 2022-12-08 12:52:31 -0800 | [diff] [blame] | 933 | status_t invalidateTracks(const std::vector<audio_port_handle_t>& portIds) override; |
| 934 | |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame] | 935 | status_t getAudioMixPort(const struct audio_port_v7 *devicePort, |
| 936 | struct audio_port_v7 *port) override; |
| 937 | |
jiabin | 220eea1 | 2024-05-17 17:55:20 +0000 | [diff] [blame] | 938 | status_t setTracksInternalMute( |
| 939 | const std::vector<media::TrackInternalMuteInfo>& tracksInternalMute) override; |
| 940 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 941 | private: |
| 942 | AudioPolicyService *mAudioPolicyService; |
| 943 | }; |
| 944 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 945 | // --- Notification Client --- |
| 946 | class NotificationClient : public IBinder::DeathRecipient { |
| 947 | public: |
| 948 | NotificationClient(const sp<AudioPolicyService>& service, |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 949 | const sp<media::IAudioPolicyServiceClient>& client, |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 950 | uid_t uid, pid_t pid); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 951 | virtual ~NotificationClient(); |
| 952 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 953 | void onAudioPortListUpdate(); |
| 954 | void onAudioPatchListUpdate(); |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 955 | void onDynamicPolicyMixStateUpdate(const String8& regId, |
| 956 | int32_t state); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 957 | void onAudioVolumeGroupChanged(volume_group_t group, int flags); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 958 | void onRecordingConfigurationUpdate( |
Eric Laurent | a9f8665 | 2018-11-28 17:23:11 -0800 | [diff] [blame] | 959 | int event, |
| 960 | const record_client_info_t *clientInfo, |
| 961 | const audio_config_base_t *clientConfig, |
| 962 | std::vector<effect_descriptor_t> clientEffects, |
| 963 | const audio_config_base_t *deviceConfig, |
| 964 | std::vector<effect_descriptor_t> effects, |
| 965 | audio_patch_handle_t patchHandle, |
| 966 | audio_source_t source); |
Jean-Michel Trivi | 9a6b9ad | 2020-10-22 16:46:43 -0700 | [diff] [blame] | 967 | void onRoutingUpdated(); |
Jean-Michel Trivi | 78f2b30 | 2022-04-15 18:18:41 +0000 | [diff] [blame] | 968 | void onVolumeRangeInitRequest(); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 969 | void setAudioPortCallbacksEnabled(bool enabled); |
François Gaffie | cfe1732 | 2018-11-07 13:41:29 +0100 | [diff] [blame] | 970 | void setAudioVolumeGroupCallbacksEnabled(bool enabled); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 971 | |
luochaojiang | 908c7d7 | 2018-06-21 14:58:04 +0800 | [diff] [blame] | 972 | uid_t uid() { |
| 973 | return mUid; |
| 974 | } |
| 975 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 976 | // IBinder::DeathRecipient |
| 977 | virtual void binderDied(const wp<IBinder>& who); |
| 978 | |
| 979 | private: |
| 980 | NotificationClient(const NotificationClient&); |
| 981 | NotificationClient& operator = (const NotificationClient&); |
| 982 | |
Ytai Ben-Tsvi | 7e7a79d | 2020-12-15 16:48:16 -0800 | [diff] [blame] | 983 | const wp<AudioPolicyService> mService; |
| 984 | const uid_t mUid; |
| 985 | const pid_t mPid; |
| 986 | const sp<media::IAudioPolicyServiceClient> mAudioPolicyServiceClient; |
| 987 | bool mAudioPortCallbacksEnabled; |
| 988 | bool mAudioVolumeGroupCallbacksEnabled; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 989 | }; |
| 990 | |
Atneya Nair | 5b1ed64 | 2023-06-23 14:43:37 -0700 | [diff] [blame] | 991 | public: |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 992 | class AudioClient : public virtual RefBase { |
| 993 | public: |
| 994 | AudioClient(const audio_attributes_t attributes, |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 995 | const audio_io_handle_t io, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 996 | const AttributionSourceState& attributionSource, |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 997 | const audio_session_t session, audio_port_handle_t portId, |
| 998 | const audio_port_handle_t deviceId) : |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 999 | attributes(attributes), io(io), attributionSource( |
| 1000 | attributionSource), session(session), portId(portId), |
| 1001 | deviceId(deviceId), active(false) {} |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1002 | ~AudioClient() override = default; |
| 1003 | |
| 1004 | |
| 1005 | const audio_attributes_t attributes; // source, flags ... |
| 1006 | const audio_io_handle_t io; // audio HAL stream IO handle |
Eric Laurent | 0d13fea | 2022-11-04 17:12:08 +0100 | [diff] [blame] | 1007 | const AttributionSourceState attributionSource; //client attributionsource |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1008 | const audio_session_t session; // audio session ID |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1009 | const audio_port_handle_t portId; |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1010 | const audio_port_handle_t deviceId; // selected input device port ID |
| 1011 | bool active; // Playback/Capture is active or inactive |
| 1012 | }; |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1013 | private: |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1014 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1015 | |
Eric Laurent | ed726cc | 2021-07-01 14:26:41 +0200 | [diff] [blame] | 1016 | |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1017 | // --- AudioPlaybackClient --- |
| 1018 | // Information about each registered AudioTrack client |
| 1019 | // (between calls to getOutputForAttr() and releaseOutput()) |
| 1020 | class AudioPlaybackClient : public AudioClient { |
| 1021 | public: |
| 1022 | AudioPlaybackClient(const audio_attributes_t attributes, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1023 | const audio_io_handle_t io, AttributionSourceState attributionSource, |
Eric Laurent | 5ada82e | 2019-08-29 17:53:54 -0700 | [diff] [blame] | 1024 | const audio_session_t session, audio_port_handle_t portId, |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 1025 | audio_port_handle_t deviceId, audio_stream_type_t stream, |
Eric Laurent | b16eac5 | 2024-08-02 16:46:08 +0000 | [diff] [blame] | 1026 | bool isSpatialized, audio_channel_mask_t channelMask) : |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1027 | AudioClient(attributes, io, attributionSource, session, portId, |
Eric Laurent | b16eac5 | 2024-08-02 16:46:08 +0000 | [diff] [blame] | 1028 | deviceId), stream(stream), isSpatialized(isSpatialized), |
| 1029 | channelMask(channelMask) {} |
Eric Laurent | d7fe086 | 2018-07-14 16:48:01 -0700 | [diff] [blame] | 1030 | ~AudioPlaybackClient() override = default; |
| 1031 | |
| 1032 | const audio_stream_type_t stream; |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 1033 | const bool isSpatialized; |
Eric Laurent | b16eac5 | 2024-08-02 16:46:08 +0000 | [diff] [blame] | 1034 | const audio_channel_mask_t channelMask; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame] | 1035 | }; |
| 1036 | |
Eric Laurent | bcfe5be | 2019-04-09 19:56:39 -0700 | [diff] [blame] | 1037 | void getPlaybackClientAndEffects(audio_port_handle_t portId, |
| 1038 | sp<AudioPlaybackClient>& client, |
| 1039 | sp<AudioPolicyEffects>& effects, |
| 1040 | const char *context); |
| 1041 | |
| 1042 | |
Eric Laurent | 10b7123 | 2018-04-13 18:14:44 -0700 | [diff] [blame] | 1043 | // A class automatically clearing and restoring binder caller identity inside |
| 1044 | // a code block (scoped variable) |
| 1045 | // Declare one systematically before calling AudioPolicyManager methods so that they are |
| 1046 | // executed with the same level of privilege as audioserver process. |
| 1047 | class AutoCallerClear { |
| 1048 | public: |
| 1049 | AutoCallerClear() : |
| 1050 | mToken(IPCThreadState::self()->clearCallingIdentity()) {} |
| 1051 | ~AutoCallerClear() { |
| 1052 | IPCThreadState::self()->restoreCallingIdentity(mToken); |
| 1053 | } |
| 1054 | |
| 1055 | private: |
| 1056 | const int64_t mToken; |
| 1057 | }; |
| 1058 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1059 | // Internal dump utilities. |
| 1060 | status_t dumpPermissionDenial(int fd); |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 1061 | void loadAudioPolicyManager(); |
| 1062 | void unloadAudioPolicyManager(); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1063 | |
Eric Laurent | 1109417 | 2022-04-05 18:27:42 +0200 | [diff] [blame] | 1064 | /** |
Eric Laurent | b16eac5 | 2024-08-02 16:46:08 +0000 | [diff] [blame] | 1065 | * Returns the channel masks for active audio tracks on the specified output mixer. |
Eric Laurent | 1109417 | 2022-04-05 18:27:42 +0200 | [diff] [blame] | 1066 | * The query can be specified to only include spatialized audio tracks or consider |
| 1067 | * all tracks. |
| 1068 | * @param output the I/O handle of the output mixer to consider |
| 1069 | * @param spatializedOnly true if only spatialized tracks should be considered |
Eric Laurent | b16eac5 | 2024-08-02 16:46:08 +0000 | [diff] [blame] | 1070 | * @return a list of channel masks for all active tracks matching the condition. |
Eric Laurent | 1109417 | 2022-04-05 18:27:42 +0200 | [diff] [blame] | 1071 | */ |
Eric Laurent | b16eac5 | 2024-08-02 16:46:08 +0000 | [diff] [blame] | 1072 | std::vector<audio_channel_mask_t> getActiveTracksMasks_l( |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1073 | audio_io_handle_t output, bool spatializedOnly = true) REQUIRES(mMutex); |
Eric Laurent | 1590359 | 2022-02-24 20:44:36 +0100 | [diff] [blame] | 1074 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1075 | mutable audio_utils::mutex mMutex{audio_utils::MutexOrder::kAudioPolicyService_Mutex}; |
| 1076 | // prevents concurrent access to AudioPolicy manager functions changing |
| 1077 | // device connection state or routing. |
| 1078 | // mMutex protects AudioPolicyManager methods that can call into audio flinger |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 1079 | // and possibly back in to audio policy service and acquire mEffectsLock. |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 1080 | sp<AudioCommandThread> mAudioCommandThread; // audio commands thread |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1081 | sp<AudioCommandThread> mOutputCommandThread; // process stop and release output |
Eric Laurent | f269b8e | 2014-06-09 20:01:29 -0700 | [diff] [blame] | 1082 | AudioPolicyInterface *mAudioPolicyManager; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1083 | AudioPolicyClient *mAudioPolicyClient; |
Hayden Gomes | 524159d | 2019-12-23 14:41:47 -0800 | [diff] [blame] | 1084 | std::vector<audio_usage_t> mSupportedSystemUsages; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 1085 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1086 | mutable audio_utils::mutex mNotificationClientsMutex{ |
| 1087 | audio_utils::MutexOrder::kAudioPolicyService_NotificationClientsMutex}; |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1088 | DefaultKeyedVector<int64_t, sp<NotificationClient>> mNotificationClients |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1089 | GUARDED_BY(mNotificationClientsMutex); |
Shunkai Yao | eab8a7c | 2023-05-15 21:07:08 +0000 | [diff] [blame] | 1090 | // Manage all effects configured in audio_effects.conf |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1091 | // never hold AudioPolicyService::mMutex when calling AudioPolicyEffects methods as |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 1092 | // those can call back into AudioPolicyService methods and try to acquire the mutex |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1093 | sp<AudioPolicyEffects> mAudioPolicyEffects GUARDED_BY(mMutex); |
| 1094 | audio_mode_t mPhoneState GUARDED_BY(mMutex); |
| 1095 | uid_t mPhoneStateOwnerUid GUARDED_BY(mMutex); |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1096 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1097 | sp<UidPolicy> mUidPolicy GUARDED_BY(mMutex); |
| 1098 | sp<SensorPrivacyPolicy> mSensorPrivacyPolicy GUARDED_BY(mMutex); |
Michael Groover | cfd2830 | 2018-12-11 19:16:46 -0800 | [diff] [blame] | 1099 | |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1100 | DefaultKeyedVector<audio_port_handle_t, sp<AudioRecordClient>> mAudioRecordClients |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1101 | GUARDED_BY(mMutex); |
Mikhail Naganov | 197d50a | 2020-04-30 22:37:43 +0000 | [diff] [blame] | 1102 | DefaultKeyedVector<audio_port_handle_t, sp<AudioPlaybackClient>> mAudioPlaybackClients |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1103 | GUARDED_BY(mMutex); |
Kevin Rocard | 8be9497 | 2019-02-22 13:26:25 -0800 | [diff] [blame] | 1104 | |
| 1105 | MediaPackageManager mPackageManager; // To check allowPlaybackCapture |
Ytai Ben-Tsvi | 1ef846b | 2020-03-26 09:41:15 -0700 | [diff] [blame] | 1106 | |
| 1107 | CaptureStateNotifier mCaptureStateNotifier; |
Evan Severson | 241d959 | 2021-01-08 12:16:02 -0800 | [diff] [blame] | 1108 | |
Andy Hung | 79eacdb | 2023-11-30 19:34:24 -0800 | [diff] [blame] | 1109 | // created in onFirstRef() and never cleared: does not need to be guarded by mMutex |
Eric Laurent | 81dd0f5 | 2021-07-05 11:54:40 +0200 | [diff] [blame] | 1110 | sp<Spatializer> mSpatializer; |
| 1111 | |
Jaideep Sharma | ba9053b | 2021-01-25 21:24:26 +0530 | [diff] [blame] | 1112 | void *mLibraryHandle = nullptr; |
| 1113 | CreateAudioPolicyManagerInstance mCreateAudioPolicyManager; |
| 1114 | DestroyAudioPolicyManagerInstance mDestroyAudioPolicyManager; |
Eric Laurent | 0d13fea | 2022-11-04 17:12:08 +0100 | [diff] [blame] | 1115 | std::unique_ptr<media::UsecaseValidator> mUsecaseValidator; |
Atneya Nair | 9f91a5e | 2024-05-09 16:25:05 -0700 | [diff] [blame] | 1116 | const sp<NativePermissionController> mPermissionController; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1117 | }; |
| 1118 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 1119 | } // namespace android |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 1120 | |
| 1121 | #endif // ANDROID_AUDIOPOLICYSERVICE_H |