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