1# Charging Idle State Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony provides the charging idle state feature. It determines whether a device is currently in the idle state according to a thermal level, battery level, charging state, and charging current of the device. A device in this state may execute some background intensive tasks. However, the conditions that determine the charging idle state vary according to product specifications. To address this issue, OpenHarmony provides the charging idle state customization function.
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
26
27The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate charging idle state customization.
28
291. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
30
312. Create a target folder by referring to the [default folder of battery idle state configuration](https://gitee.com/openharmony/powermgr_thermal_manager/tree/master/services/native/profile), and install it in `//vendor/hihope/rk3568/thermal`. The content is as follows:
32
33    ```text
34    profile
35    ├── BUILD.gn
36    ├── thermal_service_config.xml
37    ```
38
393. Write the custom `thermal_service_config.xml` file by referring to the [thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml) file in the default folder of charging idle state configuration. The following table describes the related configuration items.
40
41    **Table 1** Configuration items for the charging idle state
42
43    | Configuration Item| Description| Data Type| Value Range|
44    | -------- | -------- | -------- | -------- |
45    | thermallevel | Thermal level threshold| int | This field is defined based on the thermal level of a device. If the thermal level of a device is less than or equal to the threshold, the device is in the charging idle state.|
46    | soc | Battery level threshold| int | The value of this field ranges from 0 to 100. If the battery level of the device is greater than or equal to the specified threshold, the device is in the charging idle state.|
47    | charging | Charging status| int | The value **1** indicates that the battery is being charged, and the value **0** indicates the opposite.|
48    | current | Battery charging current threshold| int | When the battery charging current is greater than or equal to the specified threshold (in mA), the battery is in the charging idle state.|
49
50    ```shell
51    <idle name="charging">
52        <thermallevel>1</thermallevel>
53        <soc>90</soc>
54        <charging>1</charging>
55        <current>1000</current>
56    </idle>
57    ```
58
594. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/BUILD.gn) file in the default folder of charging idle state configuration to pack the `thermal_service_config.xml` file to the `/vendor/etc/thermal_config` directory. The configuration is as follows:
60
61    ```shell
62    import("//build/ohos.gni")                      # Reference build/ohos.gni.
63
64    ohos_prebuilt_etc("thermal_service_config") {
65        source = "thermal_service_config.xml"
66        relative_install_dir = "thermal_config"
67        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
68        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
69    }
70    ```
71
725. 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:
73
74    ```json
75    {
76        "parts": {
77            "product_rk3568": {
78                "module_list": [
79                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
80                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
81                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
82                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
83                    "//vendor/hihope/rk3568/etc:product_etc_conf",
84                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // Add the configuration for building of thermal_service_config.
85                ]
86            }
87        },
88        "subsystem": "product_hihope"
89    }
90    ```
91    In the preceding code, `//vendor/hihope/rk3568/thermal/` is the folder path, `profile` is the folder name, and `thermal_service_config` is the build target.
92
936. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
94
95    ```shell
96    ./build.sh --product-name rk3568 --ccache
97    ```
98
997. Burn the customized version to the DAYU200 development board.
100
101### Debugging and Verification
102
1031. After startup, run the following command to launch the shell command line:
104    ```shell
105    hdc shell
106    ```
107
1082. Obtain the current charging idle state.
109    ```shell
110    hidumper -s 3303 -a -i
111    ```
112
113    The following is the reference charging idle state after customization:
114    ```shell
115    -------------------------------[ability]-------------------------------
116
117
118    ----------------------------------ThermalService---------------------------------
119    thermallevel: 1
120    soc: 100
121    charging: 1
122    current: 1000
123    ```
124
125## Reference
126During development, you can refer to the [default charging idle state configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
127
128Packing path: `/vendor/etc/thermal_config/hdf`
129