• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, covering the screen, 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        "tp_cover": {
61            "action": 1,
62            "delayMs": 0
63        }
64    }
65    ```
66
67    **Table 1** Description of hibernation sources
68
69    | Hibernation Source| Description|
70    | -------- | -------- |
71    | powerkey | Hibernation by power button|
72    | timeout | Hibernation by timeout|
73    | lid | Hibernation by lid|
74    | switch | Hibernation by switch|
75    | tp_cover | Hibernation by screen covering|
76
77    **Table 2** Description of the hibernation source configuration
78
79    | Item| Description|
80    | -------- | -------- |
81    | action | Action to take after the screen is turned off. Set this parameter to an enumerated value. For details, see Table 3.|
82    | delayMs | Delay, in ms.|
83
84    **Table 3** Description of action
85
86    | action | Value| Description|
87    | -------- | -------- | -------- |
88    | ACTION_NONE | 0 | No action.|
89    | ACTION_AUTO_SUSPEND | 1 | Automatically entering the sleep mode.|
90    | ACTION_FORCE_SUSPEND | 2 | Forcibly entering the sleep mode.|
91    | ACTION_HIBERNATE | 3 | Entering the hibernation state.|
92    | ACTION_SHUTDOWN | 4 | Shutting down the system.|
93
944. 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:
95
96    ```shell
97    import("//build/ohos.gni")               # Reference build/ohos.gni.
98
99    ohos_prebuilt_etc("suspend_config") {
100        source = "power_suspend.json"
101        relative_install_dir = "power_config"
102        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
103        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
104    }
105    ```
106
1075. 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:
108
109    ```json
110    {
111        "parts": {
112            "product_rk3568": {
113                "module_list": [
114                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
115                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
116                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
117                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
118                    "//vendor/hihope/rk3568/etc:product_etc_conf",
119                    "//vendor/hihope/rk3568/power_manager/profile:wakeup_config" // Add the configuration for building of suspend_config.
120                ]
121            }
122        },
123        "subsystem": "product_hihope"
124    }
125    ```
126    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.
127
1286. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
129
130    ```shell
131    ./build.sh --product-name rk3568 --ccache
132    ```
133
1347. Burn the customized version to the DAYU200 development board.
135
136### Debugging and Verification
137
1381. Customize hibernation sources in the `power_suspend.json` file.
139    ```json
140    {
141        "powerkey": {
142            "action": 4,
143            "delayMs": 0
144        },
145        "timeout": {
146            "action": 1,
147            "delayMs": 0
148        },
149        "lid": {
150            "action": 1,
151            "delayMs": 0
152        },
153        "switch": {
154            "action": 1,
155            "delayMs": 0
156        },
157        "tp_cover": {
158            "action": 1,
159            "delayMs": 0
160        }
161    }
162    ```
163
1642. Power on the device, and then press the power button.
165
166    The device is powered off.
167
1683. Power on the device again, and then wait for a while.
169
170    The device screen is turned off.
171