1# Battery Level Customization 2 3## Overview 4 5### Introduction 6 7By default, OpenHarmony provides the battery level based on the current battery power, such as the full battery level, high battery level, low battery level, and extremely low battery level. It can generate an alert or take required service processing based on the current battery level. However, the battery level specifications vary according to products. To address this issue, OpenHarmony provides the function of customizing battery levels. 8 9### Constraints 10 11 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 battery level customization. 29 301. Create the `battery` 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 battery level configuration](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile), and install it in `//vendor/hihope/rk3568/battery`. The content is as follows: 33 34 ```text 35 profile 36 ├── BUILD.gn 37 ├── battery_config.json 38 ``` 39 403. Write the custom `battery_config.json` file by referring to the [battery_config.json](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json) file in the default folder of battery level configuration. For example: 41 42 ```json 43 { 44 "soc": { 45 "shutdown": 5, 46 "critical": 10, 47 "warning": 15, 48 "low": 30, 49 "normal": 60, 50 "high": 90, 51 "full": 100 52 } 53 } 54 ``` 55 56 **Table 1** Battery level configuration 57 58 | Battery Level| Battery Volume| Description| 59 | -------- | -------- | -------- | 60 | shutdown | 5 | Power-off battery level| 61 | critical | 10 | Extremely low battery level| 62 | warning | 15 | Alarm battery level| 63 | low | 30 | Low battery level| 64 | normal | 60 | Normal battery level| 65 | high | 90 | High battery level| 66 | full | 100 | Full battery level| 67 68 694. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/BUILD.gn) file in the default folder of battery level configuration to pack the `battery_config.json` file to the `//vendor/etc/battery` directory. The configuration is as follows: 70 71 ```shell 72 import("//build/ohos.gni") # Reference build/ohos.gni. 73 74 ohos_prebuilt_etc("battery_config") { 75 source = "battery_config.json" 76 relative_install_dir = "battery" 77 install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory. 78 part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. 79 } 80 ``` 81 825. 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: 83 84 ```json 85 { 86 "parts": { 87 "product_rk3568": { 88 "module_list": [ 89 "//vendor/hihope/rk3568/default_app_config:default_app_config", 90 "//vendor/hihope/rk3568/image_conf:custom_image_conf", 91 "//vendor/hihope/rk3568/preinstall-config:preinstall-config", 92 "//vendor/hihope/rk3568/resourceschedule:resourceschedule", 93 "//vendor/hihope/rk3568/etc:product_etc_conf", 94 "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config. 95 ] 96 } 97 }, 98 "subsystem": "product_hihope" 99 } 100 ``` 101 In the preceding code, `//vendor/hihope/rk3568/battery/` is the folder path, `profile` is the folder name, and `battery_config` is the build target. 102 1036. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 104 105 ```shell 106 ./build.sh --product-name rk3568 --ccache 107 ``` 108 1097. Burn the customized version to the DAYU200 development board. 110 111### Debugging and Verification 112 1131. After startup, run the following command to launch the shell command line: 114 ``` 115 hdc shell 116 ``` 117 1182. Go to the custom battery level configuration directory. The path of DAYU200 is used as an example. 119 ``` 120 cd /data/service/el0/battery/battery/ 121 ``` 122 1233. Modify the charging status, simulate reporting of the battery power change, and check whether the returned battery level is correct. The following uses the default charging type as an example. 124 125 1. Modify the battery power. 126 ``` 127 echo 100 > capacity 128 ``` 129 2. Report the battery power change to obtain the current battery level. 130 ``` 131 hidumper -s 3302 -a -i 132 ``` 133 3. Check whether the battery level is correct. 134 135 ``` 136 -------------------------------[ability]------------------------------- 137 138 139 ----------------------------------BatteryService--------------------------------- 140 Current time: 2017-08-05 17:22:48.589 141 142 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 143 144 batteryLevel: 1 145 146 ······ 147 ``` 148 149 4. Modify the battery power. 150 ``` 151 echo 90 > capacity 152 ``` 153 5. Report the battery power change to obtain the current battery level. 154 ``` 155 hidumper -s 3302 -a -i 156 ``` 157 6. Check whether the battery level is correct. 158 159 ``` 160 -------------------------------[ability]------------------------------- 161 162 163 ----------------------------------BatteryService--------------------------------- 164 Current time: 2017-08-05 17:24:29.716 165 166 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 167 168 batteryLevel: 2 169 170 ······ 171 ``` 172 173 7. Modify the battery power. 174 ``` 175 echo 60 > capacity 176 ``` 177 8. Report the battery power change to obtain the current battery level. 178 ``` 179 hidumper -s 3302 -a -i 180 ``` 181 9. Check whether the battery level is correct. 182 183 ``` 184 -------------------------------[ability]------------------------------- 185 186 187 ----------------------------------BatteryService--------------------------------- 188 Current time: 2017-08-05 17:25:09.837 189 190 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 191 192 batteryLevel: 3 193 194 ······ 195 ``` 196 197 10. Modify the battery power. 198 ``` 199 echo 30 > capacity 200 ``` 201 11. Report the battery power change to obtain the current battery level. 202 ``` 203 hidumper -s 3302 -a -i 204 ``` 205 12. Check whether the battery level is correct. 206 207 ``` 208 -------------------------------[ability]------------------------------- 209 210 211 ----------------------------------BatteryService--------------------------------- 212 Current time: 2017-08-05 17:26:20.495 213 214 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 215 216 batteryLevel: 4 217 218 ······ 219 ``` 220 221 13. Modify the battery power. 222 ``` 223 echo 15 > capacity 224 ``` 225 14. Report the battery power change to obtain the current battery level. 226 ``` 227 hidumper -s 3302 -a -i 228 ``` 229 15. Check whether the battery level is correct. 230 231 ``` 232 -------------------------------[ability]------------------------------- 233 234 235 ----------------------------------BatteryService--------------------------------- 236 Current time: 2017-08-05 17:27:05.312 237 238 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 239 240 batteryLevel: 5 241 242 ······ 243 ``` 244 245 16. Modify the battery power. 246 ``` 247 echo 10 > capacity 248 ``` 249 17. Report the battery power change to obtain the current battery level. 250 ``` 251 hidumper -s 3302 -a -i 252 ``` 253 18. Check whether the battery level is correct. 254 255 ``` 256 -------------------------------[ability]------------------------------- 257 258 259 ----------------------------------BatteryService--------------------------------- 260 Current time: 2017-08-05 17:27:56.270 261 262 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 263 264 batteryLevel: 6 265 266 ······ 267 ``` 268 269 19. Modify the battery power. 270 ``` 271 echo 5 > capacity 272 ``` 273 20. Report the battery power change to obtain the current battery level. 274 ``` 275 hidumper -s 3302 -a -i 276 ``` 277 21. Check whether the battery level is correct. 278 279 ``` 280 -------------------------------[ability]------------------------------- 281 282 283 ----------------------------------BatteryService--------------------------------- 284 Current time: 2017-08-05 17:28:38.066 285 286 ··· (Only the battery level configuration is displayed here. Other information is omitted.) 287 288 batteryLevel: 7 289 290 ······ 291 ``` 292 293## Reference 294During development, you can refer to the [default battery level configuration](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json), as shown below: 295 296 297 298```json 299{ 300 "soc": { 301 "shutdown": 1, 302 "critical": 5, 303 "warning": 10, 304 "low": 20, 305 "normal": 90, 306 "high": 99, 307 "full": 100 308 } 309} 310``` 311 312Packing path: /system/etc/battery 313