• 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 OHOS_DISTRIBUTED_SCHED_SERVICE_H
17 #define OHOS_DISTRIBUTED_SCHED_SERVICE_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <set>
22 #include <unordered_map>
23 
24 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
25 #include "form_mgr_interface.h"
26 #endif
27 #include "iremote_object.h"
28 #include "iremote_proxy.h"
29 #include "system_ability.h"
30 
31 #include "app_mgr_interface.h"
32 #include "app_state_observer.h"
33 #include "datashare_manager.h"
34 #include "distributed_sched_stub.h"
35 #include "distributed_sched_continuation.h"
36 #include "dms_callback_task.h"
37 #include "dsched_collaborate_callback_mgr.h"
38 #include "idms_interactive_adapter.h"
39 #ifdef DMSFWK_INTERACTIVE_ADAPTER
40 #include "softbus_adapter/softbus_adapter.h"
41 #endif
42 #include "svc_distributed_connection.h"
43 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
44 #include "mission/distributed_mission_focused_listener.h"
45 #include "mission/distributed_mission_info.h"
46 #include "nocopyable.h"
47 #endif
48 #include "dsched_collab.h"
49 #include "dsched_continue.h"
50 #include "dsched_continue_event.h"
51 #include "single_instance.h"
52 
53 namespace OHOS {
54 namespace DistributedSchedule {
55 class ConnectAbilitySession;
56 
57 enum class ServiceRunningState {
58     STATE_NO_START,
59     STATE_RUNNING
60 };
61 
62 enum class TargetComponent {
63     HARMONY_COMPONENT,
64 };
65 
66 struct ConnectInfo {
67     CallerInfo callerInfo;
68     sptr<IRemoteObject> callbackWrapper;
69     AppExecFwk::ElementName element;
70 };
71 
72 struct ProcessDiedNotifyInfo {
73     std::string remoteDeviceId;
74     CallerInfo callerInfo;
75     TargetComponent targetComponent;
76 };
77 
78 struct CallInfo {
79     int32_t connectToken;
80     std::string remoteDeviceId;
81 };
82 
83 struct ObserverInfo {
84     sptr<AppStateObserver> appStateObserver;
85     std::string srcDeviceId;
86     int32_t connectToken;
87     std::string dstBundleName;
88     std::string dstAbilityName;
89     sptr<IRemoteObject> srcConnect;
90     sptr<IRemoteObject> token;
91 };
92 
93 class DistributedSchedService : public SystemAbility, public DistributedSchedStub {
94     DECLARE_SYSTEM_ABILITY(DistributedSchedService);
95     DECLARE_SINGLE_INSTANCE_BASE(DistributedSchedService);
96 
97 public:
98     ~DistributedSchedService() = default;
99     void OnStart(const SystemAbilityOnDemandReason &startReason) override;
100     void OnStop(const SystemAbilityOnDemandReason &stopReason) override;
101     int32_t OnIdle(const SystemAbilityOnDemandReason& idleReason) override;
102     void OnActive(const SystemAbilityOnDemandReason &activeReason) override;
103 
104     /**
105      * @brief If SA is pulled by root and not networked with other devices, uninstall SA after creating the database
106      *
107      * @param startReason, The reason why SA was pulled up.
108      */
109     void HandleBootStart(const SystemAbilityOnDemandReason &startReason);
110     bool DoStart();
111     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
112     void DeviceOnlineNotify(const std::string& deviceId);
113     void DeviceOfflineNotify(const std::string& deviceId);
114     void DeviceOfflineNotifyAfterDelete(const std::string& networkId);
115     void DurationStart(const std::string srcDeviceId, const std::string dstDeviceId);
116 
117     int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
118         uint32_t accessToken) override;
119     int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
120         const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
121         const AccountInfo& accountInfo) override;
122     int32_t SendResultFromRemote(OHOS::AAFwk::Want& want, int32_t requestCode,
123         const CallerInfo& callerInfo, const AccountInfo& accountInfo, int32_t resultCode) override;
124     int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId,
125         const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams) override;
126     int32_t ProcessContinueLocalMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
127         const std::string& bundleName, const sptr<IRemoteObject>& callback,
128         const OHOS::AAFwk::WantParams& wantParams);
129     int32_t ProcessContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
130         const std::string& bundleName, const sptr<IRemoteObject>& callback,
131         const OHOS::AAFwk::WantParams& wantParams);
132     int32_t ContinueMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
133         const std::string& bundleName, const sptr<IRemoteObject>& callback,
134         const OHOS::AAFwk::WantParams& wantParams) override;
135     int32_t DealDSchedEventResult(const OHOS::AAFwk::Want& want, int32_t status);
136     bool GetIsFreeInstall(int32_t missionId);
137     int32_t StartContinuation(const OHOS::AAFwk::Want& want, int32_t missionId, int32_t callerUid,
138         int32_t status, uint32_t accessToken) override;
139     void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override;
140     int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess, const std::string dstInfo) override;
141     int32_t NotifyDSchedEventResultFromRemote(const std::string type, int32_t dSchedEventResult) override;
142     void NotifyContinuationCallbackResult(int32_t missionId, int32_t resultCode);
143     void NotifyDSchedEventCallbackResult(int32_t resultCode);
144     void NotifyDSchedEventCallbackResult(int32_t resultCode, const EventNotify& event);
145     int32_t NotifyFreeInstallResult(const CallbackTaskItem item, int32_t resultCode);
146     int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
147         int32_t callerUid, int32_t callerPid, uint32_t accessToken) override;
148     int32_t DisconnectRemoteAbility(const sptr<IRemoteObject>& connect, int32_t callerUid,
149         uint32_t accessToken) override;
150     int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo,
151         const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override;
152     int32_t DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
153         int32_t uid, const std::string& sourceDeviceId) override;
154     int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override;
155     int32_t ConnectDExtensionFromRemote(const DExtConnectInfo& connectInfo, DExtConnectResultInfo& resultInfo) override;
156 #ifdef SUPPORT_DISTRIBUTED_MISSION_MANAGER
157     int32_t GetMissionInfos(const std::string& deviceId, int32_t numMissions,
158         std::vector<AAFwk::MissionInfo>& missionInfos) override;
159     int32_t NotifyMissionsChangedFromRemote(const std::vector<DstbMissionInfo>& missionInfos,
160         const CallerInfo& callerInfo) override;
161     int32_t GetRemoteMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
162         std::unique_ptr<AAFwk::MissionSnapshot>& missionSnapshot) override;
163     int32_t StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag,
164         int32_t callingUid, uint32_t callingTokenId) override;
165     int32_t StartSyncMissionsFromRemote(const CallerInfo& callerInfo,
166         std::vector<DstbMissionInfo>& missionInfos) override;
167     int32_t StopSyncRemoteMissions(const std::string& devId, int32_t callingUid) override;
168     int32_t StopSyncMissionsFromRemote(const CallerInfo& callerInfo) override;
169     int32_t RegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj,
170         int32_t callingUid) override;
171     int32_t RegisterOnListener(const std::string& type, const sptr<IRemoteObject>& obj, int32_t callingUid) override;
172     int32_t RegisterOffListener(const std::string& type, const sptr<IRemoteObject>& obj, int32_t callingUid) override;
173     int32_t UnRegisterMissionListener(const std::u16string& devId, const sptr<IRemoteObject>& obj) override;
174     int32_t SetMissionContinueState(int32_t missionId, const AAFwk::ContinueState &state, int32_t callingUid) override;
175     void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override;
176 #endif
177     int32_t RegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj) override;
178     int32_t UnRegisterDSchedEventListener(const DSchedEventType& type, const sptr<IRemoteObject>& obj) override;
179     int32_t GetContinueInfo(std::string& dstNetworkId, std::string& srcNetworkId) override;
180     int32_t GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events) override;
181     void ProcessConnectDied(const sptr<IRemoteObject>& connect);
182     void ProcessDeviceOffline(const std::string& deviceId);
183     void DumpConnectInfo(std::string& info);
184     void DumpSessionsLocked(const std::list<ConnectAbilitySession>& sessionsList, std::string& info);
185     void DumpElementLocked(const std::list<AppExecFwk::ElementName>& elementsList, std::string& info);
186     int32_t StartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
187         int32_t callerUid, int32_t callerPid, uint32_t accessToken) override;
188     int32_t ReleaseRemoteAbility(const sptr<IRemoteObject>& connect,
189         const AppExecFwk::ElementName &element) override;
190     int32_t StartAbilityByCallFromRemote(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
191         const CallerInfo& callerInfo, const AccountInfo& accountInfo) override;
192     int32_t ReleaseAbilityFromRemote(const sptr<IRemoteObject>& connect, const AppExecFwk::ElementName &element,
193         const CallerInfo& callerInfo) override;
194 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
195     int32_t StartRemoteShareForm(const std::string& remoteDeviceId,
196         const AppExecFwk::FormShareInfo& formShareInfo) override;
197     int32_t StartShareFormFromRemote(
198         const std::string& remoteDeviceId, const AppExecFwk::FormShareInfo& formShareInfo) override;
199     void ProcessFormMgrDied(const wptr<IRemoteObject>& remote);
200 #endif
201     void ProcessCallerDied(const sptr<IRemoteObject>& connect, int32_t deviceType);
202     void ProcessCalleeDied(const sptr<IRemoteObject>& connect);
203     void ProcessCallResult(const sptr<IRemoteObject>& calleeConnect, const sptr<IRemoteObject>& callerConnect);
204     int32_t StartRemoteFreeInstall(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
205         uint32_t accessToken, const sptr<IRemoteObject>& callback) override;
206     int32_t StartFreeInstallFromRemote(const FreeInstallInfo& info, int64_t taskId) override;
207     bool CheckSinkAccessControlUser(const FreeInstallInfo& info);
208     int32_t NotifyCompleteFreeInstallFromRemote(int64_t taskId, int32_t resultCode) override;
209     int32_t NotifyCompleteFreeInstall(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode);
210     int32_t GetDistributedComponentList(std::vector<std::string>& distributedComponents) override;
211     void SetContinuationTimeout(int32_t missionId, int32_t timeout);
212     void RemoveContinuationTimeout(int32_t missionId);
213     std::string GetContinuaitonDevice(int32_t missionId);
214     int32_t NotifyStateChangedFromRemote(int32_t abilityState, int32_t connectToken,
215         const AppExecFwk::ElementName& element) override;
216     int32_t NotifyStateChanged(int32_t abilityState, AppExecFwk::ElementName& element,
217         const sptr<IRemoteObject>& token);
218     int32_t StopRemoteExtensionAbility(const OHOS::AAFwk::Want& want, int32_t callerUid,
219         uint32_t accessToken, int32_t extensionType) override;
220     int32_t StopExtensionAbilityFromRemote(const OHOS::AAFwk::Want& remoteWant, const CallerInfo& callerInfo,
221         const AccountInfo& accountInfo, int32_t extensionType) override;
222     int32_t CheckTargetPermission(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
223         const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension);
224     int32_t CheckTargetPermission4DiffBundle(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
225         const AccountInfo& accountInfo, int32_t flag, bool needQueryExtension);
226     int32_t CheckCollabStartPermission(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
227         const AccountInfo& accountInfo, bool needQueryExtension);
228     ErrCode QueryOsAccount(int32_t& activeAccountId);
229     void RegisterDataShareObserver(const std::string& key);
230     int32_t ContinueStateCallbackRegister(int32_t missionId, std::string bundleName, std::string moduleName,
231         std::string abilityName, sptr<IRemoteObject> callback);
232     int32_t ContinueStateCallbackUnRegister(int32_t missionId, std::string bundleName, std::string moduleName,
233         std::string abilityName);
234 
235 #ifdef DMSFWK_INTERACTIVE_ADAPTER
236     bool CheckRemoteOsType(const std::string& netwokId) override;
237     int32_t StartAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
238     int32_t StopAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
239     int32_t ConnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
240     int32_t DisconnectAbilityFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
241     int32_t NotifyAbilityLifecycleChangedFromRemoteAdapter(MessageParcel& data, MessageParcel& reply) override;
242 
243     void OnDeviceOnlineEx(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
244     void OnDeviceOfflineEx(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
245     void OnDeviceInfoChangedEx(const OHOS::DistributedHardware::DmDeviceInfo& deviceInfo);
246 #endif
247     int32_t OnHAEventAdapter(const std::string& instanceTag, int32_t eventType,
248         const std::string& eventId, const std::unordered_map<std::string, std::string>& properties);
249 
250 private:
251     DistributedSchedService();
252     bool Init();
253     void InitDataShareManager();
254     void InitMissionManager();
255     void InitCommonEventListener();
256     int32_t GetCallerInfo(const std::string &localDeviceId, int32_t callerUid, uint32_t accessToken,
257         CallerInfo &callerInfo);
258     void RemoteConnectAbilityMappingLocked(const sptr<IRemoteObject>& connect, const std::string& localDeviceId,
259         const std::string& remoteDeviceId, const AppExecFwk::ElementName& element, const CallerInfo& callerInfo,
260         TargetComponent targetComponent);
261     int32_t DisconnectEachRemoteAbilityLocked(const std::string& localDeviceId,
262         const std::string& remoteDeviceId, const sptr<IRemoteObject>& connect);
263     sptr<IDistributedSched> GetRemoteDms(const std::string& remoteDeviceId);
264     static bool GetLocalDeviceId(std::string& localDeviceId);
265     bool CheckDeviceId(const std::string& localDeviceId, const std::string& remoteDeviceId);
266     bool CheckDeviceIdFromRemote(const std::string& localDeviceId,
267         const std::string& destinationDeviceId, const std::string& sourceDeviceId);
268     void NotifyDeviceOfflineToAppLocked(const sptr<IRemoteObject>& connect, const ConnectAbilitySession& session);
269     int32_t NotifyApp(const sptr<IRemoteObject>& connect, const AppExecFwk::ElementName& element, int32_t errCode);
270     void NotifyProcessDiedAll(const std::list<ProcessDiedNotifyInfo>& notifyList);
271     void NotifyProcessDied(const std::string& remoteDeviceId, const CallerInfo& callerInfo,
272         TargetComponent targetComponent);
273     int32_t CheckDistributedConnectLocked(const CallerInfo& callerInfo) const;
274     void DecreaseConnectLocked(int32_t uid);
275     static int32_t GetUidLocked(const std::list<ConnectAbilitySession>& sessionList);
276     int32_t TryConnectRemoteAbility(const OHOS::AAFwk::Want& want,
277         const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo);
278     int32_t ContinueLocalMissionDealFreeInstall(OHOS::AAFwk::Want& want, int32_t missionId,
279         const std::string& dstDeviceId, const sptr<IRemoteObject>& callback);
280 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
281     sptr<AppExecFwk::IFormMgr> GetFormMgrProxy();
282 #endif
283     int32_t SetCallerInfo(int32_t callerUid, std::string localDeviceId, uint32_t accessToken, CallerInfo& callerInfo);
284     int32_t SetWantForContinuation(AAFwk::Want& newWant, int32_t missionId);
285     int32_t ContinueLocalMission(const std::string& dstDeviceId, int32_t missionId,
286         const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
287     int32_t ContinueAbilityWithTimeout(const std::string& dstDeviceId, int32_t missionId,
288         const sptr<IRemoteObject>& callback, uint32_t remoteBundleVersion = 0);
289     int32_t ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId, int32_t missionId,
290         const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
291     int32_t ContinueRemoteMission(const std::string& srcDeviceId, const std::string& dstDeviceId,
292         const std::string& bundleName, const sptr<IRemoteObject>& callback, const OHOS::AAFwk::WantParams& wantParams);
293     int32_t TryStartRemoteAbilityByCall(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
294         const CallerInfo& callerInfo);
295     int32_t StartLocalAbility(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode);
296     int32_t StartAbility(const OHOS::AAFwk::Want& want, int32_t requestCode);
297     int32_t HandleRemoteNotify(const FreeInstallInfo& info, int64_t taskId, int32_t resultCode);
298     void ReportDistributedComponentChange(const CallerInfo& callerInfo, int32_t changeType,
299         int32_t componentType, int32_t deviceType);
300     void ReportDistributedComponentChange(const ConnectInfo& connectInfo, int32_t changeType,
301         int32_t componentType, int32_t deviceType);
302     void HandleLocalCallerDied(const sptr<IRemoteObject>& connect);
303     void SaveCallerComponent(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
304         const CallerInfo& callerInfo);
305     void RemoveCallerComponent(const sptr<IRemoteObject>& connect);
306     void ProcessCalleeOffline(const std::string& deviceId);
307     void GetConnectComponentList(std::vector<std::string>& distributedComponents);
308     void GetCallComponentList(std::vector<std::string>& distributedComponents);
309     void ProcessFreeInstallOffline(const std::string& deviceId);
310     bool RegisterAppStateObserver(const OHOS::AAFwk::Want& want, const CallerInfo& callerInfo,
311         const sptr<IRemoteObject>& srcConnect, const sptr<IRemoteObject>& callbackWrapper);
312     void UnregisterAppStateObserver(const sptr<IRemoteObject>& callbackWrapper);
313     sptr<AppExecFwk::IAppMgr> GetAppManager();
314     int32_t SaveConnectToken(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect);
315     void SetCleanMissionFlag(const OHOS::AAFwk::Want& want, int32_t missionId);
316     void RemoveConnectAbilityInfo(const std::string& deviceId);
317     void InitWifiStateListener();
318     void InitWifiSemiStateListener();
319     void InitBluetoothStateListener();
320     void NotifyContinuateEventResult(int32_t resultCode, const EventNotify& event);
321     void InitDeviceCfg();
322     void NotifyCollaborateEventResult(int32_t resultCode, const EventNotify& event);
323     void GetContinueEventInfo(int32_t callingUid, std::vector<EventNotify> &events);
324     void GetCollaborateEventInfo(int32_t callingUid, std::vector<EventNotify> &events);
325     void GetCollaborateEventsByCallers(int32_t callingUid, const std::string &callingBundleName,
326         std::vector<EventNotify> &events);
327     void GetCollaborateEventsByCallees(int32_t callingUid, const std::string &callingBundleName,
328         std::vector<EventNotify> &events);
329     void GetCurSrcCollaborateEvent(const CallerInfo &callerInfo, const AppExecFwk::ElementName &element,
330         DSchedEventState state, int32_t ret, EventNotify &event);
331     void GetCurDestCollaborateEvent(const CallerInfo &callerInfo, const AppExecFwk::ElementName &element,
332         DSchedEventState state, int32_t ret, EventNotify &event);
333     void NotifyCollaborateEventWithSessions(const std::list<ConnectAbilitySession> &sessionsList,
334         DSchedEventState state, int32_t ret);
335     bool CheckCallingUid();
336 
337 #ifdef DMSFWK_INTERACTIVE_ADAPTER
338     int32_t GetDmsInteractiveAdapterProxy();
339     int32_t StartRemoteAbilityAdapter(const OHOS::AAFwk::Want& want, int32_t callerUid, int32_t requestCode,
340         uint32_t accessToken);
341     int32_t ConnectRemoteAbilityAdapter(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
342         int32_t callerUid, int32_t callerPid, uint32_t accessToken);
343     int32_t DisconnectRemoteAbilityAdapter(const sptr<IRemoteObject>& connect, int32_t callerUid,
344         uint32_t accessToken);
345 #endif
346 
347 private:
348     std::shared_ptr<DSchedContinuation> dschedContinuation_;
349     std::shared_ptr<DSchedCollaborationCallbackMgr> collaborateCbMgr_;
350     std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> distributedConnectAbilityMap_;
351     std::map<sptr<IRemoteObject>, ConnectInfo> connectAbilityMap_;
352     std::unordered_map<int32_t, uint32_t> trackingUidMap_;
353     std::mutex distributedLock_;
354     std::mutex connectLock_;
355     sptr<IRemoteObject::DeathRecipient> connectDeathRecipient_;
356     sptr<SvcDistributedConnection> svcDConn_;
357 #ifdef SUPPORT_DISTRIBUTED_FORM_SHARE
358     sptr<IRemoteObject::DeathRecipient> formMgrDeathRecipient_;
359     sptr<AppExecFwk::IFormMgr> formMgrProxy_;
360     std::mutex formMgrLock_;
361 #endif
362     std::mutex calleeLock_;
363     std::map<sptr<IRemoteObject>, ConnectInfo> calleeMap_;
364     sptr<IRemoteObject::DeathRecipient> callerDeathRecipient_;
365     std::shared_ptr<DmsCallbackTask> dmsCallbackTask_;
366     std::shared_ptr<AppExecFwk::EventHandler> componentChangeHandler_;
367     std::mutex callerLock_;
368     std::map<sptr<IRemoteObject>, std::list<ConnectAbilitySession>> callerMap_;
369     sptr<IRemoteObject::DeathRecipient> callerDeathRecipientForLocalDevice_;
370     std::mutex observerLock_;
371     std::map<sptr<IRemoteObject>, ObserverInfo> observerMap_;
372     std::mutex callLock_;
373     std::map<sptr<IRemoteObject>, CallInfo> callMap_;
374     std::mutex tokenMutex_;
375     std::mutex registerMutex_;
376     std::atomic<int32_t> token_ {0};
377     std::map<std::string, sptr<AppStateObserver>> bundleNameMap_;
378     sptr<DistributedMissionFocusedListener> missionFocusedListener_ = nullptr;
379 
380 #ifdef DMSFWK_INTERACTIVE_ADAPTER
381     std::mutex dmsAdapetrLock_;
382     void *dllHandle_ = nullptr;
383     IDmsInteractiveAdapter dmsAdapetr_ = {
384         .StartRemoteAbilityAdapter = nullptr,
385         .StartAbilityFromRemoteAdapter = nullptr,
386         .StopAbilityFromRemoteAdapter = nullptr,
387         .ConnectRemoteAbilityAdapter = nullptr,
388         .ConnectAbilityFromRemoteAdapter = nullptr,
389         .DisconnectRemoteAbilityAdapter = nullptr,
390         .DisconnectAbilityFromRemoteAdapter = nullptr,
391         .NotifyAbilityLifecycleChangedFromRemoteAdapter = nullptr,
392         .OnDeviceOnlineEx = nullptr,
393         .OnDeviceOfflineEx = nullptr,
394         .OnDeviceInfoChangedEx = nullptr,
395         .OnHAEventAdapter = nullptr,
396     };
397 #endif
398 };
399 
400 class ConnectAbilitySession {
401 public:
402     ConnectAbilitySession(const std::string& sourceDeviceId, const std::string& destinationDeviceId,
403         const CallerInfo& callerInfo, TargetComponent targetComponent = TargetComponent::HARMONY_COMPONENT);
404     ~ConnectAbilitySession() = default;
405 
GetSourceDeviceId()406     const std::string& GetSourceDeviceId() const
407     {
408         return sourceDeviceId_;
409     }
410 
GetDestinationDeviceId()411     const std::string& GetDestinationDeviceId() const
412     {
413         return destinationDeviceId_;
414     }
415 
GetElementsList()416     std::list<AppExecFwk::ElementName> GetElementsList() const
417     {
418         return elementsList_;
419     }
420 
GetCallerInfo()421     CallerInfo GetCallerInfo() const
422     {
423         return callerInfo_;
424     }
425 
GetTargetComponent()426     TargetComponent GetTargetComponent() const
427     {
428         return targetComponent_;
429     }
430 
431     bool IsSameCaller(const CallerInfo& callerInfo);
432     void AddElement(const AppExecFwk::ElementName& element);
433 
434 private:
435     std::string sourceDeviceId_;
436     std::string destinationDeviceId_;
437     std::list<AppExecFwk::ElementName> elementsList_;
438     CallerInfo callerInfo_;
439     TargetComponent targetComponent_;
440 };
441 
442 class CallerDeathRecipient : public IRemoteObject::DeathRecipient {
443 public:
444     CallerDeathRecipient() = default;
CallerDeathRecipient(int32_t deviceType)445     explicit CallerDeathRecipient(int32_t deviceType)
446     {
447         deviceType_ = deviceType;
448     }
449     ~CallerDeathRecipient() override = default;
450     void OnRemoteDied(const wptr<IRemoteObject>& remote) override;
451 private:
452     int32_t deviceType_ = IDistributedSched::CALLEE;
453 };
454 } // namespace DistributedSchedule
455 } // namespace OHOS
456 #endif // OHOS_DISTRIBUTED_SCHED_SERVICE_H
457