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_I_DM_SERVICE_IMPL_H
17 #define OHOS_I_DM_SERVICE_IMPL_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "socket.h"
23 
24 #include "idevice_manager_service_listener.h"
25 #include "dm_device_info.h"
26 #include "dm_publish_info.h"
27 #include "dm_subscribe_info.h"
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 class IDeviceManagerServiceImpl {
32 public:
~IDeviceManagerServiceImpl()33     virtual ~IDeviceManagerServiceImpl() {}
34 
35     /**
36      * @tc.name: IDeviceManagerServiceImpl::Initialize
37      * @tc.desc: Initialize the device manager service impl
38      * @tc.type: FUNC
39      */
40     virtual int32_t Initialize(const std::shared_ptr<IDeviceManagerServiceListener> &listener) = 0;
41 
42     /**
43      * @tc.name: IDeviceManagerServiceImpl::Release
44      * @tc.desc: Release the device manager service impl
45      * @tc.type: FUNC
46      */
47     virtual void Release() = 0;
48 
49     /**
50      * @tc.name: IDeviceManagerServiceImpl::StartDeviceDiscovery
51      * @tc.desc: Start Device Discovery of the device manager service impl
52      * @tc.type: FUNC
53      */
54     virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
55                                          const std::string &extra) = 0;
56 
57     /**
58      * @tc.name: IDeviceManagerServiceImpl::StartDeviceDiscovery
59      * @tc.desc: Start Device Discovery of the device manager service impl
60      * @tc.type: FUNC
61      */
62     virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const uint16_t subscribeId,
63                                  const std::string &filterOptions) = 0;
64 
65    /**
66      * @tc.name: IDeviceManagerServiceImpl::StopDeviceDiscovery
67      * @tc.desc: Stop Device Discovery of the device manager service impl
68      * @tc.type: FUNC
69      */
70     virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) = 0;
71 
72    /**
73      * @tc.name: IDeviceManagerServiceImpl::PublishDeviceDiscovery
74      * @tc.desc: Publish Device Discovery of the device manager service impl
75      * @tc.type: FUNC
76      */
77     virtual int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo) = 0;
78 
79     /**
80      * @tc.name: IDeviceManagerServiceImpl::UnPublishDeviceDiscovery
81      * @tc.desc: UnPublish Device Discovery of the device manager service impl
82      * @tc.type: FUNC
83      */
84     virtual int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) = 0;
85 
86     /**
87      * @tc.name: IDeviceManagerServiceImpl::AuthenticateDevice
88      * @tc.desc: Authenticate Device of the device manager service impl
89      * @tc.type: FUNC
90      */
91     virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
92                                        const std::string &extra) = 0;
93 
94     /**
95      * @tc.name: IDeviceManagerServiceImpl::UnAuthenticateDevice
96      * @tc.desc: UnAuthenticate Device of the device manager service impl
97      * @tc.type: FUNC
98      */
99     virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const std::string &networkId) = 0;
100 
101     /**
102      * @tc.name: IDeviceManagerServiceImpl::BindDevice
103      * @tc.desc: Bind Device of the device manager service impl
104      * @tc.type: FUNC
105      */
106     virtual int32_t BindDevice(const std::string &pkgName, int32_t authType, const std::string &deviceId,
107         const std::string &bindParam) = 0;
108 
109     /**
110      * @tc.name: IDeviceManagerServiceImpl::UnBindDevice
111      * @tc.desc: UnBindDevice Device of the device manager service impl
112      * @tc.type: FUNC
113      */
114     virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId) = 0;
115 
116     /**
117      * @tc.name: IDeviceManagerServiceImpl::SetUserOperation
118      * @tc.desc: Se tUser Operation of device manager service impl
119      * @tc.type: FUNC
120      */
121     virtual int32_t SetUserOperation(std::string &pkgName, int32_t action, const std::string &params) = 0;
122 
123     /**
124      * @tc.name: IDeviceManagerServiceImpl::HandleDeviceStatusChange
125      * @tc.desc: Handle Device Status Event to the device manager service impl
126      * @tc.type: FUNC
127      */
128     virtual void HandleDeviceStatusChange(DmDeviceState devState, DmDeviceInfo &devInfo) = 0;
129     /**
130      * @tc.name: IDeviceManagerServiceImpl::OnSessionOpened
131      * @tc.desc: Send Session Opened event to the device manager service impl
132      * @tc.type: FUNC
133      */
134     virtual int OnSessionOpened(int sessionId, int result) = 0;
135 
136     /**
137      * @tc.name: IDeviceManagerServiceImpl::OnSessionClosed
138      * @tc.desc: Send Session Closed event to the device manager service impl
139      * @tc.type: FUNC
140      */
141     virtual void OnSessionClosed(int sessionId) = 0;
142 
143     /**
144      * @tc.name: IDeviceManagerServiceImpl::OnBytesReceived
145      * @tc.desc: Send Bytes Received event to the device manager service impl
146      * @tc.type: FUNC
147      */
148     virtual void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen) = 0;
149 
150     /**
151      * @tc.name: IDeviceManagerServiceImpl::RequestCredential
152      * @tc.desc: RequestCredential of the Device Manager Service
153      * @tc.type: FUNC
154      */
155     virtual int32_t RequestCredential(const std::string &reqJsonStr, std::string &returnJsonStr) = 0;
156     /**
157      * @tc.name: IDeviceManagerServiceImpl::ImportCredential
158      * @tc.desc: ImportCredential of the Device Manager Service
159      * @tc.type: FUNC
160      */
161     virtual int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo) = 0;
162     /**
163      * @tc.name: IDeviceManagerServiceImpl::DeleteCredential
164      * @tc.desc: DeleteCredential of the Device Manager Service
165      * @tc.type: FUNC
166      */
167     virtual int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo) = 0;
168     /**
169      * @tc.name: IDeviceManagerServiceImpl::MineRequestCredential
170      * @tc.desc: MineRequestCredential of the Device Manager Service
171      * @tc.type: FUNC
172      */
173     virtual int32_t MineRequestCredential(const std::string &pkgName, std::string &returnJsonStr) = 0;
174     /**
175      * @tc.name: IDeviceManagerServiceImpl::CheckCredential
176      * @tc.desc: CheckCredential of the Device Manager Service
177      * @tc.type: FUNC
178      */
179     virtual int32_t CheckCredential(const std::string &pkgName, const std::string &reqJsonStr,
180         std::string &returnJsonStr) = 0;
181     /**
182      * @tc.name: IDeviceManagerServiceImpl::ImportCredential
183      * @tc.desc: ImportCredential of the Device Manager Service
184      * @tc.type: FUNC
185      */
186     virtual int32_t ImportCredential(const std::string &pkgName, const std::string &reqJsonStr,
187         std::string &returnJsonStr) = 0;
188     /**
189      * @tc.name: IDeviceManagerServiceImpl::DeleteCredential
190      * @tc.desc: DeleteCredential of the Device Manager Service
191      * @tc.type: FUNC
192      */
193     virtual int32_t DeleteCredential(const std::string &pkgName, const std::string &reqJsonStr,
194         std::string &returnJsonStr) = 0;
195     /**
196      * @tc.name: IDeviceManagerServiceImpl::RegisterCredentialCallback
197      * @tc.desc: RegisterCredentialCallback
198      * @tc.type: FUNC
199      */
200     virtual int32_t RegisterCredentialCallback(const std::string &pkgName) = 0;
201     /**
202      * @tc.name: IDeviceManagerServiceImpl::UnRegisterCredentialCallback
203      * @tc.desc: UnRegisterCredentialCallback
204      * @tc.type: FUNC
205      */
206     virtual int32_t UnRegisterCredentialCallback(const std::string &pkgName) = 0;
207 
208     /**
209      * @tc.name: IDeviceManagerServiceImpl::NotifyEvent
210      * @tc.desc: NotifyEvent
211      * @tc.type: FUNC
212      */
213     virtual int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event) = 0;
214 
215     /**
216      * @tc.name: IDeviceManagerServiceImpl::GetGroupType
217      * @tc.desc: GetGroupType
218      * @tc.type: FUNC
219      */
220     virtual int32_t GetGroupType(std::vector<DmDeviceInfo> &deviceList) = 0;
221 
222     /**
223      * @tc.name: IDeviceManagerServiceImpl::GetUdidHashByNetWorkId
224      * @tc.desc: GetUdidHashByNetWorkId
225      * @tc.type: FUNC
226      */
227     virtual int32_t GetUdidHashByNetWorkId(const char *networkId, std::string &deviceId) = 0;
228 
229     /**
230      * @tc.name: IDeviceManagerServiceImpl::ImportAuthCode
231      * @tc.desc: ImportAuthCode
232      * @tc.type: FUNC
233      */
234     virtual int32_t ImportAuthCode(const std::string &pkgName, const std::string &authCode) = 0;
235 
236     /**
237      * @tc.name: IDeviceManagerServiceImpl::ExportAuthCode
238      * @tc.desc: ExportAuthCode
239      * @tc.type: FUNC
240      */
241     virtual int32_t ExportAuthCode(std::string &authCode) = 0;
242 
243     /**
244      * @tc.name: IDeviceManagerServiceImpl::BindTarget
245      * @tc.desc: BindTarget
246      * @tc.type: FUNC
247      */
248     virtual int32_t BindTarget(const std::string &pkgName, const PeerTargetId &targetId,
249         const std::map<std::string, std::string> &bindParam) = 0;
250 
251     /**
252      * @tc.name: IDeviceManagerServiceImpl::LoadHardwareFwkService
253      * @tc.desc: LoadHardwareFwkService
254      * @tc.type: FUNC
255      */
256     virtual void LoadHardwareFwkService() = 0;
257 
258     /**
259      * @tc.name: IDeviceManagerServiceImpl::RegisterUiStateCallback
260      * @tc.desc: RegisterUiStateCallback
261      * @tc.type: FUNC
262      */
263     virtual int32_t RegisterUiStateCallback(const std::string &pkgName) = 0;
264 
265     /**
266      * @tc.name: IDeviceManagerServiceImpl::UnRegisterUiStateCallback
267      * @tc.desc: UnRegisterUiStateCallback
268      * @tc.type: FUNC
269      */
270     virtual int32_t UnRegisterUiStateCallback(const std::string &pkgName) = 0;
271 
272     virtual std::unordered_map<std::string, DmAuthForm> GetAppTrustDeviceIdList(std::string pkgname) = 0;
273     virtual void OnUnbindSessionOpened(int32_t socket, PeerSocketInfo info) = 0;
274     virtual void OnUnbindSessionCloseed(int32_t socket) = 0;
275     virtual void OnUnbindBytesReceived(int32_t socket, const void *data, uint32_t dataLen) = 0;
276     virtual int32_t DpAclAdd(const std::string &udid) = 0;
277     virtual int32_t IsSameAccount(const std::string &udid) = 0;
278     virtual void AccountCommonEventCallback(int32_t userId, std::string commonEventType) = 0;
279     virtual void ScreenCommonEventCallback(std::string commonEventType) = 0;
280     virtual int32_t CheckIsSameAccount(const DmAccessCaller &caller, const std::string &srcUdid,
281         const DmAccessCallee &callee, const std::string &sinkUdid) = 0;
282     virtual int32_t CheckAccessControl(const DmAccessCaller &caller, const std::string &srcUdid,
283         const DmAccessCallee &callee, const std::string &sinkUdid) = 0;
284     virtual void HandleDeviceNotTrust(const std::string &udid) = 0;
285     virtual void HandleIdentAccountLogout(const std::string &udid, int32_t userId, const std::string &accountId) = 0;
286     virtual void HandleUserRemoved(int32_t preUserId) = 0;
287     virtual std::map<std::string, int32_t> GetDeviceIdAndBindType(int32_t userId, const std::string &accountId) = 0;
288     virtual int32_t StopAuthenticateDevice(const std::string &pkgName) = 0;
289     virtual void HandleDeviceScreenStatusChange(DmDeviceInfo &devInfo) = 0;
290     virtual void HandleCredentialAuthStatus(const std::string &proofInfo, uint16_t deviceTypeId,
291                                             int32_t errcode) = 0;
292 };
293 
294 using CreateDMServiceFuncPtr = IDeviceManagerServiceImpl *(*)(void);
295 } // namespace DistributedHardware
296 } // namespace OHOS
297 #endif // OHOS_I_DM_SERVICE_IMPL_H
298