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