1e41f4b71Sopenharmony_ci# Subscribing to Common Events in Static Mode (for System Applications Only)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## When to Use
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciA static subscriber is started once it receives a target event published by the system or application. At the same time, the [onReceiveEvent()](../../reference/apis-basic-services-kit/js-apis-application-staticSubscriberExtensionAbility-sys.md#staticsubscriberextensionabilityonreceiveevent) callback is triggered,
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciin which you can implement the service logic. For example, if an application needs to execute some initialization tasks during device power-on, the application can subscribe to the power-on event in static mode. After receiving the power-on event, the application is started to execute the initialization tasks.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciSubscribing to a common event in static mode is achieved by configuring a declaration file and implementing a class that inherits from [StaticSubscriberExtensionAbility](../../reference/apis-basic-services-kit/js-apis-application-staticSubscriberExtensionAbility-sys.md).
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci> **NOTE**
12e41f4b71Sopenharmony_ci>
13e41f4b71Sopenharmony_ci> The static subscription mode has negative impact on system power consumption. Therefore, exercise caution when using this mode.
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## How to Develop
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci1. Declare a static subscriber.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci   To declare a static subscriber, create an ExtensionAbility, which is derived from the **StaticSubscriberExtensionAbility** class, in the project.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci   You can implement service logic in the [`onReceiveEvent()`](../../reference/apis-basic-services-kit/js-apis-application-staticSubscriberExtensionAbility-sys.md#staticsubscriberextensionabilityonreceiveevent) callback.
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci   ```ts
24e41f4b71Sopenharmony_ci   import { commonEventManager, StaticSubscriberExtensionAbility } from '@kit.BasicServicesKit';
25e41f4b71Sopenharmony_ci   import { hilog } from '@kit.PerformanceAnalysisKit';
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ci   const TAG: string = 'StaticSubscriber';
28e41f4b71Sopenharmony_ci   const DOMAIN_NUMBER: number = 0xFF00;
29e41f4b71Sopenharmony_ci   
30e41f4b71Sopenharmony_ci   export default class StaticSubscriber extends StaticSubscriberExtensionAbility {
31e41f4b71Sopenharmony_ci     onReceiveEvent(event: commonEventManager.CommonEventData): void {
32e41f4b71Sopenharmony_ci       hilog.info(DOMAIN_NUMBER, TAG, 'onReceiveEvent, event: ' + event.event);
33e41f4b71Sopenharmony_ci       //...
34e41f4b71Sopenharmony_ci     }
35e41f4b71Sopenharmony_ci   }
36e41f4b71Sopenharmony_ci   ```
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci2. Configure static subscriber settings.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci   After writing the static subscriber code, configure the subscriber in the [module.json5](../../quick-start/module-configuration-file.md) file.
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci   ```json
43e41f4b71Sopenharmony_ci   {
44e41f4b71Sopenharmony_ci     "module": {
45e41f4b71Sopenharmony_ci   	...
46e41f4b71Sopenharmony_ci       "extensionAbilities": [
47e41f4b71Sopenharmony_ci         {
48e41f4b71Sopenharmony_ci           "name": "StaticSubscriber",
49e41f4b71Sopenharmony_ci           "srcEntry": "./ets/staticsubscriber/StaticSubscriber.ets",
50e41f4b71Sopenharmony_ci           "description": "$string:StaticSubscriber_desc",
51e41f4b71Sopenharmony_ci           "icon": "$media:app_icon",
52e41f4b71Sopenharmony_ci           "label": "$string:StaticSubscriber_label",
53e41f4b71Sopenharmony_ci           "type": "staticSubscriber",
54e41f4b71Sopenharmony_ci           "exported": false,
55e41f4b71Sopenharmony_ci           "metadata": [
56e41f4b71Sopenharmony_ci             {
57e41f4b71Sopenharmony_ci               "name": "ohos.extension.staticSubscriber",
58e41f4b71Sopenharmony_ci               "resource": "$profile:staticsubscriber"
59e41f4b71Sopenharmony_ci             }
60e41f4b71Sopenharmony_ci           ]
61e41f4b71Sopenharmony_ci         }
62e41f4b71Sopenharmony_ci       ],
63e41f4b71Sopenharmony_ci   	...
64e41f4b71Sopenharmony_ci     }
65e41f4b71Sopenharmony_ci   }
66e41f4b71Sopenharmony_ci   ```
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci   Some fields in the file are described as follows:
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci   - **srcEntry**: entry file path of the ExtensionAbility, that is, the file path of the static subscriber declared in Step 2.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci   - **type**: ExtensionAbility type. For a static subscriber, set this field to **staticSubscriber**.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci   - **metadata**: level-2 configuration file information of the ExtensionAbility. The configuration information varies according to the ExtensionAbility type. Therefore, you must use different config files to indicate the specific configuration.
75e41f4b71Sopenharmony_ci        - **name**: name of the ExtensionAbility. For a static subscriber, declare the name as **ohos.extension.staticSubscriber** for successful identification.
76e41f4b71Sopenharmony_ci        - **resource**: path that stores the ExtensionAbility configuration, which is customizable. In this example, the path is **resources/base/profile/subscribe.json**.
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci3. Configure the level-2 configuration file to which the metadata points.
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci   ```json
82e41f4b71Sopenharmony_ci   {
83e41f4b71Sopenharmony_ci     "commonEvents": [
84e41f4b71Sopenharmony_ci       {
85e41f4b71Sopenharmony_ci         "name": "StaticSubscriber",
86e41f4b71Sopenharmony_ci         "permission": "",
87e41f4b71Sopenharmony_ci         "events": [
88e41f4b71Sopenharmony_ci           "usual.event.AIRPLANE_MODE"
89e41f4b71Sopenharmony_ci         ]
90e41f4b71Sopenharmony_ci       }
91e41f4b71Sopenharmony_ci     ]
92e41f4b71Sopenharmony_ci   }
93e41f4b71Sopenharmony_ci   ```
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci   If the level-2 configuration file is not declared in this format, the file cannot be identified. Some fields in the file are described as follows:
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci   - **name**: name of the ExtensionAbility, which must be the same as the name of **extensionAbility** declared in **module.json5**.
98e41f4b71Sopenharmony_ci   - **permission**: permission required for the publisher. If a publisher without the required permission attempts to publish an event, the event is regarded as invalid and will not be published.
99e41f4b71Sopenharmony_ci   - **events**: list of target events to subscribe to.
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci4. Modify the [preset configuration file](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/preinstall-config/install_list_capability.json) of the device, that is, the **/system/variant/phone/base/etc/app/install_list_capability.json** file on the device. When the device is started, this file is read. During application installation, the common event type specified by **allowCommonEvent** in the file is authorized. The **install_list_capability.json** file contains the following fields:
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci   - **bundleName**: bundle name of the application.
104e41f4b71Sopenharmony_ci   - **app_signature**: fingerprint information of the application. For details about how to configure fingerprint information, see [Application Privilege Configuration](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/subsys-app-privilege-config-guide.md#configuration-in-install_list_capabilityjson), or obtain and enter the app ID using [Bundle Manager](https://gitee.com/openharmony/docs/blob/master/en/application-dev/tools/bm-tool.md).
105e41f4b71Sopenharmony_ci   - **allowCommonEvent**: type of common event that can be started by static broadcast.
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci   ```json
108e41f4b71Sopenharmony_ci   [
109e41f4b71Sopenharmony_ci     ...
110e41f4b71Sopenharmony_ci     {
111e41f4b71Sopenharmony_ci       "bundleName": "com.samples.stageprocessthread", // Bundle name.
112e41f4b71Sopenharmony_ci       "app_signature": ["****"], // Fingerprint information.
113e41f4b71Sopenharmony_ci       "allowCommonEvent": ["usual.event.AIRPLANE_MODE"] // Type of common event that can be started by static broadcast.
114e41f4b71Sopenharmony_ci     }
115e41f4b71Sopenharmony_ci   ]
116e41f4b71Sopenharmony_ci   ```
117e41f4b71Sopenharmony_ci   
118e41f4b71Sopenharmony_ci   > **NOTE**
119e41f4b71Sopenharmony_ci   >
120e41f4b71Sopenharmony_ci   > The **install_list_capability.json** file is available only for preinstalled applications.
121