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
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 uint32_t MAX_IFACE_NUM = 16;
28 constexpr uint32_t MAX_NET_CAP_NUM = 32;
29 constexpr uint32_t UID_FOUNDATION = 5523;
30 const std::vector<uint32_t> SYSTEM_CODE{static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE),
31 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY),
32 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY)};
33 const std::vector<uint32_t> PERMISSION_NEED_CACHE_CODES{
34 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK),
35 static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET)};
36 } // namespace
NetConnServiceStub()37 NetConnServiceStub::NetConnServiceStub()
38 {
39 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SYSTEM_READY)] = {&NetConnServiceStub::OnSystemReady,
40 {}};
41 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK)] = {
42 &NetConnServiceStub::OnRegisterNetConnCallback, {Permission::GET_NETWORK_INFO}};
43 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_CONN_CALLBACK_BY_SPECIFIER)] = {
44 &NetConnServiceStub::OnRegisterNetConnCallbackBySpecifier, {Permission::GET_NETWORK_INFO}};
45 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_CONN_CALLBACK)] = {
46 &NetConnServiceStub::OnUnregisterNetConnCallback, {Permission::GET_NETWORK_INFO}};
47 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UPDATE_NET_STATE_FOR_TEST)] = {
48 &NetConnServiceStub::OnUpdateNetStateForTest, {}};
49 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REG_NET_SUPPLIER)] = {
50 &NetConnServiceStub::OnRegisterNetSupplier, {Permission::CONNECTIVITY_INTERNAL}};
51 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREG_NETWORK)] = {
52 &NetConnServiceStub::OnUnregisterNetSupplier, {Permission::CONNECTIVITY_INTERNAL}};
53 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_SUPPLIER_INFO)] = {
54 &NetConnServiceStub::OnUpdateNetSupplierInfo, {Permission::CONNECTIVITY_INTERNAL}};
55 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_NET_LINK_INFO)] = {
56 &NetConnServiceStub::OnUpdateNetLinkInfo, {Permission::CONNECTIVITY_INTERNAL}};
57 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_DETECTION_RET_CALLBACK)] = {
58 &NetConnServiceStub::OnRegisterNetDetectionCallback, {}};
59 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_UNREGISTER_NET_DETECTION_RET_CALLBACK)] = {
60 &NetConnServiceStub::OnUnRegisterNetDetectionCallback, {}};
61 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_NET_DETECTION)] = {
62 &NetConnServiceStub::OnNetDetection, {Permission::GET_NETWORK_INFO, Permission::INTERNET}};
63 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_BIND_SOCKET)] = {&NetConnServiceStub::OnBindSocket,
64 {}};
65 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_SUPPLIER_CALLBACK)] = {
66 &NetConnServiceStub::OnRegisterNetSupplierCallback, {Permission::CONNECTIVITY_INTERNAL}};
67 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_AIRPLANE_MODE)] = {
68 &NetConnServiceStub::OnSetAirplaneMode, {Permission::CONNECTIVITY_INTERNAL}};
69 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_GLOBAL_HTTP_PROXY)] = {
70 &NetConnServiceStub::OnSetGlobalHttpProxy, {Permission::CONNECTIVITY_INTERNAL}};
71 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_APP_NET)] = {&NetConnServiceStub::OnSetAppNet,
72 {Permission::INTERNET}};
73 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION)] = {
74 &NetConnServiceStub::OnSetInternetPermission, {Permission::CONNECTIVITY_INTERNAL}};
75 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_REGISTER_NET_INTERFACE_CALLBACK)] = {
76 &NetConnServiceStub::OnRegisterNetInterfaceCallback, {Permission::CONNECTIVITY_INTERNAL}};
77 InitQueryFuncToInterfaceMap();
78 }
79
InitQueryFuncToInterfaceMap()80 void NetConnServiceStub::InitQueryFuncToInterfaceMap()
81 {
82 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACE_NAMES)] = {
83 &NetConnServiceStub::OnGetIfaceNames, {}};
84 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_IFACENAME_BY_TYPE)] = {
85 &NetConnServiceStub::OnGetIfaceNameByType, {}};
86 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GETDEFAULTNETWORK)] = {
87 &NetConnServiceStub::OnGetDefaultNet, {Permission::GET_NETWORK_INFO}};
88 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_HASDEFAULTNET)] = {
89 &NetConnServiceStub::OnHasDefaultNet, {Permission::GET_NETWORK_INFO}};
90 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_NET)] = {
91 &NetConnServiceStub::OnGetSpecificNet, {}};
92 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ALL_NETS)] = {&NetConnServiceStub::OnGetAllNets,
93 {Permission::GET_NETWORK_INFO}};
94 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_SPECIFIC_UID_NET)] = {
95 &NetConnServiceStub::OnGetSpecificUidNet, {}};
96 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_CONNECTION_PROPERTIES)] = {
97 &NetConnServiceStub::OnGetConnectionProperties, {Permission::GET_NETWORK_INFO}};
98 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_CAPABILITIES)] = {
99 &NetConnServiceStub::OnGetNetCapabilities, {Permission::GET_NETWORK_INFO}};
100 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESSES_BY_NAME)] = {
101 &NetConnServiceStub::OnGetAddressesByName, {Permission::INTERNET}};
102 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_ADDRESS_BY_NAME)] = {
103 &NetConnServiceStub::OnGetAddressByName, {Permission::INTERNET}};
104 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_IS_DEFAULT_NET_METERED)] = {
105 &NetConnServiceStub::OnIsDefaultNetMetered, {Permission::GET_NETWORK_INFO}};
106 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_GLOBAL_HTTP_PROXY)] = {
107 &NetConnServiceStub::OnGetGlobalHttpProxy, {}};
108 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_DEFAULT_HTTP_PROXY)] = {
109 &NetConnServiceStub::OnGetDefaultHttpProxy, {}};
110 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_NET_ID_BY_IDENTIFIER)] = {
111 &NetConnServiceStub::OnGetNetIdByIdentifier, {}};
112 memberFuncMap_[static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_GET_INTERFACE_CONFIGURATION)] = {
113 &NetConnServiceStub::OnGetNetInterfaceConfiguration, {Permission::CONNECTIVITY_INTERNAL}};
114 }
115
~NetConnServiceStub()116 NetConnServiceStub::~NetConnServiceStub() {}
117
ToUtf8(std::u16string str16)118 std::string ToUtf8(std::u16string str16)
119 {
120 return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(str16);
121 }
122
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)123 int32_t NetConnServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
124 MessageOption &option)
125 {
126 NETMGR_LOG_D("stub call start, code = [%{public}d]", code);
127
128 std::u16string myDescripter = NetConnServiceStub::GetDescriptor();
129 std::u16string remoteDescripter = data.ReadInterfaceToken();
130 NETMGR_LOG_D("myDescripter[%{public}s], remoteDescripter[%{public}s]", ToUtf8(myDescripter).c_str(),
131 ToUtf8(remoteDescripter).c_str());
132 if (myDescripter != remoteDescripter) {
133 NETMGR_LOG_E("descriptor checked fail");
134 if (!reply.WriteInt32(NETMANAGER_ERR_DESCRIPTOR_MISMATCH)) {
135 return IPC_STUB_WRITE_PARCEL_ERR;
136 }
137 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
138 }
139
140 auto itFunc = memberFuncMap_.find(code);
141 if (itFunc == memberFuncMap_.end()) {
142 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
143 }
144 auto requestFunc = itFunc->second.first;
145 if (requestFunc == nullptr) {
146 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
147 }
148 if (code == static_cast<uint32_t>(ConnInterfaceCode::CMD_NM_SET_INTERNET_PERMISSION)) {
149 // get uid should be called in this function
150 auto uid = IPCSkeleton::GetCallingUid();
151 if (uid != UID_FOUNDATION) {
152 if (!reply.WriteInt32(NETMANAGER_ERR_PERMISSION_DENIED)) {
153 return IPC_STUB_WRITE_PARCEL_ERR;
154 }
155 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
156 }
157 }
158
159 int32_t ret = OnRequestCheck(code, itFunc->second.second);
160 if (ret == NETMANAGER_SUCCESS) {
161 return (this->*requestFunc)(data, reply);
162 }
163 if (!reply.WriteInt32(ret)) {
164 return IPC_STUB_WRITE_PARCEL_ERR;
165 }
166 NETMGR_LOG_D("stub default case, need check");
167 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
168 }
169
OnRequestCheck(uint32_t code,const std::set<std::string> & permissions)170 int32_t NetConnServiceStub::OnRequestCheck(uint32_t code, const std::set<std::string> &permissions)
171 {
172 if (std::find(SYSTEM_CODE.begin(), SYSTEM_CODE.end(), code) != SYSTEM_CODE.end()) {
173 if (!NetManagerPermission::IsSystemCaller()) {
174 NETMGR_LOG_E("Non-system applications use system APIs.");
175 return NETMANAGER_ERR_NOT_SYSTEM_CALL;
176 }
177 }
178
179 if (std::find(PERMISSION_NEED_CACHE_CODES.begin(), PERMISSION_NEED_CACHE_CODES.end(), code) !=
180 PERMISSION_NEED_CACHE_CODES.end()) {
181 if (CheckPermissionWithCache(permissions)) {
182 return NETMANAGER_SUCCESS;
183 }
184 } else {
185 if (CheckPermission(permissions)) {
186 return NETMANAGER_SUCCESS;
187 }
188 }
189 return NETMANAGER_ERR_PERMISSION_DENIED;
190 }
191
CheckPermission(const std::set<std::string> & permissions)192 bool NetConnServiceStub::CheckPermission(const std::set<std::string> &permissions)
193 {
194 for (const auto &permission : permissions) {
195 if (!NetManagerPermission::CheckPermission(permission)) {
196 return false;
197 }
198 }
199 return true;
200 }
201
CheckPermissionWithCache(const std::set<std::string> & permissions)202 bool NetConnServiceStub::CheckPermissionWithCache(const std::set<std::string> &permissions)
203 {
204 for (const auto &permission : permissions) {
205 if (!NetManagerPermission::CheckPermissionWithCache(permission)) {
206 return false;
207 }
208 }
209 return true;
210 }
211
OnSystemReady(MessageParcel & data,MessageParcel & reply)212 int32_t NetConnServiceStub::OnSystemReady(MessageParcel &data, MessageParcel &reply)
213 {
214 SystemReady();
215 return 0;
216 }
217
OnSetInternetPermission(MessageParcel & data,MessageParcel & reply)218 int32_t NetConnServiceStub::OnSetInternetPermission(MessageParcel &data, MessageParcel &reply)
219 {
220 uint32_t uid;
221 if (!data.ReadUint32(uid)) {
222 return NETMANAGER_ERR_READ_DATA_FAIL;
223 }
224
225 uint8_t allow;
226 if (!data.ReadUint8(allow)) {
227 return NETMANAGER_ERR_READ_DATA_FAIL;
228 }
229
230 int32_t ret = SetInternetPermission(uid, allow);
231 if (!reply.WriteInt32(ret)) {
232 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
233 }
234
235 return NETMANAGER_SUCCESS;
236 }
237
OnRegisterNetSupplier(MessageParcel & data,MessageParcel & reply)238 int32_t NetConnServiceStub::OnRegisterNetSupplier(MessageParcel &data, MessageParcel &reply)
239 {
240 NETMGR_LOG_D("stub processing");
241 NetBearType bearerType;
242 std::string ident;
243 std::set<NetCap> netCaps;
244
245 uint32_t type = 0;
246 if (!data.ReadUint32(type)) {
247 return NETMANAGER_ERR_READ_DATA_FAIL;
248 }
249 if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
250 return NETMANAGER_ERR_INTERNAL;
251 }
252 bearerType = static_cast<NetBearType>(type);
253
254 if (!data.ReadString(ident)) {
255 return NETMANAGER_ERR_READ_DATA_FAIL;
256 }
257 uint32_t size = 0;
258 uint32_t value = 0;
259 if (!data.ReadUint32(size)) {
260 return NETMANAGER_ERR_READ_DATA_FAIL;
261 }
262 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
263 for (uint32_t i = 0; i < size; ++i) {
264 if (!data.ReadUint32(value)) {
265 return NETMANAGER_ERR_READ_DATA_FAIL;
266 }
267 netCaps.insert(static_cast<NetCap>(value));
268 }
269
270 uint32_t supplierId = 0;
271 int32_t ret = RegisterNetSupplier(bearerType, ident, netCaps, supplierId);
272 if (!reply.WriteInt32(ret)) {
273 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
274 }
275 if (ret == NETMANAGER_SUCCESS) {
276 NETMGR_LOG_I("supplierId[%{public}d].", supplierId);
277 if (!reply.WriteUint32(supplierId)) {
278 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
279 }
280 }
281 return NETMANAGER_SUCCESS;
282 }
283
OnUnregisterNetSupplier(MessageParcel & data,MessageParcel & reply)284 int32_t NetConnServiceStub::OnUnregisterNetSupplier(MessageParcel &data, MessageParcel &reply)
285 {
286 uint32_t supplierId;
287 if (!data.ReadUint32(supplierId)) {
288 return NETMANAGER_ERR_READ_DATA_FAIL;
289 }
290
291 int32_t ret = UnregisterNetSupplier(supplierId);
292 if (!reply.WriteInt32(ret)) {
293 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
294 }
295
296 return NETMANAGER_SUCCESS;
297 }
298
OnRegisterNetSupplierCallback(MessageParcel & data,MessageParcel & reply)299 int32_t NetConnServiceStub::OnRegisterNetSupplierCallback(MessageParcel &data, MessageParcel &reply)
300 {
301 int32_t result = NETMANAGER_SUCCESS;
302 uint32_t supplierId;
303 data.ReadUint32(supplierId);
304 sptr<IRemoteObject> remote = data.ReadRemoteObject();
305 if (remote == nullptr) {
306 NETMGR_LOG_E("Callback ptr is nullptr.");
307 result = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
308 reply.WriteInt32(result);
309 return result;
310 }
311
312 sptr<INetSupplierCallback> callback = iface_cast<INetSupplierCallback>(remote);
313 if (callback == nullptr) {
314 result = NETMANAGER_ERR_LOCAL_PTR_NULL;
315 reply.WriteInt32(result);
316 return result;
317 }
318
319 result = RegisterNetSupplierCallback(supplierId, callback);
320 reply.WriteInt32(result);
321 return result;
322 }
323
OnRegisterNetConnCallback(MessageParcel & data,MessageParcel & reply)324 int32_t NetConnServiceStub::OnRegisterNetConnCallback(MessageParcel &data, MessageParcel &reply)
325 {
326 int32_t result = NETMANAGER_SUCCESS;
327 sptr<IRemoteObject> remote = data.ReadRemoteObject();
328 if (remote == nullptr) {
329 NETMGR_LOG_E("Callback ptr is nullptr.");
330 result = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
331 reply.WriteInt32(result);
332 return result;
333 }
334
335 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
336 if (callback == nullptr) {
337 result = NETMANAGER_ERR_LOCAL_PTR_NULL;
338 reply.WriteInt32(result);
339 return result;
340 }
341
342 result = RegisterNetConnCallback(callback);
343 reply.WriteInt32(result);
344 return result;
345 }
346
OnRegisterNetConnCallbackBySpecifier(MessageParcel & data,MessageParcel & reply)347 int32_t NetConnServiceStub::OnRegisterNetConnCallbackBySpecifier(MessageParcel &data, MessageParcel &reply)
348 {
349 sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
350 uint32_t timeoutMS = data.ReadUint32();
351 int32_t result = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
352 sptr<IRemoteObject> remote = data.ReadRemoteObject();
353 if (remote == nullptr) {
354 NETMGR_LOG_E("callback ptr is nullptr.");
355 reply.WriteInt32(result);
356 return result;
357 }
358
359 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
360 if (callback == nullptr) {
361 result = NETMANAGER_ERR_LOCAL_PTR_NULL;
362 reply.WriteInt32(result);
363 return result;
364 }
365
366 result = RegisterNetConnCallback(netSpecifier, callback, timeoutMS);
367 reply.WriteInt32(result);
368 return result;
369 }
370
OnUnregisterNetConnCallback(MessageParcel & data,MessageParcel & reply)371 int32_t NetConnServiceStub::OnUnregisterNetConnCallback(MessageParcel &data, MessageParcel &reply)
372 {
373 int32_t result = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
374 sptr<IRemoteObject> remote = data.ReadRemoteObject();
375 if (remote == nullptr) {
376 NETMGR_LOG_E("callback ptr is nullptr.");
377 reply.WriteInt32(result);
378 return result;
379 }
380
381 sptr<INetConnCallback> callback = iface_cast<INetConnCallback>(remote);
382 if (callback == nullptr) {
383 result = NETMANAGER_ERR_LOCAL_PTR_NULL;
384 reply.WriteInt32(result);
385 return result;
386 }
387
388 result = UnregisterNetConnCallback(callback);
389 reply.WriteInt32(result);
390 return result;
391 }
392
OnUpdateNetStateForTest(MessageParcel & data,MessageParcel & reply)393 int32_t NetConnServiceStub::OnUpdateNetStateForTest(MessageParcel &data, MessageParcel &reply)
394 {
395 NETMGR_LOG_I("Test NetConnServiceStub::OnUpdateNetStateForTest(), begin");
396 sptr<NetSpecifier> netSpecifier = NetSpecifier::Unmarshalling(data);
397
398 int32_t netState;
399 if (!data.ReadInt32(netState)) {
400 return NETMANAGER_ERR_READ_DATA_FAIL;
401 }
402
403 NETMGR_LOG_I("Test NetConnServiceStub::OnUpdateNetStateForTest(), netState[%{public}d]", netState);
404 int32_t result = UpdateNetStateForTest(netSpecifier, netState);
405 NETMGR_LOG_I("Test NetConnServiceStub::OnUpdateNetStateForTest(), result[%{public}d]", result);
406 reply.WriteInt32(result);
407 return result;
408 }
409
OnUpdateNetSupplierInfo(MessageParcel & data,MessageParcel & reply)410 int32_t NetConnServiceStub::OnUpdateNetSupplierInfo(MessageParcel &data, MessageParcel &reply)
411 {
412 NETMGR_LOG_D("OnUpdateNetSupplierInfo in.");
413 uint32_t supplierId;
414 if (!data.ReadUint32(supplierId)) {
415 NETMGR_LOG_D("fail to get supplier id.");
416 return NETMANAGER_ERR_READ_DATA_FAIL;
417 }
418
419 NETMGR_LOG_D("OnUpdateNetSupplierInfo supplierId=[%{public}d].", supplierId);
420 sptr<NetSupplierInfo> netSupplierInfo = NetSupplierInfo::Unmarshalling(data);
421 int32_t ret = UpdateNetSupplierInfo(supplierId, netSupplierInfo);
422 if (!reply.WriteInt32(ret)) {
423 NETMGR_LOG_D("fail to update net supplier info.");
424 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
425 }
426 NETMGR_LOG_D("OnUpdateNetSupplierInfo out.");
427
428 return NETMANAGER_SUCCESS;
429 }
430
OnUpdateNetLinkInfo(MessageParcel & data,MessageParcel & reply)431 int32_t NetConnServiceStub::OnUpdateNetLinkInfo(MessageParcel &data, MessageParcel &reply)
432 {
433 uint32_t supplierId;
434
435 if (!data.ReadUint32(supplierId)) {
436 return NETMANAGER_ERR_READ_DATA_FAIL;
437 }
438
439 sptr<NetLinkInfo> netLinkInfo = NetLinkInfo::Unmarshalling(data);
440
441 int32_t ret = UpdateNetLinkInfo(supplierId, netLinkInfo);
442 if (!reply.WriteInt32(ret)) {
443 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
444 }
445
446 return NETMANAGER_SUCCESS;
447 }
448
OnRegisterNetDetectionCallback(MessageParcel & data,MessageParcel & reply)449 int32_t NetConnServiceStub::OnRegisterNetDetectionCallback(MessageParcel &data, MessageParcel &reply)
450 {
451 if (!data.ContainFileDescriptors()) {
452 NETMGR_LOG_E("Execute ContainFileDescriptors failed");
453 }
454 int32_t netId = 0;
455 if (!data.ReadInt32(netId)) {
456 return NETMANAGER_ERR_READ_DATA_FAIL;
457 }
458
459 int32_t result = NETMANAGER_SUCCESS;
460 sptr<IRemoteObject> remote = data.ReadRemoteObject();
461 if (remote == nullptr) {
462 NETMGR_LOG_E("Callback ptr is nullptr.");
463 result = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
464 reply.WriteInt32(result);
465 return result;
466 }
467
468 sptr<INetDetectionCallback> callback = iface_cast<INetDetectionCallback>(remote);
469 if (callback == nullptr) {
470 result = NETMANAGER_ERR_LOCAL_PTR_NULL;
471 reply.WriteInt32(result);
472 return result;
473 }
474
475 result = RegisterNetDetectionCallback(netId, callback);
476 reply.WriteInt32(result);
477 return result;
478 }
479
OnUnRegisterNetDetectionCallback(MessageParcel & data,MessageParcel & reply)480 int32_t NetConnServiceStub::OnUnRegisterNetDetectionCallback(MessageParcel &data, MessageParcel &reply)
481 {
482 if (!data.ContainFileDescriptors()) {
483 NETMGR_LOG_E("Execute ContainFileDescriptors failed");
484 }
485 int32_t netId = 0;
486 if (!data.ReadInt32(netId)) {
487 return NETMANAGER_ERR_READ_DATA_FAIL;
488 }
489
490 int32_t result = NETMANAGER_SUCCESS;
491 sptr<IRemoteObject> remote = data.ReadRemoteObject();
492 if (remote == nullptr) {
493 NETMGR_LOG_E("Callback ptr is nullptr.");
494 result = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
495 reply.WriteInt32(result);
496 return result;
497 }
498
499 sptr<INetDetectionCallback> callback = iface_cast<INetDetectionCallback>(remote);
500 if (callback == nullptr) {
501 result = NETMANAGER_ERR_LOCAL_PTR_NULL;
502 reply.WriteInt32(result);
503 return result;
504 }
505
506 result = UnRegisterNetDetectionCallback(netId, callback);
507 reply.WriteInt32(result);
508 return result;
509 }
510
OnNetDetection(MessageParcel & data,MessageParcel & reply)511 int32_t NetConnServiceStub::OnNetDetection(MessageParcel &data, MessageParcel &reply)
512 {
513 int32_t netId = 0;
514 if (!data.ReadInt32(netId)) {
515 return NETMANAGER_ERR_READ_DATA_FAIL;
516 }
517 int32_t ret = NetDetection(netId);
518 if (!reply.WriteInt32(ret)) {
519 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
520 }
521 return NETMANAGER_SUCCESS;
522 }
523
OnGetIfaceNames(MessageParcel & data,MessageParcel & reply)524 int32_t NetConnServiceStub::OnGetIfaceNames(MessageParcel &data, MessageParcel &reply)
525 {
526 uint32_t netType = 0;
527 if (!data.ReadUint32(netType)) {
528 return NETMANAGER_ERR_READ_DATA_FAIL;
529 }
530 NetBearType bearerType = static_cast<NetBearType>(netType);
531 std::list<std::string> ifaceNames;
532 int32_t ret = GetIfaceNames(bearerType, ifaceNames);
533 if (!reply.WriteInt32(ret)) {
534 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
535 }
536 if (ret == NETMANAGER_SUCCESS) {
537 if (!reply.WriteUint32(ifaceNames.size())) {
538 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
539 }
540
541 for (const auto &ifaceName : ifaceNames) {
542 if (!reply.WriteString(ifaceName)) {
543 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
544 }
545 }
546 }
547 return ret;
548 }
549
OnGetIfaceNameByType(MessageParcel & data,MessageParcel & reply)550 int32_t NetConnServiceStub::OnGetIfaceNameByType(MessageParcel &data, MessageParcel &reply)
551 {
552 uint32_t netType = 0;
553 if (!data.ReadUint32(netType)) {
554 return NETMANAGER_ERR_READ_DATA_FAIL;
555 }
556 NetBearType bearerType = static_cast<NetBearType>(netType);
557
558 std::string ident;
559 if (!data.ReadString(ident)) {
560 return NETMANAGER_ERR_READ_DATA_FAIL;
561 }
562
563 std::string ifaceName;
564 int32_t ret = GetIfaceNameByType(bearerType, ident, ifaceName);
565 if (!reply.WriteInt32(ret)) {
566 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
567 }
568 if (ret == NETMANAGER_SUCCESS) {
569 if (!reply.WriteString(ifaceName)) {
570 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
571 }
572 }
573 return ret;
574 }
575
OnGetDefaultNet(MessageParcel & data,MessageParcel & reply)576 int32_t NetConnServiceStub::OnGetDefaultNet(MessageParcel &data, MessageParcel &reply)
577 {
578 NETMGR_LOG_D("OnGetDefaultNet Begin...");
579 int32_t netId;
580 int32_t result = GetDefaultNet(netId);
581 NETMGR_LOG_D("GetDefaultNet result is: [%{public}d]", result);
582 if (!reply.WriteInt32(result)) {
583 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
584 }
585 if (result == NETMANAGER_SUCCESS) {
586 if (!reply.WriteUint32(netId)) {
587 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
588 }
589 }
590 return NETMANAGER_SUCCESS;
591 }
592
OnHasDefaultNet(MessageParcel & data,MessageParcel & reply)593 int32_t NetConnServiceStub::OnHasDefaultNet(MessageParcel &data, MessageParcel &reply)
594 {
595 NETMGR_LOG_D("OnHasDefaultNet Begin...");
596 bool flag = false;
597 int32_t result = HasDefaultNet(flag);
598 NETMGR_LOG_D("HasDefaultNet result is: [%{public}d]", result);
599 if (!reply.WriteInt32(result)) {
600 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
601 }
602 if (result == NETMANAGER_SUCCESS) {
603 if (!reply.WriteBool(flag)) {
604 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
605 }
606 }
607 return NETMANAGER_SUCCESS;
608 }
609
OnGetSpecificNet(MessageParcel & data,MessageParcel & reply)610 int32_t NetConnServiceStub::OnGetSpecificNet(MessageParcel &data, MessageParcel &reply)
611 {
612 uint32_t type;
613 if (!data.ReadUint32(type)) {
614 return NETMANAGER_ERR_READ_DATA_FAIL;
615 }
616
617 if (type > static_cast<uint32_t>(NetBearType::BEARER_DEFAULT)) {
618 return NETMANAGER_ERR_INTERNAL;
619 }
620
621 NetBearType bearerType = static_cast<NetBearType>(type);
622
623 NETMGR_LOG_D("stub execute GetSpecificNet");
624 std::list<int32_t> netIdList;
625 int32_t ret = GetSpecificNet(bearerType, netIdList);
626 if (!reply.WriteInt32(ret)) {
627 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
628 }
629 if (ret == NETMANAGER_SUCCESS) {
630 uint32_t size = static_cast<uint32_t>(netIdList.size());
631 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
632 if (!reply.WriteUint32(size)) {
633 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
634 }
635
636 uint32_t index = 0;
637 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
638 if (++index > MAX_IFACE_NUM) {
639 break;
640 }
641 if (!reply.WriteInt32(*p)) {
642 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
643 }
644 }
645 }
646 return ret;
647 }
648
OnGetAllNets(MessageParcel & data,MessageParcel & reply)649 int32_t NetConnServiceStub::OnGetAllNets(MessageParcel &data, MessageParcel &reply)
650 {
651 NETMGR_LOG_D("stub execute GetAllNets");
652 std::list<int32_t> netIdList;
653 int32_t ret = GetAllNets(netIdList);
654 if (!reply.WriteInt32(ret)) {
655 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
656 }
657 if (ret == NETMANAGER_SUCCESS) {
658 uint32_t size = static_cast<uint32_t>(netIdList.size());
659 if (!reply.WriteUint32(size)) {
660 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
661 }
662
663 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
664 if (!reply.WriteInt32(*p)) {
665 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
666 }
667 }
668 }
669 return ret;
670 }
671
OnGetSpecificUidNet(MessageParcel & data,MessageParcel & reply)672 int32_t NetConnServiceStub::OnGetSpecificUidNet(MessageParcel &data, MessageParcel &reply)
673 {
674 int32_t uid = 0;
675 if (!data.ReadInt32(uid)) {
676 return NETMANAGER_ERR_READ_DATA_FAIL;
677 }
678 NETMGR_LOG_D("stub execute GetSpecificUidNet");
679
680 int32_t netId = 0;
681 int32_t ret = GetSpecificUidNet(uid, netId);
682 if (!reply.WriteInt32(ret)) {
683 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
684 }
685 if (ret == NETMANAGER_SUCCESS) {
686 if (!reply.WriteInt32(netId)) {
687 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
688 }
689 }
690 return ret;
691 }
692
OnGetConnectionProperties(MessageParcel & data,MessageParcel & reply)693 int32_t NetConnServiceStub::OnGetConnectionProperties(MessageParcel &data, MessageParcel &reply)
694 {
695 int32_t netId = 0;
696 if (!data.ReadInt32(netId)) {
697 return NETMANAGER_ERR_READ_DATA_FAIL;
698 }
699
700 NETMGR_LOG_D("stub execute GetConnectionProperties");
701 NetLinkInfo info;
702 int32_t ret = GetConnectionProperties(netId, info);
703 if (!reply.WriteInt32(ret)) {
704 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
705 }
706 if (ret == NETMANAGER_SUCCESS) {
707 sptr<NetLinkInfo> netLinkInfo_ptr = new (std::nothrow) NetLinkInfo(info);
708 if (!NetLinkInfo::Marshalling(reply, netLinkInfo_ptr)) {
709 NETMGR_LOG_E("proxy Marshalling failed");
710 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
711 }
712 }
713 return ret;
714 }
715
OnGetNetCapabilities(MessageParcel & data,MessageParcel & reply)716 int32_t NetConnServiceStub::OnGetNetCapabilities(MessageParcel &data, MessageParcel &reply)
717 {
718 int32_t netId = 0;
719 if (!data.ReadInt32(netId)) {
720 return NETMANAGER_ERR_READ_DATA_FAIL;
721 }
722
723 NETMGR_LOG_D("stub execute GetNetCapabilities");
724
725 NetAllCapabilities netAllCap;
726 int32_t ret = GetNetCapabilities(netId, netAllCap);
727 if (!reply.WriteInt32(ret)) {
728 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
729 }
730 if (ret == NETMANAGER_SUCCESS) {
731 if (!reply.WriteUint32(netAllCap.linkUpBandwidthKbps_) ||
732 !reply.WriteUint32(netAllCap.linkDownBandwidthKbps_)) {
733 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
734 }
735 uint32_t size = netAllCap.netCaps_.size();
736 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
737 if (!reply.WriteUint32(size)) {
738 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
739 }
740 uint32_t index = 0;
741 for (auto netCap : netAllCap.netCaps_) {
742 if (++index > MAX_NET_CAP_NUM) {
743 break;
744 }
745 if (!reply.WriteUint32(static_cast<uint32_t>(netCap))) {
746 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
747 }
748 }
749
750 size = netAllCap.bearerTypes_.size();
751 size = size > MAX_NET_CAP_NUM ? MAX_NET_CAP_NUM : size;
752 if (!reply.WriteUint32(size)) {
753 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
754 }
755 index = 0;
756 for (auto bearerType : netAllCap.bearerTypes_) {
757 if (++index > MAX_NET_CAP_NUM) {
758 break;
759 }
760 if (!reply.WriteUint32(static_cast<uint32_t>(bearerType))) {
761 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
762 }
763 }
764 }
765 return ret;
766 }
767
OnGetAddressesByName(MessageParcel & data,MessageParcel & reply)768 int32_t NetConnServiceStub::OnGetAddressesByName(MessageParcel &data, MessageParcel &reply)
769 {
770 std::string host;
771 if (!data.ReadString(host)) {
772 return NETMANAGER_ERR_READ_DATA_FAIL;
773 }
774 int32_t netId;
775 if (!data.ReadInt32(netId)) {
776 return NETMANAGER_ERR_READ_DATA_FAIL;
777 }
778 NETMGR_LOG_D("stub execute GetAddressesByName");
779 std::vector<INetAddr> addrList;
780 int32_t ret = GetAddressesByName(host, netId, addrList);
781 if (!reply.WriteInt32(ret)) {
782 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
783 }
784 if (ret == NETMANAGER_SUCCESS) {
785 uint32_t size = static_cast<uint32_t>(addrList.size());
786 size = size > MAX_IFACE_NUM ? MAX_IFACE_NUM : size;
787 if (!reply.WriteUint32(size)) {
788 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
789 }
790 uint32_t index = 0;
791 for (auto p = addrList.begin(); p != addrList.end(); ++p) {
792 if (++index > MAX_IFACE_NUM) {
793 break;
794 }
795 sptr<INetAddr> netaddr_ptr = (std::make_unique<INetAddr>(*p)).release();
796 if (!INetAddr::Marshalling(reply, netaddr_ptr)) {
797 NETMGR_LOG_E("proxy Marshalling failed");
798 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
799 }
800 }
801 }
802 return ret;
803 }
804
OnGetAddressByName(MessageParcel & data,MessageParcel & reply)805 int32_t NetConnServiceStub::OnGetAddressByName(MessageParcel &data, MessageParcel &reply)
806 {
807 std::string host;
808 if (!data.ReadString(host)) {
809 return NETMANAGER_ERR_READ_DATA_FAIL;
810 }
811 int32_t netId;
812 if (!data.ReadInt32(netId)) {
813 return NETMANAGER_ERR_READ_DATA_FAIL;
814 }
815 NETMGR_LOG_D("stub execute GetAddressByName");
816 INetAddr addr;
817 int32_t ret = GetAddressByName(host, netId, addr);
818 if (!reply.WriteInt32(ret)) {
819 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
820 }
821 if (ret == NETMANAGER_SUCCESS) {
822 sptr<INetAddr> netaddr_ptr = (std::make_unique<INetAddr>(addr)).release();
823 if (!INetAddr::Marshalling(reply, netaddr_ptr)) {
824 NETMGR_LOG_E("proxy Marshalling failed");
825 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
826 }
827 }
828 return ret;
829 }
830
OnBindSocket(MessageParcel & data,MessageParcel & reply)831 int32_t NetConnServiceStub::OnBindSocket(MessageParcel &data, MessageParcel &reply)
832 {
833 int32_t socket_fd;
834 if (!data.ReadInt32(socket_fd)) {
835 return NETMANAGER_ERR_READ_DATA_FAIL;
836 }
837 int32_t netId;
838 if (!data.ReadInt32(netId)) {
839 return NETMANAGER_ERR_READ_DATA_FAIL;
840 }
841 NETMGR_LOG_D("stub execute BindSocket");
842
843 int32_t ret = BindSocket(socket_fd, netId);
844 if (!reply.WriteInt32(ret)) {
845 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
846 }
847 return ret;
848 }
849
OnSetAirplaneMode(MessageParcel & data,MessageParcel & reply)850 int32_t NetConnServiceStub::OnSetAirplaneMode(MessageParcel &data, MessageParcel &reply)
851 {
852 bool state = false;
853 if (!data.ReadBool(state)) {
854 return NETMANAGER_ERR_READ_DATA_FAIL;
855 }
856 int32_t ret = SetAirplaneMode(state);
857 if (!reply.WriteInt32(ret)) {
858 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
859 }
860 return ret;
861 }
862
OnIsDefaultNetMetered(MessageParcel & data,MessageParcel & reply)863 int32_t NetConnServiceStub::OnIsDefaultNetMetered(MessageParcel &data, MessageParcel &reply)
864 {
865 NETMGR_LOG_D("stub execute IsDefaultNetMetered");
866 bool flag = false;
867 int32_t result = IsDefaultNetMetered(flag);
868 if (!reply.WriteInt32(result)) {
869 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
870 }
871 if (result == NETMANAGER_SUCCESS) {
872 if (!reply.WriteBool(flag)) {
873 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
874 }
875 }
876 return NETMANAGER_SUCCESS;
877 }
878
OnSetGlobalHttpProxy(MessageParcel & data,MessageParcel & reply)879 int32_t NetConnServiceStub::OnSetGlobalHttpProxy(MessageParcel &data, MessageParcel &reply)
880 {
881 NETMGR_LOG_D("stub execute SetGlobalHttpProxy");
882
883 HttpProxy httpProxy;
884 if (!HttpProxy::Unmarshalling(data, httpProxy)) {
885 return ERR_FLATTEN_OBJECT;
886 }
887
888 int32_t ret = SetGlobalHttpProxy(httpProxy);
889 if (!reply.WriteInt32(ret)) {
890 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
891 }
892 return ret;
893 }
894
OnGetGlobalHttpProxy(MessageParcel & data,MessageParcel & reply)895 int32_t NetConnServiceStub::OnGetGlobalHttpProxy(MessageParcel &data, MessageParcel &reply)
896 {
897 HttpProxy httpProxy;
898 int32_t result = GetGlobalHttpProxy(httpProxy);
899 if (!reply.WriteInt32(result)) {
900 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
901 }
902
903 if (result != NETMANAGER_SUCCESS) {
904 return result;
905 }
906
907 if (!httpProxy.Marshalling(reply)) {
908 return ERR_FLATTEN_OBJECT;
909 }
910 return NETMANAGER_SUCCESS;
911 }
912
OnGetDefaultHttpProxy(MessageParcel & data,MessageParcel & reply)913 int32_t NetConnServiceStub::OnGetDefaultHttpProxy(MessageParcel &data, MessageParcel &reply)
914 {
915 NETMGR_LOG_I("stub execute OnGetDefaultHttpProxy");
916 int32_t bindNetId = 0;
917 if (!data.ReadInt32(bindNetId)) {
918 return NETMANAGER_ERR_READ_DATA_FAIL;
919 }
920 HttpProxy httpProxy;
921 int32_t result = GetDefaultHttpProxy(bindNetId, httpProxy);
922 if (!reply.WriteInt32(result)) {
923 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
924 }
925
926 if (result != NETMANAGER_SUCCESS) {
927 return result;
928 }
929
930 if (!httpProxy.Marshalling(reply)) {
931 return ERR_FLATTEN_OBJECT;
932 }
933 return NETMANAGER_SUCCESS;
934 }
935
OnGetNetIdByIdentifier(MessageParcel & data,MessageParcel & reply)936 int32_t NetConnServiceStub::OnGetNetIdByIdentifier(MessageParcel &data, MessageParcel &reply)
937 {
938 NETMGR_LOG_D("stub execute OnGetNetIdByIdentifier");
939 std::string ident;
940 if (!data.ReadString(ident)) {
941 return NETMANAGER_ERR_READ_DATA_FAIL;
942 }
943
944 std::list<int32_t> netIdList;
945 int32_t ret = GetNetIdByIdentifier(ident, netIdList);
946 if (!reply.WriteInt32(ret)) {
947 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
948 }
949
950 if (ret == NETMANAGER_SUCCESS) {
951 uint32_t size = static_cast<uint32_t>(netIdList.size());
952 if (!reply.WriteUint32(size)) {
953 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
954 }
955 for (auto p = netIdList.begin(); p != netIdList.end(); ++p) {
956 if (!reply.WriteInt32(*p)) {
957 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
958 }
959 }
960 }
961 return ret;
962 }
963
OnSetAppNet(MessageParcel & data,MessageParcel & reply)964 int32_t NetConnServiceStub::OnSetAppNet(MessageParcel &data, MessageParcel &reply)
965 {
966 int32_t netId = 0;
967 if (!data.ReadInt32(netId)) {
968 return NETMANAGER_ERR_READ_DATA_FAIL;
969 }
970 int ret = SetAppNet(netId);
971 if (!reply.WriteInt32(ret)) {
972 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
973 }
974 return ret;
975 }
976
OnRegisterNetInterfaceCallback(MessageParcel & data,MessageParcel & reply)977 int32_t NetConnServiceStub::OnRegisterNetInterfaceCallback(MessageParcel &data, MessageParcel &reply)
978 {
979 int32_t ret = NETMANAGER_SUCCESS;
980 sptr<IRemoteObject> remote = data.ReadRemoteObject();
981 if (remote == nullptr) {
982 NETMGR_LOG_E("Callback ptr is nullptr.");
983 ret = NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
984 reply.WriteInt32(ret);
985 return ret;
986 }
987
988 sptr<INetInterfaceStateCallback> callback = iface_cast<INetInterfaceStateCallback>(remote);
989 ret = RegisterNetInterfaceCallback(callback);
990 if (!reply.WriteInt32(ret)) {
991 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
992 }
993 return ret;
994 }
995
OnGetNetInterfaceConfiguration(MessageParcel & data,MessageParcel & reply)996 int32_t NetConnServiceStub::OnGetNetInterfaceConfiguration(MessageParcel &data, MessageParcel &reply)
997 {
998 std::string iface;
999 if (!data.ReadString(iface)) {
1000 return NETMANAGER_ERR_READ_DATA_FAIL;
1001 }
1002
1003 NetInterfaceConfiguration config;
1004 int32_t ret = GetNetInterfaceConfiguration(iface, config);
1005 if (!reply.WriteInt32(ret)) {
1006 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
1007 }
1008
1009 if (ret == NETMANAGER_SUCCESS) {
1010 if (!config.Marshalling(reply)) {
1011 return ERR_FLATTEN_OBJECT;
1012 }
1013 }
1014 return ret;
1015 }
1016 } // namespace NetManagerStandard
1017 } // namespace OHOS
1018