1 /*
2 * Copyright (c) 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 <memory>
17
18 #include "networkvpn_service_proxy.h"
19
20 #include "ipc_types.h"
21
22 #include "net_manager_constants.h"
23 #include "net_manager_ext_constants.h"
24 #include "netmgr_ext_log_wrapper.h"
25
26 namespace OHOS {
27 namespace NetManagerStandard {
NetworkVpnServiceProxy(const sptr<IRemoteObject> & impl)28 NetworkVpnServiceProxy::NetworkVpnServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<INetworkVpnService>(impl)
29 {
30 }
31
WriteTokenAndSendRequest(INetworkVpnService::MessageCode code,MessageParcel & data,MessageParcel & reply)32 int32_t NetworkVpnServiceProxy::WriteTokenAndSendRequest(INetworkVpnService::MessageCode code, MessageParcel &data,
33 MessageParcel &reply)
34 {
35 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
36 NETMGR_EXT_LOG_E("write interface token failed");
37 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
38 }
39
40 sptr<IRemoteObject> remote = Remote();
41 if (remote == nullptr) {
42 NETMGR_EXT_LOG_E("remote is nullptr");
43 return NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL;
44 }
45 MessageOption option(MessageOption::TF_SYNC);
46 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
47 }
48
SendRequest(INetworkVpnService::MessageCode code,MessageParcel & data,MessageParcel & reply)49 int32_t NetworkVpnServiceProxy::SendRequest(INetworkVpnService::MessageCode code, MessageParcel &data,
50 MessageParcel &reply)
51 {
52 sptr<IRemoteObject> remote = Remote();
53 if (remote == nullptr) {
54 NETMGR_EXT_LOG_E("remote is nullptr");
55 return NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL;
56 }
57 MessageOption option(MessageOption::TF_SYNC);
58 return remote->SendRequest(static_cast<uint32_t>(code), data, reply, option);
59 }
60
Prepare(bool & isExistVpn,bool & isRun,std::string & pkg)61 int32_t NetworkVpnServiceProxy::Prepare(bool &isExistVpn, bool &isRun, std::string &pkg)
62 {
63 MessageParcel data;
64 MessageParcel reply;
65 int32_t ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_PREPARE, data, reply);
66 if (ERR_NONE != ret) {
67 NETMGR_EXT_LOG_E("Prepare proxy SendRequest failed, error code: [%{public}d]", ret);
68 return ret;
69 }
70
71 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
72 if (!reply.ReadInt32(result)) {
73 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
74 }
75 if (!reply.ReadBool(isExistVpn) || !reply.ReadBool(isRun) || !reply.ReadString(pkg)) {
76 NETMGR_EXT_LOG_E("Prepare proxy read data failed");
77 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
78 }
79 return result;
80 }
81
GetSelfAppName(std::string & selfAppName,std::string & selfBundleName)82 int32_t NetworkVpnServiceProxy::GetSelfAppName(std::string &selfAppName, std::string &selfBundleName)
83 {
84 MessageParcel data;
85 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
86 NETMGR_EXT_LOG_E("write interface token failed");
87 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
88 }
89 MessageParcel reply;
90 auto ret = SendRequest(INetworkVpnService::MessageCode::CMD_GET_SELF_APP_NAME, data, reply);
91 if (ret != ERR_NONE) {
92 NETMGR_EXT_LOG_E("SendRequest failed %{public}d", ret);
93 return ret;
94 }
95 if (!reply.ReadString(selfAppName)) {
96 NETMGR_EXT_LOG_E("IPC ReadString selfAppName failed");
97 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
98 }
99 if (!reply.ReadString(selfBundleName)) {
100 NETMGR_EXT_LOG_E("IPC ReadString selfBundleName failed");
101 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
102 }
103 return ERR_NONE;
104 }
105
SetSelfVpnPid()106 int32_t NetworkVpnServiceProxy::SetSelfVpnPid()
107 {
108 MessageParcel data;
109 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
110 NETMGR_EXT_LOG_E("write interface token failed");
111 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
112 }
113 MessageParcel reply;
114 auto ret = SendRequest(INetworkVpnService::MessageCode::CMD_SET_SELF_VPN_PID, data, reply);
115 if (ret != ERR_NONE) {
116 NETMGR_EXT_LOG_E("SendRequest failed %{public}d", ret);
117 return ret;
118 }
119 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
120 if (!reply.ReadInt32(result)) {
121 NETMGR_EXT_LOG_E("IPC ReadInt32 failed");
122 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
123 }
124 return ERR_NONE;
125 }
126
SetUpVpn(const sptr<VpnConfig> & config,bool isVpnExtCall)127 int32_t NetworkVpnServiceProxy::SetUpVpn(const sptr<VpnConfig> &config, bool isVpnExtCall)
128 {
129 MessageParcel data;
130 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
131 NETMGR_EXT_LOG_E("write interface token failed");
132 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
133 }
134 if (!config->Marshalling(data)) {
135 NETMGR_EXT_LOG_E("SetUpVpn proxy Marshalling failed");
136 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
137 }
138
139 MessageParcel reply;
140 int32_t ret = 0;
141 if (isVpnExtCall) {
142 ret = SendRequest(INetworkVpnService::MessageCode::CMD_START_VPN_EXT, data, reply);
143 } else {
144 ret = SendRequest(INetworkVpnService::MessageCode::CMD_START_VPN, data, reply);
145 }
146 if (ERR_NONE != ret) {
147 NETMGR_EXT_LOG_E("SetUpVpn proxy SendRequest failed, error code: [%{public}d]", ret);
148 return ret;
149 }
150 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
151 if (!reply.ReadInt32(result)) {
152 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
153 }
154 return result;
155 }
156
Protect(bool isVpnExtCall)157 int32_t NetworkVpnServiceProxy::Protect(bool isVpnExtCall)
158 {
159 MessageParcel data;
160 MessageParcel reply;
161 int32_t ret = 0;
162 if (isVpnExtCall) {
163 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_PROTECT_EXT, data, reply);
164 } else {
165 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_PROTECT, data, reply);
166 }
167 if (ERR_NONE != ret) {
168 NETMGR_EXT_LOG_E("Protect proxy SendRequest failed, error code: [%{public}d]", ret);
169 return ret;
170 }
171 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
172 if (!reply.ReadInt32(result)) {
173 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
174 }
175 return result;
176 }
177
DestroyVpn(bool isVpnExtCall)178 int32_t NetworkVpnServiceProxy::DestroyVpn(bool isVpnExtCall)
179 {
180 MessageParcel data;
181 MessageParcel reply;
182 int32_t ret = 0;
183 if (isVpnExtCall) {
184 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_STOP_VPN_EXT, data, reply);
185 } else {
186 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_STOP_VPN, data, reply);
187 }
188 if (ERR_NONE != ret) {
189 NETMGR_EXT_LOG_E("DestroyVpn proxy SendRequest failed, error code: [%{public}d]", ret);
190 return ret;
191 }
192 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
193 if (!reply.ReadInt32(result)) {
194 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
195 }
196 return result;
197 }
198
199 #ifdef SUPPORT_SYSVPN
SetUpVpn(const sptr<SysVpnConfig> & config)200 int32_t NetworkVpnServiceProxy::SetUpVpn(const sptr<SysVpnConfig> &config)
201 {
202 if (config == nullptr) {
203 NETMGR_EXT_LOG_E("SetUpVpn failed, config is null");
204 return NETMANAGER_EXT_ERR_PARAMETER_ERROR;
205 }
206 NETMGR_EXT_LOG_I("SetUpVpn id=%{public}s", config->vpnId_.c_str());
207 MessageParcel data;
208 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
209 NETMGR_EXT_LOG_E("write interface token failed");
210 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
211 }
212
213 // LCOV_EXCL_START
214 if (!(data.WriteString(config->vpnId_) && data.WriteInt32(config->vpnType_))) {
215 NETMGR_EXT_LOG_E("SetUpVpn proxy write data failed");
216 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
217 }
218 // LCOV_EXCL_STOP
219 MessageParcel reply;
220 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_SETUP_SYS_VPN, data, reply);
221 if (ret != ERR_NONE) {
222 NETMGR_EXT_LOG_E("SetUpVpn proxy SendRequest failed, error code: [%{public}d]", ret);
223 return ret;
224 }
225 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
226 if (!reply.ReadInt32(result)) {
227 NETMGR_EXT_LOG_E("reply read data failed");
228 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
229 }
230 return result;
231 }
232
AddSysVpnConfig(sptr<SysVpnConfig> & config)233 int32_t NetworkVpnServiceProxy::AddSysVpnConfig(sptr<SysVpnConfig> &config)
234 {
235 if (config == nullptr) {
236 NETMGR_EXT_LOG_E("AddSysVpnConfig failed, config is null");
237 return NETMANAGER_EXT_ERR_PARAMETER_ERROR;
238 }
239 NETMGR_EXT_LOG_I("NetworkVpnServiceProxy AddSysVpnConfig id=%{public}s", config->vpnId_.c_str());
240 MessageParcel data;
241 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
242 NETMGR_EXT_LOG_E("AddSysVpnConfig write interface token failed");
243 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
244 }
245 if (!config->Marshalling(data)) {
246 NETMGR_EXT_LOG_E("AddSysVpnConfig proxy Marshalling failed");
247 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
248 }
249 MessageParcel reply;
250 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_ADD_SYS_VPN_CONFIG, data, reply);
251 if (ret != ERR_NONE) {
252 NETMGR_EXT_LOG_E("AddSysVpnConfig proxy SendRequest failed, error code: [%{public}d]", ret);
253 return ret;
254 }
255 if (!reply.ReadInt32(ret)) {
256 NETMGR_EXT_LOG_E("reply ReadInt32 failed");
257 return NETMANAGER_EXT_ERR_READ_REPLY_FAIL;
258 }
259 return NETMANAGER_EXT_SUCCESS;
260 }
261
DeleteSysVpnConfig(const std::string & vpnId)262 int32_t NetworkVpnServiceProxy::DeleteSysVpnConfig(const std::string &vpnId)
263 {
264 if (vpnId.empty()) {
265 NETMGR_EXT_LOG_E("DeleteSysVpnConfig failed, vpnId is empty");
266 return NETMANAGER_EXT_ERR_PARAMETER_ERROR;
267 }
268 NETMGR_EXT_LOG_I("NetworkVpnServiceProxy DeleteSysVpnConfig id=%{public}s", vpnId.c_str());
269 MessageParcel data;
270 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
271 NETMGR_EXT_LOG_E("DeleteSysVpnConfig write interface token failed");
272 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
273 }
274 // LCOV_EXCL_START
275 if (!data.WriteString(vpnId)) {
276 NETMGR_EXT_LOG_E("DeleteSysVpnConfig proxy write data failed");
277 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
278 }
279 // LCOV_EXCL_STOP
280 MessageParcel reply;
281 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_DELETE_SYS_VPN_CONFIG, data, reply);
282 if (ret != ERR_NONE) {
283 NETMGR_EXT_LOG_E("DeleteSysVpnConfig proxy SendRequest failed, error code: [%{public}d]", ret);
284 return ret;
285 }
286 if (!reply.ReadInt32(ret)) {
287 NETMGR_EXT_LOG_E("reply ReadInt32 failed");
288 return NETMANAGER_EXT_ERR_READ_REPLY_FAIL;
289 }
290 return NETMANAGER_EXT_SUCCESS;
291 }
292
GetSysVpnConfigList(std::vector<SysVpnConfig> & vpnList)293 int32_t NetworkVpnServiceProxy::GetSysVpnConfigList(std::vector<SysVpnConfig> &vpnList)
294 {
295 NETMGR_EXT_LOG_I("NetworkVpnServiceProxy GetSysVpnConfigList");
296 MessageParcel data;
297 MessageParcel reply;
298 int32_t ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_GET_SYS_VPN_CONFIG_LIST, data, reply);
299 if (ret != ERR_NONE) {
300 NETMGR_EXT_LOG_E("GetSysVpnConfigList proxy WriteTokenAndSendRequest failed, error code: [%{public}d]", ret);
301 return ret;
302 }
303 int vpnListSize = 0;
304 if (!reply.ReadInt32(vpnListSize)) {
305 NETMGR_EXT_LOG_E("GetSysVpnConfigList read data size failed");
306 return NETMANAGER_EXT_ERR_READ_REPLY_FAIL;
307 }
308 if (vpnListSize > SYSVPN_MAX_SIZE) {
309 NETMGR_EXT_LOG_E("GetSysVpnConfigList failed, size=%{public}d is too large", vpnListSize);
310 return NETMANAGER_EXT_ERR_INTERNAL;
311 }
312 for (int32_t idx = 0; idx < vpnListSize; idx++) {
313 sptr<SysVpnConfig> vpnConfig = new (std::nothrow) SysVpnConfig();
314 if (vpnConfig == nullptr) {
315 NETMGR_EXT_LOG_E("GetSysVpnConfigList failed, vpnConfig is null");
316 return NETMANAGER_EXT_ERR_INTERNAL;
317 }
318 reply.ReadString(vpnConfig->vpnId_);
319 reply.ReadString(vpnConfig->vpnName_);
320 reply.ReadInt32(vpnConfig->vpnType_);
321 vpnList.push_back(*vpnConfig);
322 }
323 return NETMANAGER_EXT_SUCCESS;
324 }
325
GetSysVpnConfig(sptr<SysVpnConfig> & config,const std::string & vpnId)326 int32_t NetworkVpnServiceProxy::GetSysVpnConfig(sptr<SysVpnConfig> &config, const std::string &vpnId)
327 {
328 if (vpnId.empty()) {
329 NETMGR_EXT_LOG_E("GetSysVpnConfig failed, vpnId is empty");
330 return NETMANAGER_EXT_ERR_PARAMETER_ERROR;
331 }
332 NETMGR_EXT_LOG_I("NetworkVpnServiceProxy GetSysVpnConfig id=%{public}s", vpnId.c_str());
333 MessageParcel data;
334 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
335 NETMGR_EXT_LOG_E("GetSysVpnConfig write interface token failed");
336 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
337 }
338 // LCOV_EXCL_START
339 if (!data.WriteString(vpnId)) {
340 NETMGR_EXT_LOG_E("GetSysVpnConfig proxy write data failed");
341 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
342 }
343 // LCOV_EXCL_STOP
344 MessageParcel reply;
345 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_GET_SYS_VPN_CONFIG, data, reply);
346 if (ret != ERR_NONE) {
347 NETMGR_EXT_LOG_E("GetSysVpnConfig proxy SendRequest failed, error code: [%{public}d]", ret);
348 return ret;
349 }
350
351 config = SysVpnConfig::Unmarshalling(reply);
352 if (config == nullptr) {
353 NETMGR_EXT_LOG_I("GetSysVpnConfig: vpn does not exist, id=%{public}s", vpnId.c_str());
354 }
355 return NETMANAGER_EXT_SUCCESS;
356 }
357
GetConnectedSysVpnConfig(sptr<SysVpnConfig> & config)358 int32_t NetworkVpnServiceProxy::GetConnectedSysVpnConfig(sptr<SysVpnConfig> &config)
359 {
360 NETMGR_EXT_LOG_I("NetworkVpnServiceProxy GetConnectedSysVpnConfig");
361 MessageParcel data;
362 MessageParcel reply;
363 int32_t ret = 0;
364 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_GET_CONNECTED_SYS_VPN_CONFIG, data, reply);
365 if (ret != ERR_NONE) {
366 NETMGR_EXT_LOG_E("GetConnectedSysVpnConfig proxy SendRequest failed, error code: [%{public}d]", ret);
367 return ret;
368 }
369 config = SysVpnConfig::Unmarshalling(reply);
370 if (config == nullptr) {
371 NETMGR_EXT_LOG_I("GetConnectedSysVpnConfig: no connected vpn");
372 }
373 return NETMANAGER_EXT_SUCCESS;
374 }
375
NotifyConnectStage(const std::string & stage,const int32_t & result)376 int32_t NetworkVpnServiceProxy::NotifyConnectStage(const std::string &stage, const int32_t &result)
377 {
378 MessageParcel data;
379 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
380 NETMGR_EXT_LOG_E("NotifyConnectStage write interface token failed");
381 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
382 }
383 // LCOV_EXCL_START
384 if (!(data.WriteString(stage) && data.WriteInt32(result))) {
385 NETMGR_EXT_LOG_E("NotifyConnectStage proxy write data failed");
386 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
387 }
388 // LCOV_EXCL_STOP
389 MessageParcel reply;
390 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_NOTIFY_CONNECT_STAGE, data, reply);
391 if (ret != ERR_NONE) {
392 NETMGR_EXT_LOG_E("NotifyConnectStage proxy SendRequest failed, error code: [%{public}d]", ret);
393 return ret;
394 }
395 int32_t resultCode = NETMANAGER_EXT_ERR_INTERNAL;
396 if (!reply.ReadInt32(resultCode)) {
397 NETMGR_EXT_LOG_E("NotifyConnectStage reply read data failed");
398 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
399 }
400 return resultCode;
401 }
402
GetSysVpnCertUri(const int32_t certType,std::string & certUri)403 int32_t NetworkVpnServiceProxy::GetSysVpnCertUri(const int32_t certType, std::string &certUri)
404 {
405 MessageParcel data;
406 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
407 NETMGR_EXT_LOG_E("GetSysVpnCertUri write interface token failed");
408 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
409 }
410 // LCOV_EXCL_START
411 if (!data.WriteInt32(certType)) {
412 NETMGR_EXT_LOG_E("GetSysVpnCertUri proxy write data failed");
413 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
414 }
415 // LCOV_EXCL_STOP
416 MessageParcel reply;
417 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_GET_SYS_VPN_CERT_URI, data, reply);
418 if (ret != ERR_NONE) {
419 NETMGR_EXT_LOG_E("GetSysVpnCertUri proxy SendRequest failed, error code: [%{public}d]", ret);
420 return ret;
421 }
422 if (!reply.ReadString(certUri)) {
423 NETMGR_EXT_LOG_E("GetSysVpnCertUri proxy read data failed");
424 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
425 }
426 return NETMANAGER_EXT_SUCCESS;
427 }
428 #endif // SUPPORT_SYSVPN
429
RegisterVpnEvent(sptr<IVpnEventCallback> callback)430 int32_t NetworkVpnServiceProxy::RegisterVpnEvent(sptr<IVpnEventCallback> callback)
431 {
432 MessageParcel data;
433 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
434 NETMGR_EXT_LOG_E("write interface token failed");
435 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
436 }
437 if (!data.WriteRemoteObject(callback->AsObject())) {
438 NETMGR_EXT_LOG_E("RegisterVpnEvent proxy write callback failed");
439 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
440 }
441
442 MessageParcel reply;
443 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_REGISTER_EVENT_CALLBACK, data, reply);
444 if (ERR_NONE != ret) {
445 NETMGR_EXT_LOG_E("RegisterVpnEvent proxy SendRequest failed, error code: [%{public}d]", ret);
446 return ret;
447 }
448 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
449 if (!reply.ReadInt32(result)) {
450 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
451 }
452 return result;
453 }
454
UnregisterVpnEvent(sptr<IVpnEventCallback> callback)455 int32_t NetworkVpnServiceProxy::UnregisterVpnEvent(sptr<IVpnEventCallback> callback)
456 {
457 MessageParcel data;
458 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
459 NETMGR_EXT_LOG_E("write interface token failed");
460 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
461 }
462 if (!data.WriteRemoteObject(callback->AsObject())) {
463 NETMGR_EXT_LOG_E("UnregisterVpnEvent proxy write callback failed");
464 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
465 }
466
467 MessageParcel reply;
468 int32_t ret = SendRequest(INetworkVpnService::MessageCode::CMD_UNREGISTER_EVENT_CALLBACK, data, reply);
469 if (ERR_NONE != ret) {
470 NETMGR_EXT_LOG_E("UnregisterVpnEvent proxy SendRequest failed, error code: [%{public}d]", ret);
471 return ret;
472 }
473 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
474 if (!reply.ReadInt32(result)) {
475 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
476 }
477 return result;
478 }
479
CreateVpnConnection(bool isVpnExtCall)480 int32_t NetworkVpnServiceProxy::CreateVpnConnection(bool isVpnExtCall)
481 {
482 MessageParcel data;
483 MessageParcel reply;
484 int32_t ret = 0;
485 if (isVpnExtCall) {
486 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_CREATE_VPN_CONNECTION_EXT, data, reply);
487 } else {
488 ret = WriteTokenAndSendRequest(INetworkVpnService::MessageCode::CMD_CREATE_VPN_CONNECTION, data, reply);
489 }
490 if (ERR_NONE != ret) {
491 NETMGR_EXT_LOG_E("CreateVpnConnection proxy SendRequest failed, error code: [%{public}d]", ret);
492 return ret;
493 }
494 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
495 if (!reply.ReadInt32(result)) {
496 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
497 }
498 return result;
499 }
500
RegisterBundleName(const std::string & bundleName,const std::string & abilityName)501 int32_t NetworkVpnServiceProxy::RegisterBundleName(const std::string &bundleName, const std::string &abilityName)
502 {
503 MessageParcel data;
504 if (!data.WriteInterfaceToken(NetworkVpnServiceProxy::GetDescriptor())) {
505 NETMGR_EXT_LOG_E("write interface token failed");
506 return NETMANAGER_EXT_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
507 }
508 if (!data.WriteString(bundleName)) {
509 NETMGR_EXT_LOG_E("RegisterBundleName write bundleName failed");
510 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
511 }
512 if (!data.WriteString(abilityName)) {
513 NETMGR_EXT_LOG_E("RegisterBundleName write abilityName failed");
514 return NETMANAGER_EXT_ERR_WRITE_DATA_FAIL;
515 }
516 MessageParcel reply;
517 auto ret = SendRequest(INetworkVpnService::MessageCode::CMD_REGISTER_BUNDLENAME, data, reply);
518 if (ret != ERR_NONE) {
519 NETMGR_EXT_LOG_E("SendRequest failed %{public}d", ret);
520 return ret;
521 }
522 int32_t result = NETMANAGER_EXT_ERR_INTERNAL;
523 if (!reply.ReadInt32(result)) {
524 return NETMANAGER_EXT_ERR_READ_DATA_FAIL;
525 }
526 return result;
527 }
528
FactoryResetVpn()529 int32_t NetworkVpnServiceProxy::FactoryResetVpn()
530 {
531 return NETMANAGER_EXT_SUCCESS;
532 }
533 } // namespace NetManagerStandard
534 } // namespace OHOS
535