openharmony 鸿蒙 js-apis-hiviewdfx-FaultLogExtensionAbility

2026-08-25 浏览 (1)

@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

NameTypeRead-OnlyOptionalDescription
contextFaultLogExtensionContextNoNoContext 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.

KitModule
AVSessionKit@ohos.multimedia.avsession (AVSession Management)
AbilityKit@ohos.UIAbilityContext
ArkUI@ohos.window (Window)
AudioKit@ohos.multimedia.audio (Audio Management)
BackgroundTasksKit@ohos.backgroundTaskManager (Background Task Management)
BackgroundTasksKit@ohos.reminderAgent (reminderAgent)
BackgroundTasksKit@ohos.reminderAgentManager (Agent-Powered Reminders)
BackgroundTasksKit@ohos.resourceschedule.backgroundTaskManager (Background Task Management)
BasicServicesKit@ohos.power (System Power Management)
BasicServicesKit@ohos.wallpaper (Wallpaper)
CameraKit@ohos.multimedia.camera (Camera Management)
CameraKit@ohos.multimedia.cameraPicker (Camera Picker)
ConnectivityKit@ohos.wifiManager (WLAN)
ConnectivityKit@ohos.wifiManagerExt (WLAN Extension)
ConnectivityKit@ohos.wifiext (WLAN Extension)
IMEKit@ohos.inputMethod (Input Method Framework)
MediaLibraryKit@ohos.multimedia.movingphotoview (MovingPhotoView)
NotificationKit@ohos.notification (Notification)
NotificationKit@ohos.notificationManager (NotificationManager)
NotificationKit@ohos.notificationSubscribe (NotificationSubscribe)
SensorServiceKit@ohos.vibrator (Vibrator)
TelephonyKit@ohos.telephony.call (Call)
TelephonyKit@ohos.telephony.sim (SIM Management)
TelephonyKit@ohos.telephony.sms (SMS)
UserAuthenticationKit@ohos.userIAM.faceAuth (Facial Authentication)
UserAuthenticationKit@ohos.userIAM.userAuth (User Authentication)

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-log-h

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

openharmony 鸿蒙 capi-hitrace

openharmony 鸿蒙 capi-hiappevent-param-h

openharmony 鸿蒙 capi-hidebug-hidebug-stackframe

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/mNpjpVz0