@ohos.hiviewdfx.FaultLogExtensionAbility (Delayed Fault Notification)
This module implements the delayed fault notification feature.
When the crash and freeze events are subscribed by HiAppEvent, the previous event can be received only after the application restarts. If the application fails to start or remains unresponsive for a long time, the fault may not be reported in time.
This module provides APIs for solving this issue. After the application implements FaultLogExtensionAbility, the system service is expected to start FaultLogExtensionAbility 30 minutes later after the application crashes or freezes.
You can subscribe to and process fault events through onFaultReportReady.
NOTE
- The initial APIs of this module are supported since API version 21. Newly added APIs will be marked with a superscript to indicate their earliest API version.
- The APIs of this module can be used only in the stage model.
- Exceptions may occur if some APIs are called by this module. For details, see Appendix.
Modules to Import
import { FaultLogExtensionAbility } from '@kit.PerformanceAnalysisKit';
FaultLogExtensionAbility
Implements the delayed fault notification. You can subscribe to and process fault events through onFaultReportReady.
NOTE
- After the FaultLogExtensionAbility is started, the fault handling can be completed only in a short period of time. It is recommended that the handling time be less than 10 seconds. If the handling is not complete within the timeout interval, you can save the status in onDisconnect.
- The timer starts when the application triggers a crash or freeze event for the first time after the device is powered on or FaultLogExtensionAbility is started last time. When a crash or screen freeze event is repeatedly triggered before FaultLogExtensionAbility is started, the timer will not restart.
- If FaultLogExtensionAbility crashes, it will not be restarted by the system service.
Properties
System capability: SystemCapability.HiviewDFX.Hiview.FaultLogger
| Name | Type | Read-Only | Optional | Description |
|---|---|---|---|---|
| context | FaultLogExtensionContext | No | No | Context of the FaultLogExtensionAbility. This context is inherited from ExtensionContext. |
onConnect
onConnect(): void
Called to perform the initialization operation when the system service completes the connection. This API can be overridden selectively.
System capability: SystemCapability.HiviewDFX.Hiview.FaultLogger
Example
export default class MyFaultLogExtension extends FaultLogExtensionAbility {
onConnect() {
console.info('onConnect');
}
}
onDisconnect
onDisconnect(): void
Called to release resources and clear the running status when the system service completes the disconnection. This API can be overridden selectively.
System capability: SystemCapability.HiviewDFX.Hiview.FaultLogger
Example
export default class MyFaultLogExtension extends FaultLogExtensionAbility {
onDisconnect() {
console.info('onDisconnect');
}
}
onFaultReportReady
onFaultReportReady(): void
Called to subscribe to and process fault events when the system service notifies the FaultLogExtensionAbility to process faults.
System capability: SystemCapability.HiviewDFX.Hiview.FaultLogger
Example
import { hiAppEvent } from '@kit.PerformanceAnalysisKit';
export default class MyFaultLogExtension extends FaultLogExtensionAbility {
onFaultReportReady() {
hiAppEvent.addWatcher({
name: "watcher",
appEventFilters: [
{
domain: hiAppEvent.domain.OS,
names: [hiAppEvent.event.APP_CRASH, hiAppEvent.event.APP_FREEZE]
}
],
onReceive: (domain: string, appEventGroups: Array<hiAppEvent.AppEventGroup>) => {
// Process the fault event.
}
});
}
}
Appendix
The following table lists the APIs that cannot be called by this module.
你可能感兴趣的鸿蒙文章
openharmony 鸿蒙 errorcode-hisysevent-sys
openharmony 鸿蒙 capi-hitrace-hitraceid
openharmony 鸿蒙 capi-hidebug-hidebug-threadcpuusage
openharmony 鸿蒙 js-apis-loglibrary-sys
openharmony 鸿蒙 capi-hiappevent-h
openharmony 鸿蒙 capi-hidebug-hidebug-jsstackframe