1 /*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "net_stats_service_proxy.h"
17
18 #include "net_manager_constants.h"
19 #include "net_mgr_log_wrapper.h"
20 #include "net_stats_constants.h"
21
22 namespace OHOS {
23 namespace NetManagerStandard {
NetStatsServiceProxy(const sptr<IRemoteObject> & impl)24 NetStatsServiceProxy::NetStatsServiceProxy(const sptr<IRemoteObject> &impl) : IRemoteProxy<INetStatsService>(impl) {}
25
26 NetStatsServiceProxy::~NetStatsServiceProxy() = default;
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply)27 int32_t NetStatsServiceProxy::SendRequest(uint32_t code, MessageParcel &data,
28 MessageParcel &reply)
29 {
30 sptr<IRemoteObject> remote = Remote();
31 if (remote == nullptr) {
32 NETMGR_LOG_E("Remote is null");
33 return NETMANAGER_ERR_OPERATION_FAILED;
34 }
35
36 MessageOption option;
37 int32_t retCode = remote->SendRequest(code, data, reply, option);
38 if (retCode != NETMANAGER_SUCCESS) {
39 return NETMANAGER_ERR_OPERATION_FAILED;
40 }
41 int32_t ret = NETMANAGER_SUCCESS;
42 if (!reply.ReadInt32(ret)) {
43 return NETMANAGER_ERR_READ_REPLY_FAIL;
44 }
45 NETMGR_LOG_D("SendRequest ret = [%{public}d]", ret);
46 return ret;
47 }
48
WriteInterfaceToken(MessageParcel & data)49 bool NetStatsServiceProxy::WriteInterfaceToken(MessageParcel &data)
50 {
51 if (!data.WriteInterfaceToken(NetStatsServiceProxy::GetDescriptor())) {
52 NETMGR_LOG_E("WriteInterfaceToken failed");
53 return false;
54 }
55 return true;
56 }
57
RegisterNetStatsCallback(const sptr<INetStatsCallback> & callback)58 int32_t NetStatsServiceProxy::RegisterNetStatsCallback(const sptr<INetStatsCallback> &callback)
59 {
60 if (callback == nullptr) {
61 NETMGR_LOG_E("The parameter of callback is nullptr");
62 return NETMANAGER_ERR_PARAMETER_ERROR;
63 }
64
65 MessageParcel dataParcel;
66 if (!WriteInterfaceToken(dataParcel)) {
67 NETMGR_LOG_E("WriteInterfaceToken failed");
68 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
69 }
70 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
71
72 MessageParcel replyParcel;
73 return SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_REGISTER_NET_STATS_CALLBACK),
74 dataParcel, replyParcel);
75 }
76
UnregisterNetStatsCallback(const sptr<INetStatsCallback> & callback)77 int32_t NetStatsServiceProxy::UnregisterNetStatsCallback(const sptr<INetStatsCallback> &callback)
78 {
79 if (callback == nullptr) {
80 NETMGR_LOG_E("The parameter of callback is nullptr");
81 return NETMANAGER_ERR_PARAMETER_ERROR;
82 }
83
84 MessageParcel dataParcel;
85 if (!WriteInterfaceToken(dataParcel)) {
86 NETMGR_LOG_E("WriteInterfaceToken failed");
87 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
88 }
89 dataParcel.WriteRemoteObject(callback->AsObject().GetRefPtr());
90
91 MessageParcel replyParcel;
92 return SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_UNREGISTER_NET_STATS_CALLBACK),
93 dataParcel, replyParcel);
94 }
95
GetIfaceRxBytes(uint64_t & stats,const std::string & interfaceName)96 int32_t NetStatsServiceProxy::GetIfaceRxBytes(uint64_t &stats, const std::string &interfaceName)
97 {
98 MessageParcel data;
99 if (!WriteInterfaceToken(data)) {
100 NETMGR_LOG_E("WriteInterfaceToken failed");
101 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
102 }
103 if (!data.WriteString(interfaceName)) {
104 NETMGR_LOG_E("WriteString failed");
105 return NETMANAGER_ERR_WRITE_DATA_FAIL;
106 }
107
108 MessageParcel reply;
109 int32_t error =
110 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_IFACE_RXBYTES), data, reply);
111 if (error != 0) {
112 if (error != STATS_ERR_READ_BPF_FAIL) {
113 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
114 }
115 return error;
116 }
117 if (!reply.ReadUint64(stats)) {
118 NETMGR_LOG_E("ReadUint64 failed");
119 return NETMANAGER_ERR_READ_REPLY_FAIL;
120 }
121 return error;
122 }
123
GetIfaceTxBytes(uint64_t & stats,const std::string & interfaceName)124 int32_t NetStatsServiceProxy::GetIfaceTxBytes(uint64_t &stats, const std::string &interfaceName)
125 {
126 MessageParcel data;
127 if (!WriteInterfaceToken(data)) {
128 NETMGR_LOG_E("WriteInterfaceToken failed");
129 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
130 }
131 if (!data.WriteString(interfaceName)) {
132 NETMGR_LOG_E("WriteString failed");
133 return NETMANAGER_ERR_WRITE_DATA_FAIL;
134 }
135
136 MessageParcel reply;
137 int32_t error =
138 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_IFACE_TXBYTES), data, reply);
139 if (error != 0) {
140 if (error != STATS_ERR_READ_BPF_FAIL) {
141 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
142 }
143 return error;
144 }
145 if (!reply.ReadUint64(stats)) {
146 NETMGR_LOG_E("ReadUint64 failed");
147 return NETMANAGER_ERR_READ_REPLY_FAIL;
148 }
149 return error;
150 }
151
GetCellularRxBytes(uint64_t & stats)152 int32_t NetStatsServiceProxy::GetCellularRxBytes(uint64_t &stats)
153 {
154 MessageParcel data;
155 if (!WriteInterfaceToken(data)) {
156 NETMGR_LOG_E("WriteInterfaceToken failed");
157 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
158 }
159
160 MessageParcel reply;
161 int32_t error =
162 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_CELLULAR_RXBYTES), data, reply);
163 if (error != 0) {
164 if (error != STATS_ERR_GET_IFACE_NAME_FAILED) {
165 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
166 }
167 return error;
168 }
169 if (!reply.ReadUint64(stats)) {
170 NETMGR_LOG_E("ReadUint64 failed");
171 return NETMANAGER_ERR_READ_REPLY_FAIL;
172 }
173 return error;
174 }
175
GetCellularTxBytes(uint64_t & stats)176 int32_t NetStatsServiceProxy::GetCellularTxBytes(uint64_t &stats)
177 {
178 MessageParcel data;
179 if (!WriteInterfaceToken(data)) {
180 NETMGR_LOG_E("WriteInterfaceToken failed");
181 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
182 }
183
184 MessageParcel reply;
185 int32_t error =
186 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_CELLULAR_TXBYTES), data, reply);
187 if (error != 0) {
188 if (error != STATS_ERR_GET_IFACE_NAME_FAILED) {
189 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
190 }
191 return error;
192 }
193 if (!reply.ReadUint64(stats)) {
194 NETMGR_LOG_E("ReadUint64 failed");
195 return NETMANAGER_ERR_READ_REPLY_FAIL;
196 }
197 return error;
198 }
199
GetAllRxBytes(uint64_t & stats)200 int32_t NetStatsServiceProxy::GetAllRxBytes(uint64_t &stats)
201 {
202 MessageParcel data;
203 if (!WriteInterfaceToken(data)) {
204 NETMGR_LOG_E("WriteInterfaceToken failed");
205 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
206 }
207
208 MessageParcel reply;
209 int32_t error =
210 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_RXBYTES), data, reply);
211 if (error != 0) {
212 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
213 return error;
214 }
215 if (!reply.ReadUint64(stats)) {
216 NETMGR_LOG_E("ReadUint64 failed");
217 return NETMANAGER_ERR_READ_REPLY_FAIL;
218 }
219 return error;
220 }
221
GetAllTxBytes(uint64_t & stats)222 int32_t NetStatsServiceProxy::GetAllTxBytes(uint64_t &stats)
223 {
224 MessageParcel data;
225 if (!WriteInterfaceToken(data)) {
226 NETMGR_LOG_E("WriteInterfaceToken failed");
227 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
228 }
229
230 MessageParcel reply;
231 MessageOption option;
232 int32_t error =
233 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_TXBYTES), data, reply);
234 if (error != 0) {
235 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
236 return error;
237 }
238 if (!reply.ReadUint64(stats)) {
239 NETMGR_LOG_E("ReadUint64 failed");
240 return NETMANAGER_ERR_READ_REPLY_FAIL;
241 }
242 return error;
243 }
244
GetUidRxBytes(uint64_t & stats,uint32_t uid)245 int32_t NetStatsServiceProxy::GetUidRxBytes(uint64_t &stats, uint32_t uid)
246 {
247 MessageParcel data;
248 if (!WriteInterfaceToken(data)) {
249 NETMGR_LOG_E("WriteInterfaceToken failed");
250 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
251 }
252 if (!data.WriteUint32(uid)) {
253 NETMGR_LOG_E("proxy uid%{public}d", uid);
254 return NETMANAGER_ERR_WRITE_DATA_FAIL;
255 }
256
257 MessageParcel reply;
258 int32_t error =
259 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_UID_RXBYTES), data, reply);
260 if (error != 0) {
261 if (error != STATS_ERR_READ_BPF_FAIL) {
262 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
263 }
264 return error;
265 }
266 if (!reply.ReadUint64(stats)) {
267 NETMGR_LOG_E("ReadUint64 failed");
268 return NETMANAGER_ERR_READ_REPLY_FAIL;
269 }
270 return error;
271 }
272
GetUidTxBytes(uint64_t & stats,uint32_t uid)273 int32_t NetStatsServiceProxy::GetUidTxBytes(uint64_t &stats, uint32_t uid)
274 {
275 MessageParcel data;
276 if (!WriteInterfaceToken(data)) {
277 NETMGR_LOG_E("WriteInterfaceToken failed");
278 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
279 }
280 if (!data.WriteUint32(uid)) {
281 NETMGR_LOG_E("proxy uid%{public}d", uid);
282 return NETMANAGER_ERR_WRITE_DATA_FAIL;
283 }
284
285 MessageParcel reply;
286 int32_t error =
287 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_UID_TXBYTES), data, reply);
288 if (error != 0) {
289 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
290 return error;
291 }
292 if (!reply.ReadUint64(stats)) {
293 NETMGR_LOG_E("ReadUint64 failed");
294 return NETMANAGER_ERR_READ_REPLY_FAIL;
295 }
296 return error;
297 }
298
GetIfaceStatsDetail(const std::string & iface,uint64_t start,uint64_t end,NetStatsInfo & statsInfo)299 int32_t NetStatsServiceProxy::GetIfaceStatsDetail(const std::string &iface, uint64_t start, uint64_t end,
300 NetStatsInfo &statsInfo)
301 {
302 MessageParcel data;
303 if (!WriteInterfaceToken(data)) {
304 NETMGR_LOG_E("WriteInterfaceToken failed");
305 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
306 }
307 if (!(data.WriteString(iface) && data.WriteUint64(start) && data.WriteUint64(end))) {
308 NETMGR_LOG_E("Write data failed");
309 return NETMANAGER_ERR_WRITE_DATA_FAIL;
310 }
311
312 MessageParcel reply;
313 int32_t sendResult =
314 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_IFACE_STATS_DETAIL), data, reply);
315 if (sendResult != 0) {
316 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", sendResult);
317 return sendResult;
318 }
319 if (!NetStatsInfo::Unmarshalling(reply, statsInfo)) {
320 return NETMANAGER_ERR_READ_REPLY_FAIL;
321 }
322 return sendResult;
323 }
324
GetUidStatsDetail(const std::string & iface,uint32_t uid,uint64_t start,uint64_t end,NetStatsInfo & statsInfo)325 int32_t NetStatsServiceProxy::GetUidStatsDetail(const std::string &iface, uint32_t uid, uint64_t start, uint64_t end,
326 NetStatsInfo &statsInfo)
327 {
328 MessageParcel data;
329 if (!WriteInterfaceToken(data)) {
330 NETMGR_LOG_E("WriteInterfaceToken failed");
331 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
332 }
333 if (!(data.WriteString(iface) && data.WriteUint32(uid) && data.WriteUint64(start) && data.WriteUint64(end))) {
334 NETMGR_LOG_E("Write data failed");
335 return NETMANAGER_ERR_WRITE_DATA_FAIL;
336 }
337
338 MessageParcel reply;
339 int32_t sendResult =
340 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_UID_STATS_DETAIL), data, reply);
341 if (sendResult != 0) {
342 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", sendResult);
343 return sendResult;
344 }
345 if (!NetStatsInfo::Unmarshalling(reply, statsInfo)) {
346 return NETMANAGER_ERR_READ_REPLY_FAIL;
347 }
348 return sendResult;
349 }
350
UpdateIfacesStats(const std::string & iface,uint64_t start,uint64_t end,const NetStatsInfo & stats)351 int32_t NetStatsServiceProxy::UpdateIfacesStats(const std::string &iface, uint64_t start, uint64_t end,
352 const NetStatsInfo &stats)
353 {
354 MessageParcel data;
355 if (!WriteInterfaceToken(data)) {
356 NETMGR_LOG_E("WriteInterfaceToken failed");
357 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
358 }
359 if (!(data.WriteString(iface) && data.WriteUint64(start) && data.WriteUint64(end))) {
360 NETMGR_LOG_E("Write data failed");
361 return NETMANAGER_ERR_WRITE_DATA_FAIL;
362 }
363 if (!stats.Marshalling(data)) {
364 return NETMANAGER_ERR_WRITE_DATA_FAIL;
365 }
366
367 MessageParcel reply;
368 return SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_UPDATE_IFACES_STATS), data, reply);
369 }
370
UpdateStatsData()371 int32_t NetStatsServiceProxy::UpdateStatsData()
372 {
373 MessageParcel data;
374 if (!WriteInterfaceToken(data)) {
375 NETMGR_LOG_E("WriteInterfaceToken failed");
376 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
377 }
378
379 MessageParcel reply;
380 return SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_UPDATE_STATS_DATA), data, reply);
381 }
382
ResetFactory()383 int32_t NetStatsServiceProxy::ResetFactory()
384 {
385 MessageParcel data;
386 if (!WriteInterfaceToken(data)) {
387 NETMGR_LOG_E("WriteInterfaceToken failed");
388 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
389 }
390
391 MessageParcel reply;
392 return SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_NSM_RESET_FACTORY), data, reply);
393 }
394
GetAllStatsInfo(std::vector<NetStatsInfo> & infos)395 int32_t NetStatsServiceProxy::GetAllStatsInfo(std::vector<NetStatsInfo> &infos)
396 {
397 MessageParcel data;
398 if (!WriteInterfaceToken(data)) {
399 NETMGR_LOG_E("WriteInterfaceToken failed");
400 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
401 }
402
403 MessageParcel reply;
404 int32_t result =
405 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_STATS_INFO), data, reply);
406 if (result != ERR_NONE) {
407 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", result);
408 return result;
409 }
410 if (!NetStatsInfo::Unmarshalling(reply, infos)) {
411 NETMGR_LOG_E("Read stats info failed");
412 return NETMANAGER_ERR_READ_REPLY_FAIL;
413 }
414 return result;
415 }
416
GetAllSimStatsInfo(std::vector<NetStatsInfo> & infos)417 int32_t NetStatsServiceProxy::GetAllSimStatsInfo(std::vector<NetStatsInfo> &infos)
418 {
419 MessageParcel data;
420 if (!WriteInterfaceToken(data)) {
421 NETMGR_LOG_E("WriteInterfaceToken failed");
422 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
423 }
424
425 MessageParcel reply;
426 int32_t result =
427 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_ALL_SIM_STATS_INFO), data, reply);
428 if (result != ERR_NONE) {
429 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", result);
430 return result;
431 }
432 if (!NetStatsInfo::Unmarshalling(reply, infos)) {
433 NETMGR_LOG_E("Read stats info failed");
434 return NETMANAGER_ERR_READ_REPLY_FAIL;
435 }
436 return result;
437 }
438
GetTrafficStatsByNetwork(std::unordered_map<uint32_t,NetStatsInfo> & infos,const sptr<NetStatsNetwork> & network)439 int32_t NetStatsServiceProxy::GetTrafficStatsByNetwork(std::unordered_map<uint32_t, NetStatsInfo> &infos,
440 const sptr<NetStatsNetwork> &network)
441 {
442 MessageParcel data;
443 if (!WriteInterfaceToken(data)) {
444 NETMGR_LOG_E("WriteInterfaceToken failed");
445 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
446 }
447 if (network == nullptr) {
448 NETMGR_LOG_E("network is nullptr");
449 return NETMANAGER_ERR_INVALID_PARAMETER;
450 }
451 if (!network->Marshalling(data)) {
452 NETMGR_LOG_E("proxy Marshalling failed");
453 return NETMANAGER_ERR_WRITE_DATA_FAIL;
454 }
455 NETMGR_LOG_D("proxy sptr<NetStatsNetwork> Marshalling success");
456 MessageParcel reply;
457 int32_t result =
458 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_TRAFFIC_STATS_BY_NETWORK), data, reply);
459 if (result != ERR_NONE) {
460 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", result);
461 return result;
462 }
463 if (!NetStatsInfo::Unmarshalling(reply, infos)) {
464 NETMGR_LOG_E("Read stats info failed");
465 return NETMANAGER_ERR_READ_REPLY_FAIL;
466 }
467 return result;
468 }
469
GetTrafficStatsByUidNetwork(std::vector<NetStatsInfoSequence> & infos,uint32_t uid,const sptr<NetStatsNetwork> & network)470 int32_t NetStatsServiceProxy::GetTrafficStatsByUidNetwork(std::vector<NetStatsInfoSequence> &infos, uint32_t uid,
471 const sptr<NetStatsNetwork> &network)
472 {
473 MessageParcel data;
474 if (!WriteInterfaceToken(data)) {
475 NETMGR_LOG_E("WriteInterfaceToken failed");
476 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
477 }
478 if (network == nullptr) {
479 NETMGR_LOG_E("network is nullptr");
480 return NETMANAGER_ERR_INVALID_PARAMETER;
481 }
482 if (!data.WriteUint32(uid)) {
483 NETMGR_LOG_E("WriteUint32 uid failed");
484 return NETMANAGER_ERR_WRITE_DATA_FAIL;
485 }
486 if (!network->Marshalling(data)) {
487 NETMGR_LOG_E("sptr<NetStatsNetwork> Marshalling failed");
488 return NETMANAGER_ERR_WRITE_DATA_FAIL;
489 }
490 NETMGR_LOG_D("proxy sptr<NetStatsNetwork> Marshalling success");
491 MessageParcel reply;
492 int32_t ret =
493 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_TRAFFIC_STATS_BY_UID_NETWORK), data, reply);
494 if (ret != ERR_NONE) {
495 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", ret);
496 return ret;
497 }
498 if (!NetStatsInfoSequence::Unmarshalling(reply, infos)) {
499 NETMGR_LOG_E("Read stats info failed");
500 return NETMANAGER_ERR_READ_REPLY_FAIL;
501 }
502 return ret;
503 }
504
SetAppStats(const PushStatsInfo & info)505 int32_t NetStatsServiceProxy::SetAppStats(const PushStatsInfo &info)
506 {
507 MessageParcel data;
508 if (!WriteInterfaceToken(data)) {
509 NETMGR_LOG_E("WriteInterfaceToken failed");
510 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
511 }
512 if (!info.Marshalling(data)) {
513 NETMGR_LOG_E("pushStatsInfo marshalling failed");
514 return NETMANAGER_ERR_WRITE_DATA_FAIL;
515 }
516 NETMGR_LOG_D("PushStatsInfo Marshalling success");
517 MessageParcel reply;
518 int32_t ret = SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_SET_APP_STATS), data, reply);
519 if (ret != ERR_NONE) {
520 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", ret);
521 return ret;
522 }
523 return ret;
524 }
525
GetCookieRxBytes(uint64_t & stats,uint64_t cookie)526 int32_t NetStatsServiceProxy::GetCookieRxBytes(uint64_t &stats, uint64_t cookie)
527 {
528 MessageParcel data;
529 if (!WriteInterfaceToken(data)) {
530 NETMGR_LOG_E("WriteInterfaceToken failed");
531 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
532 }
533 if (!data.WriteUint64(cookie)) {
534 NETMGR_LOG_E("proxy cookie write failed.");
535 return NETMANAGER_ERR_WRITE_DATA_FAIL;
536 }
537
538 MessageParcel reply;
539 int32_t error =
540 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_COOKIE_RXBYTES), data, reply);
541 if (error != 0) {
542 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
543 return error;
544 }
545 if (!reply.ReadUint64(stats)) {
546 NETMGR_LOG_E("ReadUint64 failed");
547 return NETMANAGER_ERR_READ_REPLY_FAIL;
548 }
549 return error;
550 }
551
GetCookieTxBytes(uint64_t & stats,uint64_t cookie)552 int32_t NetStatsServiceProxy::GetCookieTxBytes(uint64_t &stats, uint64_t cookie)
553 {
554 MessageParcel data;
555 if (!WriteInterfaceToken(data)) {
556 NETMGR_LOG_E("WriteInterfaceToken failed");
557 return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL;
558 }
559 if (!data.WriteUint64(cookie)) {
560 NETMGR_LOG_E("proxy cookie write failed.");
561 return NETMANAGER_ERR_WRITE_DATA_FAIL;
562 }
563
564 MessageParcel reply;
565 int32_t error =
566 SendRequest(static_cast<uint32_t>(StatsInterfaceCode::CMD_GET_COOKIE_TXBYTES), data, reply);
567 if (error != 0) {
568 NETMGR_LOG_E("proxy SendRequest failed, error code: [%{public}d]", error);
569 return error;
570 }
571 if (!reply.ReadUint64(stats)) {
572 NETMGR_LOG_E("ReadUint64 failed");
573 return NETMANAGER_ERR_READ_REPLY_FAIL;
574 }
575 return error;
576 }
577 } // namespace NetManagerStandard
578 } // namespace OHOS
579