openharmony之充电空闲状态定制开发

概述

简介

OpenHarmony系统默认集成充电空闲状态检测功能。该功能通过综合评估设备热等级、电池电量、充电状态及充电电流等参数,判断设备是否满足空闲状态条件,从而触发后台任务执行。由于不同设备的硬件特性存在差异,各产品需根据实际设计需求进行定制化配置。

本指导文档以DAYU200开发套件为例,详细说明定制开发流程,开发者可根据具体产品需求调整实现方案。

关于电源管理模块学习欢迎订阅专栏文章《openharmony之电源管理模块需求定制总结

约束与限制

  • 配置文件存储路径需遵循产品配置策略,示例中采用/vendor路径,实际开发中应根据项目规范调整
  • 热等级阈值需结合设备散热能力设定,建议通过温控测试确定合理范围
  • 电池参数配置应符合电池安全规范,避免设置超出硬件规格的电流阈值

开发流程

开发环境要求

  • 硬件平台:DAYU200/Hi3516DV300等标准系统开发板
  • 开发环境:基于Linux的编译环境

定制开发步骤

1. 创建配置目录

在产品专属目录下创建温控配置目录:

bash 复制代码
mkdir -p /vendor/hihope/rk3568/thermal
2. 配置文件准备

从默认配置目录获取模板文件:

bash 复制代码
cp -r /services/native/profile/thermal_service_config.xml /vendor/hihope/rk3568/thermal/
3. 配置参数说明

XML配置文件包含以下关键参数:

参数项 数据类型 取值范围 配置说明
thermallevel int 0-7 设备热等级阈值,当当前热等级≤该值时进入空闲状态
soc int 0-100 电池电量阈值,当电量≥该值时进入空闲状态
charging int 0/1 充电状态标识,1表示正在充电
current int ≥0(单位:mA) 充电电流阈值,当实际电流≥该值时进入空闲状态

打包路径:/vendor/etc/thermal_config/hdf

示例配置:

xml 复制代码
<idle name="charging">
    <thermallevel>1</thermallevel>  <!-- 热等级≤1 -->
    <soc>90</soc>                   <!-- 电量≥90% -->
    <charging>1</charging>          <!-- 正在充电 -->
    <current>1000</current>         <!-- 电流≥1000mA -->
</idle>
4. 构建配置文件

创建BUILD.gn构建配置:

gn 复制代码
import("//build/ohos.gni")

ohos_prebuilt_etc("thermal_service_config") {
    source = "thermal_service_config.xml"
    relative_install_dir = "thermal_config"
    install_images = [ chipset_base_dir ]
    part_name = "product_rk3568"
}
5. 集成编译配置

ohos.build中添加编译模块:

json 复制代码
{
    "parts": {
        "product_rk3568": {
            "module_list": [
                ...
                "//vendor/hihope/rk3568/thermal/profile:thermal_service_config"
            ]
        }
    },
    "subsystem": "product_hihope"
}
6. 编译与烧录

执行编译命令:

bash 复制代码
./build.sh --product-name rk3568 --ccache

将生成的固件烧录至开发板完成部署。

调测验证

状态检测方法

  1. 通过HDC工具进入设备shell:

    bash 复制代码
    hdc shell
  2. 执行状态查询命令:

    bash 复制代码
    hidumper -s 3303 -a -i

预期输出示例

复制代码
-------------------------------[ability]-------------------------------
----------------------------------ThermalService---------------------------------
thermallevel: 1
soc: 90
charging: 1
current: 1000

参考资源

  • 默认配置文件路径:/services/native/profile/thermal_service_config.xml
  • 系统配置文档:/resources/base/etc/thermal_config/thermal_service_config.xml
  • 温控服务源码:/services/native/thermal/thermal_service.cpp

注意:实际开发中应结合设备硬件规格进行参数优化,建议通过温升测试验证配置有效性。电流阈值设置应留有安全余量,避免触发过流保护。

附录:完整配置文件示例

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 2022-2023 Huawei Device Co., Ltd.
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  -->

