1# Power Mode Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony provides the power mode feature, which offers the following options: normal mode, performance mode, power-saving mode, and super power-saving mode. However, the power mode configuration varies according to hardware specifications of different products. To address this issue, OpenHarmony provides the power mode customization function, allowing you to customize power modes depending on your hardware specifications.
8
9### Basic Concepts
10
11OpenHarmony supports the following four power modes, each of which corresponds to the specified power and performance policy.
12
13- Normal mode: default power mode, in which the system brightness, screen-off time, and sleep time meet the requirements of most users.
14
15- Performance mode: power mode that emphasizes on the performance, such as increasing the system brightness, disabling the screen-off time, and preventing the system from entering the sleep mode.
16
17- Power-saving mode: power mode that emphasizes on power saving, such as decreasing the system brightness, reducing the screen-off time, and shortening the time for entering sleep mode.
18
19- Super power-saving mode: power mode that emphasizes on ultimate power saving, such as greatly decreasing the system brightness, greatly reducing the screen-off time, and greatly shortening the time for entering sleep mode.
20
21
22### Constraints
23
24The 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.
25
26## How to Develop
27
28### Setting Up the Environment
29
30**Hardware requirements:**
31
32Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
33
34**Environment requirements:**
35
36For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
37
38### Getting Started with Development
39
40The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate power mode customization.
41
421. Create the `power_manager` folder in the product directory [vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
43
442. Create a target folder by referring to the [default power mode configuration folder](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:
45
46    ```text
47    profile
48    ├── BUILD.gn
49    ├── power_mode_config.xml
50    ```
51
523. Write the custom `power_mode_config.xml` file by referring to the [power_mode_config.xml](https://gitee.com/openharmony/powermgr_power_manager/blob/master/services/native/profile/power_mode_config.xml) file in the default power mode configuration folder.
53
54    The **proxy** node is used to configure the power mode.
55
56    **Table 1** Description of the proxy node
57    | Power Mode| ID |
58    | :------ | --- |
59    | Normal mode| 600 |
60    | Power-saving mode| 601 |
61    | Performance mode| 602 |
62    | Super power-saving mode| 603 |
63
64    The **switch** node is used to configure items of the power mode.
65
66    **Table 2** Description of the **switch** node
67    | Configuration Item| ID | Value Range|
68    | :------ | ----- | ----- |
69    | Screen-off time| 101 | **value** indicates the screen-off duration, in unit of ms. It is an integer greater than or equal to **-1**. The value **-1** indicates that the screen-off function is disabled.|
70    | Auto sleep time| 102 | **value** indicates the time for automatically entering the sleep mode, in unit of ms. It is an integer greater than or equal to **-1**. The value **-1** indicates that the auto sleep function is disabled. |
71    | Automatic brightness adjustment| 103 | **value** indicates whether to enable automatic brightness adjustment. The options are as follows:<br>- **-1**: disable automatic brightness adjustment.<br>- **1**: enable automatic brightness adjustment.|
72    | Automatic screen rotation| 107 | **value** indicates whether to enable automatic screen rotation. The options are as follows:<br>- **-1**: disable automatic screen rotation.<br>- **1**: enable automatic screen rotation.|
73    | System brightness| 115 | **value** indicates the screen brightness. It is an integer ranging from 0 to 255.|
74    | Vibration switch| 120 | **value** indicates whether to enable vibration. The options are as follows:<br>- **-1**: disable vibration.<br>- **1**: enable vibration.|
75
76    The following uses the normal mode as an example:
77
78    ```xml
79    <switch_proxy version="1">
80        <proxy id="600">
81            <switch id="101" value="10000"/>
82            <switch id="102" value="0"/>
83            <switch id="103" value="-1"/>
84            <switch id="107" value="1"/>
85            <switch id="115" value="30"/>
86            <switch id="120" value="1"/>
87        </proxy>
88    ```
89
904. 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 power mode configuration folder to pack the `power_mode_config.xml` file to the `/vendor/etc/power_config` directory. The configuration is as follows:
91
92    ```shell
93    import("//base/powermgr/power_manager/powermgr.gni")
94    import("//build/ohos.gni")
95
96    ## Install vendor power_mode_config.xml to /vendor/etc/power_config/power_mode_config.xml
97    ohos_prebuilt_etc("power_mode_config_vendor") {  # custom name, for example, power_mode_config_vendor.
98    source = "power_mode_config.xml"
99    relative_install_dir = "power_config"
100    install_images = [ chipset_base_dir ]            # Required configuration for installing the power_mode_config.xml file in the vendor directory, where chipset_base_dir = "vendor". If this field is left unspecified, the power_mode_config.xml file is installed in the system directory by default.
101    part_name = "${product_rk3568}"                  # Set part_name to product_rk3568 for subsequent build.
102    }
103
104    group("power_service_config") {
105    deps = [ ":power_mode_config_vendor" ]
106    }
107
108    ```
109
1105. 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:
111
112    ```json
113    {
114      "parts": {
115        "product_rk3568": {
116          "module_list": [
117            "//vendor/hihope/rk3568/default_app_config:default_app_config",
118            "//vendor/hihope/rk3568/image_conf:custom_image_conf",
119            "//vendor/hihope/rk3568/power_manager/profile:power_mode_config_vendor", # Add the configuration for building of power_mode_config_vendor.
120            "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
121            "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
122            "//vendor/hihope/rk3568/etc:product_etc_conf"
123          ]
124        }
125      },
126      "subsystem": "product_hihope"
127    }
128    ```
129
130
1316. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
132
133    ```shell
134    ./build.sh --product-name rk3568 --ccache
135    ```
136
1377. Burn the customized version to the DAYU200 development board.
138
139### Debugging and Verification
140
1411. After startup, run the following command to launch the shell command line:
142
143    ```shell
144    hdc shell
145    ```
146
1472. Set the power mode to the normal mode, and verify the setting.
148
149    1. Set the power mode to the normal mode.
150
151        ```shell
152        power-shell setmode 600
153        ```
154
155    2. Check whether the setting of the power mode is successful.
156
157        ```shell
158        Set Mode: 600
159        Set Mode Success!
160
161        ```
162    3. Obtain the auto sleep time.
163
164        ```shell
165        hidumper -s 3301 -a -a
166
167        -------------------------------[ability]-------------------------------
168
169
170        ----------------------------------PowerManagerService---------------------------------
171        POWER STATE DUMP:
172        Current State: INACTIVE  Reason: 1  Time: 33227
173        ScreenOffTime: Timeout=10000ms
174        ··· (Only the auto sleep time configuration is displayed here. Other information is omitted.)
175
176        ```
177
178    4. Turn on the screen. If the screen turns off after 10 seconds, the setting of the auto sleep time is successful.
179
1803. Set the power mode to the power-saving mode, and verify the setting.
181
182    1. Set the power mode to the power-saving mode.
183
184        ```shell
185        power-shell setmode 601
186        ```
187
188    2. Check whether the setting of the power mode is successful.
189
190        ```shell
191        Set Mode: 601
192        Set Mode Success!
193
194        ```
195    3. Obtain the auto sleep time.
196
197        ```shell
198        hidumper -s 3301 -a -a
199
200        -------------------------------[ability]-------------------------------
201
202
203        ----------------------------------PowerManagerService---------------------------------
204        POWER STATE DUMP:
205        Current State: INACTIVE  Reason: 1  Time: 33227
206        ScreenOffTime: Timeout=20000ms
207        ··· (Only the auto sleep time configuration is displayed here. Other information is omitted.)
208
209        ```
210
211    4. Turn on the screen. If the screen turns off after 20 seconds, the setting of the auto sleep time is successful.
212
2134. Set the power mode to the performance mode, and verify the setting.
214
215    1. Set the power mode to the performance mode.
216
217        ```shell
218        power-shell setmode 602
219        ```
220
221    2. Check whether the setting of the power mode is successful.
222
223        ```shell
224        Set Mode: 602
225        Set Mode Success!
226
227        ```
228    3. Obtain the auto sleep time.
229
230        ```shell
231        hidumper -s 3301 -a -a
232
233        -------------------------------[ability]-------------------------------
234
235
236        ----------------------------------PowerManagerService---------------------------------
237        POWER STATE DUMP:
238        Current State: INACTIVE  Reason: 1  Time: 33227
239        ScreenOffTime: Timeout=30000ms
240        ··· (Only the auto sleep time configuration is displayed here. Other information is omitted.)
241
242        ```
243
244    4. Turn on the screen. If the screen turns off after 30 seconds, the setting of the auto sleep time is successful.
245
2465. Set the power mode to the super power-saving mode, and verify the setting.
247
248    1. Set the power mode to the super power-saving mode.
249
250        ```shell
251        power-shell setmode 603
252        ```
253
254    2. Check whether the setting of the power mode is successful.
255
256        ```shell
257        Set Mode: 603
258        Set Mode Success!
259
260        ```
261    3. Obtain the auto sleep time.
262
263        ```shell
264        hidumper -s 3301 -a -a
265
266        -------------------------------[ability]-------------------------------
267
268
269        ----------------------------------PowerManagerService---------------------------------
270        POWER STATE DUMP:
271        Current State: INACTIVE  Reason: 1  Time: 33227
272        ScreenOffTime: Timeout=40000ms
273        ··· (Only the auto sleep time configuration is displayed here. Other information is omitted.)
274
275        ```
276
277    4. Turn on the screen. If the screen turns off after 40 seconds, the setting of the auto sleep time is successful.
278
279## Reference
280
281During development, you can refer to the [default power mode configuration](https://gitee.com/openharmony/powermgr_power_manager/blob/master/services/native/profile/power_mode_config.xml):
282
283Packing path: `/system/etc/power_config/power_mode_config.xml`
284