Comment 36 for bug 384304

Revision history for this message
In , Martin Pitt (pitti) wrote :

Created an attachment (id=31309)
proposed patch

In the downstream bug, Javier Martín proposed a patch which fixed the issue for him.

------ quote ------
Attached is a patch to fix this bug. The problem is in function dkp_daemon_get_on_battery_local of dkp-daemon.c. The logic is "we're on battery as soon as _any_ battery goes discharging", but often batteries have troubles reporting their charging/discharging status and just say "unknown" (at least in my two laptops, an IBM T42 and an Asus Eee 901), so relying on the batteries' status to figure out wether we are plugged in or not is not acceptable. Rather, we should ask the AC power device directly and change the above logic to: "we're on battery as soon as _any_ AC supply goes online".

This fixes the scenario in which devkit-power -d reports "on-battery: no" after unplugging the AC, but apparently only when the battery is fully charged. Under those circumstances, the battery (through the /sys/devices filesystem) happens to report an "Unknown" status (who knows why). That confuses the devkit-power daemon, since the "on-battery" yes/no decision depends on the battery reporting a "charging" or "discharging" status, and not on the AC device itself (which seems more sensible to me).

The end result is that gnome-power-manager will never realize when AC goes off-line and it will never switch to the "on battery" policy. The biggest
issue I had with this was that my laptop never went to sleep after closing
the lid (since I only instruct g-p-m to suspend when closing the lid on
batteries) and I've already found my laptop cooking in its bag three times.
----------- end quote -------------