目录

Introduction to HiAppEvent

Overview

HiAppEvent is an event subscription and event recording mechanism provided by the system for app developers. It supports recording fault, statistical, security, and behavior events during app running, helping you locate issues, analyze app running status, and collect statistics on visits, user activity, operation habits, and other key factors that affect user experience.

Basic Concepts

Logging: a function that logs changes caused by user operations to provide service data for development, product, and O&M analysis.

Event subscription: You can use the addWatcher API of HiAppEvent to register a watcher for system events or application events that you concern. In this way, when the subscribed event occurs, you can receive and process the event callback information.

Implementation Principles

[h2]System Event Subscription Mechanism

In the current system application sandbox mechanism, an application process can access only its own application sandbox directory. For details, see Application Sandbox. However, the system event information is not stored in the application sandbox directory. As a result, the information cannot be directly obtained.

The application calls the addWatcher API of HiAppEvent to subscribe to system events and create a shared directory. When the application process is faulty, the DFX system captures the related information, generates events and logs, and writes them to the shared directory. After detecting an event, HiAppEvent sends the event to the application.

[h2]Application Event Subscription Mechanism

After calling the addWatcher API to subscribe to the application event, the application must call the write API to log application events.

HiAppEvent associates application events based on the event domain and event name, and sends the events to the application using the callback set through the addWatcher API.

If an application has subscribed to an event but exits before the callback is triggered, the callback of the event will be executed after the application calls addWatcher at the next startup. For example, if an application subscribes to the crash event and exits due to a crash, the event callback is executed after addWatcher is called upon the next startup.

Constraints

Currently, apps include various types such as standard apps, app clones, atomic services, and input method apps. The subscription specifications for system events vary across different app types. Starting from API version 22, the HiAppEvent system event subscription capability supports input method apps. For details, see the following table:

System Event Name Application Clone Subscription Atomic Service Subscription Input Method Application Subscription
Crash event Supported Supported Supported
Application freeze event Supported Supported Supported
Application freeze warning event Supported Supported Supported
Resource leak event Supported Supported Supported
Address sanitizer event Supported Not supported Supported
Main thread jank event Supported Supported Supported
Task execution timeout event Supported Not supported Supported
Application killed event Supported Supported Supported
Time-consuming launch event Not supported Supported Not supported
Scrolling frame loss event Not supported Supported Not supported
High CPU usage event Not supported Not supported Supported
Battery usage statistics event Not supported Not supported Supported
Audio jank event Not supported Not supported Not supported
ArkWeb scrolling frame loss event Supported Supported Supported

System Event Fault Log Directory Specifications

HiAppEvent supports subscribing to system events. Some event information contains the external_log and page_switch_log fields, which include log path information. The current fault log directory specifications are as follows. Note that the directory specifications may be updated with version evolution.

Fault Log File Directory Directory Contents Directory Space Limit
/data/storage/el2/log/hiappevent Crash event logs, application freeze logs, address boundary violation event logs, task execution timeout event logs, and CPU high-load event logs.

Default: 5 MB.

Note: When minidump is enabled, the limit is adjusted to 35 MB. When minidump is disabled, the limit is restored to 5 MB.

/data/storage/el2/log/watchdog Main thread timeout event logs and frame drop event logs. 10 MB
/data/storage/el2/log/resourcelimit Resource leak event logs. 2048 MB
/data/storage/el2/log/page_switch Page switch logs. 18320 KB. Page switch logs are automatically aged by the system when the limit is reached.