1e41f4b71Sopenharmony_ci# Default Hibernation Behavior Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciBy 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.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### Constraints
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ciThe configuration paths for battery level customization are subject to the configuration policy.
12e41f4b71Sopenharmony_ciThe 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.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## How to Develop
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### Setting Up the Environment
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**Hardware requirements:**
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciDevelopment board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**Environment requirements:**
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciFor details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci### Getting Started with Development
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ciThe following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate default hibernation behavior customization.
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci1. Create the `power_manager` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci2. 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:
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci    ```text
35e41f4b71Sopenharmony_ci    profile
36e41f4b71Sopenharmony_ci    ├── BUILD.gn
37e41f4b71Sopenharmony_ci    ├── power_suspend.json
38e41f4b71Sopenharmony_ci    ```
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci3. Write the custom `power_suspend.json` file that contains the custom default hibernation behavior. The following is an example of hibernation behavior configuration:
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci    ```json
43e41f4b71Sopenharmony_ci    {
44e41f4b71Sopenharmony_ci        "powerkey": {
45e41f4b71Sopenharmony_ci            "action": 1,
46e41f4b71Sopenharmony_ci            "delayMs": 0
47e41f4b71Sopenharmony_ci        },
48e41f4b71Sopenharmony_ci        "timeout": {
49e41f4b71Sopenharmony_ci            "action": 1,
50e41f4b71Sopenharmony_ci            "delayMs": 0
51e41f4b71Sopenharmony_ci        },
52e41f4b71Sopenharmony_ci        "lid": {
53e41f4b71Sopenharmony_ci            "action": 1,
54e41f4b71Sopenharmony_ci            "delayMs": 0
55e41f4b71Sopenharmony_ci        },
56e41f4b71Sopenharmony_ci        "switch": {
57e41f4b71Sopenharmony_ci            "action": 1,
58e41f4b71Sopenharmony_ci            "delayMs": 0
59e41f4b71Sopenharmony_ci        }
60e41f4b71Sopenharmony_ci    }
61e41f4b71Sopenharmony_ci    ```
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ci    **Table 1** Description of hibernation sources
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci    | Hibernation Source| Description|
66e41f4b71Sopenharmony_ci    | -------- | -------- |
67e41f4b71Sopenharmony_ci    | powerkey | Hibernation by power button|
68e41f4b71Sopenharmony_ci    | timeout | Hibernation by timeout|
69e41f4b71Sopenharmony_ci    | lid | Hibernation by lid|
70e41f4b71Sopenharmony_ci    | switch | Hibernation by switch|
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci    **Table 2** Description of the hibernation source configuration
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci    | Item| Description|
75e41f4b71Sopenharmony_ci    | -------- | -------- |
76e41f4b71Sopenharmony_ci    | action | Action to take after the screen is turned off. Set this parameter to an enumerated value. For details, see Table 3.|
77e41f4b71Sopenharmony_ci    | delayMs | Delay, in ms.|
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci    **Table 3** Description of action
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci    | action | Value| Description|
82e41f4b71Sopenharmony_ci    | -------- | -------- | -------- |
83e41f4b71Sopenharmony_ci    | ACTION_NONE | 0 | No action.|
84e41f4b71Sopenharmony_ci    | ACTION_AUTO_SUSPEND | 1 | Automatically entering the sleep mode.|
85e41f4b71Sopenharmony_ci    | ACTION_FORCE_SUSPEND | 2 | Forcibly entering the sleep mode.|
86e41f4b71Sopenharmony_ci    | ACTION_HIBERNATE | 3 | Entering the hibernation state.|
87e41f4b71Sopenharmony_ci    | ACTION_SHUTDOWN | 4 | Shutting down the system.|
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci4. 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:
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci    ```shell
92e41f4b71Sopenharmony_ci    import("//build/ohos.gni")               # Reference build/ohos.gni.
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("suspend_config") {
95e41f4b71Sopenharmony_ci        source = "power_suspend.json"
96e41f4b71Sopenharmony_ci        relative_install_dir = "power_config"
97e41f4b71Sopenharmony_ci        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
98e41f4b71Sopenharmony_ci        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
99e41f4b71Sopenharmony_ci    }
100e41f4b71Sopenharmony_ci    ```
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci5. 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:
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci    ```json
105e41f4b71Sopenharmony_ci    {
106e41f4b71Sopenharmony_ci        "parts": {
107e41f4b71Sopenharmony_ci            "product_rk3568": {
108e41f4b71Sopenharmony_ci                "module_list": [
109e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
110e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
111e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
112e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
113e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/etc:product_etc_conf",
114e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/power_manager/profile:wakeup_config" // Add the configuration for building of suspend_config.
115e41f4b71Sopenharmony_ci                ]
116e41f4b71Sopenharmony_ci            }
117e41f4b71Sopenharmony_ci        },
118e41f4b71Sopenharmony_ci        "subsystem": "product_hihope"
119e41f4b71Sopenharmony_ci    }
120e41f4b71Sopenharmony_ci    ```
121e41f4b71Sopenharmony_ci    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.
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci    ```shell
126e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
127e41f4b71Sopenharmony_ci    ```
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board.
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci### Debugging and Verification
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci1. Customize hibernation sources in the `power_suspend.json` file.
134e41f4b71Sopenharmony_ci    ```json
135e41f4b71Sopenharmony_ci    {
136e41f4b71Sopenharmony_ci        "powerkey": {
137e41f4b71Sopenharmony_ci            "action": 4,
138e41f4b71Sopenharmony_ci            "delayMs": 0
139e41f4b71Sopenharmony_ci        },
140e41f4b71Sopenharmony_ci        "timeout": {
141e41f4b71Sopenharmony_ci            "action": 1,
142e41f4b71Sopenharmony_ci            "delayMs": 0
143e41f4b71Sopenharmony_ci        },
144e41f4b71Sopenharmony_ci        "lid": {
145e41f4b71Sopenharmony_ci            "action": 1,
146e41f4b71Sopenharmony_ci            "delayMs": 0
147e41f4b71Sopenharmony_ci        },
148e41f4b71Sopenharmony_ci        "switch": {
149e41f4b71Sopenharmony_ci            "action": 1,
150e41f4b71Sopenharmony_ci            "delayMs": 0
151e41f4b71Sopenharmony_ci        }
152e41f4b71Sopenharmony_ci    }
153e41f4b71Sopenharmony_ci    ```
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci2. Power on the device, and then press the power button.
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci    The device is powered off.
158e41f4b71Sopenharmony_ci
159e41f4b71Sopenharmony_ci3. Power on the device again, and then wait for a while.
160e41f4b71Sopenharmony_ci
161e41f4b71Sopenharmony_ci    The device screen is turned off.
162