1# 热场景定制开发指导
2
3## 概述
4
5### 简介
6
7OpenHarmony默认提供了热场景的特性。在设备使用过程中,比如游戏、拍照、通话时需要保证性能、温度和功耗的平衡。在不同场景下,热管理的策略会有所不同,如游戏场景下不会降低屏幕亮度,但是在不同的产品上对热场景的定义是不同的,产品希望根据产品的设计规格来定制此特性。OpenHarmony提供了热场景的定制方式,产品定制开发者可根据产品的设计规格来定制这些特性。
8
9### 约束与限制
10
11产品定制的配置路径,需要根据[配置策略](https://gitee.com/openharmony/customization_config_policy)决定。本开发指导中的定制路径以`/vendor`进行举例,请开发者根据具体的产品配置策略,修改定制路径。
12
13## 开发指导
14
15### 搭建环境
16
17设备要求:
18
19标准系统开发板,如DAYU200/Hi3516DV300开源套件。
20
21环境要求:
22
23Linux调测环境,相关要求和配置可参考《[快速入门](../quick-start/quickstart-overview.md)》。
24
25### 开发步骤
26
27本文以[DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)为例介绍热场景的定制方法。
28
291. 在产品目录[(/vendor/hihope/rk3568)](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568)下创建thermal文件夹。
30
312. 参考[默认热场景的配置文件夹](https://gitee.com/openharmony/powermgr_thermal_manager/tree/master/services/native/profile)创建目标文件夹,并安装到`//vendor/hihope/rk3568/thermal`,文件格式如下:
32
33    ```text
34    profile
35    ├── BUILD.gn
36    ├── thermal_service_config.xml
37    ```
38
393. 参考[默认热场景的配置文件夹中的thermal_service_config.xml](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml)编写定制的thermal_service_config.xml。包含热场景配置说明及定制后的热场景配置如下:
40
41    **表1** 热场景配置说明
42
43    | 配置项 | 配置项描述 | 配置项参数 | 配置项参数描述 | 配置项参数类型 | 配置项参数取值范围 |
44    | -------- | -------- | -------- | -------- | -------- | -------- |
45    | name="scene" | 配置一种或多种使用场景,可以在枚举中任选 | param | 具体的使用场景:拍照、电话、游戏 | enum | cam,call,game |
46
47    screen和charge是配置的使用场景的状态,分别为是否亮屏和是否充电。
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. 外部可调用thermal service的UpdateThermalState接口设置场景状态值。
57```cpp
58bool UpdateThermalState(const std::string& tag, const std::string& val, bool isImmed = false)
59```
60| 参数 | 说明 | 类型 |
61|---|---|---|
62| tag | 场景标签 | string |
63| val | 场景状态值 | string |
64| isImmed | 是否立即更新温控动作值 | bool |
65
665. 参考[默认热场景配置文件夹中的BUILD.gn](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/BUILD.gn)编写BUILD.gn文件,将thermal_service_config.xml打包到`/vendor/etc/thermal_config`目录下
67
68    ```shell
69    import("//build/ohos.gni")                      # 引用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 ]       # 安装到vendor目录下的必要配置
75        part_name = "product_rk3568"                # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改
76    }
77    ```
78
796. 将编译目标添加到[ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build)的"module_list"中,例如:
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", // 添加thermal_service_config的编译
92                ]
93            }
94        },
95        "subsystem": "product_hihope"
96    }
97    ```
98    “//vendor/hihope/rk3568/thermal/”为文件夹路径,“profile”为创建的文件夹名字,“thermal_service_config”为编译目标。
99
1007. 参考《[快速入门](../quick-start/quickstart-overview.md)》编译定制版本,编译命令如下:
101
102    ```shell
103    ./build.sh --product-name rk3568 --ccache
104    ```
105
1068. 将定制版本烧录到DAYU200开发板中。
107
108### 调测验证
109
1101. 开机后,进入shell命令行:
111    ```shell
112    hdc shell
113    ```
114
1152. 获取当前热场景信息。
116    ```shell
117    hidumper -s 3303 -a -s
118    ```
119
120    查看定制后的热场景结果如下:
121    ```shell
122    -------------------------------[ability]-------------------------------
123
124
125    ----------------------------------ThermalService---------------------------------
126    name: scene  params: cam,call,game
127    name: screen
128    name: charge
129    ```
130
131## 参考
132开发过程中可参考的配置文件路径:[默认热场景源码路径](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml)
133
134打包路径:`/vendor/etc/thermal_config/hdf`
135
136