1# Thermal Scene Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony provides the thermal scene feature. During device usage, for example, gaming, photographing, or calling, the system will try to balance the performance, temperature, and power consumption. The thermal policy is usually scenario-specific. For example, the thermal policy in the gaming scenario does not decrease the screen brightness. However, the thermal scene definition varies according to product specifications. To address this issue, OpenHarmony provides the thermal scene 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 scene 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 scene 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 scene configuration folder. The following table describes the related configuration items.
40
41    **Table 1** Configuration items for the thermal scene
42
43    | Configuration Item| Description| Parameter| Parameter Description| Parameter Type| Value Range|
44    | -------- | -------- | -------- | -------- | -------- | -------- |
45    | name="scene" | One or more thermal scenes specified by enum values.| param | Available thermal scenes: photographing, calling, and gaming.| enum | cam, call, and game|
46
47    **screen** and **charge** indicate the thermal status of the application; and specifically, whether the screen is turned on and whether the battery is being charged.
48
49    ```shell
50    <state>
51        <item name="scene" param="cam,call,game"/>
52        <item name="screen"/>
53        <item name="charge"/>
54    </state>
55    ```
564. An external system can call the **UpdateThermalState** API of the thermal service to set the thermal status.
57```cpp
58bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false)
59```
60| Parameter| Description| Type|
61|---|---|---|
62| tag | Scenario tag.| string |
63| val | Scenario status value.| string |
64| isImmed | Whether to update the thermal control action value immediately.| bool |
65
665. 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 scene configuration folder to pack the `thermal_service_config.xml` file to the `/vendor/etc/thermal_config` directory. The configuration is as follows:
67
68    ```shell
69    import("//build/ohos.gni")                      # Reference build/ohos.gni.
70
71    ohos_prebuilt_etc("thermal_service_config") {
72        source = "thermal_service_config.xml"
73        relative_install_dir = "thermal_config"
74        install_images = [ chipset_base_dir ]       # Required configuration for installing the thermal_service_config.xml file in the vendor directory.
75        part_name = "product_rk3568"                # Set part_name to product_rk3568 for subsequent build. You can change it as required.
76    }
77    ```
78
796. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build). For example:
80
81    ```json
82    {
83        "parts": {
84            "product_rk3568": {
85                "module_list": [
86                    "//vendor/hihope/rk3568/default_app_config:default_app_config",
87                    "//vendor/hihope/rk3568/image_conf:custom_image_conf",
88                    "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
89                    "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
90                    "//vendor/hihope/rk3568/etc:product_etc_conf",
91                    "//vendor/hihope/rk3568/thermal/profile:thermal_service_config", // Add the configuration for building of thermal_service_config.
92                ]
93            }
94        },
95        "subsystem": "product_hihope"
96    }
97    ```
98    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.
99
1007. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
101
102    ```shell
103    ./build.sh --product-name rk3568 --ccache
104    ```
105
1068. Burn the customized version to the DAYU200 development board.
107
108### Debugging and Verification
109
1101. After startup, run the following command to launch the shell command line:
111    ```shell
112    hdc shell
113    ```
114
1152. Obtain the current thermal scene information.
116    ```shell
117    hidumper -s 3303 -a -s
118    ```
119
120    The following is the reference thermal scene result after customization:
121    ```shell
122    -------------------------------[ability]-------------------------------
123
124
125    ----------------------------------ThermalService---------------------------------
126    name: scene  params: cam,call,game
127    name: screen
128    name: charge
129    ```
130
131## Reference
132During development, you can refer to the [default thermal scene configuration](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml).
133
134Packing path: `/vendor/etc/thermal_config/hdf`
135