1# uevent Customization 2 3## Overview 4 5### Introduction 6 7By default, OpenHarmony is designed to take an action based on the uevent received by the battery management system. To address your diverse demands, OpenHarmony provides the uevent customization function, allowing you to customize the uevents for taking desired actions. The customization is simply done through modification of the configuration file. 8 9## How to Develop 10 11### Setting Up the Environment 12 13**Hardware requirements:** 14 15Development board running the standard system, for example, the DAYU200 or Hi3516D V300 open source suite. 16 17**Environment requirements:** 18 19For details about the requirements on the Linux environment, see [Quick Start](../quick-start/quickstart-overview.md). 20 21### Getting Started with Development 22 23The following uses [DAYU200](https://gitee.com/openharmony/vendor_hihope/tree/master/rk3568) as an example to illustrate uevent customization. 24 251. Modify the `battery_config.json` file in the battery service configuration folder of the [HDI layer](https://gitee.com/openharmony/drivers_peripheral/tree/master/battery/interfaces/hdi_service/profile) and the [service layer](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile). The uevent configuration is as follows: 26 27 ```json 28 { 29 "uevent": { 30 "SUBSYSTEM=hw_power": { 31 "BATTERY_UNDER_VOLTAGE=1": "shutdown", 32 "BATTERY_UNDER_CURRENT=2": "reboot", 33 "BATTERY_UNDER_VOLTAGE=3": "sendcommonevent" 34 } 35 } 36 } 37 ``` 38 39 **Table 1** Subsystem configuration 40 41 | **Subsystem**| Description| 42 | -------- | -------- | 43 | SUBSYSTEM=hw_power | Subsystem: **hw_power**| 44 45 **Table 2** uevent description 46 47 | uevent| Description| 48 | -------- | -------- | 49 | BATTERY_UNDER_VOLTAGE=1 | uevent (regular expression supported) indicating that the battery voltage is less than 1.| 50 | BATTERY_UNDER_CURRENT=2 | uevent (regular expression supported) indicating that the battery voltage is less than 2.| 51 | BATTERY_UNDER_VOLTAGE=3 | uevent (regular expression supported) indicating that the battery voltage is less than 3.| 52 53 **Table 3** Action description 54 55 | Action| Type| Description| 56 | -------- | -------- | -------- | 57 | shutdown | string | Shut down the system.| 58 | reboot | string | Restart the system.| 59 | sendcommonevent | string | Send broadcast.| 60 612. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 62 63 ```shell 64 ./build.sh --product-name rk3568 --ccache 65 ``` 66 673. Burn the customized version to the DAYU200 development board. 68 69### Debugging and Verification 70 711. Change the uevent receiving code (https://gitee.com/openharmony/drivers_peripheral/blob/master/battery/interfaces/hdi_service/src/battery_thread.cpp) to forcibly receive the uevent event BATTERY_UNDER_VOLTAGE=1 in the configuration file. 72 ```c++ 73 void BatteryThread::UeventCallback(void* service) 74 { 75 char msg[UEVENT_MSG_LEN + UEVENT_RESERVED_SIZE] = { 0 }; 76 77 ssize_t len = recv(ueventFd_, msg, UEVENT_MSG_LEN, 0); 78 if (len < 0 || len >= UEVENT_MSG_LEN) { 79 BATTERY_HILOGI(COMP_HDI, "recv return msg is invalid, len: %{public}zd", len); 80 return; 81 } 82 83 // msg separator 84 msg[len] = '\0'; 85 msg[len + 1] = '\0'; 86 87 std::string powerUevent; 88 if (!MatchPowerUevent(msg, powerUevent)) { 89 return; 90 } 91 powerUevent = "BATTERY_UNDER_VOLTAGE=1"; 92 BATTERY_HILOGI(FEATURE_BATT_INFO, "PowerUevent msg:%{public}s", 93 powerUevent.c_str()); 94 UpdateBatteryInfo(service, powerUevent); 95 } 96 ``` 972. Build the customized version by referring to [Quick Start](../quick-start/quickstart-overview.md). 98 99 ```shell 100 ./build.sh --product-name rk3568 --ccache 101 ``` 102 1033. Burn the customized version to the DAYU200 development board. 1044. Check whether the device is powered off when it receives a uevent indicating that the battery voltage is less than 1. 105 106## Reference 107During development, you can refer to the [default uevent configuration](https://gitee.com/openharmony/powermgr_battery_manager/tree/master/services/native/profile/), as shown below: 108 109The default configuration is as follows: 110 111```json 112{ 113 "uevent": { 114 "SUBSYSTEM=hw_power": { 115 "BATTERY_UNDER_VOLTAGE=1": "shutdown", 116 "BATTERY_UNDER_VOLTAGE=2": "reboot", 117 "BATTERY_UNDER_VOLTAGE=3": "sendcommonevent" 118 } 119 } 120} 121``` 122 123Packing path: /system/etc/battery 124