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    | thermallevel | 热等级阈值 | int | 根据产品的热等级进行定义,当设备热等级小于等于该阈值时,其状态为充电空闲状态。 |
46    | soc | 电池电量阈值 | int | 0~100,当设备电量大于等于该阈值时,其状态为充电空闲状态。 |
47    | charging | 电池是否在充电 | int | 1为正在充电,0为不在充电。 |
48    | current | 电池充电电流阈值 | int | 单位为mA,当电池充电电流大于等于该阈值时,其状态为充电空闲状态。 |
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. 参考[默认充电空闲状态配置文件夹中的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`目录下
60
61    ```shell
62    import("//build/ohos.gni")                      # 引用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 ]       # 安装到vendor目录下的必要配置
68        part_name = "product_rk3568"                # part_name暂定为product_rk3568,以实现后续编译,产品定制根据需要自行修改
69    }
70    ```
71
725. 将编译目标添加到[ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build)的"module_list"中,例如:
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", // 添加thermal_service_config的编译
85                ]
86            }
87        },
88        "subsystem": "product_hihope"
89    }
90    ```
91    “//vendor/hihope/rk3568/thermal/”为文件夹路径,“profile”为创建的文件夹名字,“thermal_service_config”为编译目标。
92
936. 参考《[快速入门](../quick-start/quickstart-overview.md)》编译定制版本,编译命令如下:
94
95    ```shell
96    ./build.sh --product-name rk3568 --ccache
97    ```
98
997. 将定制版本烧录到DAYU200开发板中。
100
101### 调测验证
102
1031. 开机后,进入shell命令行:
104    ```shell
105    hdc shell
106    ```
107
1082. 获取当前充电空闲状态。
109    ```shell
110    hidumper -s 3303 -a -i
111    ```
112
113    查看定制后的充电空闲状态结果如下:
114    ```shell
115    -------------------------------[ability]-------------------------------
116
117
118    ----------------------------------ThermalService---------------------------------
119    thermallevel: 1
120    soc: 100
121    charging: 1
122    current: 1000
123    ```
124
125## 参考
126开发过程中可参考的配置文件路径:[默认充电空闲状态源码路径](https://gitee.com/openharmony/powermgr_thermal_manager/blob/master/services/native/profile/thermal_service_config.xml)
127
128打包路径:`/vendor/etc/thermal_config/hdf`
129
130
131
132