subsys-power-brightness-customization.md 7.5 KB
Newer Older
S
shawn_he 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
# System Brightness Customization

## Overview

### Introduction

By 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.

### Basic Concepts

**System brightness**
Global brightness of OpenHarmony. The customized brightness range is effective for all application windows.

**Window brightness**
Brightness 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.

### Constraints

The [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.

## How to Develop

### Setting Up the Environment

**Hardware requirements:**

Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.

**Environment requirements:**

For details about the requirements on the Linux environment, see [Quick Start](../quick-start/Readme-EN.md).

### How to Develop

1. 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 file format is as follows:
     
    ```text
    etc
    ├── BUILD.gn
    ├── display.para
    ├── display.para.dac
    ```

2. 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:

    ```shell
    # Brightness limits is 0-255.
    const.display.brightness.min=50
    const.display.brightness.default=75
    const.display.brightness.max=150
    ``` 

3. 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.

    ```shell
    const.display.brightness.="foundation:foundation:444"
    ``` 

4. 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:

    ```shell
    import("//base/powermgr/display_manager/displaymgr.gni")
    import("//build/ohos.gni")

    ## Install display.para to /vendor/etc/param/display.para
    ohos_prebuilt_etc("display.para") {
    source = "display.para"
    relative_install_dir = "param"
    install_images = [ chipset_base_dir ]
    part_name = "${displaymgr_part_name}"
    subsystem_name = "powermgr"
    }

    ohos_prebuilt_etc("display.para.dac") {
    source = "display.para.dac"
    relative_install_dir = "param"
    install_images = [ chipset_base_dir ]
    part_name = "${displaymgr_part_name}"
    subsystem_name = "powermgr"
    }

    group("param_files") {
    deps = [
        ":display.para",
        ":display.para.dac",
    ]
    }
    ```

5. 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.
 
    ```shell
    "service_group": [ "//base/powermgr/display_manager/service/etc:param_files" ]
    ``` 
    In the preceding code, **//base/powermgr/display_manager/service** indicates the directory of the created folder, and **etc** indicates the folder name.

6. Build the customized version by referring to [Quick Start](../quick-start/Readme-EN.md). The following command uses DAYU200 as an example:

    ```shell
    ./build.sh --product-name rk3568 --ccache
    ```

7. Burn the customized version to the DAYU200 development board.

### Debugging and Verification

1. After startup, run the following command to launch the shell command line:

    ```shell
    hdc shell
    ```

2. Run the following command to check the console output:

    ```shell
    hidumper -s 3308 -a -a
    ```

3. Check the console output for the customized system brightness thresholds.

    The default system brightness thresholds are as follows:

    ```shell
    ----------------------------------DisplayPowerManagerService---------------------------------
    DISPLAY POWER MANAGER DUMP:
    Display Id=0 State=2 Discount=1.000000 Brightness=102
    DeviceBrightness=102
    Support Ambient Light: FALSE
    Auto Adjust Brightness: OFF
    Brightness Limits: Max=255 Min=5 Default=102

    ```

    Assume that the system brightness thresholds are set to **Max=150 Min=50 Default=75**. The console output is as follows:

    ```shell
    # cd vendor/etc/param                                                          
    # ls
    display.para      thermal.para      usb.para.dac  
    display.para.dac  thermal.para.dac  
    # cat display.para
    # Copyright (C) 2022 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.

    # Brightness limits is 0-255.
    const.display.brightness.min=50
    const.display.brightness.default=75
    const.display.brightness.max=150# 
    # 
    # cd
    # hidumper -s 3308 -a -a

    -------------------------------[ability]-------------------------------


    ----------------------------------DisplayPowerManagerService---------------------------------
    DISPLAY POWER MANAGER DUMP:
    Display Id=0 State=0 Discount=1.000000 Brightness=75
    DeviceBrightness=75
    Support Ambient Light: FALSE
    Auto Adjust Brightness: OFF
    Brightness Limits: Max=150 Min=50 Default=75

    ```

4. Set the system brightness thresholds to the customized values.

## Reference

For 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).

Default configuration:

```shell
# Brightness limits is 0-255.
const.display.brightness.min=5
const.display.brightness.default=102
const.display.brightness.max=255
``` 

Packing directory: /system/etc/param