• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Charging Type Customization
2
3## Overview
4
5### Introduction
6
7By default, OpenHarmony supports multiple charging types. You can charge devices through different types of charging, for example, wired fast charging and wireless fast charging. OpenHarmony can display appropriate animations or take required service processing based on the charging type. However, the supported charging types vary according to products. To address this issue, OpenHarmony provides the charging type customization function.
8
9### Constraints
10
11
12The configuration path for battery level customization is subject to the [configuration policy](https://gitee.com/openharmony/customization_config_policy). In this development guide, `/vendor` is used as an example of the configuration path. During actual development, you need to modify the customization path based on the product configuration policy.
13
14## How to Develop
15
16### Setting Up the Environment
17
18**Hardware requirements:**
19
20Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
21
22**Environment requirements:**
23
24For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
25
26### Getting Started with Development
27
28The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate charging type customization.
29
301. Create the `battery` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
31
322. Create a target folder by referring to the [default folder of charging type configuration](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile), and install it in `//vendor/hihope/rk3568/battery`. The content is as follows:
33
34    ```text
35    profile
36    ├── BUILD.gn
37    ├── battery_config.json
38    ```
39
403. Write the custom `battery_config.json` file by referring to the [battery_config.json](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json) file in the default folder of charging type configuration. For example:
41
42    ```shell
43    {
44        "charger": {
45            "type": {
46                "path": "/data/service/el0/battery/charger_type"
47            }
48        }
49    }
50    ```
51
524. Write the `BUILD.gn` file by referring to the [BUILD.gn](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/BUILD.gn) file in the default folder of charging type configuration to pack the `battery_config.json` file to the `//vendor/etc/battery` directory. The configuration is as follows:
53
54    ```shell
55    import("//build/ohos.gni")                # Reference build/ohos.gni.
56
57    ohos_prebuilt_etc("battery_config") {
58        source = "battery_config.json"
59        relative_install_dir = "battery"
60        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
61        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
62    }
63    ```
64
655. Add the build target to `module_list` in [ohos.build](https://gitee.com/openharmony/vendor_hihope/blob/master/rk3568/ohos.build) in the `/vendor/hihope/rk3568` directory. For example:
66
67    ```json
68    {
69    "parts": {
70        "product_rk3568": {
71        "module_list": [
72            "//vendor/hihope/rk3568/default_app_config:default_app_config",
73            "//vendor/hihope/rk3568/image_conf:custom_image_conf",
74            "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
75            "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
76            "//vendor/hihope/rk3568/etc:product_etc_conf",
77            "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config.
78        ]
79        }
80    },
81    "subsystem": "product_hihope"
82    }
83    ```
84    In the preceding code, `//vendor/hihope/rk3568/battery/` is the folder path, `profile` is the folder name, and `battery_config` is the build target.
85
866. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
87
88    ```shell
89    ./build.sh --product-name rk3568 --ccache
90    ```
91
927. Burn the customized version to the DAYU200 development board.
93
94### Debugging and Verification
95
96
971. After startup, run the following command to launch the shell command line:
98    ```
99    hdc shell
100    ```
101
1022. Go to the custom battery level configuration directory. The path of DAYU200 is used as an example.
103    ```
104    cd /data/service/el0/battery/
105    ```
106
1073. Modify the charging status, simulate reporting of the battery power change, and check whether the returned battery level is correct. The following uses the default charging type as an example.
108    1. Modify the charging type.
109    ```
110    echo 1 > charger_type
111    ```
112    2. Report the charging status change to trigger mapping between the charging type and animation.
113    ```
114    hidumper -s 3302 -a -r
115    ```
116    3. Check the output for the charging type.
117    ```
118    hidumper -s 3302 -a -i
119    ```
120    ```
121    -------------------------------[ability]----------------------------
122    ------------------------------BatteryService------------------------
123    capacity: 11
124    batteryLevel: 4
125    chargingStatus: 1
126    healthState: 1
127    pluggedType: 2
128    voltage: 4123456
129    present: 0
130    technology: Li-ion
131    nowCurrent: 1000
132    currentAverage: 1000
133    totalEnergy: 4000000
134    remainingEnergy: 4000000
135    remainingChargeTime: 0
136    temperature: 222
137    chargeType: 1
138    ```
139    ![charger_type1](figures/charger_type1.jpg)
140
141
142## Reference
143During development, you can refer to the [default charging type configuration](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json), as shown below:
144
145
146
147    ```shell
148    {
149        "charger": {
150            "type": {
151                "path": "/data/service/el0/battery/charger_type"
152            }
153        }
154    }
155    ```
156
157Packing path: /system/etc/battery
158