• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ST_AUDIO_POLICY_MANAGER_H
17 #define ST_AUDIO_POLICY_MANAGER_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include "audio_client_tracker_callback_service.h"
22 #include "audio_client_tracker_callback_listener.h"
23 #include "audio_effect.h"
24 #include "audio_interrupt_callback.h"
25 #include "iaudio_policy.h"
26 #include "audio_policy_manager_listener_stub_impl.h"
27 #include "audio_policy_client_stub_impl.h"
28 #include "audio_routing_manager.h"
29 #include "audio_routing_manager_listener.h"
30 #include "audio_anahs_manager_listener.h"
31 #include "audio_policy_interface.h"
32 #include "audio_system_manager.h"
33 #include "istandard_client_tracker.h"
34 #include "audio_policy_log.h"
35 #include "microphone_descriptor.h"
36 #include "audio_spatialization_manager.h"
37 #include "audio_combine_denoising_manager.h"
38 #include "audio_stream_descriptor.h"
39 #include "sle_audio_operation_callback_stub_impl.h"
40 
41 namespace OHOS {
42 namespace AudioStandard {
43 using InternalDeviceType = DeviceType;
44 using InternalAudioCapturerOptions = AudioCapturerOptions;
45 using AudioServerDiedCallBack = std::function<void()>;
46 
47 struct CallbackChangeInfo {
48     std::mutex mutex;
49     bool isEnable = false;
50 };
51 
52 class AudioPolicyManager {
53 public:
54     static AudioPolicyManager& GetInstance();
55     static const sptr<IAudioPolicy> GetAudioPolicyManagerProxy(bool block = true);
56 
57     int32_t GetMaxVolumeLevel(AudioVolumeType volumeType, DeviceType deviceType = DEVICE_TYPE_NONE);
58 
59     int32_t GetMinVolumeLevel(AudioVolumeType volumeType, DeviceType deviceType = DEVICE_TYPE_NONE);
60 
61     int32_t SetSystemVolumeLevel(AudioVolumeType volumeType, int32_t volumeLevel, bool isLegacy = false,
62         int32_t volumeFlag = 0, int32_t uid = 0);
63 
64     int32_t SetSystemNotificationVolumeLevel(AudioVolumeType volumeType, int32_t volumeLevel, bool isLegacy = false,
65         int32_t volumeFlag = 0, int32_t uid = 0);
66 
67     int32_t SetSystemVolumeLevelWithDevice(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType,
68         int32_t volumeFlag = 0);
69     int32_t SetAppVolumeLevel(int32_t appUid, int32_t volumeLevel, int32_t volumeFlag = 0);
70 
71     int32_t SetAppVolumeMuted(int32_t appUid, bool muted, int32_t volumeFlag = 0);
72 
73     int32_t SetAppRingMuted(int32_t appUid, bool muted);
74 
75     int32_t SetAdjustVolumeForZone(int32_t zoneId);
76 
77     int32_t IsAppVolumeMute(int32_t appUid, bool muted, bool &isMute);
78 
79     int32_t SetSelfAppVolumeLevel(int32_t volumeLevel, int32_t volumeFlag = 0);
80 
81     AudioStreamType GetSystemActiveVolumeType(const int32_t clientUid);
82 
83     int32_t GetSystemVolumeLevel(AudioVolumeType volumeType, int32_t uid = 0);
84 
85     int32_t GetSystemNotificationVolumeLevel(AudioVolumeType volumeType, int32_t uid = 0);
86 
87     int32_t GetAppVolumeLevel(int32_t appUid, int32_t &volumeLevel);
88 
89     int32_t GetSelfAppVolumeLevel(int32_t &volumeLevel);
90 
91     int32_t SetLowPowerVolume(int32_t streamId, float volume);
92 
93     float GetLowPowerVolume(int32_t streamId);
94 
95     float GetSingleStreamVolume(int32_t streamId);
96 
97     AudioStreamInfo GetFastStreamInfo();
98 
99     int32_t SetStreamMute(AudioVolumeType volumeType, bool mute, bool isLegacy = false,
100         const DeviceType &deviceType = DEVICE_TYPE_NONE);
101 
102     bool GetStreamMute(AudioVolumeType volumeType);
103 
104     bool IsStreamActive(AudioVolumeType volumeType);
105 
106     bool IsStreamActiveByStreamUsage(StreamUsage streamUsage);
107 
108     bool IsFastPlaybackSupported(AudioStreamInfo &streamInfo, StreamUsage usage);
109     bool IsFastRecordingSupported(AudioStreamInfo &streamInfo, SourceType source);
110 
111     int32_t SelectOutputDevice(sptr<AudioRendererFilter> audioRendererFilter,
112         std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors);
113 
114     std::string GetSelectedDeviceInfo(int32_t uid, int32_t pid, AudioStreamType streamType);
115 
116     int32_t SelectInputDevice(sptr<AudioCapturerFilter> audioCapturerFilter,
117         std::vector<std::shared_ptr<AudioDeviceDescriptor>> audioDeviceDescriptors);
118 
119     int32_t ExcludeOutputDevices(AudioDeviceUsage audioDevUsage,
120         std::vector<std::shared_ptr<AudioDeviceDescriptor>> &audioDeviceDescriptors);
121 
122     int32_t UnexcludeOutputDevices(AudioDeviceUsage audioDevUsage,
123         std::vector<std::shared_ptr<AudioDeviceDescriptor>> &audioDeviceDescriptors);
124 
125     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetExcludedDevices(
126         AudioDeviceUsage audioDevUsage);
127 
128     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevices(DeviceFlag deviceFlag);
129 
130     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetDevicesInner(DeviceFlag deviceFlag);
131 
132     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetOutputDevice(
133         sptr<AudioRendererFilter> audioRendererFilter);
134 
135     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetInputDevice(
136         sptr<AudioCapturerFilter> audioCapturerFilter);
137 
138     int32_t SetDeviceActive(InternalDeviceType deviceType, bool active, const int32_t uid = INVALID_UID);
139 
140     bool IsDeviceActive(InternalDeviceType deviceType);
141 
142     DeviceType GetActiveOutputDevice();
143 
144     uint16_t GetDmDeviceType();
145 
146     DeviceType GetActiveInputDevice();
147 
148     int32_t SetRingerModeLegacy(AudioRingerMode ringMode);
149 
150     int32_t SetRingerMode(AudioRingerMode ringMode);
151 
152 #ifdef FEATURE_DTMF_TONE
153     std::vector<int32_t> GetSupportedTones(const std::string &countryCode);
154 
155     std::shared_ptr<ToneInfo> GetToneConfig(int32_t ltonetype, const std::string &countryCode);
156 #endif
157 
158     AudioRingerMode GetRingerMode();
159 
160     int32_t SetAudioScene(AudioScene scene);
161 
162     int32_t SetMicrophoneMute(bool isMute);
163 
164     int32_t SetMicrophoneMuteAudioConfig(bool isMute);
165 
166     int32_t SetMicrophoneMutePersistent(const bool isMute, const PolicyType type);
167 
168     bool GetPersistentMicMuteState();
169 
170     bool IsMicrophoneMuteLegacy();
171 
172     bool IsMicrophoneMute();
173 
174     AudioScene GetAudioScene();
175 
176     int32_t SetDeviceChangeCallback(const int32_t clientId, const DeviceFlag flag,
177         const std::shared_ptr<AudioManagerDeviceChangeCallback> &callback);
178 
179     int32_t UnsetDeviceChangeCallback(const int32_t clientId, DeviceFlag flag,
180         std::shared_ptr<AudioManagerDeviceChangeCallback> &cb);
181 
182     int32_t SetRingerModeCallback(const int32_t clientId,
183         const std::shared_ptr<AudioRingerModeCallback> &callback, API_VERSION api_v = API_9);
184 
185     int32_t SetAppVolumeChangeCallbackForUid(const int32_t appUid,
186         const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback);
187 
188     int32_t UnsetAppVolumeCallbackForUid(
189         const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback = nullptr);
190 
191     int32_t SetSelfAppVolumeChangeCallback(const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback);
192 
193     int32_t UnsetSelfAppVolumeCallback(const std::shared_ptr<AudioManagerAppVolumeChangeCallback> &callback);
194 
195     int32_t SetActiveVolumeTypeCallback(const std::shared_ptr<AudioManagerActiveVolumeTypeChangeCallback> &callback);
196 
197     int32_t UnsetActiveVolumeTypeCallback(const std::shared_ptr<AudioManagerActiveVolumeTypeChangeCallback> &callback);
198 
199     int32_t UnsetRingerModeCallback(const int32_t clientId);
200 
201     int32_t UnsetRingerModeCallback(const int32_t clientId,
202         const std::shared_ptr<AudioRingerModeCallback> &callback);
203 
204     int32_t SetMicStateChangeCallback(const int32_t clientId,
205         const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback);
206 
207     int32_t UnsetMicStateChangeCallback(const std::shared_ptr<AudioManagerMicStateChangeCallback> &callback);
208 
209     int32_t SetAudioInterruptCallback(const uint32_t sessionID,
210         const std::shared_ptr<AudioInterruptCallback> &callback, uint32_t clientUid, const int32_t zoneID = 0);
211 
212     int32_t UnsetAudioInterruptCallback(const uint32_t sessionID, const int32_t zoneID = 0);
213 
214     int32_t ActivateAudioInterrupt(
215         AudioInterrupt &audioInterrupt, const int32_t zoneID = 0, const bool isUpdatedAudioStrategy = false);
216 
217     int32_t SetAppConcurrencyMode(const int32_t appUid, const int32_t mode = 0);
218 
219     int32_t SetAppSlientOnDisplay(const int32_t displayId = -1);
220 
221     int32_t DeactivateAudioInterrupt(const AudioInterrupt &audioInterrupt, const int32_t zoneID = 0);
222 
223     int32_t ActivatePreemptMode(void);
224 
225     int32_t DeactivatePreemptMode(void);
226 
227     int32_t SetQueryClientTypeCallback(const std::shared_ptr<AudioQueryClientTypeCallback> &callback);
228 
229     int32_t SetQueryBundleNameListCallback(const std::shared_ptr<AudioQueryBundleNameListCallback> &callback);
230 
231     int32_t SetAudioManagerInterruptCallback(const int32_t clientId,
232         const std::shared_ptr<AudioInterruptCallback> &callback);
233 
234     int32_t UnsetAudioManagerInterruptCallback(const int32_t clientId);
235 
236     int32_t RequestAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt);
237 
238     int32_t AbandonAudioFocus(const int32_t clientId, const AudioInterrupt &audioInterrupt);
239 
240     AudioStreamType GetStreamInFocus(const int32_t zoneID = 0);
241 
242     AudioStreamType GetStreamInFocusByUid(const int32_t uid, const int32_t zoneID = 0);
243 
244     int32_t GetSessionInfoInFocus(AudioInterrupt &audioInterrupt, const int32_t zoneID = 0);
245 
246     int32_t RegisterAudioPolicyServerDiedCb(std::shared_ptr<AudioSessionManagerPolicyServiceDiedCallback> &callback);
247 
248     static void AudioSessionManagerCallback();
249 
250     int32_t ActivateAudioSession(const AudioSessionStrategy &strategy);
251 
252     int32_t DeactivateAudioSession();
253 
254     bool IsAudioSessionActivated();
255 
256     int32_t SetAudioSessionCallback(const std::shared_ptr<AudioSessionCallback> &audioSessionCallback);
257 
258     int32_t UnsetAudioSessionCallback();
259 
260     int32_t UnsetAudioSessionCallback(const std::shared_ptr<AudioSessionCallback> &audioSessionCallback);
261 
262     int32_t SetAudioSessionScene(const AudioSessionScene audioSessionScene);
263 
264     int32_t SetAudioSessionStateChangeCallback(
265         const std::shared_ptr<AudioSessionStateChangedCallback> &stateChangedCallback);
266 
267     int32_t UnsetAudioSessionStateChangeCallback();
268 
269     int32_t UnsetAudioSessionStateChangeCallback(
270         const std::shared_ptr<AudioSessionStateChangedCallback> &stateChangedCallback);
271 
272     int32_t GetDefaultOutputDevice(DeviceType &deviceType);
273 
274     int32_t SetDefaultOutputDevice(DeviceType deviceType);
275 
276     int32_t SetAudioSessionCurrentDeviceChangeCallback(
277         const std::shared_ptr<AudioSessionCurrentDeviceChangedCallback> &deviceChangedCallback);
278 
279     int32_t UnsetAudioSessionCurrentDeviceChangeCallback();
280 
281     int32_t UnsetAudioSessionCurrentDeviceChangeCallback(
282         const std::shared_ptr<AudioSessionCurrentDeviceChangedCallback> &deviceChangedCallback);
283 
284     int32_t SetVolumeKeyEventCallback(const int32_t clientPid,
285         const std::shared_ptr<VolumeKeyEventCallback> &callback, API_VERSION api_v = API_9);
286 
287     int32_t UnsetVolumeKeyEventCallback(const std::shared_ptr<VolumeKeyEventCallback> &callback);
288 
289     int32_t SetSystemVolumeChangeCallback(const int32_t clientPid,
290         const std::shared_ptr<SystemVolumeChangeCallback> &callback);
291 
292     int32_t UnsetSystemVolumeChangeCallback(const std::shared_ptr<SystemVolumeChangeCallback> &callback);
293 
294     int32_t GetPreferredOutputStreamType(AudioRendererInfo &rendererInfo);
295 
296     int32_t GetPreferredInputStreamType(AudioCapturerInfo &capturerInfo);
297 
298     int32_t CreateRendererClient(
299         std::shared_ptr<AudioStreamDescriptor> streamDesc, uint32_t &flag, uint32_t &sessionId, std::string &networkId);
300 
301     int32_t CreateCapturerClient(
302         std::shared_ptr<AudioStreamDescriptor> streamDesc, uint32_t &flag, uint32_t &sessionId);
303 
304     int32_t RegisterAudioRendererEventListener(const std::shared_ptr<AudioRendererStateChangeCallback> &callback);
305 
306     int32_t UnregisterAudioRendererEventListener(
307         const std::vector<std::shared_ptr<AudioRendererStateChangeCallback>> &callbacks);
308 
309     int32_t UnregisterAudioRendererEventListener(
310         const std::shared_ptr<AudioRendererStateChangeCallback> &callback);
311 
312     int32_t RegisterAudioCapturerEventListener(const int32_t clientPid,
313         const std::shared_ptr<AudioCapturerStateChangeCallback> &callback);
314 
315     int32_t UnregisterAudioCapturerEventListener(const int32_t clientPid);
316 
317     int32_t RegisterDeviceChangeWithInfoCallback(
318         const uint32_t sessionID, const std::weak_ptr<DeviceChangeWithInfoCallback> &callback);
319 
320     int32_t UnregisterDeviceChangeWithInfoCallback(const uint32_t sessionID);
321 
322     int32_t RegisterTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo,
323         const std::shared_ptr<AudioClientTracker> &clientTrackerObj);
324 
325     int32_t UpdateTracker(AudioMode &mode, AudioStreamChangeInfo &streamChangeInfo);
326 
327     int32_t GetCurrentRendererChangeInfos(
328         std::vector<std::shared_ptr<AudioRendererChangeInfo>> &audioRendererChangeInfos);
329 
330     int32_t GetCurrentCapturerChangeInfos(
331         std::vector<std::shared_ptr<AudioCapturerChangeInfo>> &audioCapturerChangeInfos);
332 
333     int32_t UpdateStreamState(const int32_t clientUid, StreamSetState streamSetState,
334                                     StreamUsage streamUsage);
335 
336     int32_t GetVolumeGroupInfos(std::string networkId, std::vector<sptr<VolumeGroupInfo>> &infos);
337 
338     int32_t GetNetworkIdByGroupId(int32_t groupId, std::string &networkId);
339 
340     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetPreferredOutputDeviceDescriptors(
341         AudioRendererInfo &rendererInfo, bool forceNoBTPermission = false);
342 
343     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetPreferredInputDeviceDescriptors(
344         AudioCapturerInfo &captureInfo);
345 
346     int32_t SetPreferredOutputDeviceChangeCallback(const AudioRendererInfo &rendererInfo,
347         const std::shared_ptr<AudioPreferredOutputDeviceChangeCallback> &callback);
348 
349     int32_t SetPreferredInputDeviceChangeCallback(const AudioCapturerInfo &capturerInfo,
350         const std::shared_ptr<AudioPreferredInputDeviceChangeCallback> &callback);
351 
352     int32_t UnsetPreferredOutputDeviceChangeCallback(
353         const std::shared_ptr<AudioPreferredOutputDeviceChangeCallback> &callback = nullptr);
354 
355     int32_t UnsetPreferredInputDeviceChangeCallback(
356         const std::shared_ptr<AudioPreferredInputDeviceChangeCallback> &callback = nullptr);
357 
358     int32_t GetAudioFocusInfoList(std::list<std::pair<AudioInterrupt, AudioFocuState>> &focusInfoList,
359         const int32_t zoneID = 0);
360 
361     int32_t RegisterFocusInfoChangeCallback(const int32_t clientId,
362         const std::shared_ptr<AudioFocusInfoChangeCallback> &callback);
363 
364     int32_t UnregisterFocusInfoChangeCallback(const int32_t clientId);
365 
366     static void AudioPolicyServerDied(pid_t pid, pid_t uid);
367 
368     int32_t SetSystemSoundUri(const std::string &key, const std::string &uri);
369 
370     std::string GetSystemSoundUri(const std::string &key);
371 
372     float GetMinStreamVolume(void);
373 
374     float GetMaxStreamVolume(void);
375     int32_t RegisterAudioPolicyServerDiedCb(const int32_t clientPid,
376         const std::shared_ptr<AudioRendererPolicyServiceDiedCallback> &callback);
377     int32_t RegisterAudioPolicyServerDiedCb(const int32_t clientPid,
378         const std::shared_ptr<AudioCapturerPolicyServiceDiedCallback> &callback);
379     int32_t UnregisterAudioPolicyServerDiedCb(const int32_t clientPid);
380 
381     int32_t RegisterAudioStreamPolicyServerDiedCb(
382         const std::shared_ptr<AudioStreamPolicyServiceDiedCallback> &callback);
383     int32_t UnregisterAudioStreamPolicyServerDiedCb(
384         const std::shared_ptr<AudioStreamPolicyServiceDiedCallback> &callback);
385 
386     bool IsVolumeUnadjustable();
387 
388     int32_t AdjustVolumeByStep(VolumeAdjustType adjustType);
389 
390     int32_t AdjustSystemVolumeByStep(AudioVolumeType volumeType, VolumeAdjustType adjustType);
391 
392     float GetSystemVolumeInDb(AudioVolumeType volumeType, int32_t volumeLevel, DeviceType deviceType);
393 
394     int32_t GetMaxRendererInstances();
395 
396     int32_t QueryEffectSceneMode(SupportedEffectConfig &supportedEffectConfig);
397 
398     int32_t GetHardwareOutputSamplingRate(const std::shared_ptr<AudioDeviceDescriptor> &desc);
399 
400     void RecoverAudioPolicyCallbackClient();
401 
402     std::vector<sptr<MicrophoneDescriptor>> GetAudioCapturerMicrophoneDescriptors(int32_t sessionID);
403 
404     std::vector<sptr<MicrophoneDescriptor>> GetAvailableMicrophones();
405 
406     int32_t SetDeviceAbsVolumeSupported(const std::string &macAddress, const bool support);
407 
408     bool IsAbsVolumeScene();
409 
410     int32_t SetA2dpDeviceVolume(const std::string &macAddress, const int32_t volume, const bool updateUi);
411 
412     int32_t SetNearlinkDeviceVolume(const std::string &macAddress, AudioVolumeType volumeType,
413         const int32_t volume, const bool updateUi);
414 
415     std::vector<std::shared_ptr<AudioDeviceDescriptor>> GetAvailableDevices(AudioDeviceUsage usage);
416 
417     int32_t SetAvailableDeviceChangeCallback(const int32_t clientId, const AudioDeviceUsage usage,
418         const std::shared_ptr<AudioManagerAvailableDeviceChangeCallback>& callback);
419 
420     int32_t UnsetAvailableDeviceChangeCallback(const int32_t clientId, AudioDeviceUsage usage);
421 
422     bool IsSpatializationEnabled();
423 
424     bool IsSpatializationEnabled(const std::string address);
425 
426     bool IsSpatializationEnabledForCurrentDevice();
427 
428     int32_t SetSpatializationEnabled(const bool enable);
429 
430     int32_t SetSpatializationEnabled(
431         const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice, const bool enable);
432 
433     bool IsHeadTrackingEnabled();
434 
435     bool IsHeadTrackingEnabled(const std::string address);
436 
437     int32_t SetHeadTrackingEnabled(const bool enable);
438 
439     int32_t SetHeadTrackingEnabled(
440         const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice, const bool enable);
441 
442     int32_t RegisterSpatializationEnabledEventListener(
443         const std::shared_ptr<AudioSpatializationEnabledChangeCallback> &callback);
444 
445     int32_t RegisterSpatializationEnabledForCurrentDeviceEventListener(
446         const std::shared_ptr<AudioSpatializationEnabledChangeForCurrentDeviceCallback> &callback);
447 
448     int32_t RegisterHeadTrackingEnabledEventListener(
449         const std::shared_ptr<AudioHeadTrackingEnabledChangeCallback> &callback);
450 
451     int32_t RegisterNnStateEventListener(const std::shared_ptr<AudioNnStateChangeCallback> &callback);
452 
453     int32_t UnregisterSpatializationEnabledEventListener();
454 
455     int32_t UnregisterSpatializationEnabledForCurrentDeviceEventListener();
456 
457     int32_t UnregisterHeadTrackingEnabledEventListener();
458 
459     int32_t UnregisterNnStateEventListener();
460 
461     AudioSpatializationState GetSpatializationState(const StreamUsage streamUsage);
462 
463     bool IsSpatializationSupported();
464 
465     bool IsSpatializationSupportedForDevice(const std::string address);
466 
467     bool IsHeadTrackingSupported();
468 
469     bool IsHeadTrackingSupportedForDevice(const std::string address);
470 
471     int32_t UpdateSpatialDeviceState(const AudioSpatialDeviceState audioSpatialDeviceState);
472 
473     int32_t RegisterSpatializationStateEventListener(const uint32_t sessionID, const StreamUsage streamUsage,
474         const std::shared_ptr<AudioSpatializationStateChangeCallback> &callback);
475 
476     int32_t ConfigDistributedRoutingRole(std::shared_ptr<AudioDeviceDescriptor> descriptor, CastType type);
477 
478     int32_t SetDistributedRoutingRoleCallback(const std::shared_ptr<AudioDistributedRoutingRoleCallback> &callback);
479 
480     int32_t UnsetDistributedRoutingRoleCallback();
481 
482     int32_t UnregisterSpatializationStateEventListener(const uint32_t sessionID);
483 
484     int32_t CreateAudioInterruptZone(const std::set<int32_t> &pids, const int32_t zoneID);
485 
486     int32_t AddAudioInterruptZonePids(const std::set<int32_t> &pids, const int32_t zoneID);
487 
488     int32_t RemoveAudioInterruptZonePids(const std::set<int32_t> &pids, const int32_t zoneID);
489 
490     int32_t ReleaseAudioInterruptZone(const int32_t zoneID);
491 
492     int32_t RegisterAudioZoneClient(const sptr<IRemoteObject>& object);
493 
494     int32_t CreateAudioZone(const std::string &name, const AudioZoneContext &context);
495 
496     void ReleaseAudioZone(int32_t zoneId);
497 
498     const std::vector<std::shared_ptr<AudioZoneDescriptor>> GetAllAudioZone();
499 
500     const std::shared_ptr<AudioZoneDescriptor> GetAudioZone(int32_t zoneId);
501 
502     int32_t GetAudioZoneByName(std::string name);
503 
504     int32_t BindDeviceToAudioZone(int32_t zoneId,
505         std::vector<std::shared_ptr<AudioDeviceDescriptor>> devices);
506 
507     int32_t UnBindDeviceToAudioZone(int32_t zoneId,
508         std::vector<std::shared_ptr<AudioDeviceDescriptor>> devices);
509 
510     int32_t EnableAudioZoneReport(bool enable);
511 
512     int32_t EnableAudioZoneChangeReport(int32_t zoneId, bool enable);
513 
514     int32_t AddUidToAudioZone(int32_t zoneId, int32_t uid);
515 
516     int32_t RemoveUidFromAudioZone(int32_t zoneId, int32_t uid);
517 
518     int32_t EnableSystemVolumeProxy(int32_t zoneId, bool enable);
519 
520     int32_t AddStreamToAudioZone(int32_t zoneId, AudioZoneStream stream);
521 
522     int32_t AddStreamsToAudioZone(int32_t zoneId, std::vector<AudioZoneStream> streams);
523 
524     int32_t RemoveStreamFromAudioZone(int32_t zoneId, AudioZoneStream stream);
525 
526     int32_t RemoveStreamsFromAudioZone(int32_t zoneId, std::vector<AudioZoneStream> streams);
527 
528     void SetZoneDeviceVisible(bool visible);
529 
530     std::list<std::pair<AudioInterrupt, AudioFocuState>> GetAudioInterruptForZone(int32_t zoneId);
531 
532     std::list<std::pair<AudioInterrupt, AudioFocuState>> GetAudioInterruptForZone(
533         int32_t zoneId, const std::string &deviceTag);
534 
535     int32_t EnableAudioZoneInterruptReport(int32_t zoneId, const std::string &deviceTag, bool enable);
536 
537     int32_t InjectInterruptToAudioZone(int32_t zoneId,
538         const std::list<std::pair<AudioInterrupt, AudioFocuState>> &interrupts);
539 
540     int32_t InjectInterruptToAudioZone(int32_t zoneId, const std::string &deviceTag,
541         const std::list<std::pair<AudioInterrupt, AudioFocuState>> &interrupts);
542 
543     int32_t SetCallDeviceActive(InternalDeviceType deviceType, bool active, std::string address,
544         const int32_t uid = INVALID_UID);
545 
546     std::shared_ptr<AudioDeviceDescriptor> GetActiveBluetoothDevice();
547 
548     ConverterConfig GetConverterConfig();
549 
550     void FetchOutputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo,
551         const AudioStreamDeviceChangeReasonExt reason);
552 
553     void FetchInputDeviceForTrack(AudioStreamChangeInfo &streamChangeInfo);
554 
555     bool IsHighResolutionExist();
556 
557     int32_t SetHighResolutionExist(bool highResExist);
558 
559     AudioSpatializationSceneType GetSpatializationSceneType();
560 
561     int32_t SetSpatializationSceneType(const AudioSpatializationSceneType spatializationSceneType);
562 
563     float GetMaxAmplitude(const int32_t deviceId);
564 
565     int32_t DisableSafeMediaVolume();
566 
567     bool IsHeadTrackingDataRequested(const std::string &macAddress);
568 
569     int32_t RegisterHeadTrackingDataRequestedEventListener(const std::string &macAddress,
570         const std::shared_ptr<HeadTrackingDataRequestedChangeCallback> &callback);
571 
572     int32_t UnregisterHeadTrackingDataRequestedEventListener(const std::string &macAddress);
573 
574     int32_t SetAudioDeviceRefinerCallback(const std::shared_ptr<AudioDeviceRefiner> &callback);
575 
576     int32_t UnsetAudioDeviceRefinerCallback();
577 
578     int32_t SetAudioClientInfoMgrCallback(const std::shared_ptr<AudioClientInfoMgrCallback> &callback);
579 
580     int32_t SetAudioVKBInfoMgrCallback(const std::shared_ptr<AudioVKBInfoMgrCallback> &callback);
581     int32_t CheckVKBInfo(const std::string &bundleName, bool &isValid);
582 
583     int32_t TriggerFetchDevice(AudioStreamDeviceChangeReasonExt reason);
584 
585     int32_t SetPreferredDevice(const PreferredType preferredType, const std::shared_ptr<AudioDeviceDescriptor> &desc,
586         const int32_t uid = INVALID_UID);
587 
588     int32_t SetAudioDeviceAnahsCallback(const std::shared_ptr<AudioDeviceAnahs> &callback);
589 
590     int32_t UnsetAudioDeviceAnahsCallback();
591 
592     int32_t MoveToNewPipe(const uint32_t sessionId, const AudioPipeType pipeType);
593 
594     void ResetClientTrackerStubMap();
595 
596     void RemoveClientTrackerStub(int32_t sessionId);
597 
598     void CheckAndRemoveClientTrackerStub(const AudioMode &mode, const AudioStreamChangeInfo &streamChangeInfo);
599 
600     int32_t InjectInterruption(const std::string networkId, InterruptEvent &event);
601 
602     int32_t SetMicrophoneBlockedCallback(const int32_t clientId,
603         const std::shared_ptr<AudioManagerMicrophoneBlockedCallback> &callback);
604 
605     int32_t UnsetMicrophoneBlockedCallback(const int32_t clientId,
606         const std::shared_ptr<AudioManagerMicrophoneBlockedCallback> &callback);
607 
608     int32_t SetDeviceVolumeBehavior(const std::string &networkId, DeviceType deviceType, VolumeBehavior volumeBehavior);
609 
610     int32_t SetQueryDeviceVolumeBehaviorCallback(
611         const std::shared_ptr<AudioQueryDeviceVolumeBehaviorCallback> &callback);
612 
613     int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray);
614     int32_t SetAudioEffectProperty(const AudioEffectPropertyArrayV3 &propertyArray);
615     int32_t GetAudioEffectProperty(AudioEffectPropertyArrayV3 &propertyArray);
616 
617     int32_t GetSupportedAudioEffectProperty(AudioEffectPropertyArray &propertyArray);
618     int32_t GetSupportedAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray);
619     int32_t SetAudioEffectProperty(const AudioEffectPropertyArray &propertyArray);
620     int32_t GetAudioEffectProperty(AudioEffectPropertyArray &propertyArray);
621     int32_t SetAudioEnhanceProperty(const AudioEnhancePropertyArray &propertyArray);
622     int32_t GetAudioEnhanceProperty(AudioEnhancePropertyArray &propertyArray);
623     bool IsAcousticEchoCancelerSupported(SourceType sourceType);
624     bool IsAudioLoopbackSupported(AudioLoopbackMode mode);
625     bool SetKaraokeParameters(const std::string &parameters);
626     int32_t SetAudioRouteCallback(uint32_t sessionId, std::shared_ptr<AudioRouteCallback> callback, uint32_t clientUid);
627     int32_t UnsetAudioRouteCallback(uint32_t sessionId);
628 
629     int32_t SetAudioSceneChangeCallback(const int32_t clientId,
630         const std::shared_ptr<AudioManagerAudioSceneChangedCallback> &callback);
631 
632     int32_t UnsetAudioSceneChangeCallback(
633         const std::shared_ptr<AudioManagerAudioSceneChangedCallback> &callback);
634 
635     int32_t LoadSplitModule(const std::string &splitArgs, const std::string &networkId);
636 
637     bool IsAllowedPlayback(const int32_t &uid, const int32_t &pid);
638 
639     int32_t SetVoiceRingtoneMute(bool isMute);
640 
641     int32_t NotifySessionStateChange(const int32_t uid, const int32_t pid, const bool hasSession);
642 
643     int32_t NotifyFreezeStateChange(const std::set<int32_t> &pidList, const bool isFreeze);
644 
645     int32_t ResetAllProxy();
646 
647     int32_t NotifyProcessBackgroundState(const int32_t uid, const int32_t pid);
648 
649     static void RegisterServerDiedCallBack(AudioServerDiedCallBack func);
650 
651     int32_t SetVirtualCall(const bool isVirtual);
652 
653     int32_t SetInputDevice(const DeviceType deviceType, const uint32_t sessionId,
654         const SourceType sourceType, bool isRunning);
655 
656     int32_t SetDeviceConnectionStatus(const std::shared_ptr<AudioDeviceDescriptor> &desc, const bool isConnected);
657 
658     int32_t SetQueryAllowedPlaybackCallback(const std::shared_ptr<AudioQueryAllowedPlaybackCallback> &callback);
659 
660     int32_t SetBackgroundMuteCallback(const std::shared_ptr<AudioBackgroundMuteCallback> &callback);
661 
662     int32_t SetAudioFormatUnsupportedErrorCallback(
663         const std::shared_ptr<AudioFormatUnsupportedErrorCallback> &callback);
664 
665     int32_t UnsetAudioFormatUnsupportedErrorCallback();
666 
667     DirectPlaybackMode GetDirectPlaybackSupport(const AudioStreamInfo &streamInfo, const StreamUsage &streamUsage);
668 
669     int32_t ForceStopAudioStream(StopAudioType audioType);
670     bool IsCapturerFocusAvailable(const AudioCapturerInfo &capturerInfo);
671     int32_t GetMaxVolumeLevelByUsage(StreamUsage streamUsage);
672     int32_t GetMinVolumeLevelByUsage(StreamUsage streamUsage);
673     int32_t GetVolumeLevelByUsage(StreamUsage streamUsage);
674     bool GetStreamMuteByUsage(StreamUsage streamUsage);
675     float GetVolumeInDbByStream(StreamUsage streamUsage, int32_t volumeLevel, DeviceType deviceType);
676     std::vector<AudioVolumeType> GetSupportedAudioVolumeTypes();
677     AudioVolumeType GetAudioVolumeTypeByStreamUsage(StreamUsage streamUsage);
678     std::vector<StreamUsage> GetStreamUsagesByVolumeType(AudioVolumeType audioVolumeType);
679     int32_t SetStreamVolumeChangeCallback(const int32_t clientPid, const std::set<StreamUsage> &streamUsages,
680         const std::shared_ptr<StreamVolumeChangeCallback> &callback);
681     int32_t UnsetStreamVolumeChangeCallback(const std::shared_ptr<StreamVolumeChangeCallback> &callback);
682     int32_t SetCallbackStreamUsageInfo(const std::set<StreamUsage> &streamUsages);
683     int32_t UpdateDeviceInfo(const std::shared_ptr<AudioDeviceDescriptor> &deviceDesc,
684         const DeviceInfoUpdateCommand command);
685     int32_t SetSleAudioOperationCallback(const std::shared_ptr<SleAudioOperationCallback> &callback);
686     bool IsCollaborativePlaybackSupported();
687     int32_t SetCollaborativePlaybackEnabledForDevice(
688         const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice, bool enabled);
689     bool IsCollaborativePlaybackEnabledForDevice(
690         const std::shared_ptr<AudioDeviceDescriptor> &selectedAudioDevice);
691     int32_t ForceVolumeKeyControlType(AudioVolumeType volumeType, int32_t duration);
692 
693     int32_t SetVolumeDegreeCallback(const int32_t clientPid,
694         const std::shared_ptr<VolumeKeyEventCallback> &callback);
695     int32_t UnsetVolumeDegreeCallback(const std::shared_ptr<VolumeKeyEventCallback> &callback);
696     int32_t SetSystemVolumeDegree(AudioVolumeType volumeType, int32_t volumeDegree,
697         int32_t volumeFlag, int32_t uid);
698     int32_t GetSystemVolumeDegree(AudioVolumeType volumeType, int32_t uid);
699     int32_t GetMinVolumeDegree(AudioVolumeType volumeType);
700 
701 private:
AudioPolicyManager()702     AudioPolicyManager() {}
~AudioPolicyManager()703     ~AudioPolicyManager() {}
704 
705     int32_t RegisterPolicyCallbackClientFunc(const sptr<IAudioPolicy> &gsp);
706     int32_t SetClientCallbacksEnable(const CallbackChange &callbackchange, const bool &enable, bool block = true);
707     int32_t SetCallbackStreamInfo(const CallbackChange &callbackChange);
708     int32_t SetCallbackRendererInfo(const AudioRendererInfo &rendererInfo);
709     int32_t SetCallbackCapturerInfo(const AudioCapturerInfo &capturerInfo);
710 
711     std::mutex listenerStubMutex_;
712     std::mutex registerCallbackMutex_;
713     std::mutex stateChangelistenerStubMutex_;
714     std::mutex clientTrackerStubMutex_;
715     sptr<AudioPolicyClientStubImpl> audioPolicyClientStubCB_;
716     std::atomic<bool> isAudioPolicyClientRegisted_ = false;
717 
718     static std::unordered_map<int32_t, std::weak_ptr<AudioRendererPolicyServiceDiedCallback>> rendererCBMap_;
719     static std::weak_ptr<AudioCapturerPolicyServiceDiedCallback> capturerCB_;
720     static std::vector<std::weak_ptr<AudioStreamPolicyServiceDiedCallback>> audioStreamCBMap_;
721     static std::unordered_map<int32_t, sptr<AudioClientTrackerCallbackService>> clientTrackerStubMap_;
722 
723     bool isAudioRendererEventListenerRegistered = false;
724     bool isAudioCapturerEventListenerRegistered = false;
725 
726     std::array<CallbackChangeInfo, CALLBACK_MAX> callbackChangeInfos_ = {};
727     std::vector<AudioRendererInfo> rendererInfos_;
728     std::vector<AudioCapturerInfo> capturerInfos_;
729 
730     std::mutex handleAvailableDeviceChangeCbsMapMutex_;
731     std::map<std::pair<int32_t, AudioDeviceUsage>,
732         sptr<IRemoteObject>> availableDeviceChangeCbsMap_;
733 
734     static std::vector<AudioServerDiedCallBack> serverDiedCbks_;
735     static std::mutex serverDiedCbkMutex_;
736 
737     static std::weak_ptr<AudioSessionManagerPolicyServiceDiedCallback> audioSessionManagerCb_;
738     static std::mutex serverDiedSessionManagerCbkMutex_;
739 };
740 } // namespce AudioStandard
741 } // namespace OHOS
742 
743 #endif // ST_AUDIO_POLICY_MANAGER_H
744