鸿蒙OpenHarmony【关机充电动画开辟】子系统电源管理

嚴華  论坛元老 | 2024-12-13 11:15:23 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 1038|帖子 1038|积分 3114

概述

简介

OpenHarmony默认提供了关机充电动画的特性,展示关机状态下的充电电量、充电动画等信息。由于定制厂商盼望定制符合自身规则和特点的显示样式,盼望根据产物的设计规格来定制此特性。为此OpenHarmony提供了关机充电动画的定制方式,产物定制开辟者可根据产物的设计规格来定制此特性。
约束与限制

配置计谋: 产物定制的配置路径,必要根据[配置计谋]决定。本开辟指导中的定制路径以/vendor进行举例,请开辟者根据详细的产物配置计谋,修改定制路径。
开辟指导

搭建环境

设备要求:
标准系统开辟板,如DAYU200/Hi3516DV300开源套件。
环境要求:
Linux调测环境
开辟步骤

本文以[DAYU200]为例介绍关机充电动画的定制方法。

  • 在产物目次[(/vendor/hihope/rk3568)]下创建animation文件夹。
  • 创建目标文件夹,并安装到//vendor/hihope/rk3568/animation目次下,文件格式如下:
    1. profile
    2. ├── BUILD.gn
    3. ├── animation.json
    复制代码
  • 创建resources文件夹放置构成动画的图片文件,并安装到//vendor/hihope/rk3568/animation目次下,文件格式如下:
    1. animation
    2. ├── resources
    3. ├── profile
    复制代码
  • 编写BUILD.gn文件,放入//vendor/hihope/rk3568/animation/resource目次下,例如:
    1. import("//build/ohos.gni")
    2. ohos_prebuilt_etc("resources_config0") {
    3.     source = "loop00000.png"                                        #图片资源
    4.     relative_install_dir = "poweroff_charger_animation/resources"
    5.     install_images = [ chipset_base_dir ]                           #安装到vendor目录下的必要配置
    6.     part_name = "product_rk3568"
    7. }
    复制代码
  • 编写定制的animation.json。包含定制后的关机充电动画配置如下:
    1. {
    2.     "animation": {
    3.         "components": [
    4.             {
    5.                 "type": "UIImageView",
    6.                 "id": "Charging_Animation_Image",
    7.                 "x": 200,
    8.                 "y": 480,
    9.                 "w": 400,
    10.                 "h": 400,
    11.                 "resPath": "/system/etc/charger/resources/",
    12.                 "imgCnt": 62,
    13.                 "updInterval": 60,
    14.                 "filePrefix": "loop"
    15.             },
    16.             {
    17.                 "type": "UILabel",
    18.                 "id": "Charging_Percent_Label",
    19.                 "text": "",
    20.                 "x": 326,
    21.                 "y": 616,
    22.                 "w": 68,
    23.                 "h": 48,
    24.                 "fontSize": 32,
    25.                 "fontColor": "#ffffffe6",
    26.                 "bgColor": "#00000000"
    27.                 "align": "center"
    28.             }
    29.         ]
    30.     },
    31.     "lackpowerChargingPrompt": {
    32.         "components": [
    33.             {
    34.                 "type": "UILabel",
    35.                 "id": "LackPower_Charging_Label",
    36.                 "text": "电池电量低",
    37.                 "x": 229,
    38.                 "y": 1037,
    39.                 "w": 250,
    40.                 "h": 45,
    41.                 "fontSize": 42,
    42.                 "fontColor": "#ff0000ff",
    43.                 "bgColor": "#00000000",
    44.                 "align": "center"
    45.             }
    46.         ]
    47.     },
    48.     "lackpowerNotChargingPrompt": {
    49.         "components": [
    50.             {
    51.                 "type": "UILabel",
    52.                 "id": "LackPower_Not_Charging_Label",
    53.                 "text": "电池电量低,请连接电源",
    54.                 "x": 110,
    55.                 "y": 1037,
    56.                 "w": 500,
    57.                 "h": 45,
    58.                 "fontSize": 42,
    59.                 "fontColor": "#ff0000ff",
    60.                 "bgColor": "#00000000",
    61.                 "align": "center"
    62.             }
    63.         ]
    64.     }
    65. }
    复制代码
    表1 关机充电动画配置分析
       节点名称作用animation动画配置信息lackpowerChargingPrompt低电量充电状态提示配置信息lackpowerNotChargingPrompt低电量未充电状态提示配置信息components组件集type组件类型id组件IDtext组件的文本内容x组件的X轴坐标y组件的Y轴坐标w组件的宽度(像素点)h组件的高度(像素点)fontSize文本的字体大小fontColor文本的字体颜色align文本对齐方式imgCnt图片数量updInterval图片更新的时间隔断(毫秒)filePrefix图片文件名的前缀resPath组件的资源文件路径
  • 编写BUILD.gn文件,将animation.json打包到/vendor/etc/charger目次下,配置如下:
    1. import("//build/ohos.gni")
    2. ohos_prebuilt_etc("animation_config") {
    3.     source = "animation.json"             #引用build/ohos.gni
    4.     relative_install_dir = "animation/resources"
    5.     install_images = [ chipset_base_dir ] #安装到vendor目录下的必要配置
    6.     part_name = "product_rk3568"          #part_name为product_rk3568,以实现后续编译
    7. }
    复制代码
  • 将编译目标添加到/vendor/hihope/rk3568目次下[ohos.build]的"module_list"中,例如:
    1. {
    2. "parts": {
    3.     "product_rk3568": {
    4.     "module_list": [
    5.         "//vendor/hihope/rk3568/default_app_config:default_app_config",
    6.         "//vendor/hihope/rk3568/image_conf:custom_image_conf",
    7.         "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
    8.         "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
    9.         "//vendor/hihope/rk3568/etc:product_etc_conf",
    10.         "//vendor/hihope/rk3568/battery/profile:battery_config",
    11.         "//vendor/hihope/rk3568/animation/profile:animation_config", #添加animation_config的编译
    12.         "//vendor/hihope/rk3568/animation/resource/resources_config" #添加图片资源的编译
    13.     ]
    14.     }
    15. },
    16. "subsystem": "product_hihope"
    17. }
    复制代码
    “//vendor/hihope/rk3568/animation/”为文件夹路径,“profile”为创建的文件夹名字,“animation_config”为编译目标。
  • 编译定制版本,编译命令如下:
    1. ./build.sh --product-name rk3568 --ccache
    复制代码
  • 将定制版本烧录到DAYU200开辟板中。
