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