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