调测验证


  • 修改代码配置: 修改代码路径:base/startup/init/services/init/init_config.c 修改函数:ReadConfig 修改前
    1. void ReadConfig(void)
    2. {
    3.     // parse cfg
    4.     char buffer[32] = {0}; // 32 reason max leb
    5.     uint32_t len = sizeof(buffer);
    6.     SystemReadParam("ohos.boot.mode", buffer, &len);
    7.     INIT_LOGI("ohos.boot.mode %s", buffer);
    8.     if (strcmp(buffer, "charger_mode") == 0) {
    9.         // 产品化定制执行此分支流程
    10.         ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
    11.         ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL);
    12.         ParseInitCfgByPriority();
    13.     } else if (strcmp(buffer, "charger") == 0) {
    14.         ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
    15.         ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL);
    16.     } else if (InUpdaterMode() == 0) {
    17.         ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
    18.         ParseInitCfgByPriority();
    19.     } else {
    20.         ReadFileInDir("/etc", ".cfg", ParseInitCfg, NULL);
    21.     }
    22. }
    复制代码
    修改后
    1. void ReadConfig(void)
    2. {
    3.     // parse cfg
    4.     char buffer[32] = {0}; // 32 reason max leb
    5.     uint32_t len = sizeof(buffer);
    6.     SystemReadParam("ohos.boot.mode", buffer, &len);
    7.     INIT_LOGI("ohos.boot.mode %s", buffer);
    8.     ParseInitCfg(INIT_CONFIGURATION_FILE, NULL);
    9.     ReadFileInDir(OTHER_CHARGE_PATH, ".cfg", ParseInitCfg, NULL);
    10.     ParseInitCfgByPriority();
    11. }
    复制代码
  • 利用hdc执行如下命令,使开辟板进入关机充电状态。
    1. hdc shell
    2. reboot charge
    复制代码

  • 进入电池电量的节点路径(以当前DAYU开辟版路径为例)。
    1. cd /data/service/el0/battery/battery
    复制代码
  • 修改电量数值,并观察充电动画数值变化。
    1. cat capacity
    复制代码
    修改当前电量为3
    1. echo 3 > capacity
    复制代码

  • 切为Not charging状态,直接进入关机状态。
    1. echo Not charging > status
    复制代码
  • 在极低电量时(此处默认1%)修改充电状态,不同的充电状态对应显示动画或关机。

    • 进入电池电量的节点路径。
    1. cd /data/service/el0/battery/battery
    2. cat capacity
    复制代码
      

    • 修改当前电量为1。
    1. echo 1 > capacity
    复制代码
      

    • 检察当前状态。
    1. cat status
    复制代码
    当前状态为Charging

       

    • 改变当前状态,为未连接电源状态。
    1. echo Not charging > status
    复制代码


  • 以下对关机动画的图片进行可定制化的测试修改,步骤与上方相同,只是图片作出替换。

    • 初始状态。

       

    • 3%电量状态。

       

    • 1%电量,充电状态。

       

    • 1%电量,未充电状态。

       

    • 当电量高于1%,切为Not charging状态
    1. echo 3 > capacity
    2. echo Not charging > status
    复制代码

