Skip to content

linux: Fix batteries which report capacity and energy/charge

linux: Fix batteries which report capacity and energy/charge

In commit 07b95b8e, a consideration for Android devices was added:

    commit 07b95b8e27e7c488828c46a28df96f1c83b185c8
    Author: Martin Pitt <martinpitt@gnome.org>
    Date:   Fri Aug 23 08:31:20 2013 +0200

        linux: Fix batteries which report capacity, but not energy/charge

        Many Android devices only export charge_full and capacity, but not charge_now
        or energy_now. In that case, directly read the percentage (from the capacity
        attribute) and calculate current energy from that.

        Thanks to Seth Forshee for the original patch!

        https://bugs.freedesktop.org/show_bug.cgi?id=68337

The change was meant to help generate an useful energy property for these devices, so that a realistic percentage could be calculated.

However, this accidentally made the if() block that calculated the percentage into an else if() that was only reached on systems where the battery did not report a capacity property.

In practice, this meant that any battery with a reported capacity would use that as its percentage, instead of calculating it from energy and energy_full.

Closes: #103 (closed)

Edited by Bastien Nocera

Merge request reports