<thermal version="0.01" product="lya">
    <base>
        <item tag="history_temp_count" value="10"/>
        <item tag="temperature_query_enum" value="soc,battery,shell,cpu,charger,ambient,ap,pa"/>
        <item tag="sim_tz" value="1"/>
    </base>

    <level>
        <sensor_cluster name="screenoff_charge" sensor="battery">
            <state screen="0" charge="1"/>
            <item level="1" threshold="40000" threshold_clr="38000"/>
            <item level="2" threshold="43000" threshold_clr="41000"/>
        </sensor_cluster>
        <sensor_cluster name="base_safe" sensor="battery,charger,cpu,soc">
            <item level="1" threshold="40000,38000,30000,40000" threshold_clr="38000,36000,28000,38000"/>
            <item level="2" threshold="43000,41000,32000,42000" threshold_clr="41000,39000,30000,40000"/>
            <item level="3" threshold="46000,44000,34000,44000" threshold_clr="44000,42000,32000,42000"/>
            <item level="4" threshold="48000,46000,36000,46000" threshold_clr="46000,44000,34000,44000"/>
        </sensor_cluster>
        <sensor_cluster name="warm_5G" sensor="pa" aux_sensor="ambient">
            <item level="1" threshold="40000" threshold_clr="38000" aux_trigger_range="5000_35000"/>
            <item level="2" threshold="43000" threshold_clr="41000" aux_trigger_range="5000_35000"/>
            <item level="3" threshold="45000" threshold_clr="44000" aux_trigger_range="5000_35000"/>
        </sensor_cluster>
        <sensor_cluster name="warm_safe" sensor="ap,soc" aux_sensor="ambient,shell">
            <item level="1" threshold="75000,30000" threshold_clr="71000,28000" aux_trigger_range="0_900000,0_40000"/>
        </sensor_cluster>
        <sensor_cluster name="high_safe" sensor="shell">
            <item level="1" threshold="40000" threshold_clr="38000" temp_rise_rate="1.5"/>
            <item level="2" threshold="43000" threshold_clr="41000" temp_rise_rate="1.5"/>
            <item level="3" threshold="46000" threshold_clr="44000" temp_rise_rate="1.5"/>
            <item level="4" threshold="48000" threshold_clr="47000" temp_rise_rate="1.5"/>
        </sensor_cluster>
        <sensor_cluster name="cold_safe" sensor="battery,soc" desc="1">
            <item level="1" threshold="-9000,-8000" threshold_clr="-6000,-5000"/>
            <item level="2" threshold="-14000,-13000" threshold_clr="-11000,-10000"/>
            <item level="3" threshold="-19000,-18000" threshold_clr="-16000,-15000"/>
            <item level="4" threshold="-21000,-20000" threshold_clr="-20000,-19000"/>
        </sensor_cluster>
    </level>

    <state>
        <item name="scene" param="cam,call,game,test"/>
        <item name="screen"/>
        <item name="charge"/>
    </state>

    <action>
        <item name="airplane"/>
        <item name="cpu_big"/>
        <item name="cpu_med"/>
        <item name="cpu_lit"/>
        <item name="gpu"/>
        <item name="boost" event="1"/>
        <item name="isolate" event="1"/>
        <item name="lcd"/>
        <item name="volume" uid="2001,2002"/>
        <item name="current_sc" protocol="current" param="sc" event="1"/>
        <item name="current_buck" protocol="current" param="buck" event="1"/>
        <item name="voltage_sc" protocol="voltage" param="sc" event="1"/>
        <item name="voltage_buck" protocol="voltage" param="buck" event="1"/>
        <item name="process_ctrl" param="32,64,128,256" event=""/>
        <item name="shut_down" event="0"/>
        <item name="thermallevel" event="1"/>
        <item name="popup"/>
        <item name="test"/>
    </action>

    <policy>
        <config name="base_safe" level="1">
            <airplane>0</airplane>
            <lcd>1.00</lcd>
            <lcd scene="cam">0.99</lcd>
            <lcd scene="call">0.98</lcd>
            <lcd scene="game">0.97</lcd>
            <lcd scene="test">0.91</lcd>
            <cpu_big>1992000</cpu_big>
            <cpu_med>1991500</cpu_med>
            <cpu_lit>1991200</cpu_lit>
            <test>99999</test>
            <process_ctrl>3</process_ctrl>
            <cpu_big scene="cam" charge="1">1991800</cpu_big>
            <cpu_big scene="cam" charge="0">1991600</cpu_big>
            <gpu screen="0">524288</gpu>
            <gpu screen="1">512000</gpu>
            <thermallevel>1</thermallevel>
            <current_sc>1800</current_sc>
            <current_sc scene="cam">1200</current_sc>
            <current_buck>1200</current_buck>
            <voltage_sc>4000</voltage_sc>
            <voltage_buck>3000</voltage_buck>
            <volume>1.0</volume>
            <boost>1</boost>
            <isolate>0</isolate>
        </config>
        <config name="base_safe" level="2">
            <airplane>1</airplane>
            <lcd>0.90</lcd>
            <lcd scene="cam">0.89</lcd>
            <lcd scene="call">0.88</lcd>
            <lcd scene="game">0.87</lcd>
            <cpu_big>1991000</cpu_big>
            <cpu_med>1990500</cpu_med>
            <cpu_lit>1990200</cpu_lit>
            <process_ctrl>2</process_ctrl>
            <cpu_big scene="cam" charge="1">1990800</cpu_big>
            <cpu_big scene="cam" charge="0">1990600</cpu_big>
            <gpu screen="0">499712</gpu>
            <gpu screen="1">487424</gpu>
            <thermallevel>2</thermallevel>
            <current_sc>1500</current_sc>
            <current_sc scene="cam">1000</current_sc>
            <current_buck>1000</current_buck>
            <voltage_sc>3000</voltage_sc>
            <voltage_buck>2000</voltage_buck>
            <volume>0.8</volume>
            <boost>1</boost>
            <isolate>1</isolate>
        </config>
        <config name="base_safe" level="3">
            <lcd>0.80</lcd>
            <lcd scene="cam">0.79</lcd>
            <lcd scene="call">0.78</lcd>
            <lcd scene="game">0.77</lcd>
            <cpu_big>1990000</cpu_big>
            <cpu_med>1989500</cpu_med>
            <cpu_lit>1989200</cpu_lit>
            <process_ctrl>1</process_ctrl>
            <cpu_big scene="cam" charge="1">1989800</cpu_big>
            <cpu_big scene="cam" charge="0">1989600</cpu_big>
            <gpu screen="0">475136</gpu>
            <gpu screen="1">462848</gpu>
            <thermallevel>3</thermallevel>
            <current_sc>1300</current_sc>
            <current_sc scene="cam">800</current_sc>
            <current_buck>800</current_buck>
            <voltage_sc>2000</voltage_sc>
            <voltage_buck>1000</voltage_buck>
            <volume>0.7</volume>
            <shut_down>1</shut_down>
            <boost>0</boost>
            <isolate>2</isolate>
        </config>
        <config name="warm_5G" level="1">
            <lcd>0.70</lcd>
            <thermallevel>4</thermallevel>
            <process_ctrl>2</process_ctrl>
        </config>
        <config name="warm_5G" level="2">
            <lcd>0.60</lcd>
            <process_ctrl>3</process_ctrl>
            <thermallevel>5</thermallevel>
        </config>
        <config name="warm_5G" level="3">
            <thermallevel>7</thermallevel>
        </config>
        <config name="warm_safe" level="1">
            <process_ctrl screen="1">3</process_ctrl>
            <shut_down screen="1">1</shut_down>
            <thermallevel>6</thermallevel>
        </config>
        <config name="cold_safe" level="1">
            <current_sc>1850</current_sc>
            <thermallevel>0</thermallevel>
        </config>
        <config name="cold_safe" level="2">
            <current_sc>1550</current_sc>
            <thermallevel>0</thermallevel>
        </config>
        <config name="cold_safe" level="3">
            <current_sc>1150</current_sc>
            <thermallevel>0</thermallevel>
        </config>
    </policy>

    <fan>
        <sensor_cluster name="fan_fault_detect" sensor="soc,gpu,fan">
            <item fault="1" threshold="50000,50000,500"/>
            <item fault="2" threshold="30000,30000,1500"/>
        </sensor_cluster>
    </fan>

    <idle name="charging">
        <thermallevel>1</thermallevel>  <!-- thermal level is equal or less than 1 -->
        <soc>80</soc> <!-- battery soc is equal or more than 80% -->
        <charging>1</charging> <!-- battery is charging -->
        <current>1000</current> <!-- battery charging current is equal or more than 1000mA -->
    </idle>
