1e41f4b71Sopenharmony_ci# Wakeup Source Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciOpenHarmony 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.
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 wakeup source 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 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:
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci    ```text
35e41f4b71Sopenharmony_ci    profile
36e41f4b71Sopenharmony_ci    ├── BUILD.gn
37e41f4b71Sopenharmony_ci    ├── power_wakeup.json
38e41f4b71Sopenharmony_ci    ```
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci3. Write the custom `power_wakeup.json` file that contains the custom wakeup sources. The following is an example of wakeup source configuration:
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci    ```json
43e41f4b71Sopenharmony_ci    {
44e41f4b71Sopenharmony_ci        "powerkey": {
45e41f4b71Sopenharmony_ci            "enable": true
46e41f4b71Sopenharmony_ci        },
47e41f4b71Sopenharmony_ci        "keyborad": {
48e41f4b71Sopenharmony_ci            "enable": true
49e41f4b71Sopenharmony_ci        },
50e41f4b71Sopenharmony_ci        "mouse": {
51e41f4b71Sopenharmony_ci            "enable": true
52e41f4b71Sopenharmony_ci        },
53e41f4b71Sopenharmony_ci        "touchscreen": {
54e41f4b71Sopenharmony_ci            "enable": true,
55e41f4b71Sopenharmony_ci            "click": 2
56e41f4b71Sopenharmony_ci        },
57e41f4b71Sopenharmony_ci        "touchpad": {
58e41f4b71Sopenharmony_ci            "enable": true
59e41f4b71Sopenharmony_ci        },
60e41f4b71Sopenharmony_ci        "pen": {
61e41f4b71Sopenharmony_ci            "enable": true
62e41f4b71Sopenharmony_ci        },
63e41f4b71Sopenharmony_ci        "lid": {
64e41f4b71Sopenharmony_ci            "enable": true
65e41f4b71Sopenharmony_ci        },
66e41f4b71Sopenharmony_ci        "switch": {
67e41f4b71Sopenharmony_ci            "enable": true
68e41f4b71Sopenharmony_ci        }
69e41f4b71Sopenharmony_ci    }
70e41f4b71Sopenharmony_ci    ```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci    **Table 1** Description of wakeup sources
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci    | Wakeup Source| Description|
75e41f4b71Sopenharmony_ci    | -------- | -------- |
76e41f4b71Sopenharmony_ci    | powerkey | Wakeup by power button|
77e41f4b71Sopenharmony_ci    | keyborad | Wakeup by keyboard|
78e41f4b71Sopenharmony_ci    | mouse | Wakeup by mouse|
79e41f4b71Sopenharmony_ci    | touchscreen | Wakeup by touchscreen|
80e41f4b71Sopenharmony_ci    | touchpad | Wakeup by touchpad|
81e41f4b71Sopenharmony_ci    | pen | Wakeup by stylus|
82e41f4b71Sopenharmony_ci    | lid | Wakeup by lid|
83e41f4b71Sopenharmony_ci    | switch | Wakeup by switch|
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci    **Table 2** Description of the wakeup source configuration
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci    | Item| Type| Description|
88e41f4b71Sopenharmony_ci    | -------- | -------- | -------- |
89e41f4b71Sopenharmony_ci    | enable | bool | Whether to enable wakeup listening|
90e41f4b71Sopenharmony_ci    | click | int | Number of clicks|
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_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 wakeup source configuration to pack the `power_wakeup.json` file to the `/vendor/etc/power_config` directory. The configuration is as follows:
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci    ```shell
96e41f4b71Sopenharmony_ci    import("//build/ohos.gni")               # Reference build/ohos.gni.
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("wakeup_config") {
99e41f4b71Sopenharmony_ci        source = "power_wakeup.json"
100e41f4b71Sopenharmony_ci        relative_install_dir = "power_config"
101e41f4b71Sopenharmony_ci        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
102e41f4b71Sopenharmony_ci        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
103e41f4b71Sopenharmony_ci    }
104e41f4b71Sopenharmony_ci    ```
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_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:
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci    ```json
109e41f4b71Sopenharmony_ci    {
110e41f4b71Sopenharmony_ci        "parts": {
111e41f4b71Sopenharmony_ci            "product_rk3568": {
112e41f4b71Sopenharmony_ci                "module_list": [
113e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
114e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
115e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
116e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
117e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/etc:product_etc_conf",
118e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/power_manager/profile:wakeup_config" // Add the configuration for building of wakeup_config.
119e41f4b71Sopenharmony_ci                ]
120e41f4b71Sopenharmony_ci            }
121e41f4b71Sopenharmony_ci        },
122e41f4b71Sopenharmony_ci        "subsystem": "product_hihope"
123e41f4b71Sopenharmony_ci    }
124e41f4b71Sopenharmony_ci    ```
125e41f4b71Sopenharmony_ci    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.
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ci    ```shell
130e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
131e41f4b71Sopenharmony_ci    ```
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board.
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci### Debugging and Verification
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci> **NOTE**
138e41f4b71Sopenharmony_ci> 
139e41f4b71Sopenharmony_ci> Currently, the Double-tap to wake feature is not supported. That is, **enable** in **touchscreen** can only be set to **false**. This feature will be provided in later versions.
140e41f4b71Sopenharmony_ci
141e41f4b71Sopenharmony_ci1. Customize wakeup sources in the `power_wakeup.json` file.
142e41f4b71Sopenharmony_ci    ```json
143e41f4b71Sopenharmony_ci    {
144e41f4b71Sopenharmony_ci        "powerkey": {
145e41f4b71Sopenharmony_ci            "enable": true
146e41f4b71Sopenharmony_ci        },
147e41f4b71Sopenharmony_ci        "keyborad": {
148e41f4b71Sopenharmony_ci            "enable": true
149e41f4b71Sopenharmony_ci        },
150e41f4b71Sopenharmony_ci        "mouse": {
151e41f4b71Sopenharmony_ci            "enable": true
152e41f4b71Sopenharmony_ci        },
153e41f4b71Sopenharmony_ci        "touchscreen": {
154e41f4b71Sopenharmony_ci            "enable": false,
155e41f4b71Sopenharmony_ci            "click": 2
156e41f4b71Sopenharmony_ci        },
157e41f4b71Sopenharmony_ci        "touchpad": {
158e41f4b71Sopenharmony_ci            "enable": false
159e41f4b71Sopenharmony_ci        },
160e41f4b71Sopenharmony_ci        "pen": {
161e41f4b71Sopenharmony_ci            "enable": false
162e41f4b71Sopenharmony_ci        },
163e41f4b71Sopenharmony_ci        "lid": {
164e41f4b71Sopenharmony_ci            "enable": false
165e41f4b71Sopenharmony_ci        },
166e41f4b71Sopenharmony_ci        "switch": {
167e41f4b71Sopenharmony_ci            "enable": false
168e41f4b71Sopenharmony_ci        }
169e41f4b71Sopenharmony_ci    }
170e41f4b71Sopenharmony_ci    ```
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci2. After the device is powered on, press the power button to switch the device to the sleep mode. Then, press the power button again.
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci    The device screen is turned on and the device is woken up.
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci3. Press the power button to switch the device to the sleep mode, and then press the keyboard.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci    The device screen is turned on and the device is woken up.
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci4. Press the power button to switch the device to the sleep mode, and then move the mouse.
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ci    The device screen is turned on and the device is woken up.
183