harmony 鸿蒙uevent Customization
uevent Customization
Overview
Introduction
By 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.
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.
Getting Started with Development
The following uses DAYU200 as an example to illustrate uevent customization.
Modify the
battery_config.json
file in the battery service configuration folder of the HDI layer and the service layer. The uevent configuration is as follows:{ "uevent": { "SUBSYSTEM=hw_power": { "BATTERY_UNDER_VOLTAGE=1": "shutdown", "BATTERY_UNDER_CURRENT=2": "reboot", "BATTERY_UNDER_VOLTAGE=3": "sendcommonevent" } } }
Table 1 Subsystem configuration
|Subsystem|Description| |——–|——–| |SUBSYSTEM=hw_power|Subsystem: hw_power|
**Table 2** uevent description
|uevent|Description| |——–|——–| |BATTERY_UNDER_VOLTAGE=1|uevent (regular expression supported) indicating that the battery voltage is less than 1.| |BATTERY_UNDER_CURRENT=2|uevent (regular expression supported) indicating that the battery voltage is less than 2.| |BATTERY_UNDER_VOLTAGE=3|uevent (regular expression supported) indicating that the battery voltage is less than 3.|
**Table 3** Action description
|Action|Type|Description| |——–|——–|——–| |shutdown|string|Shut down the system.| |reboot|string|Restart the system.| |sendcommonevent|string|Send broadcast.|
Build the customized version by referring to Quick Start.
./build.sh --product-name rk3568 --ccache
Burn the customized version to the DAYU200 development board.
Debugging and Verification
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.
void BatteryThread::UeventCallback(void* service) { char msg[UEVENT_MSG_LEN + UEVENT_RESERVED_SIZE] = { 0 }; ssize_t len = recv(ueventFd_, msg, UEVENT_MSG_LEN, 0); if (len < 0||len >= UEVENT_MSG_LEN) { BATTERY_HILOGI(COMP_HDI, "recv return msg is invalid, len: %{public}zd", len); return; } // msg separator msg[len] = '\0'; msg[len + 1] = '\0'; std::string powerUevent; if (!MatchPowerUevent(msg, powerUevent)) { return; } powerUevent = "BATTERY_UNDER_VOLTAGE=1"; BATTERY_HILOGI(FEATURE_BATT_INFO, "PowerUevent msg:%{public}s", powerUevent.c_str()); UpdateBatteryInfo(service, powerUevent); }
Build the customized version by referring to Quick Start.
./build.sh --product-name rk3568 --ccache
Burn the customized version to the DAYU200 development board.
Check whether the device is powered off when it receives a uevent indicating that the battery voltage is less than 1.
Reference
During development, you can refer to the default uevent configuration, as shown below:
The default configuration is as follows:
{
"uevent": {
"SUBSYSTEM=hw_power": {
"BATTERY_UNDER_VOLTAGE=1": "shutdown",
"BATTERY_UNDER_VOLTAGE=2": "reboot",
"BATTERY_UNDER_VOLTAGE=3": "sendcommonevent"
}
}
}
Packing path: /system/etc/battery
你可能感兴趣的鸿蒙文章
harmony 鸿蒙AI Framework Development Guide
harmony 鸿蒙Neural Network Runtime Device Access
harmony 鸿蒙Application Privilege Configuration
harmony 鸿蒙Setting Up a Development Environment
harmony 鸿蒙Development Guidelines
harmony 鸿蒙Application Framework Overview
harmony 鸿蒙ArkCompiler Development
harmony 鸿蒙Window Title Bar Customization Development (ArkTS)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