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

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.

Reviewers: bu5hm4n, raster, zmike!, devilhorns

Reviewed By: raster

Subscribers: cedric, bu5hm4n

Tags: #enlightenment-git

Differential Revision: https://phab.enlightenment.org/D7736
This commit is contained in:
Stephen 'Okra' Houston 2019-01-23 10:17:00 -06:00
parent 87c058e04e
commit 42d16a0ec1
1 changed files with 6 additions and 1 deletions

View File

@ -182,7 +182,7 @@ _batman_udev_battery_del(const char *syspath, Instance *inst)
EINA_LIST_FOREACH(batman_device_batteries, l, bat)
{
if (inst == bat->inst)
if ((inst == bat->inst) && (eina_streq(bat->udi, syspath)))
{
batman_device_batteries = eina_list_remove_list(batman_device_batteries, l);
eina_stringshare_del(bat->udi);
@ -324,6 +324,11 @@ _batman_udev_battery_update(const char *syspath, Battery *bat, Instance *inst)
bat->charging = 1;
else if ((!strcmp(test, "Unknown")) && (bat->charge_rate > 0))
bat->charging = 1;
else if ((!strcmp(test, "Unknown")) && (bat->charge_rate <= 0) && (bat->last_full_charge <= 0))
{
_batman_udev_battery_del(syspath, inst);
return;
}
else
bat->charging = 0;
eina_stringshare_del(test);