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