• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "domain_filter_rule.h"
19 #include "firewall_rule.h"
20 #include "http_proxy.h"
21 #include "iptables_utils.h"
22 #include "os_account_info.h"
23 #include "update_policy_utils.h"
24 #include "usb_device_id.h"
25 
26 namespace OHOS {
27 namespace EDM {
28 const uint32_t APPID_MAX_SIZE = 200;
InvokeSendRequestGetEnterpriseInfo(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)29 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetEnterpriseInfo(uint32_t code, MessageParcel &data,
30     MessageParcel &reply, MessageOption &option)
31 {
32     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetEnterpriseInfo code :" << code;
33     EntInfo entInfo;
34     code_ = code;
35     reply.WriteInt32(ERR_OK);
36     entInfo.Marshalling(reply);
37     return 0;
38 }
39 
InvokeSendRequestEnableAdmin(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)40 int EnterpriseDeviceMgrStubMock::InvokeSendRequestEnableAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply,
41     MessageOption &option)
42 {
43     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestEnableAdmin code :" << code;
44     code_ = code;
45     reply.WriteInt32(ERR_OK);
46     std::vector<std::string> writeArray{"com.edm.test.demo"};
47     reply.WriteInt32(writeArray.size());
48     reply.WriteStringVector(writeArray);
49     return 0;
50 }
51 
InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)52 int EnterpriseDeviceMgrStubMock::InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code, MessageParcel &data,
53     MessageParcel &reply, MessageOption &option)
54 {
55     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestMapEnableAdminTwoSuc code :" << code;
56     code_ = code;
57     reply.WriteInt32(ERR_OK);
58     std::vector<std::string> writeArray{"com.edm.test.demo"};
59     reply.WriteStringVector(writeArray);
60 
61     std::vector<std::string> writeArray2{"set date time policy"};
62     reply.WriteStringVector(writeArray2);
63     return 0;
64 }
65 
InvokeSendRequestSetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)66 int EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
67     MessageOption &option)
68 {
69     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
70     code_ = code;
71     reply.WriteInt32(ERR_OK);
72     return 0;
73 }
74 
InvokeSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)75 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
76     MessageOption &option)
77 {
78     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
79     code_ = code;
80     reply.WriteInt32(ERR_OK);
81     reply.WriteString(RETURN_STRING);
82     return 0;
83 }
84 
InvokeSendRequestGetPolicyForWriteFileToStream(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)85 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyForWriteFileToStream(uint32_t code, MessageParcel &data,
86     MessageParcel &reply, MessageOption &option)
87 {
88     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicyForWriteFileToStream :" << code;
89     code_ = code;
90     reply.WriteInt32(ERR_OK);
91     reply.WriteFileDescriptor(1);
92     return 0;
93 }
94 
InvokeSendRequestSetPolicyInstallFail(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)95 int EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicyInstallFail(uint32_t code, MessageParcel &data,
96     MessageParcel &reply, MessageOption &option)
97 {
98     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestSetPolicyInstallFail code :" << code;
99     code_ = code;
100     reply.WriteInt32(EdmReturnErrCode::APPLICATION_INSTALL_FAILED);
101     return 0;
102 }
103 
InvokeBoolSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)104 int EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy(uint32_t code, MessageParcel &data,
105     MessageParcel &reply, MessageOption &option)
106 {
107     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
108     code_ = code;
109     reply.WriteInt32(ERR_OK);
110     reply.WriteBool(true);
111     return 0;
112 }
113 
InvokeBoolSendRequestGetFirewallRule(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)114 int EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetFirewallRule(uint32_t code, MessageParcel &data,
115     MessageParcel &reply, MessageOption &option)
116 {
117     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeBoolSendRequestGetFirewallRule code :" << code;
118     code_ = code;
119     reply.WriteInt32(ERR_OK);
120     reply.WriteInt32(1);
121     IPTABLES::DomainFilterRule rule{IPTABLES::Action::INVALID, "321", "www.example.com"};
122     IPTABLES::DomainFilterRuleParcel ruleParcel{rule};
123     ruleParcel.Marshalling(reply);
124     return 0;
125 }
126 
InvokeSendRequestGetDomainFilterRules(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)127 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetDomainFilterRules(uint32_t code, MessageParcel &data,
128     MessageParcel &reply, MessageOption &option)
129 {
130     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetDomainFilterRules code :" << code;
131     code_ = code;
132     reply.WriteInt32(ERR_OK);
133     reply.WriteInt32(1);
134     IPTABLES::FirewallRule rule{IPTABLES::Direction::INVALID, IPTABLES::Action::INVALID, IPTABLES::Protocol::INVALID,
135         "", "", "", "", ""};
136     IPTABLES::FirewallRuleParcel ruleParcel{rule};
137     ruleParcel.Marshalling(reply);
138     return 0;
139 }
140 
InvokeIntSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)141 int EnterpriseDeviceMgrStubMock::InvokeIntSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
142     MessageOption &option)
143 {
144     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeIntSendRequestGetPolicy code :" << code;
145     code_ = code;
146     reply.WriteInt32(ERR_OK);
147     reply.WriteInt32(0);
148     return 0;
149 }
150 
InvokeArrayStringSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)151 int EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy(uint32_t code, MessageParcel &data,
152     MessageParcel &reply, MessageOption &option)
153 {
154     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
155     code_ = code;
156     reply.WriteInt32(ERR_OK);
157     reply.WriteInt32(1);
158     reply.WriteStringVector(std::vector<std::string>{RETURN_STRING});
159     return 0;
160 }
161 
InvokeSendRequestGetErrPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)162 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetErrPolicy(uint32_t code, MessageParcel &data,
163     MessageParcel &reply, MessageOption &option)
164 {
165     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
166     code_ = code;
167     reply.WriteInt32(EdmReturnErrCode::SYSTEM_ABNORMALLY);
168     return 0;
169 }
170 
InvokeSendRequestGetPolicyExceedsMax(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)171 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyExceedsMax(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.WriteInt32(APPID_MAX_SIZE + 1);
178     reply.WriteStringVector(std::vector<std::string>{RETURN_STRING});
179     return 0;
180 }
181 
InvokeArrayElementSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)182 int EnterpriseDeviceMgrStubMock::InvokeArrayElementSendRequestGetPolicy(uint32_t code, MessageParcel &data,
183     MessageParcel &reply, MessageOption &option)
184 {
185     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
186     code_ = code;
187     reply.WriteInt32(ERR_OK);
188     reply.WriteStringVector(std::vector<std::string>{ELEMENT_STRING});
189     return 0;
190 }
191 
InvokeSendRequestParamError(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)192 int EnterpriseDeviceMgrStubMock::InvokeSendRequestParamError(uint32_t code, MessageParcel &data, MessageParcel &reply,
193     MessageOption &option)
194 {
195     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
196     code_ = code;
197     reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR);
198     reply.WriteString(RETURN_STRING);
199     return 0;
200 }
201 
InvokeHttpProxySendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)202 int EnterpriseDeviceMgrStubMock::InvokeHttpProxySendRequestGetPolicy(uint32_t code, MessageParcel &data,
203     MessageParcel &reply, MessageOption &option)
204 {
205     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeHttpProxySendRequestGetPolicy code :" << code;
206     code_ = code;
207     OHOS::NetManagerStandard::HttpProxy httpProxy;
208     reply.WriteInt32(ERR_OK);
209     httpProxy.Marshalling(reply);
210     return ERR_OK;
211 }
212 
InvokeBluetoothProxySendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)213 int EnterpriseDeviceMgrStubMock::InvokeBluetoothProxySendRequestGetPolicy(uint32_t code, MessageParcel &data,
214     MessageParcel &reply, MessageOption &option)
215 {
216     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeBluetoothProxySendRequestGetPolicy code :" << code;
217     EntInfo entInfo;
218     code_ = code;
219     reply.WriteInt32(ERR_OK);
220     reply.WriteString(RETURN_STRING);
221     reply.WriteInt32(1);
222     reply.WriteInt32(1);
223     return 0;
224 }
225 
InvokeAccountProxySendRequestAddOsAccount(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)226 int EnterpriseDeviceMgrStubMock::InvokeAccountProxySendRequestAddOsAccount(uint32_t code, MessageParcel &data,
227     MessageParcel &reply, MessageOption &option)
228 {
229     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeOsAccountProxySendRequestGetPolicy code :" << code;
230     OHOS::AccountSA::OsAccountInfo accountInfo;
231     code_ = code;
232     reply.WriteInt32(ERR_OK);
233     accountInfo.SetLocalName(RETURN_STRING);
234     accountInfo.Marshalling(reply);
235     reply.WriteString(RETURN_STRING);
236     reply.WriteString(RETURN_STRING);
237     return 0;
238 }
239 
InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)240 int EnterpriseDeviceMgrStubMock::InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data,
241     MessageParcel &reply, MessageOption &option)
242 {
243     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeAllowedUsbDevicesSendRequestGetPolicy code :" << code;
244     code_ = code;
245     reply.WriteInt32(ERR_OK);
246     std::vector<UsbDeviceId> usbDeviceIds;
247     UsbDeviceId id1;
248     int32_t testVid = 1;
249     int32_t testPid = 9;
250     id1.SetVendorId(testVid);
251     id1.SetProductId(testPid);
252     usbDeviceIds.push_back(id1);
253     reply.WriteInt32(usbDeviceIds.size());
254     std::for_each(usbDeviceIds.begin(), usbDeviceIds.end(), [&](const auto usbDeviceId) {
255         usbDeviceId.Marshalling(reply);
256     });
257     return 0;
258 }
259 
InvokeSendRequestGetSuperAdmin(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)260 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetSuperAdmin(uint32_t code, MessageParcel &data,
261     MessageParcel &reply, MessageOption &option)
262 {
263     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetSuperAdmin code :" << code;
264     code_ = code;
265     reply.WriteInt32(ERR_OK);
266     reply.WriteString(RETURN_STRING);
267     reply.WriteString(RETURN_STRING);
268     return 0;
269 }
270 
InvokeSendRequestGetOTAUpdatePolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)271 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetOTAUpdatePolicy(uint32_t code, MessageParcel &data,
272     MessageParcel &reply, MessageOption &option)
273 {
274     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetOTAUpdatePolicy code :" << code;
275     code_ = code;
276     reply.WriteInt32(ERR_OK);
277     UpdatePolicy updatePolicy;
278     updatePolicy.type = UpdatePolicyType::PROHIBIT;
279     updatePolicy.version = UPGRADE_VERSION;
280     UpdatePolicyUtils::WriteUpdatePolicy(reply, updatePolicy);
281     return 0;
282 }
283 
InvokeSendRequestGetUpgradeResult(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)284 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetUpgradeResult(uint32_t code, MessageParcel &data,
285     MessageParcel &reply, MessageOption &option)
286 {
287     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetOTAUpdatePolicy code :" << code;
288     code_ = code;
289     reply.WriteInt32(ERR_OK);
290     UpgradeResult upgradeResult;
291     upgradeResult.status = UpgradeStatus::UPGRADE_FAILURE;
292     upgradeResult.version = UPGRADE_VERSION;
293     upgradeResult.errorCode = UPGRADE_FAILED_CODE;
294     upgradeResult.errorMessage = UPGRADE_FAILED_MESSAGE;
295     UpdatePolicyUtils::WriteUpgradeResult(reply, upgradeResult);
296     return 0;
297 }
298 
InvokeSendRequestGetPasswordPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)299 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPasswordPolicy(uint32_t code, MessageParcel &data,
300     MessageParcel &reply, MessageOption &option)
301 {
302     GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPasswordPolicy code :" << code;
303     code_ = code;
304     reply.WriteInt32(ERR_OK);
305     reply.WriteString("test_complexityReg");
306     reply.WriteInt64(1);
307     reply.WriteString("test_additionalDescription");
308     return 0;
309 }
310 } // namespace EDM
311 } // namespace OHOS
312