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 #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 "usb_device_id.h"
24
25 namespace OHOS {
26 namespace EDM {
InvokeSendRequestGetEnterpriseInfo(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)27 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetEnterpriseInfo(uint32_t code, MessageParcel &data,
28 MessageParcel &reply, MessageOption &option)
29 {
30 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetEnterpriseInfo code :" << code;
31 EntInfo entInfo;
32 code_ = code;
33 reply.WriteInt32(ERR_OK);
34 entInfo.Marshalling(reply);
35 return 0;
36 }
37
InvokeSendRequestEnableAdmin(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)38 int EnterpriseDeviceMgrStubMock::InvokeSendRequestEnableAdmin(uint32_t code, MessageParcel &data, MessageParcel &reply,
39 MessageOption &option)
40 {
41 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestEnableAdmin code :" << code;
42 code_ = code;
43 reply.WriteInt32(ERR_OK);
44 std::vector<std::string> writeArray{"com.edm.test.demo"};
45 reply.WriteInt32(writeArray.size());
46 reply.WriteStringVector(writeArray);
47 return 0;
48 }
49
InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)50 int EnterpriseDeviceMgrStubMock::InvokeSendRequestMapEnableAdminTwoSuc(uint32_t code, MessageParcel &data,
51 MessageParcel &reply, MessageOption &option)
52 {
53 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestMapEnableAdminTwoSuc code :" << code;
54 code_ = code;
55 reply.WriteInt32(ERR_OK);
56 std::vector<std::string> writeArray{"com.edm.test.demo"};
57 reply.WriteStringVector(writeArray);
58
59 std::vector<std::string> writeArray2{"set date time policy"};
60 reply.WriteStringVector(writeArray2);
61 return 0;
62 }
63
InvokeSendRequestSetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)64 int EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
65 MessageOption &option)
66 {
67 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
68 code_ = code;
69 reply.WriteInt32(ERR_OK);
70 return 0;
71 }
72
InvokeSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)73 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
74 MessageOption &option)
75 {
76 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
77 code_ = code;
78 reply.WriteInt32(ERR_OK);
79 reply.WriteString(RETURN_STRING);
80 return 0;
81 }
82
InvokeBoolSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)83 int EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy(uint32_t code, MessageParcel &data,
84 MessageParcel &reply, MessageOption &option)
85 {
86 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
87 code_ = code;
88 reply.WriteInt32(ERR_OK);
89 reply.WriteBool(true);
90 return 0;
91 }
92
InvokeBoolSendRequestGetFirewallRule(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)93 int EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetFirewallRule(uint32_t code, MessageParcel &data,
94 MessageParcel &reply, MessageOption &option)
95 {
96 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeBoolSendRequestGetFirewallRule code :" << code;
97 code_ = code;
98 reply.WriteInt32(ERR_OK);
99 reply.WriteInt32(1);
100 IPTABLES::DomainFilterRule rule{IPTABLES::Action::INVALID, "321", "www.example.com"};
101 IPTABLES::DomainFilterRuleParcel ruleParcel{rule};
102 ruleParcel.Marshalling(reply);
103 return 0;
104 }
105
InvokeSendRequestGetDomainFilterRules(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)106 int EnterpriseDeviceMgrStubMock::InvokeSendRequestGetDomainFilterRules(uint32_t code, MessageParcel &data,
107 MessageParcel &reply, MessageOption &option)
108 {
109 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetDomainFilterRules code :" << code;
110 code_ = code;
111 reply.WriteInt32(ERR_OK);
112 reply.WriteInt32(1);
113 IPTABLES::FirewallRule rule{IPTABLES::Direction::INVALID, IPTABLES::Action::INVALID, IPTABLES::Protocol::INVALID,
114 "", "", "", "", ""};
115 IPTABLES::FirewallRuleParcel ruleParcel{rule};
116 ruleParcel.Marshalling(reply);
117 return 0;
118 }
119
InvokeIntSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)120 int EnterpriseDeviceMgrStubMock::InvokeIntSendRequestGetPolicy(uint32_t code, MessageParcel &data, MessageParcel &reply,
121 MessageOption &option)
122 {
123 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeIntSendRequestGetPolicy code :" << code;
124 code_ = code;
125 reply.WriteInt32(ERR_OK);
126 reply.WriteInt32(0);
127 return 0;
128 }
129
InvokeArrayStringSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)130 int EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy(uint32_t code, MessageParcel &data,
131 MessageParcel &reply, MessageOption &option)
132 {
133 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
134 code_ = code;
135 reply.WriteInt32(ERR_OK);
136 reply.WriteInt32(1);
137 reply.WriteStringVector(std::vector<std::string>{RETURN_STRING});
138 return 0;
139 }
140
InvokeArrayElementSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)141 int EnterpriseDeviceMgrStubMock::InvokeArrayElementSendRequestGetPolicy(uint32_t code, MessageParcel &data,
142 MessageParcel &reply, MessageOption &option)
143 {
144 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
145 code_ = code;
146 reply.WriteInt32(ERR_OK);
147 reply.WriteStringVector(std::vector<std::string>{ELEMENT_STRING});
148 return 0;
149 }
150
InvokeSendRequestParamError(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)151 int EnterpriseDeviceMgrStubMock::InvokeSendRequestParamError(uint32_t code, MessageParcel &data, MessageParcel &reply,
152 MessageOption &option)
153 {
154 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeSendRequestGetPolicy code :" << code;
155 code_ = code;
156 reply.WriteInt32(EdmReturnErrCode::PARAM_ERROR);
157 reply.WriteString(RETURN_STRING);
158 return 0;
159 }
160
InvokeHttpProxySendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)161 int EnterpriseDeviceMgrStubMock::InvokeHttpProxySendRequestGetPolicy(uint32_t code, MessageParcel &data,
162 MessageParcel &reply, MessageOption &option)
163 {
164 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeHttpProxySendRequestGetPolicy code :" << code;
165 code_ = code;
166 OHOS::NetManagerStandard::HttpProxy httpProxy;
167 reply.WriteInt32(ERR_OK);
168 httpProxy.Marshalling(reply);
169 return ERR_OK;
170 }
171
InvokeBluetoothProxySendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)172 int EnterpriseDeviceMgrStubMock::InvokeBluetoothProxySendRequestGetPolicy(uint32_t code, MessageParcel &data,
173 MessageParcel &reply, MessageOption &option)
174 {
175 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeBluetoothProxySendRequestGetPolicy code :" << code;
176 EntInfo entInfo;
177 code_ = code;
178 reply.WriteInt32(ERR_OK);
179 reply.WriteString(RETURN_STRING);
180 reply.WriteInt32(1);
181 reply.WriteInt32(1);
182 return 0;
183 }
184
InvokeAccountProxySendRequestAddOsAccount(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)185 int EnterpriseDeviceMgrStubMock::InvokeAccountProxySendRequestAddOsAccount(uint32_t code, MessageParcel &data,
186 MessageParcel &reply, MessageOption &option)
187 {
188 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeOsAccountProxySendRequestGetPolicy code :" << code;
189 OHOS::AccountSA::OsAccountInfo accountInfo;
190 code_ = code;
191 reply.WriteInt32(ERR_OK);
192 accountInfo.SetLocalName(RETURN_STRING);
193 accountInfo.Marshalling(reply);
194 reply.WriteString(RETURN_STRING);
195 reply.WriteString(RETURN_STRING);
196 return 0;
197 }
198
InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)199 int EnterpriseDeviceMgrStubMock::InvokeAllowedUsbDevicesSendRequestGetPolicy(uint32_t code, MessageParcel &data,
200 MessageParcel &reply, MessageOption &option)
201 {
202 GTEST_LOG_(INFO) << "mock EnterpriseDeviceMgrStubMock InvokeAllowedUsbDevicesSendRequestGetPolicy code :" << code;
203 code_ = code;
204 reply.WriteInt32(ERR_OK);
205 std::vector<UsbDeviceId> usbDeviceIds;
206 UsbDeviceId id1;
207 int32_t testVid = 1;
208 int32_t testPid = 9;
209 id1.SetVendorId(testVid);
210 id1.SetProductId(testPid);
211 usbDeviceIds.push_back(id1);
212 reply.WriteInt32(usbDeviceIds.size());
213 std::for_each(usbDeviceIds.begin(), usbDeviceIds.end(), [&](const auto usbDeviceId) {
214 usbDeviceId.Marshalling(reply);
215 });
216 return 0;
217 }
218 } // namespace EDM
219 } // namespace OHOS
220