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 
22 namespace OHOS {
23 namespace NetManagerStandard {
24 static constexpr uint32_t MAX_IFACE_NUM = 16;
25 static constexpr uint32_t MAX_NET_CAP_NUM = 32;
26 
NetConnServiceProxy(const sptr<IRemoteObject> & impl)27 NetConnServiceProxy::NetConnServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<INetConnService>(impl) {}
28 
~NetConnServiceProxy()29 NetConnServiceProxy::~NetConnServiceProxy() {}
30 
SystemReady()31 int32_t NetConnServiceProxy::SystemReady()
32 {
33     MessageParcel data;
34     MessageParcel reply;
35     if (!WriteInterfaceToken(data)) {
36         NETMGR_LOG_E("WriteInterfaceToken failed");
37         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
38     }
39 
40     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SYSTEM_READY), data, reply);
41     if (error != NETMANAGER_SUCCESS) {
42         return error;
43     }
44 
45     return NETMANAGER_SUCCESS;
46 }
47 
SetInternetPermission(uint32_t uid,uint8_t allow)48 int32_t NetConnServiceProxy::SetInternetPermission(uint32_t uid, uint8_t allow)
49 {
50     MessageParcel data;
51     MessageParcel reply;
52     if (!WriteInterfaceToken(data)) {
53         NETMGR_LOG_E("WriteInterfaceToken failed");
54         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
55     }
56 
57     NETMGR_LOG_D("proxy SetInternetPermission [%{public}u %{public}hhu]", uid, allow);
58     if (!data.WriteUint32(uid)) {
59         return NETMANAGER_ERR_WRITE_DATA_FAIL;
60     }
61     if (!data.WriteUint8(allow)) {
62         return NETMANAGER_ERR_WRITE_DATA_FAIL;
63     }
64     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION),
65                                       data, reply);
66     if (error != NETMANAGER_SUCCESS) {
67         return error;
68     }
69 
70     return reply.ReadInt32();
71 }
72 
EnableVnicNetwork(const sptr<NetLinkInfo> & netLinkInfo,const std::set<int32_t> & uids)73 int32_t NetConnServiceProxy::EnableVnicNetwork(const sptr<NetLinkInfo> &netLinkInfo, const std::set<int32_t> &uids)
74 {
75     if (netLinkInfo == nullptr) {
76         NETMGR_LOG_E("netLinkInfo is null");
77         return NETMANAGER_ERR_LOCAL_PTR_NULL;
78     }
79 
80     MessageParcel data;
81     MessageParcel reply;
82     if (!WriteInterfaceToken(data)) {
83         NETMGR_LOG_E("WriteInterfaceToken failed");
84         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
85     }
86 
87     if (!netLinkInfo->Marshalling(data)) {
88         NETMGR_LOG_E("proxy Marshalling failed");
89         return NETMANAGER_ERR_WRITE_DATA_FAIL;
90     }
91 
92     if (!data.WriteInt32(uids.size())) {
93         return NETMANAGER_ERR_READ_DATA_FAIL;
94     }
95 
96     for (const auto &uid: uids) {
97         if (!data.WriteInt32(uid)) {
98             return NETMANAGER_ERR_READ_DATA_FAIL;
99         }
100     }
101 
102     int32_t error =
103         RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_VNIC_NET_WORK), data, reply);
104     if (error != NETMANAGER_SUCCESS) {
105         return error;
106     }
107 
108     int32_t ret;
109     if (!reply.ReadInt32(ret)) {
110         return NETMANAGER_ERR_READ_REPLY_FAIL;
111     }
112     return ret;
113 }
114 
DisableVnicNetwork()115 int32_t NetConnServiceProxy::DisableVnicNetwork()
116 {
117     MessageParcel data;
118     MessageParcel reply;
119     if (!WriteInterfaceToken(data)) {
120         NETMGR_LOG_E("WriteInterfaceToken failed");
121         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
122     }
123 
124     int32_t error =
125         RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_VNIC_NET_WORK), data, reply);
126     if (error != NETMANAGER_SUCCESS) {
127         return error;
128     }
129 
130     int32_t ret;
131     if (!reply.ReadInt32(ret)) {
132         return NETMANAGER_ERR_READ_REPLY_FAIL;
133     }
134     return ret;
135 }
136 
RegisterNetSupplier(NetBearType bearerType,const std::string & ident,const std::set<NetCap> & netCaps,uint32_t & supplierId)137 int32_t NetConnServiceProxy::RegisterNetSupplier(NetBearType bearerType, const std::string &ident,
138                                                  const std::set<NetCap> &netCaps, uint32_t &supplierId)
139 {
140     MessageParcel data;
141     MessageParcel reply;
142     if (!WriteInterfaceToken(data)) {
143         NETMGR_LOG_E("WriteInterfaceToken failed");
144         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
145     }
146 
147     if (!data.WriteUint32(static_cast<uint32_t>(bearerType))) {
148         return NETMANAGER_ERR_WRITE_DATA_FAIL;
149     }
150 
151     if (!data.WriteString(ident)) {
152         return NETMANAGER_ERR_WRITE_DATA_FAIL;
153     }
154 
155     uint32_t size = static_cast<uint32_t>(netCaps.size());
156     if (!data.WriteUint32(size)) {
157         return NETMANAGER_ERR_WRITE_DATA_FAIL;
158     }
159     for (auto netCap : netCaps) {
160         if (!data.WriteUint32(static_cast<uint32_t>(netCap))) {
161             return NETMANAGER_ERR_WRITE_DATA_FAIL;
162         }
163     }
164 
165     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REG_NET_SUPPLIER), data, reply);
166     if (error != NETMANAGER_SUCCESS) {
167         return error;
168     }
169 
170     int32_t ret;
171     if (!reply.ReadInt32(ret)) {
172         return NETMANAGER_ERR_READ_REPLY_FAIL;
173     }
174     if (ret == NETMANAGER_SUCCESS) {
175         if (!reply.ReadUint32(supplierId)) {
176             return NETMANAGER_ERR_READ_REPLY_FAIL;
177         }
178     }
179     return ret;
180 }
181 
UnregisterNetSupplier(uint32_t supplierId)182 int32_t NetConnServiceProxy::UnregisterNetSupplier(uint32_t supplierId)
183 {
184     MessageParcel data;
185     MessageParcel reply;
186     if (!WriteInterfaceToken(data)) {
187         NETMGR_LOG_E("WriteInterfaceToken failed");
188         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
189     }
190 
191     NETMGR_LOG_D("proxy supplierId[%{public}d]", supplierId);
192     if (!data.WriteUint32(supplierId)) {
193         return NETMANAGER_ERR_WRITE_DATA_FAIL;
194     }
195 
196     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREG_NETWORK), data, reply);
197     if (error != NETMANAGER_SUCCESS) {
198         return error;
199     }
200 
201     return reply.ReadInt32();
202 }
203 
RegisterNetSupplierCallback(uint32_t supplierId,const sptr<INetSupplierCallback> & callback)204 int32_t NetConnServiceProxy::RegisterNetSupplierCallback(uint32_t supplierId,
205                                                          const sptr<INetSupplierCallback> &callback)
206 {
207     if (callback == nullptr) {
208         NETMGR_LOG_E("The parameter of callback is nullptr");
209         return NETMANAGER_ERR_LOCAL_PTR_NULL;
210     }
211 
212     MessageParcel dataParcel;
213     if (!WriteInterfaceToken(dataParcel)) {
214         NETMGR_LOG_E("WriteInterfaceToken failed");
215         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
216     }
217     dataParcel.WriteUint32(supplierId);
218     dataParcel.WriteRemoteObject(callback->AsObject());
219 
220     MessageParcel replyParcel;
221     int32_t retCode = RemoteSendRequest(
222         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_SUPPLIER_CALLBACK), dataParcel, replyParcel);
223     if (retCode != NETMANAGER_SUCCESS) {
224         return retCode;
225     }
226     NETMGR_LOG_I("SendRequest retCode:[%{public}d]", retCode);
227     return replyParcel.ReadInt32();
228 }
229 
RegisterNetConnCallback(const sptr<INetConnCallback> callback)230 int32_t NetConnServiceProxy::RegisterNetConnCallback(const sptr<INetConnCallback> callback)
231 {
232     if (callback == nullptr) {
233         NETMGR_LOG_E("The parameter of callback is nullptr");
234         return NETMANAGER_ERR_LOCAL_PTR_NULL;
235     }
236 
237     MessageParcel dataParcel;
238     if (!WriteInterfaceToken(dataParcel)) {
239         NETMGR_LOG_E("WriteInterfaceToken failed");
240         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
241     }
242     dataParcel.WriteRemoteObject(callback->AsObject());
243 
244     MessageParcel replyParcel;
245     int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK),
246                                         dataParcel, replyParcel);
247     if (retCode != NETMANAGER_SUCCESS) {
248         return retCode;
249     }
250     NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
251     return replyParcel.ReadInt32();
252 }
253 
RegisterNetConnCallback(const sptr<NetSpecifier> & netSpecifier,const sptr<INetConnCallback> callback,const uint32_t & timeoutMS)254 int32_t NetConnServiceProxy::RegisterNetConnCallback(const sptr<NetSpecifier> &netSpecifier,
255                                                      const sptr<INetConnCallback> callback, const uint32_t &timeoutMS)
256 {
257     if (netSpecifier == nullptr || callback == nullptr) {
258         NETMGR_LOG_E("The parameter of netSpecifier or callback is nullptr");
259         return NETMANAGER_ERR_LOCAL_PTR_NULL;
260     }
261 
262     MessageParcel dataParcel;
263     if (!WriteInterfaceToken(dataParcel)) {
264         NETMGR_LOG_E("WriteInterfaceToken failed");
265         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
266     }
267     netSpecifier->Marshalling(dataParcel);
268     dataParcel.WriteUint32(timeoutMS);
269     dataParcel.WriteRemoteObject(callback->AsObject());
270 
271     MessageParcel replyParcel;
272     int32_t retCode = RemoteSendRequest(
273         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK_BY_SPECIFIER),
274         dataParcel, replyParcel);
275     if (retCode != NETMANAGER_SUCCESS) {
276         return retCode;
277     }
278     NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
279     return replyParcel.ReadInt32();
280 }
281 
RequestNetConnection(const sptr<NetSpecifier> netSpecifier,const sptr<INetConnCallback> callback,const uint32_t timeoutMS)282 int32_t NetConnServiceProxy::RequestNetConnection(const sptr<NetSpecifier> netSpecifier,
283                                                   const sptr<INetConnCallback> callback, const uint32_t timeoutMS)
284 {
285     if (netSpecifier == nullptr || callback == nullptr) {
286         NETMGR_LOG_E("The parameter of netSpecifier or callback is nullptr");
287         return NETMANAGER_ERR_LOCAL_PTR_NULL;
288     }
289 
290     MessageParcel dataParcel;
291     if (!WriteInterfaceToken(dataParcel)) {
292         NETMGR_LOG_E("WriteInterfaceToken failed");
293         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
294     }
295     netSpecifier->Marshalling(dataParcel);
296     dataParcel.WriteUint32(timeoutMS);
297     dataParcel.WriteRemoteObject(callback->AsObject());
298 
299     MessageParcel replyParcel;
300     int32_t retCode = RemoteSendRequest(
301         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REQUEST_NET_CONNECTION),
302         dataParcel, replyParcel);
303     if (retCode != NETMANAGER_SUCCESS) {
304         return retCode;
305     }
306     NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
307     return replyParcel.ReadInt32();
308 }
309 
UnregisterNetConnCallback(const sptr<INetConnCallback> & callback)310 int32_t NetConnServiceProxy::UnregisterNetConnCallback(const sptr<INetConnCallback> &callback)
311 {
312     if (callback == nullptr) {
313         NETMGR_LOG_E("The parameter of callback is nullptr");
314         return NETMANAGER_ERR_LOCAL_PTR_NULL;
315     }
316 
317     MessageParcel dataParcel;
318     if (!WriteInterfaceToken(dataParcel)) {
319         NETMGR_LOG_E("WriteInterfaceToken failed");
320         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
321     }
322     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
323 
324     MessageParcel replyParcel;
325     int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_CONN_CALLBACK),
326                                         dataParcel, replyParcel);
327     if (retCode != NETMANAGER_SUCCESS) {
328         return retCode;
329     }
330     NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
331     return replyParcel.ReadInt32();
332 }
333 
UpdateNetStateForTest(const sptr<NetSpecifier> & netSpecifier,int32_t netState)334 int32_t NetConnServiceProxy::UpdateNetStateForTest(const sptr<NetSpecifier> &netSpecifier, int32_t netState)
335 {
336     NETMGR_LOG_I("Test NetConnServiceProxy::UpdateNetStateForTest(), begin");
337     if (netSpecifier == nullptr) {
338         NETMGR_LOG_E("The parameter of netSpecifier is nullptr");
339         return NETMANAGER_ERR_LOCAL_PTR_NULL;
340     }
341 
342     MessageParcel dataParcel;
343     if (!WriteInterfaceToken(dataParcel)) {
344         NETMGR_LOG_E("WriteInterfaceToken failed");
345         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
346     }
347     netSpecifier->Marshalling(dataParcel);
348 
349     if (!dataParcel.WriteInt32(netState)) {
350         return NETMANAGER_ERR_WRITE_DATA_FAIL;
351     }
352 
353     MessageParcel replyParcel;
354     int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_STATE_FOR_TEST),
355                                         dataParcel, replyParcel);
356     if (retCode != NETMANAGER_SUCCESS) {
357         return retCode;
358     }
359     NETMGR_LOG_I("NetConnServiceProxy::UpdateNetStateForTest(), SendRequest retCode:[%{public}d]", retCode);
360     return replyParcel.ReadInt32();
361 }
362 
UpdateNetSupplierInfo(uint32_t supplierId,const sptr<NetSupplierInfo> & netSupplierInfo)363 int32_t NetConnServiceProxy::UpdateNetSupplierInfo(uint32_t supplierId, const sptr<NetSupplierInfo> &netSupplierInfo)
364 {
365     if (netSupplierInfo == nullptr) {
366         NETMGR_LOG_E("netSupplierInfo is null");
367         return NETMANAGER_ERR_LOCAL_PTR_NULL;
368     }
369 
370     MessageParcel data;
371     MessageParcel reply;
372     if (!WriteInterfaceToken(data)) {
373         NETMGR_LOG_E("WriteInterfaceToken failed");
374         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
375     }
376 
377     NETMGR_LOG_D("proxy supplierId[%{public}d]", supplierId);
378     if (!data.WriteUint32(supplierId)) {
379         return NETMANAGER_ERR_WRITE_DATA_FAIL;
380     }
381     NETMGR_LOG_D("proxy supplierId[%{public}d] Marshalling success", supplierId);
382     if (!netSupplierInfo->Marshalling(data)) {
383         NETMGR_LOG_E("proxy Marshalling failed");
384         return NETMANAGER_ERR_WRITE_DATA_FAIL;
385     }
386     NETMGR_LOG_D("proxy Marshalling success");
387 
388     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_SUPPLIER_INFO),
389                                       data, reply);
390     if (error != NETMANAGER_SUCCESS) {
391         return error;
392     }
393     NETMGR_LOG_I("UpdateNetSupplierInfo out.");
394     return reply.ReadInt32();
395 }
396 
UpdateNetLinkInfo(uint32_t supplierId,const sptr<NetLinkInfo> & netLinkInfo)397 int32_t NetConnServiceProxy::UpdateNetLinkInfo(uint32_t supplierId, const sptr<NetLinkInfo> &netLinkInfo)
398 {
399     if (netLinkInfo == nullptr) {
400         NETMGR_LOG_E("netLinkInfo is null");
401         return NETMANAGER_ERR_LOCAL_PTR_NULL;
402     }
403 
404     MessageParcel data;
405     MessageParcel reply;
406     if (!WriteInterfaceToken(data)) {
407         NETMGR_LOG_E("WriteInterfaceToken failed");
408         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
409     }
410 
411     if (!data.WriteUint32(supplierId)) {
412         return NETMANAGER_ERR_WRITE_DATA_FAIL;
413     }
414 
415     if (!netLinkInfo->Marshalling(data)) {
416         NETMGR_LOG_E("proxy Marshalling failed");
417         return NETMANAGER_ERR_WRITE_DATA_FAIL;
418     }
419 
420     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_LINK_INFO),
421                                       data, reply);
422     if (error != NETMANAGER_SUCCESS) {
423         return error;
424     }
425 
426     return reply.ReadInt32();
427 }
428 
RegisterNetDetectionCallback(int32_t netId,const sptr<INetDetectionCallback> & callback)429 int32_t NetConnServiceProxy::RegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback)
430 {
431     if (callback == nullptr) {
432         NETMGR_LOG_E("The parameter of callback is nullptr");
433         return NETMANAGER_ERR_LOCAL_PTR_NULL;
434     }
435 
436     MessageParcel dataParcel;
437     if (!WriteInterfaceToken(dataParcel)) {
438         NETMGR_LOG_E("WriteInterfaceToken failed");
439         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
440     }
441     if (!dataParcel.WriteInt32(netId)) {
442         return NETMANAGER_ERR_WRITE_DATA_FAIL;
443     }
444     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
445 
446     MessageParcel replyParcel;
447     int32_t error = RemoteSendRequest(
448         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_DETECTION_RET_CALLBACK), dataParcel, replyParcel);
449     if (error != NETMANAGER_SUCCESS) {
450         return error;
451     }
452     return replyParcel.ReadInt32();
453 }
454 
UnRegisterNetDetectionCallback(int32_t netId,const sptr<INetDetectionCallback> & callback)455 int32_t NetConnServiceProxy::UnRegisterNetDetectionCallback(int32_t netId, const sptr<INetDetectionCallback> &callback)
456 {
457     if (callback == nullptr) {
458         NETMGR_LOG_E("The parameter of callback is nullptr");
459         return NETMANAGER_ERR_LOCAL_PTR_NULL;
460     }
461 
462     MessageParcel dataParcel;
463     if (!WriteInterfaceToken(dataParcel)) {
464         NETMGR_LOG_E("WriteInterfaceToken failed");
465         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
466     }
467     if (!dataParcel.WriteInt32(netId)) {
468         return NETMANAGER_ERR_WRITE_DATA_FAIL;
469     }
470     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
471 
472     MessageParcel replyParcel;
473     int32_t error = RemoteSendRequest(
474         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_DETECTION_RET_CALLBACK),
475         dataParcel, replyParcel);
476     if (error != NETMANAGER_SUCCESS) {
477         return error;
478     }
479     return replyParcel.ReadInt32();
480 }
481 
NetDetection(int32_t netId)482 int32_t NetConnServiceProxy::NetDetection(int32_t netId)
483 {
484     MessageParcel dataParcel;
485     if (!WriteInterfaceToken(dataParcel)) {
486         NETMGR_LOG_E("WriteInterfaceToken failed");
487         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
488     }
489     if (!dataParcel.WriteInt32(netId)) {
490         return NETMANAGER_ERR_WRITE_DATA_FAIL;
491     }
492 
493     MessageParcel replyParcel;
494     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_NET_DETECTION),
495                                       dataParcel, replyParcel);
496     if (error != NETMANAGER_SUCCESS) {
497         return error;
498     }
499     return replyParcel.ReadInt32();
500 }
501 
GetIfaceNames(NetBearType bearerType,std::list<std::string> & ifaceNames)502 int32_t NetConnServiceProxy::GetIfaceNames(NetBearType bearerType, std::list<std::string> &ifaceNames)
503 {
504     MessageParcel data;
505     if (!WriteInterfaceToken(data)) {
506         NETMGR_LOG_E("WriteInterfaceToken failed");
507         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
508     }
509 
510     if (!data.WriteUint32(bearerType)) {
511         return NETMANAGER_ERR_WRITE_DATA_FAIL;
512     }
513 
514     MessageParcel reply;
515     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACE_NAMES),
516                                       data, reply);
517     if (error != NETMANAGER_SUCCESS) {
518         return error;
519     }
520 
521     int32_t ret = NETMANAGER_SUCCESS;
522     if (!reply.ReadInt32(ret)) {
523         return NETMANAGER_ERR_READ_REPLY_FAIL;
524     }
525     if (ret == NETMANAGER_SUCCESS) {
526         uint32_t size = 0;
527         if (!reply.ReadUint32(size)) {
528             return NETMANAGER_ERR_READ_REPLY_FAIL;
529         }
530         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
531         for (uint32_t i = 0; i < size; ++i) {
532             std::string value;
533             if (!reply.ReadString(value)) {
534                 return NETMANAGER_ERR_READ_REPLY_FAIL;
535             }
536             ifaceNames.push_back(value);
537         }
538     }
539     return ret;
540 }
541 
GetIfaceNameByType(NetBearType bearerType,const std::string & ident,std::string & ifaceName)542 int32_t NetConnServiceProxy::GetIfaceNameByType(NetBearType bearerType, const std::string &ident,
543                                                 std::string &ifaceName)
544 {
545     MessageParcel data;
546     if (!WriteInterfaceToken(data)) {
547         NETMGR_LOG_E("WriteInterfaceToken failed");
548         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
549     }
550     if (bearerType >= BEARER_DEFAULT) {
551         return NETMANAGER_ERR_INTERNAL;
552     }
553     uint32_t netType = static_cast<NetBearType>(bearerType);
554     if (!data.WriteUint32(netType)) {
555         return NETMANAGER_ERR_WRITE_DATA_FAIL;
556     }
557 
558     if (!data.WriteString(ident)) {
559         return NETMANAGER_ERR_WRITE_DATA_FAIL;
560     }
561 
562     MessageParcel reply;
563     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACENAME_BY_TYPE),
564                                       data, reply);
565     if (error != NETMANAGER_SUCCESS) {
566         return error;
567     }
568 
569     int32_t ret = 0;
570     if (!reply.ReadInt32(ret)) {
571         return NETMANAGER_ERR_READ_REPLY_FAIL;
572     }
573     if (ret == NETMANAGER_SUCCESS) {
574         if (!reply.ReadString(ifaceName)) {
575             return NETMANAGER_ERR_READ_REPLY_FAIL;
576         }
577     }
578     return ret;
579 }
580 
GetIfaceNameIdentMaps(NetBearType bearerType,SafeMap<std::string,std::string> & ifaceNameIdentMaps)581 int32_t NetConnServiceProxy::GetIfaceNameIdentMaps(NetBearType bearerType,
582                                                    SafeMap<std::string, std::string> &ifaceNameIdentMaps)
583 {
584     MessageParcel data;
585     if (!WriteInterfaceToken(data)) {
586         NETMGR_LOG_E("WriteInterfaceToken failed");
587         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
588     }
589     if (bearerType >= BEARER_DEFAULT) {
590         return NETMANAGER_ERR_INTERNAL;
591     }
592     uint32_t netType = static_cast<NetBearType>(bearerType);
593     if (!data.WriteUint32(netType)) {
594         return NETMANAGER_ERR_WRITE_DATA_FAIL;
595     }
596     MessageParcel reply;
597     int32_t ret = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_GET_IFACENAME_IDENT_MAPS),
598                                     data, reply);
599     if (ret != NETMANAGER_SUCCESS) {
600         return ret;
601     }
602     if (!reply.ReadInt32(ret)) {
603         return NETMANAGER_ERR_READ_REPLY_FAIL;
604     }
605     uint32_t size = 0;
606     if (!reply.ReadUint32(size)) {
607         return NETMANAGER_ERR_READ_REPLY_FAIL;
608     }
609     size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
610     for (uint32_t i = 0; i < size; ++i) {
611         std::string key;
612         std::string value;
613         if (!reply.ReadString(key) || !reply.ReadString(value)) {
614             return NETMANAGER_ERR_READ_REPLY_FAIL;
615         }
616         ifaceNameIdentMaps.EnsureInsert(key, value);
617     }
618     return ret;
619 }
620 
WriteInterfaceToken(MessageParcel & data)621 bool NetConnServiceProxy::WriteInterfaceToken(MessageParcel &data)
622 {
623     if (!data.WriteInterfaceToken(NetConnServiceProxy::GetDescriptor())) {
624         NETMGR_LOG_E("WriteInterfaceToken failed");
625         return false;
626     }
627     return true;
628 }
629 
GetDefaultNet(int32_t & netId)630 int32_t NetConnServiceProxy::GetDefaultNet(int32_t &netId)
631 {
632     MessageParcel dataParcel;
633     if (!WriteInterfaceToken(dataParcel)) {
634         NETMGR_LOG_E("WriteInterfaceToken failed");
635         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
636     }
637 
638     MessageParcel replyParcel;
639     int32_t errCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK),
640                                         dataParcel, replyParcel);
641     if (errCode != NETMANAGER_SUCCESS) {
642         return errCode;
643     }
644     NETMGR_LOG_D("SendRequest errcode:[%{public}d]", errCode);
645     int32_t ret = 0;
646     if (!replyParcel.ReadInt32(ret)) {
647         return NETMANAGER_ERR_READ_REPLY_FAIL;
648     }
649     if (ret == NETMANAGER_SUCCESS) {
650         if (!replyParcel.ReadInt32(netId)) {
651             return NETMANAGER_ERR_READ_REPLY_FAIL;
652         }
653     }
654     return ret;
655 }
656 
HasDefaultNet(bool & flag)657 int32_t NetConnServiceProxy::HasDefaultNet(bool &flag)
658 {
659     MessageParcel dataParcel;
660     if (!WriteInterfaceToken(dataParcel)) {
661         NETMGR_LOG_E("WriteInterfaceToken failed");
662         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
663     }
664 
665     MessageParcel replyParcel;
666     int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET),
667                                         dataParcel, replyParcel);
668     if (retCode != NETMANAGER_SUCCESS) {
669         return retCode;
670     }
671     NETMGR_LOG_D("SendRequest retCode:[%{public}d]", retCode);
672 
673     int32_t ret = 0;
674     if (!replyParcel.ReadInt32(ret)) {
675         return NETMANAGER_ERR_READ_REPLY_FAIL;
676     }
677     if (ret == NETMANAGER_SUCCESS) {
678         if (!replyParcel.ReadBool(flag)) {
679             return NETMANAGER_ERR_READ_REPLY_FAIL;
680         }
681     }
682     return ret;
683 }
684 
GetSpecificNet(NetBearType bearerType,std::list<int32_t> & netIdList)685 int32_t NetConnServiceProxy::GetSpecificNet(NetBearType bearerType, std::list<int32_t> &netIdList)
686 {
687     MessageParcel data;
688     if (!WriteInterfaceToken(data)) {
689         NETMGR_LOG_E("WriteInterfaceToken failed");
690         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
691     }
692 
693     uint32_t type = static_cast<uint32_t>(bearerType);
694     if (!data.WriteUint32(type)) {
695         return NETMANAGER_ERR_WRITE_DATA_FAIL;
696     }
697 
698     MessageParcel reply;
699     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET),
700                                       data, reply);
701     if (error != NETMANAGER_SUCCESS) {
702         return error;
703     }
704 
705     int32_t ret = NETMANAGER_SUCCESS;
706     if (!reply.ReadInt32(ret)) {
707         return NETMANAGER_ERR_READ_REPLY_FAIL;
708     }
709     if (ret == NETMANAGER_SUCCESS) {
710         uint32_t size = 0;
711         if (!reply.ReadUint32(size)) {
712             return NETMANAGER_ERR_READ_REPLY_FAIL;
713         }
714         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
715         for (uint32_t i = 0; i < size; ++i) {
716             uint32_t value;
717             if (!reply.ReadUint32(value)) {
718                 return NETMANAGER_ERR_READ_REPLY_FAIL;
719             }
720             netIdList.push_back(value);
721         }
722     }
723     return ret;
724 }
725 
GetAllNets(std::list<int32_t> & netIdList)726 int32_t NetConnServiceProxy::GetAllNets(std::list<int32_t> &netIdList)
727 {
728     MessageParcel data;
729     if (!WriteInterfaceToken(data)) {
730         NETMGR_LOG_E("WriteInterfaceToken failed");
731         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
732     }
733 
734     MessageParcel reply;
735     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ALL_NETS),
736                                       data, reply);
737     if (error != NETMANAGER_SUCCESS) {
738         return error;
739     }
740 
741     int32_t ret = NETMANAGER_SUCCESS;
742     if (!reply.ReadInt32(ret)) {
743         return NETMANAGER_ERR_READ_REPLY_FAIL;
744     }
745     if (ret == NETMANAGER_SUCCESS) {
746         uint32_t size;
747         if (!reply.ReadUint32(size)) {
748             return NETMANAGER_ERR_READ_REPLY_FAIL;
749         }
750         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
751         for (uint32_t i = 0; i < size; ++i) {
752             uint32_t value;
753             if (!reply.ReadUint32(value)) {
754                 return NETMANAGER_ERR_READ_REPLY_FAIL;
755             }
756             netIdList.push_back(value);
757         }
758     }
759     return ret;
760 }
761 
GetSpecificUidNet(int32_t uid,int32_t & netId)762 int32_t NetConnServiceProxy::GetSpecificUidNet(int32_t uid, int32_t &netId)
763 {
764     MessageParcel data;
765     if (!WriteInterfaceToken(data)) {
766         NETMGR_LOG_E("WriteInterfaceToken failed");
767         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
768     }
769 
770     if (!data.WriteInt32(uid)) {
771         return NETMANAGER_ERR_WRITE_DATA_FAIL;
772     }
773 
774     MessageParcel reply;
775     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_UID_NET),
776                                       data, reply);
777     if (error != NETMANAGER_SUCCESS) {
778         return error;
779     }
780 
781     int32_t ret = NETMANAGER_SUCCESS;
782     if (!reply.ReadInt32(ret)) {
783         return NETMANAGER_ERR_READ_REPLY_FAIL;
784     }
785     if (ret == NETMANAGER_SUCCESS) {
786         if (!reply.ReadInt32(netId)) {
787             return NETMANAGER_ERR_READ_REPLY_FAIL;
788         }
789     }
790     return ret;
791 }
792 
GetConnectionProperties(int32_t netId,NetLinkInfo & info)793 int32_t NetConnServiceProxy::GetConnectionProperties(int32_t netId, NetLinkInfo &info)
794 {
795     MessageParcel data;
796     if (!WriteInterfaceToken(data)) {
797         NETMGR_LOG_E("WriteInterfaceToken failed");
798         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
799     }
800 
801     if (!data.WriteInt32(netId)) {
802         return NETMANAGER_ERR_WRITE_DATA_FAIL;
803     }
804 
805     MessageParcel reply;
806     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_CONNECTION_PROPERTIES),
807                                       data, reply);
808     if (error != NETMANAGER_SUCCESS) {
809         return error;
810     }
811 
812     int32_t ret = NETMANAGER_SUCCESS;
813     if (!reply.ReadInt32(ret)) {
814         return NETMANAGER_ERR_READ_REPLY_FAIL;
815     }
816     if (ret == NETMANAGER_SUCCESS) {
817         sptr<NetLinkInfo> netLinkInfo_ptr = NetLinkInfo::Unmarshalling(reply);
818         if (netLinkInfo_ptr != nullptr) {
819             info = *netLinkInfo_ptr;
820         }
821     }
822     return ret;
823 }
824 
GetNetCapabilities(int32_t netId,NetAllCapabilities & netAllCap)825 int32_t NetConnServiceProxy::GetNetCapabilities(int32_t netId, NetAllCapabilities &netAllCap)
826 {
827     MessageParcel data;
828     if (!WriteInterfaceToken(data)) {
829         NETMGR_LOG_E("WriteInterfaceToken failed");
830         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
831     }
832 
833     if (!data.WriteInt32(netId)) {
834         return NETMANAGER_ERR_WRITE_DATA_FAIL;
835     }
836 
837     MessageParcel reply;
838     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_CAPABILITIES),
839                                       data, reply);
840     if (error != NETMANAGER_SUCCESS) {
841         return error;
842     }
843 
844     int32_t ret = NETMANAGER_SUCCESS;
845     if (!reply.ReadInt32(ret)) {
846         return NETMANAGER_ERR_READ_REPLY_FAIL;
847     }
848     return (ret == NETMANAGER_SUCCESS) ? GetNetCapData(reply, netAllCap) : ret;
849 }
850 
GetNetCapData(MessageParcel & reply,NetAllCapabilities & netAllCap)851 int32_t NetConnServiceProxy::GetNetCapData(MessageParcel &reply, NetAllCapabilities &netAllCap)
852 {
853     if (!reply.ReadUint32(netAllCap.linkUpBandwidthKbps_)) {
854         return NETMANAGER_ERR_READ_REPLY_FAIL;
855     }
856     if (!reply.ReadUint32(netAllCap.linkDownBandwidthKbps_)) {
857         return NETMANAGER_ERR_READ_REPLY_FAIL;
858     }
859     uint32_t size = 0;
860     if (!reply.ReadUint32(size)) {
861         return NETMANAGER_ERR_READ_REPLY_FAIL;
862     }
863     size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
864     uint32_t value = 0;
865     for (uint32_t i = 0; i < size; ++i) {
866         if (!reply.ReadUint32(value)) {
867             return NETMANAGER_ERR_READ_REPLY_FAIL;
868         }
869         if (value < NET_CAPABILITY_END) {
870             netAllCap.netCaps_.insert(static_cast<NetCap>(value));
871         }
872     }
873     if (!reply.ReadUint32(size)) {
874         return NETMANAGER_ERR_READ_REPLY_FAIL;
875     }
876     size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
877     for (uint32_t i = 0; i < size; ++i) {
878         if (!reply.ReadUint32(value)) {
879             return NETMANAGER_ERR_READ_REPLY_FAIL;
880         }
881         netAllCap.bearerTypes_.insert(static_cast<NetBearType>(value));
882     }
883     return NETMANAGER_SUCCESS;
884 }
885 
GetAddressesByName(const std::string & host,int32_t netId,std::vector<INetAddr> & addrList)886 int32_t NetConnServiceProxy::GetAddressesByName(const std::string &host, int32_t netId, std::vector<INetAddr> &addrList)
887 {
888     MessageParcel data;
889     if (!WriteInterfaceToken(data)) {
890         NETMGR_LOG_E("WriteInterfaceToken failed");
891         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
892     }
893     if (!data.WriteString(host)) {
894         return NETMANAGER_ERR_WRITE_DATA_FAIL;
895     }
896     if (!data.WriteInt32(netId)) {
897         return NETMANAGER_ERR_WRITE_DATA_FAIL;
898     }
899 
900     MessageParcel reply;
901     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESSES_BY_NAME),
902                                       data, reply);
903     if (error != NETMANAGER_SUCCESS) {
904         return error;
905     }
906 
907     int32_t ret = NETMANAGER_SUCCESS;
908     if (!reply.ReadInt32(ret)) {
909         return NETMANAGER_ERR_READ_REPLY_FAIL;
910     }
911 
912     if (ret == NETMANAGER_SUCCESS) {
913         uint32_t size;
914         if (!reply.ReadUint32(size)) {
915             return NETMANAGER_ERR_READ_REPLY_FAIL;
916         }
917         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
918         for (uint32_t i = 0; i < size; ++i) {
919             sptr<INetAddr> netaddr_ptr = INetAddr::Unmarshalling(reply);
920             if (netaddr_ptr != nullptr) {
921                 addrList.push_back(*netaddr_ptr);
922             }
923         }
924     }
925     return ret;
926 }
927 
GetAddressByName(const std::string & host,int32_t netId,INetAddr & addr)928 int32_t NetConnServiceProxy::GetAddressByName(const std::string &host, int32_t netId, INetAddr &addr)
929 {
930     MessageParcel data;
931     if (!WriteInterfaceToken(data)) {
932         NETMGR_LOG_E("WriteInterfaceToken failed");
933         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
934     }
935 
936     if (!data.WriteString(host)) {
937         return NETMANAGER_ERR_WRITE_DATA_FAIL;
938     }
939     if (!data.WriteInt32(netId)) {
940         return NETMANAGER_ERR_WRITE_DATA_FAIL;
941     }
942 
943     MessageParcel reply;
944     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESS_BY_NAME),
945                                       data, reply);
946     if (error != NETMANAGER_SUCCESS) {
947         return error;
948     }
949     int32_t ret = NETMANAGER_SUCCESS;
950     if (!reply.ReadInt32(ret)) {
951         return NETMANAGER_ERR_READ_REPLY_FAIL;
952     }
953     if (ret == NETMANAGER_SUCCESS) {
954         sptr<INetAddr> netaddr_ptr = INetAddr::Unmarshalling(reply);
955         if (netaddr_ptr != nullptr) {
956             addr = *netaddr_ptr;
957         }
958     }
959     return ret;
960 }
961 
BindSocket(int32_t socketFd,int32_t netId)962 int32_t NetConnServiceProxy::BindSocket(int32_t socketFd, int32_t netId)
963 {
964     MessageParcel data;
965     if (!WriteInterfaceToken(data)) {
966         NETMGR_LOG_E("WriteInterfaceToken failed");
967         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
968     }
969 
970     if (!data.WriteInt32(socketFd)) {
971         return NETMANAGER_ERR_WRITE_DATA_FAIL;
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_BIND_SOCKET),
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     return ret;
989 }
990 
SetAirplaneMode(bool state)991 int32_t NetConnServiceProxy::SetAirplaneMode(bool state)
992 {
993     MessageParcel data;
994     if (!WriteInterfaceToken(data)) {
995         NETMGR_LOG_E("WriteInterfaceToken failed");
996         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
997     }
998 
999     if (!data.WriteBool(state)) {
1000         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1001     }
1002 
1003     MessageParcel reply;
1004     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE),
1005                                       data, reply);
1006     if (error != NETMANAGER_SUCCESS) {
1007         return error;
1008     }
1009 
1010     int32_t ret = NETMANAGER_SUCCESS;
1011     if (!reply.ReadInt32(ret)) {
1012         return NETMANAGER_ERR_READ_REPLY_FAIL;
1013     }
1014     return ret;
1015 }
1016 
IsDefaultNetMetered(bool & isMetered)1017 int32_t NetConnServiceProxy::IsDefaultNetMetered(bool &isMetered)
1018 {
1019     MessageParcel data;
1020     if (!WriteInterfaceToken(data)) {
1021         NETMGR_LOG_E("WriteInterfaceToken failed");
1022         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1023     }
1024 
1025     MessageParcel reply;
1026     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_DEFAULT_NET_METERED),
1027                                       data, reply);
1028     if (error != NETMANAGER_SUCCESS) {
1029         return error;
1030     }
1031 
1032     int32_t ret = NETMANAGER_SUCCESS;
1033     if (!reply.ReadInt32(ret)) {
1034         return NETMANAGER_ERR_READ_REPLY_FAIL;
1035     }
1036     if (ret == NETMANAGER_SUCCESS) {
1037         if (!reply.ReadBool(isMetered)) {
1038             return NETMANAGER_ERR_READ_REPLY_FAIL;
1039         }
1040     }
1041     return ret;
1042 }
1043 
SetGlobalHttpProxy(const HttpProxy & httpProxy)1044 int32_t NetConnServiceProxy::SetGlobalHttpProxy(const HttpProxy &httpProxy)
1045 {
1046     MessageParcel data;
1047     if (!WriteInterfaceToken(data)) {
1048         NETMGR_LOG_E("WriteInterfaceToken failed");
1049         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1050     }
1051 
1052     if (!httpProxy.Marshalling(data)) {
1053         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1054     }
1055 
1056     MessageParcel reply;
1057     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY),
1058                                       data, reply);
1059     if (error != NETMANAGER_SUCCESS) {
1060         return error;
1061     }
1062 
1063     int32_t ret = NETMANAGER_SUCCESS;
1064     if (!reply.ReadInt32(ret)) {
1065         return NETMANAGER_ERR_READ_REPLY_FAIL;
1066     }
1067     return ret;
1068 }
1069 
GetGlobalHttpProxy(HttpProxy & httpProxy)1070 int32_t NetConnServiceProxy::GetGlobalHttpProxy(HttpProxy &httpProxy)
1071 {
1072     MessageParcel data;
1073     if (!WriteInterfaceToken(data)) {
1074         NETMGR_LOG_E("WriteInterfaceToken failed");
1075         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1076     }
1077 
1078     MessageParcel reply;
1079     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY),
1080                                       data, reply);
1081     if (error != NETMANAGER_SUCCESS) {
1082         return error;
1083     }
1084 
1085     int32_t ret = NETMANAGER_SUCCESS;
1086     if (!reply.ReadInt32(ret)) {
1087         return NETMANAGER_ERR_READ_REPLY_FAIL;
1088     }
1089 
1090     if (ret == NETMANAGER_SUCCESS) {
1091         if (!HttpProxy::Unmarshalling(reply, httpProxy)) {
1092             return NETMANAGER_ERR_READ_REPLY_FAIL;
1093         }
1094     }
1095     return ret;
1096 }
1097 
GetDefaultHttpProxy(int32_t bindNetId,HttpProxy & httpProxy)1098 int32_t NetConnServiceProxy::GetDefaultHttpProxy(int32_t bindNetId, HttpProxy &httpProxy)
1099 {
1100     MessageParcel data;
1101     if (!WriteInterfaceToken(data)) {
1102         NETMGR_LOG_E("WriteInterfaceToken failed");
1103         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1104     }
1105 
1106     if (!data.WriteInt32(bindNetId)) {
1107         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1108     }
1109 
1110     MessageParcel reply;
1111     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_DEFAULT_HTTP_PROXY),
1112                                       data, reply);
1113     if (error != NETMANAGER_SUCCESS) {
1114         return error;
1115     }
1116 
1117     int32_t ret = NETMANAGER_SUCCESS;
1118     if (!reply.ReadInt32(ret)) {
1119         return NETMANAGER_ERR_READ_REPLY_FAIL;
1120     }
1121 
1122     if (ret == NETMANAGER_SUCCESS) {
1123         if (!HttpProxy::Unmarshalling(reply, httpProxy)) {
1124             return NETMANAGER_ERR_READ_REPLY_FAIL;
1125         }
1126     }
1127     return ret;
1128 }
1129 
GetNetIdByIdentifier(const std::string & ident,std::list<int32_t> & netIdList)1130 int32_t NetConnServiceProxy::GetNetIdByIdentifier(const std::string &ident, std::list<int32_t> &netIdList)
1131 {
1132     MessageParcel data;
1133     if (!WriteInterfaceToken(data)) {
1134         NETMGR_LOG_E("WriteInterfaceToken failed");
1135         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1136     }
1137 
1138     if (!data.WriteString(ident)) {
1139         NETMGR_LOG_E("Write string data failed");
1140         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1141     }
1142 
1143     MessageParcel reply;
1144     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_ID_BY_IDENTIFIER),
1145                                       data, reply);
1146     if (error != NETMANAGER_SUCCESS) {
1147         return error;
1148     }
1149 
1150     int32_t ret = NETMANAGER_SUCCESS;
1151     if (!reply.ReadInt32(ret)) {
1152         NETMGR_LOG_E("Read return code failed");
1153         return NETMANAGER_ERR_READ_REPLY_FAIL;
1154     }
1155 
1156     if (ret == NETMANAGER_SUCCESS) {
1157         uint32_t size = 0;
1158         if (!reply.ReadUint32(size)) {
1159             return NETMANAGER_ERR_READ_REPLY_FAIL;
1160         }
1161         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1162         int32_t value = 0;
1163         for (uint32_t i = 0; i < size; ++i) {
1164             if (!reply.ReadInt32(value)) {
1165                 return NETMANAGER_ERR_READ_REPLY_FAIL;
1166             }
1167             netIdList.push_back(value);
1168         }
1169     }
1170     return ret;
1171 }
1172 
SetAppNet(int32_t netId)1173 int32_t NetConnServiceProxy::SetAppNet(int32_t netId)
1174 {
1175     MessageParcel data;
1176     if (!WriteInterfaceToken(data)) {
1177         NETMGR_LOG_E("WriteInterfaceToken failed");
1178         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1179     }
1180 
1181     if (!data.WriteInt32(netId)) {
1182         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1183     }
1184 
1185     MessageParcel reply;
1186     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_NET),
1187                                       data, reply);
1188     if (error != NETMANAGER_SUCCESS) {
1189         return error;
1190     }
1191 
1192     int32_t ret = NETMANAGER_SUCCESS;
1193     if (!reply.ReadInt32(ret)) {
1194         return NETMANAGER_ERR_READ_REPLY_FAIL;
1195     }
1196     return ret;
1197 }
1198 
RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> & callback)1199 int32_t NetConnServiceProxy::RegisterNetInterfaceCallback(const sptr<INetInterfaceStateCallback> &callback)
1200 {
1201     if (callback == nullptr) {
1202         NETMGR_LOG_E("The parameter of callback is nullptr");
1203         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1204     }
1205 
1206     MessageParcel dataParcel;
1207     if (!WriteInterfaceToken(dataParcel)) {
1208         NETMGR_LOG_E("WriteInterfaceToken failed");
1209         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1210     }
1211     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1212 
1213     MessageParcel replyParcel;
1214     int32_t retCode = RemoteSendRequest(
1215         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_INTERFACE_CALLBACK),
1216         dataParcel, replyParcel);
1217     if (retCode != NETMANAGER_SUCCESS) {
1218         return retCode;
1219     }
1220     return replyParcel.ReadInt32();
1221 }
1222 
GetNetInterfaceConfiguration(const std::string & iface,NetInterfaceConfiguration & config)1223 int32_t NetConnServiceProxy::GetNetInterfaceConfiguration(const std::string &iface, NetInterfaceConfiguration &config)
1224 {
1225     MessageParcel data;
1226     if (!WriteInterfaceToken(data)) {
1227         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1228     }
1229     if (!data.WriteString(iface)) {
1230         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1231     }
1232     MessageParcel reply;
1233     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_INTERFACE_CONFIGURATION),
1234                                       data, reply);
1235     if (error != NETMANAGER_SUCCESS) {
1236         return error;
1237     }
1238     int32_t ret = NETMANAGER_SUCCESS;
1239     if (!reply.ReadInt32(ret)) {
1240         return NETMANAGER_ERR_READ_REPLY_FAIL;
1241     }
1242     if (ret == NETMANAGER_SUCCESS) {
1243         if (!NetInterfaceConfiguration::Unmarshalling(reply, config)) {
1244             return NETMANAGER_ERR_READ_REPLY_FAIL;
1245         }
1246     }
1247     return ret;
1248 }
1249 
RemoteSendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)1250 int32_t NetConnServiceProxy::RemoteSendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply)
1251 {
1252     sptr<IRemoteObject> remote = Remote();
1253     if (remote == nullptr) {
1254         NETMGR_LOG_E("Remote is null");
1255         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1256     }
1257 
1258     MessageOption option;
1259     int32_t error = remote->SendRequest(code, data, reply, option);
1260     if (error != ERR_NONE) {
1261         NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
1262         return NETMANAGER_ERR_OPERATION_FAILED;
1263     }
1264 
1265     return NETMANAGER_SUCCESS;
1266 }
1267 
AddNetworkRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)1268 int32_t NetConnServiceProxy::AddNetworkRoute(int32_t netId, const std::string &ifName,
1269                                              const std::string &destination, const std::string &nextHop)
1270 {
1271     MessageParcel data;
1272     MessageParcel reply;
1273     if (!WriteInterfaceToken(data)) {
1274         NETMGR_LOG_E("WriteInterfaceToken failed");
1275         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1276     }
1277 
1278     if (!data.WriteInt32(netId)) {
1279         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1280     }
1281 
1282     if (!data.WriteString(ifName)) {
1283         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1284     }
1285 
1286     if (!data.WriteString(destination)) {
1287         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1288     }
1289 
1290     if (!data.WriteString(nextHop)) {
1291         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1292     }
1293 
1294     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ROUTE),
1295                                       data, reply);
1296     if (error != NETMANAGER_SUCCESS) {
1297         return error;
1298     }
1299 
1300     return reply.ReadInt32();
1301 }
1302 
RemoveNetworkRoute(int32_t netId,const std::string & ifName,const std::string & destination,const std::string & nextHop)1303 int32_t NetConnServiceProxy::RemoveNetworkRoute(int32_t netId, const std::string &ifName,
1304                                                 const std::string &destination, const std::string &nextHop)
1305 {
1306     MessageParcel data;
1307     MessageParcel reply;
1308     if (!WriteInterfaceToken(data)) {
1309         NETMGR_LOG_E("WriteInterfaceToken failed");
1310         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1311     }
1312 
1313     if (!data.WriteInt32(netId)) {
1314         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1315     }
1316 
1317     if (!data.WriteString(ifName)) {
1318         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1319     }
1320 
1321     if (!data.WriteString(destination)) {
1322         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1323     }
1324 
1325     if (!data.WriteString(nextHop)) {
1326         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1327     }
1328 
1329     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ROUTE),
1330                                       data, reply);
1331     if (error != NETMANAGER_SUCCESS) {
1332         return error;
1333     }
1334 
1335     return reply.ReadInt32();
1336 }
1337 
AddInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)1338 int32_t NetConnServiceProxy::AddInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
1339                                                  int32_t prefixLength)
1340 {
1341     MessageParcel data;
1342     MessageParcel reply;
1343     if (!WriteInterfaceToken(data)) {
1344         NETMGR_LOG_E("WriteInterfaceToken failed");
1345         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1346     }
1347 
1348     if (!data.WriteString(ifName)) {
1349         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1350     }
1351 
1352     if (!data.WriteString(ipAddr)) {
1353         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1354     }
1355 
1356     if (!data.WriteInt32(prefixLength)) {
1357         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1358     }
1359 
1360     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ADDRESS),
1361                                       data, reply);
1362     if (error != NETMANAGER_SUCCESS) {
1363         return error;
1364     }
1365 
1366     return reply.ReadInt32();
1367 }
1368 
DelInterfaceAddress(const std::string & ifName,const std::string & ipAddr,int32_t prefixLength)1369 int32_t NetConnServiceProxy::DelInterfaceAddress(const std::string &ifName, const std::string &ipAddr,
1370                                                  int32_t prefixLength)
1371 {
1372     MessageParcel data;
1373     MessageParcel reply;
1374     if (!WriteInterfaceToken(data)) {
1375         NETMGR_LOG_E("WriteInterfaceToken failed");
1376         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1377     }
1378 
1379     if (!data.WriteString(ifName)) {
1380         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1381     }
1382 
1383     if (!data.WriteString(ipAddr)) {
1384         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1385     }
1386 
1387     if (!data.WriteInt32(prefixLength)) {
1388         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1389     }
1390 
1391     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ADDRESS),
1392                                       data, reply);
1393     if (error != NETMANAGER_SUCCESS) {
1394         return error;
1395     }
1396 
1397     return reply.ReadInt32();
1398 }
1399 
AddStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)1400 int32_t NetConnServiceProxy::AddStaticArp(const std::string &ipAddr, const std::string &macAddr,
1401                                           const std::string &ifName)
1402 {
1403     MessageParcel data;
1404     MessageParcel reply;
1405     if (!WriteInterfaceToken(data)) {
1406         NETMGR_LOG_E("WriteInterfaceToken failed");
1407         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1408     }
1409 
1410     if (!data.WriteString(ipAddr)) {
1411         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1412     }
1413 
1414     if (!data.WriteString(macAddr)) {
1415         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1416     }
1417 
1418     if (!data.WriteString(ifName)) {
1419         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1420     }
1421 
1422     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_STATIC_ARP),
1423                                       data, reply);
1424     if (error != NETMANAGER_SUCCESS) {
1425         return error;
1426     }
1427 
1428     return reply.ReadInt32();
1429 }
1430 
DelStaticArp(const std::string & ipAddr,const std::string & macAddr,const std::string & ifName)1431 int32_t NetConnServiceProxy::DelStaticArp(const std::string &ipAddr, const std::string &macAddr,
1432                                           const std::string &ifName)
1433 {
1434     MessageParcel data;
1435     MessageParcel reply;
1436     if (!WriteInterfaceToken(data)) {
1437         NETMGR_LOG_E("WriteInterfaceToken failed");
1438         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1439     }
1440 
1441     if (!data.WriteString(ipAddr)) {
1442         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1443     }
1444 
1445     if (!data.WriteString(macAddr)) {
1446         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1447     }
1448 
1449     if (!data.WriteString(ifName)) {
1450         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1451     }
1452 
1453     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DEL_STATIC_ARP),
1454                                       data, reply);
1455     if (error != NETMANAGER_SUCCESS) {
1456         return error;
1457     }
1458 
1459     return reply.ReadInt32();
1460 }
1461 
RegisterSlotType(uint32_t supplierId,int32_t type)1462 int32_t NetConnServiceProxy::RegisterSlotType(uint32_t supplierId, int32_t type)
1463 {
1464     MessageParcel data;
1465     MessageParcel reply;
1466     if (!WriteInterfaceToken(data)) {
1467         NETMGR_LOG_E("WriteInterfaceToken failed");
1468         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1469     }
1470 
1471     if (!data.WriteUint32(supplierId)) {
1472         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1473     }
1474 
1475     if (!data.WriteInt32(type)) {
1476         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1477     }
1478 
1479     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_SLOT_TYPE),
1480                                       data, reply);
1481     if (error != NETMANAGER_SUCCESS) {
1482         return error;
1483     }
1484 
1485     return reply.ReadInt32();
1486 }
1487 
GetSlotType(std::string & type)1488 int32_t NetConnServiceProxy::GetSlotType(std::string &type)
1489 {
1490     MessageParcel data;
1491     MessageParcel reply;
1492     if (!WriteInterfaceToken(data)) {
1493         NETMGR_LOG_E("WriteInterfaceToken failed");
1494         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1495     }
1496 
1497     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SLOT_TYPE),
1498                                       data, reply);
1499     if (error != NETMANAGER_SUCCESS) {
1500         return error;
1501     }
1502     int32_t ret = reply.ReadInt32();
1503     if (ret == NETMANAGER_SUCCESS) {
1504         if (!reply.ReadString(type)) {
1505             return NETMANAGER_ERR_READ_REPLY_FAIL;
1506         }
1507     }
1508     return ret;
1509 }
1510 
FactoryResetNetwork()1511 int32_t NetConnServiceProxy::FactoryResetNetwork()
1512 {
1513     MessageParcel data;
1514     if (!WriteInterfaceToken(data)) {
1515         NETMGR_LOG_E("WriteInterfaceToken failed");
1516         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1517     }
1518 
1519     MessageParcel reply;
1520     int32_t error =
1521         RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FACTORYRESET_NETWORK), data, reply);
1522     if (error != NETMANAGER_SUCCESS) {
1523         return error;
1524     }
1525 
1526     int32_t ret = NETMANAGER_SUCCESS;
1527     if (!reply.ReadInt32(ret)) {
1528         return NETMANAGER_ERR_READ_REPLY_FAIL;
1529     }
1530     return ret;
1531 }
1532 
RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> & callback)1533 int32_t NetConnServiceProxy::RegisterNetFactoryResetCallback(const sptr<INetFactoryResetCallback> &callback)
1534 {
1535     if (callback == nullptr) {
1536         NETMGR_LOG_E("The parameter of callback is nullptr");
1537         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1538     }
1539 
1540     MessageParcel dataParcel;
1541     if (!WriteInterfaceToken(dataParcel)) {
1542         NETMGR_LOG_E("WriteInterfaceToken failed");
1543         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1544     }
1545     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1546 
1547     MessageParcel replyParcel;
1548     int32_t retCode = RemoteSendRequest(
1549         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_FACTORYRESET_CALLBACK), dataParcel, replyParcel);
1550     if (retCode != NETMANAGER_SUCCESS) {
1551         return retCode;
1552     }
1553     return replyParcel.ReadInt32();
1554 }
1555 
IsPreferCellularUrl(const std::string & url,bool & preferCellular)1556 int32_t NetConnServiceProxy::IsPreferCellularUrl(const std::string& url, bool& preferCellular)
1557 {
1558     MessageParcel data;
1559     MessageParcel reply;
1560     if (!WriteInterfaceToken(data)) {
1561         NETMGR_LOG_E("WriteInterfaceToken failed");
1562         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1563     }
1564     if (!data.WriteString(url)) {
1565         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1566     }
1567     int32_t error = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_PREFER_CELLULAR_URL),
1568                                       data, reply);
1569     if (error != NETMANAGER_SUCCESS) {
1570         return error;
1571     }
1572     int32_t ret = reply.ReadInt32();
1573     if (ret == NETMANAGER_SUCCESS) {
1574         if (!reply.ReadBool(preferCellular)) {
1575             return NETMANAGER_ERR_READ_REPLY_FAIL;
1576         }
1577     }
1578     return ret;
1579 }
1580 
RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)1581 int32_t NetConnServiceProxy::RegisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)
1582 {
1583     if (callback == nullptr) {
1584         NETMGR_LOG_E("The parameter of callback is nullptr");
1585         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1586     }
1587 
1588     MessageParcel dataParcel;
1589     if (!WriteInterfaceToken(dataParcel)) {
1590         NETMGR_LOG_E("WriteInterfaceToken failed");
1591         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1592     }
1593     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1594 
1595     MessageParcel replyParcel;
1596     int32_t retCode = RemoteSendRequest(
1597         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_PREAIRPLANE_CALLBACK), dataParcel, replyParcel);
1598     if (retCode != NETMANAGER_SUCCESS) {
1599         return retCode;
1600     }
1601     return replyParcel.ReadInt32();
1602 }
1603 
UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)1604 int32_t NetConnServiceProxy::UnregisterPreAirplaneCallback(const sptr<IPreAirplaneCallback> callback)
1605 {
1606     if (callback == nullptr) {
1607         NETMGR_LOG_E("The parameter of callback is nullptr");
1608         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1609     }
1610 
1611     MessageParcel dataParcel;
1612     if (!WriteInterfaceToken(dataParcel)) {
1613         NETMGR_LOG_E("WriteInterfaceToken failed");
1614         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1615     }
1616     dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
1617 
1618     MessageParcel replyParcel;
1619     int32_t retCode = RemoteSendRequest(
1620         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_PREAIRPLANE_CALLBACK), dataParcel, replyParcel);
1621     if (retCode != NETMANAGER_SUCCESS) {
1622         return retCode;
1623     }
1624     return replyParcel.ReadInt32();
1625 }
1626 
UpdateSupplierScore(NetBearType bearerType,uint32_t detectionStatus,uint32_t & supplierId)1627 int32_t NetConnServiceProxy::UpdateSupplierScore(NetBearType bearerType, uint32_t detectionStatus, uint32_t& supplierId)
1628 {
1629     MessageParcel data;
1630     MessageParcel reply;
1631     if (!WriteInterfaceToken(data)) {
1632         NETMGR_LOG_E("WriteInterfaceToken failed");
1633         return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
1634     }
1635     uint32_t type = static_cast<uint32_t>(bearerType);
1636     if (!data.WriteUint32(type)) {
1637         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1638     }
1639     if (!data.WriteUint32(detectionStatus)) {
1640         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1641     }
1642     if (!data.WriteUint32(supplierId)) {
1643         return NETMANAGER_ERR_WRITE_DATA_FAIL;
1644     }
1645     int32_t retCode = RemoteSendRequest(static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_SUPPLIER_SCORE),
1646         data, reply);
1647     if (retCode != NETMANAGER_SUCCESS) {
1648         return retCode;
1649     }
1650     int32_t ret;
1651     if (!reply.ReadInt32(ret)) {
1652         return NETMANAGER_ERR_READ_REPLY_FAIL;
1653     }
1654     if (ret == NETMANAGER_SUCCESS) {
1655         if (!reply.ReadUint32(supplierId)) {
1656             return NETMANAGER_ERR_READ_REPLY_FAIL;
1657         }
1658     }
1659     return ret;
1660 }
1661 } // namespace NetManagerStandard
1662 } // namespace OHOS
1663