• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "device_manager_impl.h"
17 
18 #include "mock_device_manager_impl.h"
19 namespace OHOS {
20 
21 namespace Notification {
22 static std::shared_ptr<DistributedHardware::DeviceStateCallback> deviceManagerCallback = nullptr;
23 static std::shared_ptr<DistributedHardware::DmInitCallback> dmInitCallback = nullptr;
24 static bool g_mockInitDeviceManager = false;
25 static bool g_mockGetTrustedDeviceList = false;
26 static bool g_mockRegisterDevStateCallback = false;
27 static bool g_mockTransDeviceIdToUdid = false;
28 
MockInitDeviceManager(bool mock)29 void DeviceTrigger::MockInitDeviceManager(bool mock)
30 {
31     g_mockInitDeviceManager = mock;
32 }
33 
MockGetTrustedDeviceList(bool mock)34 void DeviceTrigger::MockGetTrustedDeviceList(bool mock)
35 {
36     g_mockGetTrustedDeviceList = mock;
37 }
38 
MockRegisterDevStateCallback(bool mock)39 void DeviceTrigger::MockRegisterDevStateCallback(bool mock)
40 {
41     g_mockRegisterDevStateCallback = mock;
42 }
43 
TriggerOnRemoteDied()44 void DeviceTrigger::TriggerOnRemoteDied()
45 {
46     dmInitCallback->OnRemoteDied();
47 }
48 
MockTransDeviceIdToUdid(bool mock)49 void DeviceTrigger::MockTransDeviceIdToUdid(bool mock)
50 {
51     g_mockTransDeviceIdToUdid = mock;
52 }
53 
TriggerDeviceOnline()54 void DeviceTrigger::TriggerDeviceOnline()
55 {
56     DistributedHardware::DmDeviceInfo remoteDevice;
57     memset_s(&remoteDevice, sizeof(remoteDevice), 0, sizeof(remoteDevice));
58     strcpy_s(remoteDevice.deviceId, sizeof(remoteDevice.deviceId) - 1, "remoteDeviceId");
59     strcpy_s(remoteDevice.networkId, sizeof(remoteDevice.networkId) - 1, "remoteNetWorkId");
60     remoteDevice.deviceTypeId = DistributedHardware::DmDeviceType::DEVICE_TYPE_WATCH;
61     deviceManagerCallback->OnDeviceOnline(remoteDevice);
62 }
63 
TriggerDeviceOffline()64 void DeviceTrigger::TriggerDeviceOffline()
65 {
66     DistributedHardware::DmDeviceInfo remoteDevice;
67     memset_s(&remoteDevice, sizeof(remoteDevice), 0, sizeof(remoteDevice));
68     strcpy_s(remoteDevice.deviceId, sizeof(remoteDevice.deviceId) - 1, "remoteDeviceId");
69     strcpy_s(remoteDevice.networkId, sizeof(remoteDevice.networkId) - 1, "remoteNetWorkId");
70     deviceManagerCallback->OnDeviceOffline(remoteDevice);
71 }
72 
TriggerDeviceChanged()73 void DeviceTrigger::TriggerDeviceChanged()
74 {
75     DistributedHardware::DmDeviceInfo remoteDevice;
76     memset_s(&remoteDevice, sizeof(remoteDevice), 0, sizeof(remoteDevice));
77     strcpy_s(remoteDevice.deviceId, sizeof(remoteDevice.deviceId) - 1, "remoteDeviceId");
78     strcpy_s(remoteDevice.networkId, sizeof(remoteDevice.networkId) - 1, "newRemoteNetWorkId");
79     deviceManagerCallback->OnDeviceChanged(remoteDevice);
80 }
81 
TriggerDeviceReady()82 void DeviceTrigger::TriggerDeviceReady()
83 {
84     DistributedHardware::DmDeviceInfo remoteDevice;
85     deviceManagerCallback->OnDeviceReady(remoteDevice);
86 }
87 }
88 
89 namespace DistributedHardware {
90 
GetInstance()91 DeviceManagerImpl &DeviceManagerImpl::GetInstance()
92 {
93     static DeviceManagerImpl deviceManagerImpl;
94     return deviceManagerImpl;
95 }
96 
InitDeviceManager(const std::string & pkgName,std::shared_ptr<DmInitCallback> callback)97 int32_t DeviceManagerImpl::InitDeviceManager(const std::string &pkgName, std::shared_ptr<DmInitCallback> callback)
98 {
99     if (Notification::g_mockInitDeviceManager) {
100         return -1;
101     }
102     Notification::dmInitCallback = callback;
103     printf("InitDeviceManager pkgName:%s\n", pkgName.c_str());
104     return 0;
105 }
106 
UnInitDeviceManager(const std::string & pkgName)107 int32_t DeviceManagerImpl::UnInitDeviceManager(const std::string &pkgName)
108 {
109     Notification::dmInitCallback = nullptr;
110     printf("UnInitDeviceManager pkgName:%s\n", pkgName.c_str());
111     return 0;
112 }
113 
GetTrustedDeviceList(const std::string & pkgName,const std::string & extra,std::vector<DmDeviceInfo> & deviceList)114 int32_t DeviceManagerImpl::GetTrustedDeviceList(const std::string &pkgName, const std::string &extra,
115                                                 std::vector<DmDeviceInfo> &deviceList)
116 {
117     if (Notification::g_mockGetTrustedDeviceList) {
118         return -1;
119     }
120     DmDeviceInfo remoteDevice;
121     memset_s(&remoteDevice, sizeof(remoteDevice), 0, sizeof(remoteDevice));
122     strcpy_s(remoteDevice.deviceId, sizeof(remoteDevice.deviceId) - 1, "remoteDeviceId");
123     strcpy_s(remoteDevice.deviceName, sizeof(remoteDevice.deviceName) - 1, "remoteDeviceId");
124     remoteDevice.deviceTypeId = DmDeviceType::DEVICE_TYPE_WATCH;
125     deviceList.push_back(remoteDevice);
126     return 0;
127 }
128 
GetTrustedDeviceList(const std::string & pkgName,const std::string & extra,bool isRefresh,std::vector<DmDeviceInfo> & deviceList)129 int32_t DeviceManagerImpl::GetTrustedDeviceList(
130     const std::string &pkgName, const std::string &extra, bool isRefresh, std::vector<DmDeviceInfo> &deviceList)
131 {
132     if (Notification::g_mockGetTrustedDeviceList) {
133         return -1;
134     }
135     DmDeviceInfo remoteDevice;
136     memset_s(&remoteDevice, sizeof(remoteDevice), 0, sizeof(remoteDevice));
137     strcpy_s(remoteDevice.deviceId, sizeof(remoteDevice.deviceId) - 1, "remoteDeviceId");
138     strcpy_s(remoteDevice.deviceName, sizeof(remoteDevice.deviceName) - 1, "remoteDeviceId");
139     remoteDevice.deviceTypeId = DmDeviceType::DEVICE_TYPE_WATCH;
140     deviceList.push_back(remoteDevice);
141     return 0;
142 }
143 
GetLocalDeviceInfo(const std::string & pkgName,DmDeviceInfo & deviceInfo)144 int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &deviceInfo)
145 {
146     memset_s(&deviceInfo, sizeof(deviceInfo), 0, sizeof(deviceInfo));
147     strcpy_s(deviceInfo.deviceId, sizeof(deviceInfo.deviceId) - 1, "localDeviceId");
148     strcpy_s(deviceInfo.deviceName, sizeof(deviceInfo.deviceName) - 1, "localDeviceName");
149     deviceInfo.deviceTypeId = DmDeviceType::DEVICE_TYPE_PHONE;
150     return 0;
151 }
152 
RegisterDevStateCallback(const std::string & pkgName,const std::string & extra,std::shared_ptr<DeviceStateCallback> callback)153 int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, const std::string &extra,
154                                                     std::shared_ptr<DeviceStateCallback> callback)
155 {
156     if (Notification::g_mockRegisterDevStateCallback) {
157         return -1;
158     }
159     Notification::deviceManagerCallback = callback;
160     return 0;
161 }
162 
UnRegisterDevStateCallback(const std::string & pkgName)163 int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName)
164 {
165     Notification::deviceManagerCallback = nullptr;
166     return 0;
167 }
168 
StartDeviceDiscovery(const std::string & pkgName,const DmSubscribeInfo & subscribeInfo,const std::string & extra,std::shared_ptr<DiscoveryCallback> callback)169 int32_t DeviceManagerImpl::StartDeviceDiscovery(const std::string &pkgName, const DmSubscribeInfo &subscribeInfo,
170                                                 const std::string &extra, std::shared_ptr<DiscoveryCallback> callback)
171 {
172     return 0;
173 }
174 
StopDeviceDiscovery(const std::string & pkgName,uint16_t subscribeId)175 int32_t DeviceManagerImpl::StopDeviceDiscovery(const std::string &pkgName, uint16_t subscribeId)
176 {
177     return 0;
178 }
179 
PublishDeviceDiscovery(const std::string & pkgName,const DmPublishInfo & publishInfo,std::shared_ptr<PublishCallback> callback)180 int32_t DeviceManagerImpl::PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo,
181     std::shared_ptr<PublishCallback> callback)
182 {
183     return 0;
184 }
185 
UnPublishDeviceDiscovery(const std::string & pkgName,int32_t publishId)186 int32_t DeviceManagerImpl::UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId)
187 {
188     return 0;
189 }
190 
AuthenticateDevice(const std::string & pkgName,int32_t authType,const DmDeviceInfo & deviceInfo,const std::string & extra,std::shared_ptr<AuthenticateCallback> callback)191 int32_t DeviceManagerImpl::AuthenticateDevice(const std::string &pkgName, int32_t authType,
192                                               const DmDeviceInfo &deviceInfo, const std::string &extra,
193                                               std::shared_ptr<AuthenticateCallback> callback)
194 {
195     return 0;
196 }
197 
UnAuthenticateDevice(const std::string & pkgName,const DmDeviceInfo & deviceInfo)198 int32_t DeviceManagerImpl::UnAuthenticateDevice(const std::string &pkgName, const DmDeviceInfo &deviceInfo)
199 {
200     return 0;
201 }
202 
RegisterDeviceManagerFaCallback(const std::string & pkgName,std::shared_ptr<DeviceManagerUiCallback> callback)203 int32_t DeviceManagerImpl::RegisterDeviceManagerFaCallback(const std::string &pkgName,
204                                                            std::shared_ptr<DeviceManagerUiCallback> callback)
205 {
206     return 0;
207 }
208 
UnRegisterDeviceManagerFaCallback(const std::string & pkgName)209 int32_t DeviceManagerImpl::UnRegisterDeviceManagerFaCallback(const std::string &pkgName)
210 {
211     return 0;
212 }
213 
VerifyAuthentication(const std::string & pkgName,const std::string & authPara,std::shared_ptr<VerifyAuthCallback> callback)214 int32_t DeviceManagerImpl::VerifyAuthentication(const std::string &pkgName, const std::string &authPara,
215                                                 std::shared_ptr<VerifyAuthCallback> callback)
216 {
217     return 0;
218 }
219 
GetFaParam(const std::string & pkgName,DmAuthParam & dmFaParam)220 int32_t DeviceManagerImpl::GetFaParam(const std::string &pkgName, DmAuthParam &dmFaParam)
221 {
222     return 0;
223 }
224 
SetUserOperation(const std::string & pkgName,int32_t action,const std::string & params)225 int32_t DeviceManagerImpl::SetUserOperation(const std::string &pkgName, int32_t action, const std::string &params)
226 {
227     return 0;
228 }
229 
GetUdidByNetworkId(const std::string & pkgName,const std::string & netWorkId,std::string & udid)230 int32_t DeviceManagerImpl::GetUdidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
231                                               std::string &udid)
232 {
233     return 0;
234 }
235 
GetUuidByNetworkId(const std::string & pkgName,const std::string & netWorkId,std::string & udid)236 int32_t DeviceManagerImpl::GetUuidByNetworkId(const std::string &pkgName, const std::string &netWorkId,
237                                               std::string &udid)
238 {
239     if (Notification::g_mockTransDeviceIdToUdid) {
240         return -1;
241     }
242     if (netWorkId == "netWorkId") {
243         udid = "udidNum";
244     }
245     return 0;
246 }
247 
RegisterDevStateCallback(const std::string & pkgName,const std::string & extra)248 int32_t DeviceManagerImpl::RegisterDevStateCallback(const std::string &pkgName, const std::string &extra)
249 {
250     return 0;
251 }
252 
UnRegisterDevStateCallback(const std::string & pkgName,const std::string & extra)253 int32_t DeviceManagerImpl::UnRegisterDevStateCallback(const std::string &pkgName, const std::string &extra)
254 {
255     return 0;
256 }
257 
RequestCredential(const std::string & pkgName,const std::string & reqJsonStr,std::string & returnJsonStr)258 int32_t DeviceManagerImpl::RequestCredential(const std::string &pkgName, const std::string &reqJsonStr,
259     std::string &returnJsonStr)
260 {
261     return 0;
262 }
263 
ImportCredential(const std::string & pkgName,const std::string & credentialInfo)264 int32_t DeviceManagerImpl::ImportCredential(const std::string &pkgName, const std::string &credentialInfo)
265 {
266     return 0;
267 }
268 
DeleteCredential(const std::string & pkgName,const std::string & deleteInfo)269 int32_t DeviceManagerImpl::DeleteCredential(const std::string &pkgName, const std::string &deleteInfo)
270 {
271     return 0;
272 }
273 
RegisterCredentialCallback(const std::string & pkgName,std::shared_ptr<CredentialCallback> callback)274 int32_t DeviceManagerImpl::RegisterCredentialCallback(const std::string &pkgName,
275     std::shared_ptr<CredentialCallback> callback)
276 {
277     return 0;
278 }
279 
UnRegisterCredentialCallback(const std::string & pkgName)280 int32_t DeviceManagerImpl::UnRegisterCredentialCallback(const std::string &pkgName)
281 {
282     return 0;
283 }
284 
NotifyEvent(const std::string & pkgName,const int32_t eventId,const std::string & event)285 int32_t DeviceManagerImpl::NotifyEvent(const std::string &pkgName, const int32_t eventId, const std::string &event)
286 {
287     return 0;
288 }
289 
OnDmServiceDied()290 int32_t DeviceManagerImpl::OnDmServiceDied()
291 {
292     return 0;
293 }
294 } // namespace DistributedHardware
295 } // namespace OHOS
296