diff --git a/en/application-dev/reference/apis/js-apis-hisysevent.md b/en/application-dev/reference/apis/js-apis-hisysevent.md index e3c08ce24cf92eda9534812d664aa466c4b7c1ef..65952c0b23946b02582d74e5be9fbc5f8c33b42d 100644 --- a/en/application-dev/reference/apis/js-apis-hisysevent.md +++ b/en/application-dev/reference/apis/js-apis-hisysevent.md @@ -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.
- **0**: Event subscription is successful.
- 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.
- **0**: Removing the watcher is successful.
- 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.
- **0**: Event query is successful.
- 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}`); +} ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-hisysevent.md b/zh-cn/application-dev/reference/apis/js-apis-hisysevent.md index 174ec0ebb77cd895952b59a0939689749c7da52d..1895a0eb1687b281cd3f8fe211f26f850f284f9d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hisysevent.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hisysevent.md @@ -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 | 系统事件订阅结果。
- 0表示订阅成功。
- 负值表示订阅失败。 | - **示例:** ```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 | 取消订阅系统事件的结果。
- 0表示取消订阅成功。
- 负值表示取消订阅失败。 | - **示例:** ```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 | 系统事件查询的结果。
- 0表示查询成功.
- 负值表示查询失败。 | - **示例:** ```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