1 /*
2 * Copyright (c) 2021-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 #include "net_conn_service_proxy.h"
16
17 #include "net_conn_constants.h"
18 #include "net_manager_constants.h"
19 #include "net_mgr_log_wrapper.h"
20 #include "ipc_skeleton.h"
21 #include "net_conn_service_pac_proxy_helper.h"
22
23 namespace OHOS {
24 namespace NetManagerStandard {
25 static constexpr uint32_t MAX_IFACE_NUM = 16;
26 static constexpr uint32_t MAX_NET_CAP_NUM = 32;
27
NetConnServiceProxy(const sptr<IRemoteObject> & impl)28 NetConnServiceProxy::NetConnServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<INetConnService>(impl) {}
29
~NetConnServiceProxy()30 NetConnServiceProxy::~NetConnServiceProxy() {}
31
SystemReady()32 int32_t NetConnServiceProxy::SystemReady()
33 {
34 MessageParcel data;
35 MessageParcel reply;
36 if (!WriteInterfaceToken(data)) {
37 NETMGR_LOG_E("WriteInterfaceToken failed");
38 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
39 }
40
41 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SYSTEM_READY), data, reply);
42 if (error != NETMANAGER_SUCCESS) {
43 return error;
44 }
45
46 return NETMANAGER_SUCCESS;
47 }
48
SetInternetPermission(uint32_t uid,uint8_t allow)49 int32_t NetConnServiceProxy::SetInternetPermission(uint32_t uid, uint8_t allow)
50 {
51 MessageParcel data;
52 MessageParcel reply;
53 if (!WriteInterfaceToken(data)) {
54 NETMGR_LOG_E("WriteInterfaceToken failed");
55 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
56 }
57
58 NETMGR_LOG_D("proxy SetInternetPermission [%{public}u %{public}hhu]", uid, allow);
59 if (!data.WriteUint32(uid)) {
60 return NETMANAGER_ERR_WRITE_DATA_FAIL;
61 }
62 if (!data.WriteUint8(allow)) {
63 return NETMANAGER_ERR_WRITE_DATA_FAIL;
64 }
65 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION),
66 data, reply);
67 if (error != NETMANAGER_SUCCESS) {
68 return error;
69 }
70
71 return reply.ReadInt32();
72 }
73
EnableVnicNetwork(const sptr<NetLinkInfo> & netLinkInfo,const std::set<int32_t> & uids)74 int32_t NetConnServiceProxy::EnableVnicNetwork(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids)
75 {
76 if (netLinkInfo == nullptr) {
77 NETMGR_LOG_E("netLinkInfo is null");
78 return NETMANAGER_ERR_LOCAL_PTR_NULL;
79 }
80
81 MessageParcel data;
82 MessageParcel reply;
83 if (!WriteInterfaceToken(data)) {
84 NETMGR_LOG_E("WriteInterfaceToken failed");
85 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
86 }
87
88 if (!data.WriteInt32(uids.size())) {
89 return NETMANAGER_ERR_READ_DATA_FAIL;
90 }
91
92 for (const auto &uid: uids) {
93 if (!data.WriteInt32(uid)) {
94 return NETMANAGER_ERR_READ_DATA_FAIL;
95 }
96 }
97
98 if (!netLinkInfo->Marshalling(data)) {
99 NETMGR_LOG_E("proxy Marshalling failed");
100 return NETMANAGER_ERR_WRITE_DATA_FAIL;
101 }
102
103 int32_t error =
104 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_VNIC_NET_WORK), data, reply);
105 if (error != NETMANAGER_SUCCESS) {
106 return error;
107 }
108
109 int32_t ret;
110 if (!reply.ReadInt32(ret)) {
111 return NETMANAGER_ERR_READ_REPLY_FAIL;
112 }
113 return ret;
114 }
115
EnableDistributedClientNet(const std::string & virnicAddr,const std::string & iif)116 int32_t NetConnServiceProxy::EnableDistributedClientNet(const std::string &virnicAddr, const std::string &iif)
117 {
118 MessageParcel data;
119 MessageParcel reply;
120 if (!WriteInterfaceToken(data)) {
121 NETMGR_LOG_E("WriteInterfaceToken failed");
122 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
123 }
124
125 if (!data.WriteString(virnicAddr)) {
126 return NETMANAGER_ERR_WRITE_DATA_FAIL;
127 }
128
129 if (!data.WriteString(iif)) {
130 return NETMANAGER_ERR_WRITE_DATA_FAIL;
131 }
132
133 int32_t error =
134 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_DISTRIBUTE_CLIENT_NET), data, reply);
135 if (error != NETMANAGER_SUCCESS) {
136 return error;
137 }
138
139 int32_t ret;
140 if (!reply.ReadInt32(ret)) {
141 return NETMANAGER_ERR_READ_REPLY_FAIL;
142 }
143 return ret;
144 }
145
EnableDistributedServerNet(const std::string & iif,const std::string & devIface,const std::string & dstAddr)146 int32_t NetConnServiceProxy::EnableDistributedServerNet(const std::string &iif, const std::string &devIface,
147 const std::string &dstAddr)
148 {
149 MessageParcel data;
150 MessageParcel reply;
151 if (!WriteInterfaceToken(data)) {
152 NETMGR_LOG_E("WriteInterfaceToken failed");
153 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
154 }
155
156 if (!data.WriteString(iif)) {
157 return NETMANAGER_ERR_WRITE_DATA_FAIL;
158 }
159
160 if (!data.WriteString(devIface)) {
161 return NETMANAGER_ERR_WRITE_DATA_FAIL;
162 }
163
164 if (!data.WriteString(dstAddr)) {
165 return NETMANAGER_ERR_WRITE_DATA_FAIL;
166 }
167
168 int32_t error =
169 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_DISTRIBUTE_SERVER_NET), data, reply);
170 if (error != NETMANAGER_SUCCESS) {
171 return error;
172 }
173
174 int32_t ret;
175 if (!reply.ReadInt32(ret)) {
176 return NETMANAGER_ERR_READ_REPLY_FAIL;
177 }
178 return ret;
179 }
180
DisableDistributedNet(bool isServer)181 int32_t NetConnServiceProxy::DisableDistributedNet(bool isServer)
182 {
183 MessageParcel data;
184 MessageParcel reply;
185 if (!WriteInterfaceToken(data)) {
186 NETMGR_LOG_E("WriteInterfaceToken failed");
187 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
188 }
189
190 if (!data.WriteBool(isServer)) {
191 return NETMANAGER_ERR_WRITE_DATA_FAIL;
192 }
193
194 int32_t error =
195 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_DISTRIBUTE_NET), data, reply);
196 if (error != NETMANAGER_SUCCESS) {
197 return error;
198 }
199
200 int32_t ret;
201 if (!reply.ReadInt32(ret)) {
202 return NETMANAGER_ERR_READ_REPLY_FAIL;
203 }
204 return ret;
205 }
206
DisableVnicNetwork()207 int32_t NetConnServiceProxy::DisableVnicNetwork()
208 {
209 MessageParcel data;
210 MessageParcel reply;
211 if (!WriteInterfaceToken(data)) {
212 NETMGR_LOG_E("WriteInterfaceToken failed");
213 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
214 }
215
216 int32_t error =
217 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_VNIC_NET_WORK), data, reply);
218 if (error != NETMANAGER_SUCCESS) {
219 return error;
220 }
221
222 int32_t ret;
223 if (!reply.ReadInt32(ret)) {
224 return NETMANAGER_ERR_READ_REPLY_FAIL;
225 }
226 return ret;
227 }
228
RegisterNetSupplier(NetBearType bearerType,const std::string & ident,const std::set<NetCap> & netCaps,uint32_t & supplierId)229 int32_t NetConnServiceProxy::RegisterNetSupplier(NetBearType bearerType, const std::string &ident,
230 const std::set<NetCap> &netCaps, uint32_t &supplierId)
231 {
232 MessageParcel data;
233 MessageParcel reply;
234 if (!WriteInterfaceToken(data)) {
235 NETMGR_LOG_E("WriteInterfaceToken failed");
236 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
237 }
238
239 if (!data.WriteUint32(static_cast<uint32_t>(bearerType))) {
240 return NETMANAGER_ERR_WRITE_DATA_FAIL;
241 }
242
243 if (!data.WriteString(ident)) {
244 return NETMANAGER_ERR_WRITE_DATA_FAIL;
245 }
246
247 uint32_t size = static_cast<uint32_t>(netCaps.size());
248 if (!data.WriteUint32(size)) {
249 return NETMANAGER_ERR_WRITE_DATA_FAIL;
250 }
251 for (auto netCap : netCaps) {
252 if (!data.WriteUint32(static_cast<uint32_t>(netCap))) {
253 return NETMANAGER_ERR_WRITE_DATA_FAIL;
254 }
255 }
256
257 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REG_NET_SUPPLIER), data, reply);
258 if (error != NETMANAGER_SUCCESS) {
259 return error;
260 }
261
262 int32_t ret;
263 if (!reply.ReadInt32(ret)) {
264 return NETMANAGER_ERR_READ_REPLY_FAIL;
265 }
266 if (ret == NETMANAGER_SUCCESS) {
267 if (!reply.ReadUint32(supplierId)) {
268 return NETMANAGER_ERR_READ_REPLY_FAIL;
269 }
270 }
271 return ret;
272 }
273
UnregisterNetSupplier(uint32_t supplierId)274 int32_t NetConnServiceProxy::UnregisterNetSupplier(uint32_t supplierId)
275 {
276 MessageParcel data;
277 MessageParcel reply;
278 if (!WriteInterfaceToken(data)) {
279 NETMGR_LOG_E("WriteInterfaceToken failed");
280 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
281 }
282
283 NETMGR_LOG_D("proxy supplierId[%{public}d]", supplierId);
284 if (!data.WriteUint32(supplierId)) {
285 return NETMANAGER_ERR_WRITE_DATA_FAIL;
286 }
287
288 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREG_NETWORK), data, reply);
289 if (error != NETMANAGER_SUCCESS) {
290 return error;
291 }
292
293 return reply.ReadInt32();
294 }
295
RegisterNetSupplierCallback(uint32_t supplierId,const sptr<INetSupplierCallback> & callback)296 int32_t NetConnServiceProxy::RegisterNetSupplierCallback(uint32_t supplierId,
297 const sptr<INetSupplierCallback> &callback)
298 {
299 if (callback == nullptr) {
300 NETMGR_LOG_E("The parameter of callback is nullptr");
301 return NETMANAGER_ERR_LOCAL_PTR_NULL;
302 }
303
304 MessageParcel dataParcel;
305 if (!WriteInterfaceToken(dataParcel)) {
306 NETMGR_LOG_E("WriteInterfaceToken failed");
307 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
308 }
309 dataParcel.WriteUint32(supplierId);
310 dataParcel.WriteRemoteObject(callback->AsObject());
311
312 MessageParcel replyParcel;
313 int32_t retCode = RemoteSendRequest(
314 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_SUPPLIER_CALLBACK), dataParcel, replyParcel);
315 if (retCode != NETMANAGER_SUCCESS) {
316 return retCode;
317 }
318 NETMGR_LOG_I("SendRequest retCode:[%{public}d]", retCode);
319 return replyParcel.ReadInt32();
320 }
321
RegisterNetConnCallback(const sptr<INetConnCallback> callback)322 int32_t NetConnServiceProxy::RegisterNetConnCallback(const sptr<INetConnCallback> callback)
323 {
324 if (callback == nullptr) {
325 NETMGR_LOG_E("The parameter of callback is nullptr");
326 return NETMANAGER_ERR_LOCAL_PTR_NULL;
327 }
328
329 MessageParcel dataParcel;
330 if (!WriteInterfaceToken(dataParcel)) {
331 NETMGR_LOG_E("WriteInterfaceToken failed");
332 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
333 }
334 dataParcel.WriteRemoteObject(callback->AsObject());
335
336 MessageParcel replyParcel;
337 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK),
338 dataParcel, replyParcel);
339 if (retCode != NETMANAGER_SUCCESS) {
340 return retCode;
341 }
342 NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
343 return replyParcel.ReadInt32();
344 }
345
RegisterNetConnCallback(const sptr<NetSpecifier> & netSpecifier,const sptr<INetConnCallback> callback,const uint32_t & timeoutMS)346 int32_t NetConnServiceProxy::RegisterNetConnCallback(const sptr<NetSpecifier> &netSpecifier,
347 const sptr<INetConnCallback> callback, const uint32_t &timeoutMS)
348 {
349 if (netSpecifier == nullptr || callback == nullptr) {
350 NETMGR_LOG_E("The parameter of netSpecifier or callback is nullptr");
351 return NETMANAGER_ERR_LOCAL_PTR_NULL;
352 }
353
354 MessageParcel dataParcel;
355 if (!WriteInterfaceToken(dataParcel)) {
356 NETMGR_LOG_E("WriteInterfaceToken failed");
357 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
358 }
359 netSpecifier->Marshalling(dataParcel);
360 dataParcel.WriteUint32(timeoutMS);
361 dataParcel.WriteRemoteObject(callback->AsObject());
362
363 MessageParcel replyParcel;
364 int32_t retCode = RemoteSendRequest(
365 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK_BY_SPECIFIER),
366 dataParcel, replyParcel);
367 if (retCode != NETMANAGER_SUCCESS) {
368 return retCode;
369 }
370 NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
371 return replyParcel.ReadInt32();
372 }
373
RequestNetConnection(const sptr<NetSpecifier> netSpecifier,const sptr<INetConnCallback> callback,const uint32_t timeoutMS)374 int32_t NetConnServiceProxy::RequestNetConnection(const sptr<NetSpecifier> netSpecifier,
375 const sptr<INetConnCallback> callback, const uint32_t timeoutMS)
376 {
377 if (netSpecifier == nullptr || callback == nullptr) {
378 NETMGR_LOG_E("The parameter of netSpecifier or callback is nullptr");
379 return NETMANAGER_ERR_LOCAL_PTR_NULL;
380 }
381
382 MessageParcel dataParcel;
383 if (!WriteInterfaceToken(dataParcel)) {
384 NETMGR_LOG_E("WriteInterfaceToken failed");
385 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
386 }
387 netSpecifier->Marshalling(dataParcel);
388 dataParcel.WriteUint32(timeoutMS);
389 dataParcel.WriteRemoteObject(callback->AsObject());
390
391 MessageParcel replyParcel;
392 int32_t retCode = RemoteSendRequest(
393 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REQUEST_NET_CONNECTION),
394 dataParcel, replyParcel);
395 if (retCode != NETMANAGER_SUCCESS) {
396 return retCode;
397 }
398 NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
399 return replyParcel.ReadInt32();
400 }
401
UnregisterNetConnCallback(const sptr<INetConnCallback> & callback)402 int32_t NetConnServiceProxy::UnregisterNetConnCallback(const sptr<INetConnCallback> &callback)
403 {
404 if (callback == nullptr) {
405 NETMGR_LOG_E("The parameter of callback is nullptr");
406 return NETMANAGER_ERR_LOCAL_PTR_NULL;
407 }
408
409 MessageParcel dataParcel;
410 if (!WriteInterfaceToken(dataParcel)) {
411 NETMGR_LOG_E("WriteInterfaceToken failed");
412 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
413 }
414 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
415
416 MessageParcel replyParcel;
417 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_CONN_CALLBACK),
418 dataParcel, replyParcel);
419 if (retCode != NETMANAGER_SUCCESS) {
420 return retCode;
421 }
422 NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
423 return replyParcel.ReadInt32();
424 }
425
UpdateNetCaps(const std::set<NetCap> & netCaps,const uint32_t supplierId)426 int32_t NetConnServiceProxy::UpdateNetCaps(const std::set<NetCap> &netCaps, const uint32_t supplierId)
427 {
428 MessageParcel data;
429 MessageParcel reply;
430 if (!WriteInterfaceToken(data)) {
431 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
432 }
433
434 uint32_t netCapsSize = static_cast<uint32_t>(netCaps.size());
435 if (!data.WriteUint32(netCapsSize)) {
436 return NETMANAGER_ERR_WRITE_DATA_FAIL;
437 }
438 for (const auto &cap : netCaps) {
439 if (!data.WriteUint32(static_cast<uint32_t>(cap))) {
440 return NETMANAGER_ERR_WRITE_DATA_FAIL;
441 }
442 }
443
444 if (!data.WriteUint32(supplierId)) {
445 return NETMANAGER_ERR_WRITE_DATA_FAIL;
446 }
447
448 int32_t result = RemoteSendRequest(
449 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_CAPS), data, reply);
450 if (result != NETMANAGER_SUCCESS) {
451 NETMGR_LOG_E("RemoteSendRequest failed");
452 return result;
453 }
454
455 if (!reply.ReadInt32(result)) {
456 return NETMANAGER_ERR_READ_REPLY_FAIL;
457 }
458 return result;
459 }
460
UpdateNetStateForTest(const sptr<NetSpecifier> & netSpecifier,int32_t netState)461 int32_t NetConnServiceProxy::UpdateNetStateForTest(const sptr<NetSpecifier> &netSpecifier, int32_t netState)
462 {
463 NETMGR_LOG_I("Test NetConnServiceProxy::UpdateNetStateForTest(), begin");
464 if (netSpecifier == nullptr) {
465 NETMGR_LOG_E("The parameter of netSpecifier is nullptr");
466 return NETMANAGER_ERR_LOCAL_PTR_NULL;
467 }
468
469 MessageParcel dataParcel;
470 if (!WriteInterfaceToken(dataParcel)) {
471 NETMGR_LOG_E("WriteInterfaceToken failed");
472 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
473 }
474 netSpecifier->Marshalling(dataParcel);
475
476 if (!dataParcel.WriteInt32(netState)) {
477 return NETMANAGER_ERR_WRITE_DATA_FAIL;
478 }
479
480 MessageParcel replyParcel;
481 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_STATE_FOR_TEST),
482 dataParcel, replyParcel);
483 if (retCode != NETMANAGER_SUCCESS) {
484 return retCode;
485 }
486 NETMGR_LOG_I("NetConnServiceProxy::UpdateNetStateForTest(), SendRequest retCode:[%{public}d]", retCode);
487 return replyParcel.ReadInt32();
488 }
489
UpdateNetSupplierInfo(uint32_t supplierId,const sptr<NetSupplierInfo> & netSupplierInfo)490 int32_t NetConnServiceProxy::UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo)
491 {
492 if (netSupplierInfo == nullptr) {
493 NETMGR_LOG_E("netSupplierInfo is null");
494 return NETMANAGER_ERR_LOCAL_PTR_NULL;
495 }
496
497 MessageParcel data;
498 MessageParcel reply;
499 if (!WriteInterfaceToken(data)) {
500 NETMGR_LOG_E("WriteInterfaceToken failed");
501 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
502 }
503
504 NETMGR_LOG_D("proxy supplierId[%{public}d]", supplierId);
505 if (!data.WriteUint32(supplierId)) {
506 return NETMANAGER_ERR_WRITE_DATA_FAIL;
507 }
508 NETMGR_LOG_D("proxy supplierId[%{public}d] Marshalling success", supplierId);
509 if (!netSupplierInfo->Marshalling(data)) {
510 NETMGR_LOG_E("proxy Marshalling failed");
511 return NETMANAGER_ERR_WRITE_DATA_FAIL;
512 }
513 NETMGR_LOG_D("proxy Marshalling success");
514
515 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_SUPPLIER_INFO),
516 data, reply);
517 if (error != NETMANAGER_SUCCESS) {
518 return error;
519 }
520 NETMGR_LOG_I("UpdateNetSupplierInfo out.");
521 return reply.ReadInt32();
522 }
523
UpdateNetLinkInfo(uint32_t supplierId,const sptr<NetLinkInfo> & netLinkInfo)524 int32_t NetConnServiceProxy::UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo)
525 {
526 if (netLinkInfo == nullptr) {
527 NETMGR_LOG_E("netLinkInfo is null");
528 return NETMANAGER_ERR_LOCAL_PTR_NULL;
529 }
530
531 MessageParcel data;
532 MessageParcel reply;
533 if (!WriteInterfaceToken(data)) {
534 NETMGR_LOG_E("WriteInterfaceToken failed");
535 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
536 }
537
538 if (!data.WriteUint32(supplierId)) {
539 return NETMANAGER_ERR_WRITE_DATA_FAIL;
540 }
541
542 if (!netLinkInfo->Marshalling(data)) {
543 NETMGR_LOG_E("proxy Marshalling failed");
544 return NETMANAGER_ERR_WRITE_DATA_FAIL;
545 }
546
547 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_LINK_INFO),
548 data, reply);
549 if (error != NETMANAGER_SUCCESS) {
550 return error;
551 }
552
553 return reply.ReadInt32();
554 }
555
RegisterNetDetectionCallback(int32_t netId,const sptr<INetDetectionCallback> & callback)556 int32_t NetConnServiceProxy::RegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback)
557 {
558 if (callback == nullptr) {
559 NETMGR_LOG_E("The parameter of callback is nullptr");
560 return NETMANAGER_ERR_LOCAL_PTR_NULL;
561 }
562
563 MessageParcel dataParcel;
564 if (!WriteInterfaceToken(dataParcel)) {
565 NETMGR_LOG_E("WriteInterfaceToken failed");
566 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
567 }
568 if (!dataParcel.WriteInt32(netId)) {
569 return NETMANAGER_ERR_WRITE_DATA_FAIL;
570 }
571 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
572
573 MessageParcel replyParcel;
574 int32_t error = RemoteSendRequest(
575 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_DETECTION_RET_CALLBACK), dataParcel, replyParcel);
576 if (error != NETMANAGER_SUCCESS) {
577 return error;
578 }
579 return replyParcel.ReadInt32();
580 }
581
UnRegisterNetDetectionCallback(int32_t netId,const sptr<INetDetectionCallback> & callback)582 int32_t NetConnServiceProxy::UnRegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback)
583 {
584 if (callback == nullptr) {
585 NETMGR_LOG_E("The parameter of callback is nullptr");
586 return NETMANAGER_ERR_LOCAL_PTR_NULL;
587 }
588
589 MessageParcel dataParcel;
590 if (!WriteInterfaceToken(dataParcel)) {
591 NETMGR_LOG_E("WriteInterfaceToken failed");
592 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
593 }
594 if (!dataParcel.WriteInt32(netId)) {
595 return NETMANAGER_ERR_WRITE_DATA_FAIL;
596 }
597 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
598
599 MessageParcel replyParcel;
600 int32_t error = RemoteSendRequest(
601 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_DETECTION_RET_CALLBACK),
602 dataParcel, replyParcel);
603 if (error != NETMANAGER_SUCCESS) {
604 return error;
605 }
606 return replyParcel.ReadInt32();
607 }
608
NetDetection(int32_t netId)609 int32_t NetConnServiceProxy::NetDetection(int32_t netId)
610 {
611 MessageParcel dataParcel;
612 if (!WriteInterfaceToken(dataParcel)) {
613 NETMGR_LOG_E("WriteInterfaceToken failed");
614 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
615 }
616 if (!dataParcel.WriteInt32(netId)) {
617 return NETMANAGER_ERR_WRITE_DATA_FAIL;
618 }
619
620 MessageParcel replyParcel;
621 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_NET_DETECTION),
622 dataParcel, replyParcel);
623 if (error != NETMANAGER_SUCCESS) {
624 return error;
625 }
626 return replyParcel.ReadInt32();
627 }
628
GetIfaceNames(NetBearType bearerType,std::list<std::string> & ifaceNames)629 int32_t NetConnServiceProxy::GetIfaceNames(NetBearType bearerType, std::list<std::string> &ifaceNames)
630 {
631 MessageParcel data;
632 if (!WriteInterfaceToken(data)) {
633 NETMGR_LOG_E("WriteInterfaceToken failed");
634 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
635 }
636
637 if (!data.WriteUint32(bearerType)) {
638 return NETMANAGER_ERR_WRITE_DATA_FAIL;
639 }
640
641 MessageParcel reply;
642 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACE_NAMES),
643 data, reply);
644 if (error != NETMANAGER_SUCCESS) {
645 return error;
646 }
647
648 int32_t ret = NETMANAGER_SUCCESS;
649 if (!reply.ReadInt32(ret)) {
650 return NETMANAGER_ERR_READ_REPLY_FAIL;
651 }
652 if (ret == NETMANAGER_SUCCESS) {
653 uint32_t size = 0;
654 if (!reply.ReadUint32(size)) {
655 return NETMANAGER_ERR_READ_REPLY_FAIL;
656 }
657 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
658 for (uint32_t i = 0; i < size; ++i) {
659 std::string value;
660 if (!reply.ReadString(value)) {
661 return NETMANAGER_ERR_READ_REPLY_FAIL;
662 }
663 ifaceNames.push_back(value);
664 }
665 }
666 return ret;
667 }
668
GetIfaceNameByType(NetBearType bearerType,const std::string & ident,std::string & ifaceName)669 int32_t NetConnServiceProxy::GetIfaceNameByType(NetBearType bearerType, const std::string &ident,
670 std::string &ifaceName)
671 {
672 MessageParcel data;
673 if (!WriteInterfaceToken(data)) {
674 NETMGR_LOG_E("WriteInterfaceToken failed");
675 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
676 }
677 if (bearerType >= BEARER_DEFAULT) {
678 return NETMANAGER_ERR_INTERNAL;
679 }
680 uint32_t netType = static_cast<NetBearType>(bearerType);
681 if (!data.WriteUint32(netType)) {
682 return NETMANAGER_ERR_WRITE_DATA_FAIL;
683 }
684
685 if (!data.WriteString(ident)) {
686 return NETMANAGER_ERR_WRITE_DATA_FAIL;
687 }
688
689 MessageParcel reply;
690 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACENAME_BY_TYPE),
691 data, reply);
692 if (error != NETMANAGER_SUCCESS) {
693 return error;
694 }
695
696 int32_t ret = 0;
697 if (!reply.ReadInt32(ret)) {
698 return NETMANAGER_ERR_READ_REPLY_FAIL;
699 }
700 if (ret == NETMANAGER_SUCCESS) {
701 if (!reply.ReadString(ifaceName)) {
702 return NETMANAGER_ERR_READ_REPLY_FAIL;
703 }
704 }
705 return ret;
706 }
707
GetIfaceNameIdentMaps(NetBearType bearerType,SafeMap<std::string,std::string> & ifaceNameIdentMaps)708 int32_t NetConnServiceProxy::GetIfaceNameIdentMaps(NetBearType bearerType,
709 SafeMap<std::string, std::string> &ifaceNameIdentMaps)
710 {
711 MessageParcel data;
712 if (!WriteInterfaceToken(data)) {
713 NETMGR_LOG_E("WriteInterfaceToken failed");
714 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
715 }
716 if (bearerType >= BEARER_DEFAULT) {
717 return NETMANAGER_ERR_INTERNAL;
718 }
719 uint32_t netType = static_cast<NetBearType>(bearerType);
720 if (!data.WriteUint32(netType)) {
721 return NETMANAGER_ERR_WRITE_DATA_FAIL;
722 }
723 MessageParcel reply;
724 int32_t ret = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_GET_IFACENAME_IDENT_MAPS),
725 data, reply);
726 if (ret != NETMANAGER_SUCCESS) {
727 return ret;
728 }
729 if (!reply.ReadInt32(ret)) {
730 return NETMANAGER_ERR_READ_REPLY_FAIL;
731 }
732 uint32_t size = 0;
733 if (!reply.ReadUint32(size)) {
734 return NETMANAGER_ERR_READ_REPLY_FAIL;
735 }
736 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
737 for (uint32_t i = 0; i < size; ++i) {
738 std::string key;
739 std::string value;
740 if (!reply.ReadString(key) || !reply.ReadString(value)) {
741 return NETMANAGER_ERR_READ_REPLY_FAIL;
742 }
743 ifaceNameIdentMaps.EnsureInsert(key, value);
744 }
745 return ret;
746 }
747
WriteInterfaceToken(MessageParcel & data)748 bool NetConnServiceProxy::WriteInterfaceToken(MessageParcel &data)
749 {
750 if (!data.WriteInterfaceToken(NetConnServiceProxy::GetDescriptor())) {
751 NETMGR_LOG_E("WriteInterfaceToken failed");
752 return false;
753 }
754 return true;
755 }
756
GetDefaultNet(int32_t & netId)757 int32_t NetConnServiceProxy::GetDefaultNet(int32_t &netId)
758 {
759 MessageParcel dataParcel;
760 if (!WriteInterfaceToken(dataParcel)) {
761 NETMGR_LOG_E("WriteInterfaceToken failed");
762 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
763 }
764
765 MessageParcel replyParcel;
766 int32_t errCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK),
767 dataParcel, replyParcel);
768 if (errCode != NETMANAGER_SUCCESS) {
769 return errCode;
770 }
771 NETMGR_LOG_D("SendRequest errcode:[%{public}d]", errCode);
772 int32_t ret = 0;
773 if (!replyParcel.ReadInt32(ret)) {
774 return NETMANAGER_ERR_READ_REPLY_FAIL;
775 }
776 if (ret == NETMANAGER_SUCCESS) {
777 if (!replyParcel.ReadInt32(netId)) {
778 return NETMANAGER_ERR_READ_REPLY_FAIL;
779 }
780 }
781 return ret;
782 }
783
HasDefaultNet(bool & flag)784 int32_t NetConnServiceProxy::HasDefaultNet(bool &flag)
785 {
786 MessageParcel dataParcel;
787 if (!WriteInterfaceToken(dataParcel)) {
788 NETMGR_LOG_E("WriteInterfaceToken failed");
789 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
790 }
791
792 MessageParcel replyParcel;
793 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET),
794 dataParcel, replyParcel);
795 if (retCode != NETMANAGER_SUCCESS) {
796 return retCode;
797 }
798 NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
799
800 int32_t ret = 0;
801 if (!replyParcel.ReadInt32(ret)) {
802 return NETMANAGER_ERR_READ_REPLY_FAIL;
803 }
804 if (ret == NETMANAGER_SUCCESS) {
805 if (!replyParcel.ReadBool(flag)) {
806 return NETMANAGER_ERR_READ_REPLY_FAIL;
807 }
808 }
809 return ret;
810 }
811
GetSpecificNet(NetBearType bearerType,std::list<int32_t> & netIdList)812 int32_t NetConnServiceProxy::GetSpecificNet(NetBearType bearerType, std::list<int32_t> &netIdList)
813 {
814 MessageParcel data;
815 if (!WriteInterfaceToken(data)) {
816 NETMGR_LOG_E("WriteInterfaceToken failed");
817 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
818 }
819
820 uint32_t type = static_cast<uint32_t>(bearerType);
821 if (!data.WriteUint32(type)) {
822 return NETMANAGER_ERR_WRITE_DATA_FAIL;
823 }
824
825 MessageParcel reply;
826 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET),
827 data, reply);
828 if (error != NETMANAGER_SUCCESS) {
829 return error;
830 }
831
832 int32_t ret = NETMANAGER_SUCCESS;
833 if (!reply.ReadInt32(ret)) {
834 return NETMANAGER_ERR_READ_REPLY_FAIL;
835 }
836 if (ret == NETMANAGER_SUCCESS) {
837 uint32_t size = 0;
838 if (!reply.ReadUint32(size)) {
839 return NETMANAGER_ERR_READ_REPLY_FAIL;
840 }
841 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
842 for (uint32_t i = 0; i < size; ++i) {
843 uint32_t value;
844 if (!reply.ReadUint32(value)) {
845 return NETMANAGER_ERR_READ_REPLY_FAIL;
846 }
847 netIdList.push_back(value);
848 }
849 }
850 return ret;
851 }
852
GetSpecificNetByIdent(NetBearType bearerType,const std::string & ident,std::list<int32_t> & netIdList)853 int32_t NetConnServiceProxy::GetSpecificNetByIdent(
854 NetBearType bearerType, const std::string &ident, std::list<int32_t> &netIdList)
855 {
856 MessageParcel data;
857 if (!WriteInterfaceToken(data)) {
858 NETMGR_LOG_E("GetSpecificNetByIdent WriteInterfaceToken failed");
859 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
860 }
861
862 uint32_t type = static_cast<uint32_t>(bearerType);
863 if (!data.WriteUint32(type)) {
864 return NETMANAGER_ERR_WRITE_DATA_FAIL;
865 }
866 if (!data.WriteString(ident)) {
867 return NETMANAGER_ERR_WRITE_DATA_FAIL;
868 }
869
870 MessageParcel reply;
871 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET_BY_IDENT),
872 data, reply);
873 if (error != NETMANAGER_SUCCESS) {
874 return error;
875 }
876
877 int32_t ret = NETMANAGER_SUCCESS;
878 if (!reply.ReadInt32(ret)) {
879 return NETMANAGER_ERR_READ_REPLY_FAIL;
880 }
881 if (ret == NETMANAGER_SUCCESS) {
882 uint32_t size = 0;
883 if (!reply.ReadUint32(size)) {
884 return NETMANAGER_ERR_READ_REPLY_FAIL;
885 }
886 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
887 for (uint32_t i = 0; i < size; ++i) {
888 uint32_t value;
889 if (!reply.ReadUint32(value)) {
890 return NETMANAGER_ERR_READ_REPLY_FAIL;
891 }
892 netIdList.push_back(value);
893 }
894 }
895 return ret;
896 }
897
GetAllNets(std::list<int32_t> & netIdList)898 int32_t NetConnServiceProxy::GetAllNets(std::list<int32_t> &netIdList)
899 {
900 MessageParcel data;
901 if (!WriteInterfaceToken(data)) {
902 NETMGR_LOG_E("WriteInterfaceToken failed");
903 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
904 }
905
906 MessageParcel reply;
907 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ALL_NETS),
908 data, reply);
909 if (error != NETMANAGER_SUCCESS) {
910 return error;
911 }
912
913 int32_t ret = NETMANAGER_SUCCESS;
914 if (!reply.ReadInt32(ret)) {
915 return NETMANAGER_ERR_READ_REPLY_FAIL;
916 }
917 if (ret == NETMANAGER_SUCCESS) {
918 uint32_t size;
919 if (!reply.ReadUint32(size)) {
920 return NETMANAGER_ERR_READ_REPLY_FAIL;
921 }
922 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
923 for (uint32_t i = 0; i < size; ++i) {
924 uint32_t value;
925 if (!reply.ReadUint32(value)) {
926 return NETMANAGER_ERR_READ_REPLY_FAIL;
927 }
928 netIdList.push_back(value);
929 }
930 }
931 return ret;
932 }
933
GetSpecificUidNet(int32_t uid,int32_t & netId)934 int32_t NetConnServiceProxy::GetSpecificUidNet(int32_t uid, int32_t &netId)
935 {
936 MessageParcel data;
937 if (!WriteInterfaceToken(data)) {
938 NETMGR_LOG_E("WriteInterfaceToken failed");
939 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
940 }
941
942 if (!data.WriteInt32(uid)) {
943 return NETMANAGER_ERR_WRITE_DATA_FAIL;
944 }
945
946 MessageParcel reply;
947 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_UID_NET),
948 data, reply);
949 if (error != NETMANAGER_SUCCESS) {
950 return error;
951 }
952
953 int32_t ret = NETMANAGER_SUCCESS;
954 if (!reply.ReadInt32(ret)) {
955 return NETMANAGER_ERR_READ_REPLY_FAIL;
956 }
957 if (ret == NETMANAGER_SUCCESS) {
958 if (!reply.ReadInt32(netId)) {
959 return NETMANAGER_ERR_READ_REPLY_FAIL;
960 }
961 }
962 return ret;
963 }
964
GetConnectionProperties(int32_t netId,NetLinkInfo & info)965 int32_t NetConnServiceProxy::GetConnectionProperties(int32_t netId, NetLinkInfo &info)
966 {
967 MessageParcel data;
968 if (!WriteInterfaceToken(data)) {
969 NETMGR_LOG_E("WriteInterfaceToken failed");
970 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
971 }
972
973 if (!data.WriteInt32(netId)) {
974 return NETMANAGER_ERR_WRITE_DATA_FAIL;
975 }
976
977 MessageParcel reply;
978 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_CONNECTION_PROPERTIES),
979 data, reply);
980 if (error != NETMANAGER_SUCCESS) {
981 return error;
982 }
983
984 int32_t ret = NETMANAGER_SUCCESS;
985 if (!reply.ReadInt32(ret)) {
986 return NETMANAGER_ERR_READ_REPLY_FAIL;
987 }
988 if (ret == NETMANAGER_SUCCESS) {
989 sptr<NetLinkInfo> netLinkInfo_ptr = NetLinkInfo::Unmarshalling(reply);
990 if (netLinkInfo_ptr != nullptr) {
991 info = *netLinkInfo_ptr;
992 }
993 }
994 return ret;
995 }
996
GetNetCapabilities(int32_t netId,NetAllCapabilities & netAllCap)997 int32_t NetConnServiceProxy::GetNetCapabilities(int32_t netId, NetAllCapabilities &netAllCap)
998 {
999 MessageParcel data;
1000 if (!WriteInterfaceToken(data)) {
1001 NETMGR_LOG_E("WriteInterfaceToken failed");
1002 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1003 }
1004
1005 if (!data.WriteInt32(netId)) {
1006 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1007 }
1008
1009 MessageParcel reply;
1010 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_CAPABILITIES),
1011 data, reply);
1012 if (error != NETMANAGER_SUCCESS) {
1013 return error;
1014 }
1015
1016 int32_t ret = NETMANAGER_SUCCESS;
1017 if (!reply.ReadInt32(ret)) {
1018 return NETMANAGER_ERR_READ_REPLY_FAIL;
1019 }
1020 return (ret == NETMANAGER_SUCCESS) ? GetNetCapData(reply, netAllCap) : ret;
1021 }
1022
GetNetCapData(MessageParcel & reply,NetAllCapabilities & netAllCap)1023 int32_t NetConnServiceProxy::GetNetCapData(MessageParcel &reply, NetAllCapabilities &netAllCap)
1024 {
1025 if (!reply.ReadUint32(netAllCap.linkUpBandwidthKbps_)) {
1026 return NETMANAGER_ERR_READ_REPLY_FAIL;
1027 }
1028 if (!reply.ReadUint32(netAllCap.linkDownBandwidthKbps_)) {
1029 return NETMANAGER_ERR_READ_REPLY_FAIL;
1030 }
1031 uint32_t size = 0;
1032 if (!reply.ReadUint32(size)) {
1033 return NETMANAGER_ERR_READ_REPLY_FAIL;
1034 }
1035 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
1036 uint32_t value = 0;
1037 for (uint32_t i = 0; i < size; ++i) {
1038 if (!reply.ReadUint32(value)) {
1039 return NETMANAGER_ERR_READ_REPLY_FAIL;
1040 }
1041 if (value < NET_CAPABILITY_END) {
1042 netAllCap.netCaps_.insert(static_cast<NetCap>(value));
1043 }
1044 }
1045 if (!reply.ReadUint32(size)) {
1046 return NETMANAGER_ERR_READ_REPLY_FAIL;
1047 }
1048 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
1049 for (uint32_t i = 0; i < size; ++i) {
1050 if (!reply.ReadUint32(value)) {
1051 return NETMANAGER_ERR_READ_REPLY_FAIL;
1052 }
1053 netAllCap.bearerTypes_.insert(static_cast<NetBearType>(value));
1054 }
1055 return NETMANAGER_SUCCESS;
1056 }
1057
GetAddressesByName(const std::string & host,int32_t netId,std::vector<INetAddr> & addrList)1058 int32_t NetConnServiceProxy::GetAddressesByName(const std::string &host, int32_t netId, std::vector<INetAddr> &addrList)
1059 {
1060 MessageParcel data;
1061 if (!WriteInterfaceToken(data)) {
1062 NETMGR_LOG_E("WriteInterfaceToken failed");
1063 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1064 }
1065 if (!data.WriteString(host)) {
1066 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1067 }
1068 if (!data.WriteInt32(netId)) {
1069 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1070 }
1071
1072 MessageParcel reply;
1073 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESSES_BY_NAME),
1074 data, reply);
1075 if (error != NETMANAGER_SUCCESS) {
1076 return error;
1077 }
1078
1079 int32_t ret = NETMANAGER_SUCCESS;
1080 if (!reply.ReadInt32(ret)) {
1081 return NETMANAGER_ERR_READ_REPLY_FAIL;
1082 }
1083
1084 if (ret == NETMANAGER_SUCCESS) {
1085 uint32_t size;
1086 if (!reply.ReadUint32(size)) {
1087 return NETMANAGER_ERR_READ_REPLY_FAIL;
1088 }
1089 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1090 for (uint32_t i = 0; i < size; ++i) {
1091 sptr<INetAddr> netaddr_ptr = INetAddr::Unmarshalling(reply);
1092 if (netaddr_ptr != nullptr) {
1093 addrList.push_back(*netaddr_ptr);
1094 }
1095 }
1096 }
1097 return ret;
1098 }
1099
GetAddressByName(const std::string & host,int32_t netId,INetAddr & addr)1100 int32_t NetConnServiceProxy::GetAddressByName(const std::string &host, int32_t netId, INetAddr &addr)
1101 {
1102 MessageParcel data;
1103 if (!WriteInterfaceToken(data)) {
1104 NETMGR_LOG_E("WriteInterfaceToken failed");
1105 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1106 }
1107
1108 if (!data.WriteString(host)) {
1109 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1110 }
1111 if (!data.WriteInt32(netId)) {
1112 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1113 }
1114
1115 MessageParcel reply;
1116 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESS_BY_NAME),
1117 data, reply);
1118 if (error != NETMANAGER_SUCCESS) {
1119 return error;
1120 }
1121 int32_t ret = NETMANAGER_SUCCESS;
1122 if (!reply.ReadInt32(ret)) {
1123 return NETMANAGER_ERR_READ_REPLY_FAIL;
1124 }
1125 if (ret == NETMANAGER_SUCCESS) {
1126 sptr<INetAddr> netaddr_ptr = INetAddr::Unmarshalling(reply);
1127 if (netaddr_ptr != nullptr) {
1128 addr = *netaddr_ptr;
1129 }
1130 }
1131 return ret;
1132 }
1133
BindSocket(int32_t socketFd,int32_t netId)1134 int32_t NetConnServiceProxy::BindSocket(int32_t socketFd, int32_t netId)
1135 {
1136 MessageParcel data;
1137 if (!WriteInterfaceToken(data)) {
1138 NETMGR_LOG_E("WriteInterfaceToken failed");
1139 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1140 }
1141
1142 if (!data.WriteInt32(socketFd)) {
1143 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1144 }
1145 if (!data.WriteInt32(netId)) {
1146 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1147 }
1148
1149 MessageParcel reply;
1150 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_BIND_SOCKET),
1151 data, reply);
1152 if (error != NETMANAGER_SUCCESS) {
1153 return error;
1154 }
1155
1156 int32_t ret = NETMANAGER_SUCCESS;
1157 if (!reply.ReadInt32(ret)) {
1158 return NETMANAGER_ERR_READ_REPLY_FAIL;
1159 }
1160 return ret;
1161 }
1162
SetAirplaneMode(bool state)1163 int32_t NetConnServiceProxy::SetAirplaneMode(bool state)
1164 {
1165 MessageParcel data;
1166 if (!WriteInterfaceToken(data)) {
1167 NETMGR_LOG_E("WriteInterfaceToken failed");
1168 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1169 }
1170
1171 if (!data.WriteBool(state)) {
1172 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1173 }
1174
1175 MessageParcel reply;
1176 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE),
1177 data, reply);
1178 if (error != NETMANAGER_SUCCESS) {
1179 return error;
1180 }
1181
1182 int32_t ret = NETMANAGER_SUCCESS;
1183 if (!reply.ReadInt32(ret)) {
1184 return NETMANAGER_ERR_READ_REPLY_FAIL;
1185 }
1186 return ret;
1187 }
1188
IsDefaultNetMetered(bool & isMetered)1189 int32_t NetConnServiceProxy::IsDefaultNetMetered(bool &isMetered)
1190 {
1191 MessageParcel data;
1192 if (!WriteInterfaceToken(data)) {
1193 NETMGR_LOG_E("WriteInterfaceToken failed");
1194 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1195 }
1196
1197 MessageParcel reply;
1198 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_DEFAULT_NET_METERED),
1199 data, reply);
1200 if (error != NETMANAGER_SUCCESS) {
1201 return error;
1202 }
1203
1204 int32_t ret = NETMANAGER_SUCCESS;
1205 if (!reply.ReadInt32(ret)) {
1206 return NETMANAGER_ERR_READ_REPLY_FAIL;
1207 }
1208 if (ret == NETMANAGER_SUCCESS) {
1209 if (!reply.ReadBool(isMetered)) {
1210 return NETMANAGER_ERR_READ_REPLY_FAIL;
1211 }
1212 }
1213 return ret;
1214 }
1215
SetGlobalHttpProxy(const HttpProxy & httpProxy)1216 int32_t NetConnServiceProxy::SetGlobalHttpProxy(const HttpProxy &httpProxy)
1217 {
1218 MessageParcel data;
1219 if (!WriteInterfaceToken(data)) {
1220 NETMGR_LOG_E("WriteInterfaceToken failed");
1221 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1222 }
1223
1224 if (!httpProxy.Marshalling(data)) {
1225 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1226 }
1227
1228 MessageParcel reply;
1229 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY),
1230 data, reply);
1231 if (error != NETMANAGER_SUCCESS) {
1232 return error;
1233 }
1234
1235 int32_t ret = NETMANAGER_SUCCESS;
1236 if (!reply.ReadInt32(ret)) {
1237 return NETMANAGER_ERR_READ_REPLY_FAIL;
1238 }
1239 return ret;
1240 }
1241
GetGlobalHttpProxy(HttpProxy & httpProxy)1242 int32_t NetConnServiceProxy::GetGlobalHttpProxy(HttpProxy &httpProxy)
1243 {
1244 MessageParcel data;
1245 if (!WriteInterfaceToken(data)) {
1246 NETMGR_LOG_E("WriteInterfaceToken failed");
1247 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1248 }
1249 if (!data.WriteInt32(httpProxy.GetUserId())) {
1250 NETMGR_LOG_E("WriteUserId failed");
1251 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1252 }
1253
1254 MessageParcel reply;
1255 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY),
1256 data, reply);
1257 if (error != NETMANAGER_SUCCESS) {
1258 return error;
1259 }
1260
1261 int32_t ret = NETMANAGER_SUCCESS;
1262 if (!reply.ReadInt32(ret)) {
1263 return NETMANAGER_ERR_READ_REPLY_FAIL;
1264 }
1265
1266 if (ret == NETMANAGER_SUCCESS) {
1267 if (!HttpProxy::Unmarshalling(reply, httpProxy)) {
1268 return NETMANAGER_ERR_READ_REPLY_FAIL;
1269 }
1270 }
1271 return ret;
1272 }
1273
GetDefaultHttpProxy(int32_t bindNetId,HttpProxy & httpProxy)1274 int32_t NetConnServiceProxy::GetDefaultHttpProxy(int32_t bindNetId, HttpProxy &httpProxy)
1275 {
1276 MessageParcel data;
1277 if (!WriteInterfaceToken(data)) {
1278 NETMGR_LOG_E("WriteInterfaceToken failed");
1279 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1280 }
1281
1282 if (!data.WriteInt32(bindNetId)) {
1283 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1284 }
1285 if (!data.WriteInt32(httpProxy.GetUserId())) {
1286 NETMGR_LOG_E("WriteUserId failed");
1287 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1288 }
1289
1290 MessageParcel reply;
1291 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_DEFAULT_HTTP_PROXY),
1292 data, reply);
1293 if (error != NETMANAGER_SUCCESS) {
1294 return error;
1295 }
1296
1297 int32_t ret = NETMANAGER_SUCCESS;
1298 if (!reply.ReadInt32(ret)) {
1299 return NETMANAGER_ERR_READ_REPLY_FAIL;
1300 }
1301
1302 if (ret == NETMANAGER_SUCCESS) {
1303 if (!HttpProxy::Unmarshalling(reply, httpProxy)) {
1304 return NETMANAGER_ERR_READ_REPLY_FAIL;
1305 }
1306 }
1307 return ret;
1308 }
1309
SetPacUrl(const std::string & pacUrl)1310 int32_t NetConnServiceProxy::SetPacUrl(const std::string &pacUrl)
1311 {
1312 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1313 return RemoteSendRequest(code, data, reply);
1314 };
1315 return NetConnServicePacProxyHelper::GetInstance(fun)->SetPacUrl(pacUrl);
1316 }
1317
GetPacUrl(std::string & pacUrl)1318 int32_t NetConnServiceProxy::GetPacUrl(std::string &pacUrl)
1319 {
1320 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1321 return RemoteSendRequest(code, data, reply);
1322 };
1323 return NetConnServicePacProxyHelper::GetInstance(fun)->GetPacUrl(pacUrl);
1324 }
1325
QueryTraceRoute(const std::string & destination,int32_t maxJumpNumber,int32_t packetsType,std::string & traceRouteInfo)1326 int32_t NetConnServiceProxy::QueryTraceRoute(
1327 const std::string &destination, int32_t maxJumpNumber, int32_t packetsType, std::string &traceRouteInfo)
1328 {
1329 MessageParcel data;
1330 if (!WriteInterfaceToken(data)) {
1331 NETMGR_LOG_E("WriteInterfaceToken failed");
1332 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1333 }
1334
1335 if (!data.WriteString(destination)) {
1336 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1337 }
1338 if (!data.WriteInt32(maxJumpNumber)) {
1339 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1340 }
1341 if (!data.WriteInt32(packetsType)) {
1342 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1343 }
1344 MessageParcel reply;
1345 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_QUERY_TRACEROUTE),
1346 data, reply);
1347 if (error != NETMANAGER_SUCCESS) {
1348 return error;
1349 }
1350
1351 int32_t ret;
1352 if (!reply.ReadInt32(ret)) {
1353 return NETMANAGER_ERR_READ_REPLY_FAIL;
1354 }
1355 if (ret == NETMANAGER_SUCCESS) {
1356 if (!reply.ReadString(traceRouteInfo)) {
1357 traceRouteInfo.clear();
1358 return NETMANAGER_ERR_READ_REPLY_FAIL;
1359 }
1360 }
1361 return ret;
1362 }
1363
SetProxyMode(const OHOS::NetManagerStandard::ProxyModeType mode)1364 int32_t NetConnServiceProxy::SetProxyMode(const OHOS::NetManagerStandard::ProxyModeType mode)
1365 {
1366 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1367 return RemoteSendRequest(code, data, reply);
1368 };
1369 return NetConnServicePacProxyHelper::GetInstance(fun)->SetProxyMode(mode);
1370 }
1371
GetProxyMode(OHOS::NetManagerStandard::ProxyModeType & mode)1372 int32_t NetConnServiceProxy::GetProxyMode(OHOS::NetManagerStandard::ProxyModeType &mode)
1373 {
1374 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1375 return RemoteSendRequest(code, data, reply);
1376 };
1377 return NetConnServicePacProxyHelper::GetInstance(fun)->GetProxyMode(mode);
1378 }
1379
SetPacFileUrl(const std::string & pacUrl)1380 int32_t NetConnServiceProxy::SetPacFileUrl(const std::string &pacUrl)
1381 {
1382 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1383 return RemoteSendRequest(code, data, reply);
1384 };
1385 return NetConnServicePacProxyHelper::GetInstance(fun)->SetPacFileUrl(pacUrl);
1386 }
1387
GetPacFileUrl(std::string & pacUrl)1388 int32_t NetConnServiceProxy::GetPacFileUrl(std::string &pacUrl)
1389 {
1390 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1391 return RemoteSendRequest(code, data, reply);
1392 };
1393 return NetConnServicePacProxyHelper::GetInstance(fun)->GetPacFileUrl(pacUrl);
1394 }
1395
FindProxyForURL(const std::string & url,const std::string & host,std::string & proxy)1396 int32_t NetConnServiceProxy::FindProxyForURL(const std::string &url, const std::string &host, std::string &proxy)
1397 {
1398 auto fun = [&](uint32_t code, MessageParcel &data, MessageParcel &reply) {
1399 return RemoteSendRequest(code, data, reply);
1400 };
1401 return NetConnServicePacProxyHelper::GetInstance(fun)->FindProxyForURL(url, host, proxy);
1402 }
1403
GetNetIdByIdentifier(const std::string & ident,std::list<int32_t> & netIdList)1404 int32_t NetConnServiceProxy::GetNetIdByIdentifier(const std::string &ident, std::list<int32_t> &netIdList)
1405 {
1406 MessageParcel data;
1407 if (!WriteInterfaceToken(data)) {
1408 NETMGR_LOG_E("WriteInterfaceToken failed");
1409 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1410 }
1411
1412 if (!data.WriteString(ident)) {
1413 NETMGR_LOG_E("Write string data failed");
1414 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1415 }
1416
1417 MessageParcel reply;
1418 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_ID_BY_IDENTIFIER),
1419 data, reply);
1420 if (error != NETMANAGER_SUCCESS) {
1421 return error;
1422 }
1423
1424 int32_t ret = NETMANAGER_SUCCESS;
1425 if (!reply.ReadInt32(ret)) {
1426 NETMGR_LOG_E("Read return code failed");
1427 return NETMANAGER_ERR_READ_REPLY_FAIL;
1428 }
1429
1430 if (ret == NETMANAGER_SUCCESS) {
1431 uint32_t size = 0;
1432 if (!reply.ReadUint32(size)) {
1433 return NETMANAGER_ERR_READ_REPLY_FAIL;
1434 }
1435 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1436 int32_t value = 0;
1437 for (uint32_t i = 0; i < size; ++i) {
1438 if (!reply.ReadInt32(value)) {
1439 return NETMANAGER_ERR_READ_REPLY_FAIL;
1440 }
1441 netIdList.push_back(value);
1442 }
1443 }
1444 return ret;
1445 }
1446
SetAppNet(int32_t netId)1447 int32_t NetConnServiceProxy::SetAppNet(int32_t netId)
1448 {
1449 MessageParcel data;
1450 if (!WriteInterfaceToken(data)) {
1451 NETMGR_LOG_E("WriteInterfaceToken failed");
1452 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1453 }
1454
1455 if (!data.WriteInt32(netId)) {
1456 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1457 }
1458
1459 MessageParcel reply;
1460 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_NET),
1461 data, reply);
1462 if (error != NETMANAGER_SUCCESS) {
1463 return error;
1464 }
1465
1466 int32_t ret = NETMANAGER_SUCCESS;
1467 if (!reply.ReadInt32(ret)) {
1468 return NETMANAGER_ERR_READ_REPLY_FAIL;
1469 }
1470 return ret;
1471 }
1472
RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> & callback)1473 int32_t NetConnServiceProxy::RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback)
1474 {
1475 if (callback == nullptr) {
1476 NETMGR_LOG_E("The parameter of callback is nullptr");
1477 return NETMANAGER_ERR_LOCAL_PTR_NULL;
1478 }
1479
1480 MessageParcel dataParcel;
1481 if (!WriteInterfaceToken(dataParcel)) {
1482 NETMGR_LOG_E("WriteInterfaceToken failed");
1483 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1484 }
1485 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1486
1487 MessageParcel replyParcel;
1488 int32_t retCode = RemoteSendRequest(
1489 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_INTERFACE_CALLBACK),
1490 dataParcel, replyParcel);
1491 if (retCode != NETMANAGER_SUCCESS) {
1492 return retCode;
1493 }
1494 return replyParcel.ReadInt32();
1495 }
1496
UnregisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> & callback)1497 int32_t NetConnServiceProxy::UnregisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback)
1498 {
1499 if (callback == nullptr) {
1500 NETMGR_LOG_E("The parameter of callback is nullptr");
1501 return NETMANAGER_ERR_LOCAL_PTR_NULL;
1502 }
1503
1504 MessageParcel dataParcel;
1505 if (!WriteInterfaceToken(dataParcel)) {
1506 NETMGR_LOG_E("WriteInterfaceToken failed");
1507 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1508 }
1509 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1510
1511 MessageParcel replyParcel;
1512 int32_t retCode = RemoteSendRequest(
1513 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_INTERFACE_CALLBACK),
1514 dataParcel, replyParcel);
1515 if (retCode != NETMANAGER_SUCCESS) {
1516 return retCode;
1517 }
1518 return replyParcel.ReadInt32();
1519 }
1520
GetNetInterfaceConfiguration(const std::string & iface,NetInterfaceConfiguration & config)1521 int32_t NetConnServiceProxy::GetNetInterfaceConfiguration(const std::string &iface, NetInterfaceConfiguration &config)
1522 {
1523 MessageParcel data;
1524 if (!WriteInterfaceToken(data)) {
1525 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1526 }
1527 if (!data.WriteString(iface)) {
1528 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1529 }
1530 MessageParcel reply;
1531 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_INTERFACE_CONFIGURATION),
1532 data, reply);
1533 if (error != NETMANAGER_SUCCESS) {
1534 return error;
1535 }
1536 int32_t ret = NETMANAGER_SUCCESS;
1537 if (!reply.ReadInt32(ret)) {
1538 return NETMANAGER_ERR_READ_REPLY_FAIL;
1539 }
1540 if (ret == NETMANAGER_SUCCESS) {
1541 if (!NetInterfaceConfiguration::Unmarshalling(reply, config)) {
1542 return NETMANAGER_ERR_READ_REPLY_FAIL;
1543 }
1544 }
1545 return ret;
1546 }
1547
SetNetInterfaceIpAddress(const std::string & iface,const std::string & ipAddress)1548 int32_t NetConnServiceProxy::SetNetInterfaceIpAddress(const std::string &iface, const std::string &ipAddress)
1549 {
1550 MessageParcel data;
1551 if (!WriteInterfaceToken(data)) {
1552 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1553 }
1554 if (!data.WriteString(iface)) {
1555 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1556 }
1557 if (!data.WriteString(ipAddress)) {
1558 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1559 }
1560 MessageParcel reply;
1561 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_IP_ADDRESS),
1562 data, reply);
1563 if (error != NETMANAGER_SUCCESS) {
1564 return error;
1565 }
1566 int32_t ret = NETMANAGER_SUCCESS;
1567 if (!reply.ReadInt32(ret)) {
1568 return NETMANAGER_ERR_READ_REPLY_FAIL;
1569 }
1570 return ret;
1571 }
1572
SetInterfaceUp(const std::string & iface)1573 int32_t NetConnServiceProxy::SetInterfaceUp(const std::string &iface)
1574 {
1575 MessageParcel data;
1576 if (!WriteInterfaceToken(data)) {
1577 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1578 }
1579 if (!data.WriteString(iface)) {
1580 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1581 }
1582 MessageParcel reply;
1583 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_UP),
1584 data, reply);
1585 if (error != NETMANAGER_SUCCESS) {
1586 return error;
1587 }
1588 int32_t ret = NETMANAGER_SUCCESS;
1589 if (!reply.ReadInt32(ret)) {
1590 return NETMANAGER_ERR_READ_REPLY_FAIL;
1591 }
1592 return ret;
1593 }
1594
SetInterfaceDown(const std::string & iface)1595 int32_t NetConnServiceProxy::SetInterfaceDown(const std::string &iface)
1596 {
1597 MessageParcel data;
1598 if (!WriteInterfaceToken(data)) {
1599 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1600 }
1601 if (!data.WriteString(iface)) {
1602 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1603 }
1604 MessageParcel reply;
1605 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_DOWN),
1606 data, reply);
1607 if (error != NETMANAGER_SUCCESS) {
1608 return error;
1609 }
1610 int32_t ret = NETMANAGER_SUCCESS;
1611 if (!reply.ReadInt32(ret)) {
1612 return NETMANAGER_ERR_READ_REPLY_FAIL;
1613 }
1614 return ret;
1615 }
1616
RemoteSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)1617 int32_t NetConnServiceProxy::RemoteSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
1618 {
1619 sptr<IRemoteObject> remote = Remote();
1620 if (remote == nullptr) {
1621 NETMGR_LOG_E("Remote is null");
1622 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1623 }
1624
1625 MessageOption option;
1626 int32_t error = remote->SendRequest(code, data, reply, option);
1627 if (error != ERR_NONE) {
1628 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
1629 return NETMANAGER_ERR_OPERATION_FAILED;
1630 }
1631
1632 return NETMANAGER_SUCCESS;
1633 }
1634
AddNetworkRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)1635 int32_t NetConnServiceProxy::AddNetworkRoute(int32_t netId, const std::string &ifName,
1636 const std::string &destination, const std::string &nextHop)
1637 {
1638 MessageParcel data;
1639 MessageParcel reply;
1640 if (!WriteInterfaceToken(data)) {
1641 NETMGR_LOG_E("WriteInterfaceToken failed");
1642 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1643 }
1644
1645 if (!data.WriteInt32(netId)) {
1646 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1647 }
1648
1649 if (!data.WriteString(ifName)) {
1650 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1651 }
1652
1653 if (!data.WriteString(destination)) {
1654 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1655 }
1656
1657 if (!data.WriteString(nextHop)) {
1658 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1659 }
1660
1661 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ROUTE),
1662 data, reply);
1663 if (error != NETMANAGER_SUCCESS) {
1664 return error;
1665 }
1666
1667 return reply.ReadInt32();
1668 }
1669
RemoveNetworkRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)1670 int32_t NetConnServiceProxy::RemoveNetworkRoute(int32_t netId, const std::string &ifName,
1671 const std::string &destination, const std::string &nextHop)
1672 {
1673 MessageParcel data;
1674 MessageParcel reply;
1675 if (!WriteInterfaceToken(data)) {
1676 NETMGR_LOG_E("WriteInterfaceToken failed");
1677 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1678 }
1679
1680 if (!data.WriteInt32(netId)) {
1681 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1682 }
1683
1684 if (!data.WriteString(ifName)) {
1685 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1686 }
1687
1688 if (!data.WriteString(destination)) {
1689 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1690 }
1691
1692 if (!data.WriteString(nextHop)) {
1693 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1694 }
1695
1696 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ROUTE),
1697 data, reply);
1698 if (error != NETMANAGER_SUCCESS) {
1699 return error;
1700 }
1701
1702 return reply.ReadInt32();
1703 }
1704
AddInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)1705 int32_t NetConnServiceProxy::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
1706 int32_t prefixLength)
1707 {
1708 MessageParcel data;
1709 MessageParcel reply;
1710 if (!WriteInterfaceToken(data)) {
1711 NETMGR_LOG_E("WriteInterfaceToken failed");
1712 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1713 }
1714
1715 if (!data.WriteString(ifName)) {
1716 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1717 }
1718
1719 if (!data.WriteString(ipAddr)) {
1720 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1721 }
1722
1723 if (!data.WriteInt32(prefixLength)) {
1724 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1725 }
1726
1727 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ADDRESS),
1728 data, reply);
1729 if (error != NETMANAGER_SUCCESS) {
1730 return error;
1731 }
1732
1733 return reply.ReadInt32();
1734 }
1735
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)1736 int32_t NetConnServiceProxy::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
1737 int32_t prefixLength)
1738 {
1739 MessageParcel data;
1740 MessageParcel reply;
1741 if (!WriteInterfaceToken(data)) {
1742 NETMGR_LOG_E("WriteInterfaceToken failed");
1743 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1744 }
1745
1746 if (!data.WriteString(ifName)) {
1747 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1748 }
1749
1750 if (!data.WriteString(ipAddr)) {
1751 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1752 }
1753
1754 if (!data.WriteInt32(prefixLength)) {
1755 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1756 }
1757
1758 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ADDRESS),
1759 data, reply);
1760 if (error != NETMANAGER_SUCCESS) {
1761 return error;
1762 }
1763
1764 return reply.ReadInt32();
1765 }
1766
AddStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)1767 int32_t NetConnServiceProxy::AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
1768 const std::string &ifName)
1769 {
1770 MessageParcel data;
1771 MessageParcel reply;
1772 if (!WriteInterfaceToken(data)) {
1773 NETMGR_LOG_E("WriteInterfaceToken failed");
1774 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1775 }
1776
1777 if (!data.WriteString(ipAddr)) {
1778 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1779 }
1780
1781 if (!data.WriteString(macAddr)) {
1782 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1783 }
1784
1785 if (!data.WriteString(ifName)) {
1786 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1787 }
1788
1789 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_STATIC_ARP),
1790 data, reply);
1791 if (error != NETMANAGER_SUCCESS) {
1792 return error;
1793 }
1794
1795 return reply.ReadInt32();
1796 }
1797
DelStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)1798 int32_t NetConnServiceProxy::DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
1799 const std::string &ifName)
1800 {
1801 MessageParcel data;
1802 MessageParcel reply;
1803 if (!WriteInterfaceToken(data)) {
1804 NETMGR_LOG_E("WriteInterfaceToken failed");
1805 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1806 }
1807
1808 if (!data.WriteString(ipAddr)) {
1809 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1810 }
1811
1812 if (!data.WriteString(macAddr)) {
1813 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1814 }
1815
1816 if (!data.WriteString(ifName)) {
1817 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1818 }
1819
1820 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DEL_STATIC_ARP),
1821 data, reply);
1822 if (error != NETMANAGER_SUCCESS) {
1823 return error;
1824 }
1825
1826 return reply.ReadInt32();
1827 }
1828
AddStaticIpv6Addr(const std::string & ipv6Addr,const std::string & macAddr,const std::string & ifName)1829 int32_t NetConnServiceProxy::AddStaticIpv6Addr(const std::string &ipv6Addr, const std::string &macAddr,
1830 const std::string &ifName)
1831 {
1832 MessageParcel data;
1833 MessageParcel reply;
1834 if (!WriteInterfaceToken(data)) {
1835 NETMGR_LOG_E("WriteInterfaceToken failed");
1836 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1837 }
1838
1839 if (!data.WriteString(ipv6Addr)) {
1840 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1841 }
1842
1843 if (!data.WriteString(macAddr)) {
1844 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1845 }
1846
1847 if (!data.WriteString(ifName)) {
1848 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1849 }
1850
1851 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_STATIC_IPV6),
1852 data, reply);
1853 if (error != NETMANAGER_SUCCESS) {
1854 return error;
1855 }
1856
1857 int32_t ret = NETMANAGER_SUCCESS;
1858 if (!reply.ReadInt32(ret)) {
1859 return NETMANAGER_ERR_READ_REPLY_FAIL;
1860 }
1861 return ret;
1862 }
1863
DelStaticIpv6Addr(const std::string & ipv6Addr,const std::string & macAddr,const std::string & ifName)1864 int32_t NetConnServiceProxy::DelStaticIpv6Addr(const std::string &ipv6Addr, const std::string &macAddr,
1865 const std::string &ifName)
1866 {
1867 MessageParcel data;
1868 MessageParcel reply;
1869 if (!WriteInterfaceToken(data)) {
1870 NETMGR_LOG_E("WriteInterfaceToken failed");
1871 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1872 }
1873
1874 if (!data.WriteString(ipv6Addr)) {
1875 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1876 }
1877
1878 if (!data.WriteString(macAddr)) {
1879 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1880 }
1881
1882 if (!data.WriteString(ifName)) {
1883 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1884 }
1885
1886 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DEL_STATIC_IPV6),
1887 data, reply);
1888 if (error != NETMANAGER_SUCCESS) {
1889 return error;
1890 }
1891
1892 int32_t ret = NETMANAGER_SUCCESS;
1893 if (!reply.ReadInt32(ret)) {
1894 return NETMANAGER_ERR_READ_REPLY_FAIL;
1895 }
1896 return ret;
1897 }
1898
RegisterSlotType(uint32_t supplierId,int32_t type)1899 int32_t NetConnServiceProxy::RegisterSlotType(uint32_t supplierId, int32_t type)
1900 {
1901 MessageParcel data;
1902 MessageParcel reply;
1903 if (!WriteInterfaceToken(data)) {
1904 NETMGR_LOG_E("WriteInterfaceToken failed");
1905 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1906 }
1907
1908 if (!data.WriteUint32(supplierId)) {
1909 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1910 }
1911
1912 if (!data.WriteInt32(type)) {
1913 return NETMANAGER_ERR_WRITE_DATA_FAIL;
1914 }
1915
1916 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_SLOT_TYPE),
1917 data, reply);
1918 if (error != NETMANAGER_SUCCESS) {
1919 return error;
1920 }
1921
1922 return reply.ReadInt32();
1923 }
1924
GetSlotType(std::string & type)1925 int32_t NetConnServiceProxy::GetSlotType(std::string &type)
1926 {
1927 MessageParcel data;
1928 MessageParcel reply;
1929 if (!WriteInterfaceToken(data)) {
1930 NETMGR_LOG_E("WriteInterfaceToken failed");
1931 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1932 }
1933
1934 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SLOT_TYPE),
1935 data, reply);
1936 if (error != NETMANAGER_SUCCESS) {
1937 return error;
1938 }
1939 int32_t ret = reply.ReadInt32();
1940 if (ret == NETMANAGER_SUCCESS) {
1941 if (!reply.ReadString(type)) {
1942 return NETMANAGER_ERR_READ_REPLY_FAIL;
1943 }
1944 }
1945 return ret;
1946 }
1947
FactoryResetNetwork()1948 int32_t NetConnServiceProxy::FactoryResetNetwork()
1949 {
1950 MessageParcel data;
1951 if (!WriteInterfaceToken(data)) {
1952 NETMGR_LOG_E("WriteInterfaceToken failed");
1953 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1954 }
1955
1956 MessageParcel reply;
1957 int32_t error =
1958 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FACTORYRESET_NETWORK), data, reply);
1959 if (error != NETMANAGER_SUCCESS) {
1960 return error;
1961 }
1962
1963 int32_t ret = NETMANAGER_SUCCESS;
1964 if (!reply.ReadInt32(ret)) {
1965 return NETMANAGER_ERR_READ_REPLY_FAIL;
1966 }
1967 return ret;
1968 }
1969
RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> & callback)1970 int32_t NetConnServiceProxy::RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> &callback)
1971 {
1972 if (callback == nullptr) {
1973 NETMGR_LOG_E("The parameter of callback is nullptr");
1974 return NETMANAGER_ERR_LOCAL_PTR_NULL;
1975 }
1976
1977 MessageParcel dataParcel;
1978 if (!WriteInterfaceToken(dataParcel)) {
1979 NETMGR_LOG_E("WriteInterfaceToken failed");
1980 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1981 }
1982 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1983
1984 MessageParcel replyParcel;
1985 int32_t retCode = RemoteSendRequest(
1986 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_FACTORYRESET_CALLBACK), dataParcel, replyParcel);
1987 if (retCode != NETMANAGER_SUCCESS) {
1988 return retCode;
1989 }
1990 return replyParcel.ReadInt32();
1991 }
1992
IsPreferCellularUrl(const std::string & url,bool & preferCellular)1993 int32_t NetConnServiceProxy::IsPreferCellularUrl(const std::string& url, bool& preferCellular)
1994 {
1995 MessageParcel data;
1996 MessageParcel reply;
1997 if (!WriteInterfaceToken(data)) {
1998 NETMGR_LOG_E("WriteInterfaceToken failed");
1999 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2000 }
2001 if (!data.WriteString(url)) {
2002 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2003 }
2004 int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_PREFER_CELLULAR_URL),
2005 data, reply);
2006 if (error != NETMANAGER_SUCCESS) {
2007 return error;
2008 }
2009 int32_t ret = reply.ReadInt32();
2010 if (ret == NETMANAGER_SUCCESS) {
2011 if (!reply.ReadBool(preferCellular)) {
2012 return NETMANAGER_ERR_READ_REPLY_FAIL;
2013 }
2014 }
2015 return ret;
2016 }
2017
RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)2018 int32_t NetConnServiceProxy::RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)
2019 {
2020 if (callback == nullptr) {
2021 NETMGR_LOG_E("The parameter of callback is nullptr");
2022 return NETMANAGER_ERR_LOCAL_PTR_NULL;
2023 }
2024
2025 MessageParcel dataParcel;
2026 if (!WriteInterfaceToken(dataParcel)) {
2027 NETMGR_LOG_E("WriteInterfaceToken failed");
2028 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2029 }
2030 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
2031
2032 MessageParcel replyParcel;
2033 int32_t retCode = RemoteSendRequest(
2034 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_PREAIRPLANE_CALLBACK), dataParcel, replyParcel);
2035 if (retCode != NETMANAGER_SUCCESS) {
2036 return retCode;
2037 }
2038 return replyParcel.ReadInt32();
2039 }
2040
UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)2041 int32_t NetConnServiceProxy::UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)
2042 {
2043 if (callback == nullptr) {
2044 NETMGR_LOG_E("The parameter of callback is nullptr");
2045 return NETMANAGER_ERR_LOCAL_PTR_NULL;
2046 }
2047
2048 MessageParcel dataParcel;
2049 if (!WriteInterfaceToken(dataParcel)) {
2050 NETMGR_LOG_E("WriteInterfaceToken failed");
2051 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2052 }
2053 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
2054
2055 MessageParcel replyParcel;
2056 int32_t retCode = RemoteSendRequest(
2057 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_PREAIRPLANE_CALLBACK), dataParcel, replyParcel);
2058 if (retCode != NETMANAGER_SUCCESS) {
2059 return retCode;
2060 }
2061 return replyParcel.ReadInt32();
2062 }
2063
UpdateSupplierScore(uint32_t supplierId,uint32_t detectionStatus)2064 int32_t NetConnServiceProxy::UpdateSupplierScore(uint32_t supplierId, uint32_t detectionStatus)
2065 {
2066 MessageParcel data;
2067 MessageParcel reply;
2068 if (!WriteInterfaceToken(data)) {
2069 NETMGR_LOG_E("WriteInterfaceToken failed");
2070 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2071 }
2072 if (!data.WriteUint32(supplierId)) {
2073 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2074 }
2075 if (!data.WriteUint32(detectionStatus)) {
2076 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2077 }
2078 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_SUPPLIER_SCORE),
2079 data, reply);
2080 if (retCode != NETMANAGER_SUCCESS) {
2081 return retCode;
2082 }
2083 int32_t ret;
2084 if (!reply.ReadInt32(ret)) {
2085 return NETMANAGER_ERR_READ_REPLY_FAIL;
2086 }
2087 return ret;
2088 }
2089
GetDefaultSupplierId(NetBearType bearerType,const std::string & ident,uint32_t & supplierId)2090 int32_t NetConnServiceProxy::GetDefaultSupplierId(NetBearType bearerType, const std::string &ident,
2091 uint32_t& supplierId)
2092 {
2093 MessageParcel data;
2094 MessageParcel reply;
2095 if (!WriteInterfaceToken(data)) {
2096 NETMGR_LOG_E("WriteInterfaceToken failed");
2097 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2098 }
2099 uint32_t type = static_cast<uint32_t>(bearerType);
2100 if (!data.WriteUint32(type)) {
2101 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2102 }
2103 if (!data.WriteString(ident)) {
2104 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2105 }
2106 if (!data.WriteUint32(supplierId)) {
2107 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2108 }
2109 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_SUPPLIER_ID),
2110 data, reply);
2111 if (retCode != NETMANAGER_SUCCESS) {
2112 return retCode;
2113 }
2114 int32_t ret;
2115 if (!reply.ReadInt32(ret)) {
2116 return NETMANAGER_ERR_READ_REPLY_FAIL;
2117 }
2118 if (ret == NETMANAGER_SUCCESS) {
2119 if (!reply.ReadUint32(supplierId)) {
2120 return NETMANAGER_ERR_READ_REPLY_FAIL;
2121 }
2122 }
2123 return ret;
2124 }
2125
CloseSocketsUid(int32_t netId,uint32_t uid)2126 int32_t NetConnServiceProxy::CloseSocketsUid(int32_t netId, uint32_t uid)
2127 {
2128 MessageParcel data;
2129 MessageParcel reply;
2130 if (!WriteInterfaceToken(data)) {
2131 NETMGR_LOG_E("WriteInterfaceToken failed");
2132 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2133 }
2134 if (!data.WriteInt32(netId)) {
2135 NETMGR_LOG_E("WriteInt32 failed");
2136 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2137 }
2138 if (!data.WriteUint32(uid)) {
2139 NETMGR_LOG_E("WriteUint32 failed");
2140 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2141 }
2142 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_CLOSE_SOCKETS_UID),
2143 data, reply);
2144 if (retCode != NETMANAGER_SUCCESS) {
2145 return retCode;
2146 }
2147 return reply.ReadInt32();
2148 }
2149
SetAppIsFrozened(uint32_t uid,bool isFrozened)2150 int32_t NetConnServiceProxy::SetAppIsFrozened(uint32_t uid, bool isFrozened)
2151 {
2152 MessageParcel data;
2153 MessageParcel reply;
2154 if (!WriteInterfaceToken(data)) {
2155 NETMGR_LOG_E("WriteInterfaceToken failed");
2156 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2157 }
2158 if (!data.WriteUint32(uid)) {
2159 NETMGR_LOG_E("WriteInt32 failed");
2160 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2161 }
2162 if (!data.WriteBool(isFrozened)) {
2163 NETMGR_LOG_E("WriteBool failed");
2164 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2165 }
2166 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_IS_FROZENED),
2167 data, reply);
2168 if (retCode != NETMANAGER_SUCCESS) {
2169 return retCode;
2170 }
2171 return reply.ReadInt32();
2172 }
2173
EnableAppFrozenedCallbackLimitation(bool flag)2174 int32_t NetConnServiceProxy::EnableAppFrozenedCallbackLimitation(bool flag)
2175 {
2176 MessageParcel data;
2177 MessageParcel reply;
2178 if (!WriteInterfaceToken(data)) {
2179 NETMGR_LOG_E("WriteInterfaceToken failed");
2180 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2181 }
2182 if (!data.WriteBool(flag)) {
2183 NETMGR_LOG_E("WriteBool failed");
2184 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2185 }
2186 int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(
2187 ConnInterfaceCode::CMD_NM_ENABLE_APP_FROZENED_CALLBACK_LIMITATION), data, reply);
2188 if (retCode != NETMANAGER_SUCCESS) {
2189 return retCode;
2190 }
2191 return reply.ReadInt32();
2192 }
2193
SetReuseSupplierId(uint32_t supplierId,uint32_t reuseSupplierId,bool isReused)2194 int32_t NetConnServiceProxy::SetReuseSupplierId(uint32_t supplierId, uint32_t reuseSupplierId, bool isReused)
2195 {
2196 MessageParcel data;
2197 MessageParcel reply;
2198 if (!WriteInterfaceToken(data)) {
2199 NETMGR_LOG_E("WriteInterfaceToken failed");
2200 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2201 }
2202 if (!data.WriteUint32(supplierId)) {
2203 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2204 }
2205 if (!data.WriteUint32(reuseSupplierId)) {
2206 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2207 }
2208 if (!data.WriteBool(isReused)) {
2209 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2210 }
2211 int32_t error =
2212 RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_REUSE_SUPPLIER_ID), data, reply);
2213 if (error != NETMANAGER_SUCCESS) {
2214 return error;
2215 }
2216 return reply.ReadInt32();
2217 }
2218
GetNetExtAttribute(int32_t netId,std::string & netExtAttribute)2219 int32_t NetConnServiceProxy::GetNetExtAttribute(int32_t netId, std::string &netExtAttribute)
2220 {
2221 MessageParcel data;
2222 if (!WriteInterfaceToken(data)) {
2223 NETMGR_LOG_E("WriteInterfaceToken failed");
2224 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2225 }
2226
2227 if (!data.WriteInt32(netId)) {
2228 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2229 }
2230 if (!data.WriteString(netExtAttribute)) {
2231 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2232 }
2233
2234 MessageParcel reply;
2235 int32_t ret = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_EXT_ATTRIBUTE),
2236 data, reply);
2237 if (ret != NETMANAGER_SUCCESS) {
2238 return ret;
2239 }
2240
2241 if (!reply.ReadInt32(ret)) {
2242 return NETMANAGER_ERR_READ_REPLY_FAIL;
2243 }
2244 if (ret == NETMANAGER_SUCCESS) {
2245 if (!reply.ReadString(netExtAttribute)) {
2246 return NETMANAGER_ERR_READ_REPLY_FAIL;
2247 }
2248 }
2249 return ret;
2250 }
2251
SetNetExtAttribute(int32_t netId,const std::string & netExtAttribute)2252 int32_t NetConnServiceProxy::SetNetExtAttribute(int32_t netId, const std::string &netExtAttribute)
2253 {
2254 MessageParcel data;
2255 if (!WriteInterfaceToken(data)) {
2256 NETMGR_LOG_E("WriteInterfaceToken failed");
2257 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
2258 }
2259
2260 if (!data.WriteInt32(netId)) {
2261 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2262 }
2263 if (!data.WriteString(netExtAttribute)) {
2264 return NETMANAGER_ERR_WRITE_DATA_FAIL;
2265 }
2266
2267 MessageParcel reply;
2268 int32_t ret = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_EXT_ATTRIBUTE),
2269 data, reply);
2270 if (ret != NETMANAGER_SUCCESS) {
2271 return ret;
2272 }
2273
2274 return reply.ReadInt32();
2275 }
2276
2277 } // namespace NetManagerStandard
2278 } // namespace OHOS
2279