1 /*
2 * Copyright (c) 2021-2022 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
23 namespace OHOS {
24 namespace NetManagerStandard {
25 namespace {
26 std::map<uint32_t, const std::string> g_codeNPS = {
27 {INetPolicyService::CMD_NPS_SET_POLICY_BY_UID, Permission::SET_NETWORK_POLICY},
28 {INetPolicyService::CMD_NPS_SET_NET_QUOTA_POLICIES, Permission::SET_NETWORK_POLICY},
29 {INetPolicyService::CMD_NPS_RESET_POLICIES, Permission::SET_NETWORK_POLICY},
30 {INetPolicyService::CMD_NPS_SET_BACKGROUND_POLICY, Permission::SET_NETWORK_POLICY},
31 {INetPolicyService::CMD_NPS_UPDATE_REMIND_POLICY, Permission::SET_NETWORK_POLICY},
32
33 {INetPolicyService::CMD_NPS_GET_POLICY_BY_UID, Permission::GET_NETWORK_POLICY},
34 {INetPolicyService::CMD_NPS_GET_UIDS_BY_POLICY, Permission::GET_NETWORK_POLICY},
35 {INetPolicyService::CMD_NPS_GET_NET_QUOTA_POLICIES, Permission::GET_NETWORK_POLICY},
36 {INetPolicyService::CMD_NPS_GET_BACKGROUND_POLICY, Permission::GET_NETWORK_POLICY},
37
38 {INetPolicyService::CMD_NPS_IS_NET_ALLOWED_BY_METERED, Permission::CONNECTIVITY_INTERNAL},
39 {INetPolicyService::CMD_NPS_IS_NET_ALLOWED_BY_IFACE, Permission::CONNECTIVITY_INTERNAL},
40 {INetPolicyService::CMD_NPS_REGISTER_NET_POLICY_CALLBACK, Permission::CONNECTIVITY_INTERNAL},
41 {INetPolicyService::CMD_NPS_UNREGISTER_NET_POLICY_CALLBACK, Permission::CONNECTIVITY_INTERNAL},
42 {INetPolicyService::CMD_NPS_GET_BACKGROUND_POLICY_BY_UID, Permission::CONNECTIVITY_INTERNAL},
43 {INetPolicyService::CMD_NPS_SET_IDLE_ALLOWED_LIST, Permission::CONNECTIVITY_INTERNAL},
44 {INetPolicyService::CMD_NPS_GET_IDLE_ALLOWED_LIST, Permission::CONNECTIVITY_INTERNAL},
45 {INetPolicyService::CMD_NPS_SET_DEVICE_IDLE_POLICY, Permission::CONNECTIVITY_INTERNAL},
46 };
47 } // namespace
48
NetPolicyServiceStub()49 NetPolicyServiceStub::NetPolicyServiceStub()
50 {
51 memberFuncMap_[CMD_NPS_SET_POLICY_BY_UID] = &NetPolicyServiceStub::OnSetPolicyByUid;
52 memberFuncMap_[CMD_NPS_GET_POLICY_BY_UID] = &NetPolicyServiceStub::OnGetPolicyByUid;
53 memberFuncMap_[CMD_NPS_GET_UIDS_BY_POLICY] = &NetPolicyServiceStub::OnGetUidsByPolicy;
54 memberFuncMap_[CMD_NPS_IS_NET_ALLOWED_BY_METERED] = &NetPolicyServiceStub::OnIsUidNetAllowedMetered;
55 memberFuncMap_[CMD_NPS_IS_NET_ALLOWED_BY_IFACE] = &NetPolicyServiceStub::OnIsUidNetAllowedIfaceName;
56 memberFuncMap_[CMD_NPS_REGISTER_NET_POLICY_CALLBACK] = &NetPolicyServiceStub::OnRegisterNetPolicyCallback;
57 memberFuncMap_[CMD_NPS_UNREGISTER_NET_POLICY_CALLBACK] = &NetPolicyServiceStub::OnUnregisterNetPolicyCallback;
58 memberFuncMap_[CMD_NPS_SET_NET_QUOTA_POLICIES] = &NetPolicyServiceStub::OnSetNetQuotaPolicies;
59 memberFuncMap_[CMD_NPS_GET_NET_QUOTA_POLICIES] = &NetPolicyServiceStub::OnGetNetQuotaPolicies;
60 memberFuncMap_[CMD_NPS_RESET_POLICIES] = &NetPolicyServiceStub::OnResetPolicies;
61 memberFuncMap_[CMD_NPS_UPDATE_REMIND_POLICY] = &NetPolicyServiceStub::OnSnoozePolicy;
62 memberFuncMap_[CMD_NPS_SET_IDLE_ALLOWED_LIST] = &NetPolicyServiceStub::OnSetDeviceIdleAllowedList;
63 memberFuncMap_[CMD_NPS_GET_IDLE_ALLOWED_LIST] = &NetPolicyServiceStub::OnGetDeviceIdleAllowedList;
64 memberFuncMap_[CMD_NPS_SET_DEVICE_IDLE_POLICY] = &NetPolicyServiceStub::OnSetDeviceIdlePolicy;
65 memberFuncMap_[CMD_NPS_SET_BACKGROUND_POLICY] = &NetPolicyServiceStub::OnSetBackgroundPolicy;
66 memberFuncMap_[CMD_NPS_GET_BACKGROUND_POLICY] = &NetPolicyServiceStub::OnGetBackgroundPolicy;
67 memberFuncMap_[CMD_NPS_GET_BACKGROUND_POLICY_BY_UID] = &NetPolicyServiceStub::OnGetBackgroundPolicyByUid;
68 InitEventHandler();
69 }
70
71 NetPolicyServiceStub::~NetPolicyServiceStub() = default;
72
InitEventHandler()73 void NetPolicyServiceStub::InitEventHandler()
74 {
75 runner_ = AppExecFwk::EventRunner::Create(NET_POLICY_WORK_THREAD);
76 if (!runner_) {
77 NETMGR_LOG_E("Create net policy work event runner.");
78 return;
79 }
80 auto core = DelayedSingleton<NetPolicyCore>::GetInstance();
81 handler_ = std::make_shared<NetPolicyEventHandler>(runner_, core);
82 core->Init(handler_);
83 }
84
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)85 int32_t NetPolicyServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply,
86 MessageOption &option)
87 {
88 std::u16string myDescriptor = NetPolicyServiceStub::GetDescriptor();
89 std::u16string remoteDescriptor = data.ReadInterfaceToken();
90 if (myDescriptor != remoteDescriptor) {
91 NETMGR_LOG_E("descriptor checked fail");
92 return NETMANAGER_ERR_DESCRIPTOR_MISMATCH;
93 }
94
95 if (handler_ == nullptr) {
96 NETMGR_LOG_E("Net policy handler is null, re-create handler.");
97 InitEventHandler();
98 }
99
100 int32_t checkPermissionResult = CheckPolicyPermission(code);
101 if (checkPermissionResult != NETMANAGER_SUCCESS) {
102 return checkPermissionResult;
103 }
104
105 auto itFunc = memberFuncMap_.find(code);
106 int32_t result = NETMANAGER_SUCCESS;
107 if (itFunc != memberFuncMap_.end()) {
108 auto requestFunc = itFunc->second;
109 if (requestFunc != nullptr) {
110 handler_->PostSyncTask(
111 [this, &data, &reply, &requestFunc, &result]() { result = (this->*requestFunc)(data, reply); },
112 AppExecFwk::EventQueue::Priority::HIGH);
113 return result;
114 }
115 }
116 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
117 }
118
CheckPermission(const std::string & permission,uint32_t funcCode)119 bool NetPolicyServiceStub::CheckPermission(const std::string &permission, uint32_t funcCode)
120 {
121 if (NetManagerPermission::CheckPermission(permission)) {
122 return true;
123 }
124 NETMGR_LOG_E("Permission denied funcCode: %{public}d permission: %{public}s", funcCode, permission.c_str());
125 return false;
126 }
127
CheckPolicyPermission(uint32_t code)128 int32_t NetPolicyServiceStub::CheckPolicyPermission(uint32_t code)
129 {
130 bool result = false;
131 if (g_codeNPS.find(code) != g_codeNPS.end()) {
132 result = CheckPermission(g_codeNPS[code], code);
133 if (!result) {
134 return NETMANAGER_ERR_PERMISSION_DENIED;
135 }
136 return NETMANAGER_SUCCESS;
137 }
138 NETMGR_LOG_E("Error funcCode, need check");
139 return NETMANAGER_ERR_PERMISSION_DENIED;
140 }
141
OnSetPolicyByUid(MessageParcel & data,MessageParcel & reply)142 int32_t NetPolicyServiceStub::OnSetPolicyByUid(MessageParcel &data, MessageParcel &reply)
143 {
144 uint32_t uid;
145 if (!data.ReadUint32(uid)) {
146 NETMGR_LOG_E("Read Uint32 data failed.");
147 return NETMANAGER_ERR_READ_DATA_FAIL;
148 }
149
150 uint32_t netPolicy;
151 if (!data.ReadUint32(netPolicy)) {
152 NETMGR_LOG_E("Read Uint32 data failed.");
153 return NETMANAGER_ERR_READ_DATA_FAIL;
154 }
155
156 int32_t result = SetPolicyByUid(uid, netPolicy);
157 if (!reply.WriteInt32(result)) {
158 NETMGR_LOG_E("Write int32 reply failed.");
159 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
160 }
161
162 return NETMANAGER_SUCCESS;
163 }
164
OnGetPolicyByUid(MessageParcel & data,MessageParcel & reply)165 int32_t NetPolicyServiceStub::OnGetPolicyByUid(MessageParcel &data, MessageParcel &reply)
166 {
167 uint32_t uid = 0;
168 if (!data.ReadUint32(uid)) {
169 return NETMANAGER_ERR_READ_DATA_FAIL;
170 }
171
172 uint32_t policy = 0;
173 int32_t result = GetPolicyByUid(uid, policy);
174 if (!reply.WriteInt32(policy)) {
175 NETMGR_LOG_E("Write int32 reply failed.");
176 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
177 }
178
179 if (!reply.WriteInt32(result)) {
180 NETMGR_LOG_E("Write int32 reply failed.");
181 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
182 }
183
184 return NETMANAGER_SUCCESS;
185 }
186
OnGetUidsByPolicy(MessageParcel & data,MessageParcel & reply)187 int32_t NetPolicyServiceStub::OnGetUidsByPolicy(MessageParcel &data, MessageParcel &reply)
188 {
189 uint32_t policy;
190 if (!data.ReadUint32(policy)) {
191 NETMGR_LOG_E("Read uint32 data failed");
192 return NETMANAGER_ERR_READ_DATA_FAIL;
193 }
194
195 std::vector<uint32_t> uids;
196 int32_t result = GetUidsByPolicy(policy, uids);
197 if (!reply.WriteUInt32Vector(uids)) {
198 NETMGR_LOG_E("Write uint32 vector reply failed");
199 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
200 }
201
202 if (!reply.WriteInt32(result)) {
203 NETMGR_LOG_E("Write int32 reply failed");
204 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
205 }
206
207 return NETMANAGER_SUCCESS;
208 }
209
OnIsUidNetAllowedMetered(MessageParcel & data,MessageParcel & reply)210 int32_t NetPolicyServiceStub::OnIsUidNetAllowedMetered(MessageParcel &data, MessageParcel &reply)
211 {
212 uint32_t uid = 0;
213 bool metered = false;
214 if (!data.ReadUint32(uid)) {
215 NETMGR_LOG_E("Read uint32 data failed");
216 return NETMANAGER_ERR_READ_DATA_FAIL;
217 }
218
219 if (!data.ReadBool(metered)) {
220 NETMGR_LOG_E("Read Bool data failed");
221 return NETMANAGER_ERR_READ_DATA_FAIL;
222 }
223
224 bool isAllowed = false;
225 int32_t result = IsUidNetAllowed(uid, metered, isAllowed);
226 if (!reply.WriteBool(isAllowed)) {
227 NETMGR_LOG_E("Write Bool reply failed");
228 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
229 }
230
231 if (!reply.WriteInt32(result)) {
232 NETMGR_LOG_E("Write int32 reply failed");
233 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
234 }
235 return NETMANAGER_SUCCESS;
236 }
237
OnIsUidNetAllowedIfaceName(MessageParcel & data,MessageParcel & reply)238 int32_t NetPolicyServiceStub::OnIsUidNetAllowedIfaceName(MessageParcel &data, MessageParcel &reply)
239 {
240 uint32_t uid = 0;
241 std::string ifaceName;
242 if (!data.ReadUint32(uid)) {
243 NETMGR_LOG_E("Read uint32 data failed");
244 return NETMANAGER_ERR_READ_DATA_FAIL;
245 }
246
247 if (!data.ReadString(ifaceName)) {
248 NETMGR_LOG_E("Read String data failed");
249 return NETMANAGER_ERR_READ_DATA_FAIL;
250 }
251
252 bool isAllowed = false;
253 int32_t result = IsUidNetAllowed(uid, ifaceName, isAllowed);
254
255 if (!reply.WriteBool(isAllowed)) {
256 NETMGR_LOG_E("Write Bool reply failed");
257 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
258 }
259
260 if (!reply.WriteInt32(result)) {
261 NETMGR_LOG_E("Write int32 reply failed");
262 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
263 }
264 return NETMANAGER_SUCCESS;
265 }
266
OnRegisterNetPolicyCallback(MessageParcel & data,MessageParcel & reply)267 int32_t NetPolicyServiceStub::OnRegisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply)
268 {
269 sptr<IRemoteObject> remote = data.ReadRemoteObject();
270 if (remote == nullptr) {
271 NETMGR_LOG_E("Callback ptr is nullptr.");
272 reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL);
273 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
274 }
275
276 sptr<INetPolicyCallback> callback = iface_cast<INetPolicyCallback>(remote);
277 int32_t result = RegisterNetPolicyCallback(callback);
278 if (!reply.WriteInt32(result)) {
279 NETMGR_LOG_E("Write int32 reply failed");
280 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
281 }
282
283 return NETMANAGER_SUCCESS;
284 }
285
OnUnregisterNetPolicyCallback(MessageParcel & data,MessageParcel & reply)286 int32_t NetPolicyServiceStub::OnUnregisterNetPolicyCallback(MessageParcel &data, MessageParcel &reply)
287 {
288 sptr<IRemoteObject> remote = data.ReadRemoteObject();
289 if (remote == nullptr) {
290 NETMGR_LOG_E("callback ptr is nullptr.");
291 reply.WriteInt32(NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL);
292 return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL;
293 }
294 sptr<INetPolicyCallback> callback = iface_cast<INetPolicyCallback>(remote);
295 int32_t result = UnregisterNetPolicyCallback(callback);
296 if (!reply.WriteInt32(result)) {
297 NETMGR_LOG_E("Write int32 reply failed");
298 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
299 }
300
301 return NETMANAGER_SUCCESS;
302 }
303
OnSetNetQuotaPolicies(MessageParcel & data,MessageParcel & reply)304 int32_t NetPolicyServiceStub::OnSetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply)
305 {
306 std::vector<NetQuotaPolicy> quotaPolicies;
307 if (!NetQuotaPolicy::Unmarshalling(data, quotaPolicies)) {
308 NETMGR_LOG_E("Unmarshalling failed.");
309 return NETMANAGER_ERR_READ_DATA_FAIL;
310 }
311
312 int32_t result = SetNetQuotaPolicies(quotaPolicies);
313 if (!reply.WriteInt32(result)) {
314 NETMGR_LOG_E("Write int32 reply failed");
315 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
316 }
317
318 return NETMANAGER_SUCCESS;
319 }
320
OnGetNetQuotaPolicies(MessageParcel & data,MessageParcel & reply)321 int32_t NetPolicyServiceStub::OnGetNetQuotaPolicies(MessageParcel &data, MessageParcel &reply)
322 {
323 std::vector<NetQuotaPolicy> quotaPolicies;
324
325 int32_t result = GetNetQuotaPolicies(quotaPolicies);
326
327 if (!NetQuotaPolicy::Marshalling(reply, quotaPolicies)) {
328 NETMGR_LOG_E("Marshalling failed");
329 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
330 }
331
332 if (!reply.WriteInt32(result)) {
333 NETMGR_LOG_E("Write int32 reply failed");
334 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
335 }
336
337 return NETMANAGER_SUCCESS;
338 }
339
OnResetPolicies(MessageParcel & data,MessageParcel & reply)340 int32_t NetPolicyServiceStub::OnResetPolicies(MessageParcel &data, MessageParcel &reply)
341 {
342 std::string subscriberId;
343 if (!data.ReadString(subscriberId)) {
344 NETMGR_LOG_E("Read String data failed");
345 return NETMANAGER_ERR_READ_DATA_FAIL;
346 }
347
348 int32_t result = ResetPolicies(subscriberId);
349 if (!reply.WriteInt32(result)) {
350 NETMGR_LOG_E("Write int32 reply failed");
351 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
352 }
353
354 return NETMANAGER_SUCCESS;
355 }
356
OnSetBackgroundPolicy(MessageParcel & data,MessageParcel & reply)357 int32_t NetPolicyServiceStub::OnSetBackgroundPolicy(MessageParcel &data, MessageParcel &reply)
358 {
359 bool isBackgroundPolicyAllow = false;
360 if (!data.ReadBool(isBackgroundPolicyAllow)) {
361 NETMGR_LOG_E("Read Bool data failed");
362 return NETMANAGER_ERR_READ_DATA_FAIL;
363 }
364
365 int32_t result = SetBackgroundPolicy(isBackgroundPolicyAllow);
366 if (!reply.WriteInt32(result)) {
367 NETMGR_LOG_E("Write int32 reply failed");
368 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
369 }
370
371 return NETMANAGER_SUCCESS;
372 }
373
OnGetBackgroundPolicy(MessageParcel & data,MessageParcel & reply)374 int32_t NetPolicyServiceStub::OnGetBackgroundPolicy(MessageParcel &data, MessageParcel &reply)
375 {
376 bool backgroundPolicy = false;
377 int32_t result = GetBackgroundPolicy(backgroundPolicy);
378
379 if (!reply.WriteBool(backgroundPolicy)) {
380 NETMGR_LOG_E("Write Bool reply failed");
381 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
382 }
383
384 if (!reply.WriteInt32(result)) {
385 NETMGR_LOG_E("Write int32 reply failed");
386 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
387 }
388
389 return NETMANAGER_SUCCESS;
390 }
391
OnGetBackgroundPolicyByUid(MessageParcel & data,MessageParcel & reply)392 int32_t NetPolicyServiceStub::OnGetBackgroundPolicyByUid(MessageParcel &data, MessageParcel &reply)
393 {
394 uint32_t uid = 0;
395 if (!data.ReadUint32(uid)) {
396 NETMGR_LOG_E("Read uint32 data failed");
397 return NETMANAGER_ERR_READ_DATA_FAIL;
398 }
399
400 uint32_t backgroundPolicyOfUid = 0;
401 int32_t result = GetBackgroundPolicyByUid(uid, backgroundPolicyOfUid);
402
403 if (!reply.WriteUint32(backgroundPolicyOfUid)) {
404 NETMGR_LOG_E("Write uint32 reply failed");
405 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
406 }
407
408 if (!reply.WriteInt32(result)) {
409 NETMGR_LOG_E("Write int32 reply failed");
410 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
411 }
412
413 return NETMANAGER_SUCCESS;
414 }
415
OnSnoozePolicy(MessageParcel & data,MessageParcel & reply)416 int32_t NetPolicyServiceStub::OnSnoozePolicy(MessageParcel &data, MessageParcel &reply)
417 {
418 int32_t netType = 0;
419 if (!data.ReadInt32(netType)) {
420 NETMGR_LOG_E("Read int32 data failed");
421 return NETMANAGER_ERR_READ_DATA_FAIL;
422 }
423
424 std::string iccid;
425 if (!data.ReadString(iccid)) {
426 NETMGR_LOG_E("Read String data failed");
427 return NETMANAGER_ERR_READ_DATA_FAIL;
428 }
429
430 uint32_t remindType = 0;
431 if (!data.ReadUint32(remindType)) {
432 NETMGR_LOG_E("Read uint32 data failed");
433 return NETMANAGER_ERR_READ_DATA_FAIL;
434 }
435
436 int32_t result = UpdateRemindPolicy(netType, iccid, remindType);
437 if (!reply.WriteInt32(result)) {
438 NETMGR_LOG_E("Write int32 reply failed");
439 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
440 }
441
442 return NETMANAGER_SUCCESS;
443 }
444
OnSetDeviceIdleAllowedList(MessageParcel & data,MessageParcel & reply)445 int32_t NetPolicyServiceStub::OnSetDeviceIdleAllowedList(MessageParcel &data, MessageParcel &reply)
446 {
447 uint32_t uid;
448 if (!data.ReadUint32(uid)) {
449 NETMGR_LOG_E("Read uint32 data failed");
450 return NETMANAGER_ERR_READ_DATA_FAIL;
451 }
452
453 bool isAllowed = false;
454 if (!data.ReadBool(isAllowed)) {
455 NETMGR_LOG_E("Read Bool data failed");
456 return NETMANAGER_ERR_READ_DATA_FAIL;
457 }
458
459 int32_t result = SetDeviceIdleAllowedList(uid, isAllowed);
460 if (!reply.WriteInt32(result)) {
461 NETMGR_LOG_E("Write int32 reply failed");
462 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
463 }
464
465 return NETMANAGER_SUCCESS;
466 }
467
OnGetDeviceIdleAllowedList(MessageParcel & data,MessageParcel & reply)468 int32_t NetPolicyServiceStub::OnGetDeviceIdleAllowedList(MessageParcel &data, MessageParcel &reply)
469 {
470 std::vector<uint32_t> uids;
471 int32_t result = GetDeviceIdleAllowedList(uids);
472
473 if (!reply.WriteUInt32Vector(uids)) {
474 NETMGR_LOG_E("Write uint32 vector reply failed");
475 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
476 }
477
478 if (!reply.WriteInt32(result)) {
479 NETMGR_LOG_E("Write int32 reply failed");
480 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
481 }
482
483 return NETMANAGER_SUCCESS;
484 }
485
OnSetDeviceIdlePolicy(MessageParcel & data,MessageParcel & reply)486 int32_t NetPolicyServiceStub::OnSetDeviceIdlePolicy(MessageParcel &data, MessageParcel &reply)
487 {
488 bool isAllowed = false;
489 if (!data.ReadBool(isAllowed)) {
490 NETMGR_LOG_E("Read Bool data failed");
491 return NETMANAGER_ERR_READ_DATA_FAIL;
492 }
493
494 int32_t result = SetDeviceIdlePolicy(isAllowed);
495 if (!reply.WriteInt32(result)) {
496 NETMGR_LOG_E("Write int32 reply failed");
497 return NETMANAGER_ERR_WRITE_REPLY_FAIL;
498 }
499
500 return NETMANAGER_SUCCESS;
501 }
502 } // namespace NetManagerStandard
503 } // namespace OHOS
504