1# Battery Temperature Protection Customization 2 3## Overview 4 5### Introduction 6 7OpenHarmony provides battery temperature protection by default. When a device is used in different environments, the battery temperature may become excessively high or low due to the impact of ambient environment. In such a case, the protection measures, for example, device shutdown, must be taken to ensure the device safety. However, the supported temperature range varies according to products. To address this issue, OpenHarmony provides the function of customizing the temperature range for battery protection. 8 9### Constraints 10 11The 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. 12 13## How to Develop 14 15### Setting Up the Environment 16 17**Hardware requirements:** 18 19Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite. 20 21**Environment requirements:** 22 23For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md). 24 25### Getting Started with Development 26The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate charging type customization. 27 281. Create the battery folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). 29 302. Create a target folder by referring to the [default folder of power temperature projection 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: 31 32 ```text 33 profile 34 ├── BUILD.gn 35 ├── battery_config.json 36 ``` 37 383. Write the custom `battery_config.json` file by referring to the `battery_config.json` file in the default folder of power temperature projection configuration. For example: 39 40 ```json 41 { 42 "temperature": { 43 "high": 500, 44 "low": -400 45 } 46 } 47 ``` 48 49 **Table 1** Description of temperature protection configuration 50 | Temperature Protection Threshold| Temperature (°C)| 51 | -------- | -------- | 52 | high | 600 | 53 | low | -500 | 54 55 564. Write the `BUILD.gn` file by referring to the `BUILD.gn` in the default folder of power temperature projection configuration to pack the `battery_config.json` file to the `//vendor/etc/battery` directory. The configuration is as follows: 57 58 ```shell 59 import("//build/ohos.gni") # Reference build/ohos.gni. 60 61 ohos_prebuilt_etc("battery_config") { 62 source = "battery_config.json" 63 relative_install_dir = "battery" 64 install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory. 65 part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. 66 } 67 ``` 68 695. 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: 70 71 ```json 72 { 73 "parts": { 74 "product_rk3568": { 75 "module_list": [ 76 "//vendor/hihope/rk3568/default_app_config:default_app_config", 77 "//vendor/hihope/rk3568/image_conf:custom_image_conf", 78 "//vendor/hihope/rk3568/preinstall-config:preinstall-config", 79 "//vendor/hihope/rk3568/resourceschedule:resourceschedule", 80 "//vendor/hihope/rk3568/etc:product_etc_conf", 81 "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config. 82 ] 83 } 84 }, 85 "subsystem": "product_hihope" 86 } 87 ``` 88 In the preceding code, `//vendor/hihope/rk3568/battery/` is the folder path, `profile` is the folder name, and `battery_config` is the build target. 89 906. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 91 92 ```shell 93 ./build.sh --product-name rk3568 --ccache 94 ``` 95 967. Burn the customized version to the DAYU200 development board. 97 98### Debugging and Verification 99 1001. After startup, run the following command to launch the shell command line: 101 ``` 102 hdc shell 103 ``` 104 1052. Go to the custom battery temperature configuration directory. The path of DAYU200 is used as an example. 106 ``` 107 cd /data/service/el0/battery/battery 108 ``` 109 1103. Modify the battery temperature. The following uses the default power temperature protection configuration as an example. 111 112 ``` 113 echo 700 > temp 114 ``` 1154. Report the battery information change to trigger temperature protection. 116 ``` 117 hidumper -s 3302 -a -r 118 ``` 119 The device is powered off. 120 1215. Upon restarting, launch the shell command line, and modify the battery temperature. 122 ``` 123 echo -600 > temp 124 ``` 1256. Report the battery information change to trigger temperature protection. 126 ``` 127 hidumper -s 3302 -a -r 128 ``` 129 The device is powered off. 130 1317. Customize the temperature protection threshold configuration. For example: 132 133 ```json 134 { 135 "temperature": { 136 "high": 500, 137 "low": -400 138 } 139 } 140 ``` 141 1428. Modify the temperature protection threshold. 143 ``` 144 echo 550 > temp 145 ``` 146 1479. Report the battery information change to trigger temperature protection. 148 ``` 149 hidumper -s 3302 -a -r 150 ``` 151 The device is powered off. 152 15310. Upon restarting, launch the shell command line, and modify the temperature protection threshold. 154 ``` 155 echo -450 > temp 156 ``` 157 15811. Report the battery information change to trigger temperature protection. 159 ``` 160 hidumper -s 3302 -a -r 161 ``` 162 The device is powered off. 163 164## Reference 165During development, you can refer to the [default power temperature protection configuration](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile/), as shown below: 166 167```json 168{ 169 "temperature": { 170 "high": 600, 171 "low": -500 172 } 173} 174``` 175Packing path: `/system/etc/battery` 176