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