1/* 2 * Copyright (C) 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 16import {AsyncCallback, Callback} from "./basic"; 17 18/** 19 * Obtains traffic statistics. 20 * 21 * @since 9 22 * @syscap SystemCapability.Communication.NetManager.Core 23 */ 24declare namespace statistics { 25 /** 26 * Queries the data traffic (including all TCP and UDP data packets) received through a specified NIC. 27 * 28 * @param nic Indicates the NIC name. 29 * @param callback Returns the data traffic received through the specified NIC. 30 */ 31 function getIfaceRxBytes(nic: string, callback: AsyncCallback<number>): void; 32 function getIfaceRxBytes(nic: string): Promise<number>; 33 34 /** 35 * Queries the data traffic (including all TCP and UDP data packets) sent through a specified NIC. 36 * 37 * @param nic Indicates the NIC name. 38 * @param callback Returns the data traffic sent through the specified NIC. 39 */ 40 function getIfaceTxBytes(nic: string, callback: AsyncCallback<number>): void; 41 function getIfaceTxBytes(nic: string): Promise<number>; 42 43 /** 44 * Queries the data traffic (including all TCP and UDP data packets) received through the cellular network. 45 * 46 * @param callback Returns the data traffic received through the cellular network. 47 */ 48 function getCellularRxBytes(callback: AsyncCallback<number>): void; 49 function getCellularRxBytes(): Promise<number>; 50 51 /** 52 * Queries the data traffic (including all TCP and UDP data packets) sent through the cellular network. 53 * 54 * @param callback Returns the data traffic sent through the cellular network. 55 */ 56 function getCellularTxBytes(callback: AsyncCallback<number>): void; 57 function getCellularTxBytes(): Promise<number>; 58 59 /** 60 * Queries the data traffic (including all TCP and UDP data packets) sent through all NICs. 61 * 62 * @param callback Returns the data traffic sent through all NICs. 63 */ 64 function getAllTxBytes(callback: AsyncCallback<number>): void; 65 function getAllTxBytes(): Promise<number>; 66 67 /** 68 * Queries the data traffic (including all TCP and UDP data packets) received through all NICs. 69 * 70 * @param callback Returns the data traffic received through all NICs. 71 */ 72 function getAllRxBytes(callback: AsyncCallback<number>): void; 73 function getAllRxBytes(): Promise<number>; 74 75 /** 76 * Queries the data traffic (including all TCP and UDP data packets) received by a specified application. 77 * This method applies only to system applications and your own applications. 78 * 79 * @param uid Indicates the process ID of the application. 80 * @param callback Returns the data traffic received by the specified application. 81 */ 82 function getUidRxBytes(uid: number, callback: AsyncCallback<number>): void; 83 function getUidRxBytes(uid: number): Promise<number>; 84 85 /** 86 * Queries the data traffic (including all TCP and UDP data packets) sent by a specified application. 87 * This method applies only to system applications and your own applications. 88 * 89 * @param uid Indicates the process ID of the application. 90 * @param callback Returns the data traffic sent by the specified application. 91 */ 92 function getUidTxBytes(uid: number, callback: AsyncCallback<number>): void; 93 function getUidTxBytes(uid: number): Promise<number>; 94 95 /** 96 * Register notifications of network traffic updates, restrictions, and warnings. 97 * 98 * @permission ohos.permission.CONNECTIVITY_INTERNAL 99 * @systemapi Hide this for inner system use. 100 */ 101 function on(type: 'netStatsChange', callback: Callback<{ iface: string, uid?: number }>): void; 102 103 /** 104 * @systemapi Hide this for inner system use. 105 */ 106 function off(type: 'netStatsChange', callback?: Callback<{ iface: string, uid?: number }>): void; 107 108 /** 109 * @systemapi Hide this for inner system use. 110 */ 111 export interface IfaceInfo { 112 iface: string; 113 startTime: number; 114 endTime: number; 115 } 116 117 /** 118 * @systemapi Hide this for inner system use. 119 */ 120 export interface UidStatsInfo { 121 /*See {@link IfaceInfo}*/ 122 ifaceInfo: IfaceInfo; 123 uid: number; 124 } 125 126 /** 127 * @systemapi Hide this for inner system use. 128 */ 129 export interface NetStatsInfo { 130 rxBytes: number; 131 txBytes: number; 132 rxPackets: number; 133 txPackets: number; 134 } 135} 136 137export default statistics;