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