UPower is an abstraction for enumerating power devices, listening to device events and querying history and statistics. Any application or service on the system can access the org.freedesktop.UPower service via the system message bus. Some operations (such as suspending the system) are restricted using PolicyKit.
UPower is used by applications such as the XFCE4 power manager applet and the Gnome power manager applet to determine if your laptop is plugged in or not, and if the battery is charging or not.
Unfortunately, UPower has some gotchas, especially with laptops. Sometimes, UPower doesn’t return the AC Power supply status correctly as it is with some of my laptops (it gets stuck in AC mode or Power mode, and the status doesn’t change until next boot, or when the laptop goes into suspend then back online again)
This is practically one of the linux annoyances I have, especially with laptops. Since I installed TLP on lubuntu (see my post here), and found out that TLP detects whether your laptop is plugged in or not correctly, and is only run on bootup time (but not polled), I wanted to turn on battery mode or ac mode of tlp in realtime by polling every 3 seconds.
This is how I did it.
Let us create a small perl script named powerpoll.pl and place it in /usr/bin (of course you have to make it executable by using chmod a+x):
$old = '4';
$new = 0;
$new = `cat /sys/class/power_supply/ADP1/online`;
if($old != $new)
$old = $new;
ADP1 here is based on my Samsung Ultranote. Replace this with the name that your laptop gives for this address.
You have to add the line:
/usr/bin/powerpoll.pl & > /dev/null
in the /etc/rc3.d/S99ondemand file on the line after:
start-stop-daemon –start –background –exec /etc/init.d/ondemand…
killall -9 powerpoll.pl
after the stop) line
In this way, the tlp program will run in battery mode and ac mode depending whether or not the power is plugged on or not every 3 seconds. The program ensures also that the tlp program will not be run every 3 seconds if the status of the ac power does not change.
This is a hackish way of forcing power management, but it works.
You can modify this perl script also by setting up brightness upon plugging of ac power and unplugging it.