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