1# 系统亮度范围定制开发指导 2 3## 概述 4 5### 简介 6 7OpenHarmony默认的亮度范围为0 ~ 255(0代表最小亮度,255代表最大亮度),是系统和所有应用窗口的亮度调节范围。部分显示设备受到其硬件约束,亮度调节范围无法达到0 ~ 255,即无法达到默认的亮度调节范围。为此OpenHarmony提供了系统亮度范围定制方式,在与不同显示设备适配时,产品定制开发者可根据显示设备自身硬件条件灵活调整系统亮度范围。 8 9### 基本概念 10 11系统亮度: 12OpenHarmony系统全局的亮度,调节后会使所有应用窗口亮度范围更改为定制的系统亮度范围。 13 14窗口亮度: 15某个应用窗口的亮度,调节后只影响此窗口,窗口退出后,恢复为系统亮度。当设置窗口亮度后,此窗口的亮度不受系统亮度的影响。 16 17### 约束与限制 18 19[OpenHarmony系统参数](./subsys-boot-init-sysparam.md)为各系统服务提供简单易用的键值对访问接口,使得各个系统服务可以通过各自的系统参数来进行业务功能的配置。系统亮度范围的定制基于此特性实现。 20 21## 开发指导 22 23### 搭建环境 24 25设备要求: 26 27标准系统开发板,如DAYU200/Hi3516DV300开源套件。 28 29环境要求: 30 31Linux调测环境,相关要求和配置可参考《[快速入门](../quick-start/Readme-CN.md)》。 32 33### 开发步骤 34 351. 参考[默认亮度范围配置文件夹](https://gitee.com/openharmony/powermgr_display_manager/tree/master/service/etc)创建目标文件夹,并安装到相应目录,文件格式如下: 36 37 ```text 38 etc 39 ├── BUILD.gn 40 ├── display.para 41 ├── display.para.dac 42 ``` 43 442. 参考[默认亮度范围配置文件夹中的display.para](https://gitee.com/openharmony/powermgr_display_manager/blob/master/service/etc/display.para)编写定制的display.para。包含定制后的亮度阈值,以max=150,default=75,min=50为例: 45 46 ```shell 47 # Brightness limits is 0-255. 48 const.display.brightness.min=50 49 const.display.brightness.default=75 50 const.display.brightness.max=150 51 ``` 52 533. 参考[默认亮度范围配置文件夹中的display.para.dac](https://gitee.com/openharmony/powermgr_display_manager/blob/master/service/etc/display.para.dac)编写display.para.dac数据访问控制文件,保证有权限解析定制后的配置: 54 55 ```shell 56 const.display.brightness.="foundation:foundation:444" 57 ``` 58 594. 参考[默认亮度范围配置文件夹中的BUILD.gn](https://gitee.com/openharmony/powermgr_display_manager/blob/master/service/etc/BUILD.gn)编写BUILD.gn文件,将display.para和display.para.dac打包到/vendor/etc/param目录下,例如: 60 61 ```shell 62 import("//base/powermgr/display_manager/displaymgr.gni") 63 import("//build/ohos.gni") 64 65 ## Install display.para to /vendor/etc/param/display.para 66 ohos_prebuilt_etc("display.para") { 67 source = "display.para" 68 relative_install_dir = "param" 69 install_images = [ chipset_base_dir ] 70 part_name = "${displaymgr_part_name}" 71 subsystem_name = "powermgr" 72 } 73 74 ohos_prebuilt_etc("display.para.dac") { 75 source = "display.para.dac" 76 relative_install_dir = "param" 77 install_images = [ chipset_base_dir ] 78 part_name = "${displaymgr_part_name}" 79 subsystem_name = "powermgr" 80 } 81 82 group("param_files") { 83 deps = [ 84 ":display.para", 85 ":display.para.dac", 86 ] 87 } 88 ``` 89 905. 参考[默认亮度范围配置bundle.json](https://gitee.com/openharmony/powermgr_display_manager/blob/master/bundle.json)编写bundle.json文件,使BUILD.gn文件进行编译,例如: 91 92 ```shell 93 "service_group": [ "//base/powermgr/display_manager/service/etc:param_files" ] 94 ``` 95 “//base/powermgr/display_manager/service”为文件夹路径,“etc”为创建的文件夹名字。 96 976. 参考《[快速入门](../quick-start/Readme-CN.md)》编译定制版本,以编译DAYU200为例,编译命令如下: 98 99 ```shell 100 ./build.sh --product-name rk3568 --ccache 101 ``` 102 1037. 将定制版本烧录到DAYU200开发板中。 104 105### 调测验证 106 1071. 开机后,先进入shell命令行: 108 109 ```shell 110 hdc shell 111 ``` 112 1132. 执行下列命令,观察console输出。 114 115 ```shell 116 hidumper -s 3308 -a -a 117 ``` 118 1193. console输出的是定制后的系统亮度阈值,如: 120 121 定制系统亮度阈值之前,默认为: 122 123 ```shell 124 ----------------------------------DisplayPowerManagerService--------------------------------- 125 DISPLAY POWER MANAGER DUMP: 126 Display Id=0 State=2 Discount=1.000000 Brightness=102 127 DeviceBrightness=102 128 Support Ambient Light: FALSE 129 Auto Adjust Brightness: OFF 130 Brightness Limits: Max=255 Min=5 Default=102 131 132 ``` 133 134 本节以Max=150 Min=50 Default=75为例,更改之后: 135 136 ```shell 137 # cd vendor/etc/param 138 # ls 139 display.para thermal.para usb.para.dac 140 display.para.dac thermal.para.dac 141 # cat display.para 142 # Copyright (C) 2022 Huawei Device Co., Ltd. 143 # Licensed under the Apache License, Version 2.0 (the "License"); 144 # you may not use this file except in compliance with the License. 145 # You may obtain a copy of the License at 146 # 147 # http://www.apache.org/licenses/LICENSE-2.0 148 # 149 # Unless required by applicable law or agreed to in writing, software 150 # distributed under the License is distributed on an "AS IS" BASIS, 151 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 152 # See the License for the specific language governing permissions and 153 # limitations under the License. 154 155 # Brightness limits is 0-255. 156 const.display.brightness.min=50 157 const.display.brightness.default=75 158 const.display.brightness.max=150# 159 # 160 # cd 161 # hidumper -s 3308 -a -a 162 163 -------------------------------[ability]------------------------------- 164 165 166 ----------------------------------DisplayPowerManagerService--------------------------------- 167 DISPLAY POWER MANAGER DUMP: 168 Display Id=0 State=0 Discount=1.000000 Brightness=75 169 DeviceBrightness=75 170 Support Ambient Light: FALSE 171 Auto Adjust Brightness: OFF 172 Brightness Limits: Max=150 Min=50 Default=75 173 174 ``` 175 1764. 系统全局的亮度阈值统一为定制后的,如设置中的亮度调节。 177 178## 参考 179 180开发过程中可参考的配置文件路径:[系统默认亮度范围配置源码路径](https://gitee.com/openharmony/powermgr_display_manager/tree/master/service/etc) 181 182默认配置: 183 184```shell 185# Brightness limits is 0-255. 186const.display.brightness.min=5 187const.display.brightness.default=102 188const.display.brightness.max=255 189``` 190 191打包路径:/system/etc/param