Page MenuHomePhabricator

Batman Udev: Don't include batteries who have unknown status, have never had a full charge, and have no charge rate.
ClosedPublic

Authored by stephenmhouston on Jan 23 2019, 8:18 AM.

Details

Summary

This fixes issues where erroneous udev detections of batteries are included. @bu5hm4n and I both have had issues where udev thinks we have two batteries because our hid/touchscreens report a battery even though they are not accurate. The problem is batman will then think there are two batteries and calculate battery percentage based off both batteries. For instance if the laptop battery is 100% and it is detecting this phony hid battery, the result is batman thinks you are at 50% battery life. This also fixes the battery removal code which should only remove the battery with the syspath the function is called with. The code was actually removing every single battery.

Test Plan

You have to have a device that udev reports two batteries for when there aren't two. It should be harmless to not include batteries that have never been charged, have no charge, and have unknown for their status.

Diff Detail

Repository
rE core/enlightenment
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 9043
Build 7820: arc lint + arc unit
stephenmhouston requested review of this revision.Jan 23 2019, 8:18 AM
raster accepted this revision.Jan 23 2019, 9:06 AM
This revision was not accepted when it landed; it landed in state Needs Review.Jan 23 2019, 10:58 AM
This revision was automatically updated to reflect the committed changes.

I have some data for hid devices with batteries. these are real devices with rechargeable batteries and ... I actually see proper reports. Note that my mouse (MX Master) showed "Unknown" until I unplugged it to run wirelessly for a while - then it started showing Full as the charge level. The Craft Keyboard shows Full. Here they were plugged in:

Directory contents so you can match it up to the cat's below:

0 capacity_level  0 model_name  0 powers@        0 status      0 uevent
0 device@         0 online      0 scope          0 subsystem@
0 manufacturer    0 power/      0 serial_number  0 type
 9:45AM /sys/class/power_supply/hidpp_battery_0 > cat *
Unknown
cat: device: Is a directory
Logitech
Wireless Mouse MX Master 2S
0
cat: power: Is a directory
cat: powers: Is a directory
Device
4069-73-db-25-08
Unknown
cat: subsystem: Is a directory
Battery
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_ONLINE=0
POWER_SUPPLY_STATUS=Unknown
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Wireless Mouse MX Master 2S
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=4069-73-db-25-08
POWER_SUPPLY_CAPACITY_LEVEL=Unknown

 9:46AM /sys/class/power_supply/hidpp_battery_1 > cat *
Full
cat: device: Is a directory
Logitech
Craft Advanced Keyboard
1
cat: power: Is a directory
cat: powers: Is a directory
Device
4066-5e-a0-53-3f
Full
cat: subsystem: Is a directory
Battery
POWER_SUPPLY_NAME=hidpp_battery_1
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Full
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Craft Advanced Keyboard
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=4066-5e-a0-53-3f
POWER_SUPPLY_CAPACITY_LEVEL=Full

Now unplugged for few minutes:

 9:59AM /sys/class/power_supply/hidpp_battery_0 > cat *
Full
cat: device: Is a directory
Logitech
Wireless Mouse MX Master 2S
1
cat: power: Is a directory
cat: powers: Is a directory
Device
4069-73-db-25-08
Discharging
cat: subsystem: Is a directory
Battery
POWER_SUPPLY_NAME=hidpp_battery_0
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Wireless Mouse MX Master 2S
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=4069-73-db-25-08
POWER_SUPPLY_CAPACITY_LEVEL=Full

 9:59AM /sys/class/power_supply/hidpp_battery_1 > cat *
Full
cat: device: Is a directory
Logitech
Craft Advanced Keyboard
1
cat: power: Is a directory
cat: powers: Is a directory
Device
4066-5e-a0-53-3f
Discharging
cat: subsystem: Is a directory
Battery
POWER_SUPPLY_NAME=hidpp_battery_1
POWER_SUPPLY_ONLINE=1
POWER_SUPPLY_STATUS=Discharging
POWER_SUPPLY_SCOPE=Device
POWER_SUPPLY_MODEL_NAME=Craft Advanced Keyboard
POWER_SUPPLY_MANUFACTURER=Logitech
POWER_SUPPLY_SERIAL_NUMBER=4066-5e-a0-53-3f
POWER_SUPPLY_CAPACITY_LEVEL=Full

So this is an example of valid battery driven/powered devices that Sometimes report Unknown (and report last full charge of 0 or none at all so it should equate to 0, and charge_rate of 0 too. My mouse even says its not online, but it is... or was (when plugged in). Perhaps when plugged in it is charging thus not online as a power_supply kind of device, thus Unknown level?

Anyway - These are devices that need to be filtered out of system battery level (when considering the batteries powering the whole device), BUT probably should be exposed in some extended info somewhere device by device. so actually some of the above should maybe become || not && ... Perhaps some devices report detailed battery levels (0-100)? These devices only report coarse strings. https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power has the details on those.

Could you ls and cat * for your errant devices (hidp/touchscreen) that reports its a power supply? Mine are true real battery powered hidp devices doing this correctly, yours seem to be wrong in doing this.