• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Wakeup Source Customization
2
3## Overview
4
5### Introduction
6
7OpenHarmony supports multiple wakeup sources, such as the power button, keyboard, and mouse, and provides custom modes for turning on and off these wakeup sources. After a device enters the sleep state, you can turn on the screen and wake up the device by pressing the power button, keyboard, or mouse. However, different products may support different peripherals, for example, stylus or folio keyboard. To address this issue, OpenHarmony provides the wakeup source customization function, allowing you to customize wakeup sources 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 wakeup source 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 wakeup source 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_wakeup.json
38    ```
39
403. Write the custom `power_wakeup.json` file that contains the custom wakeup sources. The following is an example of wakeup source configuration:
41
42    ```json
43    {
44        "powerkey": {
45            "enable": true
46        },
47        "keyborad": {
48            "enable": true
49        },
50        "mouse": {
51            "enable": true
52        },
53        "touchscreen": {
54            "enable": true,
55            "click": 2
56        },
57        "touchpad": {
58            "enable": true
59        },
60        "pen": {
61            "enable": true
62        },
63        "lid": {
64            "enable": true
65        },
66        "switch": {
67            "enable": true
68        }
69    }
70    ```
71
72    **Table 1** Description of wakeup sources
73
74    | Wakeup Source| Description|
75    | -------- | -------- |
76    | powerkey | Wakeup by power button|
77    | keyborad | Wakeup by keyboard|
78    | mouse | Wakeup by mouse|
79    | touchscreen | Wakeup by touchscreen|
80    | touchpad | Wakeup by touchpad|
81    | pen | Wakeup by stylus|
82    | lid | Wakeup by lid|
83    | switch | Wakeup by switch|
84
85    **Table 2** Description of the wakeup source configuration
86
87    | Item| Type| Description|
88    | -------- | -------- | -------- |
89    | enable | bool | Whether to enable wakeup listening|
90    | click | int | Number of clicks|
91
92
934. 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 wakeup source configuration to pack the `power_wakeup.json` file to the `/vendor/etc/power_config` directory. The configuration is as follows:
94
95    ```shell
96    import("//build/ohos.gni")               # Reference build/ohos.gni.
97
98    ohos_prebuilt_etc("wakeup_config") {
99        source = "power_wakeup.json"
100        relative_install_dir = "power_config"
101        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
102        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
103    }
104    ```
105
1065. 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:
107
108    ```json
109    {
110        "parts": {
111            "product_rk3568": {
112                "module_list": [
113                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
114                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
115                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
116                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
117                    "//vendor/hihope/rk3568/etc:product_etc_conf",
118                    "//vendor/hihope/rk3568/power_manager/profile:wakeup_config" // Add the configuration for building of wakeup_config.
119                ]
120            }
121        },
122        "subsystem": "product_hihope"
123    }
124    ```
125    In the preceding code, `//vendor/hihope/rk3568/power_manager/` is the folder path, `profile` is the folder name, and `wakeup_config` is the build target.
126
1276. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
128
129    ```shell
130    ./build.sh --product-name rk3568 --ccache
131    ```
132
1337. Burn the customized version to the DAYU200 development board.
134
135### Debugging and Verification
136
1371. Customize wakeup sources in the `power_wakeup.json` file.
138    ```json
139    {
140        "powerkey": {
141            "enable": true
142        },
143        "keyborad": {
144            "enable": true
145        },
146        "mouse": {
147            "enable": true
148        },
149        "touchscreen": {
150            "enable": false,
151            "click": 2
152        },
153        "touchpad": {
154            "enable": false
155        },
156        "pen": {
157            "enable": false
158        },
159        "lid": {
160            "enable": false
161        },
162        "switch": {
163            "enable": false
164        }
165    }
166    ```
167
1682. After the device is powered on, press the power button to switch the device to the sleep mode. Then, press the power button again.
169
170    The device screen is turned on and the device is woken up.
171
1723. Press the power button to switch the device to the sleep mode, and then press the keyboard.
173
174    The device screen is turned on and the device is woken up.
175
1764. Press the power button to switch the device to the sleep mode, and then move the mouse.
177
178    The device screen is turned on and the device is woken up.
179