Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2e486b13
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2e486b13
编写于
7月 03, 2023
作者:
X
xujie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add history
Change-Id: I4b6cd61addf0789423dcd57d4ad1df53d81a28b8 Signed-off-by:
N
xujie
<
xujie223@huawei.com
>
上级
42ba49a8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
349 addition
and
0 deletion
+349
-0
zh-cn/application-dev/reference/apis/js-apis-net-statistics.md
.../application-dev/reference/apis/js-apis-net-statistics.md
+333
-0
zh-cn/application-dev/reference/errorcodes/errorcode-net-statistics.md
...tion-dev/reference/errorcodes/errorcode-net-statistics.md
+16
-0
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-net-statistics.md
浏览文件 @
2e486b13
...
@@ -583,3 +583,336 @@ getUidTxBytes(uid: number): Promise\<number>;
...
@@ -583,3 +583,336 @@ getUidTxBytes(uid: number): Promise\<number>;
console
.
log
(
JSON
.
stringify
(
stats
))
console
.
log
(
JSON
.
stringify
(
stats
))
})
})
```
```
## statistics.on('netStatsChange')<sup>10+</sup>
on(type: 'netStatsChange', callback: Callback
\<
{ iface: string, uid?: number }>): void
注册流量改变事件通知。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.GET_NETWORK_STATS
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 订阅事件,固定为'netStatsChange'。|
| callback | Callback
\<
{ iface: string, uid?: number }
\>
| 是 | 当流量有改变时触发回调函数。
<br>
iface:网卡名称。
<br>
uid:应用uid |
**错误码:**
以下错误码的详细介绍参见
[
statistics错误码
](
../errorcodes/errorcode-net-statistics
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100002 | Operation failed. Cannot connect to service. |
| 2100003 | System internal error. |
**示例:**
```
js
statistics
.
on
(
'
netStatsChange
'
,
(
data
)
=>
{
console
.
log
(
'
on netStatsChange
'
+
JSON
.
stringify
(
data
));
});
```
## statistics.on('netStatsChange')<sup>10+</sup>
off(type: 'netStatsChange', callback?: Callback
\<
{ iface: string, uid?: number }>): void;
注销流量改变事件通知。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.GET_NETWORK_STATS
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | --------------------------------------- | ---- | ---------- |
| type | string | 是 | 注销订阅事件,固定为'netStatsChange'。 |
| callback | Callback
\<
{ iface: string, uid?: number }
\>
| 否 | 当流量有改变时触发回调函数。
<br>
iface:网卡名称。
<br>
uid:应用uid |
**错误码:**
以下错误码的详细介绍参见
[
statistics错误码
](
../errorcodes/errorcode-net-statistics
)
。
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100002 | Operation failed. Cannot connect to service. |
| 2100003 | System internal error. |
**示例:**
```
js
statistics
.
off
(
'
netStatsChange
'
);
```
## statistics.getIfaceStats<sup>10+</sup>
getIfaceStats(ifaceInfo: IfaceInfo, callback: AsyncCallback
\<
NetStatsInfo>): void;
获取网卡历史流量信息,使用callback方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.GET_NETWORK_STATS
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
| ifaceInfo |
[
IfaceInfo
](
#IfaceInfo
)
| 是 | 指定查询的网卡信息,参见
[
IfaceInfo
](
#IfaceInfo
)
。 |
| callback | AsyncCallback
\<
[
NetStatsInfo
](
#NetStatsInfo
)
> | 是 | 回调函数。成功时statsInfo返回包含网卡历史流量信息,error为undefined,否则为错误对象|
**错误码:**
以下错误码的详细介绍参见
[
statistics错误码
](
../errorcodes/errorcode-net-statistics
)
。
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100001 | Invalid parameter value. |
| 2100002 | Operation failed. Cannot connect to service. |
| 2100003 | System internal error. |
| 2103017 | Read data from database failed. |
**示例:**
```
js
let
ifaceInfo
=
{
iface
:
"
wlan0
"
,
startTime
:
1685948465
,
endTime
:
16859485670
}
statistics
.
getIfaceStats
(
ifaceInfo
),
(
error
,
statsInfo
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
"
getIfaceStats bytes of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxBytes
));
console
.
log
(
"
getIfaceStats bytes of send =
"
+
JSON
.
stringify
(
statsInfo
.
txBytes
));
console
.
log
(
"
getIfaceStats packets of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxPackets
));
console
.
log
(
"
getIfaceStats packets of send =
"
+
JSON
.
stringify
(
statsInfo
.
txPackets
));
});
```
## statistics.getIfaceStats<sup>10+</sup>
getIfaceStats(ifaceInfo: IfaceInfo): Promise
\<
NetStatsInfo>;
获取网卡历史流量信息,使用Promise方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.GET_NETWORK_STATS
**系统能力**
:SystemCapability.Communication.NetManager.Core
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
| ifaceInfo |
[
IfaceInfo
](
#IfaceInfo
)
| 是 | 指定查询的网卡信息,参见
[
IfaceInfo
](
#IfaceInfo
)
。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
\<
[
NetStatsInfo
](
#NetStatsInfo
)
> | 以Promise形式返回获取结果。成功时NetStatsInfo返回包含网卡历史流量信息。 |
**错误码:**
以下错误码的详细介绍参见
[
statistics错误码
](
../errorcodes/errorcode-net-statistics
)
。
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100001 | Invalid parameter value. |
| 2100002 | Operation failed. Cannot connect to service. |
| 2100003 | System internal error. |
| 2103017 | Read data from database failed. |
**示例:**
```
js
let
ifaceInfo
=
{
iface
:
"
wlan0
"
,
startTime
:
1685948465
,
endTime
:
16859485670
}
statistics
.
getIfaceStats
().
then
(
function
(
statsInfo
)
{
console
.
log
(
"
getIfaceStats bytes of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxBytes
));
console
.
log
(
"
getIfaceStats bytes of send =
"
+
JSON
.
stringify
(
statsInfo
.
txBytes
));
console
.
log
(
"
getIfaceStats packets of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxPackets
));
console
.
log
(
"
getIfaceStats packets of send =
"
+
JSON
.
stringify
(
statsInfo
.
txPackets
));
})
```
## statistics.getIfaceUidStats<sup>10+</sup>
getIfaceUidStats(uidStatsInfo: UidStatsInfo, callback: AsyncCallback
\<
NetStatsInfo>): void;
获取应用历史流量信息,使用callback方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.GET_NETWORK_STATS
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
| uidStatsInfo |
[
UidStatsInfo
](
#UidStatsInfo
)
| 是 | 指定查询的应用历史流量信息,参见
[
UidStatsInfo
](
#UidStatsInfo
)
。 |
| callback | AsyncCallback
\<
[
NetStatsInfo
](
#NetStatsInfo
)
> | 是 | 回调函数。成功时statsInfo返回包含应用历史流量信息,error为undefined,否则为错误对象|
**错误码:**
以下错误码的详细介绍参见
[
statistics错误码
](
../errorcodes/errorcode-net-statistics
)
。
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100001 | Invalid parameter value. |
| 2100002 | Operation failed. Cannot connect to service. |
| 2100003 | System internal error. |
| 2103017 | Read data from database failed. |
**示例:**
```
js
let
uidStatsInfo
=
{
ifaceInfo
:
{
iface
:
"
wlan0
"
,
startTime
:
1685948465
,
endTime
:
16859485670
},
uid
:
20010037
}
statistics
.
getIfaceStats
(
uidStatsInfo
),
(
error
,
statsInfo
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
"
getIfaceStats bytes of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxBytes
));
console
.
log
(
"
getIfaceStats bytes of send =
"
+
JSON
.
stringify
(
statsInfo
.
txBytes
));
console
.
log
(
"
getIfaceStats packets of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxPackets
));
console
.
log
(
"
getIfaceStats packets of send =
"
+
JSON
.
stringify
(
statsInfo
.
txPackets
));
});
```
## statistics.getIfaceUidStats<sup>10+</sup>
getIfaceUidStats(uidStatsInfo: UidStatsInfo): Promise
\<
NetStatsInfo>;
获取应用历史流量信息,使用Promise方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.GET_NETWORK_STATS
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------------ | ----------------------------- | ---- | ------------------------------------------------------------ |
| uidStatsInfo |
[
UidStatsInfo
](
#UidStatsInfo
)
| 是 | 指定查询的应用历史流量信息,参见
[
UidStatsInfo
](
#UidStatsInfo
)
。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
\<
[
NetStatsInfo
](
#NetStatsInfo
)
> | 以Promise形式返回获取结果。成功时NetStatsInfo返回包含应用历史流量信息。 |
**错误码:**
以下错误码的详细介绍参见
[
statistics错误码
](
../errorcodes/errorcode-net-statistics
)
。
| 错误码ID | 错误信息 |
| ------- | ----------------------------- |
| 201 | Permission denied. |
| 202 | Non-system applications use system APIs. |
| 401 | Parameter error. |
| 2100001 | Invalid parameter value. |
| 2100002 | Operation failed. Cannot connect to service. |
| 2100003 | System internal error. |
| 2103017 | Read data from database failed. |
**示例:**
```
js
let
uidStatsInfo
=
{
ifaceInfo
:
{
iface
:
"
wlan0
"
,
startTime
:
1685948465
,
endTime
:
16859485670
},
uid
:
20010037
}
statistics
.
getIfaceStats
(
uidStatsInfo
).
then
(
function
(
statsInfo
)
{
console
.
log
(
"
getIfaceStats bytes of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxBytes
));
console
.
log
(
"
getIfaceStats bytes of send =
"
+
JSON
.
stringify
(
statsInfo
.
txBytes
));
console
.
log
(
"
getIfaceStats packets of received =
"
+
JSON
.
stringify
(
statsInfo
.
rxPackets
));
console
.
log
(
"
getIfaceStats packets of send =
"
+
JSON
.
stringify
(
statsInfo
.
txPackets
));
})
```
## IfaceInfo<sup>10+</sup>
查询网卡历史流量参数信息。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| --------------------- | ---------------------------------- | --- | ------------------------ |
| iface | string | 是 | 需要查询我网卡名。|
| startTime | number | 是 | 查询的开始时间(时间戳;单位:秒)。 |
| endTime | number | 是 | 查询的结束时间(时间戳;单位:秒)。 |
## UidStatsInfo<sup>10+</sup>
查询应用历史流量参数信息。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| --------------------- | ---------------------------------- | --- | ------------------------ |
| ifaceInfo | IfaceInfo
\<
[
IfaceInfo
](
#IfaceInfo
)
> | 是 | 需查询的网卡和时间参数信息|
| uid | number | 是 | 需查询的应用uid|
## NetStatsInfo<sup>10+</sup>
获取的历史流量信息。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| --------------------- | ---------------------------------- | --- | ------------------------ |
| rxBytes | number | 是 | 流量下行数据(单位:字节)|
| txBytes | number | 是 | 流量上行数据(单位:字节)|
| rxPackets | number | 是 | 流量下行包个数|
| txPackets | number | 是 | 流量上行包个数|
\ No newline at end of file
zh-cn/application-dev/reference/errorcodes/errorcode-net-statistics.md
浏览文件 @
2e486b13
...
@@ -117,4 +117,20 @@ Get iface name failed.
...
@@ -117,4 +117,20 @@ Get iface name failed.
检查传入的网卡名是否正确。
检查传入的网卡名是否正确。
## 2103017 读取数据库失败
**错误信息**
Read data from database failed.
**错误描述**
读取数据库失败。
**可能原因**
数据库被损坏。
**处理步骤**
检查本机数据库文件是否被损坏。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录