1e41f4b71Sopenharmony_ci# Battery Level Customization
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciBy default, OpenHarmony provides the battery level based on the current battery power, such as the full battery level, high battery level, low battery level, and extremely low battery level. It can generate an alert or take required service processing based on the current battery level. However, the battery level specifications vary according to products. To address this issue, OpenHarmony provides the function of customizing battery levels.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci### Constraints
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci 
12e41f4b71Sopenharmony_ciThe 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.
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci## How to Develop
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### Setting Up the Environment
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci**Hardware requirements:**
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciDevelopment board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci**Environment requirements:**
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciFor details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md).
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci### Getting Started with Development
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ciThe following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate battery level customization.
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci1. Create the `battery` folder in the product directory [/vendor/hihope/rk3568](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568).
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci2. Create a target folder by referring to the [default folder of battery level 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:
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci    ```text
35e41f4b71Sopenharmony_ci    profile
36e41f4b71Sopenharmony_ci    ├── BUILD.gn
37e41f4b71Sopenharmony_ci    ├── battery_config.json
38e41f4b71Sopenharmony_ci    ```
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci3. 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 battery level configuration. For example:
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci    ```json
43e41f4b71Sopenharmony_ci    {
44e41f4b71Sopenharmony_ci        "soc": {
45e41f4b71Sopenharmony_ci            "shutdown": 5,
46e41f4b71Sopenharmony_ci            "critical": 10,
47e41f4b71Sopenharmony_ci            "warning": 15,
48e41f4b71Sopenharmony_ci            "low": 30,
49e41f4b71Sopenharmony_ci            "normal": 60,
50e41f4b71Sopenharmony_ci            "high": 90,
51e41f4b71Sopenharmony_ci            "full": 100
52e41f4b71Sopenharmony_ci        }
53e41f4b71Sopenharmony_ci    }
54e41f4b71Sopenharmony_ci    ``` 
55e41f4b71Sopenharmony_ci
56e41f4b71Sopenharmony_ci    **Table 1** Battery level configuration
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci    | Battery Level| Battery Volume| Description|
59e41f4b71Sopenharmony_ci    | -------- | -------- | -------- |
60e41f4b71Sopenharmony_ci    | shutdown | 5 | Power-off battery level|
61e41f4b71Sopenharmony_ci    | critical | 10 | Extremely low battery level|
62e41f4b71Sopenharmony_ci    | warning | 15 | Alarm battery level|
63e41f4b71Sopenharmony_ci    | low | 30 | Low battery level|
64e41f4b71Sopenharmony_ci    | normal | 60 | Normal battery level|
65e41f4b71Sopenharmony_ci    | high | 90 | High battery level|
66e41f4b71Sopenharmony_ci    | full | 100 | Full battery level|
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci4. 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 battery level configuration to pack the `battery_config.json` file to the `//vendor/etc/battery` directory. The configuration is as follows:
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci    ```shell
72e41f4b71Sopenharmony_ci    import("//build/ohos.gni")               # Reference build/ohos.gni.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci    ohos_prebuilt_etc("battery_config") {
75e41f4b71Sopenharmony_ci        source = "battery_config.json"
76e41f4b71Sopenharmony_ci        relative_install_dir = "battery"
77e41f4b71Sopenharmony_ci        install_images = [ chipset_base_dir ] # Required configuration for installing the battery_config.json file in the vendor directory.
78e41f4b71Sopenharmony_ci        part_name = "product_rk3568"          # Set part_name to product_rk3568 for subsequent build.
79e41f4b71Sopenharmony_ci    }
80e41f4b71Sopenharmony_ci    ```
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci5. 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:
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci    ```json
85e41f4b71Sopenharmony_ci    {
86e41f4b71Sopenharmony_ci    "parts": {
87e41f4b71Sopenharmony_ci        "product_rk3568": {
88e41f4b71Sopenharmony_ci        "module_list": [
89e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/default_app_config:default_app_config",
90e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/image_conf:custom_image_conf",
91e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/preinstall-config:preinstall-config",
92e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/resourceschedule:resourceschedule",
93e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/etc:product_etc_conf",
94e41f4b71Sopenharmony_ci            "//vendor/hihope/rk3568/battery/profile:battery_config" # Add the configuration for building of battery_config.
95e41f4b71Sopenharmony_ci        ]
96e41f4b71Sopenharmony_ci        }
97e41f4b71Sopenharmony_ci    },
98e41f4b71Sopenharmony_ci    "subsystem": "product_hihope"
99e41f4b71Sopenharmony_ci    }
100e41f4b71Sopenharmony_ci    ```
101e41f4b71Sopenharmony_ci    In the preceding code, `//vendor/hihope/rk3568/battery/` is the folder path, `profile` is the folder name, and `battery_config` is the build target.
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci6. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md).
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci    ```shell
106e41f4b71Sopenharmony_ci    ./build.sh --product-name rk3568 --ccache
107e41f4b71Sopenharmony_ci    ```
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci7. Burn the customized version to the DAYU200 development board.
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci### Debugging and Verification
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci1. After startup, run the following command to launch the shell command line:
114e41f4b71Sopenharmony_ci    ```
115e41f4b71Sopenharmony_ci    hdc shell
116e41f4b71Sopenharmony_ci    ```
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci2. Go to the custom battery level configuration directory. The path of DAYU200 is used as an example.
119e41f4b71Sopenharmony_ci    ```
120e41f4b71Sopenharmony_ci    cd /data/service/el0/battery/battery/
121e41f4b71Sopenharmony_ci    ```
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci3. 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.
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci    1. Modify the battery power.
126e41f4b71Sopenharmony_ci    ```
127e41f4b71Sopenharmony_ci    echo 100 > capacity
128e41f4b71Sopenharmony_ci    ```
129e41f4b71Sopenharmony_ci    2. Report the battery power change to obtain the current battery level.
130e41f4b71Sopenharmony_ci    ```
131e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
132e41f4b71Sopenharmony_ci    ```
133e41f4b71Sopenharmony_ci    3. Check whether the battery level is correct.
134e41f4b71Sopenharmony_ci    
135e41f4b71Sopenharmony_ci    ```
136e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
140e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:22:48.589
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci    batteryLevel: 1
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci    ······
147e41f4b71Sopenharmony_ci    ```
148e41f4b71Sopenharmony_ci
149e41f4b71Sopenharmony_ci    4. Modify the battery power.
150e41f4b71Sopenharmony_ci    ```
151e41f4b71Sopenharmony_ci    echo 90 > capacity
152e41f4b71Sopenharmony_ci    ```
153e41f4b71Sopenharmony_ci    5. Report the battery power change to obtain the current battery level.
154e41f4b71Sopenharmony_ci    ```
155e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
156e41f4b71Sopenharmony_ci    ```
157e41f4b71Sopenharmony_ci    6. Check whether the battery level is correct.
158e41f4b71Sopenharmony_ci    
159e41f4b71Sopenharmony_ci    ```
160e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
161e41f4b71Sopenharmony_ci
162e41f4b71Sopenharmony_ci
163e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
164e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:24:29.716
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_ci    batteryLevel: 2
169e41f4b71Sopenharmony_ci    
170e41f4b71Sopenharmony_ci    ······
171e41f4b71Sopenharmony_ci    ```
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci    7. Modify the battery power.
174e41f4b71Sopenharmony_ci    ```
175e41f4b71Sopenharmony_ci    echo 60 > capacity
176e41f4b71Sopenharmony_ci    ```
177e41f4b71Sopenharmony_ci    8. Report the battery power change to obtain the current battery level.
178e41f4b71Sopenharmony_ci    ```
179e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
180e41f4b71Sopenharmony_ci    ```
181e41f4b71Sopenharmony_ci    9. Check whether the battery level is correct.
182e41f4b71Sopenharmony_ci
183e41f4b71Sopenharmony_ci    ```
184e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ci
187e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
188e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:25:09.837
189e41f4b71Sopenharmony_ci
190e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci    batteryLevel: 3
193e41f4b71Sopenharmony_ci    
194e41f4b71Sopenharmony_ci    ······
195e41f4b71Sopenharmony_ci    ```
196e41f4b71Sopenharmony_ci
197e41f4b71Sopenharmony_ci    10. Modify the battery power.
198e41f4b71Sopenharmony_ci    ```
199e41f4b71Sopenharmony_ci    echo 30 > capacity
200e41f4b71Sopenharmony_ci    ```
201e41f4b71Sopenharmony_ci    11. Report the battery power change to obtain the current battery level.
202e41f4b71Sopenharmony_ci    ```
203e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
204e41f4b71Sopenharmony_ci    ```
205e41f4b71Sopenharmony_ci    12. Check whether the battery level is correct.
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci    ```
208e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
212e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:26:20.495
213e41f4b71Sopenharmony_ci
214e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
215e41f4b71Sopenharmony_ci
216e41f4b71Sopenharmony_ci    batteryLevel: 4
217e41f4b71Sopenharmony_ci    
218e41f4b71Sopenharmony_ci    ······
219e41f4b71Sopenharmony_ci    ```
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci    13. Modify the battery power.
222e41f4b71Sopenharmony_ci    ```
223e41f4b71Sopenharmony_ci    echo 15 > capacity
224e41f4b71Sopenharmony_ci    ```
225e41f4b71Sopenharmony_ci    14. Report the battery power change to obtain the current battery level.
226e41f4b71Sopenharmony_ci    ```
227e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
228e41f4b71Sopenharmony_ci    ```
229e41f4b71Sopenharmony_ci    15. Check whether the battery level is correct.
230e41f4b71Sopenharmony_ci
231e41f4b71Sopenharmony_ci    ```
232e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
233e41f4b71Sopenharmony_ci
234e41f4b71Sopenharmony_ci
235e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
236e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:27:05.312
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci    batteryLevel: 5
241e41f4b71Sopenharmony_ci    
242e41f4b71Sopenharmony_ci    ······
243e41f4b71Sopenharmony_ci    ```
244e41f4b71Sopenharmony_ci
245e41f4b71Sopenharmony_ci    16. Modify the battery power.
246e41f4b71Sopenharmony_ci    ```
247e41f4b71Sopenharmony_ci    echo 10 > capacity
248e41f4b71Sopenharmony_ci    ```
249e41f4b71Sopenharmony_ci    17. Report the battery power change to obtain the current battery level.
250e41f4b71Sopenharmony_ci    ```
251e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
252e41f4b71Sopenharmony_ci    ```
253e41f4b71Sopenharmony_ci    18. Check whether the battery level is correct.
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ci    ```
256e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
257e41f4b71Sopenharmony_ci
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
260e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:27:56.270
261e41f4b71Sopenharmony_ci
262e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
263e41f4b71Sopenharmony_ci
264e41f4b71Sopenharmony_ci    batteryLevel: 6
265e41f4b71Sopenharmony_ci    
266e41f4b71Sopenharmony_ci    ······
267e41f4b71Sopenharmony_ci    ```
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci    19. Modify the battery power.
270e41f4b71Sopenharmony_ci    ```
271e41f4b71Sopenharmony_ci    echo 5 > capacity
272e41f4b71Sopenharmony_ci    ```
273e41f4b71Sopenharmony_ci    20. Report the battery power change to obtain the current battery level.
274e41f4b71Sopenharmony_ci    ```
275e41f4b71Sopenharmony_ci    hidumper -s 3302 -a -i
276e41f4b71Sopenharmony_ci    ```
277e41f4b71Sopenharmony_ci    21. Check whether the battery level is correct.
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci    ```
280e41f4b71Sopenharmony_ci    -------------------------------[ability]-------------------------------
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci    ----------------------------------BatteryService---------------------------------
284e41f4b71Sopenharmony_ci    Current time: 2017-08-05 17:28:38.066
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci    ··· (Only the battery level configuration is displayed here. Other information is omitted.)
287e41f4b71Sopenharmony_ci
288e41f4b71Sopenharmony_ci    batteryLevel: 7
289e41f4b71Sopenharmony_ci    
290e41f4b71Sopenharmony_ci    ······
291e41f4b71Sopenharmony_ci    ```
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci## Reference
294e41f4b71Sopenharmony_ciDuring development, you can refer to the [default battery level configuration](https://gitee.com/openharmony/powermgr_battery_manager/blob/master/services/native/profile/battery_config.json), as shown below:
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci 
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci```json
299e41f4b71Sopenharmony_ci{
300e41f4b71Sopenharmony_ci    "soc": {
301e41f4b71Sopenharmony_ci        "shutdown": 1,
302e41f4b71Sopenharmony_ci        "critical": 5,
303e41f4b71Sopenharmony_ci        "warning": 10,
304e41f4b71Sopenharmony_ci        "low": 20,
305e41f4b71Sopenharmony_ci        "normal": 90,
306e41f4b71Sopenharmony_ci        "high": 99,
307e41f4b71Sopenharmony_ci        "full": 100
308e41f4b71Sopenharmony_ci    }
309e41f4b71Sopenharmony_ci}
310e41f4b71Sopenharmony_ci``` 
311e41f4b71Sopenharmony_ci
312e41f4b71Sopenharmony_ciPacking path: /system/etc/battery
313