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