From 2e486b132717c0b98a3b1c5ee1e8a5dce5d0ee98 Mon Sep 17 00:00:00 2001 From: xujie Date: Mon, 3 Jul 2023 14:35:04 +0800 Subject: [PATCH] add history Change-Id: I4b6cd61addf0789423dcd57d4ad1df53d81a28b8 Signed-off-by: xujie --- .../reference/apis/js-apis-net-statistics.md | 333 ++++++++++++++++++ .../errorcodes/errorcode-net-statistics.md | 16 + 2 files changed, 349 insertions(+) diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md b/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md index 434ceda923..6b1b5c3458 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-statistics.md @@ -583,3 +583,336 @@ getUidTxBytes(uid: number): Promise\; console.log(JSON.stringify(stats)) }) ``` + +## statistics.on('netStatsChange')10+ + +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 }\> | 是 | 当流量有改变时触发回调函数。
iface:网卡名称。
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')10+ + +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 }\> | 否 | 当流量有改变时触发回调函数。
iface:网卡名称。
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.getIfaceStats10+ + +getIfaceStats(ifaceInfo: IfaceInfo, callback: AsyncCallback\): 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.getIfaceStats10+ + +getIfaceStats(ifaceInfo: IfaceInfo): Promise\; + +获取网卡历史流量信息,使用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.getIfaceUidStats10+ + +getIfaceUidStats(uidStatsInfo: UidStatsInfo, callback: AsyncCallback\): 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.getIfaceUidStats10+ + +getIfaceUidStats(uidStatsInfo: UidStatsInfo): Promise\; + +获取应用历史流量信息,使用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)); + }) +``` + +## IfaceInfo10+ + +查询网卡历史流量参数信息。 + +**系统接口**:此接口为系统接口。 + +**系统能力**:SystemCapability.Communication.NetManager.Core + +| 名称 | 类型 | 必填 | 说明 | +| --------------------- | ---------------------------------- | --- | ------------------------ | +| iface | string | 是 | 需要查询我网卡名。| +| startTime | number | 是 | 查询的开始时间(时间戳;单位:秒)。 | +| endTime | number | 是 | 查询的结束时间(时间戳;单位:秒)。 | + +## UidStatsInfo10+ + +查询应用历史流量参数信息。 + +**系统接口**:此接口为系统接口。 + +**系统能力**:SystemCapability.Communication.NetManager.Core + +| 名称 | 类型 | 必填 | 说明 | +| --------------------- | ---------------------------------- | --- | ------------------------ | +| ifaceInfo | IfaceInfo\<[IfaceInfo](#IfaceInfo)> | 是 | 需查询的网卡和时间参数信息| +| uid | number | 是 | 需查询的应用uid| + +## NetStatsInfo10+ + +获取的历史流量信息。 + +**系统接口**:此接口为系统接口。 + +**系统能力**:SystemCapability.Communication.NetManager.Core + +| 名称 | 类型 | 必填 | 说明 | +| --------------------- | ---------------------------------- | --- | ------------------------ | +| rxBytes | number | 是 | 流量下行数据(单位:字节)| +| txBytes | number | 是 | 流量上行数据(单位:字节)| +| rxPackets | number | 是 | 流量下行包个数| +| txPackets | number | 是 | 流量上行包个数| \ No newline at end of file diff --git a/zh-cn/application-dev/reference/errorcodes/errorcode-net-statistics.md b/zh-cn/application-dev/reference/errorcodes/errorcode-net-statistics.md index 5c1b31b560..1ac4a00513 100644 --- a/zh-cn/application-dev/reference/errorcodes/errorcode-net-statistics.md +++ b/zh-cn/application-dev/reference/errorcodes/errorcode-net-statistics.md @@ -117,4 +117,20 @@ Get iface name failed. 检查传入的网卡名是否正确。 +## 2103017 读取数据库失败 +**错误信息** + +Read data from database failed. + +**错误描述** + +读取数据库失败。 + +**可能原因** + +数据库被损坏。 + +**处理步骤** + +检查本机数据库文件是否被损坏。 -- GitLab