参考

开辟过程中可参考的配置文件路径:[默认关机充电动画配置源码路径]
默认配置:
  1. {
  2.         "animation": {
  3.             "components": [
  4.                 {
  5.                     "type": "UIImageView",
  6.                     "id": "Charging_Animation_Image",
  7.                     "x": 180,
  8.                     "y": 410,
  9.                     "w": 400,
  10.                     "h": 400,
  11.                     "resPath": "/system/etc/charger/resources/",
  12.                     "imgCnt": 62,
  13.                     "updInterval": 60,
  14.                     "filePrefix": "loop"
  15.                 },
  16.                 {
  17.                     "type": "UILabel",
  18.                     "id": "Charging_Percent_Label",
  19.                     "text": "",
  20.                     "x": 365,
  21.                     "y": 580,
  22.                     "w": 65,
  23.                     "h": 43,
  24.                     "fontSize": 32,
  25.                     "fontColor": "#ffffffe6",
  26.                     "bgColor": "#00000000",
  27.                     "align": "center"
  28.                 }
  29.             ],
  30.         },
  31.         "lackpowerChargingPrompt": {
  32.             "components": [
  33.                 {
  34.                     "type": "UILabel",
  35.                     "id": "LackPower_Charging_Label",
  36.                     "text": "电池电量低",
  37.                     "x": 229,
  38.                     "y": 1037,
  39.                     "w": 250,
  40.                     "h": 45,
  41.                     "fontSize": 42,
  42.                     "fontColor": "#ff0000ff",
  43.                     "bgColor": "#00000000",
  44.                     "align": "center"
  45.                 }
  46.             ]
  47.         },
  48.         "lackpowerNotChargingPrompt": {
  49.             "components": [
  50.                 {
  51.                     "type": "UILabel",
  52.                     "id": "LackPower_Not_Charging_Label",
  53.                     "text": "电池电量低,请连接电源",
  54.                     "x": 110,
  55.                     "y": 1037,
  56.                     "w": 500,
  57.                     "h": 45,
  58.                     "fontSize": 42,
  59.                     "fontColor": "#ff0000ff",
  60.                     "bgColor": "#00000000",
  61.                     "align": "center"
  62.                 }
  63.             ]
  64.         }
  65.     }
复制代码
打包路径:/system/etc/charger/resource

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

嚴華

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表