</thermal>
相关推荐
小雨青年8 小时前
鸿蒙 HarmonyOS 6 | ArkUI (05):布局进阶 RelativeContainer 相对布局与 Flex 弹性布局
华为·harmonyos
特立独行的猫a12 小时前
鸿蒙PC三方库编译libiconv链接报错,解决 libtool 链接参数丢失问题过程总结
harmonyos·交叉编译·libiconv·三方库·鸿蒙pc·libtool
哈__12 小时前
Flutter 开发鸿蒙 PC 第一个应用:窗口创建 + 大屏布局
flutter·华为·harmonyos
特立独行的猫a13 小时前
鸿蒙PC命令行及三方库libiconv移植:鸿蒙PC生态的字符编码基石
harmonyos·交叉编译·libiconv·三方库移植·鸿蒙pc
kirk_wang14 小时前
Flutter Widget核心概念深度解析
flutter·移动开发·跨平台·arkts·鸿蒙
不爱学英文的码字机器16 小时前
【鸿蒙PC命令行适配】基于OHOS SDK直接构建xz命令集(xz、xzgrep、xzdiff),完善tar.xz解压能力
华为·harmonyos
特立独行的猫a17 小时前
[鸿蒙PC命令行程序移植实战]:交叉编译移植最新openSSL 4.0.0到鸿蒙PC
华为·harmonyos·移植·openssl·交叉编译·鸿蒙pc
特立独行的猫a18 小时前
[鸿蒙PC命令行适配] 移植Aria2文件下载神器最新版到鸿蒙PC的完整教程 (附可运行程序)
harmonyos·移植·交叉编译·aria2·鸿蒙pc
程序员老刘·19 小时前
ArkUI-X 6.0 跨平台框架能否取代 Flutter?
flutter·鸿蒙系统·跨平台开发·客户端开发
特立独行的猫a20 小时前
[鸿蒙PC三方库交叉编译] libtool与鸿蒙SDK工具链的冲突解决方案:从glibc污染到参数透传的深度解析
华为·harmonyos·ndk·三方库移植·鸿蒙pc·libtool