Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
042a8b67
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
042a8b67
编写于
10月 13, 2022
作者:
X
xuyong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
HiSysEvent napi接口文档增加异常相关的try-catch指导说明
Signed-off-by:
N
xuyong
<
xuyong59@huawei.com
>
上级
fc77c051
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
222 addition
and
218 deletion
+222
-218
en/application-dev/reference/apis/js-apis-hisysevent.md
en/application-dev/reference/apis/js-apis-hisysevent.md
+111
-109
zh-cn/application-dev/reference/apis/js-apis-hisysevent.md
zh-cn/application-dev/reference/apis/js-apis-hisysevent.md
+111
-109
未找到文件。
en/application-dev/reference/apis/js-apis-hisysevent.md
浏览文件 @
042a8b67
...
...
@@ -60,20 +60,24 @@ Writes event information to the event file. This API uses an asynchronous callba
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
try
{
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
```
...
...
@@ -102,26 +106,30 @@ Writes event information to the event file. This API uses a promise to return th
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
}).
then
(
(
val
)
=>
{
// do something here.
}
).
catch
(
(
err
)
=>
{
// do something here.
}
)
try
{
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
}).
then
(
(
val
)
=>
{
// do something here.
}
).
catch
(
(
err
)
=>
{
// do something here.
}
)
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
```
## RuleType
...
...
@@ -177,32 +185,30 @@ Adds a watcher for event subscription.
| ------ | ----------------------------- | ---- | ------------------------ |
| watcher |
[
Watcher
](
#watcher
)
| Yes| Watcher for event subscription.|
**Return value**
| Type | Description|
| ------- | -------------------------------------------------- |
| number | Event subscription result.
<br>
-
**0**
: Event subscription is successful.
<br>
- A value smaller than
**0**
: Event subscription has failed.|
**Example**
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
let
watcher
=
{
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
}
try
{
hiSysEvent
.
addWatcher
(
watcher
)
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
let
ret
=
hiSysEvent
.
addWatcher
(
watcher
)
```
## hiSysEvent.removeWatcher
...
...
@@ -221,33 +227,31 @@ Removes a watcher used for event subscription.
| ------ | ------------- | ---- | ------------------------ |
| watcher |
[
Watcher
](
#watcher
)
| Yes| Watcher for event subscription.|
**Return value**
| Type | Description|
| ------- | ----------------------------------------------------------- |
| number | Result of removing the watcher.
<br>
-
**0**
: Removing the watcher is successful.
<br>
- A value smaller than
**0**
: Removing the watcher has failed.|
**Example**
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
let
watcher
=
{
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
}
try
{
hiSysEvent
.
addWatcher
(
watcher
)
hiSysEvent
.
removeWatcher
(
watcher
)
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
let
ret
=
hiSysEvent
.
addWatcher
(
watcher
)
hiSysEvent
.
removeWatcher
(
watcher
)
```
## QueryArg
...
...
@@ -281,7 +285,7 @@ Defines an event query instance.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| onQuery | function | Yes| Callback of queried events: (infos:
[
SysEventInfo
](
#syseventinfo
)[]
, seqs: number[]
) => void|
| onQuery | function | Yes| Callback of queried events: (infos:
[
SysEventInfo
](
#syseventinfo
)[]
) => void|
| onComplete | function | Yes| Callback of query result statistics: (reason: number, total: number) => void|
## hiSysEvent.query
...
...
@@ -302,44 +306,42 @@ Queries system events.
| rules |
[
QueryRule
](
#queryrule
)[]
| Yes | Array of event query rules.|
| querier |
[
Querier
](
#querier
)
| Yes | Event query instance.|
**Return value**
| Type | Description |
| ------- | ----------------------------------------------------------- |
| number | Event query result.
<br>
-
**0**
: Event query is successful.
<br>
- A value smaller than
**0**
: Event query has failed.|
**Example**
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
hiSysEvent
.
query
({
beginTime
:
-
1
,
endTime
:
-
1
,
maxEvents
:
5
,
},
[{
domain
:
"
RELIABILITY
"
,
names
:
[
"
STACK
"
],
}],
{
onQuery
:
function
(
infos
,
seqs
)
{
// do something here.
},
onComplete
:
function
(
reason
,
total
)
{
// do something here.
}
})
try
{
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
hiSysEvent
.
query
({
beginTime
:
-
1
,
endTime
:
-
1
,
maxEvents
:
5
,
},
[{
domain
:
"
RELIABILITY
"
,
names
:
[
"
STACK
"
],
}],
{
onQuery
:
function
(
infos
)
{
// do something here.
},
onComplete
:
function
(
reason
,
total
)
{
// do something here.
}
})
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
```
zh-cn/application-dev/reference/apis/js-apis-hisysevent.md
浏览文件 @
042a8b67
...
...
@@ -60,20 +60,24 @@ write(info: SysEventInfo, callback: AsyncCallback<void>): void
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
try
{
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
```
...
...
@@ -102,26 +106,30 @@ write(info: SysEventInfo): Promise<void>
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
}).
then
(
(
val
)
=>
{
// do something here.
}
).
catch
(
(
err
)
=>
{
// do something here.
}
)
try
{
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
}).
then
(
(
val
)
=>
{
// do something here.
}
).
catch
(
(
err
)
=>
{
// do something here.
}
)
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
```
## RuleType
...
...
@@ -177,32 +185,30 @@ addWatcher(watcher: Watcher): number
| ------ | ----------------------------- | ---- | ------------------------ |
| watcher |
[
Watcher
](
#watcher
)
| 是 | 系统事件订阅者对象。 |
**返回值:**
| 类型 | 说明 |
| ------- | -------------------------------------------------- |
| number | 系统事件订阅结果。
<br>
- 0表示订阅成功。
<br>
- 负值表示订阅失败。 |
**示例:**
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
let
watcher
=
{
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
}
try
{
hiSysEvent
.
addWatcher
(
watcher
)
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
let
ret
=
hiSysEvent
.
addWatcher
(
watcher
)
```
## hiSysEvent.removeWatcher
...
...
@@ -221,33 +227,31 @@ removeWatcher(watcher: Watcher): number
| ------ | ------------- | ---- | ------------------------ |
| watcher |
[
Watcher
](
#watcher
)
| 是 | 系统事件订阅者对象。 |
**返回值:**
| 类型 | 说明 |
| ------- | ----------------------------------------------------------- |
| number | 取消订阅系统事件的结果。
<br>
- 0表示取消订阅成功。
<br>
- 负值表示取消订阅失败。 |
**示例:**
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
let
watcher
=
{
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
rules
:
[{
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
tag
:
"
STABILITY
"
,
ruleType
:
hiSysEvent
.
RuleType
.
WHOLE_WORD
,
}],
onEvent
:
(
info
)
=>
{
// do something here.
},
onServiceDied
:
()
=>
{
// do something here.
}
}
try
{
let
ret
=
hiSysEvent
.
addWatcher
(
watcher
)
hiSysEvent
.
removeWatcher
(
watcher
)
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
let
ret
=
hiSysEvent
.
addWatcher
(
watcher
)
hiSysEvent
.
removeWatcher
(
watcher
)
```
## QueryArg
...
...
@@ -281,7 +285,7 @@ hiSysEvent.removeWatcher(watcher)
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| onQuery | function | 是 | 返回查询到的系统事件的回调方法(infos:
[
SysEventInfo
](
#syseventinfo
)[]
, seqs: number[]
) => void。 |
| onQuery | function | 是 | 返回查询到的系统事件的回调方法(infos:
[
SysEventInfo
](
#syseventinfo
)[]
) => void。 |
| onComplete | function | 是 | 查询结果统计的回调方法(reason: number, total: number) => void。 |
## hiSysEvent.query
...
...
@@ -302,44 +306,42 @@ query(queryArg: QueryArg, rules: QueryRule[], querier: Querier): number
| rules |
[
QueryRule
](
#queryrule
)[]
| 是 | 查询规则数组,每次查询可配置多个查询规则。 |
| querier |
[
Querier
](
#querier
)
| 是 | 查询者对象,包含查询结果及结束的相关回调。 |
**返回值:**
| 类型 | 说明 |
| ------- | ----------------------------------------------------------- |
| number | 系统事件查询的结果。
<br>
- 0表示查询成功.
<br>
- 负值表示查询失败。 |
**示例:**
```
js
import
hiSysEvent
from
'
@ohos.hiSysEvent
'
;
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
hiSysEvent
.
query
({
beginTime
:
-
1
,
endTime
:
-
1
,
maxEvents
:
5
,
},
[{
domain
:
"
RELIABILITY
"
,
names
:
[
"
STACK
"
],
}],
{
onQuery
:
function
(
infos
,
seqs
)
{
// do something here.
},
onComplete
:
function
(
reason
,
total
)
{
// do something here.
}
})
try
{
hiSysEvent
.
write
({
domain
:
"
RELIABILITY
"
,
name
:
"
STACK
"
,
eventType
:
hiSysEvent
.
EventType
.
FAULT
,
params
:
{
PID
:
487
,
UID
:
103
,
PACKAGE_NAME
:
"
com.ohos.hisysevent.test
"
,
PROCESS_NAME
:
"
syseventservice
"
,
MSG
:
"
no msg.
"
}
},
(
err
,
val
)
=>
{
// do something here.
})
hiSysEvent
.
query
({
beginTime
:
-
1
,
endTime
:
-
1
,
maxEvents
:
5
,
},
[{
domain
:
"
RELIABILITY
"
,
names
:
[
"
STACK
"
],
}],
{
onQuery
:
function
(
infos
)
{
// do something here.
},
onComplete
:
function
(
reason
,
total
)
{
// do something here.
}
})
}
catch
(
error
)
{
console
.
error
(
`error code:
${
error
.
code
}
, error msg:
${
error
.
message
}
`
);
}
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录