• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "net_conn_service_stub.h"
17 #include "ipc_skeleton.h"
18 #include "net_conn_constants.h"
19 #include "net_conn_types.h"
20 #include "net_manager_constants.h"
21 #include "net_mgr_log_wrapper.h"
22 #include "netmanager_base_permission.h"
23 
24 namespace OHOS {
25 namespace NetManagerStandard {
26 namespace {
27 constexpr int32_t MAX_VNIC_UID_ARRAY_SIZE = 20;
28 constexpr uint32_t MAX_IFACE_NUM = 16;
29 constexpr uint32_t MAX_NET_CAP_NUM = 32;
30 constexpr uint32_t UID_FOUNDATION = 5523;
31 const std::vector<uint32_t> SYSTEM_CODE{static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE),
32                                         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY),
33                                         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY),
34                                         static_cast<uint32_t>(ConnInterfaceCode::CMD_GET_IFACENAME_IDENT_MAPS),
35                                         static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FACTORYRESET_NETWORK)};
36 const std::vector<uint32_t> PERMISSION_NEED_CACHE_CODES{
37     static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK),
38     static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET)};
39 } // namespace
NetConnServiceStub()40 NetConnServiceStub::NetConnServiceStub()
41 {
42     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SYSTEM_READY)] = {
43         &NetConnServiceStub::OnSystemReady, {}};
44     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK)] = {
45         &NetConnServiceStub::OnRegisterNetConnCallback, {Permission::GET_NETWORK_INFO}};
46     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK_BY_SPECIFIER)] = {
47         &NetConnServiceStub::OnRegisterNetConnCallbackBySpecifier, {Permission::GET_NETWORK_INFO}};
48     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REQUEST_NET_CONNECTION)] = {
49         &NetConnServiceStub::OnRequestNetConnectionBySpecifier, {}};
50     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_CONN_CALLBACK)] = {
51         &NetConnServiceStub::OnUnregisterNetConnCallback, {Permission::GET_NETWORK_INFO}};
52     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_STATE_FOR_TEST)] = {
53         &NetConnServiceStub::OnUpdateNetStateForTest, {}};
54     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REG_NET_SUPPLIER)] = {
55         &NetConnServiceStub::OnRegisterNetSupplier, {Permission::CONNECTIVITY_INTERNAL}};
56     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREG_NETWORK)] = {
57         &NetConnServiceStub::OnUnregisterNetSupplier, {Permission::CONNECTIVITY_INTERNAL}};
58     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_CAPS)] = {
59         &NetConnServiceStub::OnUpdateNetCaps, {Permission::CONNECTIVITY_INTERNAL}};
60     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_SUPPLIER_INFO)] = {
61         &NetConnServiceStub::OnUpdateNetSupplierInfo, {Permission::CONNECTIVITY_INTERNAL}};
62     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_LINK_INFO)] = {
63         &NetConnServiceStub::OnUpdateNetLinkInfo, {Permission::CONNECTIVITY_INTERNAL}};
64     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_DETECTION_RET_CALLBACK)] = {
65         &NetConnServiceStub::OnRegisterNetDetectionCallback, {}};
66     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_DETECTION_RET_CALLBACK)] = {
67         &NetConnServiceStub::OnUnRegisterNetDetectionCallback, {}};
68     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_NET_DETECTION)] = {
69         &NetConnServiceStub::OnNetDetection, {Permission::GET_NETWORK_INFO, Permission::INTERNET}};
70     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_BIND_SOCKET)] = {&NetConnServiceStub::OnBindSocket,
71                                                                                     {}};
72     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_SUPPLIER_CALLBACK)] = {
73         &NetConnServiceStub::OnRegisterNetSupplierCallback, {Permission::CONNECTIVITY_INTERNAL}};
74     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE)] = {
75         &NetConnServiceStub::OnSetAirplaneMode, {Permission::CONNECTIVITY_INTERNAL}};
76     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY)] = {
77         &NetConnServiceStub::OnSetGlobalHttpProxy, {Permission::CONNECTIVITY_INTERNAL}};
78     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_NET)] = {&NetConnServiceStub::OnSetAppNet,
79                                                                                     {Permission::INTERNET}};
80     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION)] = {
81         &NetConnServiceStub::OnSetInternetPermission, {Permission::CONNECTIVITY_INTERNAL}};
82     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_INTERFACE_CALLBACK)] = {
83         &NetConnServiceStub::OnRegisterNetInterfaceCallback, {Permission::CONNECTIVITY_INTERNAL}};
84     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_INTERFACE_CALLBACK)] = {
85         &NetConnServiceStub::OnUnregisterNetInterfaceCallback, {Permission::CONNECTIVITY_INTERNAL}};
86     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ROUTE)] = {
87         &NetConnServiceStub::OnAddNetworkRoute, {Permission::CONNECTIVITY_INTERNAL}};
88     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ROUTE)] = {
89         &NetConnServiceStub::OnRemoveNetworkRoute, {Permission::CONNECTIVITY_INTERNAL}};
90     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_PREFER_CELLULAR_URL)] = {
91         &NetConnServiceStub::OnIsPreferCellularUrl, {Permission::GET_NETWORK_INFO}};
92     InitAll();
93 }
94 
InitAll()95 void NetConnServiceStub::InitAll()
96 {
97     InitInterfaceFuncToInterfaceMap();
98     InitResetNetFuncToInterfaceMap();
99     InitStaticArpToInterfaceMap();
100     InitQueryFuncToInterfaceMap();
101     InitQueryFuncToInterfaceMapExt();
102     InitVnicFuncToInterfaceMap();
103     InitVirnicFuncToInterfaceMap();
104 }
105 
InitInterfaceFuncToInterfaceMap()106 void NetConnServiceStub::InitInterfaceFuncToInterfaceMap()
107 {
108     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_NET_ADDRESS)] = {
109         &NetConnServiceStub::OnAddInterfaceAddress, {Permission::CONNECTIVITY_INTERNAL}};
110     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REMOVE_NET_ADDRESS)] = {
111         &NetConnServiceStub::OnDelInterfaceAddress, {Permission::CONNECTIVITY_INTERNAL}};
112     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_PREAIRPLANE_CALLBACK)] = {
113         &NetConnServiceStub::OnRegisterPreAirplaneCallback, {Permission::CONNECTIVITY_INTERNAL}};
114     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_PREAIRPLANE_CALLBACK)] = {
115         &NetConnServiceStub::OnUnregisterPreAirplaneCallback, {Permission::CONNECTIVITY_INTERNAL}};
116     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DECREASE_SUPPLIER_SCORE)] = {
117         &NetConnServiceStub::OnDecreaseSupplierScore, {Permission::CONNECTIVITY_INTERNAL}};
118     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_INCREASE_SUPPLIER_SCORE)] = {
119         &NetConnServiceStub::OnIncreaseSupplierScore, {Permission::CONNECTIVITY_INTERNAL}};
120     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_CLOSE_SOCKETS_UID)] = {
121         &NetConnServiceStub::OnCloseSocketsUid, {Permission::CONNECTIVITY_INTERNAL}};
122     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_IS_FROZENED)] = {
123         &NetConnServiceStub::OnSetAppIsFrozened, {Permission::CONNECTIVITY_INTERNAL}};
124     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_APP_FROZENED_CALLBACK_LIMITATION)] = {
125         &NetConnServiceStub::OnEnableAppFrozenedCallbackLimitation, {Permission::CONNECTIVITY_INTERNAL}};
126 }
127 
InitResetNetFuncToInterfaceMap()128 void NetConnServiceStub::InitResetNetFuncToInterfaceMap()
129 {
130     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_FACTORYRESET_NETWORK)] = {
131         &NetConnServiceStub::OnFactoryResetNetwork, {Permission::CONNECTIVITY_INTERNAL}};
132     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_FACTORYRESET_CALLBACK)] = {
133         &NetConnServiceStub::OnRegisterNetFactoryResetCallback, {Permission::CONNECTIVITY_INTERNAL}};
134 }
135 
InitStaticArpToInterfaceMap()136 void NetConnServiceStub::InitStaticArpToInterfaceMap()
137 {
138     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ADD_STATIC_ARP)] = {
139         &NetConnServiceStub::OnAddStaticArp, {Permission::CONNECTIVITY_INTERNAL}};
140     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DEL_STATIC_ARP)] = {
141         &NetConnServiceStub::OnDelStaticArp, {Permission::CONNECTIVITY_INTERNAL}};
142 }
143 
InitQueryFuncToInterfaceMap()144 void NetConnServiceStub::InitQueryFuncToInterfaceMap()
145 {
146     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACE_NAMES)] = {
147         &NetConnServiceStub::OnGetIfaceNames, {}};
148     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACENAME_BY_TYPE)] = {
149         &NetConnServiceStub::OnGetIfaceNameByType, {}};
150     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_GET_IFACENAME_IDENT_MAPS)] = {
151         &NetConnServiceStub::OnGetIfaceNameIdentMaps, {Permission::GET_NETWORK_INFO}};
152     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK)] = {
153         &NetConnServiceStub::OnGetDefaultNet, {Permission::GET_NETWORK_INFO}};
154     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET)] = {
155         &NetConnServiceStub::OnHasDefaultNet, {Permission::GET_NETWORK_INFO}};
156     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET)] = {
157         &NetConnServiceStub::OnGetSpecificNet, {}};
158     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ALL_NETS)] = {&NetConnServiceStub::OnGetAllNets,
159                                                                                      {Permission::GET_NETWORK_INFO}};
160     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_UID_NET)] = {
161         &NetConnServiceStub::OnGetSpecificUidNet, {}};
162     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_CONNECTION_PROPERTIES)] = {
163         &NetConnServiceStub::OnGetConnectionProperties, {Permission::GET_NETWORK_INFO}};
164     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_CAPABILITIES)] = {
165         &NetConnServiceStub::OnGetNetCapabilities, {Permission::GET_NETWORK_INFO}};
166     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESSES_BY_NAME)] = {
167         &NetConnServiceStub::OnGetAddressesByName, {Permission::INTERNET}};
168     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESS_BY_NAME)] = {
169         &NetConnServiceStub::OnGetAddressByName, {Permission::INTERNET}};
170     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_DEFAULT_NET_METERED)] = {
171         &NetConnServiceStub::OnIsDefaultNetMetered, {Permission::GET_NETWORK_INFO}};
172     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY)] = {
173         &NetConnServiceStub::OnGetGlobalHttpProxy, {}};
174     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_DEFAULT_HTTP_PROXY)] = {
175         &NetConnServiceStub::OnGetDefaultHttpProxy, {}};
176     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_ID_BY_IDENTIFIER)] = {
177         &NetConnServiceStub::OnGetNetIdByIdentifier, {}};
178     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_INTERFACE_CONFIGURATION)] = {
179         &NetConnServiceStub::OnGetNetInterfaceConfiguration, {Permission::CONNECTIVITY_INTERNAL}};
180     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_IP_ADDRESS)] = {
181         &NetConnServiceStub::OnSetNetInterfaceIpAddress, {Permission::CONNECTIVITY_INTERNAL}};
182     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_UP)] = {
183         &NetConnServiceStub::OnSetInterfaceUp, {Permission::CONNECTIVITY_INTERNAL}};
184     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERFACE_DOWN)] = {
185         &NetConnServiceStub::OnSetInterfaceDown, {Permission::CONNECTIVITY_INTERNAL}};
186     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_SLOT_TYPE)] = {
187         &NetConnServiceStub::OnRegisterSlotType, {Permission::CONNECTIVITY_INTERNAL}};
188     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SLOT_TYPE)] = {
189         &NetConnServiceStub::OnGetSlotType, {Permission::GET_NETWORK_INFO}};
190     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_PAC_URL)] = {
191         &NetConnServiceStub::OnSetPacUrl, {Permission::SET_PAC_URL}};
192     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_PAC_URL)] = {
193         &NetConnServiceStub::OnGetPacUrl, {}};
194 }
195 
InitQueryFuncToInterfaceMapExt()196 void NetConnServiceStub::InitQueryFuncToInterfaceMapExt()
197 {
198     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET_BY_IDENT)] = {
199         &NetConnServiceStub::OnGetSpecificNetByIdent, {}};
200 }
201 
InitVnicFuncToInterfaceMap()202 void NetConnServiceStub::InitVnicFuncToInterfaceMap()
203 {
204     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_VNIC_NET_WORK)] = {
205         &NetConnServiceStub::OnEnableVnicNetwork, {Permission::CONNECTIVITY_INTERNAL}};
206     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_VNIC_NET_WORK)] = {
207         &NetConnServiceStub::OnDisableVnicNetwork, {Permission::CONNECTIVITY_INTERNAL}};
208 }
209 
InitVirnicFuncToInterfaceMap()210 void NetConnServiceStub::InitVirnicFuncToInterfaceMap()
211 {
212     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_DISTRIBUTE_CLIENT_NET)] = {
213         &NetConnServiceStub::OnEnableDistributedClientNet, {Permission::CONNECTIVITY_INTERNAL}};
214     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_ENABLE_DISTRIBUTE_SERVER_NET)] = {
215         &NetConnServiceStub::OnEnableDistributedServerNet, {Permission::CONNECTIVITY_INTERNAL}};
216     memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_DISABLE_DISTRIBUTE_NET)] = {
217         &NetConnServiceStub::OnDisableDistributedNet, {Permission::CONNECTIVITY_INTERNAL}};
218 }
219 
~NetConnServiceStub()220 NetConnServiceStub::~NetConnServiceStub() {}
221 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)222 int32_t NetConnServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
223                                             MessageOption &option)
224 {
225     NETMGR_LOG_D("stub call start, code = [%{public}d]", code);
226 
227     std::u16string myDescripter = NetConnServiceStub::GetDescriptor();
228     std::u16string remoteDescripter = data.ReadInterfaceToken();
229     if (myDescripter != remoteDescripter) {
230         NETMGR_LOG_E("descriptor checked fail.");
231         if (!reply.WriteInt32(NETMANAGER_ERR_DESCRIPTOR_MISMATCH)) {
232             return IPC_STUB_WRITE_PARCEL_ERR;
233         }
234         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
235     }
236 
237     auto itFunc = memberFuncMap_.find(code);
238     if (itFunc == memberFuncMap_.end()) {
239         NETMGR_LOG_E("memberFuncMap not found this code! code: [%{public}d]", code);
240         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
241     }
242     auto requestFunc = itFunc->second.first;
243     if (requestFunc == nullptr) {
244         NETMGR_LOG_E("requestFunc is nullptr. code:[%{public}d]", code);
245         return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
246     }
247     if (code == static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION)) {
248         // get uid should be called in this function
249         auto uid = IPCSkeleton::GetCallingUid();
250         if (uid != UID_FOUNDATION && !CheckPermission({Permission::CONNECTIVITY_INTERNAL})) {
251             if (!reply.WriteInt32(NETMANAGER_ERR_PERMISSION_DENIED)) {
252                 return IPC_STUB_WRITE_PARCEL_ERR;
253             }
254             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
255         }
256     }
257 
258     int32_t ret = OnRequestCheck(code, itFunc->second.second);
259     if (ret == NETMANAGER_SUCCESS) {
260         ret =(this->*requestFunc)(data, reply);
261         NETMGR_LOG_D("stub call end, code = [%{public}d]", code);
262         return ret;
263     }
264     if (!reply.WriteInt32(ret)) {
265         return IPC_STUB_WRITE_PARCEL_ERR;
266     }
267     NETMGR_LOG_D("stub default case, need check");
268     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
269 }
270 
OnRequestCheck(uint32_t code,const std::set<std::string> & permissions)271 int32_t NetConnServiceStub::OnRequestCheck(uint32_t code, const std::set<std::string> &permissions)
272 {
273     if (std::find(SYSTEM_CODE.begin(), SYSTEM_CODE.end(), code) != SYSTEM_CODE.end()) {
274         if (!NetManagerPermission::IsSystemCaller()) {
275             NETMGR_LOG_E("Non-system applications use system APIs.");
276             return NETMANAGER_ERR_NOT_SYSTEM_CALL;
277         }
278     }
279 
280     if (std::find(PERMISSION_NEED_CACHE_CODES.begin(), PERMISSION_NEED_CACHE_CODES.end(), code) !=
281         PERMISSION_NEED_CACHE_CODES.end()) {
282         if (CheckPermissionWithCache(permissions)) {
283             return NETMANAGER_SUCCESS;
284         }
285     } else {
286         if (CheckPermission(permissions)) {
287             return NETMANAGER_SUCCESS;
288         }
289     }
290     return NETMANAGER_ERR_PERMISSION_DENIED;
291 }
292 
CheckPermission(const std::set<std::string> & permissions)293 bool NetConnServiceStub::CheckPermission(const std::set<std::string> &permissions)
294 {
295     for (const auto &permission : permissions) {
296         if (!NetManagerPermission::CheckPermission(permission)) {
297             return false;
298         }
299     }
300     return true;
301 }
302 
CheckPermissionWithCache(const std::set<std::string> & permissions)303 bool NetConnServiceStub::CheckPermissionWithCache(const std::set<std::string> &permissions)
304 {
305     for (const auto &permission : permissions) {
306         if (!NetManagerPermission::CheckPermissionWithCache(permission)) {
307             return false;
308         }
309     }
310     return true;
311 }
312 
OnSystemReady(MessageParcel & data,MessageParcel & reply)313 int32_t NetConnServiceStub::OnSystemReady(MessageParcel &data, MessageParcel &reply)
314 {
315     int32_t ret = SystemReady();
316     if (!reply.WriteInt32(ret)) {
317         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
318     }
319 
320     return NETMANAGER_SUCCESS;
321 }
322 
OnSetInternetPermission(MessageParcel & data,MessageParcel & reply)323 int32_t NetConnServiceStub::OnSetInternetPermission(MessageParcel &data, MessageParcel &reply)
324 {
325     uint32_t uid;
326     if (!data.ReadUint32(uid)) {
327         return NETMANAGER_ERR_READ_DATA_FAIL;
328     }
329 
330     uint8_t allow;
331     if (!data.ReadUint8(allow)) {
332         return NETMANAGER_ERR_READ_DATA_FAIL;
333     }
334 
335     int32_t ret = SetInternetPermission(uid, allow);
336     if (!reply.WriteInt32(ret)) {
337         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
338     }
339 
340     return NETMANAGER_SUCCESS;
341 }
342 
OnEnableVnicNetwork(MessageParcel & data,MessageParcel & reply)343 int32_t NetConnServiceStub::OnEnableVnicNetwork(MessageParcel &data, MessageParcel &reply)
344 {
345     std::set<int32_t> uids;
346     int32_t size = 0;
347     int32_t uid = 0;
348     if (!data.ReadInt32(size)) {
349         return NETMANAGER_ERR_READ_DATA_FAIL;
350     }
351 
352     if (size < 0 || size > MAX_VNIC_UID_ARRAY_SIZE) {
353         NETMGR_LOG_E("vnic uids size is invalid");
354         return NETMANAGER_ERR_READ_DATA_FAIL;
355     }
356 
357     for (int32_t index = 0; index < size; index++) {
358         if (!data.ReadInt32(uid)) {
359             return NETMANAGER_ERR_READ_DATA_FAIL;
360         }
361         uids.insert(uid);
362     }
363 
364     sptr<NetLinkInfo> netLinkInfo = NetLinkInfo::Unmarshalling(data);
365     if (netLinkInfo == nullptr) {
366         NETMGR_LOG_E("netLinkInfo ptr is nullptr.");
367         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
368             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
369         }
370         return NETMANAGER_ERR_LOCAL_PTR_NULL;
371     }
372 
373     int32_t ret = EnableVnicNetwork(netLinkInfo, uids);
374     if (!reply.WriteInt32(ret)) {
375         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
376     }
377     return NETMANAGER_SUCCESS;
378 }
379 
OnDisableVnicNetwork(MessageParcel & data,MessageParcel & reply)380 int32_t NetConnServiceStub::OnDisableVnicNetwork(MessageParcel &data, MessageParcel &reply)
381 {
382     int32_t ret = DisableVnicNetwork();
383     if (!reply.WriteInt32(ret)) {
384         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
385     }
386     return NETMANAGER_SUCCESS;
387 }
388 
OnEnableDistributedClientNet(MessageParcel & data,MessageParcel & reply)389 int32_t NetConnServiceStub::OnEnableDistributedClientNet(MessageParcel &data, MessageParcel &reply)
390 {
391     std::string virnicAddr = "";
392     if (!data.ReadString(virnicAddr)) {
393         return NETMANAGER_ERR_READ_DATA_FAIL;
394     }
395     std::string iif = "";
396     if (!data.ReadString(iif)) {
397         return NETMANAGER_ERR_READ_DATA_FAIL;
398     }
399 
400     int32_t ret = EnableDistributedClientNet(virnicAddr, iif);
401     if (!reply.WriteInt32(ret)) {
402         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
403     }
404     return NETMANAGER_SUCCESS;
405 }
406 
OnEnableDistributedServerNet(MessageParcel & data,MessageParcel & reply)407 int32_t NetConnServiceStub::OnEnableDistributedServerNet(MessageParcel &data, MessageParcel &reply)
408 {
409     std::string iif = "";
410     if (!data.ReadString(iif)) {
411         return NETMANAGER_ERR_READ_DATA_FAIL;
412     }
413     std::string devIface = "";
414     if (!data.ReadString(devIface)) {
415         return NETMANAGER_ERR_READ_DATA_FAIL;
416     }
417     std::string dstAddr = "";
418     if (!data.ReadString(dstAddr)) {
419         return NETMANAGER_ERR_READ_DATA_FAIL;
420     }
421 
422     int32_t ret = EnableDistributedServerNet(iif, devIface, dstAddr);
423     if (!reply.WriteInt32(ret)) {
424         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
425     }
426     return NETMANAGER_SUCCESS;
427 }
428 
OnDisableDistributedNet(MessageParcel & data,MessageParcel & reply)429 int32_t NetConnServiceStub::OnDisableDistributedNet(MessageParcel &data, MessageParcel &reply)
430 {
431     bool isServer = false;
432     if (!data.ReadBool(isServer)) {
433         return NETMANAGER_ERR_READ_DATA_FAIL;
434     }
435 
436     int32_t ret = DisableDistributedNet(isServer);
437     if (!reply.WriteInt32(ret)) {
438         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
439     }
440     return NETMANAGER_SUCCESS;
441 }
442 
OnRegisterNetSupplier(MessageParcel & data,MessageParcel & reply)443 int32_t NetConnServiceStub::OnRegisterNetSupplier(MessageParcel &data, MessageParcel &reply)
444 {
445     NETMGR_LOG_D("stub processing");
446     NetBearType bearerType;
447     std::string ident;
448     std::set<NetCap> netCaps;
449 
450     uint32_t type = 0;
451     if (!data.ReadUint32(type)) {
452         return NETMANAGER_ERR_READ_DATA_FAIL;
453     }
454     if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
455         return NETMANAGER_ERR_INTERNAL;
456     }
457     bearerType = static_cast<NetBearType>(type);
458 
459     if (!data.ReadString(ident)) {
460         return NETMANAGER_ERR_READ_DATA_FAIL;
461     }
462     uint32_t size = 0;
463     uint32_t value = 0;
464     if (!data.ReadUint32(size)) {
465         return NETMANAGER_ERR_READ_DATA_FAIL;
466     }
467     size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
468     for (uint32_t i = 0; i < size; ++i) {
469         if (!data.ReadUint32(value)) {
470             return NETMANAGER_ERR_READ_DATA_FAIL;
471         }
472         if (value < NET_CAPABILITY_END) {
473             netCaps.insert(static_cast<NetCap>(value));
474         }
475     }
476 
477     uint32_t supplierId = 0;
478     int32_t ret = RegisterNetSupplier(bearerType, ident, netCaps, supplierId);
479     if (!reply.WriteInt32(ret)) {
480         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
481     }
482     if (ret == NETMANAGER_SUCCESS) {
483         NETMGR_LOG_D("supplierId[%{public}d].", supplierId);
484         if (!reply.WriteUint32(supplierId)) {
485             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
486         }
487     }
488     return NETMANAGER_SUCCESS;
489 }
490 
OnUpdateNetCaps(MessageParcel & data,MessageParcel & reply)491 int32_t NetConnServiceStub::OnUpdateNetCaps(MessageParcel &data, MessageParcel &reply)
492 {
493     NETMGR_LOG_D("On update net caps.");
494     std::set<NetCap> netCaps;
495     uint32_t netCapsSize = 0;
496     uint32_t netCapVal = 0;
497 
498     if (!data.ReadUint32(netCapsSize)) {
499         return NETMANAGER_ERR_READ_DATA_FAIL;
500     }
501     if (netCapsSize > MAX_NET_CAP_NUM) {
502         return NETMANAGER_EXT_ERR_IPC_CONNECT_STUB_FAIL;
503     }
504     for (uint32_t netCapIndex = 0; netCapIndex < netCapsSize; ++netCapIndex) {
505         if (!data.ReadUint32(netCapVal)) {
506             return NETMANAGER_ERR_READ_DATA_FAIL;
507         }
508         if (netCapVal < NET_CAPABILITY_END) {
509             netCaps.insert(static_cast<NetCap>(netCapVal));
510         }
511     }
512 
513     uint32_t supplierId = 0;
514     if (!data.ReadUint32(supplierId)) {
515         return NETMANAGER_ERR_READ_DATA_FAIL;
516     }
517     int32_t ret = UpdateNetCaps(netCaps, supplierId);
518     if (!reply.WriteInt32(ret)) {
519         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
520     }
521     return NETMANAGER_SUCCESS;
522 }
523 
OnUnregisterNetSupplier(MessageParcel & data,MessageParcel & reply)524 int32_t NetConnServiceStub::OnUnregisterNetSupplier(MessageParcel &data, MessageParcel &reply)
525 {
526     uint32_t supplierId;
527     if (!data.ReadUint32(supplierId)) {
528         return NETMANAGER_ERR_READ_DATA_FAIL;
529     }
530 
531     int32_t ret = UnregisterNetSupplier(supplierId);
532     if (!reply.WriteInt32(ret)) {
533         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
534     }
535 
536     return NETMANAGER_SUCCESS;
537 }
538 
OnRegisterNetSupplierCallback(MessageParcel & data,MessageParcel & reply)539 int32_t NetConnServiceStub::OnRegisterNetSupplierCallback(MessageParcel &data, MessageParcel &reply)
540 {
541     uint32_t supplierId;
542     data.ReadUint32(supplierId);
543     sptr<IRemoteObject> remote = data.ReadRemoteObject();
544     if (remote == nullptr) {
545         NETMGR_LOG_E("Remote ptr is nullptr.");
546         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
547             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
548         }
549         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
550     }
551 
552     sptr<INetSupplierCallback> callback = iface_cast<INetSupplierCallback>(remote);
553     if (callback == nullptr) {
554         NETMGR_LOG_E("Callback ptr is nullptr.");
555         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
556             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
557         }
558         return NETMANAGER_ERR_LOCAL_PTR_NULL;
559     }
560 
561     int32_t result = RegisterNetSupplierCallback(supplierId, callback);
562     if (!reply.WriteInt32(result)) {
563         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
564     }
565     return NETMANAGER_SUCCESS;
566 }
567 
OnRegisterNetConnCallback(MessageParcel & data,MessageParcel & reply)568 int32_t NetConnServiceStub::OnRegisterNetConnCallback(MessageParcel &data, MessageParcel &reply)
569 {
570     sptr<IRemoteObject> remote = data.ReadRemoteObject();
571     if (remote == nullptr) {
572         NETMGR_LOG_E("Remote ptr is nullptr.");
573         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
574             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
575         }
576         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
577     }
578 
579     sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
580     if (callback == nullptr) {
581         NETMGR_LOG_E("Callback ptr is nullptr.");
582         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
583             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
584         }
585         return NETMANAGER_ERR_LOCAL_PTR_NULL;
586     }
587 
588     int32_t result = RegisterNetConnCallback(callback);
589     if (!reply.WriteInt32(result)) {
590         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
591     }
592     return NETMANAGER_SUCCESS;
593 }
594 
OnRegisterNetConnCallbackBySpecifier(MessageParcel & data,MessageParcel & reply)595 int32_t NetConnServiceStub::OnRegisterNetConnCallbackBySpecifier(MessageParcel &data, MessageParcel &reply)
596 {
597     sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
598     uint32_t timeoutMS = data.ReadUint32();
599     sptr<IRemoteObject> remote = data.ReadRemoteObject();
600     if (remote == nullptr) {
601         NETMGR_LOG_E("callback ptr is nullptr.");
602         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
603             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
604         }
605         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
606     }
607 
608     sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
609     if (callback == nullptr) {
610         NETMGR_LOG_E("Callback ptr is nullptr.");
611         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
612             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
613         }
614         return NETMANAGER_ERR_LOCAL_PTR_NULL;
615     }
616 
617     int32_t result = RegisterNetConnCallback(netSpecifier, callback, timeoutMS);
618     if (!reply.WriteInt32(result)) {
619         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
620     }
621     return NETMANAGER_SUCCESS;
622 }
623 
OnRequestNetConnectionBySpecifier(MessageParcel & data,MessageParcel & reply)624 int32_t NetConnServiceStub::OnRequestNetConnectionBySpecifier(MessageParcel &data, MessageParcel &reply)
625 {
626     sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
627     uint32_t timeoutMS = data.ReadUint32();
628     sptr<IRemoteObject> remote = data.ReadRemoteObject();
629     if (remote == nullptr) {
630         NETMGR_LOG_E("Remote ptr is nullptr.");
631         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
632             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
633         }
634         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
635     }
636 
637     sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
638     if (callback == nullptr) {
639         NETMGR_LOG_E("Callback ptr is nullptr.");
640         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
641             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
642         }
643         return NETMANAGER_ERR_LOCAL_PTR_NULL;
644     }
645 
646     int32_t result = RequestNetConnection(netSpecifier, callback, timeoutMS);
647     if (!reply.WriteInt32(result)) {
648         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
649     }
650     return NETMANAGER_SUCCESS;
651 }
652 
OnUnregisterNetConnCallback(MessageParcel & data,MessageParcel & reply)653 int32_t NetConnServiceStub::OnUnregisterNetConnCallback(MessageParcel &data, MessageParcel &reply)
654 {
655     sptr<IRemoteObject> remote = data.ReadRemoteObject();
656     if (remote == nullptr) {
657         NETMGR_LOG_E("Remote ptr is nullptr.");
658         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
659             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
660         }
661         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
662     }
663 
664     sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
665     if (callback == nullptr) {
666         NETMGR_LOG_E("Callback ptr is nullptr.");
667         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
668             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
669         }
670         return NETMANAGER_ERR_LOCAL_PTR_NULL;
671     }
672 
673     int32_t result = UnregisterNetConnCallback(callback);
674     if (!reply.WriteInt32(result)) {
675         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
676     }
677     return NETMANAGER_SUCCESS;
678 }
679 
OnUpdateNetStateForTest(MessageParcel & data,MessageParcel & reply)680 int32_t NetConnServiceStub::OnUpdateNetStateForTest(MessageParcel &data, MessageParcel &reply)
681 {
682     NETMGR_LOG_D("Test NetConnServiceStub::OnUpdateNetStateForTest(), begin");
683     sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
684 
685     int32_t netState;
686     if (!data.ReadInt32(netState)) {
687         return NETMANAGER_ERR_READ_DATA_FAIL;
688     }
689 
690     NETMGR_LOG_D("Test NetConnServiceStub::OnUpdateNetStateForTest(), netState[%{public}d]", netState);
691     int32_t result = UpdateNetStateForTest(netSpecifier, netState);
692     NETMGR_LOG_D("Test NetConnServiceStub::OnUpdateNetStateForTest(), result[%{public}d]", result);
693     if (!reply.WriteInt32(result)) {
694         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
695     }
696     return NETMANAGER_SUCCESS;
697 }
698 
OnUpdateNetSupplierInfo(MessageParcel & data,MessageParcel & reply)699 int32_t NetConnServiceStub::OnUpdateNetSupplierInfo(MessageParcel &data, MessageParcel &reply)
700 {
701     NETMGR_LOG_D("OnUpdateNetSupplierInfo in.");
702     uint32_t supplierId;
703     if (!data.ReadUint32(supplierId)) {
704         NETMGR_LOG_D("fail to get supplier id.");
705         return NETMANAGER_ERR_READ_DATA_FAIL;
706     }
707 
708     NETMGR_LOG_D("OnUpdateNetSupplierInfo supplierId=[%{public}d].", supplierId);
709     sptr<NetSupplierInfo> netSupplierInfo = NetSupplierInfo::Unmarshalling(data);
710     int32_t ret = UpdateNetSupplierInfo(supplierId, netSupplierInfo);
711     if (!reply.WriteInt32(ret)) {
712         NETMGR_LOG_D("fail to update net supplier info.");
713         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
714     }
715     NETMGR_LOG_D("OnUpdateNetSupplierInfo out.");
716 
717     return NETMANAGER_SUCCESS;
718 }
719 
OnUpdateNetLinkInfo(MessageParcel & data,MessageParcel & reply)720 int32_t NetConnServiceStub::OnUpdateNetLinkInfo(MessageParcel &data, MessageParcel &reply)
721 {
722     uint32_t supplierId;
723 
724     if (!data.ReadUint32(supplierId)) {
725         return NETMANAGER_ERR_READ_DATA_FAIL;
726     }
727 
728     sptr<NetLinkInfo> netLinkInfo = NetLinkInfo::Unmarshalling(data);
729 
730     int32_t ret = UpdateNetLinkInfo(supplierId, netLinkInfo);
731     if (!reply.WriteInt32(ret)) {
732         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
733     }
734 
735     return NETMANAGER_SUCCESS;
736 }
737 
OnRegisterNetDetectionCallback(MessageParcel & data,MessageParcel & reply)738 int32_t NetConnServiceStub::OnRegisterNetDetectionCallback(MessageParcel &data, MessageParcel &reply)
739 {
740     if (!data.ContainFileDescriptors()) {
741         NETMGR_LOG_E("Execute ContainFileDescriptors failed");
742     }
743     int32_t netId = 0;
744     if (!data.ReadInt32(netId)) {
745         return NETMANAGER_ERR_READ_DATA_FAIL;
746     }
747 
748     sptr<IRemoteObject> remote = data.ReadRemoteObject();
749     if (remote == nullptr) {
750         NETMGR_LOG_E("Remote ptr is nullptr.");
751         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
752             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
753         }
754         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
755     }
756 
757     sptr<INetDetectionCallback> callback = iface_cast<INetDetectionCallback>(remote);
758     if (callback == nullptr) {
759         NETMGR_LOG_E("Callback ptr is nullptr.");
760         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
761             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
762         }
763         return NETMANAGER_ERR_LOCAL_PTR_NULL;
764     }
765 
766     int32_t result = RegisterNetDetectionCallback(netId, callback);
767     if (!reply.WriteInt32(result)) {
768         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
769     }
770     return NETMANAGER_SUCCESS;
771 }
772 
OnUnRegisterNetDetectionCallback(MessageParcel & data,MessageParcel & reply)773 int32_t NetConnServiceStub::OnUnRegisterNetDetectionCallback(MessageParcel &data, MessageParcel &reply)
774 {
775     if (!data.ContainFileDescriptors()) {
776         NETMGR_LOG_E("Execute ContainFileDescriptors failed");
777     }
778     int32_t netId = 0;
779     if (!data.ReadInt32(netId)) {
780         return NETMANAGER_ERR_READ_DATA_FAIL;
781     }
782 
783     sptr<IRemoteObject> remote = data.ReadRemoteObject();
784     if (remote == nullptr) {
785         NETMGR_LOG_E("Remote ptr is nullptr.");
786         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
787             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
788         }
789         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
790     }
791 
792     sptr<INetDetectionCallback> callback = iface_cast<INetDetectionCallback>(remote);
793     if (callback == nullptr) {
794         NETMGR_LOG_E("Callback ptr is nullptr.");
795         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
796             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
797         }
798         return NETMANAGER_ERR_LOCAL_PTR_NULL;
799     }
800 
801     int32_t result = UnRegisterNetDetectionCallback(netId, callback);
802     if (!reply.WriteInt32(result)) {
803         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
804     }
805     return NETMANAGER_SUCCESS;
806 }
807 
OnNetDetection(MessageParcel & data,MessageParcel & reply)808 int32_t NetConnServiceStub::OnNetDetection(MessageParcel &data, MessageParcel &reply)
809 {
810     int32_t netId = 0;
811     if (!data.ReadInt32(netId)) {
812         return NETMANAGER_ERR_READ_DATA_FAIL;
813     }
814     int32_t ret = NetDetection(netId);
815     if (!reply.WriteInt32(ret)) {
816         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
817     }
818     return NETMANAGER_SUCCESS;
819 }
820 
OnGetIfaceNames(MessageParcel & data,MessageParcel & reply)821 int32_t NetConnServiceStub::OnGetIfaceNames(MessageParcel &data, MessageParcel &reply)
822 {
823     uint32_t netType = 0;
824     if (!data.ReadUint32(netType)) {
825         return NETMANAGER_ERR_READ_DATA_FAIL;
826     }
827     if (netType > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
828         return NETMANAGER_ERR_INTERNAL;
829     }
830     NetBearType bearerType = static_cast<NetBearType>(netType);
831     std::list<std::string> ifaceNames;
832     int32_t ret = GetIfaceNames(bearerType, ifaceNames);
833     if (!reply.WriteInt32(ret)) {
834         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
835     }
836     if (ret == NETMANAGER_SUCCESS) {
837         if (!reply.WriteUint32(ifaceNames.size())) {
838             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
839         }
840 
841         for (const auto &ifaceName : ifaceNames) {
842             if (!reply.WriteString(ifaceName)) {
843                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
844             }
845         }
846     }
847     return NETMANAGER_SUCCESS;
848 }
849 
OnGetIfaceNameByType(MessageParcel & data,MessageParcel & reply)850 int32_t NetConnServiceStub::OnGetIfaceNameByType(MessageParcel &data, MessageParcel &reply)
851 {
852     uint32_t netType = 0;
853     if (!data.ReadUint32(netType)) {
854         return NETMANAGER_ERR_READ_DATA_FAIL;
855     }
856     if (netType > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
857         return NETMANAGER_ERR_INTERNAL;
858     }
859     NetBearType bearerType = static_cast<NetBearType>(netType);
860 
861     std::string ident;
862     if (!data.ReadString(ident)) {
863         return NETMANAGER_ERR_READ_DATA_FAIL;
864     }
865 
866     std::string ifaceName;
867     int32_t ret = GetIfaceNameByType(bearerType, ident, ifaceName);
868     if (!reply.WriteInt32(ret)) {
869         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
870     }
871     if (ret == NETMANAGER_SUCCESS) {
872         if (!reply.WriteString(ifaceName)) {
873             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
874         }
875     }
876     return NETMANAGER_SUCCESS;
877 }
878 
OnGetIfaceNameIdentMaps(MessageParcel & data,MessageParcel & reply)879 int32_t NetConnServiceStub::OnGetIfaceNameIdentMaps(MessageParcel &data, MessageParcel &reply)
880 {
881     uint32_t netType = 0;
882     if (!data.ReadUint32(netType)) {
883         return NETMANAGER_ERR_READ_DATA_FAIL;
884     }
885     if (netType > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
886         return NETMANAGER_ERR_INTERNAL;
887     }
888     NetBearType bearerType = static_cast<NetBearType>(netType);
889     SafeMap<std::string, std::string> ifaceNameIdentMaps;
890     int32_t ret = GetIfaceNameIdentMaps(bearerType, ifaceNameIdentMaps);
891     if (!reply.WriteInt32(ret)) {
892         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
893     }
894     if (ret == NETMANAGER_SUCCESS) {
895         if (!reply.WriteUint32(ifaceNameIdentMaps.Size())) {
896             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
897         }
898         int32_t err = NETMANAGER_SUCCESS;
899         ifaceNameIdentMaps.Iterate([&err, &reply](const std::string &k, const std::string &v) -> void {
900             if (!reply.WriteString(k) || !reply.WriteString(v)) {
901                 err = NETMANAGER_ERR_WRITE_REPLY_FAIL;
902             }
903         });
904         if (err != NETMANAGER_SUCCESS) {
905             return err;
906         }
907     }
908     return NETMANAGER_SUCCESS;
909 }
910 
OnGetDefaultNet(MessageParcel & data,MessageParcel & reply)911 int32_t NetConnServiceStub::OnGetDefaultNet(MessageParcel &data, MessageParcel &reply)
912 {
913     NETMGR_LOG_D("OnGetDefaultNet Begin...");
914     int32_t netId;
915     int32_t result = GetDefaultNet(netId);
916     NETMGR_LOG_D("GetDefaultNet result is: [%{public}d]", result);
917     if (!reply.WriteInt32(result)) {
918         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
919     }
920     if (result == NETMANAGER_SUCCESS) {
921         if (!reply.WriteUint32(netId)) {
922             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
923         }
924     }
925     return NETMANAGER_SUCCESS;
926 }
927 
OnHasDefaultNet(MessageParcel & data,MessageParcel & reply)928 int32_t NetConnServiceStub::OnHasDefaultNet(MessageParcel &data, MessageParcel &reply)
929 {
930     NETMGR_LOG_D("OnHasDefaultNet Begin...");
931     bool flag = false;
932     int32_t result = HasDefaultNet(flag);
933     NETMGR_LOG_D("HasDefaultNet result is: [%{public}d]", result);
934     if (!reply.WriteInt32(result)) {
935         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
936     }
937     if (result == NETMANAGER_SUCCESS) {
938         if (!reply.WriteBool(flag)) {
939             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
940         }
941     }
942     return NETMANAGER_SUCCESS;
943 }
944 
OnGetSpecificNet(MessageParcel & data,MessageParcel & reply)945 int32_t NetConnServiceStub::OnGetSpecificNet(MessageParcel &data, MessageParcel &reply)
946 {
947     uint32_t type;
948     if (!data.ReadUint32(type)) {
949         return NETMANAGER_ERR_READ_DATA_FAIL;
950     }
951 
952     if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
953         return NETMANAGER_ERR_INTERNAL;
954     }
955 
956     NetBearType bearerType = static_cast<NetBearType>(type);
957 
958     NETMGR_LOG_D("stub execute GetSpecificNet");
959     std::list<int32_t> netIdList;
960     int32_t ret = GetSpecificNet(bearerType, netIdList);
961     if (!reply.WriteInt32(ret)) {
962         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
963     }
964     if (ret == NETMANAGER_SUCCESS) {
965         uint32_t size = static_cast<uint32_t>(netIdList.size());
966         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
967         if (!reply.WriteUint32(size)) {
968             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
969         }
970 
971         uint32_t index = 0;
972         for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
973             if (++index > MAX_IFACE_NUM) {
974                 break;
975             }
976             if (!reply.WriteInt32(*p)) {
977                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
978             }
979         }
980     }
981     return NETMANAGER_SUCCESS;
982 }
983 
OnGetSpecificNetByIdent(MessageParcel & data,MessageParcel & reply)984 int32_t NetConnServiceStub::OnGetSpecificNetByIdent(MessageParcel &data, MessageParcel &reply)
985 {
986     uint32_t type;
987     std::string ident = "";
988     if (!data.ReadUint32(type)) {
989         return NETMANAGER_ERR_READ_DATA_FAIL;
990     }
991 
992     if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
993         return NETMANAGER_ERR_INTERNAL;
994     }
995 
996     NetBearType bearerType = static_cast<NetBearType>(type);
997     if (!data.ReadString(ident)) {
998         return NETMANAGER_ERR_READ_DATA_FAIL;
999     }
1000 
1001     NETMGR_LOG_D("stub execute GetSpecificNetByIdent");
1002     std::list<int32_t> netIdList;
1003     int32_t ret = GetSpecificNetByIdent(bearerType, ident, netIdList);
1004     if (!reply.WriteInt32(ret)) {
1005         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1006     }
1007     if (ret == NETMANAGER_SUCCESS) {
1008         uint32_t size = static_cast<uint32_t>(netIdList.size());
1009         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1010         if (!reply.WriteUint32(size)) {
1011             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1012         }
1013 
1014         uint32_t index = 0;
1015         for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1016             if (++index > MAX_IFACE_NUM) {
1017                 break;
1018             }
1019             if (!reply.WriteInt32(*p)) {
1020                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1021             }
1022         }
1023     }
1024     return NETMANAGER_SUCCESS;
1025 }
1026 
OnGetAllNets(MessageParcel & data,MessageParcel & reply)1027 int32_t NetConnServiceStub::OnGetAllNets(MessageParcel &data, MessageParcel &reply)
1028 {
1029     NETMGR_LOG_D("stub execute GetAllNets");
1030     std::list<int32_t> netIdList;
1031     int32_t ret = GetAllNets(netIdList);
1032     if (!reply.WriteInt32(ret)) {
1033         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1034     }
1035     if (ret == NETMANAGER_SUCCESS) {
1036         uint32_t size = static_cast<uint32_t>(netIdList.size());
1037         if (!reply.WriteUint32(size)) {
1038             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1039         }
1040 
1041         for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1042             if (!reply.WriteInt32(*p)) {
1043                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1044             }
1045         }
1046     }
1047     return NETMANAGER_SUCCESS;
1048 }
1049 
OnGetSpecificUidNet(MessageParcel & data,MessageParcel & reply)1050 int32_t NetConnServiceStub::OnGetSpecificUidNet(MessageParcel &data, MessageParcel &reply)
1051 {
1052     int32_t uid = 0;
1053     if (!data.ReadInt32(uid)) {
1054         return NETMANAGER_ERR_READ_DATA_FAIL;
1055     }
1056     NETMGR_LOG_D("stub execute GetSpecificUidNet");
1057 
1058     int32_t netId = 0;
1059     int32_t ret = GetSpecificUidNet(uid, netId);
1060     if (!reply.WriteInt32(ret)) {
1061         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1062     }
1063     if (ret == NETMANAGER_SUCCESS) {
1064         if (!reply.WriteInt32(netId)) {
1065             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1066         }
1067     }
1068     return NETMANAGER_SUCCESS;
1069 }
1070 
OnGetConnectionProperties(MessageParcel & data,MessageParcel & reply)1071 int32_t NetConnServiceStub::OnGetConnectionProperties(MessageParcel &data, MessageParcel &reply)
1072 {
1073     int32_t netId = 0;
1074     if (!data.ReadInt32(netId)) {
1075         return NETMANAGER_ERR_READ_DATA_FAIL;
1076     }
1077 
1078     NETMGR_LOG_D("stub execute GetConnectionProperties");
1079     NetLinkInfo info;
1080     int32_t ret = GetConnectionProperties(netId, info);
1081     if (!reply.WriteInt32(ret)) {
1082         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1083     }
1084     if (ret == NETMANAGER_SUCCESS) {
1085         sptr<NetLinkInfo> netLinkInfo_ptr = new (std::nothrow) NetLinkInfo(info);
1086         if (!NetLinkInfo::Marshalling(reply, netLinkInfo_ptr)) {
1087             NETMGR_LOG_E("proxy Marshalling failed");
1088             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1089         }
1090     }
1091     return NETMANAGER_SUCCESS;
1092 }
1093 
OnGetNetCapabilities(MessageParcel & data,MessageParcel & reply)1094 int32_t NetConnServiceStub::OnGetNetCapabilities(MessageParcel &data, MessageParcel &reply)
1095 {
1096     int32_t netId = 0;
1097     if (!data.ReadInt32(netId)) {
1098         return NETMANAGER_ERR_READ_DATA_FAIL;
1099     }
1100 
1101     NETMGR_LOG_D("stub execute GetNetCapabilities");
1102 
1103     NetAllCapabilities netAllCap;
1104     int32_t ret = GetNetCapabilities(netId, netAllCap);
1105     if (!reply.WriteInt32(ret)) {
1106         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1107     }
1108     if (ret == NETMANAGER_SUCCESS) {
1109         if (!reply.WriteUint32(netAllCap.linkUpBandwidthKbps_) ||
1110             !reply.WriteUint32(netAllCap.linkDownBandwidthKbps_)) {
1111             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1112         }
1113         uint32_t size = netAllCap.netCaps_.size();
1114         size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
1115         if (!reply.WriteUint32(size)) {
1116             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1117         }
1118         uint32_t index = 0;
1119         for (auto netCap : netAllCap.netCaps_) {
1120             if (++index > MAX_NET_CAP_NUM) {
1121                 break;
1122             }
1123             if (!reply.WriteUint32(static_cast<uint32_t>(netCap))) {
1124                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1125             }
1126         }
1127 
1128         size = netAllCap.bearerTypes_.size();
1129         size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
1130         if (!reply.WriteUint32(size)) {
1131             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1132         }
1133         index = 0;
1134         for (auto bearerType : netAllCap.bearerTypes_) {
1135             if (++index > MAX_NET_CAP_NUM) {
1136                 break;
1137             }
1138             if (!reply.WriteUint32(static_cast<uint32_t>(bearerType))) {
1139                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1140             }
1141         }
1142     }
1143     return NETMANAGER_SUCCESS;
1144 }
1145 
OnGetAddressesByName(MessageParcel & data,MessageParcel & reply)1146 int32_t NetConnServiceStub::OnGetAddressesByName(MessageParcel &data, MessageParcel &reply)
1147 {
1148     std::string host;
1149     if (!data.ReadString(host)) {
1150         return NETMANAGER_ERR_READ_DATA_FAIL;
1151     }
1152     int32_t netId;
1153     if (!data.ReadInt32(netId)) {
1154         return NETMANAGER_ERR_READ_DATA_FAIL;
1155     }
1156     NETMGR_LOG_D("stub execute GetAddressesByName");
1157     std::vector<INetAddr> addrList;
1158     int32_t ret = GetAddressesByName(host, netId, addrList);
1159     if (!reply.WriteInt32(ret)) {
1160         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1161     }
1162     if (ret == NETMANAGER_SUCCESS) {
1163         uint32_t size = static_cast<uint32_t>(addrList.size());
1164         size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
1165         if (!reply.WriteUint32(size)) {
1166             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1167         }
1168         uint32_t index = 0;
1169         for (auto p = addrList.begin(); p != addrList.end(); ++p) {
1170             if (++index > MAX_IFACE_NUM) {
1171                 break;
1172             }
1173             sptr<INetAddr> netaddr_ptr = (std::make_unique<INetAddr>(*p)).release();
1174             if (!INetAddr::Marshalling(reply, netaddr_ptr)) {
1175                 NETMGR_LOG_E("proxy Marshalling failed");
1176                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1177             }
1178         }
1179     }
1180     return NETMANAGER_SUCCESS;
1181 }
1182 
OnGetAddressByName(MessageParcel & data,MessageParcel & reply)1183 int32_t NetConnServiceStub::OnGetAddressByName(MessageParcel &data, MessageParcel &reply)
1184 {
1185     std::string host;
1186     if (!data.ReadString(host)) {
1187         return NETMANAGER_ERR_READ_DATA_FAIL;
1188     }
1189     int32_t netId;
1190     if (!data.ReadInt32(netId)) {
1191         return NETMANAGER_ERR_READ_DATA_FAIL;
1192     }
1193     NETMGR_LOG_D("stub execute GetAddressByName");
1194     INetAddr addr;
1195     int32_t ret = GetAddressByName(host, netId, addr);
1196     if (!reply.WriteInt32(ret)) {
1197         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1198     }
1199     if (ret == NETMANAGER_SUCCESS) {
1200         sptr<INetAddr> netaddr_ptr = (std::make_unique<INetAddr>(addr)).release();
1201         if (!INetAddr::Marshalling(reply, netaddr_ptr)) {
1202             NETMGR_LOG_E("proxy Marshalling failed");
1203             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1204         }
1205     }
1206     return NETMANAGER_SUCCESS;
1207 }
1208 
OnBindSocket(MessageParcel & data,MessageParcel & reply)1209 int32_t NetConnServiceStub::OnBindSocket(MessageParcel &data, MessageParcel &reply)
1210 {
1211     int32_t socketFd;
1212     if (!data.ReadInt32(socketFd)) {
1213         return NETMANAGER_ERR_READ_DATA_FAIL;
1214     }
1215     int32_t netId;
1216     if (!data.ReadInt32(netId)) {
1217         return NETMANAGER_ERR_READ_DATA_FAIL;
1218     }
1219     NETMGR_LOG_D("stub execute BindSocket");
1220 
1221     int32_t ret = BindSocket(socketFd, netId);
1222     if (!reply.WriteInt32(ret)) {
1223         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1224     }
1225     return NETMANAGER_SUCCESS;
1226 }
1227 
OnSetAirplaneMode(MessageParcel & data,MessageParcel & reply)1228 int32_t NetConnServiceStub::OnSetAirplaneMode(MessageParcel &data, MessageParcel &reply)
1229 {
1230     bool state = false;
1231     if (!data.ReadBool(state)) {
1232         return NETMANAGER_ERR_READ_DATA_FAIL;
1233     }
1234     int32_t ret = SetAirplaneMode(state);
1235     if (!reply.WriteInt32(ret)) {
1236         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1237     }
1238     return NETMANAGER_SUCCESS;
1239 }
1240 
OnIsDefaultNetMetered(MessageParcel & data,MessageParcel & reply)1241 int32_t NetConnServiceStub::OnIsDefaultNetMetered(MessageParcel &data, MessageParcel &reply)
1242 {
1243     NETMGR_LOG_D("stub execute IsDefaultNetMetered");
1244     bool flag = false;
1245     int32_t result = IsDefaultNetMetered(flag);
1246     if (!reply.WriteInt32(result)) {
1247         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1248     }
1249     if (result == NETMANAGER_SUCCESS) {
1250         if (!reply.WriteBool(flag)) {
1251             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1252         }
1253     }
1254     return NETMANAGER_SUCCESS;
1255 }
1256 
OnSetGlobalHttpProxy(MessageParcel & data,MessageParcel & reply)1257 int32_t NetConnServiceStub::OnSetGlobalHttpProxy(MessageParcel &data, MessageParcel &reply)
1258 {
1259     NETMGR_LOG_D("stub execute SetGlobalHttpProxy");
1260 
1261     HttpProxy httpProxy;
1262     if (!HttpProxy::Unmarshalling(data, httpProxy)) {
1263         return ERR_FLATTEN_OBJECT;
1264     }
1265     if (httpProxy.GetUserId() == 0) {
1266         httpProxy.SetUserId(PRIMARY_USER_ID);
1267         NETMGR_LOG_I("SetGlobalHttpProxy change userId");
1268     }
1269 
1270     int32_t ret = SetGlobalHttpProxy(httpProxy);
1271     if (!reply.WriteInt32(ret)) {
1272         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1273     }
1274     return NETMANAGER_SUCCESS;
1275 }
1276 
OnGetGlobalHttpProxy(MessageParcel & data,MessageParcel & reply)1277 int32_t NetConnServiceStub::OnGetGlobalHttpProxy(MessageParcel &data, MessageParcel &reply)
1278 {
1279     int32_t userId = -1;
1280     if (!data.ReadInt32(userId)) {
1281         NETMGR_LOG_E("ReadUserId failed");
1282         return NETMANAGER_ERR_READ_DATA_FAIL;
1283     }
1284 
1285     HttpProxy httpProxy;
1286     httpProxy.SetUserId(userId);
1287     int32_t result = GetGlobalHttpProxy(httpProxy);
1288     if (!reply.WriteInt32(result)) {
1289         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1290     }
1291 
1292     if (result != NETMANAGER_SUCCESS) {
1293         return result;
1294     }
1295 
1296     if (!httpProxy.Marshalling(reply)) {
1297         return ERR_FLATTEN_OBJECT;
1298     }
1299     return NETMANAGER_SUCCESS;
1300 }
1301 
OnGetDefaultHttpProxy(MessageParcel & data,MessageParcel & reply)1302 int32_t NetConnServiceStub::OnGetDefaultHttpProxy(MessageParcel &data, MessageParcel &reply)
1303 {
1304     NETMGR_LOG_D("stub execute OnGetDefaultHttpProxy");
1305     int32_t bindNetId = 0;
1306     if (!data.ReadInt32(bindNetId)) {
1307         return NETMANAGER_ERR_READ_DATA_FAIL;
1308     }
1309     int32_t userId = -1;
1310     if (!data.ReadInt32(userId)) {
1311         NETMGR_LOG_E("ReadUserId failed");
1312         return NETMANAGER_ERR_READ_DATA_FAIL;
1313     }
1314     HttpProxy httpProxy;
1315     httpProxy.SetUserId(userId);
1316     int32_t result = GetDefaultHttpProxy(bindNetId, httpProxy);
1317     if (!reply.WriteInt32(result)) {
1318         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1319     }
1320 
1321     if (result != NETMANAGER_SUCCESS) {
1322         return result;
1323     }
1324 
1325     if (!httpProxy.Marshalling(reply)) {
1326         return ERR_FLATTEN_OBJECT;
1327     }
1328     return NETMANAGER_SUCCESS;
1329 }
1330 
OnGetPacUrl(MessageParcel & data,MessageParcel & reply)1331 int32_t NetConnServiceStub::OnGetPacUrl(MessageParcel &data, MessageParcel &reply)
1332 {
1333     NETMGR_LOG_D("stub execute OnGetPacUrl");
1334     std::string pacUrl = "";
1335     int32_t ret = GetPacUrl(pacUrl);
1336     if (!reply.WriteInt32(ret)) {
1337         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1338     }
1339     if (ret != NETMANAGER_SUCCESS) {
1340         return ret;
1341     }
1342     if (!reply.WriteString(pacUrl)) {
1343         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1344     }
1345 
1346     return NETMANAGER_SUCCESS;
1347 }
1348 
OnSetPacUrl(MessageParcel & data,MessageParcel & reply)1349 int32_t NetConnServiceStub::OnSetPacUrl(MessageParcel &data, MessageParcel &reply)
1350 {
1351     NETMGR_LOG_D("stub execute OnSetPacUrl");
1352     std::string pacUrl;
1353     if (!data.ReadString(pacUrl)) {
1354         return NETMANAGER_ERR_READ_DATA_FAIL;
1355     }
1356 
1357     int32_t ret = SetPacUrl(pacUrl);
1358     if (!reply.WriteInt32(ret)) {
1359         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1360     }
1361 
1362     return NETMANAGER_SUCCESS;
1363 }
1364 
OnGetNetIdByIdentifier(MessageParcel & data,MessageParcel & reply)1365 int32_t NetConnServiceStub::OnGetNetIdByIdentifier(MessageParcel &data, MessageParcel &reply)
1366 {
1367     NETMGR_LOG_D("stub execute OnGetNetIdByIdentifier");
1368     std::string ident;
1369     if (!data.ReadString(ident)) {
1370         return NETMANAGER_ERR_READ_DATA_FAIL;
1371     }
1372 
1373     std::list<int32_t> netIdList;
1374     int32_t ret = GetNetIdByIdentifier(ident, netIdList);
1375     if (!reply.WriteInt32(ret)) {
1376         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1377     }
1378 
1379     if (ret == NETMANAGER_SUCCESS) {
1380         uint32_t size = static_cast<uint32_t>(netIdList.size());
1381         if (!reply.WriteUint32(size)) {
1382             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1383         }
1384         for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
1385             if (!reply.WriteInt32(*p)) {
1386                 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1387             }
1388         }
1389     }
1390     return NETMANAGER_SUCCESS;
1391 }
1392 
OnSetAppNet(MessageParcel & data,MessageParcel & reply)1393 int32_t NetConnServiceStub::OnSetAppNet(MessageParcel &data, MessageParcel &reply)
1394 {
1395     int32_t netId = 0;
1396     if (!data.ReadInt32(netId)) {
1397         return NETMANAGER_ERR_READ_DATA_FAIL;
1398     }
1399     int ret = SetAppNet(netId);
1400     if (!reply.WriteInt32(ret)) {
1401         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1402     }
1403     return NETMANAGER_SUCCESS;
1404 }
1405 
OnRegisterNetInterfaceCallback(MessageParcel & data,MessageParcel & reply)1406 int32_t NetConnServiceStub::OnRegisterNetInterfaceCallback(MessageParcel &data, MessageParcel &reply)
1407 {
1408     sptr<IRemoteObject> remote = data.ReadRemoteObject();
1409     if (remote == nullptr) {
1410         NETMGR_LOG_E("Remote ptr is nullptr.");
1411         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1412             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1413         }
1414         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1415     }
1416 
1417     sptr<INetInterfaceStateCallback> callback = iface_cast<INetInterfaceStateCallback>(remote);
1418     int32_t ret = RegisterNetInterfaceCallback(callback);
1419     if (!reply.WriteInt32(ret)) {
1420         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1421     }
1422     return NETMANAGER_SUCCESS;
1423 }
1424 
OnUnregisterNetInterfaceCallback(MessageParcel & data,MessageParcel & reply)1425 int32_t NetConnServiceStub::OnUnregisterNetInterfaceCallback(MessageParcel &data, MessageParcel &reply)
1426 {
1427     sptr<IRemoteObject> remote = data.ReadRemoteObject();
1428     if (remote == nullptr) {
1429         NETMGR_LOG_E("Remote ptr is nullptr.");
1430         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1431             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1432         }
1433         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1434     }
1435 
1436     sptr<INetInterfaceStateCallback> callback = iface_cast<INetInterfaceStateCallback>(remote);
1437     int32_t ret = UnregisterNetInterfaceCallback(callback);
1438     if (!reply.WriteInt32(ret)) {
1439         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1440     }
1441     return NETMANAGER_SUCCESS;
1442 }
1443 
OnGetNetInterfaceConfiguration(MessageParcel & data,MessageParcel & reply)1444 int32_t NetConnServiceStub::OnGetNetInterfaceConfiguration(MessageParcel &data, MessageParcel &reply)
1445 {
1446     std::string iface;
1447     if (!data.ReadString(iface)) {
1448         return NETMANAGER_ERR_READ_DATA_FAIL;
1449     }
1450 
1451     NetInterfaceConfiguration config;
1452     int32_t ret = GetNetInterfaceConfiguration(iface, config);
1453     if (!reply.WriteInt32(ret)) {
1454         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1455     }
1456 
1457     if (ret == NETMANAGER_SUCCESS) {
1458         if (!config.Marshalling(reply)) {
1459             return ERR_FLATTEN_OBJECT;
1460         }
1461     }
1462     return NETMANAGER_SUCCESS;
1463 }
1464 
OnSetNetInterfaceIpAddress(MessageParcel & data,MessageParcel & reply)1465 int32_t NetConnServiceStub::OnSetNetInterfaceIpAddress(MessageParcel &data, MessageParcel &reply)
1466 {
1467     std::string iface;
1468     if (!data.ReadString(iface)) {
1469         return NETMANAGER_ERR_READ_DATA_FAIL;
1470     }
1471 
1472     std::string ipAddress;
1473     if (!data.ReadString(ipAddress)) {
1474         return NETMANAGER_ERR_READ_DATA_FAIL;
1475     }
1476 
1477     int32_t ret = SetNetInterfaceIpAddress(iface, ipAddress);
1478     if (!reply.WriteInt32(ret)) {
1479         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1480     }
1481 
1482     return NETMANAGER_SUCCESS;
1483 }
1484 
OnSetInterfaceUp(MessageParcel & data,MessageParcel & reply)1485 int32_t NetConnServiceStub::OnSetInterfaceUp(MessageParcel &data, MessageParcel &reply)
1486 {
1487     std::string iface;
1488     if (!data.ReadString(iface)) {
1489         return NETMANAGER_ERR_READ_DATA_FAIL;
1490     }
1491 
1492     int32_t ret = SetInterfaceUp(iface);
1493     if (!reply.WriteInt32(ret)) {
1494         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1495     }
1496 
1497     return NETMANAGER_SUCCESS;
1498 }
1499 
OnSetInterfaceDown(MessageParcel & data,MessageParcel & reply)1500 int32_t NetConnServiceStub::OnSetInterfaceDown(MessageParcel &data, MessageParcel &reply)
1501 {
1502     std::string iface;
1503     if (!data.ReadString(iface)) {
1504         return NETMANAGER_ERR_READ_DATA_FAIL;
1505     }
1506 
1507     int32_t ret = SetInterfaceDown(iface);
1508     if (!reply.WriteInt32(ret)) {
1509         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1510     }
1511 
1512     return NETMANAGER_SUCCESS;
1513 }
1514 
OnAddNetworkRoute(MessageParcel & data,MessageParcel & reply)1515 int32_t NetConnServiceStub::OnAddNetworkRoute(MessageParcel &data, MessageParcel &reply)
1516 {
1517     int32_t netId = 0;
1518     if (!data.ReadInt32(netId)) {
1519         return NETMANAGER_ERR_READ_DATA_FAIL;
1520     }
1521 
1522     std::string ifName = "";
1523     if (!data.ReadString(ifName)) {
1524         return NETMANAGER_ERR_READ_DATA_FAIL;
1525     }
1526 
1527     std::string destination = "";
1528     if (!data.ReadString(destination)) {
1529         return NETMANAGER_ERR_READ_DATA_FAIL;
1530     }
1531 
1532     std::string nextHop = "";
1533     if (!data.ReadString(nextHop)) {
1534         return NETMANAGER_ERR_READ_DATA_FAIL;
1535     }
1536 
1537     int32_t ret = AddNetworkRoute(netId, ifName, destination, nextHop);
1538     if (!reply.WriteInt32(ret)) {
1539         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1540     }
1541 
1542     return NETMANAGER_SUCCESS;
1543 }
1544 
1545 
OnRemoveNetworkRoute(MessageParcel & data,MessageParcel & reply)1546 int32_t NetConnServiceStub::OnRemoveNetworkRoute(MessageParcel &data, MessageParcel &reply)
1547 {
1548     int32_t netId = 0;
1549     if (!data.ReadInt32(netId)) {
1550         return NETMANAGER_ERR_READ_DATA_FAIL;
1551     }
1552 
1553     std::string ifName = "";
1554     if (!data.ReadString(ifName)) {
1555         return NETMANAGER_ERR_READ_DATA_FAIL;
1556     }
1557 
1558     std::string destination = "";
1559     if (!data.ReadString(destination)) {
1560         return NETMANAGER_ERR_READ_DATA_FAIL;
1561     }
1562 
1563     std::string nextHop = "";
1564     if (!data.ReadString(nextHop)) {
1565         return NETMANAGER_ERR_READ_DATA_FAIL;
1566     }
1567 
1568     int32_t ret = RemoveNetworkRoute(netId, ifName, destination, nextHop);
1569     if (!reply.WriteInt32(ret)) {
1570         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1571     }
1572 
1573     return NETMANAGER_SUCCESS;
1574 }
1575 
OnAddInterfaceAddress(MessageParcel & data,MessageParcel & reply)1576 int32_t NetConnServiceStub::OnAddInterfaceAddress(MessageParcel &data, MessageParcel &reply)
1577 {
1578     std::string ifName = "";
1579     if (!data.ReadString(ifName)) {
1580         return NETMANAGER_ERR_READ_DATA_FAIL;
1581     }
1582 
1583     std::string ipAddr = "";
1584     if (!data.ReadString(ipAddr)) {
1585         return NETMANAGER_ERR_READ_DATA_FAIL;
1586     }
1587 
1588     int32_t prefixLength = 0;
1589     if (!data.ReadInt32(prefixLength)) {
1590         return NETMANAGER_ERR_READ_DATA_FAIL;
1591     }
1592 
1593     int32_t ret = AddInterfaceAddress(ifName, ipAddr, prefixLength);
1594     if (!reply.WriteInt32(ret)) {
1595         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1596     }
1597 
1598     return NETMANAGER_SUCCESS;
1599 }
1600 
OnDelInterfaceAddress(MessageParcel & data,MessageParcel & reply)1601 int32_t NetConnServiceStub::OnDelInterfaceAddress(MessageParcel &data, MessageParcel &reply)
1602 {
1603     std::string ifName = "";
1604     if (!data.ReadString(ifName)) {
1605         return NETMANAGER_ERR_READ_DATA_FAIL;
1606     }
1607 
1608     std::string ipAddr = "";
1609     if (!data.ReadString(ipAddr)) {
1610         return NETMANAGER_ERR_READ_DATA_FAIL;
1611     }
1612 
1613     int32_t prefixLength = 0;
1614     if (!data.ReadInt32(prefixLength)) {
1615         return NETMANAGER_ERR_READ_DATA_FAIL;
1616     }
1617 
1618     int32_t ret = DelInterfaceAddress(ifName, ipAddr, prefixLength);
1619     if (!reply.WriteInt32(ret)) {
1620         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1621     }
1622 
1623     return NETMANAGER_SUCCESS;
1624 }
1625 
OnAddStaticArp(MessageParcel & data,MessageParcel & reply)1626 int32_t NetConnServiceStub::OnAddStaticArp(MessageParcel &data, MessageParcel &reply)
1627 {
1628     std::string ipAddr = "";
1629     if (!data.ReadString(ipAddr)) {
1630         return NETMANAGER_ERR_READ_DATA_FAIL;
1631     }
1632 
1633     std::string macAddr = "";
1634     if (!data.ReadString(macAddr)) {
1635         return NETMANAGER_ERR_READ_DATA_FAIL;
1636     }
1637 
1638     std::string ifName = "";
1639     if (!data.ReadString(ifName)) {
1640         return NETMANAGER_ERR_READ_DATA_FAIL;
1641     }
1642 
1643     int32_t ret = AddStaticArp(ipAddr, macAddr, ifName);
1644     if (!reply.WriteInt32(ret)) {
1645         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1646     }
1647 
1648     return NETMANAGER_SUCCESS;
1649 }
1650 
OnDelStaticArp(MessageParcel & data,MessageParcel & reply)1651 int32_t NetConnServiceStub::OnDelStaticArp(MessageParcel &data, MessageParcel &reply)
1652 {
1653     std::string ipAddr = "";
1654     if (!data.ReadString(ipAddr)) {
1655         return NETMANAGER_ERR_READ_DATA_FAIL;
1656     }
1657 
1658     std::string macAddr = "";
1659     if (!data.ReadString(macAddr)) {
1660         return NETMANAGER_ERR_READ_DATA_FAIL;
1661     }
1662 
1663     std::string ifName = "";
1664     if (!data.ReadString(ifName)) {
1665         return NETMANAGER_ERR_READ_DATA_FAIL;
1666     }
1667 
1668     int32_t ret = DelStaticArp(ipAddr, macAddr, ifName);
1669     if (!reply.WriteInt32(ret)) {
1670         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1671     }
1672 
1673     return NETMANAGER_SUCCESS;
1674 }
1675 
OnRegisterSlotType(MessageParcel & data,MessageParcel & reply)1676 int32_t NetConnServiceStub::OnRegisterSlotType(MessageParcel &data, MessageParcel &reply)
1677 {
1678     uint32_t supplierId = 0;
1679     if (!data.ReadUint32(supplierId)) {
1680         return NETMANAGER_ERR_READ_DATA_FAIL;
1681     }
1682 
1683     int32_t type = 0;
1684     if (!data.ReadInt32(type)) {
1685         return NETMANAGER_ERR_READ_DATA_FAIL;
1686     }
1687 
1688     int32_t ret = RegisterSlotType(supplierId, type);
1689     if (!reply.WriteInt32(ret)) {
1690         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1691     }
1692 
1693     return NETMANAGER_SUCCESS;
1694 }
1695 
OnGetSlotType(MessageParcel & data,MessageParcel & reply)1696 int32_t NetConnServiceStub::OnGetSlotType(MessageParcel &data, MessageParcel &reply)
1697 {
1698     std::string type = "";
1699     int32_t ret = GetSlotType(type);
1700     if (!reply.WriteInt32(ret)) {
1701         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1702     }
1703     if (!reply.WriteString(type)) {
1704         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1705     }
1706     return NETMANAGER_SUCCESS;
1707 }
1708 
OnFactoryResetNetwork(MessageParcel & data,MessageParcel & reply)1709 int32_t NetConnServiceStub::OnFactoryResetNetwork(MessageParcel &data, MessageParcel &reply)
1710 {
1711     int32_t ret = FactoryResetNetwork();
1712     if (!reply.WriteInt32(ret)) {
1713         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1714     }
1715 
1716     return NETMANAGER_SUCCESS;
1717 }
1718 
OnRegisterNetFactoryResetCallback(MessageParcel & data,MessageParcel & reply)1719 int32_t NetConnServiceStub::OnRegisterNetFactoryResetCallback(MessageParcel &data, MessageParcel &reply)
1720 {
1721     sptr<IRemoteObject> remote = data.ReadRemoteObject();
1722     if (remote == nullptr) {
1723         NETMGR_LOG_E("Remote ptr is nullptr.");
1724         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1725             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1726         }
1727         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1728     }
1729 
1730     sptr<INetFactoryResetCallback> callback = iface_cast<INetFactoryResetCallback>(remote);
1731     if (callback == nullptr) {
1732         NETMGR_LOG_E("Callback ptr is nullptr.");
1733         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
1734             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1735         }
1736         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1737     }
1738 
1739     int32_t result = RegisterNetFactoryResetCallback(callback);
1740     if (!reply.WriteInt32(result)) {
1741         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1742     }
1743 
1744     return NETMANAGER_SUCCESS;
1745 }
1746 
OnIsPreferCellularUrl(MessageParcel & data,MessageParcel & reply)1747 int32_t NetConnServiceStub::OnIsPreferCellularUrl(MessageParcel &data, MessageParcel &reply)
1748 {
1749     std::string url;
1750     if (!data.ReadString(url)) {
1751         return NETMANAGER_ERR_READ_DATA_FAIL;
1752     }
1753     bool preferCellular = false;
1754     int32_t ret = IsPreferCellularUrl(url, preferCellular);
1755     if (!reply.WriteInt32(ret)) {
1756         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1757     }
1758     if (!reply.WriteBool(preferCellular)) {
1759         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1760     }
1761 
1762     return NETMANAGER_SUCCESS;
1763 }
1764 
OnDecreaseSupplierScore(MessageParcel & data,MessageParcel & reply)1765 int32_t NetConnServiceStub::OnDecreaseSupplierScore(MessageParcel &data, MessageParcel &reply)
1766 {
1767     uint32_t type = 0;
1768     std::string ident = "";
1769     uint32_t supplierId;
1770     if (!data.ReadUint32(type)) {
1771         return NETMANAGER_ERR_READ_DATA_FAIL;
1772     }
1773     if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
1774         return NETMANAGER_ERR_INTERNAL;
1775     }
1776     if (!data.ReadString(ident)) {
1777         return NETMANAGER_ERR_READ_DATA_FAIL;
1778     }
1779     if (!data.ReadUint32(supplierId)) {
1780         return NETMANAGER_ERR_READ_DATA_FAIL;
1781     }
1782     NetBearType bearerType = static_cast<NetBearType>(type);
1783     int32_t ret = DecreaseSupplierScore(bearerType, ident, supplierId);
1784     if (!reply.WriteInt32(ret)) {
1785         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1786     }
1787     if (ret == NETMANAGER_SUCCESS) {
1788         NETMGR_LOG_D("supplierId[%{public}d].", supplierId);
1789         if (!reply.WriteUint32(supplierId)) {
1790             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1791         }
1792     }
1793     return NETMANAGER_SUCCESS;
1794 }
1795 
OnIncreaseSupplierScore(MessageParcel & data,MessageParcel & reply)1796 int32_t NetConnServiceStub::OnIncreaseSupplierScore(MessageParcel &data, MessageParcel &reply)
1797 {
1798     uint32_t supplierId;
1799     if (!data.ReadUint32(supplierId)) {
1800         return NETMANAGER_ERR_READ_DATA_FAIL;
1801     }
1802     int32_t ret = IncreaseSupplierScore(supplierId);
1803     if (!reply.WriteInt32(ret)) {
1804         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1805     }
1806     return NETMANAGER_SUCCESS;
1807 }
1808 
OnRegisterPreAirplaneCallback(MessageParcel & data,MessageParcel & reply)1809 int32_t NetConnServiceStub::OnRegisterPreAirplaneCallback(MessageParcel &data, MessageParcel &reply)
1810 {
1811     sptr<IRemoteObject> remote = data.ReadRemoteObject();
1812     if (remote == nullptr) {
1813         NETMGR_LOG_E("Remote ptr is nullptr.");
1814         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1815             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1816         }
1817         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1818     }
1819 
1820     sptr<IPreAirplaneCallback> callback = iface_cast<IPreAirplaneCallback>(remote);
1821     if (callback == nullptr) {
1822         NETMGR_LOG_E("Callback ptr is nullptr.");
1823         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
1824             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1825         }
1826         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1827     }
1828 
1829     int32_t result = RegisterPreAirplaneCallback(callback);
1830     if (!reply.WriteInt32(result)) {
1831         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1832     }
1833 
1834     return NETMANAGER_SUCCESS;
1835 }
1836 
OnUnregisterPreAirplaneCallback(MessageParcel & data,MessageParcel & reply)1837 int32_t NetConnServiceStub::OnUnregisterPreAirplaneCallback(MessageParcel &data, MessageParcel &reply)
1838 {
1839     sptr<IRemoteObject> remote = data.ReadRemoteObject();
1840     if (remote == nullptr) {
1841         NETMGR_LOG_E("Remote ptr is nullptr.");
1842         if (!reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL)) {
1843             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1844         }
1845         return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
1846     }
1847 
1848     sptr<IPreAirplaneCallback> callback = iface_cast<IPreAirplaneCallback>(remote);
1849     if (callback == nullptr) {
1850         NETMGR_LOG_E("Callback ptr is nullptr.");
1851         if (!reply.WriteInt32(NETMANAGER_ERR_LOCAL_PTR_NULL)) {
1852             return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1853         }
1854         return NETMANAGER_ERR_LOCAL_PTR_NULL;
1855     }
1856 
1857     int32_t result = UnregisterPreAirplaneCallback(callback);
1858     if (!reply.WriteInt32(result)) {
1859         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1860     }
1861 
1862     return NETMANAGER_SUCCESS;
1863 }
1864 
OnCloseSocketsUid(MessageParcel & data,MessageParcel & reply)1865 int32_t NetConnServiceStub::OnCloseSocketsUid(MessageParcel &data, MessageParcel &reply)
1866 {
1867     int32_t netId;
1868     NETMGR_LOG_I("OnCloseSocketsUid");
1869     if (!data.ReadInt32(netId)) {
1870         NETMGR_LOG_E("ReadInt32 error.");
1871         return NETMANAGER_ERR_READ_DATA_FAIL;
1872     }
1873     uint32_t uid;
1874     if (!data.ReadUint32(uid)) {
1875         NETMGR_LOG_E("ReadUint32 error.");
1876         return NETMANAGER_ERR_READ_DATA_FAIL;
1877     }
1878 
1879     int32_t ret = CloseSocketsUid(netId, uid);
1880     if (!reply.WriteInt32(ret)) {
1881         NETMGR_LOG_E("reply.WriteInt32 error");
1882         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1883     }
1884     return NETMANAGER_SUCCESS;
1885 }
1886 
OnSetAppIsFrozened(MessageParcel & data,MessageParcel & reply)1887 int32_t NetConnServiceStub::OnSetAppIsFrozened(MessageParcel &data, MessageParcel &reply)
1888 {
1889     uint32_t uid = 0;
1890     if (!data.ReadUint32(uid)) {
1891         NETMGR_LOG_E("ReadUint32 error.");
1892         return NETMANAGER_ERR_READ_DATA_FAIL;
1893     }
1894     bool isFrozened = false;
1895     if (!data.ReadBool(isFrozened)) {
1896         NETMGR_LOG_E("ReadBool error.");
1897         return NETMANAGER_ERR_READ_DATA_FAIL;
1898     }
1899 
1900     int32_t ret = SetAppIsFrozened(uid, isFrozened);
1901     if (!reply.WriteInt32(ret)) {
1902         NETMGR_LOG_E("reply.WriteInt32 error");
1903         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1904     }
1905     return NETMANAGER_SUCCESS;
1906 }
1907 
OnEnableAppFrozenedCallbackLimitation(MessageParcel & data,MessageParcel & reply)1908 int32_t NetConnServiceStub::OnEnableAppFrozenedCallbackLimitation(MessageParcel &data, MessageParcel &reply)
1909 {
1910     bool flag = false;
1911     if (!data.ReadBool(flag)) {
1912         NETMGR_LOG_E("ReadBool error.");
1913         return NETMANAGER_ERR_READ_DATA_FAIL;
1914     }
1915 
1916     int32_t ret = EnableAppFrozenedCallbackLimitation(flag);
1917     if (!reply.WriteInt32(ret)) {
1918         NETMGR_LOG_E("reply.WriteInt32 error");
1919         return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1920     }
1921     return NETMANAGER_SUCCESS;
1922 }
1923 } // namespace NetManagerStandard
1924 } // namespace OHOS
1925