1 /*
2  * Copyright (c) 2021-2023 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_ADAPTER_H
17 #define OHOS_DISTRIBUTED_SCHED_ADAPTER_H
18 
19 #include "ability_info.h"
20 #include "ability_manager_client.h"
21 #include "caller_info.h"
22 #include "device_auth.h"
23 #include "dfx/distributed_radar.h"
24 #include "distributed_sched_interface.h"
25 #include "event_handler.h"
26 #include "if_system_ability_manager.h"
27 #include "iremote_object.h"
28 #include "mission/distributed_mission_change_listener.h"
29 #include "mission/distributed_mission_info.h"
30 #include "single_instance.h"
31 #include "uri.h"
32 
33 namespace OHOS {
34 namespace DistributedSchedule {
35 class DistributedSchedAdapter {
36     DECLARE_SINGLE_INSTANCE(DistributedSchedAdapter);
37 
38 public:
39     using AccountInfo = IDistributedSched::AccountInfo;
40 
41     void Init();
42     void UnInit();
43 
44     int32_t ConnectAbility(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
45         const sptr<IRemoteObject>& callerToken);
46     int32_t DisconnectAbility(const sptr<IRemoteObject>& connect);
47     void DeviceOnline(const std::string& deviceId);
48     void DeviceOffline(const std::string& deviceId);
49     void ProcessConnectDied(const sptr<IRemoteObject>& connect);
50     int32_t GetLocalMissionInfos(int32_t numMissions, std::vector<DstbMissionInfo>& missionInfos);
51     int32_t RegisterMissionListener(const sptr<AAFwk::IMissionListener>& listener);
52     int32_t UnRegisterMissionListener(const sptr<AAFwk::IMissionListener>& listener);
53     int32_t GetLocalMissionSnapshotInfo(const std::string& networkId, int32_t missionId,
54         AAFwk::MissionSnapshot& missionSnapshot);
55     int32_t ReleaseAbility(const sptr<IRemoteObject>& connect, const AppExecFwk::ElementName &element);
56     int32_t StartAbilityByCall(const OHOS::AAFwk::Want& want, const sptr<IRemoteObject>& connect,
57         const sptr<IRemoteObject>& callerToken);
58     void ProcessCallerDied(const sptr<IRemoteObject>& connect, int32_t deviceType);
59     void ProcessCalleeDied(const sptr<IRemoteObject>& connect);
60     bool InitHichainService();
61     void ProcessCallResult(const sptr<IRemoteObject>& calleeConnect, const sptr<IRemoteObject>& callerConnect);
62     bool CheckAccessToGroup(const std::string& groupId, const std::string& targetBundleName);
63     bool GetRelatedGroups(const std::string& udid, const std::string& bundleName, std::string& returnGroups);
64 private:
65     void ProcessDeviceOffline(const std::string& deviceId);
66 
67     std::shared_ptr<AppExecFwk::EventHandler> dmsAdapterHandler_;
68     const DeviceGroupManager* hichainGmInstance_ = nullptr;
69     std::mutex hichainLock_;
70 };
71 } // namespace DistributedSchedule
72 } // namespace OHOS
73 #endif // OHOS_DISTRIBUTED_SCHED_ADAPTER_H
74