• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_DEVICE_MANAGER_IMPL_H
17 #define OHOS_DEVICE_MANAGER_IMPL_H
18 
19 #include "device_manager.h"
20 #if !defined(__LITEOS_M__)
21 #include "ipc_client_manager.h"
22 #include "ipc_client_proxy.h"
23 #endif
24 #include <map>
25 #include <mutex>
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 class DeviceManagerImpl : public DeviceManager {
30 public:
31     static DeviceManagerImpl &GetInstance();
32 
33 public:
34     /**
35      * @tc.name: DeviceManagerImpl::InitDeviceManager
36      * @tc.desc: Initialize DeviceManager
37      * @tc.type: FUNC
38      */
39     virtual int32_t InitDeviceManager(const std::string &pkgName,
40                                       std::shared_ptr<DmInitCallback> dmInitCallback) override;
41     /**
42      * @tc.name: DeviceManagerImpl::UnInitDeviceManager
43      * @tc.desc: UnInitialize DeviceManager
44      * @tc.type: FUNC
45      */
46     virtual int32_t UnInitDeviceManager(const std::string &pkgName) override;
47     /**
48      * @tc.name: DeviceManagerImpl::GetTrustedDeviceList
49      * @tc.desc: Get device list of trusted devices
50      * @tc.type: FUNC
51      */
52     virtual int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
53                                          std::vector<DmDeviceInfo> &deviceList) override;
54     /**
55      * @tc.name: DeviceManagerImpl::GetTrustedDeviceList
56      * @tc.desc: Get device list of trusted devices
57      * @tc.type: FUNC
58      */
59     virtual int32_t GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
60         bool isRefresh, std::vector<DmDeviceInfo> &deviceList) override;
61 	/**
62      * @tc.name: DeviceManagerImpl::GetAvailableDeviceList
63      * @tc.desc: Get device list of trusted devices
64      * @tc.type: FUNC
65      */
66     virtual int32_t GetAvailableDeviceList(const std::string &pkgName,
67     	std::vector<DmDeviceBasicInfo> &deviceList) override;
68     /**
69      * @tc.name: DeviceManagerImpl::GetLocalDeviceInfo
70      * @tc.desc: Get local device information
71      * @tc.type: FUNC
72      */
73     virtual int32_t GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info) override;
74     /**
75      * @tc.name: DeviceManagerImpl::GetDeviceInfo
76      * @tc.desc: Get local device information by networkId
77      * @tc.type: FUNC
78      */
79     virtual int32_t GetDeviceInfo(const std::string &pkgName, const std::string networkId,
80                                   DmDeviceInfo &deviceInfo) override;
81     /**
82      * @tc.name: DeviceManagerImpl::RegisterDevStateCallback
83      * @tc.desc: Register device development status callback
84      * @tc.type: FUNC
85      */
86     virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
87                                              std::shared_ptr<DeviceStateCallback> callback) override;
88     /**
89      * @tc.name: DeviceManagerImpl::RegisterDevStatusCallback
90      * @tc.desc: Register device development status callback
91      * @tc.type: FUNC
92      */
93     virtual int32_t RegisterDevStatusCallback(const std::string &pkgName, const std::string &extra,
94                                                 std::shared_ptr<DeviceStatusCallback> callback) override;
95     /**
96      * @tc.name: DeviceManagerImpl::UnRegisterDevStateCallback
97      * @tc.desc: UnRegister device development status callback
98      * @tc.type: FUNC
99      */
100     virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName) override;
101     /**
102      * @tc.name: DeviceManagerImpl::UnRegisterDevStatusCallback
103      * @tc.desc: UnRegister device development status callback
104      * @tc.type: FUNC
105      */
106     virtual int32_t UnRegisterDevStatusCallback(const std::string &pkgName) override;
107     /**
108      * @tc.name: DeviceManagerImpl::StartDeviceDiscovery
109      * @tc.desc: Initiate device discovery
110      * @tc.type: FUNC
111      */
112     virtual int32_t StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
113                                          const std::string &extra,
114                                          std::shared_ptr<DiscoveryCallback> callback) override;
115     /**
116      * @tc.name: DeviceManagerImpl::StartDeviceDiscovery
117      * @tc.desc: Initiate device discovery
118      * @tc.type: FUNC
119      */
120     virtual int32_t StartDeviceDiscovery(const std::string &pkgName, uint64_t tokenId,
121                                          const std::string &filterOptions,
122                                          std::shared_ptr<DiscoveryCallback> callback) override;
123     /**
124      * @tc.name: DeviceManagerImpl::StopDeviceDiscovery
125      * @tc.desc: Stop device discovery
126      * @tc.type: FUNC
127      */
128     virtual int32_t StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId) override;
129     /**
130      * @brief Stop device discovery.
131      * @param pkgName package name.
132      * @param tokenId app flag to discovery device.
133      * @return Returns 0 if success.
134      */
135     virtual int32_t StopDeviceDiscovery(uint64_t tokenId, const std::string &pkgName) override;
136     /**
137      * @tc.name: DeviceManagerImpl::PublishDeviceDiscovery
138      * @tc.desc: Publish device discovery
139      * @tc.type: FUNC
140      */
141     virtual int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo,
142         std::shared_ptr<PublishCallback> callback) override;
143     /**
144      * @tc.name: DeviceManagerImpl::UnPublishDeviceDiscovery
145      * @tc.desc: UnPublish device discovery
146      * @tc.type: FUNC
147      */
148     virtual int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId) override;
149     /**
150      * @tc.name: DeviceManagerImpl::AuthenticateDevice
151      * @tc.desc: Complete verifying the device
152      * @tc.type: FUNC
153      */
154     virtual int32_t AuthenticateDevice(const std::string &pkgName, int32_t authType, const DmDeviceInfo &deviceInfo,
155                                        const std::string &extra,
156                                        std::shared_ptr<AuthenticateCallback> callback) override;
157     /**
158      * @tc.name: DeviceManagerImpl::UnAuthenticateDevice
159      * @tc.desc: Cancel complete verification of device
160      * @tc.type: FUNC
161      */
162     virtual int32_t UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo) override;
163     /**
164      * @tc.name: DeviceManagerImpl::VerifyAuthentication
165      * @tc.desc: Verify device authentication
166      * @tc.type: FUNC
167      */
168     virtual int32_t VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
169                                          std::shared_ptr<VerifyAuthCallback> callback) override;
170     /**
171      * @tc.name: DeviceManagerImpl::RegisterDeviceManagerFaCallback
172      * @tc.desc: Register Fa callback for device manager
173      * @tc.type: FUNC
174      */
175     virtual int32_t RegisterDeviceManagerFaCallback(const std::string &pkgName,
176                                                     std::shared_ptr<DeviceManagerUiCallback> callback) override;
177     /**
178      * @tc.name: DeviceManagerImpl::UnRegisterDeviceManagerFaCallback
179      * @tc.desc: Unregister Fa callback for device manager
180      * @tc.type: FUNC
181      */
182     virtual int32_t UnRegisterDeviceManagerFaCallback(const std::string &pkgName) override;
183     /**
184      * @tc.name: DeviceManagerImpl::GetFaParam
185      * @tc.desc: Get Fa Param
186      * @tc.type: FUNC
187      */
188     virtual int32_t GetFaParam(const std::string &pkgName, DmAuthParam &dmFaParam) override;
189     /**
190      * @tc.name: DeviceManagerImpl::SetUserOperation
191      * @tc.desc: Set User Actions
192      * @tc.type: FUNC
193      */
194     virtual int32_t SetUserOperation(const std::string &pkgName, int32_t action, const std::string &params) override;
195     /**
196      * @tc.name: DeviceManagerImpl::GetUdidByNetworkId
197      * @tc.desc: Get Udid by NetworkId
198      * @tc.type: FUNC
199      */
200     virtual int32_t GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
201                                        std::string &udid) override;
202     /**
203      * @tc.name: DeviceManagerImpl::GetUuidByNetworkId
204      * @tc.desc: Get Uuid by NetworkId
205      * @tc.type: FUNC
206      */
207     virtual int32_t GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
208                                        std::string &uuid) override;
209     /**
210      * @tc.name: DeviceManagerImpl::RegisterDevStateCallback
211      * @tc.desc: Register development status callback
212      * @tc.type: FUNC
213      */
214     virtual int32_t RegisterDevStateCallback(const std::string &pkgName, const std::string &extra) override;
215     /**
216      * @tc.name: DeviceManagerImpl::UnRegisterDevStateCallback
217      * @tc.desc: Unregister development status callback
218      * @tc.type: FUNC
219      */
220     virtual int32_t UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra) override;
221     /**
222      * @tc.name: DeviceManagerImpl::RequestCredential
223      * @tc.desc: RequestCredential
224      * @tc.type: FUNC
225      */
226     virtual int32_t RequestCredential(const std::string &pkgName, const std::string &reqJsonStr,
227         std::string &returnJsonStr) override;
228     /**
229      * @tc.name: DeviceManagerImpl::ImportCredential
230      * @tc.desc: ImportCredential
231      * @tc.type: FUNC
232      */
233     virtual int32_t ImportCredential(const std::string &pkgName, const std::string &credentialInfo) override;
234     /**
235      * @tc.name: DeviceManagerImpl::DeleteCredential
236      * @tc.desc: DeleteCredential
237      * @tc.type: FUNC
238      */
239     virtual int32_t DeleteCredential(const std::string &pkgName, const std::string &deleteInfo) override;
240     /**
241      * @tc.name: DeviceManagerImpl::RegisterCredentialCallback
242      * @tc.desc: RegisterCredentialCallback
243      * @tc.type: FUNC
244      */
245     virtual int32_t RegisterCredentialCallback(const std::string &pkgName,
246         std::shared_ptr<CredentialCallback> callback) override;
247     /**
248      * @tc.name: DeviceManagerImpl::UnRegisterCredentialCallback
249      * @tc.desc: UnRegisterCredentialCallback
250      * @tc.type: FUNC
251      */
252     virtual int32_t UnRegisterCredentialCallback(const std::string &pkgName) override;
253 
254     /**
255      * @tc.name: DeviceManagerImpl::NotifyEvent
256      * @tc.desc: NotifyEvent
257      * @tc.type: FUNC
258      */
259     virtual int32_t NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event) override;
260 
261     virtual int32_t GetEncryptedUuidByNetworkId(const std::string &pkgName, const std::string &networkId,
262         std::string &uuid) override;
263 
264     virtual int32_t GenerateEncryptedUuid(const std::string &pkgName, const std::string &uuid,
265         const std::string &appId, std::string &encryptedUuid) override;
266 
267     /**
268      * @tc.name: DeviceManagerImpl::CheckAPIAccessPermission
269      * @tc.desc: check permission for device manager API
270      * @tc.type: FUNC
271      */
272     virtual int32_t CheckAPIAccessPermission() override;
273     virtual int32_t CheckNewAPIAccessPermission() override;
274 
275     int32_t OnDmServiceDied();
276     int32_t RegisterUiStateCallback(const std::string &pkgName);
277     int32_t UnRegisterUiStateCallback(const std::string &pkgName);
278 
279     virtual int32_t GetLocalDeviceNetWorkId(const std::string &pkgName, std::string &networkId) override;
280     virtual int32_t GetLocalDeviceId(const std::string &pkgName, std::string &networkId) override;
281     virtual int32_t GetLocalDeviceType(const std::string &pkgName, int32_t &deviceType) override;
282     virtual int32_t GetLocalDeviceName(const std::string &pkgName, std::string &deviceName) override;
283     virtual int32_t GetDeviceName(const std::string &pkgName, const std::string &networkId,
284         std::string &deviceName) override;
285     virtual int32_t GetDeviceType(const std::string &pkgName,
286         const std::string &networkId, int32_t &deviceType) override;
287     virtual int32_t BindDevice(const std::string &pkgName, int32_t bindType, const std::string &deviceId,
288         const std::string &extra, std::shared_ptr<AuthenticateCallback> callback) override;
289     virtual int32_t UnBindDevice(const std::string &pkgName, const std::string &deviceId) override;
290     virtual int32_t GetNetworkTypeByNetworkId(const std::string &pkgName, const std::string &netWorkId,
291                                        int32_t &netWorkType) override;
292 private:
293     DeviceManagerImpl() = default;
294     ~DeviceManagerImpl() = default;
295     DeviceManagerImpl(const DeviceManagerImpl &) = delete;
296     DeviceManagerImpl &operator=(const DeviceManagerImpl &) = delete;
297     DeviceManagerImpl(DeviceManagerImpl &&) = delete;
298     DeviceManagerImpl &operator=(DeviceManagerImpl &&) = delete;
299 
300 private:
301 #if !defined(__LITEOS_M__)
302     std::shared_ptr<IpcClientProxy> ipcClientProxy_ =
303         std::make_shared<IpcClientProxy>(std::make_shared<IpcClientManager>());
304 #endif
305     std::mutex subscribIdLock;
306     std::map<uint64_t, uint16_t> subscribIdMap_;
307 };
308 } // namespace DistributedHardware
309 } // namespace OHOS
310 #endif // OHOS_DEVICE_MANAGER_IMPL_H
311