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