Skip to content

Commit

Permalink
[battery-udev] Add battery tracker that utilizes udev. Fixes JB#43282
Browse files Browse the repository at this point in the history
Reading battery information from virtual filesystem provided by statefs has
problems that vary from one device type to another.

Implementing udev based battery and charger tracking bypasses problematic
statefs interfaces and also allows suspend proofing input processing in more
robust manner.

The battery-udev plugin enumerates all power_supply devices via libudev on
startup and then subscribes to change notifications. Properties exposed via
udev are mapped into battery / charger information in the format expected by
mce and then broadcast internally within mce via relevant aatapipes and
externally on D-Bus.

If some power_supply devices are producing false positives or otherwise
causing problems for the heuristics, they can be excluded from evaluation
via blacklist block in mce configuration files.

  [BatteryUDevDeviceBlacklist]
  <device1 sysname>=TRUE
  <device2 sysname>=TRUE

Sample config file at: inifiles/battery-udev-devices.ini

When debugging (porting to new platform etc) the plugin can be instructed to
track also changes in power_supply properties that should not be relevant
for battery / charger state evaluation via config block like:

  [BatteryUDevPropertyBlacklist]
  <property name>=TRUE  # property changes are not shown
  <property name>=FALSE # property changes are shown
  # properties not mentioned in blacklist are show

Sample config file at: inifiles/battery-udev-properties.ini

Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
  • Loading branch information
spiiroin committed Oct 30, 2018
1 parent c560670 commit d2e2e0a
Show file tree
Hide file tree
Showing 7 changed files with 1,475 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .depend
Expand Up @@ -534,6 +534,26 @@ modules/battery-statefs.pic.o:\
mce-log.h\
mce.h\

modules/battery-udev.o:\
modules/battery-udev.c\
datapipe.h\
mce-conf.h\
mce-io.h\
mce-lib.h\
mce-log.h\
mce-wakelock.h\
mce.h\

modules/battery-udev.pic.o:\
modules/battery-udev.c\
datapipe.h\
mce-conf.h\
mce-io.h\
mce-lib.h\
mce-log.h\
mce-wakelock.h\
mce.h\

modules/battery-upower.o:\
modules/battery-upower.c\
builtin-gconf.h\
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Expand Up @@ -161,6 +161,7 @@ MODULES += $(MODULE_DIR)/battery-bme.so
MODULES += $(MODULE_DIR)/battery-upower.so
MODULES += $(MODULE_DIR)/bluetooth.so
MODULES += $(MODULE_DIR)/battery-statefs.so
MODULES += $(MODULE_DIR)/battery-udev.so
MODULES += $(MODULE_DIR)/buttonbacklight.so
MODULES += $(MODULE_DIR)/display.so
MODULES += $(MODULE_DIR)/usbmode.so
Expand Down Expand Up @@ -345,6 +346,7 @@ MODULE_PKG_NAMES += gmodule-2.0
MODULE_PKG_NAMES += dbus-1
MODULE_PKG_NAMES += dbus-glib-1
MODULE_PKG_NAMES += usb_moded
MODULE_PKG_NAMES += libudev

MODULE_PKG_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(MODULE_PKG_NAMES))
MODULE_PKG_LDLIBS := $(shell $(PKG_CONFIG) --libs $(MODULE_PKG_NAMES))
Expand Down Expand Up @@ -583,6 +585,7 @@ NORMALIZE_USES_SPC =\
modules/audiorouting.c\
modules/battery-upower.c\
modules/battery-statefs.c\
modules/battery-udev.c\
modules/bluetooth.c\
modules/buttonbacklight.c\
modules/callstate.c\
Expand Down Expand Up @@ -660,6 +663,7 @@ NORMALIZE_UNKNOWN = $(filter-out $(NORMALIZE_KNOWN), $(SOURCEFILES_ALL))

