• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 OHOS_AVSESSION_SERVICE_H
17 #define OHOS_AVSESSION_SERVICE_H
18 
19 #include <atomic>
20 #include <mutex>
21 #include <map>
22 
23 #include "iremote_stub.h"
24 #include "system_ability.h"
25 #include "audio_info.h"
26 #include "avsession_service_stub.h"
27 #include "avsession_item.h"
28 #include "avcontroller_item.h"
29 #include "session_container.h"
30 #include "iclient_death.h"
31 #include "isession_listener.h"
32 #include "focus_session_strategy.h"
33 #include "background_audio_controller.h"
34 #include "ability_manager_adapter.h"
35 #include "device_manager.h"
36 #include "dm_device_info.h"
37 #include "audio_adapter.h"
38 #include "remote_session_command_process.h"
39 #include "i_avsession_service_listener.h"
40 #include "avqueue_info.h"
41 #include "migrate/migrate_avsession_server.h"
42 #include "migrate/migrate_avsession_proxy.h"
43 #include "account_manager_adapter.h"
44 #include "app_manager_adapter.h"
45 #include "avsession_dynamic_loader.h"
46 #include "avsession_errors.h"
47 #include "avsession_log.h"
48 #include "avsession_info.h"
49 #include "file_ex.h"
50 #include "iservice_registry.h"
51 #include "key_event_adapter.h"
52 #include "nlohmann/json.hpp"
53 #include "session_stack.h"
54 #include "avsession_trace.h"
55 #include "avsession_dumper.h"
56 #include "command_send_limit.h"
57 #include "avsession_sysevent.h"
58 #include "json_utils.h"
59 #include "avsession_utils.h"
60 #include "avcontrol_command.h"
61 #include "avsession_event_handler.h"
62 #include "bundle_status_adapter.h"
63 #include "if_system_ability_manager.h"
64 #include "avsession_radar.h"
65 #include "system_ability_load_callback_stub.h"
66 
67 #include "common_event_manager.h"
68 #include "common_event_subscribe_info.h"
69 #include "common_event_subscriber.h"
70 #include "common_event_support.h"
71 #include "matching_skills.h"
72 
73 #include "avsession_users_manager.h"
74 
75 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
76 #include "av_router.h"
77 #include "collaboration_manager.h"
78 #endif
79 
80 namespace OHOS::AVSession {
81 class AVSessionDumper;
82 
83 class ClientDeathRecipient : public IRemoteObject::DeathRecipient {
84 public:
85     explicit ClientDeathRecipient(const std::function<void()>& callback);
86 
87     void OnRemoteDied(const wptr<IRemoteObject>& object) override;
88 
89 private:
90     std::function<void()> callback_;
91 };
92 
93 class AVSessionInitDMCallback : public OHOS::DistributedHardware::DmInitCallback {
94 public:
95     AVSessionInitDMCallback() = default;
96     ~AVSessionInitDMCallback() override = default;
OnRemoteDied()97     void OnRemoteDied() override {};
98 };
99 
100 class AVSessionSystemAbilityLoadCallback : public SystemAbilityLoadCallbackStub {
101 public:
102     explicit AVSessionSystemAbilityLoadCallback(AVSessionService *ptr);
103     virtual ~AVSessionSystemAbilityLoadCallback();
104 
105     void OnLoadSACompleteForRemote(const std::string& deviceId,
106         int32_t systemAbilityId, const sptr<IRemoteObject>& remoteObject);
107 
108 private:
109     AVSessionService *servicePtr_ = nullptr;
110 };
111 
112 class AVSessionDeviceStateCallback : public OHOS::DistributedHardware::DeviceStateCallback {
113 public:
114     explicit AVSessionDeviceStateCallback(AVSessionService *ptr);
115     virtual ~AVSessionDeviceStateCallback();
116 
117     void OnDeviceOnline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
118     void OnDeviceReady(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
119     void OnDeviceOffline(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
120     void OnDeviceChanged(const OHOS::DistributedHardware::DmDeviceInfo &deviceInfo) override;
121 
122 private:
123     AVSessionService *servicePtr_ = nullptr;
124 };
125 
126 class EventSubscriber : public EventFwk::CommonEventSubscriber {
127 public:
128     EventSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo, AVSessionService *ptr);
129     virtual ~EventSubscriber() = default;
130     void OnReceiveEvent(const EventFwk::CommonEventData &eventData) override;
131 private:
132     AVSessionService *servicePtr_ = nullptr;
133 };
134 
135 class AVSessionService : public SystemAbility, public AVSessionServiceStub, public IAVSessionServiceListener {
136     DECLARE_SYSTEM_ABILITY(AVSessionService);
137 
138 public:
139     DISALLOW_COPY_AND_MOVE(AVSessionService);
140 
141     explicit AVSessionService(int32_t systemAbilityId, bool runOnCreate = true);
142 
143     ~AVSessionService() override;
144 
145     void OnDump() override;
146 
147     void OnStart() override;
148 
149     void OnStartProcess();
150 
151     void OnStop() override;
152 
153     int32_t OnIdle(const SystemAbilityOnDemandReason& idleReason) override;
154 
155     void OnActive(const SystemAbilityOnDemandReason& activeReason) override;
156 
157     void PullMigrateStub();
158 
159     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
160 
161     void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
162 
163     sptr<IRemoteObject> CreateSessionInner(const std::string& tag, int32_t type,
164                                            const AppExecFwk::ElementName& elementName) override;
165 
166     int32_t CreateSessionInner(const std::string& tag, int32_t type, const AppExecFwk::ElementName& elementName,
167                                sptr<IRemoteObject>& object) override;
168 
169     int32_t GetAllSessionDescriptors(std::vector<AVSessionDescriptor>& descriptors) override;
170 
171     int32_t GetSessionDescriptorsBySessionId(const std::string& sessionId, AVSessionDescriptor& descriptor) override;
172 
173     int32_t GetHistoricalSessionDescriptors(int32_t maxSize, std::vector<AVSessionDescriptor>& descriptors) override;
174 
175     int32_t GetHistoricalAVQueueInfos(int32_t maxSize, int32_t maxAppSize,
176                                       std::vector<AVQueueInfo>& avQueueInfos) override;
177 
178     int32_t StartAVPlayback(const std::string& bundleName, const std::string& assetId) override;
179 
180     int32_t StartAVPlayback(const std::string& bundleName, const std::string& assetId, const std::string& deviceId);
181 
182     int32_t HandleKeyEvent(const MMI::KeyEvent& keyEvent);
183 
184     int32_t CreateControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override;
185 
186 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
187     int32_t GetAVCastControllerInner(const std::string& sessionId, sptr<IRemoteObject>& object) override;
188 #endif
189 
190     int32_t RegisterSessionListener(const sptr<ISessionListener>& listener) override;
191 
192     int32_t RegisterSessionListenerForAllUsers(const sptr<ISessionListener>& listener) override;
193 
194     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent) override;
195 
196     int32_t SendSystemAVKeyEvent(const MMI::KeyEvent& keyEvent, const AAFwk::Want &wantParam) override;
197 
198     int32_t SendSystemControlCommand(const AVControlCommand& command) override;
199 
200     int32_t RegisterClientDeathObserver(const sptr<IClientDeath>& observer) override;
201 
202     void OnClientDied(pid_t pid);
203 
204     void HandleSessionRelease(std::string sessionId, bool continuePlay = false);
205 
206     void HandleCallStartEvent();
207 
208     void HandleControllerRelease(AVControllerItem& controller);
209 
210     std::int32_t Dump(std::int32_t fd, const std::vector<std::u16string>& args) override;
211 
212     int32_t CastAudio(const SessionToken& token,
213                       const std::vector<AudioStandard::AudioDeviceDescriptor>& sinkAudioDescriptors) override;
214 
215     int32_t CastAudioForAll(const std::vector<AudioStandard::AudioDeviceDescriptor>& sinkAudioDescriptors) override;
216 
NotifyAudioSessionCheckTrigger(const int32_t uid)217     void NotifyAudioSessionCheckTrigger(const int32_t uid)
218     {
219         return NotifyAudioSessionCheck(uid);
220     }
221 
222     void NotifyBackgroundReportCheck(const int32_t uid, const int32_t pid,
223         AudioStandard::StreamUsage streamUsage, AudioStandard::RendererState rendererState);
224 
225     void SuperLauncher(std::string deviceId, std::string serviceName,
226         std::string extraInfo, const std::string& state);
227 
228     void ReleaseSuperLauncher(std::string serviceName);
229 
230     void ConnectSuperLauncher(std::string deviceId, std::string serviceName);
231 
232     void SucceedSuperLauncher(std::string deviceId, std::string extraInfo);
233 
234 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
235     void ReleaseCastSession() override;
236 
237     void CreateSessionByCast(const int64_t castHandle) override;
238 
239     void NotifyDeviceAvailable(const OutputDeviceInfo& castOutputDeviceInfo) override;
240 
241     void NotifyDeviceLogEvent(const DeviceLogEventCode eventId, const int64_t param) override;
242 
243     void NotifyDeviceOffline(const std::string& deviceId) override;
244 
245     void NotifyMirrorToStreamCast();
246 
247     bool IsMirrorToStreamCastAllowed(sptr<AVSessionItem>& session);
248 
249     __attribute__((no_sanitize("cfi"))) int32_t MirrorToStreamCast(sptr<AVSessionItem>& session);
250 
251     void SetIsSupportMirrorToStream(bool isSupportMirrorToStream) override;
252 
253     void SplitExtraInfo(std::string info);
254 
255     int32_t StartCast(const SessionToken& sessionToken, const OutputDeviceInfo& outputDeviceInfo) override;
256 
257     int32_t StopCast(const SessionToken& sessionToken) override;
258 
259     int32_t checkEnableCast(bool enable) override;
260 
261     void setInCast(bool isInCast) override;
262 #endif
263 
264     int32_t Close(void) override;
265 
266     void AddAvQueueInfoToFile(AVSessionItem& session);
267 
268     std::string GetAVQueueDir(int32_t userId = 0);
269 
270     std::string GetAVSortDir(int32_t userId = 0);
271 
272     void HandleUserEvent(const std::string &type, const int &userId);
273 
274     void HandleRemoveMediaCardEvent();
275 
276     void HandleMediaCardStateChangeEvent(std::string isAppear);
277 
278     void RegisterBundleDeleteEventForHistory(int32_t userId = 0);
279 
280     void NotifyMigrateStop(const std::string &deviceId);
281 
282     void InitCastEngineService();
283 
284     bool ProcessTargetMigrate(bool isOnline, const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
285 
286     int32_t GetDistributedSessionControllersInner(const DistributedSessionType& sessionType,
287         std::vector<sptr<IRemoteObject>>& sessionControllers) override;
288 
289     void NotifyRemoteDistributedSessionControllersChanged(
290         const std::vector<sptr<IRemoteObject>>& sessionControllers);
291 
292     void NotifyRemoteBundleChange(const std::string bundleName);
293 
294 private:
295 
296     void NotifyProcessStatus(bool isStart);
297 
298     static SessionContainer& GetContainer();
299     static AVSessionUsersManager& GetUsersManager();
300 
301     std::string AllocSessionId();
302 
303     bool AbilityHasSession(pid_t pid);
304 
305     sptr<AVControllerItem> GetPresentController(pid_t pid, const std::string& sessionId);
306 
307     void NotifySessionCreate(const AVSessionDescriptor& descriptor);
308     void NotifySessionRelease(const AVSessionDescriptor& descriptor);
309     void NotifyTopSessionChanged(const AVSessionDescriptor& descriptor);
310     void NotifyAudioSessionCheck(const int32_t uid);
311     void NotifySystemUI(const AVSessionDescriptor* historyDescriptor, bool isActiveSession, bool addCapsule,
312                         bool isCapsuleUpdate);
313     void NotifyDeviceChange();
314     void PublishEvent(int32_t mediaPlayState);
315 
316     void AddClientDeathObserver(pid_t pid, const sptr<IClientDeath>& observer,
317         const sptr<ClientDeathRecipient> recipient);
318     void RemoveClientDeathObserver(pid_t pid);
319 
320     void AddSessionListener(pid_t pid, const sptr<ISessionListener>& listener);
321     void AddSessionListenerForAllUsers(pid_t pid, const sptr<ISessionListener>& listener);
322     void RemoveSessionListener(pid_t pid);
323 
324     void AddInnerSessionListener(SessionListener* listener);
325     void RemoveInnerSessionListener(SessionListener* listener);
326 
327     void AddHistoricalRecordListener(HistoricalRecordListener* listener);
328     void RemoveHistoricalRecordListener(HistoricalRecordListener* listener);
329 
330     sptr<AVSessionItem> SelectSessionByUid(const AudioStandard::AudioRendererChangeInfo& info);
331 
332     void OutputDeviceChangeListener(const AudioRendererChangeInfos& infos);
333 
334     std::function<bool(int32_t, int32_t)> GetAllowedPlaybackCallbackFunc();
335 
336     sptr<AVSessionItem> CreateSessionInner(const std::string& tag, int32_t type, bool thirdPartyApp,
337                                            const AppExecFwk::ElementName& elementName);
338 
339     int32_t CreateSessionInner(const std::string& tag, int32_t type, bool thirdPartyApp,
340                                const AppExecFwk::ElementName& elementName, sptr<AVSessionItem>& sessionItem);
341 
342     bool IsParamInvalid(const std::string& tag, int32_t type, const AppExecFwk::ElementName& elementName);
343 
344     void ServiceCallback(sptr<AVSessionItem>& sessionItem);
345 
346     sptr<AVSessionItem> CreateNewSession(const std::string& tag, int32_t type, bool thirdPartyApp,
347                                          const AppExecFwk::ElementName& elementName);
348 
349     sptr<AVControllerItem> CreateNewControllerForSession(pid_t pid, sptr<AVSessionItem>& session);
350 
351     int32_t CancelCastAudioForClientExit(pid_t pid, const sptr<AVSessionItem>& session);
352 
353     void ClearSessionForClientDiedNoLock(pid_t pid, bool continuePlay);
354 
355     void ClearControllerForClientDiedNoLock(pid_t pid);
356 
357     void InitKeyEvent();
358 
359     void InitAudio();
360 
361     void InitAMS();
362 
363     void InitDM();
364 
365     void InitBMS();
366 
367     void InitRadarBMS();
368 
369     void InitAccountMgr();
370 
371     void InitCommonEventService();
372 
373     void InitCollaboration();
374 
375     bool SelectFocusSession(const FocusSessionStrategy::FocusSessionChangeInfo& info);
376 
377     void RefreshFocusSessionSort(sptr<AVSessionItem> &session);
378 
379     void UpdateTopSession(const sptr<AVSessionItem>& newTopSession, int32_t userId = 0);
380 
381     void HandleFocusSession(const FocusSessionStrategy::FocusSessionChangeInfo& info, bool isPlaying);
382 
383     void HandleDeviceChange(const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>> &desc);
384 
385     __attribute__((no_sanitize("cfi"))) std::shared_ptr<RemoteSessionCommandProcess> GetService(
386         const std::string& deviceId);
387 
388     int32_t CastAudioProcess(const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors,
389                              const std::string& sourceSessionInfo,
390                              sptr<AVSessionItem>& session);
391 
392     int32_t CastAudioInner(const std::vector<AudioStandard::AudioDeviceDescriptor>& sinkAudioDescriptors,
393                            const std::string& sourceSessionInfo,
394                            const sptr<AVSessionItem>& session);
395 
396     int32_t CancelCastAudioInner(const std::vector<AudioStandard::AudioDeviceDescriptor>& sinkDevices,
397                                  const std::string& sourceSessionInfo,
398                                  const sptr<AVSessionItem>& session);
399 
400     int32_t RemoteCastAudioInner(const std::string& sourceSessionInfo, std::string& sinkSessionInfo);
401 
402     int32_t RemoteCancelCastAudioInner(const std::string& sessionInfo);
403 
404     int32_t ProcessCastAudioCommand(const RemoteServiceCommand command, const std::string& input,
405                                     std::string& output) override;
406 
407     int32_t CastAudioForNewSession(const sptr<AVSessionItem>& session);
408 
409     bool IsLocalDevice(const std::string& networkId);
410 
411     int32_t GetLocalNetworkId(std::string& networkId);
412 
413     int32_t GetTrustedDeviceName(const std::string& networkId, std::string& deviceName);
414 
415     int32_t GetTrustedDevicesInfo(std::vector<OHOS::DistributedHardware::DmDeviceInfo>& deviceList);
416 
417     int32_t SetBasicInfo(std::string& sessionInfo);
418 
419     void SetDeviceInfo(const std::vector<AudioStandard::AudioDeviceDescriptor>& castAudioDescriptors,
420                            sptr<AVSessionItem>& session);
421 
422     int32_t GetAudioDescriptor(const std::string deviceId,
423                                std::vector<AudioStandard::AudioDeviceDescriptor>& audioDeviceDescriptors);
424 
425     bool GetAudioDescriptorByDeviceId(
426         const std::vector<std::shared_ptr<AudioStandard::AudioDeviceDescriptor>>& descriptors,
427         const std::string& deviceId,
428         AudioStandard::AudioDeviceDescriptor& audioDescriptor);
429 
430     void GetDeviceInfo(const sptr<AVSessionItem>& session,
431                            const std::vector<AudioStandard::AudioDeviceDescriptor>& descriptors,
432                            std::vector<AudioStandard::AudioDeviceDescriptor>& castSinkDescriptors,
433                            std::vector<AudioStandard::AudioDeviceDescriptor>& cancelSinkDescriptors);
434 
435     int32_t SelectOutputDevice(const int32_t uid, const AudioStandard::AudioDeviceDescriptor& descriptor);
436 
437     int32_t StartDefaultAbilityByCall(std::string& sessionId);
438 
439     int32_t StartAbilityByCall(const std::string& sessionIdNeeded, std::string& sessionId);
440 
441     void HandleEventHandlerCallBack();
442 
443     bool IsHistoricalSession(const std::string& sessionId);
444 
445     void DeleteHistoricalRecord(const std::string& bundleName, int32_t userId = 0);
446 
447     void DeleteAVQueueInfoRecord(const std::string& bundleName, int32_t userId = 0);
448 
449     const nlohmann::json& GetSubNode(const nlohmann::json& node, const std::string& name);
450 
451     void SaveSessionInfoInFile(const std::string& sessionId, const std::string& sessionType,
452         const AppExecFwk::ElementName& elementName);
453 
454     bool CheckAndCreateDir(const std::string& filePath);
455 
456     bool CheckUserDirValid(int32_t userId = 0);
457 
458     bool LoadStringFromFileEx(const std::string& filePath, std::string& content);
459 
460     bool SaveStringToFileEx(const std::string& filePath, const std::string& content);
461 
462     bool CheckStringAndCleanFile(const std::string& filePath);
463 
464     void ClearClientResources(pid_t pid, bool continuePlay);
465 
466     bool SaveAvQueueInfo(std::string& oldContent, const std::string &bundleName,
467         const AVMetaData& meta, const int32_t userId);
468 
469     int32_t GetHistoricalSessionDescriptorsFromFile(std::vector<AVSessionDescriptor>& descriptors);
470 
471     void ReportStartCastBegin(std::string func, const OutputDeviceInfo& outputDeviceInfo, int32_t uid);
472 
473     void ReportStartCastEnd(std::string func, const OutputDeviceInfo &outputDeviceInfo, int32_t uid, int ret);
474 
475     void HandleAppStateChange(int uid, int state);
476 
477     void UpdateFrontSession(sptr<AVSessionItem>& sessionItem, bool isAdd);
478 
479     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> CreateWantAgent(
480         const AVSessionDescriptor* histroyDescriptor);
481 
482     std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> CreateNftRemoveWant(int32_t uid);
483 
484     void DoMetadataImgClean(AVMetaData& data);
485 
486     void HandleSystemKeyColdStart(const AVControlCommand &command, const std::string deviceId = "");
487 
488     bool SubscribeCommonEvent();
489 
490     bool UnSubscribeCommonEvent();
491 
492     void ReportSessionInfo(const sptr <AVSessionItem>& session, int res);
493 
494     bool CheckAncoAudio();
495 
496     int32_t ConvertKeyCodeToCommand(int keyCode);
497 
498     void RemoveExpired(std::list<std::chrono::system_clock::time_point> &list,
499         const std::chrono::system_clock::time_point &now, int32_t time = 1);
500 
501     void LowQualityCheck(int32_t uid, int32_t pid, AudioStandard::StreamUsage streamUsage,
502         AudioStandard::RendererState rendererState);
503 
504     void PlayStateCheck(int32_t uid, AudioStandard::StreamUsage streamUsage,
505         AudioStandard::RendererState rState);
506 
507     std::shared_ptr<std::list<sptr<AVSessionItem>>> GetCurSessionListForFront(int32_t userId = 0);
508 
509     std::shared_ptr<std::list<sptr<AVSessionItem>>> GetCurKeyEventSessionList(int32_t userId = 0);
510 
511     void AddCapsuleServiceCallback(sptr<AVSessionItem>& sessionItem);
512 
513     bool VerifyNotification();
514 
515     void HandleChangeTopSession(int32_t infoUid, int32_t userId);
516 
517     bool IsTopSessionPlaying();
518 
519     bool NotifyFlowControl();
520 
521     bool IsCapsuleNeeded();
522 
523     int32_t GetLocalDeviceType();
524 
525     void DoTargetDevListenWithDM();
526 
527     void DoRemoteAVSessionLoad(std::string remoteDeviceId);
528 
529     void DoConnectProcessWithMigrate(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
530 
531     void DoConnectProcessWithMigrateServer(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
532 
533     void DoConnectProcessWithMigrateProxy(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
534 
535     void DoDisconnectProcessWithMigrate(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
536 
537     void DoDisconnectProcessWithMigrateServer(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
538 
539     void DoDisconnectProcessWithMigrateProxy(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
540 
541     void UpdateLocalFrontSession(std::shared_ptr<std::list<sptr<AVSessionItem>>> sessionListForFront);
542 
543     void NotifyLocalFrontSessionChangeForMigrate(std::string localFrontSessionIdUpdate);
544 
545     bool CheckWhetherTargetDevIsNext(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
546 
547     void NotifyHistoricalRecordChange(const std::string& bundleName, int32_t userId);
548 
549     void AddKeyEventServiceCallback(sptr<AVSessionItem>& sessionItem);
550 
551     std::string GetLocalTitle();
552 
553     std::atomic<uint32_t> sessionSeqNum_ {};
554     std::atomic<bool> isMediaCardOpen_ = false;
555     std::atomic<bool> hasRemoveEvent_ = false;
556 
557     sptr<AVSessionItem> topSession_;
558     std::map<pid_t, std::list<sptr<AVControllerItem>>> controllers_;
559     std::map<pid_t, sptr<IClientDeath>> clientDeathObservers_;
560     std::map<pid_t, sptr<ClientDeathRecipient>> clientDeathRecipients_;
561     std::list<SessionListener*> innerSessionListeners_;
562     std::list<HistoricalRecordListener*> historicalRecordListeners_;
563     std::map<std::string, std::shared_ptr<AbilityManagerAdapter>> abilityManager_;
564     FocusSessionStrategy focusSessionStrategy_;
565     BackgroundAudioController backgroundAudioController_;
566     std::map<std::string, std::string> castAudioSessionMap_;
567     bool isAllSessionCast_ {};
568     std::string outputDeviceId_;
569     std::unique_ptr<AVSessionDumper> dumpHelper_ {};
570     friend class AVSessionDumper;
571     std::shared_ptr<MigrateAVSessionServer> migrateAVSession_;
572     std::shared_ptr<EventSubscriber> subscriber_;
573     bool isScreenOn_ = false;
574     bool isScreenLocked_ = true;
575     std::list<std::chrono::system_clock::time_point> flowControlPublishTimestampList_;
576     std::function<bool(int32_t, int32_t)> queryAllowedPlaybackCallbackFunc_;
577 
578     // The following locks are used in the defined order of priority
579     std::recursive_mutex sessionServiceLock_;
580 
581     std::recursive_mutex sessionFrontLock_;
582 
583     std::recursive_mutex sessionListenersLock_;
584 
585     std::recursive_mutex migrateListenersLock_;
586 
587     std::recursive_mutex sessionFileLock_;
588 
589     std::recursive_mutex avQueueFileLock_;
590 
591     std::recursive_mutex abilityManagerLock_;
592 
593     std::recursive_mutex screenStateLock_;
594 
595     std::recursive_mutex clientDeathLock_;
596 
597     std::recursive_mutex notifyLock_;
598 
599     // DMSDP related locks
600     std::recursive_mutex isAllSessionCastLock_;
601 
602     std::recursive_mutex outputDeviceIdLock_;
603 
604     std::recursive_mutex castAudioSessionMapLock_;
605 
606     std::recursive_mutex historicalRecordListenersLock_;
607 
608     std::recursive_mutex keyEventListLock_;
609 
610 #ifdef CASTPLUS_CAST_ENGINE_ENABLE
611     std::pair<std::string, std::string> castserviceNameStatePair_;
612     const std::string deviceStateConnection = "CONNECT_SUCC";
613     const std::string deviceStateDisconnection = "IDLE";
614     const std::string seperator = ",";
615     int appState = -1;
616     std::atomic<bool> isSupportMirrorToStream_ = false;
617     std::string castDeviceId_ = "0";
618     std::string castDeviceName_ = " ";
619     int32_t castDeviceType_ = 0;
620     const int32_t beginAddPos = 3;
621     const int32_t endDecPos = 4;
622     const int32_t typeAddPos = 2;
623     std::recursive_mutex checkEnableCastLock_;
624 #endif
625 
626     static constexpr const char *SORT_FILE_NAME = "sortinfo";
627     static constexpr const char *DEFAULT_SESSION_ID = "default";
628     static constexpr const char *DEFAULT_BUNDLE_NAME = "com.example.himusicdemo";
629     static constexpr const char *DEFAULT_ABILITY_NAME = "MainAbility";
630     static constexpr const int32_t SYSTEMUI_LIVEVIEW_TYPECODE_MDEDIACONTROLLER = 2;
631     static constexpr const char *AVQUEUE_FILE_NAME = "avqueueinfo";
632 
633     const std::string MEDIA_CONTROL_BUNDLENAME = "com.ohos.mediacontroller";
634     const std::string MEDIA_CONTROL_ABILITYNAME = "com.ohos.mediacontroller.avplayer.mainability";
635     const std::string MEDIA_CONTROL_STATE = "usual.event.MEDIA_CONTROL_STATE";
636     const std::string MEDIA_PLAY_STATE = "MediaPlaybackState";
637 
638     int32_t pressCount_ {};
639     int32_t maxHistoryNums_ = 10;
640     bool isFirstPress_ = true;
641     bool isInCast_ = false;
642     bool is2in1_ = false;
643 
644     void *migrateStubFuncHandle_ = nullptr;
645 
646     std::shared_ptr<AVSessionDeviceStateCallback> deviceStateCallback_ = nullptr;
647     sptr<AVSessionSystemAbilityLoadCallback> abilityLoadCallback_ = nullptr;
648     int32_t localDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_PHONE;
649     int32_t targetDeviceType_ = OHOS::DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
650     const std::string serviceName = "av_session";
651     std::string deviceIdForMigrate_ = "";
652     std::string localFrontSessionId_ = "";
653     bool isMigrateTargetFound_ = false;
654     std::map<std::string, std::shared_ptr<MigrateAVSessionServer>> migrateAVSessionServerMap_;
655     std::map<std::string, std::shared_ptr<SoftbusSession>> migrateAVSessionProxyMap_;
656 
657     const int32_t ONE_CLICK = 1;
658     const int32_t DOUBLE_CLICK = 2;
659     const int32_t THREE_CLICK = 3;
660     const int32_t unSetHistoryNum = 3;
661     const int32_t CLICK_TIMEOUT = 500;
662     const int32_t lowQualityTimeout = 1000;
663     const int32_t errorStateTimeout = 3 * 1000;
664     const int32_t defMaxHistoryNum = 10;
665     const int32_t maxFileLength = 32 * 1024 * 1024;
666     const int32_t maxAVQueueInfoLen = 99;
667     const int32_t allocSpace = 2;
668     const int32_t avSessionUid = 6700;
669     const int32_t ancoUid = 1041;
670     const int32_t saType = 1;
671     const int32_t remoteMediaNone = 4;
672     const int32_t remoteMediaAlive = 3;
673     const int32_t mediaPlayStateTrue = 1;
674     const int32_t mediaPlayStateFalse = 0;
675     const uint32_t MAX_NOTIFICATION_NUM = 3;
676     const int32_t NOTIFICATION_CONTROL_TIME = 1000;
677     const int32_t cancelTimeout = 5000;
678     const uint8_t doRemoteLoadRetryTime = 5;
679 };
680 } // namespace OHOS::AVSession
681 #endif // OHOS_AVSESSION_SERVICE_H
682