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