1e41f4b71Sopenharmony_ci# Charging Idle State Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciBy 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.
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_ci
27e41f4b71Sopenharmony_ciThe following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate charging idle state customization.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci1. Create the `thermal` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci2. 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:
32e41f4b71Sopenharmony_ci     
33e41f4b71Sopenharmony_ci    ```text
34e41f4b71Sopenharmony_ci    profile
35e41f4b71Sopenharmony_ci    ├── BUILD.gn
36e41f4b71Sopenharmony_ci    ├── thermal_service_config.xml
37e41f4b71Sopenharmony_ci    ```
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci3. 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.
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci    **Table 1** Configuration items for the charging idle state
42e41f4b71Sopenharmony_ci    
43e41f4b71Sopenharmony_ci    | Configuration Item| Description| Data Type| Value Range|
44e41f4b71Sopenharmony_ci    | -------- | -------- | -------- | -------- |
45e41f4b71Sopenharmony_ci    | 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.|
46e41f4b71Sopenharmony_ci    | 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.|
47e41f4b71Sopenharmony_ci    | charging | Charging status| int | The value **1** indicates that the battery is being charged, and the value **0** indicates the opposite.|
48e41f4b71Sopenharmony_ci    | 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.|
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci    ```shell
51e41f4b71Sopenharmony_ci    <idle name="charging">
52e41f4b71Sopenharmony_ci        <thermallevel>1</thermallevel>
53e41f4b71Sopenharmony_ci        <soc>90</soc>
54e41f4b71Sopenharmony_ci        <charging>1</charging>
55e41f4b71Sopenharmony_ci        <current>1000</current>
56e41f4b71Sopenharmony_ci    </idle>
57e41f4b71Sopenharmony_ci    ```
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci4. 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:
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci    ```shell
62e41f4b71Sopenharmony_ci    import("//build/ohos.gni")                      # Reference build/ohos.gni.
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("thermal_service_config") {
65e41f4b71Sopenharmony_ci        source = "thermal_service_config.xml"
66e41f4b71Sopenharmony_ci        relative_install_dir = "thermal_config"
67e41f4b71Sopenharmony_ci        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
68e41f4b71Sopenharmony_ci        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
69e41f4b71Sopenharmony_ci    }
70e41f4b71Sopenharmony_ci    ```
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_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:
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci    ```json
75e41f4b71Sopenharmony_ci    {
76e41f4b71Sopenharmony_ci        "parts": {
77e41f4b71Sopenharmony_ci            "product_rk3568": {
78e41f4b71Sopenharmony_ci                "module_list": [
79e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
80e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
81e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
82e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
83e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/etc:product_etc_conf",
84e41f4b71Sopenharmony_ci                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // Add the configuration for building of thermal_service_config.
85e41f4b71Sopenharmony_ci                ]
86e41f4b71Sopenharmony_ci            }
87e41f4b71Sopenharmony_ci        },
88e41f4b71Sopenharmony_ci        "subsystem": "product_hihope"
89e41f4b71Sopenharmony_ci    }
90e41f4b71Sopenharmony_ci    ```
91e41f4b71Sopenharmony_ci    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.
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci    ```shell
96e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
97e41f4b71Sopenharmony_ci    ```
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board.
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci### Debugging and Verification
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci1. After startup, run the following command to launch the shell command line:
104e41f4b71Sopenharmony_ci    ```shell
105e41f4b71Sopenharmony_ci    hdc shell
106e41f4b71Sopenharmony_ci    ```
107e41f4b71Sopenharmony_ci
108e41f4b71Sopenharmony_ci2. Obtain the current charging idle state.
109e41f4b71Sopenharmony_ci    ```shell
110e41f4b71Sopenharmony_ci    hidumper -s 3303 -a -i
111e41f4b71Sopenharmony_ci    ```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci    The following is the reference charging idle state after customization:
114e41f4b71Sopenharmony_ci    ```shell
115e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci    ----------------------------------ThermalService---------------------------------
119e41f4b71Sopenharmony_ci    thermallevel: 1
120e41f4b71Sopenharmony_ci    soc: 100
121e41f4b71Sopenharmony_ci    charging: 1
122e41f4b71Sopenharmony_ci    current: 1000
123e41f4b71Sopenharmony_ci    ```
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci## Reference
126e41f4b71Sopenharmony_ciDuring 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).
127e41f4b71Sopenharmony_ci
128e41f4b71Sopenharmony_ciPacking path: `/vendor/etc/thermal_config/hdf`
129