1# Thermal Policy Customization
2
3## Overview
4
5### Introduction
6
7By default, the OpenHarmony provides the thermal policy feature. Various components on a device can generate heat. Therefore, for different components, the thermal policy needs to be defined based on their thermal levels and thermal scenes. However, thermal control at different thermal levels varies according to product specifications. To address this issue, OpenHarmony provides the thermal policy 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 thermal policy 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 thermal policy configuration folder](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 thermal policy configuration folder. The following tables describe the related configuration items.
40
41    **Table 1** Description of the config configuration
42
43    | Configuration Item| Description| Type| Value Range|
44    | -------- | -------- | -------- | -------- |
45    | name | Name of the sensor cluster corresponding to the thermal policy.| string | Corresponding to the sensor cluster name defined in [Thermal Level](../subsystems/subsys-thermal_level.md).|
46    | level | Thermal level corresponding to the thermal policy.| int | Corresponding to the thermal level defined for the sensor cluster in [Thermal Level](../subsystems/subsys-thermal_level.md).|
47
48    **Table 2** Description of configuration items
49
50    | Configuration Item| Description| Type| Value Range|
51    | -------- | -------- | -------- | -------- |
52    | scene	| Application scenario.| string | Corresponding to the application scenario defined in [Thermal Scene](../subsystems/subsys-thermal_scene.md).|
53    | charge | Charging status.| int | The value **1** indicates charging, and the value **0** indicates the opposite.|
54    | screen | Screen status.| int | The value **1** indicates that the screen is on, and the value **0** indicates the opposite.|
55
56    **Table 3** Description of the node configuration
57
58    | Node| Value Type| Value Range| Description|
59    | -------- | -------- | -------- | -------- |
60    | lcd | double | 0.00~1.00 | Percentage of the screen brightness (represented by a floating point number).|
61    | cpu_big | int | Product-specific| CPU big core frequency.|
62    | cpu_med | int | Product-specific| CPU medium-core frequency.|
63    | cpu_lit | int | Product-specific| CPU small-core frequency.|
64    | process_ctrl | enum | 1: KILL_FG_PROCESS_APP<br>2: KILL_BG_PROCESS_APP<br>3: KILL_ALL_PROCESS_APP| Process control.|
65    | gpu | int | Product-specific| GPU frequency.|
66    | thermallevel | int | Corresponding to **level** defined in the **config** node| Thermal level.|
67    | current_sc | int | Product-specific| Fast charging current.|
68    | current_buck | int | Product-specific| Slow charging current.|
69    | voltage_sc | int | Product-specific| Fast charging voltage.|
70    | voltage_buck | int | Product-specific| Slow charging voltage.|
71    | volume | double | 0.00~1.00 | Volume percentage (represented by a floating point number).|
72
73    ```shell
74    <policy>
75        <config name="base_safe" level="1">
76            <lcd>1.00</lcd>
77            <lcd scene="cam">0.99</lcd>
78            <lcd scene="call">0.98</lcd>
79            <lcd scene="game">0.95</lcd>
80            <cpu_big>1992000</cpu_big>
81            <cpu_med>1991500</cpu_med>
82            <cpu_lit>1991200</cpu_lit>
83            <process_ctrl>3</process_ctrl>
84            <cpu_big scene="cam" charge="1">1991800</cpu_big>
85            <cpu_big scene="cam" charge="0">1991600</cpu_big>
86            <gpu screen="0">524288</gpu>
87            <gpu screen="1">512000</gpu>
88            <thermallevel>1</thermallevel>
89            <current_sc>1800</current_sc>
90            <current_sc scene="cam">1200</current_sc>
91            <current_buck>1200</current_buck>
92            <voltage_sc>4000</voltage_sc>
93            <voltage_buck>3000</voltage_buck>
94            <volume>1.0</volume>
95        </config>
96    <policy>
97        <config name="base_safe" level="2">
98            <lcd>0.90</lcd>
99            <lcd scene="cam">0.89</lcd>
100            <lcd scene="call">0.88</lcd>
101            <lcd scene="game">0.87</lcd>
102            <cpu_big>1991000</cpu_big>
103            <cpu_med>1990500</cpu_med>
104            <cpu_lit>1990200</cpu_lit>
105            <process_ctrl>2</process_ctrl>
106            <cpu_big scene="cam" charge="1">1990800</cpu_big>
107            <cpu_big scene="cam" charge="0">1990600</cpu_big>
108            <gpu screen="0">499712</gpu>
109            <gpu screen="1">487424</gpu>
110            <thermallevel>2</thermallevel>
111            <current_sc>1500</current_sc>
112            <current_sc scene="cam">1000</current_sc>
113            <current_buck>1000</current_buck>
114            <voltage_sc>3000</voltage_sc>
115            <voltage_buck>2000</voltage_buck>
116            <volume>0.8</volume>
117        </config>
118    </policy>
119    ```
120
1214. 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 thermal policy configuration folder to pack the `thermal_service_config.xml` file to the `/vendor/etc/thermal_config` directory. The configuration is as follows:
122
123    ```shell
124    import("//build/ohos.gni")                      # Reference build/ohos.gni.
125
126    ohos_prebuilt_etc("thermal_service_config") {
127        source = "thermal_service_config.xml"
128        relative_install_dir = "thermal_config"
129        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
130        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
131    }
132    ```
133
1345. 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:
135
136    ```json
137    {
138        "parts": {
139            "product_rk3568": {
140                "module_list": [
141                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
142                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
143                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
144                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
145                    "//vendor/hihope/rk3568/etc:product_etc_conf",
146                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // Add the configuration for building of thermal_service_config.
147                ]
148            }
149        },
150        "subsystem": "product_hihope"
151    }
152    ```
153    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.
154
1556. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
156
157    ```shell
158    ./build.sh --product-name rk3568 --ccache
159    ```
160
1617. Burn the customized version to the DAYU200 development board.
162
163### Debugging and Verification
164
1651. After startup, run the following command to launch the shell command line:
166    ```shell
167    hdc shell
168    ```
169
1702. Obtain the current thermal policy information.
171    ```shell
172    hidumper -s 3303 -a -p
173    ```
174
175    The following is the reference thermal policy result after customization:
176    ```shell
177    -------------------------------[ability]-------------------------------
178
179
180    ----------------------------------ThermalService---------------------------------
181    name: base_safe	level: 1
182    actionName: lcd	actionValue: 1.00	isProp: 0
183    actionName: lcd	actionValue: 0.99	scene: cam	isProp: 1
184    actionName: lcd	actionValue: 0.98	scene: call	isProp: 1
185    actionName: lcd	actionValue: 0.95	scene: game	isProp: 1
186    actionName: cpu_big	actionValue: 1992000	isProp: 0
187    actionName: cpu_med	actionValue: 1991500	isProp: 0
188    actionName: cpu_lit	actionValue: 1991200	isProp: 0
189    actionName: process_ctrl	actionValue: 3	isProp: 0
190    actionName: cpu_big	actionValue: 1991800	charge: 1	scene: cam	isProp: 1
191    actionName: cpu_big	actionValue: 1991600	charge: 0	scene: cam	isProp: 1
192    actionName: gpu	actionValue: 524288	screen: 0	isProp: 1
193    actionName: gpu	actionValue: 512000	screen: 1	isProp: 1
194    actionName: thermallevel	actionValue: 1	isProp: 0
195    actionName: current_sc	actionValue: 1800	isProp: 0
196    actionName: current_sc	actionValue: 1200	scene: cam	isProp: 1
197    actionName: current_buck	actionValue: 1200	isProp: 0
198    actionName: voltage_sc	actionValue: 4000	isProp: 0
199    actionName: voltage_buck	actionValue: 3000	isProp: 0
200    actionName: volume	actionValue: 1.0	isProp: 0
201    actionName: boost	actionValue: 1	isProp: 0
202
203    level: 2
204    actionName: lcd	actionValue: 0.90	isProp: 0
205    actionName: lcd	actionValue: 0.89	scene: cam	isProp: 1
206    actionName: lcd	actionValue: 0.88	scene: call	isProp: 1
207    actionName: lcd	actionValue: 0.87	scene: game	isProp: 1
208    actionName: cpu_big	actionValue: 1991000	isProp: 0
209    actionName: cpu_med	actionValue: 1990500	isProp: 0
210    actionName: cpu_lit	actionValue: 1990200	isProp: 0
211    actionName: process_ctrl	actionValue: 2	isProp: 0
212    actionName: cpu_big	actionValue: 1990800	charge: 1	scene: cam	isProp: 1
213    actionName: cpu_big	actionValue: 1990600	charge: 0	scene: cam	isProp: 1
214    actionName: gpu	actionValue: 499712	screen: 0	isProp: 1
215    actionName: gpu	actionValue: 487424	screen: 1	isProp: 1
216    actionName: thermallevel	actionValue: 2	isProp: 0
217    actionName: current_sc	actionValue: 1500	isProp: 0
218    actionName: current_sc	actionValue: 1000	scene: cam	isProp: 1
219    actionName: current_buck	actionValue: 1000	isProp: 0
220    actionName: voltage_sc	actionValue: 3000	isProp: 0
221    actionName: voltage_buck	actionValue: 2000	isProp: 0
222    actionName: volume	actionValue: 0.8	isProp: 0
223    actionName: boost	actionValue: 1	isProp: 0
224    ```
225
226## Reference
227During development, you can refer to the [default thermal policy configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
228
229Packing path: `/vendor/etc/thermal_config/hdf`
230