normalize::
normalize_whitespace -M Makefile
normalize_whitespace -a inifiles/*.ini config/*.conf
normalize_whitespace -t -b -e -s $(NORMALIZE_USES_SPC)
normalize_whitespace -T -e -s $(NORMALIZE_USES_TAB)
ifneq ($(NORMALIZE_UNKNOWN),)
Expand Down
18 changes: 18 additions & 0 deletions inifiles/battery-udev-devices.ini
@@ -0,0 +1,18 @@
# Configuration file for MCE - udev battery plugin

[BatteryUDevDeviceBlacklist]

# By default mce tracks all power supply devices via udev to evaluate
# current battery capacity, charging status and whether any charger
# devices are in active state. Should there be misclassification or
# other hiccups, mce can be instructed to ignore some devices by
# adding a lines with content:
# <device sysname>=TRUE

# Sony Xperia XA2 has "pc_port" charger power supply device
# occasionally gets stuck to POWER_SUPPLY_ONLINE=1 state - which
# makes it look like charger cable never gets disconnected.
# Blacklisting the charger device means charger connection state
# is deduced from battery charging status rather than potentially
# misreported charger device state.
pc_port=TRUE
156 changes: 156 additions & 0 deletions inifiles/battery-udev-properties.ini
@@ -0,0 +1,156 @@
# Configuration file for MCE - udev battery plugin

[BatteryUDevPropertyBlacklist]

# If "BatteryUDevPropertyBlacklist" config block does not exist,
# mce will track and process only udev properties that are needed
# for battery/charger state evaluation.

# If "BatteryUDevPropertyBlacklist" config block does exist, mce
# will still ignore properties with TRUE value, but emits diagnostic
# logging when undefined / properties set to FALSE change value.

# Thus the idea is that when device is functioning as expected,
# a config file like this is not required at all. But when debugging
# problems, it can be used to gain visibility on select power
# supply device property changes.

# Note: Values that are needed for state evaluation (and thus can't
# be blacklisted) are as follows:
#
# POWER_SUPPLY_PRESENT
# POWER_SUPPLY_ONLINE
# POWER_SUPPLY_CAPACITY
# POWER_SUPPLY_STATUS

# Generic device properties
bootdevice=TRUE
ACTION=TRUE
DEVPATH=TRUE
PLATFORM_DEVICE=TRUE
PLATFORM_FOLDER=TRUE
SEQNUM=TRUE
SUBSYSTEM=TRUE
USEC_INITIALIZED=TRUE

# "Uninteresting" power supply device specific properties seen
# on already supported hardwares.
POWER_SUPPLY_ALLOW_HVDCP3=TRUE
POWER_SUPPLY_BATTERY_CHARGING_ENABLED=TRUE
#POWER_SUPPLY_BATTERY_TYPE=TRUE
POWER_SUPPLY_BATT_AGING=TRUE
POWER_SUPPLY_BOOST_CURRENT=TRUE
POWER_SUPPLY_CABLE_TYPE
POWER_SUPPLY_CAPACITY_RAW=TRUE
POWER_SUPPLY_CC_STEP=TRUE
POWER_SUPPLY_CC_STEP_SEL=TRUE
POWER_SUPPLY_CHARGER_DISABLE
POWER_SUPPLY_CHARGER_TEMP=TRUE
POWER_SUPPLY_CHARGER_TEMP_MAX=TRUE
POWER_SUPPLY_CHARGE_CONTROL_LIMIT
POWER_SUPPLY_CHARGE_CONTROL_LIMIT_MAX
POWER_SUPPLY_CHARGE_COUNTER=TRUE
POWER_SUPPLY_CHARGE_CURRENT
POWER_SUPPLY_CHARGE_DONE=TRUE
POWER_SUPPLY_CHARGE_FULL=TRUE
POWER_SUPPLY_CHARGE_FULL_DESIGN=TRUE
POWER_SUPPLY_CHARGE_NOW=TRUE
POWER_SUPPLY_CHARGE_NOW_ERROR=TRUE
POWER_SUPPLY_CHARGE_NOW_RAW=TRUE
POWER_SUPPLY_CHARGE_TERM_CUR
#POWER_SUPPLY_CHARGE_TYPE=TRUE
POWER_SUPPLY_CHARGE_VOLTAGE
POWER_SUPPLY_CHARGING_ENABLED=TRUE
POWER_SUPPLY_CONSTANT_CHARGE_CURRENT_MAX=TRUE
POWER_SUPPLY_CONSTANT_CHARGE_VOLTAGE=TRUE
POWER_SUPPLY_CTM_CURRENT_MAX=TRUE
POWER_SUPPLY_CURRENT_AVG
POWER_SUPPLY_CURRENT_MAX=TRUE
POWER_SUPPLY_CURRENT_NOW=TRUE
POWER_SUPPLY_CURRENT_QNOVO=TRUE
POWER_SUPPLY_CYCLE_COUNT=TRUE
POWER_SUPPLY_CYCLE_COUNT_ID=TRUE
POWER_SUPPLY_DEBUG_BATTERY=TRUE
POWER_SUPPLY_DIE_HEALTH=TRUE
POWER_SUPPLY_DP_DM=TRUE
POWER_SUPPLY_ENABLE_CHARGER
POWER_SUPPLY_ENABLE_CHARGING
POWER_SUPPLY_ENABLE_SHUTDOWN_AT_LOW_BATTERY=TRUE
POWER_SUPPLY_ENERGY_EMPTY
POWER_SUPPLY_ENERGY_EMPTY_DESIGN
POWER_SUPPLY_ENERGY_FULL
POWER_SUPPLY_ENERGY_FULL_DESIGN
POWER_SUPPLY_ENERGY_NOW
POWER_SUPPLY_ESR_COUNT=TRUE
POWER_SUPPLY_FCC_DELTA=TRUE
POWER_SUPPLY_FLASH_ACTIVE=TRUE
POWER_SUPPLY_FLASH_CURRENT_MAX=TRUE
POWER_SUPPLY_FLASH_TRIGGER=TRUE
POWER_SUPPLY_FV_CFG=TRUE
POWER_SUPPLY_FV_CMP_CFG=TRUE
POWER_SUPPLY_HEALTH=TRUE
POWER_SUPPLY_HI_POWER
POWER_SUPPLY_HW_CURRENT_MAX=TRUE
POWER_SUPPLY_INPUT_CURRENT_LIMITED=TRUE
POWER_SUPPLY_INPUT_CURRENT_MAX=TRUE
POWER_SUPPLY_INPUT_CURRENT_NOW=TRUE
POWER_SUPPLY_INPUT_CURRENT_SETTLED=TRUE
POWER_SUPPLY_INPUT_CUR_LIMIT
POWER_SUPPLY_INPUT_SUSPEND=TRUE
POWER_SUPPLY_INPUT_VOLTAGE_SETTLED=TRUE
POWER_SUPPLY_INT_CLD=TRUE
POWER_SUPPLY_LOW_POWER
POWER_SUPPLY_LRC_ENABLE=TRUE
POWER_SUPPLY_LRC_NOT_STARTUP=TRUE
POWER_SUPPLY_LRC_SOCMAX=TRUE
POWER_SUPPLY_LRC_SOCMIN=TRUE
POWER_SUPPLY_MAX_CHARGE_CURRENT
POWER_SUPPLY_MAX_CHARGE_VOLTAGE
POWER_SUPPLY_MAX_TEMP
POWER_SUPPLY_MIN_TEMP
POWER_SUPPLY_MODEL_NAME
POWER_SUPPLY_NAME=TRUE
POWER_SUPPLY_PARALLEL_DISABLE=TRUE
POWER_SUPPLY_PARALLEL_MODE=TRUE
POWER_SUPPLY_PD_ACTIVE=TRUE
POWER_SUPPLY_PD_ALLOWED=TRUE
POWER_SUPPLY_PD_CURRENT_MAX=TRUE
POWER_SUPPLY_PD_VOLTAGE_MAX=TRUE
POWER_SUPPLY_PD_VOLTAGE_MIN=TRUE
POWER_SUPPLY_PE_START=TRUE
POWER_SUPPLY_PR_SWAP=TRUE
#POWER_SUPPLY_REAL_TYPE=TRUE
POWER_SUPPLY_RERUN_AICL=TRUE
POWER_SUPPLY_RESISTANCE=TRUE
POWER_SUPPLY_RESISTANCE_CAPACITIVE
POWER_SUPPLY_RESISTANCE_ID=TRUE
POWER_SUPPLY_RESISTANCE_NOW
POWER_SUPPLY_RESTRICTED_CHARGING=TRUE
POWER_SUPPLY_SAFETY_TIMER_ENABLED=TRUE
POWER_SUPPLY_SCOPE=TRUE
POWER_SUPPLY_SDP_CURRENT_MAX=TRUE
POWER_SUPPLY_SET_SHIP_MODE=TRUE
POWER_SUPPLY_SOC_REPORTING_READY=TRUE
POWER_SUPPLY_STEP_CHARGING_ENABLED=TRUE
#POWER_SUPPLY_SUB_TYPE=TRUE
POWER_SUPPLY_SW_JEITA_ENABLED=TRUE
POWER_SUPPLY_SYSTEM_TEMP_LEVEL=TRUE
POWER_SUPPLY_TECHNOLOGY=TRUE
POWER_SUPPLY_TEMP=TRUE
POWER_SUPPLY_TEMP_COOL=TRUE
POWER_SUPPLY_TEMP_WARM=TRUE
POWER_SUPPLY_TIME_TO_EMPTY_AVG=TRUE
POWER_SUPPLY_TIME_TO_FULL_AVG=TRUE
#POWER_SUPPLY_TYPE=TRUE
POWER_SUPPLY_TYPEC_CC_ORIENTATION=TRUE
POWER_SUPPLY_TYPEC_MODE=TRUE
POWER_SUPPLY_TYPEC_POWER_ROLE=TRUE
POWER_SUPPLY_UPDATE_NOW=TRUE
POWER_SUPPLY_USB_OTG=TRUE
POWER_SUPPLY_VOLTAGE_MAX=TRUE
POWER_SUPPLY_VOLTAGE_MAX_DESIGN=TRUE
POWER_SUPPLY_VOLTAGE_MIN=TRUE
POWER_SUPPLY_VOLTAGE_MIN_DESIGN
POWER_SUPPLY_VOLTAGE_NOW=TRUE
POWER_SUPPLY_VOLTAGE_OCV=TRUE
POWER_SUPPLY_VOLTAGE_QNOVO=TRUE
2 changes: 1 addition & 1 deletion inifiles/mce.ini
Expand Up @@ -16,7 +16,7 @@ ModulePath=/usr/lib/mce/modules
# to avoid unnecessary brightness fluctuations on mce startup
#
# Note: the name should not include the "lib"-prefix
Modules=radiostates;filter-brightness-als;display;keypad;led;battery-statefs;inactivity;alarm;callstate;audiorouting;proximity;powersavemode;cpu-keepalive;doubletap;packagekit;sensor-gestures;bluetooth;memnotify;usbmode;buttonbacklight;fingerprint;
Modules=radiostates;filter-brightness-als;display;keypad;led;battery-udev;inactivity;alarm;callstate;audiorouting;proximity;powersavemode;cpu-keepalive;doubletap;packagekit;sensor-gestures;bluetooth;memnotify;usbmode;buttonbacklight;fingerprint;

[KeyPad]

Expand Down

0 comments on commit d2e2e0a

Please sign in to comment.