blob: 7fc52dd24b3649c13deec8a2c17a0ca497556ca6 [file] [log] [blame]
Mathias Agopian65ab4712010-07-14 17:59:35 -07001/*
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 Laurent7c7f10b2011-06-17 21:29:58 -070020#include <cutils/misc.h>
21#include <cutils/config_utils.h>
Mathias Agopiane762be92013-05-09 16:26:45 -070022#include <cutils/compiler.h>
Glenn Kastend1d8f232011-07-08 09:34:50 -070023#include <utils/String8.h>
Mathias Agopian65ab4712010-07-14 17:59:35 -070024#include <utils/Vector.h>
Eric Laurent7c7f10b2011-06-17 21:29:58 -070025#include <utils/SortedVector.h>
Glenn Kastend2dcb082011-02-03 16:55:26 -080026#include <binder/BinderService.h>
Svet Ganovf4ddfef2018-01-16 07:37:58 -080027#include <binder/IUidObserver.h>
Dima Zavin64760242011-05-11 14:15:23 -070028#include <system/audio.h>
Dima Zavin7394a4f2011-06-13 18:16:26 -070029#include <system/audio_policy.h>
Eric Laurent7c7f10b2011-06-17 21:29:58 -070030#include <media/IAudioPolicyService.h>
31#include <media/ToneGenerator.h>
32#include <media/AudioEffect.h>
Eric Laurentbaac1832014-12-01 17:52:59 -080033#include <media/AudioPolicy.h>
Kevin Rocard8be94972019-02-22 13:26:25 -080034#include <mediautils/ServiceUtilities.h>
bryant_liuba2b4392014-06-11 16:49:30 +080035#include "AudioPolicyEffects.h"
Jean-Michel Trivi56ec4ff2015-01-23 16:45:18 -080036#include "managerdefault/AudioPolicyManager.h"
Michael Groovercfd28302018-12-11 19:16:46 -080037#include <android/hardware/BnSensorPrivacyListener.h>
Dima Zavinfce7a472011-04-19 22:30:36 -070038
Svet Ganovf4ddfef2018-01-16 07:37:58 -080039#include <unordered_map>
bryant_liuba2b4392014-06-11 16:49:30 +080040
Mathias Agopian65ab4712010-07-14 17:59:35 -070041namespace android {
42
Mathias Agopian65ab4712010-07-14 17:59:35 -070043// ----------------------------------------------------------------------------
44
Glenn Kastend2dcb082011-02-03 16:55:26 -080045class AudioPolicyService :
46 public BinderService<AudioPolicyService>,
47 public BnAudioPolicyService,
Eric Laurentde070132010-07-13 04:45:46 -070048 public IBinder::DeathRecipient
Mathias Agopian65ab4712010-07-14 17:59:35 -070049{
Glenn Kastend2dcb082011-02-03 16:55:26 -080050 friend class BinderService<AudioPolicyService>;
Mathias Agopian65ab4712010-07-14 17:59:35 -070051
52public:
Glenn Kastend2dcb082011-02-03 16:55:26 -080053 // for BinderService
Mathias Agopiane762be92013-05-09 16:26:45 -070054 static const char *getServiceName() ANDROID_API { return "media.audio_policy"; }
Mathias Agopian65ab4712010-07-14 17:59:35 -070055
56 virtual status_t dump(int fd, const Vector<String16>& args);
57
58 //
59 // BnAudioPolicyService (see AudioPolicyInterface for method descriptions)
60 //
61
Dima Zavinfce7a472011-04-19 22:30:36 -070062 virtual status_t setDeviceConnectionState(audio_devices_t device,
63 audio_policy_dev_state_t state,
Paul McLeane743a472015-01-28 11:07:31 -080064 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -080065 const char *device_name,
66 audio_format_t encodedFormat);
Dima Zavinfce7a472011-04-19 22:30:36 -070067 virtual audio_policy_dev_state_t getDeviceConnectionState(
68 audio_devices_t device,
Eric Laurentde070132010-07-13 04:45:46 -070069 const char *device_address);
Pavlin Radoslavovf862bc62016-12-26 18:57:22 -080070 virtual status_t handleDeviceConfigChange(audio_devices_t device,
71 const char *device_address,
Aniket Kumar Lata4e464702019-01-10 23:38:46 -080072 const char *device_name,
73 audio_format_t encodedFormat);
Glenn Kastenf78aee72012-01-04 11:00:47 -080074 virtual status_t setPhoneState(audio_mode_t state);
Dima Zavinfce7a472011-04-19 22:30:36 -070075 virtual status_t setForceUse(audio_policy_force_use_t usage, audio_policy_forced_cfg_t config);
76 virtual audio_policy_forced_cfg_t getForceUse(audio_policy_force_use_t usage);
Eric Laurentf4e63452017-11-06 19:31:46 +000077 virtual audio_io_handle_t getOutput(audio_stream_type_t stream);
Kevin Rocard153f92d2018-12-18 18:33:28 -080078 status_t getOutputForAttr(const audio_attributes_t *attr,
79 audio_io_handle_t *output,
80 audio_session_t session,
81 audio_stream_type_t *stream,
82 pid_t pid,
83 uid_t uid,
84 const audio_config_t *config,
85 audio_output_flags_t flags,
86 audio_port_handle_t *selectedDeviceId,
87 audio_port_handle_t *portId,
88 std::vector<audio_io_handle_t> *secondaryOutputs) override;
Eric Laurentd7fe0862018-07-14 16:48:01 -070089 virtual status_t startOutput(audio_port_handle_t portId);
90 virtual status_t stopOutput(audio_port_handle_t portId);
91 virtual void releaseOutput(audio_port_handle_t portId);
Eric Laurentcaf7f482014-11-25 17:50:47 -080092 virtual status_t getInputForAttr(const audio_attributes_t *attr,
93 audio_io_handle_t *input,
94 audio_session_t session,
Eric Laurentb2379ba2016-05-23 17:42:12 -070095 pid_t pid,
Eric Laurent8c7e6da2015-04-21 17:37:00 -070096 uid_t uid,
Eric Laurentfee19762018-01-29 18:44:13 -080097 const String16& opPackageName,
Eric Laurent20b9ef02016-12-05 11:03:16 -080098 const audio_config_base_t *config,
Paul McLean466dc8e2015-04-17 13:15:36 -060099 audio_input_flags_t flags,
Eric Laurent9ae8c592017-06-22 17:17:09 -0700100 audio_port_handle_t *selectedDeviceId = NULL,
Eric Laurent20b9ef02016-12-05 11:03:16 -0800101 audio_port_handle_t *portId = NULL);
Eric Laurent4eb58f12018-12-07 16:41:02 -0800102 virtual status_t startInput(audio_port_handle_t portId);
Eric Laurentfee19762018-01-29 18:44:13 -0800103 virtual status_t stopInput(audio_port_handle_t portId);
104 virtual void releaseInput(audio_port_handle_t portId);
Dima Zavinfce7a472011-04-19 22:30:36 -0700105 virtual status_t initStreamVolume(audio_stream_type_t stream,
Mathias Agopian65ab4712010-07-14 17:59:35 -0700106 int indexMin,
107 int indexMax);
Eric Laurent83844cc2011-11-18 16:43:31 -0800108 virtual status_t setStreamVolumeIndex(audio_stream_type_t stream,
109 int index,
110 audio_devices_t device);
111 virtual status_t getStreamVolumeIndex(audio_stream_type_t stream,
112 int *index,
113 audio_devices_t device);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700114
Dima Zavinfce7a472011-04-19 22:30:36 -0700115 virtual uint32_t getStrategyForStream(audio_stream_type_t stream);
Eric Laurent63742522012-03-08 13:42:42 -0800116 virtual audio_devices_t getDevicesForStream(audio_stream_type_t stream);
Eric Laurentde070132010-07-13 04:45:46 -0700117
Glenn Kasten58e5aa32012-06-20 14:08:14 -0700118 virtual audio_io_handle_t getOutputForEffect(const effect_descriptor_t *desc);
119 virtual status_t registerEffect(const effect_descriptor_t *desc,
Eric Laurent7c7f10b2011-06-17 21:29:58 -0700120 audio_io_handle_t io,
Eric Laurentde070132010-07-13 04:45:46 -0700121 uint32_t strategy,
Glenn Kastend848eb42016-03-08 13:42:11 -0800122 audio_session_t session,
Eric Laurentde070132010-07-13 04:45:46 -0700123 int id);
124 virtual status_t unregisterEffect(int id);
Eric Laurentdb7c0792011-08-10 10:37:50 -0700125 virtual status_t setEffectEnabled(int id, bool enabled);
Glenn Kastenfff6d712012-01-12 16:38:12 -0800126 virtual bool isStreamActive(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivi272ab542013-02-04 16:26:02 -0800127 virtual bool isStreamActiveRemotely(audio_stream_type_t stream, uint32_t inPastMs = 0) const;
Jean-Michel Trivid7086032012-10-10 12:11:16 -0700128 virtual bool isSourceActive(audio_source_t source) const;
Eric Laurentde070132010-07-13 04:45:46 -0700129
Glenn Kastend848eb42016-03-08 13:42:11 -0800130 virtual status_t queryDefaultPreProcessing(audio_session_t audioSession,
Eric Laurent57dae992011-07-24 13:36:09 -0700131 effect_descriptor_t *descriptors,
132 uint32_t *count);
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700133 virtual status_t addSourceDefaultEffect(const effect_uuid_t *type,
134 const String16& opPackageName,
135 const effect_uuid_t *uuid,
136 int32_t priority,
137 audio_source_t source,
138 audio_unique_id_t* id);
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700139 virtual status_t addStreamDefaultEffect(const effect_uuid_t *type,
140 const String16& opPackageName,
141 const effect_uuid_t *uuid,
142 int32_t priority,
143 audio_usage_t usage,
144 audio_unique_id_t* id);
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700145 virtual status_t removeSourceDefaultEffect(audio_unique_id_t id);
Ari Hausman-Cohen433722e2018-04-24 14:25:22 -0700146 virtual status_t removeStreamDefaultEffect(audio_unique_id_t id);
147
Mathias Agopian65ab4712010-07-14 17:59:35 -0700148 virtual status_t onTransact(
149 uint32_t code,
150 const Parcel& data,
151 Parcel* reply,
152 uint32_t flags);
153
154 // IBinder::DeathRecipient
155 virtual void binderDied(const wp<IBinder>& who);
156
Eric Laurentf5ada6e2014-10-09 17:49:00 -0700157 // RefBase
158 virtual void onFirstRef();
159
Mathias Agopian65ab4712010-07-14 17:59:35 -0700160 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700161 // Helpers for the struct audio_policy_service_ops implementation.
162 // This is used by the audio policy manager for certain operations that
163 // are implemented by the policy service.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700164 //
Dima Zavinfce7a472011-04-19 22:30:36 -0700165 virtual void setParameters(audio_io_handle_t ioHandle,
166 const char *keyValuePairs,
167 int delayMs);
168
169 virtual status_t setStreamVolume(audio_stream_type_t stream,
Eric Laurentde070132010-07-13 04:45:46 -0700170 float volume,
171 audio_io_handle_t output,
172 int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700173 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
Richard Fitzgeraldad3af332013-03-25 16:54:37 +0000174 virtual bool isOffloadSupported(const audio_offload_info_t &config);
Michael Chana94fbb22018-04-24 14:31:19 +1000175 virtual bool isDirectOutputSupported(const audio_config_base_t& config,
176 const audio_attributes_t& attributes);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700177
Eric Laurent203b1a12014-04-01 10:34:16 -0700178 virtual status_t listAudioPorts(audio_port_role_t role,
179 audio_port_type_t type,
180 unsigned int *num_ports,
181 struct audio_port *ports,
182 unsigned int *generation);
183 virtual status_t getAudioPort(struct audio_port *port);
184 virtual status_t createAudioPatch(const struct audio_patch *patch,
185 audio_patch_handle_t *handle);
186 virtual status_t releaseAudioPatch(audio_patch_handle_t handle);
187 virtual status_t listAudioPatches(unsigned int *num_patches,
188 struct audio_patch *patches,
189 unsigned int *generation);
190 virtual status_t setAudioPortConfig(const struct audio_port_config *config);
191
Eric Laurentb52c1522014-05-20 11:27:36 -0700192 virtual void registerClient(const sp<IAudioPolicyServiceClient>& client);
193
Eric Laurente8726fe2015-06-26 09:39:24 -0700194 virtual void setAudioPortCallbacksEnabled(bool enabled);
195
Eric Laurentdf3dc7e2014-07-27 18:39:40 -0700196 virtual status_t acquireSoundTriggerSession(audio_session_t *session,
197 audio_io_handle_t *ioHandle,
198 audio_devices_t *device);
199
200 virtual status_t releaseSoundTriggerSession(audio_session_t session);
201
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700202 virtual audio_mode_t getPhoneState();
203
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700204 virtual status_t registerPolicyMixes(const Vector<AudioMix>& mixes, bool registration);
Eric Laurentbaac1832014-12-01 17:52:59 -0800205
Jean-Michel Trivibda70da2018-12-19 07:30:15 -0800206 virtual status_t setUidDeviceAffinities(uid_t uid, const Vector<AudioDeviceTypeAddr>& devices);
207
208 virtual status_t removeUidDeviceAffinities(uid_t uid);
209
Eric Laurent554a2772015-04-10 11:29:24 -0700210 virtual status_t startAudioSource(const struct audio_port_config *source,
211 const audio_attributes_t *attributes,
Eric Laurent3e6c7e12018-07-27 17:09:23 -0700212 audio_port_handle_t *portId);
213 virtual status_t stopAudioSource(audio_port_handle_t portId);
Eric Laurent554a2772015-04-10 11:29:24 -0700214
Andy Hung2ddee192015-12-18 17:34:44 -0800215 virtual status_t setMasterMono(bool mono);
216 virtual status_t getMasterMono(bool *mono);
217
Eric Laurentac9cef52017-06-09 15:46:26 -0700218 virtual float getStreamVolumeDB(
219 audio_stream_type_t stream, int index, audio_devices_t device);
220
jiabin81772902018-04-02 17:52:27 -0700221 virtual status_t getSurroundFormats(unsigned int *numSurroundFormats,
222 audio_format_t *surroundFormats,
223 bool *surroundFormatsEnabled,
224 bool reported);
Arun Mirpuri11029ad2018-12-19 20:45:19 -0800225 virtual status_t getHwOffloadEncodingFormatsSupportedForA2DP(
226 std::vector<audio_format_t> *formats);
jiabin81772902018-04-02 17:52:27 -0700227 virtual status_t setSurroundFormatEnabled(audio_format_t audioFormat, bool enabled);
228
Eric Laurentb78763e2018-10-17 10:08:02 -0700229 virtual status_t setAssistantUid(uid_t uid);
230 virtual status_t setA11yServicesUids(const std::vector<uid_t>& uids);
231
jiabin6012f912018-11-02 17:06:30 -0700232 virtual bool isHapticPlaybackSupported();
233
François Gaffied0ba9ed2018-11-05 11:50:42 +0100234 virtual status_t listAudioProductStrategies(AudioProductStrategyVector &strategies);
235 virtual product_strategy_t getProductStrategyFromAudioAttributes(const AudioAttributes &aa);
236
Eric Laurentd7fe0862018-07-14 16:48:01 -0700237 status_t doStopOutput(audio_port_handle_t portId);
238 void doReleaseOutput(audio_port_handle_t portId);
Eric Laurentbfb1b832013-01-07 09:53:42 -0800239
Eric Laurent951f4552014-05-20 10:48:17 -0700240 status_t clientCreateAudioPatch(const struct audio_patch *patch,
241 audio_patch_handle_t *handle,
242 int delayMs);
243 status_t clientReleaseAudioPatch(audio_patch_handle_t handle,
244 int delayMs);
Eric Laurente1715a42014-05-20 11:30:42 -0700245 virtual status_t clientSetAudioPortConfig(const struct audio_port_config *config,
246 int delayMs);
247
luochaojiang908c7d72018-06-21 14:58:04 +0800248 void removeNotificationClient(uid_t uid, pid_t pid);
Eric Laurentb52c1522014-05-20 11:27:36 -0700249 void onAudioPortListUpdate();
250 void doOnAudioPortListUpdate();
251 void onAudioPatchListUpdate();
252 void doOnAudioPatchListUpdate();
Eric Laurent951f4552014-05-20 10:48:17 -0700253
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700254 void onDynamicPolicyMixStateUpdate(const String8& regId, int32_t state);
255 void doOnDynamicPolicyMixStateUpdate(const String8& regId, int32_t state);
Eric Laurenta9f86652018-11-28 17:23:11 -0800256 void onRecordingConfigurationUpdate(int event,
257 const record_client_info_t *clientInfo,
258 const audio_config_base_t *clientConfig,
259 std::vector<effect_descriptor_t> clientEffects,
260 const audio_config_base_t *deviceConfig,
261 std::vector<effect_descriptor_t> effects,
262 audio_patch_handle_t patchHandle,
263 audio_source_t source);
264 void doOnRecordingConfigurationUpdate(int event,
265 const record_client_info_t *clientInfo,
266 const audio_config_base_t *clientConfig,
267 std::vector<effect_descriptor_t> clientEffects,
268 const audio_config_base_t *deviceConfig,
269 std::vector<effect_descriptor_t> effects,
270 audio_patch_handle_t patchHandle,
271 audio_source_t source);
Jean-Michel Trivide801052015-04-14 19:10:14 -0700272
Mathias Agopian65ab4712010-07-14 17:59:35 -0700273private:
Mathias Agopiane762be92013-05-09 16:26:45 -0700274 AudioPolicyService() ANDROID_API;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700275 virtual ~AudioPolicyService();
276
277 status_t dumpInternals(int fd);
278
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800279 // Handles binder shell commands
280 virtual status_t shellCommand(int in, int out, int err, Vector<String16>& args);
281
282 // Sets whether the given UID records only silence
Eric Laurente8c8b432018-10-17 10:08:02 -0700283 virtual void setAppState_l(uid_t uid, app_state_t state);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800284
285 // Overrides the UID state as if it is idle
286 status_t handleSetUidState(Vector<String16>& args, int err);
287
288 // Clears the override for the UID state
289 status_t handleResetUidState(Vector<String16>& args, int err);
290
291 // Gets the UID state
292 status_t handleGetUidState(Vector<String16>& args, int out, int err);
293
294 // Prints the shell command help
295 status_t printHelp(int out);
296
Eric Laurent99fcae42018-05-17 16:59:18 -0700297 std::string getDeviceTypeStrForPortId(audio_port_handle_t portId);
298
Ari Hausman-Cohen24628312018-08-13 15:01:09 -0700299 status_t getAudioPolicyEffects(sp<AudioPolicyEffects>& audioPolicyEffects);
300
Eric Laurente8c8b432018-10-17 10:08:02 -0700301 app_state_t apmStatFromAmState(int amState);
302
303 void updateUidStates();
304 void updateUidStates_l();
305
Michael Groovercfd28302018-12-11 19:16:46 -0800306 void silenceAllRecordings_l();
307
Eric Laurent4eb58f12018-12-07 16:41:02 -0800308 static bool isPrivacySensitive(audio_source_t source);
309
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800310 // If recording we need to make sure the UID is allowed to do that. If the UID is idle
311 // then it cannot record and gets buffers with zeros - silence. As soon as the UID
312 // transitions to an active state we will start reporting buffers with data. This approach
313 // transparently handles recording while the UID transitions between idle/active state
314 // avoiding to get stuck in a state receiving non-empty buffers while idle or in a state
315 // receiving empty buffers while active.
Mikhail Naganoveae73eb2018-04-03 16:57:36 -0700316 class UidPolicy : public BnUidObserver, public virtual IBinder::DeathRecipient {
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800317 public:
318 explicit UidPolicy(wp<AudioPolicyService> service)
Eric Laurentb78763e2018-10-17 10:08:02 -0700319 : mService(service), mObserverRegistered(false), mAssistantUid(0) {}
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800320
321 void registerSelf();
322 void unregisterSelf();
323
Mikhail Naganoveae73eb2018-04-03 16:57:36 -0700324 // IBinder::DeathRecipient implementation
325 void binderDied(const wp<IBinder> &who) override;
326
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800327 bool isUidActive(uid_t uid);
Eric Laurente8c8b432018-10-17 10:08:02 -0700328 int getUidState(uid_t uid);
Eric Laurentb78763e2018-10-17 10:08:02 -0700329 void setAssistantUid(uid_t uid) { mAssistantUid = uid; }
330 bool isAssistantUid(uid_t uid) { return uid == mAssistantUid; }
331 void setA11yUids(const std::vector<uid_t>& uids) { mA11yUids.clear(); mA11yUids = uids; }
332 bool isA11yUid(uid_t uid);
Eric Laurent4eb58f12018-12-07 16:41:02 -0800333 bool isA11yOnTop();
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800334
Mikhail Naganoveae73eb2018-04-03 16:57:36 -0700335 // BnUidObserver implementation
336 void onUidActive(uid_t uid) override;
337 void onUidGone(uid_t uid, bool disabled) override;
338 void onUidIdle(uid_t uid, bool disabled) override;
Eric Laurente8c8b432018-10-17 10:08:02 -0700339 void onUidStateChanged(uid_t uid, int32_t procState, int64_t procStateSeq);
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800340
Mikhail Naganoveae73eb2018-04-03 16:57:36 -0700341 void addOverrideUid(uid_t uid, bool active) { updateOverrideUid(uid, active, true); }
342 void removeOverrideUid(uid_t uid) { updateOverrideUid(uid, false, false); }
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800343
Eric Laurente8c8b432018-10-17 10:08:02 -0700344 void updateUid(std::unordered_map<uid_t, std::pair<bool, int>> *uids,
345 uid_t uid, bool active, int state, bool insert);
346
347 private:
348 void notifyService();
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800349 void updateOverrideUid(uid_t uid, bool active, bool insert);
Eric Laurente8c8b432018-10-17 10:08:02 -0700350 void updateUidLocked(std::unordered_map<uid_t, std::pair<bool, int>> *uids,
351 uid_t uid, bool active, int state, bool insert);
352 void checkRegistered();
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800353
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800354 wp<AudioPolicyService> mService;
Mikhail Naganoveae73eb2018-04-03 16:57:36 -0700355 Mutex mLock;
356 bool mObserverRegistered;
Eric Laurente8c8b432018-10-17 10:08:02 -0700357 std::unordered_map<uid_t, std::pair<bool, int>> mOverrideUids;
358 std::unordered_map<uid_t, std::pair<bool, int>> mCachedUids;
Eric Laurentb78763e2018-10-17 10:08:02 -0700359 uid_t mAssistantUid;
360 std::vector<uid_t> mA11yUids;
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800361 };
362
Michael Groovercfd28302018-12-11 19:16:46 -0800363 // If sensor privacy is enabled then all apps, including those that are active, should be
364 // prevented from recording. This is handled similar to idle UIDs, any app that attempts
365 // to record while sensor privacy is enabled will receive buffers with zeros. As soon as
366 // sensor privacy is disabled active apps will receive the expected data when recording.
367 class SensorPrivacyPolicy : public hardware::BnSensorPrivacyListener {
368 public:
369 explicit SensorPrivacyPolicy(wp<AudioPolicyService> service)
370 : mService(service) {}
371
372 void registerSelf();
373 void unregisterSelf();
374
375 bool isSensorPrivacyEnabled();
376
377 binder::Status onSensorPrivacyChanged(bool enabled);
378
379 private:
380 wp<AudioPolicyService> mService;
381 std::atomic_bool mSensorPrivacyEnabled;
382 };
383
Eric Laurentdcd4ab12018-06-29 17:45:13 -0700384 // Thread used to send audio config commands to audio flinger
Glenn Kasten85ab62c2012-11-01 11:11:38 -0700385 // For audio config commands, it is necessary because audio flinger requires that the calling
386 // process (user) has permission to modify audio settings.
Mathias Agopian65ab4712010-07-14 17:59:35 -0700387 class AudioCommandThread : public Thread {
388 class AudioCommand;
389 public:
390
391 // commands for tone AudioCommand
392 enum {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700393 SET_VOLUME,
394 SET_PARAMETERS,
Eric Laurentbfb1b832013-01-07 09:53:42 -0800395 SET_VOICE_VOLUME,
396 STOP_OUTPUT,
Eric Laurent951f4552014-05-20 10:48:17 -0700397 RELEASE_OUTPUT,
398 CREATE_AUDIO_PATCH,
399 RELEASE_AUDIO_PATCH,
Eric Laurentb52c1522014-05-20 11:27:36 -0700400 UPDATE_AUDIOPORT_LIST,
Eric Laurente1715a42014-05-20 11:30:42 -0700401 UPDATE_AUDIOPATCH_LIST,
402 SET_AUDIOPORT_CONFIG,
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800403 DYN_POLICY_MIX_STATE_UPDATE,
404 RECORDING_CONFIGURATION_UPDATE
Mathias Agopian65ab4712010-07-14 17:59:35 -0700405 };
406
Eric Laurentbfb1b832013-01-07 09:53:42 -0800407 AudioCommandThread (String8 name, const wp<AudioPolicyService>& service);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700408 virtual ~AudioCommandThread();
409
410 status_t dump(int fd);
411
412 // Thread virtuals
413 virtual void onFirstRef();
414 virtual bool threadLoop();
415
416 void exit();
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800417 status_t volumeCommand(audio_stream_type_t stream, float volume,
418 audio_io_handle_t output, int delayMs = 0);
419 status_t parametersCommand(audio_io_handle_t ioHandle,
420 const char *keyValuePairs, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700421 status_t voiceVolumeCommand(float volume, int delayMs = 0);
Eric Laurentd7fe0862018-07-14 16:48:01 -0700422 void stopOutputCommand(audio_port_handle_t portId);
423 void releaseOutputCommand(audio_port_handle_t portId);
Eric Laurent0ede8922014-05-09 18:04:42 -0700424 status_t sendCommand(sp<AudioCommand>& command, int delayMs = 0);
425 void insertCommand_l(sp<AudioCommand>& command, int delayMs = 0);
Eric Laurent951f4552014-05-20 10:48:17 -0700426 status_t createAudioPatchCommand(const struct audio_patch *patch,
427 audio_patch_handle_t *handle,
428 int delayMs);
429 status_t releaseAudioPatchCommand(audio_patch_handle_t handle,
430 int delayMs);
Eric Laurentb52c1522014-05-20 11:27:36 -0700431 void updateAudioPortListCommand();
432 void updateAudioPatchListCommand();
Eric Laurente1715a42014-05-20 11:30:42 -0700433 status_t setAudioPortConfigCommand(const struct audio_port_config *config,
434 int delayMs);
Eric Laurenta9f86652018-11-28 17:23:11 -0800435 void dynamicPolicyMixStateUpdateCommand(const String8& regId,
436 int32_t state);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800437 void recordingConfigurationUpdateCommand(
Eric Laurenta9f86652018-11-28 17:23:11 -0800438 int event,
439 const record_client_info_t *clientInfo,
440 const audio_config_base_t *clientConfig,
441 std::vector<effect_descriptor_t> clientEffects,
442 const audio_config_base_t *deviceConfig,
443 std::vector<effect_descriptor_t> effects,
444 audio_patch_handle_t patchHandle,
445 audio_source_t source);
Eric Laurent951f4552014-05-20 10:48:17 -0700446 void insertCommand_l(AudioCommand *command, int delayMs = 0);
Mathias Agopian65ab4712010-07-14 17:59:35 -0700447 private:
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100448 class AudioCommandData;
449
Mathias Agopian65ab4712010-07-14 17:59:35 -0700450 // descriptor for requested tone playback event
Eric Laurent0ede8922014-05-09 18:04:42 -0700451 class AudioCommand: public RefBase {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700452
453 public:
454 AudioCommand()
Eric Laurent0ede8922014-05-09 18:04:42 -0700455 : mCommand(-1), mStatus(NO_ERROR), mWaitStatus(false) {}
Mathias Agopian65ab4712010-07-14 17:59:35 -0700456
457 void dump(char* buffer, size_t size);
458
Eric Laurentdcd4ab12018-06-29 17:45:13 -0700459 int mCommand; // SET_VOLUME, SET_PARAMETERS...
Mathias Agopian65ab4712010-07-14 17:59:35 -0700460 nsecs_t mTime; // time stamp
Eric Laurent0ede8922014-05-09 18:04:42 -0700461 Mutex mLock; // mutex associated to mCond
Mathias Agopian65ab4712010-07-14 17:59:35 -0700462 Condition mCond; // condition for status return
463 status_t mStatus; // command status
464 bool mWaitStatus; // true if caller is waiting for status
Eric Laurent0ede8922014-05-09 18:04:42 -0700465 sp<AudioCommandData> mParam; // command specific parameter data
Mathias Agopian65ab4712010-07-14 17:59:35 -0700466 };
467
Eric Laurent0ede8922014-05-09 18:04:42 -0700468 class AudioCommandData: public RefBase {
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100469 public:
470 virtual ~AudioCommandData() {}
471 protected:
472 AudioCommandData() {}
473 };
474
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100475 class VolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700476 public:
Glenn Kastenfff6d712012-01-12 16:38:12 -0800477 audio_stream_type_t mStream;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700478 float mVolume;
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800479 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700480 };
481
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100482 class ParametersData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700483 public:
Glenn Kasten72ef00d2012-01-17 11:09:42 -0800484 audio_io_handle_t mIO;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700485 String8 mKeyValuePairs;
486 };
487
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100488 class VoiceVolumeData : public AudioCommandData {
Mathias Agopian65ab4712010-07-14 17:59:35 -0700489 public:
490 float mVolume;
491 };
492
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100493 class StopOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800494 public:
Eric Laurentd7fe0862018-07-14 16:48:01 -0700495 audio_port_handle_t mPortId;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800496 };
497
Jesper Tragardh48412dc2014-03-24 14:12:43 +0100498 class ReleaseOutputData : public AudioCommandData {
Eric Laurentbfb1b832013-01-07 09:53:42 -0800499 public:
Eric Laurentd7fe0862018-07-14 16:48:01 -0700500 audio_port_handle_t mPortId;
Eric Laurentbfb1b832013-01-07 09:53:42 -0800501 };
502
Eric Laurent951f4552014-05-20 10:48:17 -0700503 class CreateAudioPatchData : public AudioCommandData {
504 public:
505 struct audio_patch mPatch;
506 audio_patch_handle_t mHandle;
507 };
508
509 class ReleaseAudioPatchData : public AudioCommandData {
510 public:
511 audio_patch_handle_t mHandle;
512 };
513
Eric Laurente1715a42014-05-20 11:30:42 -0700514 class SetAudioPortConfigData : public AudioCommandData {
515 public:
516 struct audio_port_config mConfig;
517 };
518
Jean-Michel Trivide801052015-04-14 19:10:14 -0700519 class DynPolicyMixStateUpdateData : public AudioCommandData {
520 public:
521 String8 mRegId;
522 int32_t mState;
523 };
524
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800525 class RecordingConfigurationUpdateData : public AudioCommandData {
526 public:
527 int mEvent;
Jean-Michel Triviac4e4292016-12-22 11:39:31 -0800528 record_client_info_t mClientInfo;
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800529 struct audio_config_base mClientConfig;
Eric Laurenta9f86652018-11-28 17:23:11 -0800530 std::vector<effect_descriptor_t> mClientEffects;
Jean-Michel Trivi7281aa92016-02-17 15:33:40 -0800531 struct audio_config_base mDeviceConfig;
Eric Laurenta9f86652018-11-28 17:23:11 -0800532 std::vector<effect_descriptor_t> mEffects;
Jean-Michel Trivi8c7cf3b2016-02-25 17:08:24 -0800533 audio_patch_handle_t mPatchHandle;
Eric Laurenta9f86652018-11-28 17:23:11 -0800534 audio_source_t mSource;
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800535 };
536
Mathias Agopian65ab4712010-07-14 17:59:35 -0700537 Mutex mLock;
538 Condition mWaitWorkCV;
Eric Laurent0ede8922014-05-09 18:04:42 -0700539 Vector < sp<AudioCommand> > mAudioCommands; // list of pending commands
Eric Laurent0ede8922014-05-09 18:04:42 -0700540 sp<AudioCommand> mLastCommand; // last processed command (used by dump)
Mathias Agopian65ab4712010-07-14 17:59:35 -0700541 String8 mName; // string used by wake lock fo delayed commands
Eric Laurentbfb1b832013-01-07 09:53:42 -0800542 wp<AudioPolicyService> mService;
Mathias Agopian65ab4712010-07-14 17:59:35 -0700543 };
544
Eric Laurentdce54a12014-03-10 12:19:46 -0700545 class AudioPolicyClient : public AudioPolicyClientInterface
546 {
547 public:
Chih-Hung Hsiehe964d4e2016-08-09 14:31:32 -0700548 explicit AudioPolicyClient(AudioPolicyService *service) : mAudioPolicyService(service) {}
Eric Laurentdce54a12014-03-10 12:19:46 -0700549 virtual ~AudioPolicyClient() {}
550
551 //
552 // Audio HW module functions
553 //
554
555 // loads a HW module.
556 virtual audio_module_handle_t loadHwModule(const char *name);
557
558 //
559 // Audio output Control functions
560 //
561
562 // opens an audio output with the requested parameters. The parameter values can indicate to use the default values
563 // in case the audio policy manager has no specific requirements for the output being opened.
564 // When the function returns, the parameter values reflect the actual values used by the audio hardware output stream.
565 // The audio policy manager can check if the proposed parameters are suitable or not and act accordingly.
Eric Laurentcf2c0212014-07-25 16:20:43 -0700566 virtual status_t openOutput(audio_module_handle_t module,
567 audio_io_handle_t *output,
568 audio_config_t *config,
569 audio_devices_t *devices,
570 const String8& address,
571 uint32_t *latencyMs,
572 audio_output_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700573 // creates a special output that is duplicated to the two outputs passed as arguments. The duplication is performed by
574 // a special mixer thread in the AudioFlinger.
575 virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, audio_io_handle_t output2);
576 // closes the output stream
577 virtual status_t closeOutput(audio_io_handle_t output);
578 // suspends the output. When an output is suspended, the corresponding audio hardware output stream is placed in
579 // standby and the AudioTracks attached to the mixer thread are still processed but the output mix is discarded.
580 virtual status_t suspendOutput(audio_io_handle_t output);
581 // restores a suspended output.
582 virtual status_t restoreOutput(audio_io_handle_t output);
583
584 //
585 // Audio input Control functions
586 //
587
588 // opens an audio input
589 virtual audio_io_handle_t openInput(audio_module_handle_t module,
Eric Laurentcf2c0212014-07-25 16:20:43 -0700590 audio_io_handle_t *input,
591 audio_config_t *config,
592 audio_devices_t *devices,
593 const String8& address,
594 audio_source_t source,
Glenn Kastenec40d282014-07-15 15:31:26 -0700595 audio_input_flags_t flags);
Eric Laurentdce54a12014-03-10 12:19:46 -0700596 // closes an audio input
597 virtual status_t closeInput(audio_io_handle_t input);
598 //
599 // misc control functions
600 //
601
602 // set a stream volume for a particular output. For the same user setting, a given stream type can have different volumes
603 // for each output (destination device) it is attached to.
604 virtual status_t setStreamVolume(audio_stream_type_t stream, float volume, audio_io_handle_t output, int delayMs = 0);
605
606 // invalidate a stream type, causing a reroute to an unspecified new output
607 virtual status_t invalidateStream(audio_stream_type_t stream);
608
609 // function enabling to send proprietary informations directly from audio policy manager to audio hardware interface.
610 virtual void setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs, int delayMs = 0);
611 // function enabling to receive proprietary informations directly from audio hardware interface to audio policy manager.
612 virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys);
613
Eric Laurentdce54a12014-03-10 12:19:46 -0700614 // set down link audio volume.
615 virtual status_t setVoiceVolume(float volume, int delayMs = 0);
616
617 // move effect to the specified output
Glenn Kastend848eb42016-03-08 13:42:11 -0800618 virtual status_t moveEffects(audio_session_t session,
Eric Laurentdce54a12014-03-10 12:19:46 -0700619 audio_io_handle_t srcOutput,
620 audio_io_handle_t dstOutput);
621
Eric Laurent951f4552014-05-20 10:48:17 -0700622 /* Create a patch between several source and sink ports */
623 virtual status_t createAudioPatch(const struct audio_patch *patch,
624 audio_patch_handle_t *handle,
625 int delayMs);
626
627 /* Release a patch */
628 virtual status_t releaseAudioPatch(audio_patch_handle_t handle,
629 int delayMs);
630
Eric Laurente1715a42014-05-20 11:30:42 -0700631 /* Set audio port configuration */
632 virtual status_t setAudioPortConfig(const struct audio_port_config *config, int delayMs);
633
Eric Laurentb52c1522014-05-20 11:27:36 -0700634 virtual void onAudioPortListUpdate();
635 virtual void onAudioPatchListUpdate();
Jean-Michel Trivide801052015-04-14 19:10:14 -0700636 virtual void onDynamicPolicyMixStateUpdate(String8 regId, int32_t state);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800637 virtual void onRecordingConfigurationUpdate(int event,
Eric Laurenta9f86652018-11-28 17:23:11 -0800638 const record_client_info_t *clientInfo,
639 const audio_config_base_t *clientConfig,
640 std::vector<effect_descriptor_t> clientEffects,
641 const audio_config_base_t *deviceConfig,
642 std::vector<effect_descriptor_t> effects,
643 audio_patch_handle_t patchHandle,
644 audio_source_t source);
Eric Laurentb52c1522014-05-20 11:27:36 -0700645
Glenn Kasteneeecb982016-02-26 10:44:04 -0800646 virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use);
Eric Laurentde3f8392014-07-27 18:38:22 -0700647
Eric Laurentdce54a12014-03-10 12:19:46 -0700648 private:
649 AudioPolicyService *mAudioPolicyService;
650 };
651
Eric Laurentb52c1522014-05-20 11:27:36 -0700652 // --- Notification Client ---
653 class NotificationClient : public IBinder::DeathRecipient {
654 public:
655 NotificationClient(const sp<AudioPolicyService>& service,
656 const sp<IAudioPolicyServiceClient>& client,
luochaojiang908c7d72018-06-21 14:58:04 +0800657 uid_t uid, pid_t pid);
Eric Laurentb52c1522014-05-20 11:27:36 -0700658 virtual ~NotificationClient();
659
Jean-Michel Trivide801052015-04-14 19:10:14 -0700660 void onAudioPortListUpdate();
661 void onAudioPatchListUpdate();
Eric Laurenta9f86652018-11-28 17:23:11 -0800662 void onDynamicPolicyMixStateUpdate(const String8& regId,
663 int32_t state);
Jean-Michel Trivi2f4fe9f2015-12-04 16:20:59 -0800664 void onRecordingConfigurationUpdate(
Eric Laurenta9f86652018-11-28 17:23:11 -0800665 int event,
666 const record_client_info_t *clientInfo,
667 const audio_config_base_t *clientConfig,
668 std::vector<effect_descriptor_t> clientEffects,
669 const audio_config_base_t *deviceConfig,
670 std::vector<effect_descriptor_t> effects,
671 audio_patch_handle_t patchHandle,
672 audio_source_t source);
Eric Laurente8726fe2015-06-26 09:39:24 -0700673 void setAudioPortCallbacksEnabled(bool enabled);
Eric Laurentb52c1522014-05-20 11:27:36 -0700674
luochaojiang908c7d72018-06-21 14:58:04 +0800675 uid_t uid() {
676 return mUid;
677 }
678
Eric Laurentb52c1522014-05-20 11:27:36 -0700679 // IBinder::DeathRecipient
680 virtual void binderDied(const wp<IBinder>& who);
681
682 private:
683 NotificationClient(const NotificationClient&);
684 NotificationClient& operator = (const NotificationClient&);
685
686 const wp<AudioPolicyService> mService;
687 const uid_t mUid;
luochaojiang908c7d72018-06-21 14:58:04 +0800688 const pid_t mPid;
Eric Laurentb52c1522014-05-20 11:27:36 -0700689 const sp<IAudioPolicyServiceClient> mAudioPolicyServiceClient;
Eric Laurente8726fe2015-06-26 09:39:24 -0700690 bool mAudioPortCallbacksEnabled;
Eric Laurentb52c1522014-05-20 11:27:36 -0700691 };
692
Eric Laurentd7fe0862018-07-14 16:48:01 -0700693 class AudioClient : public virtual RefBase {
694 public:
695 AudioClient(const audio_attributes_t attributes,
696 const audio_io_handle_t io, uid_t uid, pid_t pid,
697 const audio_session_t session, const audio_port_handle_t deviceId) :
698 attributes(attributes), io(io), uid(uid), pid(pid),
699 session(session), deviceId(deviceId), active(false) {}
700 ~AudioClient() override = default;
701
702
703 const audio_attributes_t attributes; // source, flags ...
704 const audio_io_handle_t io; // audio HAL stream IO handle
705 const uid_t uid; // client UID
706 const pid_t pid; // client PID
707 const audio_session_t session; // audio session ID
708 const audio_port_handle_t deviceId; // selected input device port ID
709 bool active; // Playback/Capture is active or inactive
710 };
711
Eric Laurentfee19762018-01-29 18:44:13 -0800712 // --- AudioRecordClient ---
713 // Information about each registered AudioRecord client
714 // (between calls to getInputForAttr() and releaseInput())
Eric Laurentd7fe0862018-07-14 16:48:01 -0700715 class AudioRecordClient : public AudioClient {
Eric Laurentfee19762018-01-29 18:44:13 -0800716 public:
717 AudioRecordClient(const audio_attributes_t attributes,
Eric Laurentd7fe0862018-07-14 16:48:01 -0700718 const audio_io_handle_t io, uid_t uid, pid_t pid,
719 const audio_session_t session, const audio_port_handle_t deviceId,
720 const String16& opPackageName) :
721 AudioClient(attributes, io, uid, pid, session, deviceId),
Eric Laurent4eb58f12018-12-07 16:41:02 -0800722 opPackageName(opPackageName), startTimeNs(0) {}
Eric Laurentd7fe0862018-07-14 16:48:01 -0700723 ~AudioRecordClient() override = default;
Eric Laurentfee19762018-01-29 18:44:13 -0800724
Eric Laurentfee19762018-01-29 18:44:13 -0800725 const String16 opPackageName; // client package name
Eric Laurent4eb58f12018-12-07 16:41:02 -0800726 nsecs_t startTimeNs;
Eric Laurentd7fe0862018-07-14 16:48:01 -0700727 };
728
729 // --- AudioPlaybackClient ---
730 // Information about each registered AudioTrack client
731 // (between calls to getOutputForAttr() and releaseOutput())
732 class AudioPlaybackClient : public AudioClient {
733 public:
734 AudioPlaybackClient(const audio_attributes_t attributes,
735 const audio_io_handle_t io, uid_t uid, pid_t pid,
736 const audio_session_t session, audio_port_handle_t deviceId,
737 audio_stream_type_t stream) :
738 AudioClient(attributes, io, uid, pid, session, deviceId), stream(stream) {}
739 ~AudioPlaybackClient() override = default;
740
741 const audio_stream_type_t stream;
Eric Laurentfee19762018-01-29 18:44:13 -0800742 };
743
Eric Laurent10b71232018-04-13 18:14:44 -0700744 // A class automatically clearing and restoring binder caller identity inside
745 // a code block (scoped variable)
746 // Declare one systematically before calling AudioPolicyManager methods so that they are
747 // executed with the same level of privilege as audioserver process.
748 class AutoCallerClear {
749 public:
750 AutoCallerClear() :
751 mToken(IPCThreadState::self()->clearCallingIdentity()) {}
752 ~AutoCallerClear() {
753 IPCThreadState::self()->restoreCallingIdentity(mToken);
754 }
755
756 private:
757 const int64_t mToken;
758 };
759
Mathias Agopian65ab4712010-07-14 17:59:35 -0700760 // Internal dump utilities.
761 status_t dumpPermissionDenial(int fd);
762
763
Eric Laurenteda6c362011-02-02 09:33:30 -0800764 mutable Mutex mLock; // prevents concurrent access to AudioPolicy manager functions changing
765 // device connection state or routing
Haynes Mathew Georgebab7bf42015-10-30 18:02:23 -0700766 mutable Mutex mEffectsLock; // serialize access to Effect state within APM.
767 // Note: lock acquisition order is always mLock > mEffectsLock:
768 // mLock protects AudioPolicyManager methods that can call into audio flinger
769 // and possibly back in to audio policy service and acquire mEffectsLock.
Glenn Kastene53b9ea2012-03-12 16:29:55 -0700770 sp<AudioCommandThread> mAudioCommandThread; // audio commands thread
Eric Laurentbfb1b832013-01-07 09:53:42 -0800771 sp<AudioCommandThread> mOutputCommandThread; // process stop and release output
Dima Zavinfce7a472011-04-19 22:30:36 -0700772 struct audio_policy_device *mpAudioPolicyDev;
773 struct audio_policy *mpAudioPolicy;
Eric Laurentf269b8e2014-06-09 20:01:29 -0700774 AudioPolicyInterface *mAudioPolicyManager;
Eric Laurentdce54a12014-03-10 12:19:46 -0700775 AudioPolicyClient *mAudioPolicyClient;
776
luochaojiang908c7d72018-06-21 14:58:04 +0800777 DefaultKeyedVector< int64_t, sp<NotificationClient> > mNotificationClients;
Eric Laurent0ebd5f92014-11-19 19:04:52 -0800778 Mutex mNotificationClientsLock; // protects mNotificationClients
bryant_liuba2b4392014-06-11 16:49:30 +0800779 // Manage all effects configured in audio_effects.conf
780 sp<AudioPolicyEffects> mAudioPolicyEffects;
Eric Laurentbb6c9a02014-09-25 14:11:47 -0700781 audio_mode_t mPhoneState;
Svet Ganovf4ddfef2018-01-16 07:37:58 -0800782
783 sp<UidPolicy> mUidPolicy;
Michael Groovercfd28302018-12-11 19:16:46 -0800784 sp<SensorPrivacyPolicy> mSensorPrivacyPolicy;
785
Eric Laurentfee19762018-01-29 18:44:13 -0800786 DefaultKeyedVector< audio_port_handle_t, sp<AudioRecordClient> > mAudioRecordClients;
Eric Laurentd7fe0862018-07-14 16:48:01 -0700787 DefaultKeyedVector< audio_port_handle_t, sp<AudioPlaybackClient> > mAudioPlaybackClients;
Kevin Rocard8be94972019-02-22 13:26:25 -0800788
789 MediaPackageManager mPackageManager; // To check allowPlaybackCapture
Mathias Agopian65ab4712010-07-14 17:59:35 -0700790};
791
Mikhail Naganov1b2a7942017-12-08 10:18:09 -0800792} // namespace android
Mathias Agopian65ab4712010-07-14 17:59:35 -0700793
794#endif // ANDROID_AUDIOPOLICYSERVICE_H