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 #include "enterprise_device_mgr_stub_mock.h"
17
18 #include <fcntl.h>
19 #include "domain_filter_rule.h"
20 #include "edm_bundle_info.h"
21 #include "firewall_rule.h"
22 #include "http_proxy.h"
23 #include "iptables_utils.h"
24 #include "os_account_info.h"
25 #include "update_policy_utils.h"
26 #include "usb_device_id.h"
27 #include "usb_interface_type.h"
28 #include "wifi_id.h"
29
30 namespace OHOS {
31 namespace EDM {
32 const uint32_t APPID_MAX_SIZE = 200;
33 const int32_t BASE_CLASS = 3;
34 const int32_t SUB_CLASS = 1;
35 const int32_t PROTOCOL = 2;
36 const std::string TEST_TARGET_PATH = "/data/service/el1/public/edm/test.txt";
37
38
InvokeGetEnterpriseInfo(const AppExecFwk::ElementName & admin,EntInfo & entInfo)39 int EnterpriseDeviceMgrStubMock::InvokeGetEnterpriseInfo(const AppExecFwk::ElementName &admin, EntInfo &entInfo)
40 {
41 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeGetEnterpriseInfo";
42 entInfo.enterpriseName = "test";
43 entInfo.description = "this is test";
44 return ERR_OK;
45 }
46
InvokeGetEnterpriseInfoFail(const AppExecFwk::ElementName & admin,EntInfo & entInfo)47 int EnterpriseDeviceMgrStubMock::InvokeGetEnterpriseInfoFail(const AppExecFwk::ElementName &admin, EntInfo &entInfo)
48 {
49 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeGetEnterpriseInfoFail";
50 entInfo.enterpriseName = "";
51 entInfo.description = "";
52 return ERR_OK;
53 }
54
InvokeIsAdminEnabledFail(const AppExecFwk::ElementName & admin,int32_t userId,bool & isEnabled)55 int EnterpriseDeviceMgrStubMock::InvokeIsAdminEnabledFail(
56 const AppExecFwk::ElementName &admin, int32_t userId, bool &isEnabled)
57 {
58 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeIsAdminEnabled";
59 isEnabled = false;
60 return ERR_OK;
61 }
62
InvokeIsSuperAdminFail(const std::string & bundleName,bool & isSuper)63 int EnterpriseDeviceMgrStubMock::InvokeIsSuperAdminFail(const std::string &bundleName, bool &isSuper)
64 {
65 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeIsSuperAdminFail";
66 isSuper = false;
67 return ERR_OK;
68 }
69
InvokeIsByodAdminFail(const AppExecFwk::ElementName & admin,bool & isByod)70 int EnterpriseDeviceMgrStubMock::InvokeIsByodAdminFail(const AppExecFwk::ElementName &admin, bool &isByod)
71 {
72 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeIsByodAdminFail";
73 isByod = false;
74 return ERR_OK;
75 }
76
InvokeGetSuperAdmin(std::string & bundleName,std::string & abilityName)77 int EnterpriseDeviceMgrStubMock::InvokeGetSuperAdmin(std::string &bundleName, std::string &abilityName)
78 {
79 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeGetSuperAdmin";
80 bundleName = RETURN_STRING;
81 abilityName = RETURN_STRING;
82 return ERR_OK;
83 }
84
InvokeGetAdmins(std::vector<std::shared_ptr<AAFwk::Want>> & wants)85 int EnterpriseDeviceMgrStubMock::InvokeGetAdmins(std::vector<std::shared_ptr<AAFwk::Want>> &wants)
86 {
87 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeGetAdmins";
88 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
89 std::string bundleName = "com.edm.test.demo";
90 std::string abilityName = "test.ability";
91 want->SetParam("bundleName", bundleName);
92 want->SetParam("abilityName", abilityName);
93 want->SetParam("adminType", static_cast<int32_t>(AdminType::BYOD));
94 wants.push_back(want);
95 return ERR_OK;
96 }
97
InvokeGetEnabledAdmin(AdminType type,std::vector<std::string> & enabledAdminList)98 int EnterpriseDeviceMgrStubMock::InvokeGetEnabledAdmin(AdminType type, std::vector<std::string> &enabledAdminList)
99 {
100 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeGetEnabledAdmin";
101 std::string enabledAdmin = "com.edm.test.demo";
102 enabledAdminList.push_back(enabledAdmin);
103 return 0;
104 }
105
InvokeSendRequestEnableAdmin(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)106 int EnterpriseDeviceMgrStubMock::InvokeSendRequestEnableAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply,
107 MessageOption &option)
108 {
109 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestEnableAdmin code :" << code;
110 code_ = code;
111 reply.WriteInt32(ERR_OK);
112 std::vector<std::string> writeArray{"com.edm.test.demo"};
113 reply.WriteInt32(writeArray.size());
114 reply.WriteStringVector(writeArray);
115 return 0;
116 }
117
InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)118 int EnterpriseDeviceMgrStubMock::InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code, MessageParcel &data,
119 MessageParcel &reply, MessageOption &option)
120 {
121 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestMapEnableAdminTwoSuc code :" << code;
122 code_ = code;
123 reply.WriteInt32(ERR_OK);
124 std::vector<std::string> writeArray{"com.edm.test.demo"};
125 reply.WriteStringVector(writeArray);
126
127 std::vector<std::string> writeArray2{"set date time policy"};
128 reply.WriteStringVector(writeArray2);
129 return 0;
130 }
131
InvokeSendRequestSetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)132 int EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
133 MessageOption &option)
134 {
135 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
136 code_ = code;
137 reply.WriteInt32(ERR_OK);
138 return 0;
139 }
140
InvokeSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)141 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
142 MessageOption &option)
143 {
144 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
145 code_ = code;
146 reply.WriteInt32(ERR_OK);
147 reply.WriteString(RETURN_STRING);
148 return 0;
149 }
150
InvokeSendRequestGetPolicyForWriteFileToStream(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)151 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyForWriteFileToStream(uint32_t code, MessageParcel &data,
152 MessageParcel &reply, MessageOption &option)
153 {
154 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicyForWriteFileToStream :" << code;
155 int32_t fd = open(TEST_TARGET_PATH.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
156 code_ = code;
157 reply.WriteInt32(ERR_OK);
158 reply.WriteFileDescriptor(fd);
159 return 0;
160 }
161
InvokeSendRequestSetPolicyInstallFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)162 int EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicyInstallFail(uint32_t code, MessageParcel &data,
163 MessageParcel &reply, MessageOption &option)
164 {
165 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestSetPolicyInstallFail code :" << code;
166 code_ = code;
167 reply.WriteInt32(EdmReturnErrCode::APPLICATION_INSTALL_FAILED);
168 return 0;
169 }
170
InvokeBoolSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)171 int EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy(uint32_t code, MessageParcel &data,
172 MessageParcel &reply, MessageOption &option)
173 {
174 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
175 code_ = code;
176 reply.WriteInt32(ERR_OK);
177 reply.WriteBool(true);
178 return 0;
179 }
180
InvokeBoolSendRequestGetFirewallRule(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)181 int EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetFirewallRule(uint32_t code, MessageParcel &data,
182 MessageParcel &reply, MessageOption &option)
183 {
184 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeBoolSendRequestGetFirewallRule code :" << code;
185 code_ = code;
186 reply.WriteInt32(ERR_OK);
187 reply.WriteInt32(1);
188 IPTABLES::DomainFilterRule rule{IPTABLES::Action::INVALID, "321", "www.example.com", IPTABLES::Direction::OUTPUT};
189 IPTABLES::DomainFilterRuleParcel ruleParcel{rule};
190 ruleParcel.Marshalling(reply);
191 return 0;
192 }
193
InvokeSendRequestGetDomainFilterRules(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)194 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetDomainFilterRules(uint32_t code, MessageParcel &data,
195 MessageParcel &reply, MessageOption &option)
196 {
197 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetDomainFilterRules code :" << code;
198 code_ = code;
199 reply.WriteInt32(ERR_OK);
200 reply.WriteInt32(1);
201 IPTABLES::FirewallRule rule{IPTABLES::Direction::INVALID, IPTABLES::Action::INVALID, IPTABLES::Protocol::INVALID,
202 "", "", "", "", ""};
203 IPTABLES::FirewallRuleParcel ruleParcel{rule};
204 ruleParcel.Marshalling(reply);
205 return 0;
206 }
207
InvokeIntSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)208 int EnterpriseDeviceMgrStubMock::InvokeIntSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
209 MessageOption &option)
210 {
211 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeIntSendRequestGetPolicy code :" << code;
212 code_ = code;
213 reply.WriteInt32(ERR_OK);
214 reply.WriteInt32(0);
215 return 0;
216 }
217
InvokeArrayStringSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)218 int EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy(uint32_t code, MessageParcel &data,
219 MessageParcel &reply, MessageOption &option)
220 {
221 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
222 code_ = code;
223 reply.WriteInt32(ERR_OK);
224 reply.WriteStringVector(std::vector<std::string>{RETURN_STRING});
225 return 0;
226 }
227
InvokeSendRequestGetErrPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)228 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetErrPolicy(uint32_t code, MessageParcel &data,
229 MessageParcel &reply, MessageOption &option)
230 {
231 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
232 code_ = code;
233 reply.WriteInt32(EdmReturnErrCode::SYSTEM_ABNORMALLY);
234 return 0;
235 }
236
InvokeSendRequestGetPolicyExceedsMax(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)237 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyExceedsMax(uint32_t code, MessageParcel &data,
238 MessageParcel &reply, MessageOption &option)
239 {
240 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
241 code_ = code;
242 reply.WriteInt32(ERR_OK);
243 reply.WriteInt32(APPID_MAX_SIZE + 1);
244 reply.WriteStringVector(std::vector<std::string>{RETURN_STRING});
245 return 0;
246 }
247
InvokeArrayElementSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)248 int EnterpriseDeviceMgrStubMock::InvokeArrayElementSendRequestGetPolicy(uint32_t code, MessageParcel &data,
249 MessageParcel &reply, MessageOption &option)
250 {
251 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
252 code_ = code;
253 reply.WriteInt32(ERR_OK);
254 reply.WriteStringVector(std::vector<std::string>{ELEMENT_STRING});
255 return 0;
256 }
257
InvokeSendRequestParamError(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)258 int EnterpriseDeviceMgrStubMock::InvokeSendRequestParamError(uint32_t code, MessageParcel &data, MessageParcel &reply,
259 MessageOption &option)
260 {
261 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
262 code_ = code;
263 reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR);
264 reply.WriteString(RETURN_STRING);
265 return 0;
266 }
267
InvokeHttpProxySendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)268 int EnterpriseDeviceMgrStubMock::InvokeHttpProxySendRequestGetPolicy(uint32_t code, MessageParcel &data,
269 MessageParcel &reply, MessageOption &option)
270 {
271 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeHttpProxySendRequestGetPolicy code :" << code;
272 code_ = code;
273 OHOS::NetManagerStandard::HttpProxy httpProxy;
274 reply.WriteInt32(ERR_OK);
275 httpProxy.Marshalling(reply);
276 return ERR_OK;
277 }
278
InvokeBluetoothProxySendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)279 int EnterpriseDeviceMgrStubMock::InvokeBluetoothProxySendRequestGetPolicy(uint32_t code, MessageParcel &data,
280 MessageParcel &reply, MessageOption &option)
281 {
282 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeBluetoothProxySendRequestGetPolicy code :" << code;
283 EntInfo entInfo;
284 code_ = code;
285 reply.WriteInt32(ERR_OK);
286 reply.WriteString(RETURN_STRING);
287 reply.WriteInt32(1);
288 reply.WriteInt32(1);
289 return 0;
290 }
291
InvokeAccountProxySendRequestAddOsAccount(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)292 int EnterpriseDeviceMgrStubMock::InvokeAccountProxySendRequestAddOsAccount(uint32_t code, MessageParcel &data,
293 MessageParcel &reply, MessageOption &option)
294 {
295 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeOsAccountProxySendRequestGetPolicy code :" << code;
296 OHOS::AccountSA::OsAccountInfo accountInfo;
297 code_ = code;
298 reply.WriteInt32(ERR_OK);
299 accountInfo.SetLocalName(RETURN_STRING);
300 accountInfo.Marshalling(reply);
301 reply.WriteString(RETURN_STRING);
302 reply.WriteString(RETURN_STRING);
303 return 0;
304 }
305
InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)306 int EnterpriseDeviceMgrStubMock::InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data,
307 MessageParcel &reply, MessageOption &option)
308 {
309 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeAllowedUsbDevicesSendRequestGetPolicy code :" << code;
310 code_ = code;
311 reply.WriteInt32(ERR_OK);
312 std::vector<UsbDeviceId> usbDeviceIds;
313 UsbDeviceId id1;
314 int32_t testVid = 1;
315 int32_t testPid = 9;
316 id1.SetVendorId(testVid);
317 id1.SetProductId(testPid);
318 usbDeviceIds.push_back(id1);
319 reply.WriteInt32(usbDeviceIds.size());
320 std::for_each(usbDeviceIds.begin(), usbDeviceIds.end(), [&](const auto usbDeviceId) {
321 usbDeviceId.Marshalling(reply);
322 });
323 return 0;
324 }
325
InvokeDisallowedUsbDevicesSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)326 int EnterpriseDeviceMgrStubMock::InvokeDisallowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data,
327 MessageParcel &reply, MessageOption &option)
328 {
329 GTEST_LOG_(INFO) <<
330 "mock EnterpriseDeviceMgrStubMock InvokeDisallowedUsbDevicesSendRequestGetPolicy code :" << code;
331 code_ = code;
332 reply.WriteInt32(ERR_OK);
333 std::vector<USB::UsbDeviceType> usbDeviceTypes;
334 USB::UsbDeviceType type;
335 type.baseClass = BASE_CLASS;
336 type.subClass = SUB_CLASS;
337 type.protocol = PROTOCOL;
338 type.isDeviceType = false;
339 usbDeviceTypes.push_back(type);
340 reply.WriteInt32(usbDeviceTypes.size());
341 std::for_each(usbDeviceTypes.begin(), usbDeviceTypes.end(), [&](const auto usbDeviceType) {
342 usbDeviceType.Marshalling(reply);
343 });
344 return 0;
345 }
346
InvokeArrayIntSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)347 int EnterpriseDeviceMgrStubMock::InvokeArrayIntSendRequestGetPolicy(uint32_t code, MessageParcel &data,
348 MessageParcel &reply, MessageOption &option)
349 {
350 GTEST_LOG_(INFO) << "mock InvokeArrayIntSendRequestGetPolicy code :" << code;
351 code_ = code;
352 reply.WriteInt32(ERR_OK);
353 std::vector<int32_t> inputData;
354 int32_t policyOne = 1;
355 int32_t policyTwo = 2;
356 inputData.push_back(policyOne);
357 inputData.push_back(policyTwo);
358 reply.WriteInt32Vector(inputData);
359 return 0;
360 }
361
InvokeSendRequestGetSuperAdmin(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)362 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetSuperAdmin(uint32_t code, MessageParcel &data,
363 MessageParcel &reply, MessageOption &option)
364 {
365 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetSuperAdmin code :" << code;
366 code_ = code;
367 reply.WriteInt32(ERR_OK);
368 reply.WriteString(RETURN_STRING);
369 reply.WriteString(RETURN_STRING);
370 return 0;
371 }
372
InvokeSendRequestGetOTAUpdatePolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)373 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetOTAUpdatePolicy(uint32_t code, MessageParcel &data,
374 MessageParcel &reply, MessageOption &option)
375 {
376 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetOTAUpdatePolicy code :" << code;
377 code_ = code;
378 reply.WriteInt32(ERR_OK);
379 UpdatePolicy updatePolicy;
380 updatePolicy.type = UpdatePolicyType::PROHIBIT;
381 updatePolicy.version = UPGRADE_VERSION;
382 UpdatePolicyUtils::WriteUpdatePolicy(reply, updatePolicy);
383 return 0;
384 }
385
InvokeSendRequestGetUpgradeResult(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)386 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetUpgradeResult(uint32_t code, MessageParcel &data,
387 MessageParcel &reply, MessageOption &option)
388 {
389 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetOTAUpdatePolicy code :" << code;
390 code_ = code;
391 reply.WriteInt32(ERR_OK);
392 UpgradeResult upgradeResult;
393 upgradeResult.status = UpgradeStatus::UPGRADE_FAILURE;
394 upgradeResult.version = UPGRADE_VERSION;
395 upgradeResult.errorCode = UPGRADE_FAILED_CODE;
396 upgradeResult.errorMessage = UPGRADE_FAILED_MESSAGE;
397 UpdatePolicyUtils::WriteUpgradeResult(reply, upgradeResult);
398 return 0;
399 }
400
InvokeSendRequestGetUpdateAuthData(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)401 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetUpdateAuthData(uint32_t code, MessageParcel &data,
402 MessageParcel &reply, MessageOption &option)
403 {
404 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetUpdateAuthData code :" << code;
405 code_ = code;
406 reply.WriteInt32(ERR_OK);
407 reply.WriteString(AUTH_DATA);
408 return 0;
409 }
410
InvokeSendRequestGetPasswordPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)411 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPasswordPolicy(uint32_t code, MessageParcel &data,
412 MessageParcel &reply, MessageOption &option)
413 {
414 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPasswordPolicy code :" << code;
415 code_ = code;
416 reply.WriteInt32(ERR_OK);
417 reply.WriteString("test_complexityReg");
418 reply.WriteInt64(1);
419 reply.WriteString("test_additionalDescription");
420 return 0;
421 }
422
InvokeSendRequestGetManagedBrowserPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)423 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetManagedBrowserPolicy(uint32_t code, MessageParcel &data,
424 MessageParcel &reply, MessageOption &option)
425 {
426 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetManagedBrowserPolicy code :" << code;
427 code_ = code;
428 reply.WriteInt32(ERR_OK);
429 int32_t size = 200;
430 reply.WriteInt32(size);
431 void* rawData = malloc(size);
432 reply.WriteRawData(rawData, size);
433 return 0;
434 }
435
InvokeSendRequestGetAdmins(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)436 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetAdmins(uint32_t code, MessageParcel &data,
437 MessageParcel &reply, MessageOption &option)
438 {
439 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetAdmins code :" << code;
440 code_ = code;
441 reply.WriteInt32(ERR_OK);
442 int32_t size = 1;
443 reply.WriteUint32(size);
444 std::shared_ptr<AAFwk::Want> want = std::make_shared<AAFwk::Want>();
445 std::string bundleName = "com.edm.test.demo";
446 std::string abilityName = "test.ability";
447 want->SetParam("bundleName", bundleName);
448 want->SetParam("abilityName", abilityName);
449 want->SetParam("adminType", static_cast<int32_t>(AdminType::BYOD));
450 reply.WriteParcelable(want.get());
451 return 0;
452 }
453
InvokeSendRequestCheckAndGetAdminProvisionInfo(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)454 int EnterpriseDeviceMgrStubMock::InvokeSendRequestCheckAndGetAdminProvisionInfo(uint32_t code, MessageParcel &data,
455 MessageParcel &reply, MessageOption &option)
456 {
457 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetAdmins code :" << code;
458 code_ = code;
459 reply.WriteInt32(ERR_OK);
460 reply.WriteString("com.edm.test.demo");
461 return 0;
462 }
463
InvokeWifiListSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)464 int EnterpriseDeviceMgrStubMock::InvokeWifiListSendRequestGetPolicy(uint32_t code, MessageParcel &data,
465 MessageParcel &reply, MessageOption &option)
466 {
467 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeWifiListSendRequestGetPolicy code :" << code;
468 code_ = code;
469 reply.WriteInt32(ERR_OK);
470 std::vector<WifiId> wifiIds;
471 WifiId id1;
472 std::string testSsid = "wifi_name";
473 std::string testBssid = "68:77:24:77:A6:D6";
474 id1.SetSsid(testSsid);
475 id1.SetBssid(testBssid);
476 wifiIds.push_back(id1);
477 reply.WriteInt32(wifiIds.size());
478 std::for_each(wifiIds.begin(), wifiIds.end(), [&](const auto wifiId) {
479 wifiId.Marshalling(reply);
480 });
481 return 0;
482 }
483
InvokeSendRequestGetInstalledBundleList(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)484 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetInstalledBundleList(uint32_t code, MessageParcel &data,
485 MessageParcel &reply, MessageOption &option)
486 {
487 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetInstalledBundleList code :" << code;
488 code_ = code;
489 EdmBundleInfo edmBundleInfo;
490 edmBundleInfo.name = "com.edm.test.demo";
491 std::vector<EdmBundleInfo> edmBundleInfos;
492 edmBundleInfos.emplace_back(edmBundleInfo);
493
494 MessageParcel tempParcel;
495 (void)tempParcel.SetMaxCapacity(EdmConstants::MAX_PARCEL_CAPACITY);
496 tempParcel.WriteInt32(edmBundleInfos.size());
497 for (auto &parcelable : edmBundleInfos) {
498 tempParcel.WriteParcelable(&parcelable);
499 }
500 reply.WriteInt32(ERR_OK);
501 size_t dataSize = tempParcel.GetDataSize();
502 reply.WriteInt32(static_cast<int32_t>(dataSize));
503 reply.WriteRawData(reinterpret_cast<uint8_t *>(tempParcel.GetData()), dataSize);
504 return 0;
505 }
506
InvokeSendRequestSizeError(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)507 int EnterpriseDeviceMgrStubMock::InvokeSendRequestSizeError(uint32_t code, MessageParcel &data, MessageParcel &reply,
508 MessageOption &option)
509 {
510 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestSizeError code :" << code;
511 code_ = code;
512 reply.WriteInt32(ERR_OK);
513 reply.WriteInt32(EDM_MAXREQUESTSIZE);
514 return 0;
515 }
516
517 } // namespace EDM
518 } // namespace OHOS
519