1b1b8bc3fSopenharmony_ci/*
2b1b8bc3fSopenharmony_ci * Copyright (C) 2022 Huawei Device Co., Ltd.
3b1b8bc3fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4b1b8bc3fSopenharmony_ci * you may not use this file except in compliance with the License.
5b1b8bc3fSopenharmony_ci * You may obtain a copy of the License at
6b1b8bc3fSopenharmony_ci *
7b1b8bc3fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8b1b8bc3fSopenharmony_ci *
9b1b8bc3fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10b1b8bc3fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11b1b8bc3fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12b1b8bc3fSopenharmony_ci * See the License for the specific language governing permissions and
13b1b8bc3fSopenharmony_ci * limitations under the License.
14b1b8bc3fSopenharmony_ci */
15b1b8bc3fSopenharmony_ci
16b1b8bc3fSopenharmony_ciimport {AsyncCallback, Callback} from './basic';
17b1b8bc3fSopenharmony_ci
18b1b8bc3fSopenharmony_ci/**
19b1b8bc3fSopenharmony_ci * Obtains traffic statistics.
20b1b8bc3fSopenharmony_ci *
21b1b8bc3fSopenharmony_ci * @since 10
22b1b8bc3fSopenharmony_ci * @syscap SystemCapability.Communication.NetManager.Core
23b1b8bc3fSopenharmony_ci */
24b1b8bc3fSopenharmony_cideclare namespace statistics {
25b1b8bc3fSopenharmony_ci  /**
26b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) received through a specified NIC.
27b1b8bc3fSopenharmony_ci   *
28b1b8bc3fSopenharmony_ci   * @param nic Indicates the NIC name.
29b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic received through the specified NIC.
30b1b8bc3fSopenharmony_ci   */
31b1b8bc3fSopenharmony_ci  function getIfaceRxBytes(nic: string, callback: AsyncCallback<number>): void;
32b1b8bc3fSopenharmony_ci  function getIfaceRxBytes(nic: string): Promise<number>;
33b1b8bc3fSopenharmony_ci
34b1b8bc3fSopenharmony_ci  /**
35b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) sent through a specified NIC.
36b1b8bc3fSopenharmony_ci   *
37b1b8bc3fSopenharmony_ci   * @param nic Indicates the NIC name.
38b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic sent through the specified NIC.
39b1b8bc3fSopenharmony_ci   */
40b1b8bc3fSopenharmony_ci  function getIfaceTxBytes(nic: string, callback: AsyncCallback<number>): void;
41b1b8bc3fSopenharmony_ci  function getIfaceTxBytes(nic: string): Promise<number>;
42b1b8bc3fSopenharmony_ci
43b1b8bc3fSopenharmony_ci  /**
44b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) received through the cellular network.
45b1b8bc3fSopenharmony_ci   *
46b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic received through the cellular network.
47b1b8bc3fSopenharmony_ci   */
48b1b8bc3fSopenharmony_ci  function getCellularRxBytes(callback: AsyncCallback<number>): void;
49b1b8bc3fSopenharmony_ci  function getCellularRxBytes(): Promise<number>;
50b1b8bc3fSopenharmony_ci
51b1b8bc3fSopenharmony_ci  /**
52b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) sent through the cellular network.
53b1b8bc3fSopenharmony_ci   *
54b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic sent through the cellular network.
55b1b8bc3fSopenharmony_ci   */
56b1b8bc3fSopenharmony_ci  function getCellularTxBytes(callback: AsyncCallback<number>): void;
57b1b8bc3fSopenharmony_ci  function getCellularTxBytes(): Promise<number>;
58b1b8bc3fSopenharmony_ci
59b1b8bc3fSopenharmony_ci  /**
60b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) sent through all NICs.
61b1b8bc3fSopenharmony_ci   *
62b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic sent through all NICs.
63b1b8bc3fSopenharmony_ci   */
64b1b8bc3fSopenharmony_ci  function getAllTxBytes(callback: AsyncCallback<number>): void;
65b1b8bc3fSopenharmony_ci  function getAllTxBytes(): Promise<number>;
66b1b8bc3fSopenharmony_ci
67b1b8bc3fSopenharmony_ci  /**
68b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) received through all NICs.
69b1b8bc3fSopenharmony_ci   *
70b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic received through all NICs.
71b1b8bc3fSopenharmony_ci   */
72b1b8bc3fSopenharmony_ci  function getAllRxBytes(callback: AsyncCallback<number>): void;
73b1b8bc3fSopenharmony_ci  function getAllRxBytes(): Promise<number>;
74b1b8bc3fSopenharmony_ci
75b1b8bc3fSopenharmony_ci  /**
76b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) received by a specified application.
77b1b8bc3fSopenharmony_ci   * This method applies only to system applications and your own applications.
78b1b8bc3fSopenharmony_ci   *
79b1b8bc3fSopenharmony_ci   * @param uid Indicates the process ID of the application.
80b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic received by the specified application.
81b1b8bc3fSopenharmony_ci   */
82b1b8bc3fSopenharmony_ci  function getUidRxBytes(uid: number, callback: AsyncCallback<number>): void;
83b1b8bc3fSopenharmony_ci  function getUidRxBytes(uid: number): Promise<number>;
84b1b8bc3fSopenharmony_ci
85b1b8bc3fSopenharmony_ci  /**
86b1b8bc3fSopenharmony_ci   * Queries the data traffic (including all TCP and UDP data packets) sent by a specified application.
87b1b8bc3fSopenharmony_ci   * This method applies only to system applications and your own applications.
88b1b8bc3fSopenharmony_ci   *
89b1b8bc3fSopenharmony_ci   * @param uid Indicates the process ID of the application.
90b1b8bc3fSopenharmony_ci   * @param callback Returns the data traffic sent by the specified application.
91b1b8bc3fSopenharmony_ci   */
92b1b8bc3fSopenharmony_ci  function getUidTxBytes(uid: number, callback: AsyncCallback<number>): void;
93b1b8bc3fSopenharmony_ci  function getUidTxBytes(uid: number): Promise<number>;
94b1b8bc3fSopenharmony_ci
95b1b8bc3fSopenharmony_ci  /**
96b1b8bc3fSopenharmony_ci   * Register notifications of network traffic updates.
97b1b8bc3fSopenharmony_ci   *
98b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
99b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
100b1b8bc3fSopenharmony_ci   */
101b1b8bc3fSopenharmony_ci  function on(type: 'netStatsChange', callback: Callback<{ iface: string, uid?: number }>): void;
102b1b8bc3fSopenharmony_ci
103b1b8bc3fSopenharmony_ci  /**
104b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
105b1b8bc3fSopenharmony_ci   */
106b1b8bc3fSopenharmony_ci  function off(type: 'netStatsChange', callback?: Callback<{ iface: string, uid?: number }>): void;
107b1b8bc3fSopenharmony_ci
108b1b8bc3fSopenharmony_ci  /**
109b1b8bc3fSopenharmony_ci   * Get the traffic usage details of the network interface in the specified time period.
110b1b8bc3fSopenharmony_ci   *
111b1b8bc3fSopenharmony_ci   * @param ifaceInfo Indicates the handle. See {@link IfaceInfo}.
112b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
113b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
114b1b8bc3fSopenharmony_ci   */
115b1b8bc3fSopenharmony_ci  function getIfaceStats(ifaceInfo: IfaceInfo, callback: AsyncCallback<NetStatsInfo>): void;
116b1b8bc3fSopenharmony_ci  function getIfaceStats(ifaceInfo: IfaceInfo): Promise<NetStatsInfo>;
117b1b8bc3fSopenharmony_ci
118b1b8bc3fSopenharmony_ci  /**
119b1b8bc3fSopenharmony_ci   * Get the traffic usage details of the specified time period of the application.
120b1b8bc3fSopenharmony_ci   *
121b1b8bc3fSopenharmony_ci   * @param uidStatsInfo Indicates the handle. See {@link UidStatsInfo}.
122b1b8bc3fSopenharmony_ci   * @permission ohos.permission.CONNECTIVITY_INTERNAL
123b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
124b1b8bc3fSopenharmony_ci   */
125b1b8bc3fSopenharmony_ci  function getIfaceUidStats(uidStatsInfo: UidStatsInfo, callback: AsyncCallback<NetStatsInfo>): void;
126b1b8bc3fSopenharmony_ci  function getIfaceUidStats(uidStatsInfo: UidStatsInfo): Promise<NetStatsInfo>;
127b1b8bc3fSopenharmony_ci
128b1b8bc3fSopenharmony_ci  /**
129b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
130b1b8bc3fSopenharmony_ci   */
131b1b8bc3fSopenharmony_ci  export interface IfaceInfo {
132b1b8bc3fSopenharmony_ci    iface: string;
133b1b8bc3fSopenharmony_ci    startTime: number;
134b1b8bc3fSopenharmony_ci    endTime: number;
135b1b8bc3fSopenharmony_ci  }
136b1b8bc3fSopenharmony_ci
137b1b8bc3fSopenharmony_ci  /**
138b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
139b1b8bc3fSopenharmony_ci   */
140b1b8bc3fSopenharmony_ci  export interface UidStatsInfo {
141b1b8bc3fSopenharmony_ci    /*See {@link IfaceInfo}*/
142b1b8bc3fSopenharmony_ci    ifaceInfo: IfaceInfo;
143b1b8bc3fSopenharmony_ci    uid: number;
144b1b8bc3fSopenharmony_ci  }
145b1b8bc3fSopenharmony_ci
146b1b8bc3fSopenharmony_ci  /**
147b1b8bc3fSopenharmony_ci   * @systemapi Hide this for inner system use.
148b1b8bc3fSopenharmony_ci   */
149b1b8bc3fSopenharmony_ci  export interface NetStatsInfo {
150b1b8bc3fSopenharmony_ci    rxBytes: number;
151b1b8bc3fSopenharmony_ci    txBytes: number;
152b1b8bc3fSopenharmony_ci    rxPackets: number;
153b1b8bc3fSopenharmony_ci    txPackets: number;
154b1b8bc3fSopenharmony_ci  }
155b1b8bc3fSopenharmony_ci}
156b1b8bc3fSopenharmony_ci
157b1b8bc3fSopenharmony_ciexport default statistics;