1e41f4b71Sopenharmony_ci# Battery Temperature Protection Customization 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## Overview 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci### Introduction 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciOpenHarmony 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. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci### Constraints 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_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. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## How to Develop 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci### Setting Up the Environment 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci**Hardware requirements:** 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciDevelopment board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Environment requirements:** 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciFor details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md). 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci### Getting Started with Development 26e41f4b71Sopenharmony_ciThe following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate charging type customization. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci1. Create the battery folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568). 29e41f4b71Sopenharmony_ci 30e41f4b71Sopenharmony_ci2. 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: 31e41f4b71Sopenharmony_ci 32e41f4b71Sopenharmony_ci ```text 33e41f4b71Sopenharmony_ci profile 34e41f4b71Sopenharmony_ci ├── BUILD.gn 35e41f4b71Sopenharmony_ci ├── battery_config.json 36e41f4b71Sopenharmony_ci ``` 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci3. 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: 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci ```json 41e41f4b71Sopenharmony_ci { 42e41f4b71Sopenharmony_ci "temperature": { 43e41f4b71Sopenharmony_ci "high": 500, 44e41f4b71Sopenharmony_ci "low": -400 45e41f4b71Sopenharmony_ci } 46e41f4b71Sopenharmony_ci } 47e41f4b71Sopenharmony_ci ``` 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci **Table 1** Description of temperature protection configuration 50e41f4b71Sopenharmony_ci | Temperature Protection Threshold| Temperature (°C)| 51e41f4b71Sopenharmony_ci | -------- | -------- | 52e41f4b71Sopenharmony_ci | high | 600 | 53e41f4b71Sopenharmony_ci | low | -500 | 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci4. 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: 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci ```shell 59e41f4b71Sopenharmony_ci import("//build/ohos.gni") # Reference build/ohos.gni. 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci ohos_prebuilt_etc("battery_config") { 62e41f4b71Sopenharmony_ci source = "battery_config.json" 63e41f4b71Sopenharmony_ci relative_install_dir = "battery" 64e41f4b71Sopenharmony_ci install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory. 65e41f4b71Sopenharmony_ci part_name = "product_rk3568" # Set part_name to product_rk3568 for subsequent build. 66e41f4b71Sopenharmony_ci } 67e41f4b71Sopenharmony_ci ``` 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_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: 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci ```json 72e41f4b71Sopenharmony_ci { 73e41f4b71Sopenharmony_ci "parts": { 74e41f4b71Sopenharmony_ci "product_rk3568": { 75e41f4b71Sopenharmony_ci "module_list": [ 76e41f4b71Sopenharmony_ci "//vendor/hihope/rk3568/default_app_config:default_app_config", 77e41f4b71Sopenharmony_ci "//vendor/hihope/rk3568/image_conf:custom_image_conf", 78e41f4b71Sopenharmony_ci "//vendor/hihope/rk3568/preinstall-config:preinstall-config", 79e41f4b71Sopenharmony_ci "//vendor/hihope/rk3568/resourceschedule:resourceschedule", 80e41f4b71Sopenharmony_ci "//vendor/hihope/rk3568/etc:product_etc_conf", 81e41f4b71Sopenharmony_ci "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config. 82e41f4b71Sopenharmony_ci ] 83e41f4b71Sopenharmony_ci } 84e41f4b71Sopenharmony_ci }, 85e41f4b71Sopenharmony_ci "subsystem": "product_hihope" 86e41f4b71Sopenharmony_ci } 87e41f4b71Sopenharmony_ci ``` 88e41f4b71Sopenharmony_ci In the preceding code, `//vendor/hihope/rk3568/battery/` is the folder path, `profile` is the folder name, and `battery_config` is the build target. 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci ```shell 93e41f4b71Sopenharmony_ci ./build.sh --product-name rk3568 --ccache 94e41f4b71Sopenharmony_ci ``` 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board. 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci### Debugging and Verification 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci1. After startup, run the following command to launch the shell command line: 101e41f4b71Sopenharmony_ci ``` 102e41f4b71Sopenharmony_ci hdc shell 103e41f4b71Sopenharmony_ci ``` 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci2. Go to the custom battery temperature configuration directory. The path of DAYU200 is used as an example. 106e41f4b71Sopenharmony_ci ``` 107e41f4b71Sopenharmony_ci cd /data/service/el0/battery/battery 108e41f4b71Sopenharmony_ci ``` 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci3. Modify the battery temperature. The following uses the default power temperature protection configuration as an example. 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci ``` 113e41f4b71Sopenharmony_ci echo 700 > temp 114e41f4b71Sopenharmony_ci ``` 115e41f4b71Sopenharmony_ci4. Report the battery information change to trigger temperature protection. 116e41f4b71Sopenharmony_ci ``` 117e41f4b71Sopenharmony_ci hidumper -s 3302 -a -r 118e41f4b71Sopenharmony_ci ``` 119e41f4b71Sopenharmony_ci The device is powered off. 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci5. Upon restarting, launch the shell command line, and modify the battery temperature. 122e41f4b71Sopenharmony_ci ``` 123e41f4b71Sopenharmony_ci echo -600 > temp 124e41f4b71Sopenharmony_ci ``` 125e41f4b71Sopenharmony_ci6. Report the battery information change to trigger temperature protection. 126e41f4b71Sopenharmony_ci ``` 127e41f4b71Sopenharmony_ci hidumper -s 3302 -a -r 128e41f4b71Sopenharmony_ci ``` 129e41f4b71Sopenharmony_ci The device is powered off. 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci7. Customize the temperature protection threshold configuration. For example: 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci ```json 134e41f4b71Sopenharmony_ci { 135e41f4b71Sopenharmony_ci "temperature": { 136e41f4b71Sopenharmony_ci "high": 500, 137e41f4b71Sopenharmony_ci "low": -400 138e41f4b71Sopenharmony_ci } 139e41f4b71Sopenharmony_ci } 140e41f4b71Sopenharmony_ci ``` 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ci8. Modify the temperature protection threshold. 143e41f4b71Sopenharmony_ci ``` 144e41f4b71Sopenharmony_ci echo 550 > temp 145e41f4b71Sopenharmony_ci ``` 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci9. Report the battery information change to trigger temperature protection. 148e41f4b71Sopenharmony_ci ``` 149e41f4b71Sopenharmony_ci hidumper -s 3302 -a -r 150e41f4b71Sopenharmony_ci ``` 151e41f4b71Sopenharmony_ci The device is powered off. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci10. Upon restarting, launch the shell command line, and modify the temperature protection threshold. 154e41f4b71Sopenharmony_ci ``` 155e41f4b71Sopenharmony_ci echo -450 > temp 156e41f4b71Sopenharmony_ci ``` 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci11. Report the battery information change to trigger temperature protection. 159e41f4b71Sopenharmony_ci ``` 160e41f4b71Sopenharmony_ci hidumper -s 3302 -a -r 161e41f4b71Sopenharmony_ci ``` 162e41f4b71Sopenharmony_ci The device is powered off. 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci## Reference 165e41f4b71Sopenharmony_ciDuring 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: 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci```json 168e41f4b71Sopenharmony_ci{ 169e41f4b71Sopenharmony_ci "temperature": { 170e41f4b71Sopenharmony_ci "high": 600, 171e41f4b71Sopenharmony_ci "low": -500 172e41f4b71Sopenharmony_ci } 173e41f4b71Sopenharmony_ci} 174e41f4b71Sopenharmony_ci``` 175e41f4b71Sopenharmony_ciPacking path: `/system/etc/battery` 176