1# Default Hibernation Behavior Customization
2
3## Overview
4
5### Introduction
6
7By default, after a device screen is turned off, OpenHarmony starts the running lock loop detection thread and then enters the hibernation state. For different devices, the mode of turning off the screen is different, which can be closing the lid, setting a timeout, or pressing the power button. Besides, the default hibernation behavior is also different, which can be performing no action, powering off the screen, or entering the hibernation state. To address this issue, OpenHarmony provides the default hibernation behavior customization function, allowing you to customize the default hibernation behavior depending on your hardware specifications.
8
9### Constraints
10
11The configuration paths for battery level customization are subject to the configuration policy.
12The configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_policy). In this development guide, `/vendor` is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.
13
14## How to Develop
15
16### Setting Up the Environment
17
18**Hardware requirements:**
19
20Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
21
22**Environment requirements:**
23
24For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
25
26### Getting Started with Development
27
28The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate default hibernation behavior customization.
29
301. Create the `power_manager` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
31
322. Create a target folder by referring to the [default folder of hibernation behavior configuration](https://gitee.com/openharmony/powermgr_power_manager/tree/master/services/native/profile), and install it in `/vendor/hihope/rk3568/power_manager`. The content is as follows:
33
34    ```text
35    profile
36    ├── BUILD.gn
37    ├── power_suspend.json
38    ```
39
403. Write the custom `power_suspend.json` file that contains the custom default hibernation behavior. The following is an example of hibernation behavior configuration:
41
42    ```json
43    {
44        "powerkey": {
45            "action": 1,
46            "delayMs": 0
47        },
48        "timeout": {
49            "action": 1,
50            "delayMs": 0
51        },
52        "lid": {
53            "action": 1,
54            "delayMs": 0
55        },
56        "switch": {
57            "action": 1,
58            "delayMs": 0
59        }
60    }
61    ```
62
63    **Table 1** Description of hibernation sources
64
65    | Hibernation Source| Description|
66    | -------- | -------- |
67    | powerkey | Hibernation by power button|
68    | timeout | Hibernation by timeout|
69    | lid | Hibernation by lid|
70    | switch | Hibernation by switch|
71
72    **Table 2** Description of the hibernation source configuration
73
74    | Item| Description|
75    | -------- | -------- |
76    | action | Action to take after the screen is turned off. Set this parameter to an enumerated value. For details, see Table 3.|
77    | delayMs | Delay, in ms.|
78
79    **Table 3** Description of action
80
81    | action | Value| Description|
82    | -------- | -------- | -------- |
83    | ACTION_NONE | 0 | No action.|
84    | ACTION_AUTO_SUSPEND | 1 | Automatically entering the sleep mode.|
85    | ACTION_FORCE_SUSPEND | 2 | Forcibly entering the sleep mode.|
86    | ACTION_HIBERNATE | 3 | Entering the hibernation state.|
87    | ACTION_SHUTDOWN | 4 | Shutting down the system.|
88
894. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_power_manager/blob/master/services/native/profile/BUILD.gn) file in the default folder of hibernation behavior configuration to pack the `power_suspend.json` file to the `/vendor/etc/power_config` directory. The configuration is as follows:
90
91    ```shell
92    import("//build/ohos.gni")               # Reference build/ohos.gni.
93
94    ohos_prebuilt_etc("suspend_config") {
95        source = "power_suspend.json"
96        relative_install_dir = "power_config"
97        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
98        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
99    }
100    ```
101
1025. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build) in the `/vendor/hihope/rk3568` directory. For example:
103
104    ```json
105    {
106        "parts": {
107            "product_rk3568": {
108                "module_list": [
109                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
110                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
111                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
112                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
113                    "//vendor/hihope/rk3568/etc:product_etc_conf",
114                    "//vendor/hihope/rk3568/power_manager/profile:wakeup_config" // Add the configuration for building of suspend_config.
115                ]
116            }
117        },
118        "subsystem": "product_hihope"
119    }
120    ```
121    In the preceding code, `//vendor/hihope/rk3568/power_manager/` is the folder path, `profile` is the folder name, and `suspend_config` is the build target.
122
1236. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
124
125    ```shell
126    ./build.sh --product-name rk3568 --ccache
127    ```
128
1297. Burn the customized version to the DAYU200 development board.
130
131### Debugging and Verification
132
1331. Customize hibernation sources in the `power_suspend.json` file.
134    ```json
135    {
136        "powerkey": {
137            "action": 4,
138            "delayMs": 0
139        },
140        "timeout": {
141            "action": 1,
142            "delayMs": 0
143        },
144        "lid": {
145            "action": 1,
146            "delayMs": 0
147        },
148        "switch": {
149            "action": 1,
150            "delayMs": 0
151        }
152    }
153    ```
154
1552. Power on the device, and then press the power button.
156
157    The device is powered off.
158
1593. Power on the device again, and then wait for a while.
160
161    The device screen is turned off.
162