1e41f4b71Sopenharmony_ci# System Brightness Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciBy default, the system brightness of OpenHarmony ranges from **0** to **255** (**0** indicates the minimum luminance and **255** the maximum). It is applicable to the entire system and all application windows. Due to hardware restrictions, some display devices are unable to support the system brightness range. To address this issue, OpenHarmony provides the function of customizing the system brightness range. This way, you can adjust the system brightness range based on the hardware specifications of the display devices.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### Basic Concepts
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci**System brightness**
12e41f4b71Sopenharmony_ciGlobal brightness of OpenHarmony. The customized brightness range is effective for all application windows.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci**Window brightness**
15e41f4b71Sopenharmony_ciBrightness of an application window. The customized brightness range is effective only for this application window. After a brightness is specified for an application window, its brightness is not affected by the system brightness.
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci### Constraints
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciThe [sysparam](./subsys-boot-init-sysparam.md) module of OpenHarmony provides an easy-to-use key-value pair access interface for system services to configure service functions based on their own system parameters. The customization of the system brightness range is dependent on this feature.
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## How to Develop
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci### Setting Up the Environment
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ci**Hardware requirements:**
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciDevelopment board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**Environment requirements:**
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ciFor details about the requirements on the Linux environment, see [Quick Start](../quick-start/Readme-EN.md).
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci### Getting Started with Development
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci1. In the target directory, create a target folder by referring to the [default brightness value configuration folder](https://gitee.com/openharmony/powermgr_display_manager/tree/master/service/etc). The content is as follows:
36e41f4b71Sopenharmony_ci     
37e41f4b71Sopenharmony_ci    ```text
38e41f4b71Sopenharmony_ci    etc
39e41f4b71Sopenharmony_ci    ├── BUILD.gn
40e41f4b71Sopenharmony_ci    ├── display.para
41e41f4b71Sopenharmony_ci    ├── display.para.dac
42e41f4b71Sopenharmony_ci    ```
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci2. Write the customized **display.para** file by referring to the [**display.para** file](https://gitee.com/openharmony/powermgr_display_manager/blob/master/service/etc/display.para) in the default brightness range configuration folder. Include the customized brightness thresholds, for example, **max=150**, **default=75**, and **min=50**, into the file:
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci    ```shell
47e41f4b71Sopenharmony_ci    # Brightness limits is 0-255.
48e41f4b71Sopenharmony_ci    const.display.brightness.min=50
49e41f4b71Sopenharmony_ci    const.display.brightness.default=75
50e41f4b71Sopenharmony_ci    const.display.brightness.max=150
51e41f4b71Sopenharmony_ci    ``` 
52e41f4b71Sopenharmony_ci
53e41f4b71Sopenharmony_ci3. Write the customized **display.para.dac** file by referring to the [**display.para.dac** file](https://gitee.com/openharmony/powermgr_display_manager/blob/master/service/etc/display.para.dac) in the default brightness range configuration folder, so as to grant the permission required to access the customized configuration.
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci    ```shell
56e41f4b71Sopenharmony_ci    const.display.brightness.="foundation:foundation:444"
57e41f4b71Sopenharmony_ci    ``` 
58e41f4b71Sopenharmony_ci
59e41f4b71Sopenharmony_ci4. Write the customized **BUILD.gn** file by referring to the [**BUILD.gn** file](https://gitee.com/openharmony/powermgr_display_manager/blob/master/service/etc/BUILD.gn) in the default brightness range configuration folder. Then, put the **display.para** and **display.para.dac** files to the **/vendor/etc/param** directory. For example:
60e41f4b71Sopenharmony_ci
61e41f4b71Sopenharmony_ci    ```shell
62e41f4b71Sopenharmony_ci    import("//base/powermgr/display_manager/displaymgr.gni")
63e41f4b71Sopenharmony_ci    import("//build/ohos.gni")
64e41f4b71Sopenharmony_ci
65e41f4b71Sopenharmony_ci    ## Install display.para to /vendor/etc/param/display.para
66e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("display.para") {
67e41f4b71Sopenharmony_ci    source = "display.para"
68e41f4b71Sopenharmony_ci    relative_install_dir = "param"
69e41f4b71Sopenharmony_ci    install_images = [ chipset_base_dir ]
70e41f4b71Sopenharmony_ci    part_name = "${displaymgr_part_name}"
71e41f4b71Sopenharmony_ci    subsystem_name = "powermgr"
72e41f4b71Sopenharmony_ci    }
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("display.para.dac") {
75e41f4b71Sopenharmony_ci    source = "display.para.dac"
76e41f4b71Sopenharmony_ci    relative_install_dir = "param"
77e41f4b71Sopenharmony_ci    install_images = [ chipset_base_dir ]
78e41f4b71Sopenharmony_ci    part_name = "${displaymgr_part_name}"
79e41f4b71Sopenharmony_ci    subsystem_name = "powermgr"
80e41f4b71Sopenharmony_ci    }
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci    group("param_files") {
83e41f4b71Sopenharmony_ci    deps = [
84e41f4b71Sopenharmony_ci        ":display.para",
85e41f4b71Sopenharmony_ci        ":display.para.dac",
86e41f4b71Sopenharmony_ci    ]
87e41f4b71Sopenharmony_ci    }
88e41f4b71Sopenharmony_ci    ```
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci5. Write the customized **bundle.json** file by referring to the [**bundle.json** file](https://gitee.com/openharmony/powermgr_display_manager/blob/master/bundle.json) in the default brightness range configuration folder, so as to compile the **BUILD.gn** file.
91e41f4b71Sopenharmony_ci 
92e41f4b71Sopenharmony_ci    ```shell
93e41f4b71Sopenharmony_ci    "service_group": [ "//base/powermgr/display_manager/service/etc:param_files" ]
94e41f4b71Sopenharmony_ci    ``` 
95e41f4b71Sopenharmony_ci    In the preceding code, **//base/powermgr/display_manager/service** indicates the directory of the created folder, and **etc** indicates the folder name.
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/Readme-EN.md). The following command uses DAYU200 as an example:
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci    ```shell
100e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
101e41f4b71Sopenharmony_ci    ```
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board.
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci### Debugging and Verification
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci1. After startup, run the following command to launch the shell command line:
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci    ```shell
110e41f4b71Sopenharmony_ci    hdc shell
111e41f4b71Sopenharmony_ci    ```
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci2. Run the following command to check the console output:
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci    ```shell
116e41f4b71Sopenharmony_ci    hidumper -s 3308 -a -a
117e41f4b71Sopenharmony_ci    ```
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci3. Check the console output for the customized system brightness thresholds.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci    The default system brightness thresholds are as follows:
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci    ```shell
124e41f4b71Sopenharmony_ci    ----------------------------------DisplayPowerManagerService---------------------------------
125e41f4b71Sopenharmony_ci    DISPLAY POWER MANAGER DUMP:
126e41f4b71Sopenharmony_ci    Display Id=0 State=2 Discount=1.000000 Brightness=102
127e41f4b71Sopenharmony_ci    DeviceBrightness=102
128e41f4b71Sopenharmony_ci    Support Ambient Light: FALSE
129e41f4b71Sopenharmony_ci    Auto Adjust Brightness: OFF
130e41f4b71Sopenharmony_ci    Brightness Limits: Max=255 Min=5 Default=102
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci    ```
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ci    Assume that the system brightness thresholds are set to **Max=150 Min=50 Default=75**. The console output is as follows:
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci    ```shell
137e41f4b71Sopenharmony_ci    # cd vendor/etc/param                                                          
138e41f4b71Sopenharmony_ci    # ls
139e41f4b71Sopenharmony_ci    display.para      thermal.para      usb.para.dac  
140e41f4b71Sopenharmony_ci    display.para.dac  thermal.para.dac  
141e41f4b71Sopenharmony_ci    # cat display.para
142e41f4b71Sopenharmony_ci    # Copyright (C) 2022 Huawei Device Co., Ltd.
143e41f4b71Sopenharmony_ci    # Licensed under the Apache License, Version 2.0 (the "License");
144e41f4b71Sopenharmony_ci    # you may not use this file except in compliance with the License.
145e41f4b71Sopenharmony_ci    # You may obtain a copy of the License at
146e41f4b71Sopenharmony_ci    #
147e41f4b71Sopenharmony_ci    #     http://www.apache.org/licenses/LICENSE-2.0
148e41f4b71Sopenharmony_ci    #
149e41f4b71Sopenharmony_ci    # Unless required by applicable law or agreed to in writing, software
150e41f4b71Sopenharmony_ci    # distributed under the License is distributed on an "AS IS" BASIS,
151e41f4b71Sopenharmony_ci    # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
152e41f4b71Sopenharmony_ci    # See the License for the specific language governing permissions and
153e41f4b71Sopenharmony_ci    # limitations under the License.
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci    # Brightness limits is 0-255.
156e41f4b71Sopenharmony_ci    const.display.brightness.min=50
157e41f4b71Sopenharmony_ci    const.display.brightness.default=75
158e41f4b71Sopenharmony_ci    const.display.brightness.max=150# 
159e41f4b71Sopenharmony_ci    # 
160e41f4b71Sopenharmony_ci    # cd
161e41f4b71Sopenharmony_ci    # hidumper -s 3308 -a -a
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci    ----------------------------------DisplayPowerManagerService---------------------------------
167e41f4b71Sopenharmony_ci    DISPLAY POWER MANAGER DUMP:
168e41f4b71Sopenharmony_ci    Display Id=0 State=0 Discount=1.000000 Brightness=75
169e41f4b71Sopenharmony_ci    DeviceBrightness=75
170e41f4b71Sopenharmony_ci    Support Ambient Light: FALSE
171e41f4b71Sopenharmony_ci    Auto Adjust Brightness: OFF
172e41f4b71Sopenharmony_ci    Brightness Limits: Max=150 Min=50 Default=75
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci    ```
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci4. Set the system brightness thresholds to the customized values.
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci## Reference
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ciFor details about how to write the configuration file during system brightness customization, refer to the [default brightness range configuration file](https://gitee.com/openharmony/powermgr_display_manager/tree/master/service/etc).
181e41f4b71Sopenharmony_ci
182e41f4b71Sopenharmony_ciDefault configuration:
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci```shell
185e41f4b71Sopenharmony_ci# Brightness limits is 0-255.
186e41f4b71Sopenharmony_ciconst.display.brightness.min=5
187e41f4b71Sopenharmony_ciconst.display.brightness.default=102
188e41f4b71Sopenharmony_ciconst.display.brightness.max=255
189e41f4b71Sopenharmony_ci``` 
190e41f4b71Sopenharmony_ci
191e41f4b71Sopenharmony_ciPacking directory: /system/etc/param
192