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_policy_service_stub.h"
17
18 #include "net_mgr_log_wrapper.h"
19 #include "net_policy_core.h"
20 #include "net_quota_policy.h"
21 #include "netmanager_base_permission.h"
22 #include "ipc_skeleton.h"
23 #include "broadcast_manager.h"
24 #include "cJSON.h"
25
26 namespace OHOS {
27 namespace NetManagerStandard {
28 namespace {
29 std::map<uint32_t, const char *> g_codeNPS = {
30 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_POLICY_BY_UID), Permission::MANAGE_NET_STRATEGY},
31 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_POLICY_BY_UID), Permission::MANAGE_NET_STRATEGY},
32 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_UIDS_BY_POLICY), Permission::MANAGE_NET_STRATEGY},
33 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_IS_NET_ALLOWED_BY_METERED), Permission::MANAGE_NET_STRATEGY},
34 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_IS_NET_ALLOWED_BY_IFACE), Permission::MANAGE_NET_STRATEGY},
35 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_REGISTER_NET_POLICY_CALLBACK), Permission::MANAGE_NET_STRATEGY},
36 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_UNREGISTER_NET_POLICY_CALLBACK),
37 Permission::MANAGE_NET_STRATEGY},
38 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_NET_QUOTA_POLICIES), Permission::MANAGE_NET_STRATEGY},
39 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_NET_QUOTA_POLICIES), Permission::MANAGE_NET_STRATEGY},
40 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_UPDATE_REMIND_POLICY), Permission::MANAGE_NET_STRATEGY},
41 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_IDLE_TRUSTLIST), Permission::MANAGE_NET_STRATEGY},
42 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_IDLE_TRUSTLIST), Permission::MANAGE_NET_STRATEGY},
43 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_DEVICE_IDLE_POLICY), Permission::MANAGE_NET_STRATEGY},
44 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_RESET_POLICIES), Permission::MANAGE_NET_STRATEGY},
45 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_BACKGROUND_POLICY), Permission::MANAGE_NET_STRATEGY},
46 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_BACKGROUND_POLICY), Permission::MANAGE_NET_STRATEGY},
47 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_BACKGROUND_POLICY_BY_UID), Permission::MANAGE_NET_STRATEGY},
48 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_POWER_SAVE_TRUSTLIST), Permission::MANAGE_NET_STRATEGY},
49 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_POWER_SAVE_TRUSTLIST), Permission::MANAGE_NET_STRATEGY},
50 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_POWER_SAVE_POLICY), Permission::MANAGE_NET_STRATEGY},
51 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_CHECK_PERMISSION), Permission::MANAGE_NET_STRATEGY},
52 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_NETWORK_ACCESS_POLICY), Permission::MANAGE_NET_STRATEGY},
53 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_NETWORK_ACCESS_POLICY), Permission::MANAGE_NET_STRATEGY},
54 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_NOTIFY_NETWORK_ACCESS_POLICY_DIAG),
55 Permission::MANAGE_NET_STRATEGY},
56 {static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_NIC_TRAFFIC_ALLOWED), Permission::MANAGE_NET_STRATEGY},
57 };
58 constexpr uint32_t MAX_IFACENAMES_SIZE = 128;
59 constexpr int UID_EDM = 3057;
60 constexpr int UID_NET_MANAGER = 1099;
61 constexpr int UID_IOT_NET_MANAGER = 7211;
62 } // namespace
63
NetPolicyServiceStub()64 NetPolicyServiceStub::NetPolicyServiceStub() : ffrtQueue_(NET_POLICY_STUB_QUEUE)
65 {
66 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_POLICY_BY_UID)] =
67 &NetPolicyServiceStub::OnSetPolicyByUid;
68 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_POLICY_BY_UID)] =
69 &NetPolicyServiceStub::OnGetPolicyByUid;
70 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_UIDS_BY_POLICY)] =
71 &NetPolicyServiceStub::OnGetUidsByPolicy;
72 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_IS_NET_ALLOWED_BY_METERED)] =
73 &NetPolicyServiceStub::OnIsUidNetAllowedMetered;
74 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_IS_NET_ALLOWED_BY_IFACE)] =
75 &NetPolicyServiceStub::OnIsUidNetAllowedIfaceName;
76 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_REGISTER_NET_POLICY_CALLBACK)] =
77 &NetPolicyServiceStub::OnRegisterNetPolicyCallback;
78 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_UNREGISTER_NET_POLICY_CALLBACK)] =
79 &NetPolicyServiceStub::OnUnregisterNetPolicyCallback;
80 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_NET_QUOTA_POLICIES)] =
81 &NetPolicyServiceStub::OnSetNetQuotaPolicies;
82 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_NET_QUOTA_POLICIES)] =
83 &NetPolicyServiceStub::OnGetNetQuotaPolicies;
84 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_RESET_POLICIES)] =
85 &NetPolicyServiceStub::OnResetPolicies;
86 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_UPDATE_REMIND_POLICY)] =
87 &NetPolicyServiceStub::OnSnoozePolicy;
88 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_IDLE_TRUSTLIST)] =
89 &NetPolicyServiceStub::OnSetDeviceIdleTrustlist;
90 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_IDLE_TRUSTLIST)] =
91 &NetPolicyServiceStub::OnGetDeviceIdleTrustlist;
92 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_DEVICE_IDLE_POLICY)] =
93 &NetPolicyServiceStub::OnSetDeviceIdlePolicy;
94 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_POWER_SAVE_TRUSTLIST)] =
95 &NetPolicyServiceStub::OnGetPowerSaveTrustlist;
96 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_POWER_SAVE_TRUSTLIST)] =
97 &NetPolicyServiceStub::OnSetPowerSaveTrustlist;
98 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_BACKGROUND_POLICY)] =
99 &NetPolicyServiceStub::OnSetBackgroundPolicy;
100 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_BACKGROUND_POLICY)] =
101 &NetPolicyServiceStub::OnGetBackgroundPolicy;
102 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_BACKGROUND_POLICY_BY_UID)] =
103 &NetPolicyServiceStub::OnGetBackgroundPolicyByUid;
104 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_POWER_SAVE_POLICY)] =
105 &NetPolicyServiceStub::OnSetPowerSavePolicy;
106 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_CHECK_PERMISSION)] =
107 &NetPolicyServiceStub::OnCheckPermission;
108 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_FACTORYRESET_POLICIES)] =
109 &NetPolicyServiceStub::OnFactoryResetPolicies;
110 ExtraNetPolicyServiceStub();
111 InitEventHandler();
112 }
113
ExtraNetPolicyServiceStub()114 void NetPolicyServiceStub::ExtraNetPolicyServiceStub()
115 {
116 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_NETWORK_ACCESS_POLICY)] =
117 &NetPolicyServiceStub::OnSetNetworkAccessPolicy;
118 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_GET_NETWORK_ACCESS_POLICY)] =
119 &NetPolicyServiceStub::OnGetNetworkAccessPolicy;
120 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_NOTIFY_NETWORK_ACCESS_POLICY_DIAG)] =
121 &NetPolicyServiceStub::OnNotifyNetAccessPolicyDiag;
122 memberFuncMap_[static_cast<uint32_t>(PolicyInterfaceCode::CMD_NPS_SET_NIC_TRAFFIC_ALLOWED)] =
123 &NetPolicyServiceStub::OnSetNicTrafficAllowed;
124 return;
125 }
126
127 NetPolicyServiceStub::~NetPolicyServiceStub() = default;
128
InitEventHandler()129 void NetPolicyServiceStub::InitEventHandler()
130 {
131 std::call_once(onceFlag, [this]() {
132 auto core = DelayedSingleton<NetPolicyCore>::GetInstance();
133 handler_ = std::make_shared<NetPolicyEventHandler>(core, ffrtQueue_);
134 core->Init(handler_);
135 });
136 }
137
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)138 int32_t NetPolicyServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
139 MessageOption &option)
140 {
141 std::u16string myDescriptor = NetPolicyServiceStub::GetDescriptor();
142 std::u16string remoteDescriptor = data.ReadInterfaceToken();
143 if (myDescriptor != remoteDescriptor) {
144 NETMGR_LOG_E("descriptor checked fail");
145 return NETMANAGER_ERR_DESCRIPTOR_MISMATCH;
146 }
147 NETMGR_LOG_D("stub call start, code = [%{public}d]", code);
148 if (handler_ == nullptr) {
149 NETMGR_LOG_E("Net policy handler is null, recreate handler.");
150 InitEventHandler();
151 if (handler_ == nullptr) {
152 NETMGR_LOG_E("recreate net policy handler failed.");
153 return NETMANAGER_ERR_INTERNAL;
154 }
155 }
156 auto itFunc = memberFuncMap_.find(code);
157 if (itFunc != memberFuncMap_.end()) {
158 int32_t checkPermissionResult = CheckPolicyPermission(code);
159 if (checkPermissionResult != NETMANAGER_SUCCESS) {
160 if (!reply.WriteInt32(checkPermissionResult)) {
161 return IPC_STUB_WRITE_PARCEL_ERR;
162 }
163 return NETMANAGER_SUCCESS;
164 }
165 int32_t result = NETMANAGER_SUCCESS;
166 auto requestFunc = itFunc->second;
167 if (requestFunc != nullptr) {
168 #ifndef UNITTEST_FORBID_FFRT
169 auto task = ffrtQueue_.submit_h([this, &data, &reply, &requestFunc, &result]() {
170 #endif
171 result = (this->*requestFunc)(data, reply);
172 #ifndef UNITTEST_FORBID_FFRT
173 }, ffrt::task_attr().name("FfrtOnRemoteRequest"));
174 ffrtQueue_.wait(task);
175 #endif
176 NETMGR_LOG_D("stub call end, code = [%{public}d], ret = [%{public}d]", code, result);
177 return result;
178 }
179 }
180 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
181 }
182
SubCheckPermission(const std::string & permission,uint32_t funcCode)183 bool NetPolicyServiceStub::SubCheckPermission(const std::string &permission, uint32_t funcCode)
184 {
185 if (NetManagerPermission::CheckPermission(permission)) {
186 return true;
187 }
188 NETMGR_LOG_E("Permission denied funcCode: %{public}d permission: %{public}s", funcCode, permission.c_str());
189 return false;
190 }
191
CheckPolicyPermission(uint32_t code)192 int32_t NetPolicyServiceStub::CheckPolicyPermission(uint32_t code)
193 {
194 bool result = NetManagerPermission::IsSystemCaller();
195 if (!result) {
196 return NETMANAGER_ERR_NOT_SYSTEM_CALL;
197 }
198 if (g_codeNPS.find(code) != g_codeNPS.end()) {
199 result = SubCheckPermission(g_codeNPS[code], code);
200 if (!result) {
201 return NETMANAGER_ERR_PERMISSION_DENIED;
202 }
203 return NETMANAGER_SUCCESS;
204 }
205 NETMGR_LOG_E("Error funcCode, need check");
206 return NETMANAGER_ERR_PERMISSION_DENIED;
207 }
208
OnSetPolicyByUid(MessageParcel & data,MessageParcel & reply)209 int32_t NetPolicyServiceStub::OnSetPolicyByUid(MessageParcel &data, MessageParcel &reply)
210 {
211 NETMGR_LOG_I("SetPolicyByUid callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
212 IPCSkeleton::GetCallingPid());
213 uint32_t uid = 0;
214 if (!data.ReadUint32(uid)) {
215 NETMGR_LOG_E("Read Uint32 data failed.");
216 return NETMANAGER_ERR_READ_DATA_FAIL;
217 }
218
219 uint32_t netPolicy = 0;
220 if (!data.ReadUint32(netPolicy)) {
221 NETMGR_LOG_E("Read Uint32 data failed.");
222 return NETMANAGER_ERR_READ_DATA_FAIL;
223 }
224
225 int32_t result = SetPolicyByUid(uid, netPolicy);
226 if (!reply.WriteInt32(result)) {
227 NETMGR_LOG_E("Write int32 reply failed.");
228 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
229 }
230
231 return NETMANAGER_SUCCESS;
232 }
233
OnGetPolicyByUid(MessageParcel & data,MessageParcel & reply)234 int32_t NetPolicyServiceStub::OnGetPolicyByUid(MessageParcel &data, MessageParcel &reply)
235 {
236 NETMGR_LOG_I("GetPolicyByUid callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
237 IPCSkeleton::GetCallingPid());
238 uint32_t uid = 0;
239 if (!data.ReadUint32(uid)) {
240 return NETMANAGER_ERR_READ_DATA_FAIL;
241 }
242
243 uint32_t policy = 0;
244 int32_t result = GetPolicyByUid(uid, policy);
245 if (!reply.WriteInt32(result)) {
246 NETMGR_LOG_E("Write int32 reply failed.");
247 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
248 }
249
250 if (result == NETMANAGER_SUCCESS) {
251 if (!reply.WriteInt32(policy)) {
252 NETMGR_LOG_E("Write int32 reply failed.");
253 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
254 }
255 }
256
257 return NETMANAGER_SUCCESS;
258 }
259
OnGetUidsByPolicy(MessageParcel & data,MessageParcel & reply)260 int32_t NetPolicyServiceStub::OnGetUidsByPolicy(MessageParcel &data, MessageParcel &reply)
261 {
262 NETMGR_LOG_I("GetUidsByPolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
263 IPCSkeleton::GetCallingPid());
264 uint32_t policy = 0;
265 if (!data.ReadUint32(policy)) {
266 NETMGR_LOG_E("Read uint32 data failed");
267 return NETMANAGER_ERR_READ_DATA_FAIL;
268 }
269
270 std::vector<uint32_t> uids;
271 int32_t result = GetUidsByPolicy(policy, uids);
272 if (!reply.WriteInt32(result)) {
273 NETMGR_LOG_E("Write int32 reply failed");
274 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
275 }
276
277 if (result == NETMANAGER_SUCCESS) {
278 if (!reply.WriteUInt32Vector(uids)) {
279 NETMGR_LOG_E("Write uint32 vector reply failed");
280 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
281 }
282 }
283
284 return NETMANAGER_SUCCESS;
285 }
286
OnIsUidNetAllowedMetered(MessageParcel & data,MessageParcel & reply)287 int32_t NetPolicyServiceStub::OnIsUidNetAllowedMetered(MessageParcel &data, MessageParcel &reply)
288 {
289 NETMGR_LOG_I("IsUidNetAllowedMetered callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
290 IPCSkeleton::GetCallingPid());
291 uint32_t uid = 0;
292 bool metered = false;
293 if (!data.ReadUint32(uid)) {
294 NETMGR_LOG_E("Read uint32 data failed");
295 return NETMANAGER_ERR_READ_DATA_FAIL;
296 }
297
298 if (!data.ReadBool(metered)) {
299 NETMGR_LOG_E("Read Bool data failed");
300 return NETMANAGER_ERR_READ_DATA_FAIL;
301 }
302
303 bool isAllowed = false;
304 int32_t result = IsUidNetAllowed(uid, metered, isAllowed);
305 if (!reply.WriteInt32(result)) {
306 NETMGR_LOG_E("Write int32 reply failed");
307 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
308 }
309
310 if (result == NETMANAGER_SUCCESS) {
311 if (!reply.WriteBool(isAllowed)) {
312 NETMGR_LOG_E("Write Bool reply failed");
313 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
314 }
315 }
316 return NETMANAGER_SUCCESS;
317 }
318
OnIsUidNetAllowedIfaceName(MessageParcel & data,MessageParcel & reply)319 int32_t NetPolicyServiceStub::OnIsUidNetAllowedIfaceName(MessageParcel &data, MessageParcel &reply)
320 {
321 NETMGR_LOG_I("IsUidNetAllowedIfaceName callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
322 IPCSkeleton::GetCallingPid());
323 uint32_t uid = 0;
324 std::string ifaceName;
325 if (!data.ReadUint32(uid)) {
326 NETMGR_LOG_E("Read uint32 data failed");
327 return NETMANAGER_ERR_READ_DATA_FAIL;
328 }
329
330 if (!data.ReadString(ifaceName)) {
331 NETMGR_LOG_E("Read String data failed");
332 return NETMANAGER_ERR_READ_DATA_FAIL;
333 }
334
335 bool isAllowed = false;
336 int32_t result = IsUidNetAllowed(uid, ifaceName, isAllowed);
337 if (!reply.WriteInt32(result)) {
338 NETMGR_LOG_E("Write int32 reply failed");
339 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
340 }
341 if (result == NETMANAGER_SUCCESS) {
342 if (!reply.WriteBool(isAllowed)) {
343 NETMGR_LOG_E("Write Bool reply failed");
344 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
345 }
346 }
347 return NETMANAGER_SUCCESS;
348 }
349
OnRegisterNetPolicyCallback(MessageParcel & data,MessageParcel & reply)350 int32_t NetPolicyServiceStub::OnRegisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply)
351 {
352 NETMGR_LOG_I("RegisterNetPolicyCallback callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
353 IPCSkeleton::GetCallingPid());
354 sptr<IRemoteObject> remote = data.ReadRemoteObject();
355 if (remote == nullptr) {
356 NETMGR_LOG_E("Callback ptr is nullptr.");
357 reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL);
358 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
359 }
360
361 sptr<INetPolicyCallback> callback = iface_cast<INetPolicyCallback>(remote);
362 int32_t result = RegisterNetPolicyCallback(callback);
363 if (!reply.WriteInt32(result)) {
364 NETMGR_LOG_E("Write int32 reply failed");
365 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
366 }
367
368 return NETMANAGER_SUCCESS;
369 }
370
OnUnregisterNetPolicyCallback(MessageParcel & data,MessageParcel & reply)371 int32_t NetPolicyServiceStub::OnUnregisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply)
372 {
373 NETMGR_LOG_I("UnregisterNetPolicyCallback callingUid/callingPid: %{public}d/%{public}d",
374 IPCSkeleton::GetCallingUid(), IPCSkeleton::GetCallingPid());
375 sptr<IRemoteObject> remote = data.ReadRemoteObject();
376 if (remote == nullptr) {
377 NETMGR_LOG_E("callback ptr is nullptr.");
378 reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL);
379 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
380 }
381 sptr<INetPolicyCallback> callback = iface_cast<INetPolicyCallback>(remote);
382 int32_t result = UnregisterNetPolicyCallback(callback);
383 if (!reply.WriteInt32(result)) {
384 NETMGR_LOG_E("Write int32 reply failed");
385 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
386 }
387
388 return NETMANAGER_SUCCESS;
389 }
390
OnSetNetQuotaPolicies(MessageParcel & data,MessageParcel & reply)391 int32_t NetPolicyServiceStub::OnSetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply)
392 {
393 NETMGR_LOG_I("SetNetQuotaPolicies callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
394 IPCSkeleton::GetCallingPid());
395 std::vector<NetQuotaPolicy> quotaPolicies;
396 if (!NetQuotaPolicy::Unmarshalling(data, quotaPolicies)) {
397 NETMGR_LOG_E("Unmarshalling failed.");
398 return NETMANAGER_ERR_READ_DATA_FAIL;
399 }
400
401 int32_t result = SetNetQuotaPolicies(quotaPolicies);
402 if (!reply.WriteInt32(result)) {
403 NETMGR_LOG_E("Write int32 reply failed");
404 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
405 }
406
407 return NETMANAGER_SUCCESS;
408 }
409
OnGetNetQuotaPolicies(MessageParcel & data,MessageParcel & reply)410 int32_t NetPolicyServiceStub::OnGetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply)
411 {
412 NETMGR_LOG_I("GetNetQuotaPolicies callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
413 IPCSkeleton::GetCallingPid());
414 std::vector<NetQuotaPolicy> quotaPolicies;
415
416 int32_t result = GetNetQuotaPolicies(quotaPolicies);
417 if (!reply.WriteInt32(result)) {
418 NETMGR_LOG_E("Write int32 reply failed");
419 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
420 }
421 if (result == NETMANAGER_SUCCESS) {
422 if (!NetQuotaPolicy::Marshalling(reply, quotaPolicies)) {
423 NETMGR_LOG_E("Marshalling failed");
424 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
425 }
426 }
427
428 return NETMANAGER_SUCCESS;
429 }
430
OnResetPolicies(MessageParcel & data,MessageParcel & reply)431 int32_t NetPolicyServiceStub::OnResetPolicies(MessageParcel &data, MessageParcel &reply)
432 {
433 NETMGR_LOG_I("ResetPolicies callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
434 IPCSkeleton::GetCallingPid());
435 std::string subscriberId;
436 if (!data.ReadString(subscriberId)) {
437 NETMGR_LOG_E("Read String data failed");
438 return NETMANAGER_ERR_READ_DATA_FAIL;
439 }
440
441 int32_t result = ResetPolicies(subscriberId);
442 if (!reply.WriteInt32(result)) {
443 NETMGR_LOG_E("Write int32 reply failed");
444 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
445 }
446
447 return NETMANAGER_SUCCESS;
448 }
449
OnSetBackgroundPolicy(MessageParcel & data,MessageParcel & reply)450 int32_t NetPolicyServiceStub::OnSetBackgroundPolicy(MessageParcel &data, MessageParcel &reply)
451 {
452 NETMGR_LOG_I("SetBackgroundPolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
453 IPCSkeleton::GetCallingPid());
454 bool isBackgroundPolicyAllow = false;
455 if (!data.ReadBool(isBackgroundPolicyAllow)) {
456 NETMGR_LOG_E("Read Bool data failed");
457 return NETMANAGER_ERR_READ_DATA_FAIL;
458 }
459
460 int32_t result = SetBackgroundPolicy(isBackgroundPolicyAllow);
461 if (!reply.WriteInt32(result)) {
462 NETMGR_LOG_E("Write int32 reply failed");
463 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
464 }
465
466 return NETMANAGER_SUCCESS;
467 }
468
OnGetBackgroundPolicy(MessageParcel & data,MessageParcel & reply)469 int32_t NetPolicyServiceStub::OnGetBackgroundPolicy(MessageParcel &data, MessageParcel &reply)
470 {
471 NETMGR_LOG_I("GetBackgroundPolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
472 IPCSkeleton::GetCallingPid());
473 bool backgroundPolicy = false;
474 int32_t result = GetBackgroundPolicy(backgroundPolicy);
475 if (!reply.WriteInt32(result)) {
476 NETMGR_LOG_E("Write int32 reply failed");
477 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
478 }
479 if (result == NETMANAGER_SUCCESS) {
480 if (!reply.WriteBool(backgroundPolicy)) {
481 NETMGR_LOG_E("Write Bool reply failed");
482 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
483 }
484 }
485 return NETMANAGER_SUCCESS;
486 }
487
OnGetBackgroundPolicyByUid(MessageParcel & data,MessageParcel & reply)488 int32_t NetPolicyServiceStub::OnGetBackgroundPolicyByUid(MessageParcel &data, MessageParcel &reply)
489 {
490 NETMGR_LOG_I("GetBackgroundPolicyByUid callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
491 IPCSkeleton::GetCallingPid());
492 uint32_t uid = 0;
493 if (!data.ReadUint32(uid)) {
494 NETMGR_LOG_E("Read uint32 data failed");
495 return NETMANAGER_ERR_READ_DATA_FAIL;
496 }
497
498 uint32_t backgroundPolicyOfUid = 0;
499 int32_t result = GetBackgroundPolicyByUid(uid, backgroundPolicyOfUid);
500 if (!reply.WriteInt32(result)) {
501 NETMGR_LOG_E("Write int32 reply failed");
502 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
503 }
504 if (result == NETMANAGER_SUCCESS) {
505 if (!reply.WriteUint32(backgroundPolicyOfUid)) {
506 NETMGR_LOG_E("Write uint32 reply failed");
507 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
508 }
509 }
510
511 return NETMANAGER_SUCCESS;
512 }
513
OnSnoozePolicy(MessageParcel & data,MessageParcel & reply)514 int32_t NetPolicyServiceStub::OnSnoozePolicy(MessageParcel &data, MessageParcel &reply)
515 {
516 NETMGR_LOG_I("SnoozePolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
517 IPCSkeleton::GetCallingPid());
518 int32_t netType = 0;
519 if (!data.ReadInt32(netType)) {
520 NETMGR_LOG_E("Read int32 data failed");
521 return NETMANAGER_ERR_READ_DATA_FAIL;
522 }
523
524 std::string simId;
525 if (!data.ReadString(simId)) {
526 NETMGR_LOG_E("Read String data failed");
527 return NETMANAGER_ERR_READ_DATA_FAIL;
528 }
529
530 uint32_t remindType = 0;
531 if (!data.ReadUint32(remindType)) {
532 NETMGR_LOG_E("Read uint32 data failed");
533 return NETMANAGER_ERR_READ_DATA_FAIL;
534 }
535
536 int32_t result = UpdateRemindPolicy(netType, simId, remindType);
537 if (!reply.WriteInt32(result)) {
538 NETMGR_LOG_E("Write int32 reply failed");
539 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
540 }
541
542 return NETMANAGER_SUCCESS;
543 }
544
OnSetDeviceIdleTrustlist(MessageParcel & data,MessageParcel & reply)545 int32_t NetPolicyServiceStub::OnSetDeviceIdleTrustlist(MessageParcel &data, MessageParcel &reply)
546 {
547 NETMGR_LOG_I("SetDeviceIdleTrustlist callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
548 IPCSkeleton::GetCallingPid());
549 std::vector<uint32_t> uids;
550 if (!data.ReadUInt32Vector(&uids)) {
551 NETMGR_LOG_E("Read uint32 data failed");
552 return NETMANAGER_ERR_READ_DATA_FAIL;
553 }
554
555 bool isAllowed = false;
556 if (!data.ReadBool(isAllowed)) {
557 NETMGR_LOG_E("Read Bool data failed");
558 return NETMANAGER_ERR_READ_DATA_FAIL;
559 }
560
561 int32_t result = SetDeviceIdleTrustlist(uids, isAllowed);
562 if (!reply.WriteInt32(result)) {
563 NETMGR_LOG_E("Write int32 reply failed");
564 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
565 }
566
567 return NETMANAGER_SUCCESS;
568 }
569
OnGetDeviceIdleTrustlist(MessageParcel & data,MessageParcel & reply)570 int32_t NetPolicyServiceStub::OnGetDeviceIdleTrustlist(MessageParcel &data, MessageParcel &reply)
571 {
572 NETMGR_LOG_I("GetDeviceIdleTrustlist callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
573 IPCSkeleton::GetCallingPid());
574 std::vector<uint32_t> uids;
575 int32_t result = GetDeviceIdleTrustlist(uids);
576 if (!reply.WriteInt32(result)) {
577 NETMGR_LOG_E("Write int32 reply failed");
578 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
579 }
580 if (result == NETMANAGER_SUCCESS) {
581 if (!reply.WriteUInt32Vector(uids)) {
582 NETMGR_LOG_E("Write uint32 vector reply failed");
583 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
584 }
585 }
586
587 return NETMANAGER_SUCCESS;
588 }
589
OnSetDeviceIdlePolicy(MessageParcel & data,MessageParcel & reply)590 int32_t NetPolicyServiceStub::OnSetDeviceIdlePolicy(MessageParcel &data, MessageParcel &reply)
591 {
592 NETMGR_LOG_I("SetDeviceIdlePolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
593 IPCSkeleton::GetCallingPid());
594 bool isAllowed = false;
595 if (!data.ReadBool(isAllowed)) {
596 NETMGR_LOG_E("Read Bool data failed");
597 return NETMANAGER_ERR_READ_DATA_FAIL;
598 }
599
600 int32_t result = SetDeviceIdlePolicy(isAllowed);
601 if (!reply.WriteInt32(result)) {
602 NETMGR_LOG_E("Write int32 reply failed");
603 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
604 }
605 return NETMANAGER_SUCCESS;
606 }
607
OnGetPowerSaveTrustlist(MessageParcel & data,MessageParcel & reply)608 int32_t NetPolicyServiceStub::OnGetPowerSaveTrustlist(MessageParcel &data, MessageParcel &reply)
609 {
610 NETMGR_LOG_I("GetPowerSaveTrustlist callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
611 IPCSkeleton::GetCallingPid());
612 std::vector<uint32_t> uids;
613 int32_t result = GetPowerSaveTrustlist(uids);
614 if (!reply.WriteInt32(result)) {
615 NETMGR_LOG_E("Write int32 reply failed");
616 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
617 }
618 if (result == NETMANAGER_SUCCESS) {
619 if (!reply.WriteUInt32Vector(uids)) {
620 NETMGR_LOG_E("Write uint32 Vector reply failed");
621 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
622 }
623 }
624
625 return NETMANAGER_SUCCESS;
626 }
627
OnSetPowerSaveTrustlist(MessageParcel & data,MessageParcel & reply)628 int32_t NetPolicyServiceStub::OnSetPowerSaveTrustlist(MessageParcel &data, MessageParcel &reply)
629 {
630 NETMGR_LOG_I("SetPowerSaveTrustlist callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
631 IPCSkeleton::GetCallingPid());
632 std::vector<uint32_t> uids;
633 if (!data.ReadUInt32Vector(&uids)) {
634 NETMGR_LOG_E("Read uint32 data failed");
635 return NETMANAGER_ERR_READ_DATA_FAIL;
636 }
637
638 bool isAllowed = false;
639 if (!data.ReadBool(isAllowed)) {
640 NETMGR_LOG_E("Read Bool data failed");
641 return NETMANAGER_ERR_READ_DATA_FAIL;
642 }
643
644 int32_t result = SetPowerSaveTrustlist(uids, isAllowed);
645 if (!reply.WriteInt32(result)) {
646 NETMGR_LOG_E("Write int32 reply failed");
647 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
648 }
649
650 return NETMANAGER_SUCCESS;
651 }
652
OnSetPowerSavePolicy(MessageParcel & data,MessageParcel & reply)653 int32_t NetPolicyServiceStub::OnSetPowerSavePolicy(MessageParcel &data, MessageParcel &reply)
654 {
655 NETMGR_LOG_I("SetPowerSavePolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
656 IPCSkeleton::GetCallingPid());
657 bool isAllowed = false;
658 if (!data.ReadBool(isAllowed)) {
659 NETMGR_LOG_E("Read Bool data failed");
660 return NETMANAGER_ERR_READ_DATA_FAIL;
661 }
662
663 int32_t result = SetPowerSavePolicy(isAllowed);
664 if (!reply.WriteInt32(result)) {
665 NETMGR_LOG_E("Write int32 reply failed");
666 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
667 }
668
669 return NETMANAGER_SUCCESS;
670 }
671
OnCheckPermission(MessageParcel & data,MessageParcel & reply)672 int32_t NetPolicyServiceStub::OnCheckPermission(MessageParcel &data, MessageParcel &reply)
673 {
674 if (!reply.WriteInt32(NETMANAGER_SUCCESS)) {
675 NETMGR_LOG_E("Write int32 reply failed");
676 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
677 }
678 return NETMANAGER_SUCCESS;
679 }
680
OnFactoryResetPolicies(MessageParcel & data,MessageParcel & reply)681 int32_t NetPolicyServiceStub::OnFactoryResetPolicies(MessageParcel &data, MessageParcel &reply)
682 {
683 return NETMANAGER_SUCCESS;
684 }
685
HandleReportNetworkPolicy()686 void NetPolicyServiceStub::HandleReportNetworkPolicy()
687 {
688 #ifndef UNITTEST_FORBID_FFRT
689 std::lock_guard<std::mutex> lock(setNetworkPolicyMutex_);
690 #endif
691 if (appNetworkPolicyMap_.empty()) {
692 return;
693 }
694 BroadcastInfo info;
695 info.action = NETWORK_POLICY_CHANGED_EVENT;
696 info.subscriberUid = HIVIEW_UID;
697 cJSON* networkPolicyJson = cJSON_CreateObject();
698 for (auto &callingPolicy : appNetworkPolicyMap_) {
699 cJSON* appPolicyJson = cJSON_CreateObject();
700 for (auto &appPolicy : callingPolicy.second) {
701 cJSON_AddNumberToObject(appPolicyJson, std::to_string(appPolicy.first).c_str(), appPolicy.second);
702 }
703 cJSON_AddItemToObject(networkPolicyJson, std::to_string(callingPolicy.first).c_str(), appPolicyJson);
704 }
705 char *pParamJson = cJSON_PrintUnformatted(networkPolicyJson);
706 cJSON_Delete(networkPolicyJson);
707 if (!pParamJson) {
708 return;
709 }
710 std::string paramStr(pParamJson);
711 NETMGR_LOG_I("HandleReportNetworkPolicy, %{public}s", paramStr.c_str());
712 std::map<std::string, std::string> param = {{NETWORK_POLICY_INFO_KEY, paramStr}};
713 BroadcastManager::GetInstance().SendBroadcast(info, param);
714 cJSON_free(pParamJson);
715 isPostDelaySetNetworkPolicy_ = false;
716 appNetworkPolicyMap_.clear();
717 }
718
HandleStoreNetworkPolicy(uint32_t uid,NetworkAccessPolicy & policy,uint32_t callingUid)719 void NetPolicyServiceStub::HandleStoreNetworkPolicy(uint32_t uid, NetworkAccessPolicy &policy,
720 uint32_t callingUid)
721 {
722 std::lock_guard<std::mutex> lock(setNetworkPolicyMutex_);
723 if (appNetworkPolicyMap_.find(callingUid) == appNetworkPolicyMap_.end()) {
724 std::map<uint32_t, uint32_t> policyMap;
725 appNetworkPolicyMap_.emplace(callingUid, std::move(policyMap));
726 }
727 uint32_t policyInfo = 0;
728 policyInfo |= policy.wifiAllow ? NET_POLICY_WIFI_ALLOW : 0;
729 policyInfo |= policy.cellularAllow ? NET_POLICY_CELLULAR_ALLOW : 0;
730 auto& allNetworkPolicy = appNetworkPolicyMap_.at(callingUid);
731 allNetworkPolicy[uid] = policyInfo;
732 if (!isPostDelaySetNetworkPolicy_) {
733 isPostDelaySetNetworkPolicy_ = true;
734 #ifndef UNITTEST_FORBID_FFRT
735 ffrtQueue_.submit([this]() {
736 #endif
737 HandleReportNetworkPolicy();
738 #ifndef UNITTEST_FORBID_FFRT
739 }, ffrt::task_attr().name("HandleReportNetworkPolicy").delay(NETWORK_POLICY_REPORT_DELAY));
740 #endif
741 }
742 }
743
OnSetNetworkAccessPolicy(MessageParcel & data,MessageParcel & reply)744 int32_t NetPolicyServiceStub::OnSetNetworkAccessPolicy(MessageParcel &data, MessageParcel &reply)
745 {
746 NETMGR_LOG_I("SetNetworkAccessPolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
747 IPCSkeleton::GetCallingPid());
748 uint32_t uid;
749
750 if (!data.ReadUint32(uid)) {
751 return NETMANAGER_ERR_READ_DATA_FAIL;
752 }
753
754 uint8_t wifi_allow;
755 uint8_t cellular_allow;
756 NetworkAccessPolicy policy;
757 bool reconfirmFlag = true;
758
759 if (!data.ReadUint8(wifi_allow)) {
760 return NETMANAGER_ERR_READ_DATA_FAIL;
761 }
762
763 if (!data.ReadUint8(cellular_allow)) {
764 return NETMANAGER_ERR_READ_DATA_FAIL;
765 }
766
767 if (!data.ReadBool(reconfirmFlag)) {
768 return NETMANAGER_ERR_READ_DATA_FAIL;
769 }
770
771 policy.wifiAllow = wifi_allow;
772 policy.cellularAllow = cellular_allow;
773 int32_t ret = SetNetworkAccessPolicy(uid, policy, reconfirmFlag);
774 if (!reply.WriteInt32(ret)) {
775 NETMGR_LOG_E("Write int32 reply failed");
776 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
777 }
778 HandleStoreNetworkPolicy(uid, policy, IPCSkeleton::GetCallingUid());
779 return NETMANAGER_SUCCESS;
780 }
781
OnGetNetworkAccessPolicy(MessageParcel & data,MessageParcel & reply)782 int32_t NetPolicyServiceStub::OnGetNetworkAccessPolicy(MessageParcel &data, MessageParcel &reply)
783 {
784 NETMGR_LOG_I("GetNetworkAccessPolicy callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
785 IPCSkeleton::GetCallingPid());
786 int32_t uid = 0;
787 uint32_t userId = 1;
788 bool flag = false;
789 if (!data.ReadBool(flag)) {
790 return NETMANAGER_ERR_READ_DATA_FAIL;
791 }
792
793 if (!data.ReadInt32(uid)) {
794 return NETMANAGER_ERR_READ_DATA_FAIL;
795 }
796
797 if (!data.ReadUint32(userId)) {
798 return NETMANAGER_ERR_READ_DATA_FAIL;
799 }
800
801 AccessPolicySave policies;
802 AccessPolicyParameter parameters;
803 parameters.flag = flag;
804 parameters.uid = uid;
805 parameters.userId = userId;
806
807 int32_t ret = GetNetworkAccessPolicy(parameters, policies);
808 if (!reply.WriteInt32(ret)) {
809 NETMGR_LOG_E("Write int32 reply failed");
810 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
811 }
812
813 if (ret == NETMANAGER_SUCCESS) {
814 ret = NetworkAccessPolicy::Marshalling(reply, policies, flag);
815 if (ret != NETMANAGER_SUCCESS) {
816 NETMGR_LOG_E("GetNetworkAccessPolicy marshalling failed");
817 return ret;
818 }
819 }
820
821 return ret;
822 }
823
OnNotifyNetAccessPolicyDiag(MessageParcel & data,MessageParcel & reply)824 int32_t NetPolicyServiceStub::OnNotifyNetAccessPolicyDiag(MessageParcel &data, MessageParcel &reply)
825 {
826 NETMGR_LOG_I("NotifyNetAccessPolicyDiag callingUid/callingPid: %{public}d/%{public}d", IPCSkeleton::GetCallingUid(),
827 IPCSkeleton::GetCallingPid());
828 uint32_t uid;
829
830 if (!data.ReadUint32(uid)) {
831 return NETMANAGER_ERR_READ_DATA_FAIL;
832 }
833
834 int32_t ret = NotifyNetAccessPolicyDiag(uid);
835 if (!reply.WriteInt32(ret)) {
836 NETMGR_LOG_E("Write int32 reply failed");
837 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
838 }
839
840 return ret;
841 }
842
OnSetNicTrafficAllowed(MessageParcel & data,MessageParcel & reply)843 int32_t NetPolicyServiceStub::OnSetNicTrafficAllowed(MessageParcel &data, MessageParcel &reply)
844 {
845 if (!NetManagerStandard::NetManagerPermission::CheckNetSysInternalPermission(
846 NetManagerStandard::Permission::NETSYS_INTERNAL)) {
847 NETMGR_LOG_E("OnSetNicTrafficAllowed CheckNetSysInternalPermission failed");
848 return NETMANAGER_ERR_PERMISSION_DENIED;
849 }
850
851 auto uid = IPCSkeleton::GetCallingUid();
852 if (uid != UID_EDM && uid != UID_NET_MANAGER && uid != UID_IOT_NET_MANAGER) {
853 NETMGR_LOG_E("OnSetNicTrafficAllowed CheckUidPermission failed");
854 return NETMANAGER_ERR_PERMISSION_DENIED;
855 }
856
857 bool status = false;
858 int32_t size = 0;
859 if (!data.ReadBool(status) || !data.ReadInt32(size)) {
860 NETMGR_LOG_E("OnSetNicTrafficAllowed read status or size failed");
861 return ERR_FLATTEN_OBJECT;
862 }
863 if (size > static_cast<int32_t>(MAX_IFACENAMES_SIZE)) {
864 NETMGR_LOG_E("OnSetNicTrafficAllowed read data size too big");
865 return ERR_FLATTEN_OBJECT;
866 }
867 std::vector<std::string> ifaceNames;
868 std::string ifaceName;
869 for (int32_t index = 0; index < size; index++) {
870 data.ReadString(ifaceName);
871 if (ifaceName.empty()) {
872 NETMGR_LOG_E("OnSetNicTrafficAllowed ifaceName is empty, size mismatch");
873 return ERR_FLATTEN_OBJECT;
874 }
875 ifaceNames.push_back(ifaceName);
876 }
877 int32_t result = SetNicTrafficAllowed(ifaceNames, status);
878 if (!reply.WriteInt32(result)) {
879 NETMGR_LOG_E("Write OnSetNicTrafficAllowed result failed");
880 return ERR_FLATTEN_OBJECT;
881 }
882 return NETMANAGER_SUCCESS;
883 }
884 } // namespace NetManagerStandard
885 } // namespace OHOS
886