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 | |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 20 | #include <cutils/misc.h> |
| 21 | #include <cutils/config_utils.h> |
Mathias Agopian | e762be9 | 2013-05-09 16:26:45 -0700 | [diff] [blame] | 22 | #include <cutils/compiler.h> |
Glenn Kasten | d1d8f23 | 2011-07-08 09:34:50 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 24 | #include <utils/Vector.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 25 | #include <utils/SortedVector.h> |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 26 | #include <binder/BinderService.h> |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 27 | #include <binder/IUidObserver.h> |
Dima Zavin | 6476024 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 28 | #include <system/audio.h> |
Dima Zavin | 7394a4f | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 29 | #include <system/audio_policy.h> |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 30 | #include <media/IAudioPolicyService.h> |
| 31 | #include <media/ToneGenerator.h> |
| 32 | #include <media/AudioEffect.h> |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 33 | #include <media/AudioPolicy.h> |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 34 | #include "AudioPolicyEffects.h" |
Jean-Michel Trivi | 56ec4ff | 2015-01-23 16:45:18 -0800 | [diff] [blame] | 35 | #include "managerdefault/AudioPolicyManager.h" |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 36 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 37 | #include <unordered_map> |
| 38 | #include <unordered_set> |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 39 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 40 | namespace android { |
| 41 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 42 | using namespace std; |
| 43 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 44 | // ---------------------------------------------------------------------------- |
| 45 | |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 46 | class AudioPolicyService : |
| 47 | public BinderService<AudioPolicyService>, |
| 48 | public BnAudioPolicyService, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 49 | public IBinder::DeathRecipient |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 50 | { |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 51 | friend class BinderService<AudioPolicyService>; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 52 | |
| 53 | public: |
Glenn Kasten | d2dcb08 | 2011-02-03 16:55:26 -0800 | [diff] [blame] | 54 | // for BinderService |
Mathias Agopian | e762be9 | 2013-05-09 16:26:45 -0700 | [diff] [blame] | 55 | static const char *getServiceName() ANDROID_API { return "media.audio_policy"; } |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 56 | |
| 57 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 58 | |
| 59 | // |
| 60 | // BnAudioPolicyService (see AudioPolicyInterface for method descriptions) |
| 61 | // |
| 62 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 63 | virtual status_t setDeviceConnectionState(audio_devices_t device, |
| 64 | audio_policy_dev_state_t state, |
Paul McLean | e743a47 | 2015-01-28 11:07:31 -0800 | [diff] [blame] | 65 | const char *device_address, |
| 66 | const char *device_name); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 67 | virtual audio_policy_dev_state_t getDeviceConnectionState( |
| 68 | audio_devices_t device, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 69 | const char *device_address); |
Pavlin Radoslavov | f862bc6 | 2016-12-26 18:57:22 -0800 | [diff] [blame] | 70 | virtual status_t handleDeviceConfigChange(audio_devices_t device, |
| 71 | const char *device_address, |
| 72 | const char *device_name); |
Glenn Kasten | f78aee7 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 73 | virtual status_t setPhoneState(audio_mode_t state); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 74 | virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config); |
| 75 | 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] | 76 | virtual audio_io_handle_t getOutput(audio_stream_type_t stream); |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 77 | virtual status_t getOutputForAttr(const audio_attributes_t *attr, |
| 78 | audio_io_handle_t *output, |
| 79 | audio_session_t session, |
| 80 | audio_stream_type_t *stream, |
Nadav Bar | 766fb02 | 2018-01-07 12:18:03 +0200 | [diff] [blame] | 81 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 82 | uid_t uid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 83 | const audio_config_t *config, |
| 84 | audio_output_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 85 | audio_port_handle_t *selectedDeviceId, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 86 | audio_port_handle_t *portId); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 87 | virtual status_t startOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 88 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 89 | audio_session_t session); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 90 | virtual status_t stopOutput(audio_io_handle_t output, |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 91 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 92 | audio_session_t session); |
| 93 | virtual void releaseOutput(audio_io_handle_t output, |
| 94 | audio_stream_type_t stream, |
| 95 | audio_session_t session); |
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, |
| 98 | audio_session_t session, |
Eric Laurent | b2379ba | 2016-05-23 17:42:12 -0700 | [diff] [blame] | 99 | pid_t pid, |
Eric Laurent | 8c7e6da | 2015-04-21 17:37:00 -0700 | [diff] [blame] | 100 | uid_t uid, |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame^] | 101 | const String16& opPackageName, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 102 | const audio_config_base_t *config, |
Paul McLean | 466dc8e | 2015-04-17 13:15:36 -0600 | [diff] [blame] | 103 | audio_input_flags_t flags, |
Eric Laurent | 9ae8c59 | 2017-06-22 17:17:09 -0700 | [diff] [blame] | 104 | audio_port_handle_t *selectedDeviceId = NULL, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 105 | audio_port_handle_t *portId = NULL); |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame^] | 106 | virtual status_t startInput(audio_port_handle_t portId, |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 107 | bool *silenced); |
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 | |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 120 | virtual uint32_t getStrategyForStream(audio_stream_type_t stream); |
Eric Laurent | 6374252 | 2012-03-08 13:42:42 -0800 | [diff] [blame] | 121 | virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream); |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 122 | |
Glenn Kasten | 58e5aa3 | 2012-06-20 14:08:14 -0700 | [diff] [blame] | 123 | virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc); |
| 124 | virtual status_t registerEffect(const effect_descriptor_t *desc, |
Eric Laurent | 7c7f10b | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 125 | audio_io_handle_t io, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 126 | uint32_t strategy, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 127 | audio_session_t session, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 128 | int id); |
| 129 | virtual status_t unregisterEffect(int id); |
Eric Laurent | db7c079 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 130 | virtual status_t setEffectEnabled(int id, bool enabled); |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 131 | 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] | 132 | 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] | 133 | virtual bool isSourceActive(audio_source_t source) const; |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 134 | |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 135 | virtual status_t queryDefaultPreProcessing(audio_session_t audioSession, |
Eric Laurent | 57dae99 | 2011-07-24 13:36:09 -0700 | [diff] [blame] | 136 | effect_descriptor_t *descriptors, |
| 137 | uint32_t *count); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 138 | virtual status_t onTransact( |
| 139 | uint32_t code, |
| 140 | const Parcel& data, |
| 141 | Parcel* reply, |
| 142 | uint32_t flags); |
| 143 | |
| 144 | // IBinder::DeathRecipient |
| 145 | virtual void binderDied(const wp<IBinder>& who); |
| 146 | |
Eric Laurent | f5ada6e | 2014-10-09 17:49:00 -0700 | [diff] [blame] | 147 | // RefBase |
| 148 | virtual void onFirstRef(); |
| 149 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 150 | // |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 151 | // Helpers for the struct audio_policy_service_ops implementation. |
| 152 | // This is used by the audio policy manager for certain operations that |
| 153 | // are implemented by the policy service. |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 154 | // |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 155 | virtual void setParameters(audio_io_handle_t ioHandle, |
| 156 | const char *keyValuePairs, |
| 157 | int delayMs); |
| 158 | |
| 159 | virtual status_t setStreamVolume(audio_stream_type_t stream, |
Eric Laurent | de07013 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 160 | float volume, |
| 161 | audio_io_handle_t output, |
| 162 | int delayMs = 0); |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 163 | virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 164 | virtual status_t stopTone(); |
| 165 | virtual status_t setVoiceVolume(float volume, int delayMs = 0); |
Richard Fitzgerald | ad3af33 | 2013-03-25 16:54:37 +0000 | [diff] [blame] | 166 | virtual bool isOffloadSupported(const audio_offload_info_t &config); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 167 | |
Eric Laurent | 203b1a1 | 2014-04-01 10:34:16 -0700 | [diff] [blame] | 168 | virtual status_t listAudioPorts(audio_port_role_t role, |
| 169 | audio_port_type_t type, |
| 170 | unsigned int *num_ports, |
| 171 | struct audio_port *ports, |
| 172 | unsigned int *generation); |
| 173 | virtual status_t getAudioPort(struct audio_port *port); |
| 174 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 175 | audio_patch_handle_t *handle); |
| 176 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle); |
| 177 | virtual status_t listAudioPatches(unsigned int *num_patches, |
| 178 | struct audio_patch *patches, |
| 179 | unsigned int *generation); |
| 180 | virtual status_t setAudioPortConfig(const struct audio_port_config *config); |
| 181 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 182 | virtual void registerClient(const sp<IAudioPolicyServiceClient>& client); |
| 183 | |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 184 | virtual void setAudioPortCallbacksEnabled(bool enabled); |
| 185 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 186 | virtual status_t acquireSoundTriggerSession(audio_session_t *session, |
| 187 | audio_io_handle_t *ioHandle, |
| 188 | audio_devices_t *device); |
| 189 | |
| 190 | virtual status_t releaseSoundTriggerSession(audio_session_t session); |
| 191 | |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 192 | virtual audio_mode_t getPhoneState(); |
| 193 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 194 | virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration); |
Eric Laurent | baac183 | 2014-12-01 17:52:59 -0800 | [diff] [blame] | 195 | |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 196 | virtual status_t startAudioSource(const struct audio_port_config *source, |
| 197 | const audio_attributes_t *attributes, |
Glenn Kasten | 559d439 | 2016-03-29 13:42:57 -0700 | [diff] [blame] | 198 | audio_patch_handle_t *handle); |
| 199 | virtual status_t stopAudioSource(audio_patch_handle_t handle); |
Eric Laurent | 554a277 | 2015-04-10 11:29:24 -0700 | [diff] [blame] | 200 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 201 | virtual status_t setMasterMono(bool mono); |
| 202 | virtual status_t getMasterMono(bool *mono); |
| 203 | |
Eric Laurent | ac9cef5 | 2017-06-09 15:46:26 -0700 | [diff] [blame] | 204 | virtual float getStreamVolumeDB( |
| 205 | audio_stream_type_t stream, int index, audio_devices_t device); |
| 206 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 207 | status_t doStopOutput(audio_io_handle_t output, |
| 208 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 209 | audio_session_t session); |
| 210 | void doReleaseOutput(audio_io_handle_t output, |
| 211 | audio_stream_type_t stream, |
| 212 | audio_session_t session); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 213 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 214 | status_t clientCreateAudioPatch(const struct audio_patch *patch, |
| 215 | audio_patch_handle_t *handle, |
| 216 | int delayMs); |
| 217 | status_t clientReleaseAudioPatch(audio_patch_handle_t handle, |
| 218 | int delayMs); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 219 | virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config, |
| 220 | int delayMs); |
| 221 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 222 | void removeNotificationClient(uid_t uid); |
| 223 | void onAudioPortListUpdate(); |
| 224 | void doOnAudioPortListUpdate(); |
| 225 | void onAudioPatchListUpdate(); |
| 226 | void doOnAudioPatchListUpdate(); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 227 | |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 228 | void onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state); |
| 229 | void doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 230 | void onRecordingConfigurationUpdate(int event, const record_client_info_t *clientInfo, |
| 231 | const audio_config_base_t *clientConfig, |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 232 | const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle); |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 233 | void doOnRecordingConfigurationUpdate(int event, const record_client_info_t *clientInfo, |
| 234 | const audio_config_base_t *clientConfig, |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 235 | const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 236 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 237 | private: |
Mathias Agopian | e762be9 | 2013-05-09 16:26:45 -0700 | [diff] [blame] | 238 | AudioPolicyService() ANDROID_API; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 239 | virtual ~AudioPolicyService(); |
| 240 | |
| 241 | status_t dumpInternals(int fd); |
| 242 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 243 | // Handles binder shell commands |
| 244 | virtual status_t shellCommand(int in, int out, int err, Vector<String16>& args); |
| 245 | |
| 246 | // Sets whether the given UID records only silence |
| 247 | virtual void setRecordSilenced(uid_t uid, bool silenced); |
| 248 | |
| 249 | // Overrides the UID state as if it is idle |
| 250 | status_t handleSetUidState(Vector<String16>& args, int err); |
| 251 | |
| 252 | // Clears the override for the UID state |
| 253 | status_t handleResetUidState(Vector<String16>& args, int err); |
| 254 | |
| 255 | // Gets the UID state |
| 256 | status_t handleGetUidState(Vector<String16>& args, int out, int err); |
| 257 | |
| 258 | // Prints the shell command help |
| 259 | status_t printHelp(int out); |
| 260 | |
| 261 | // If recording we need to make sure the UID is allowed to do that. If the UID is idle |
| 262 | // then it cannot record and gets buffers with zeros - silence. As soon as the UID |
| 263 | // transitions to an active state we will start reporting buffers with data. This approach |
| 264 | // transparently handles recording while the UID transitions between idle/active state |
| 265 | // avoiding to get stuck in a state receiving non-empty buffers while idle or in a state |
| 266 | // receiving empty buffers while active. |
| 267 | class UidPolicy : public BnUidObserver { |
| 268 | public: |
| 269 | explicit UidPolicy(wp<AudioPolicyService> service) |
| 270 | : mService(service) {} |
| 271 | |
| 272 | void registerSelf(); |
| 273 | void unregisterSelf(); |
| 274 | |
| 275 | bool isUidActive(uid_t uid); |
| 276 | |
| 277 | void onUidGone(uid_t uid, bool disabled); |
| 278 | void onUidActive(uid_t uid); |
| 279 | void onUidIdle(uid_t uid, bool disabled); |
| 280 | |
| 281 | void addOverrideUid(uid_t uid, bool active); |
| 282 | void removeOverrideUid(uid_t uid); |
| 283 | |
| 284 | private: |
| 285 | bool isUidActiveLocked(uid_t uid); |
| 286 | void updateOverrideUid(uid_t uid, bool active, bool insert); |
| 287 | |
| 288 | Mutex mUidLock; |
| 289 | wp<AudioPolicyService> mService; |
| 290 | std::unordered_set<uid_t> mActiveUids; |
| 291 | std::unordered_map<uid_t, bool> mOverrideUids; |
| 292 | }; |
| 293 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 294 | // Thread used for tone playback and to send audio config commands to audio flinger |
Glenn Kasten | 85ab62c | 2012-11-01 11:11:38 -0700 | [diff] [blame] | 295 | // For tone playback, using a separate thread is necessary to avoid deadlock with mLock because |
| 296 | // startTone() and stopTone() are normally called with mLock locked and requesting a tone start |
| 297 | // or stop will cause calls to AudioPolicyService and an attempt to lock mLock. |
| 298 | // For audio config commands, it is necessary because audio flinger requires that the calling |
| 299 | // process (user) has permission to modify audio settings. |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 300 | class AudioCommandThread : public Thread { |
| 301 | class AudioCommand; |
| 302 | public: |
| 303 | |
| 304 | // commands for tone AudioCommand |
| 305 | enum { |
| 306 | START_TONE, |
| 307 | STOP_TONE, |
| 308 | SET_VOLUME, |
| 309 | SET_PARAMETERS, |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 310 | SET_VOICE_VOLUME, |
| 311 | STOP_OUTPUT, |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 312 | RELEASE_OUTPUT, |
| 313 | CREATE_AUDIO_PATCH, |
| 314 | RELEASE_AUDIO_PATCH, |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 315 | UPDATE_AUDIOPORT_LIST, |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 316 | UPDATE_AUDIOPATCH_LIST, |
| 317 | SET_AUDIOPORT_CONFIG, |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 318 | DYN_POLICY_MIX_STATE_UPDATE, |
| 319 | RECORDING_CONFIGURATION_UPDATE |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 320 | }; |
| 321 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 322 | AudioCommandThread (String8 name, const wp<AudioPolicyService>& service); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 323 | virtual ~AudioCommandThread(); |
| 324 | |
| 325 | status_t dump(int fd); |
| 326 | |
| 327 | // Thread virtuals |
| 328 | virtual void onFirstRef(); |
| 329 | virtual bool threadLoop(); |
| 330 | |
| 331 | void exit(); |
Glenn Kasten | 3d2f877 | 2012-01-27 15:25:25 -0800 | [diff] [blame] | 332 | void startToneCommand(ToneGenerator::tone_type type, |
| 333 | audio_stream_type_t stream); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 334 | void stopToneCommand(); |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 335 | status_t volumeCommand(audio_stream_type_t stream, float volume, |
| 336 | audio_io_handle_t output, int delayMs = 0); |
| 337 | status_t parametersCommand(audio_io_handle_t ioHandle, |
| 338 | const char *keyValuePairs, int delayMs = 0); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 339 | status_t voiceVolumeCommand(float volume, int delayMs = 0); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 340 | void stopOutputCommand(audio_io_handle_t output, |
| 341 | audio_stream_type_t stream, |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 342 | audio_session_t session); |
| 343 | void releaseOutputCommand(audio_io_handle_t output, |
| 344 | audio_stream_type_t stream, |
| 345 | audio_session_t session); |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 346 | status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0); |
| 347 | void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 348 | status_t createAudioPatchCommand(const struct audio_patch *patch, |
| 349 | audio_patch_handle_t *handle, |
| 350 | int delayMs); |
| 351 | status_t releaseAudioPatchCommand(audio_patch_handle_t handle, |
| 352 | int delayMs); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 353 | void updateAudioPortListCommand(); |
| 354 | void updateAudioPatchListCommand(); |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 355 | status_t setAudioPortConfigCommand(const struct audio_port_config *config, |
| 356 | int delayMs); |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 357 | void dynamicPolicyMixStateUpdateCommand(const String8& regId, int32_t state); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 358 | void recordingConfigurationUpdateCommand( |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 359 | int event, |
| 360 | const record_client_info_t *clientInfo, |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 361 | const audio_config_base_t *clientConfig, |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 362 | const audio_config_base_t *deviceConfig, |
| 363 | audio_patch_handle_t patchHandle); |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 364 | void insertCommand_l(AudioCommand *command, int delayMs = 0); |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 365 | private: |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 366 | class AudioCommandData; |
| 367 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 368 | // descriptor for requested tone playback event |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 369 | class AudioCommand: public RefBase { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 370 | |
| 371 | public: |
| 372 | AudioCommand() |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 373 | : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {} |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 374 | |
| 375 | void dump(char* buffer, size_t size); |
| 376 | |
| 377 | int mCommand; // START_TONE, STOP_TONE ... |
| 378 | nsecs_t mTime; // time stamp |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 379 | Mutex mLock; // mutex associated to mCond |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 380 | Condition mCond; // condition for status return |
| 381 | status_t mStatus; // command status |
| 382 | bool mWaitStatus; // true if caller is waiting for status |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 383 | sp<AudioCommandData> mParam; // command specific parameter data |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 384 | }; |
| 385 | |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 386 | class AudioCommandData: public RefBase { |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 387 | public: |
| 388 | virtual ~AudioCommandData() {} |
| 389 | protected: |
| 390 | AudioCommandData() {} |
| 391 | }; |
| 392 | |
| 393 | class ToneData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 394 | public: |
Glenn Kasten | 3d2f877 | 2012-01-27 15:25:25 -0800 | [diff] [blame] | 395 | ToneGenerator::tone_type mType; // tone type (START_TONE only) |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 396 | audio_stream_type_t mStream; // stream type (START_TONE only) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 397 | }; |
| 398 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 399 | class VolumeData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 400 | public: |
Glenn Kasten | fff6d71 | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 401 | audio_stream_type_t mStream; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 402 | float mVolume; |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 403 | audio_io_handle_t mIO; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 404 | }; |
| 405 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 406 | class ParametersData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 407 | public: |
Glenn Kasten | 72ef00d | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 408 | audio_io_handle_t mIO; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 409 | String8 mKeyValuePairs; |
| 410 | }; |
| 411 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 412 | class VoiceVolumeData : public AudioCommandData { |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 413 | public: |
| 414 | float mVolume; |
| 415 | }; |
| 416 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 417 | class StopOutputData : public AudioCommandData { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 418 | public: |
| 419 | audio_io_handle_t mIO; |
| 420 | audio_stream_type_t mStream; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 421 | audio_session_t mSession; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 422 | }; |
| 423 | |
Jesper Tragardh | 48412dc | 2014-03-24 14:12:43 +0100 | [diff] [blame] | 424 | class ReleaseOutputData : public AudioCommandData { |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 425 | public: |
| 426 | audio_io_handle_t mIO; |
Eric Laurent | e83b55d | 2014-11-14 10:06:21 -0800 | [diff] [blame] | 427 | audio_stream_type_t mStream; |
| 428 | audio_session_t mSession; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 429 | }; |
| 430 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 431 | class CreateAudioPatchData : public AudioCommandData { |
| 432 | public: |
| 433 | struct audio_patch mPatch; |
| 434 | audio_patch_handle_t mHandle; |
| 435 | }; |
| 436 | |
| 437 | class ReleaseAudioPatchData : public AudioCommandData { |
| 438 | public: |
| 439 | audio_patch_handle_t mHandle; |
| 440 | }; |
| 441 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 442 | class SetAudioPortConfigData : public AudioCommandData { |
| 443 | public: |
| 444 | struct audio_port_config mConfig; |
| 445 | }; |
| 446 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 447 | class DynPolicyMixStateUpdateData : public AudioCommandData { |
| 448 | public: |
| 449 | String8 mRegId; |
| 450 | int32_t mState; |
| 451 | }; |
| 452 | |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 453 | class RecordingConfigurationUpdateData : public AudioCommandData { |
| 454 | public: |
| 455 | int mEvent; |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 456 | record_client_info_t mClientInfo; |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 457 | struct audio_config_base mClientConfig; |
| 458 | struct audio_config_base mDeviceConfig; |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 459 | audio_patch_handle_t mPatchHandle; |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 460 | }; |
| 461 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 462 | Mutex mLock; |
| 463 | Condition mWaitWorkCV; |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 464 | Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 465 | ToneGenerator *mpToneGenerator; // the tone generator |
Eric Laurent | 0ede892 | 2014-05-09 18:04:42 -0700 | [diff] [blame] | 466 | sp<AudioCommand> mLastCommand; // last processed command (used by dump) |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 467 | String8 mName; // string used by wake lock fo delayed commands |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 468 | wp<AudioPolicyService> mService; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 469 | }; |
| 470 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 471 | class AudioPolicyClient : public AudioPolicyClientInterface |
| 472 | { |
| 473 | public: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 474 | explicit AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {} |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 475 | virtual ~AudioPolicyClient() {} |
| 476 | |
| 477 | // |
| 478 | // Audio HW module functions |
| 479 | // |
| 480 | |
| 481 | // loads a HW module. |
| 482 | virtual audio_module_handle_t loadHwModule(const char *name); |
| 483 | |
| 484 | // |
| 485 | // Audio output Control functions |
| 486 | // |
| 487 | |
| 488 | // opens an audio output with the requested parameters. The parameter values can indicate to use the default values |
| 489 | // in case the audio policy manager has no specific requirements for the output being opened. |
| 490 | // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream. |
| 491 | // 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] | 492 | virtual status_t openOutput(audio_module_handle_t module, |
| 493 | audio_io_handle_t *output, |
| 494 | audio_config_t *config, |
| 495 | audio_devices_t *devices, |
| 496 | const String8& address, |
| 497 | uint32_t *latencyMs, |
| 498 | audio_output_flags_t flags); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 499 | // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by |
| 500 | // a special mixer thread in the AudioFlinger. |
| 501 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2); |
| 502 | // closes the output stream |
| 503 | virtual status_t closeOutput(audio_io_handle_t output); |
| 504 | // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in |
| 505 | // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded. |
| 506 | virtual status_t suspendOutput(audio_io_handle_t output); |
| 507 | // restores a suspended output. |
| 508 | virtual status_t restoreOutput(audio_io_handle_t output); |
| 509 | |
| 510 | // |
| 511 | // Audio input Control functions |
| 512 | // |
| 513 | |
| 514 | // opens an audio input |
| 515 | virtual audio_io_handle_t openInput(audio_module_handle_t module, |
Eric Laurent | cf2c021 | 2014-07-25 16:20:43 -0700 | [diff] [blame] | 516 | audio_io_handle_t *input, |
| 517 | audio_config_t *config, |
| 518 | audio_devices_t *devices, |
| 519 | const String8& address, |
| 520 | audio_source_t source, |
Glenn Kasten | ec40d28 | 2014-07-15 15:31:26 -0700 | [diff] [blame] | 521 | audio_input_flags_t flags); |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 522 | // closes an audio input |
| 523 | virtual status_t closeInput(audio_io_handle_t input); |
| 524 | // |
| 525 | // misc control functions |
| 526 | // |
| 527 | |
| 528 | // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes |
| 529 | // for each output (destination device) it is attached to. |
| 530 | virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0); |
| 531 | |
| 532 | // invalidate a stream type, causing a reroute to an unspecified new output |
| 533 | virtual status_t invalidateStream(audio_stream_type_t stream); |
| 534 | |
| 535 | // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface. |
| 536 | virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0); |
| 537 | // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager. |
| 538 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys); |
| 539 | |
| 540 | // request the playback of a tone on the specified stream: used for instance to replace notification sounds when playing |
| 541 | // over a telephony device during a phone call. |
| 542 | virtual status_t startTone(audio_policy_tone_t tone, audio_stream_type_t stream); |
| 543 | virtual status_t stopTone(); |
| 544 | |
| 545 | // set down link audio volume. |
| 546 | virtual status_t setVoiceVolume(float volume, int delayMs = 0); |
| 547 | |
| 548 | // move effect to the specified output |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 549 | virtual status_t moveEffects(audio_session_t session, |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 550 | audio_io_handle_t srcOutput, |
| 551 | audio_io_handle_t dstOutput); |
| 552 | |
Eric Laurent | 951f455 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 553 | /* Create a patch between several source and sink ports */ |
| 554 | virtual status_t createAudioPatch(const struct audio_patch *patch, |
| 555 | audio_patch_handle_t *handle, |
| 556 | int delayMs); |
| 557 | |
| 558 | /* Release a patch */ |
| 559 | virtual status_t releaseAudioPatch(audio_patch_handle_t handle, |
| 560 | int delayMs); |
| 561 | |
Eric Laurent | e1715a4 | 2014-05-20 11:30:42 -0700 | [diff] [blame] | 562 | /* Set audio port configuration */ |
| 563 | virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs); |
| 564 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 565 | virtual void onAudioPortListUpdate(); |
| 566 | virtual void onAudioPatchListUpdate(); |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 567 | virtual void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 568 | virtual void onRecordingConfigurationUpdate(int event, |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 569 | const record_client_info_t *clientInfo, |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 570 | const audio_config_base_t *clientConfig, |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 571 | const audio_config_base_t *deviceConfig, audio_patch_handle_t patchHandle); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 572 | |
Glenn Kasten | eeecb98 | 2016-02-26 10:44:04 -0800 | [diff] [blame] | 573 | virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use); |
Eric Laurent | de3f839 | 2014-07-27 18:38:22 -0700 | [diff] [blame] | 574 | |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 575 | private: |
| 576 | AudioPolicyService *mAudioPolicyService; |
| 577 | }; |
| 578 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 579 | // --- Notification Client --- |
| 580 | class NotificationClient : public IBinder::DeathRecipient { |
| 581 | public: |
| 582 | NotificationClient(const sp<AudioPolicyService>& service, |
| 583 | const sp<IAudioPolicyServiceClient>& client, |
| 584 | uid_t uid); |
| 585 | virtual ~NotificationClient(); |
| 586 | |
Jean-Michel Trivi | de80105 | 2015-04-14 19:10:14 -0700 | [diff] [blame] | 587 | void onAudioPortListUpdate(); |
| 588 | void onAudioPatchListUpdate(); |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 589 | void onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state); |
Jean-Michel Trivi | 2f4fe9f | 2015-12-04 16:20:59 -0800 | [diff] [blame] | 590 | void onRecordingConfigurationUpdate( |
Jean-Michel Trivi | ac4e429 | 2016-12-22 11:39:31 -0800 | [diff] [blame] | 591 | int event, const record_client_info_t *clientInfo, |
Jean-Michel Trivi | 7281aa9 | 2016-02-17 15:33:40 -0800 | [diff] [blame] | 592 | const audio_config_base_t *clientConfig, |
Jean-Michel Trivi | 8c7cf3b | 2016-02-25 17:08:24 -0800 | [diff] [blame] | 593 | const audio_config_base_t *deviceConfig, |
| 594 | audio_patch_handle_t patchHandle); |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 595 | void setAudioPortCallbacksEnabled(bool enabled); |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 596 | |
| 597 | // IBinder::DeathRecipient |
| 598 | virtual void binderDied(const wp<IBinder>& who); |
| 599 | |
| 600 | private: |
| 601 | NotificationClient(const NotificationClient&); |
| 602 | NotificationClient& operator = (const NotificationClient&); |
| 603 | |
| 604 | const wp<AudioPolicyService> mService; |
| 605 | const uid_t mUid; |
| 606 | const sp<IAudioPolicyServiceClient> mAudioPolicyServiceClient; |
Eric Laurent | e8726fe | 2015-06-26 09:39:24 -0700 | [diff] [blame] | 607 | bool mAudioPortCallbacksEnabled; |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 608 | }; |
| 609 | |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame^] | 610 | // --- AudioRecordClient --- |
| 611 | // Information about each registered AudioRecord client |
| 612 | // (between calls to getInputForAttr() and releaseInput()) |
| 613 | class AudioRecordClient : public RefBase { |
| 614 | public: |
| 615 | AudioRecordClient(const audio_attributes_t attributes, |
| 616 | const audio_io_handle_t input, uid_t uid, pid_t pid, |
| 617 | const String16& opPackageName, const audio_session_t session) : |
| 618 | attributes(attributes), |
| 619 | input(input), uid(uid), pid(pid), |
| 620 | opPackageName(opPackageName), session(session), |
| 621 | active(false), isConcurrent(false), isVirtualDevice(false) {} |
| 622 | virtual ~AudioRecordClient() {} |
| 623 | |
| 624 | const audio_attributes_t attributes; // source, flags ... |
| 625 | const audio_io_handle_t input; // audio HAL input IO handle |
| 626 | const uid_t uid; // client UID |
| 627 | const pid_t pid; // client PID |
| 628 | const String16 opPackageName; // client package name |
| 629 | const audio_session_t session; // audio session ID |
| 630 | bool active; // Capture is active or inactive |
| 631 | bool isConcurrent; // is allowed to concurrent capture |
| 632 | bool isVirtualDevice; // uses vitual device: updated by APM::getInputForAttr() |
| 633 | }; |
| 634 | |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 635 | // Internal dump utilities. |
| 636 | status_t dumpPermissionDenial(int fd); |
| 637 | |
| 638 | |
Eric Laurent | eda6c36 | 2011-02-02 09:33:30 -0800 | [diff] [blame] | 639 | mutable Mutex mLock; // prevents concurrent access to AudioPolicy manager functions changing |
| 640 | // device connection state or routing |
Haynes Mathew George | bab7bf4 | 2015-10-30 18:02:23 -0700 | [diff] [blame] | 641 | mutable Mutex mEffectsLock; // serialize access to Effect state within APM. |
| 642 | // Note: lock acquisition order is always mLock > mEffectsLock: |
| 643 | // mLock protects AudioPolicyManager methods that can call into audio flinger |
| 644 | // and possibly back in to audio policy service and acquire mEffectsLock. |
Glenn Kasten | e53b9ea | 2012-03-12 16:29:55 -0700 | [diff] [blame] | 645 | sp<AudioCommandThread> mAudioCommandThread; // audio commands thread |
| 646 | sp<AudioCommandThread> mTonePlaybackThread; // tone playback thread |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 647 | sp<AudioCommandThread> mOutputCommandThread; // process stop and release output |
Dima Zavin | fce7a47 | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 648 | struct audio_policy_device *mpAudioPolicyDev; |
| 649 | struct audio_policy *mpAudioPolicy; |
Eric Laurent | f269b8e | 2014-06-09 20:01:29 -0700 | [diff] [blame] | 650 | AudioPolicyInterface *mAudioPolicyManager; |
Eric Laurent | dce54a1 | 2014-03-10 12:19:46 -0700 | [diff] [blame] | 651 | AudioPolicyClient *mAudioPolicyClient; |
| 652 | |
Eric Laurent | b52c152 | 2014-05-20 11:27:36 -0700 | [diff] [blame] | 653 | DefaultKeyedVector< uid_t, sp<NotificationClient> > mNotificationClients; |
Eric Laurent | 0ebd5f9 | 2014-11-19 19:04:52 -0800 | [diff] [blame] | 654 | Mutex mNotificationClientsLock; // protects mNotificationClients |
bryant_liu | ba2b439 | 2014-06-11 16:49:30 +0800 | [diff] [blame] | 655 | // Manage all effects configured in audio_effects.conf |
| 656 | sp<AudioPolicyEffects> mAudioPolicyEffects; |
Eric Laurent | bb6c9a0 | 2014-09-25 14:11:47 -0700 | [diff] [blame] | 657 | audio_mode_t mPhoneState; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 658 | |
| 659 | sp<UidPolicy> mUidPolicy; |
Eric Laurent | fee1976 | 2018-01-29 18:44:13 -0800 | [diff] [blame^] | 660 | DefaultKeyedVector< audio_port_handle_t, sp<AudioRecordClient> > mAudioRecordClients; |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 661 | }; |
| 662 | |
Mikhail Naganov | 1b2a794 | 2017-12-08 10:18:09 -0800 | [diff] [blame] | 663 | } // namespace android |
Mathias Agopian | 65ab471 | 2010-07-14 17:59:35 -0700 | [diff] [blame] | 664 | |
| 665 | #endif // ANDROID_AUDIOPOLICYSERVICE_H |