1/* 2 * Copyright (C) 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/** 17 * @file 18 * @kit NetworkKit 19 */ 20 21import type { AsyncCallback, Callback } from './@ohos.base'; 22import type connection from './@ohos.net.connection'; 23 24/** 25 * Obtains traffic statistics. 26 * @namespace statistics 27 * @syscap SystemCapability.Communication.NetManager.Core 28 * @since 10 29 */ 30declare namespace statistics { 31 /** 32 * @typedef {connection.NetBearType} 33 * @syscap SystemCapability.Communication.NetManager.Core 34 * @since 12 35 */ 36 type NetBearType = connection.NetBearType; 37 38 /** 39 * Queries the data traffic (including all TCP and UDP data packets) received through a specified NIC. 40 * @param { string } nic - Network interface card. 41 * @param { AsyncCallback<number> } callback - Returns the data traffic received through the specified NIC. 42 * @throws { BusinessError } 401 - Parameter error. 43 * @throws { BusinessError } 2100002 - Failed to connect to the service. 44 * @throws { BusinessError } 2100003 - System internal error. 45 * @throws { BusinessError } 2103005 - Failed to read the system map. 46 * @throws { BusinessError } 2103011 - Failed to create a system map. 47 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 48 * @syscap SystemCapability.Communication.NetManager.Core 49 * @since 10 50 */ 51 function getIfaceRxBytes(nic: string, callback: AsyncCallback<number>): void; 52 53 /** 54 * Queries the data traffic (including all TCP and UDP data packets) received through a specified NIC. 55 * @param { string } nic - Network interface card. 56 * @returns { Promise<number> } The promise returned by the function. 57 * @throws { BusinessError } 401 - Parameter error. 58 * @throws { BusinessError } 2100002 - Failed to connect to the service. 59 * @throws { BusinessError } 2100003 - System internal error. 60 * @throws { BusinessError } 2103005 - Failed to read the system map. 61 * @throws { BusinessError } 2103011 - Failed to create a system map. 62 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 63 * @syscap SystemCapability.Communication.NetManager.Core 64 * @since 10 65 */ 66 function getIfaceRxBytes(nic: string): Promise<number>; 67 68 /** 69 * Queries the data traffic (including all TCP and UDP data packets) sent through a specified NIC. 70 * @param { string } nic - Network interface card. 71 * @param { AsyncCallback<number> } callback - Returns the data traffic sent through the specified NIC. 72 * @throws { BusinessError } 401 - Parameter error. 73 * @throws { BusinessError } 2100002 - Failed to connect to the service. 74 * @throws { BusinessError } 2100003 - System internal error. 75 * @throws { BusinessError } 2103005 - Failed to read the system map. 76 * @throws { BusinessError } 2103011 - Failed to create a system map. 77 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 78 * @syscap SystemCapability.Communication.NetManager.Core 79 * @since 10 80 */ 81 function getIfaceTxBytes(nic: string, callback: AsyncCallback<number>): void; 82 83 /** 84 * Queries the data traffic (including all TCP and UDP data packets) sent through a specified NIC. 85 * @param { string } nic - Network interface card. 86 * @returns { Promise<number> } The promise returned by the function. 87 * @throws { BusinessError } 401 - Parameter error. 88 * @throws { BusinessError } 2100002 - Failed to connect to the service. 89 * @throws { BusinessError } 2100003 - System internal error. 90 * @throws { BusinessError } 2103005 - Failed to read the system map. 91 * @throws { BusinessError } 2103011 - Failed to create a system map. 92 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 93 * @syscap SystemCapability.Communication.NetManager.Core 94 * @since 10 95 */ 96 function getIfaceTxBytes(nic: string): Promise<number>; 97 98 /** 99 * Queries the data traffic (including all TCP and UDP data packets) received through the cellular network. 100 * @param { AsyncCallback<number> } callback - Returns the data traffic received through the cellular network. 101 * @throws { BusinessError } 2100002 - Failed to connect to the service. 102 * @throws { BusinessError } 2100003 - System internal error. 103 * @throws { BusinessError } 2103005 - Failed to read the system map. 104 * @throws { BusinessError } 2103011 - Failed to create a system map. 105 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 106 * @syscap SystemCapability.Communication.NetManager.Core 107 * @since 10 108 */ 109 function getCellularRxBytes(callback: AsyncCallback<number>): void; 110 111 /** 112 * Queries the data traffic (including all TCP and UDP data packets) received through the cellular network. 113 * @returns { Promise<number> } The promise returned by the function. 114 * @throws { BusinessError } 2100002 - Failed to connect to the service. 115 * @throws { BusinessError } 2100003 - System internal error. 116 * @throws { BusinessError } 2103005 - Failed to read the system map. 117 * @throws { BusinessError } 2103011 - Failed to create a system map. 118 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 119 * @syscap SystemCapability.Communication.NetManager.Core 120 * @since 10 121 */ 122 function getCellularRxBytes(): Promise<number>; 123 124 /** 125 * Queries the data traffic (including all TCP and UDP data packets) sent through the cellular network. 126 * @param { AsyncCallback<number> } callback - Returns the data traffic sent through the cellular network. 127 * @throws { BusinessError } 2100002 - Failed to connect to the service. 128 * @throws { BusinessError } 2100003 - System internal error. 129 * @throws { BusinessError } 2103005 - Failed to read the system map. 130 * @throws { BusinessError } 2103011 - Failed to create a system map. 131 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 132 * @syscap SystemCapability.Communication.NetManager.Core 133 * @since 10 134 */ 135 function getCellularTxBytes(callback: AsyncCallback<number>): void; 136 137 /** 138 * Queries the data traffic (including all TCP and UDP data packets) sent through the cellular network. 139 * @returns { Promise<number> } The promise returned by the function. 140 * @throws { BusinessError } 2100002 - Failed to connect to the service. 141 * @throws { BusinessError } 2100003 - System internal error. 142 * @throws { BusinessError } 2103005 - Failed to read the system map. 143 * @throws { BusinessError } 2103011 - Failed to create a system map. 144 * @throws { BusinessError } 2103012 - Failed to obtain the NIC name. 145 * @syscap SystemCapability.Communication.NetManager.Core 146 * @since 10 147 */ 148 function getCellularTxBytes(): Promise<number>; 149 150 /** 151 * Queries the data traffic (including all TCP and UDP data packets) received through all NICs. 152 * @param { AsyncCallback<number> } callback - Returns the data traffic received through all NICs. 153 * @throws { BusinessError } 2100002 - Failed to connect to the service. 154 * @throws { BusinessError } 2100003 - System internal error. 155 * @throws { BusinessError } 2103005 - Failed to read the system map. 156 * @throws { BusinessError } 2103011 - Failed to create a system map. 157 * @syscap SystemCapability.Communication.NetManager.Core 158 * @since 10 159 */ 160 function getAllRxBytes(callback: AsyncCallback<number>): void; 161 162 /** 163 * Queries the data traffic (including all TCP and UDP data packets) received through all NICs. 164 * @returns { Promise<number> } The promise returned by the function. 165 * @throws { BusinessError } 2100002 - Failed to connect to the service. 166 * @throws { BusinessError } 2100003 - System internal error. 167 * @throws { BusinessError } 2103005 - Failed to read the system map. 168 * @throws { BusinessError } 2103011 - Failed to create a system map. 169 * @syscap SystemCapability.Communication.NetManager.Core 170 * @since 10 171 */ 172 function getAllRxBytes(): Promise<number>; 173 174 /** 175 * Queries the data traffic (including all TCP and UDP data packets) sent through all NICs. 176 * @param { AsyncCallback<number> } callback - Returns the data traffic sent through all NICs. 177 * @throws { BusinessError } 2100002 - Failed to connect to the service. 178 * @throws { BusinessError } 2100003 - System internal error. 179 * @throws { BusinessError } 2103005 - Failed to read the system map. 180 * @throws { BusinessError } 2103011 - Failed to create a system map. 181 * @syscap SystemCapability.Communication.NetManager.Core 182 * @since 10 183 */ 184 function getAllTxBytes(callback: AsyncCallback<number>): void; 185 186 /** 187 * Queries the data traffic (including all TCP and UDP data packets) sent through all NICs. 188 * @returns { Promise<number> } The promise returned by the function. 189 * @throws { BusinessError } 2100002 - Failed to connect to the service. 190 * @throws { BusinessError } 2100003 - System internal error. 191 * @throws { BusinessError } 2103005 - Failed to read the system map. 192 * @throws { BusinessError } 2103011 - Failed to create a system map. 193 * @syscap SystemCapability.Communication.NetManager.Core 194 * @since 10 195 */ 196 function getAllTxBytes(): Promise<number>; 197 198 /** 199 * Queries the data traffic (including all TCP and UDP data packets) received by a specified application. 200 * @param { number } uid - Indicates the process ID of the application. 201 * @param { AsyncCallback<number> } callback - Returns the data traffic received by the specified application. 202 * @throws { BusinessError } 401 - Parameter error. 203 * @throws { BusinessError } 2100002 - Failed to connect to the service. 204 * @throws { BusinessError } 2100003 - System internal error. 205 * @throws { BusinessError } 2103005 - Failed to read the system map. 206 * @throws { BusinessError } 2103011 - Failed to create a system map. 207 * @syscap SystemCapability.Communication.NetManager.Core 208 * @since 10 209 */ 210 function getUidRxBytes(uid: number, callback: AsyncCallback<number>): void; 211 212 /** 213 * Queries the data traffic (including all TCP and UDP data packets) received by a specified application. 214 * @param { number } uid - Indicates the process ID of the application. 215 * @returns { Promise<number> } The promise returned by the function. 216 * @throws { BusinessError } 401 - Parameter error. 217 * @throws { BusinessError } 2100002 - Failed to connect to the service. 218 * @throws { BusinessError } 2100003 - System internal error. 219 * @throws { BusinessError } 2103005 - Failed to read the system map. 220 * @throws { BusinessError } 2103011 - Failed to create a system map. 221 * @syscap SystemCapability.Communication.NetManager.Core 222 * @since 10 223 */ 224 function getUidRxBytes(uid: number): Promise<number>; 225 226 /** 227 * Queries the data traffic (including all TCP and UDP data packets) sent by a specified application. 228 * @param { number } uid - Indicates the process ID of the application. 229 * @param { AsyncCallback<number> } callback - Returns the data traffic sent by the specified application. 230 * @throws { BusinessError } 401 - Parameter error. 231 * @throws { BusinessError } 2100002 - Failed to connect to the service. 232 * @throws { BusinessError } 2100003 - System internal error. 233 * @throws { BusinessError } 2103005 - Failed to read the system map. 234 * @throws { BusinessError } 2103011 - Failed to create a system map. 235 * @syscap SystemCapability.Communication.NetManager.Core 236 * @since 10 237 */ 238 function getUidTxBytes(uid: number, callback: AsyncCallback<number>): void; 239 240 /** 241 * Queries the data traffic (including all TCP and UDP data packets) sent by a specified application. 242 * @param { number } uid - Indicates the process ID of the application. 243 * @returns { Promise<number> } The promise returned by the function. 244 * @throws { BusinessError } 401 - Parameter error. 245 * @throws { BusinessError } 2100002 - Failed to connect to the service. 246 * @throws { BusinessError } 2100003 - System internal error. 247 * @throws { BusinessError } 2103005 - Failed to read the system map. 248 * @throws { BusinessError } 2103011 - Failed to create a system map. 249 * @syscap SystemCapability.Communication.NetManager.Core 250 * @since 10 251 */ 252 function getUidTxBytes(uid: number): Promise<number>; 253 254 /** 255 * Register notifications of network traffic updates. 256 * @permission ohos.permission.GET_NETWORK_STATS 257 * @param { 'netStatsChange' } type - Indicates Event name. 258 * @param { Callback<{ iface: string, uid?: number }> } callback - The callback of on. 259 * @throws { BusinessError } 201 - Permission denied. 260 * @throws { BusinessError } 202 - Non-system applications use system APIs. 261 * @throws { BusinessError } 401 - Parameter error. 262 * @throws { BusinessError } 2100002 - Failed to connect to the service. 263 * @throws { BusinessError } 2100003 - System internal error. 264 * @syscap SystemCapability.Communication.NetManager.Core 265 * @systemapi Hide this for inner system use. 266 * @since 10 267 */ 268 /** 269 * Register notifications of network traffic updates. 270 * @permission ohos.permission.GET_NETWORK_STATS 271 * @param { 'netStatsChange' } type - Indicates Event name. 272 * @param { Callback<NetStatsChangeInfo> } callback - The callback of on. 273 * @throws { BusinessError } 201 - Permission denied. 274 * @throws { BusinessError } 202 - Non-system applications use system APIs. 275 * @throws { BusinessError } 401 - Parameter error. 276 * @throws { BusinessError } 2100002 - Failed to connect to the service. 277 * @throws { BusinessError } 2100003 - System internal error. 278 * @syscap SystemCapability.Communication.NetManager.Core 279 * @systemapi Hide this for inner system use. 280 * @since 11 281 */ 282 function on(type: 'netStatsChange', callback: Callback<NetStatsChangeInfo>): void; 283 284 /** 285 * Unregister notifications of network traffic updates. 286 * @permission ohos.permission.GET_NETWORK_STATS 287 * @param { 'netStatsChange' } type - Indicates Event name. 288 * @param { Callback<{ iface: string, uid?: number }> } callback - The callback of off. 289 * @throws { BusinessError } 201 - Permission denied. 290 * @throws { BusinessError } 202 - Non-system applications use system APIs. 291 * @throws { BusinessError } 401 - Parameter error. 292 * @throws { BusinessError } 2100002 - Failed to connect to the service. 293 * @throws { BusinessError } 2100003 - System internal error. 294 * @syscap SystemCapability.Communication.NetManager.Core 295 * @systemapi Hide this for inner system use. 296 * @since 10 297 */ 298 /** 299 * Unregister notifications of network traffic updates. 300 * @permission ohos.permission.GET_NETWORK_STATS 301 * @param { 'netStatsChange' } type - Indicates Event name. 302 * @param { Callback<NetStatsChangeInfo> } callback - The callback of off. 303 * @throws { BusinessError } 201 - Permission denied. 304 * @throws { BusinessError } 202 - Non-system applications use system APIs. 305 * @throws { BusinessError } 401 - Parameter error. 306 * @throws { BusinessError } 2100002 - Failed to connect to the service. 307 * @throws { BusinessError } 2100003 - System internal error. 308 * @syscap SystemCapability.Communication.NetManager.Core 309 * @systemapi Hide this for inner system use. 310 * @since 11 311 */ 312 function off(type: 'netStatsChange', callback?: Callback<NetStatsChangeInfo>): void; 313 314 /** 315 * Get the traffic usage details of the network interface in the specified time period. 316 * @permission ohos.permission.GET_NETWORK_STATS 317 * @param { IfaceInfo } ifaceInfo - Detailed query content. See {@link IfaceInfo}. 318 * @param { AsyncCallback<NetStatsInfo> } callback - Returns the {@link NetStatsInfo} object; 319 * @throws { BusinessError } 201 - Permission denied. 320 * @throws { BusinessError } 202 - Non-system applications use system APIs. 321 * @throws { BusinessError } 401 - Parameter error. 322 * @throws { BusinessError } 2100001 - Invalid parameter value. 323 * @throws { BusinessError } 2100002 - Failed to connect to the service. 324 * @throws { BusinessError } 2100003 - System internal error. 325 * @throws { BusinessError } 2103017 - Failed to read the database. 326 * @syscap SystemCapability.Communication.NetManager.Core 327 * @systemapi Hide this for inner system use. 328 * @since 10 329 */ 330 function getTrafficStatsByIface(ifaceInfo: IfaceInfo, callback: AsyncCallback<NetStatsInfo>): void; 331 332 /** 333 * Get the traffic usage details of the network interface in the specified time period. 334 * @permission ohos.permission.GET_NETWORK_STATS 335 * @param { IfaceInfo } ifaceInfo - Detailed query content. See {@link IfaceInfo}. 336 * @returns { Promise<NetStatsInfo> } The promise returned by the function. 337 * @throws { BusinessError } 201 - Permission denied. 338 * @throws { BusinessError } 202 - Non-system applications use system APIs. 339 * @throws { BusinessError } 401 - Parameter error. 340 * @throws { BusinessError } 2100001 - Invalid parameter value. 341 * @throws { BusinessError } 2100002 - Failed to connect to the service. 342 * @throws { BusinessError } 2100003 - System internal error. 343 * @throws { BusinessError } 2103017 - Failed to read the database. 344 * @syscap SystemCapability.Communication.NetManager.Core 345 * @systemapi Hide this for inner system use. 346 * @since 10 347 */ 348 function getTrafficStatsByIface(ifaceInfo: IfaceInfo): Promise<NetStatsInfo>; 349 350 /** 351 * Get the traffic usage details of the specified time period of the application. 352 * @permission ohos.permission.GET_NETWORK_STATS 353 * @param { UidInfo } uidInfo - Detailed query content. See {@link UidInfo}. 354 * @param { AsyncCallback<NetStatsInfo> } callback - Returns the {@link NetStatsInfo} object; 355 * @throws { BusinessError } 201 - Permission denied. 356 * @throws { BusinessError } 202 - Non-system applications use system APIs. 357 * @throws { BusinessError } 401 - Parameter error. 358 * @throws { BusinessError } 2100001 - Invalid parameter value. 359 * @throws { BusinessError } 2100002 - Failed to connect to the service. 360 * @throws { BusinessError } 2100003 - System internal error. 361 * @throws { BusinessError } 2103017 - Failed to read the database. 362 * @syscap SystemCapability.Communication.NetManager.Core 363 * @systemapi Hide this for inner system use. 364 * @since 10 365 */ 366 function getTrafficStatsByUid(uidInfo: UidInfo, callback: AsyncCallback<NetStatsInfo>): void; 367 368 /** 369 * Get the traffic usage details of the specified time period of the application. 370 * @permission ohos.permission.GET_NETWORK_STATS 371 * @param { UidInfo } uidInfo - Detailed query content. See {@link UidInfo}. 372 * @returns { Promise<NetStatsInfo> } The promise returned by the function. 373 * @throws { BusinessError } 201 - Permission denied. 374 * @throws { BusinessError } 202 - Non-system applications use system APIs. 375 * @throws { BusinessError } 401 - Parameter error. 376 * @throws { BusinessError } 2100001 - Invalid parameter value. 377 * @throws { BusinessError } 2100002 - Failed to connect to the service. 378 * @throws { BusinessError } 2100003 - System internal error. 379 * @throws { BusinessError } 2103017 - Failed to read the database. 380 * @syscap SystemCapability.Communication.NetManager.Core 381 * @systemapi Hide this for inner system use. 382 * @since 10 383 */ 384 function getTrafficStatsByUid(uidInfo: UidInfo): Promise<NetStatsInfo>; 385 386 /** 387 * Queries the data traffic (including all TCP and UDP data packets) received through a specified sockfd. 388 * @param { number } sockfd - Indicates the file descriptor of the given socket. 389 * @param { AsyncCallback<number> } callback - Returns the data traffic bytes received by the specified sockfd. 390 * @throws { BusinessError } 401 - Parameter error. 391 * @throws { BusinessError } 2100001 - Invalid parameter value. 392 * @throws { BusinessError } 2100002 - Failed to connect to the service. 393 * @throws { BusinessError } 2100003 - System internal error. 394 * @syscap SystemCapability.Communication.NetManager.Core 395 * @since 11 396 */ 397 function getSockfdRxBytes(sockfd: number, callback: AsyncCallback<number>): void; 398 399 /** 400 * Queries the data traffic (including all TCP and UDP data packets) received through a specified sockfd. 401 * @param { number } sockfd - Indicates the file descriptor of the given socket. 402 * @returns { Promise<number> } Returns the data traffic bytes received by the specified sockfd. 403 * @throws { BusinessError } 401 - Parameter error. 404 * @throws { BusinessError } 2100001 - Invalid parameter value. 405 * @throws { BusinessError } 2100002 - Failed to connect to the service. 406 * @throws { BusinessError } 2100003 - System internal error. 407 * @syscap SystemCapability.Communication.NetManager.Core 408 * @since 11 409 */ 410 function getSockfdRxBytes(sockfd: number): Promise<number>; 411 412 /** 413 * Queries the data traffic (including all TCP and UDP data packets) sent through a specified sockfd. 414 * @param { number } sockfd - Indicates the file descriptor of the given socket. 415 * @param { AsyncCallback<number> } callback - Returns the data traffic bytes sent by the specified sockfd. 416 * @throws { BusinessError } 401 - Parameter error. 417 * @throws { BusinessError } 2100001 - Invalid parameter value 418 * @throws { BusinessError } 2100002 - Failed to connect to the service. 419 * @throws { BusinessError } 2100003 - System internal error. 420 * @syscap SystemCapability.Communication.NetManager.Core 421 * @since 11 422 */ 423 function getSockfdTxBytes(sockfd: number, callback: AsyncCallback<number>): void; 424 425 /** 426 * Queries the data traffic (including all TCP and UDP data packets) sent through a specified sockfd. 427 * @param { number } sockfd - Indicates the file descriptor of the given socket. 428 * @returns { Promise<number> } Returns the data traffic bytes sent by the specified sockfd. 429 * @throws { BusinessError } 401 - Parameter error. 430 * @throws { BusinessError } 2100001 - Invalid parameter value 431 * @throws { BusinessError } 2100002 - Failed to connect to the service. 432 * @throws { BusinessError } 2100003 - System internal error. 433 * @syscap SystemCapability.Communication.NetManager.Core 434 * @since 11 435 */ 436 function getSockfdTxBytes(sockfd: number): Promise<number>; 437 438 /** 439 * Parameters for obtaining detailed information on network interface traffic usage. 440 * @interface IfaceInfo 441 * @syscap SystemCapability.Communication.NetManager.Core 442 * @systemapi Hide this for inner system use. 443 * @since 10 444 */ 445 export interface IfaceInfo { 446 /** 447 * Network interface for querying traffic. 448 * @type {string} 449 * @syscap SystemCapability.Communication.NetManager.Core 450 * @systemapi Hide this for inner system use. 451 * @since 10 452 */ 453 iface: string; 454 455 /** 456 * Start time for querying traffic. 457 * @type {number} 458 * @syscap SystemCapability.Communication.NetManager.Core 459 * @systemapi Hide this for inner system use. 460 * @since 10 461 */ 462 startTime: number; 463 464 /** 465 * End time for querying traffic. 466 * @type {number} 467 * @syscap SystemCapability.Communication.NetManager.Core 468 * @systemapi Hide this for inner system use. 469 * @since 10 470 */ 471 endTime: number; 472 } 473 474 /** 475 * Parameters for obtaining detailed information on application traffic usage. 476 * @interface UidInfo 477 * @syscap SystemCapability.Communication.NetManager.Core 478 * @systemapi Hide this for inner system use. 479 * @since 10 480 */ 481 export interface UidInfo { 482 /** 483 * See {@link IfaceInfo} 484 * @type {IfaceInfo} 485 * @syscap SystemCapability.Communication.NetManager.Core 486 * @systemapi Hide this for inner system use. 487 * @since 10 488 */ 489 ifaceInfo: IfaceInfo; 490 491 /** 492 * Uid of app for querying traffic. 493 * @type {number} 494 * @syscap SystemCapability.Communication.NetManager.Core 495 * @systemapi Hide this for inner system use. 496 * @since 10 497 */ 498 uid: number; 499 } 500 501 /** 502 * Detailed information of statistics. 503 * @interface NetStatsInfo 504 * @syscap SystemCapability.Communication.NetManager.Core 505 * @systemapi Hide this for inner system use. 506 * @since 10 507 */ 508 export interface NetStatsInfo { 509 /** 510 * Bytes of received. 511 * @type {number} 512 * @syscap SystemCapability.Communication.NetManager.Core 513 * @systemapi Hide this for inner system use. 514 * @since 10 515 */ 516 rxBytes: number; 517 518 /** 519 * Bytes of send. 520 * @type {number} 521 * @syscap SystemCapability.Communication.NetManager.Core 522 * @systemapi Hide this for inner system use. 523 * @since 10 524 */ 525 txBytes: number; 526 527 /** 528 * Packets of received. 529 * @type {number} 530 * @syscap SystemCapability.Communication.NetManager.Core 531 * @systemapi Hide this for inner system use. 532 * @since 10 533 */ 534 rxPackets: number; 535 536 /** 537 * Packets of send. 538 * @type {number} 539 * @syscap SystemCapability.Communication.NetManager.Core 540 * @systemapi Hide this for inner system use. 541 * @since 10 542 */ 543 txPackets: number; 544 } 545 546 /** 547 * Used to monitor and manage the status and usage of network interfaces. 548 * @interface NetStatsChangeInfo 549 * @syscap SystemCapability.Communication.NetManager.Core 550 * @systemapi Hide this for inner system use. 551 * @since 11 552 */ 553 export interface NetStatsChangeInfo { 554 /** 555 * Network interface for querying traffic. 556 * @type { string } 557 * @syscap SystemCapability.Communication.NetManager.Core 558 * @systemapi Hide this for inner system use. 559 * @since 11 560 */ 561 iface: string; 562 /** 563 * Network interface for querying traffic. 564 * @type { ?number } 565 * @syscap SystemCapability.Communication.NetManager.Core 566 * @systemapi Hide this for inner system use. 567 * @since 11 568 */ 569 uid?: number; 570 } 571 572 /** 573 * An {@link NetStatsInfo} array with start time and end time. 574 * @syscap SystemCapability.Communication.NetManager.Core 575 * @systemapi Hide this for inner system use. 576 * @since 12 577 */ 578 export type NetStatsInfoSequence = { 579 /** 580 * Start time for querying traffic. 581 * @type { number } 582 * @syscap SystemCapability.Communication.NetManager.Core 583 * @systemapi Hide this for inner system use. 584 * @since 12 585 */ 586 startTime: number; 587 /** 588 * End time for querying traffic. 589 * @type { number } 590 * @syscap SystemCapability.Communication.NetManager.Core 591 * @systemapi Hide this for inner system use. 592 * @since 12 593 */ 594 endTime: number; 595 /** 596 * Detailed information of statistics. 597 * @type { NetStatsInfo } 598 * @syscap SystemCapability.Communication.NetManager.Core 599 * @systemapi Hide this for inner system use. 600 * @since 12 601 */ 602 info: NetStatsInfo; 603 }[]; 604 605 /** 606 * {@link NetStatsInfo} for every UID. Key is UID. 607 * @syscap SystemCapability.Communication.NetManager.Core 608 * @systemapi Hide this for inner system use. 609 * @since 12 610 */ 611 export type UidNetStatsInfo = { 612 [uid: number]: NetStatsInfo; 613 }; 614 615 /** 616 * Parameters for obtaining detailed information on specified network traffic usage. 617 * @interface NetworkInfo 618 * @syscap SystemCapability.Communication.NetManager.Core 619 * @systemapi Hide this for inner system use. 620 * @since 12 621 */ 622 export interface NetworkInfo { 623 /** 624 * Network type for querying traffic. 625 * @type { NetBearType } 626 * @syscap SystemCapability.Communication.NetManager.Core 627 * @systemapi Hide this for inner system use. 628 * @since 12 629 */ 630 type: NetBearType; 631 /** 632 * Start time for querying traffic. 633 * @type { number } 634 * @syscap SystemCapability.Communication.NetManager.Core 635 * @systemapi Hide this for inner system use. 636 * @since 12 637 */ 638 startTime: number; 639 /** 640 * End time for querying traffic. 641 * @type { number } 642 * @syscap SystemCapability.Communication.NetManager.Core 643 * @systemapi Hide this for inner system use. 644 * @since 12 645 */ 646 endTime: number; 647 /** 648 * SIM card id for querying traffic. 649 * @type { ?number } 650 * @syscap SystemCapability.Communication.NetManager.Core 651 * @systemapi Hide this for inner system use. 652 * @since 12 653 */ 654 simId?: number; 655 } 656 657 /** 658 * Get the traffic usage details of the specified network of all applications in the specified time period. 659 * @permission ohos.permission.GET_NETWORK_STATS 660 * @param { NetworkInfo } networkInfo - Information about the network to be queried. 661 * @returns { Promise<UidNetStatsInfo> } The statistics of the sim card. 662 * @throws { BusinessError } 201 - Permission denied. 663 * @throws { BusinessError } 202 - Non-system applications use system APIs. 664 * @throws { BusinessError } 401 - Parameter error. 665 * @throws { BusinessError } 2100001 - Invalid parameter value. 666 * @throws { BusinessError } 2100002 - Failed to connect to the service. 667 * @throws { BusinessError } 2100003 - System internal error. 668 * @throws { BusinessError } 2103017 - Failed to read the database. 669 * @syscap SystemCapability.Communication.NetManager.Core 670 * @systemapi Hide this for inner system use. 671 * @since 12 672 */ 673 function getTrafficStatsByNetwork(networkInfo: NetworkInfo): Promise<UidNetStatsInfo>; 674 /** 675 * Get the traffic usage sequence of the specified network of the application in the specified time period. 676 * @permission ohos.permission.GET_NETWORK_STATS 677 * @param { number } uid - UID with this parameter, get stats info of this UID. 678 * @param { NetworkInfo } networkInfo - Information about the network to be queried. 679 * @returns { Promise<NetStatsInfoSequence> } The statistics history of the sim card. 680 * @throws { BusinessError } 201 - Permission denied. 681 * @throws { BusinessError } 202 - Non-system applications use system APIs. 682 * @throws { BusinessError } 401 - Parameter error. 683 * @throws { BusinessError } 2100001 - Invalid parameter value. 684 * @throws { BusinessError } 2100002 - Failed to connect to the service. 685 * @throws { BusinessError } 2100003 - System internal error. 686 * @throws { BusinessError } 2103017 - Failed to read the database. 687 * @syscap SystemCapability.Communication.NetManager.Core 688 * @systemapi Hide this for inner system use. 689 * @since 12 690 */ 691 function getTrafficStatsByUidNetwork(uid: number, networkInfo: NetworkInfo): Promise<NetStatsInfoSequence>; 692} 693 694export default statistics;