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