[Pm-utils] on_ac_power is broken
seife at suse.de
Mon Dec 4 01:22:06 PST 2006
even something as simple as on_ac_power can be broken :-)
This is the bug report i got for it (interesting part starts from comment#10):
Basically the logic right now is:
- check all present ac adapters.
- If any is "online", => exit 0, "on AC power!"
- if no ac adapter was present or online, check if there is any battery.
- if there is a battery => exit 1, "not on AC power!"
- it there is no AC adapter and no battery:
=> assume ac, exit 0
The problem is, that on a desktop, there can be no AC adapter (the power
supply is not exposed via ACPI for example), but a battery, for example
the battery in the wireless mouse :-)
Instead of checking for the exact battery type and add even more dbus calls
to HAL with all their overhead, i decided to just skip the battery test:
- if there are no AC adapters at all:
=> assume "on AC power", since this is probably a desktop.
- check all ac adapters:
- if any is "online", => exit 0, "on AC power"
- exit 1, no ac adapter was online => on battery.
The only thing i can remember where i could be wrong here is if there are
machines where the AC adapter "appears" once you plug it in, and disappears
once you unplug it. I have not yet seen such a machine yet (both ACPI and
APM always have the adapter, but it is either "online" or "offline").
I have no idea how this is handled on power pcs or handheld devices, so
somebody else has to try it there.
@@ -29,13 +29,17 @@
# Check for AC/DC/etc adapters
-for device in $(hal-find-by-capability --capability ac_adapter) ; do
+ac_adapters=$(hal-find-by-capability --capability ac_adapter)
+# If there are no ac_adapters, it is most likely a desktop.
+# assume online
+[ -z "$ac_adapters" ] && exit 0
+# Check if all $ac_adapters are not present
+for device in $ac_adapters ; do
present=$(hal-get-property --udi $device --key ac_adapter.present)
[ "$present" == "true" ] && exit 0
-# If there are no ac_adapters, check for batteries.
-hal-find-by-capability --capability battery >/dev/null 2>&1 && exit 1
-# If there are no batteries assume AC.
+# If none of them were present, ret will be 1, signalling "not on AC power"
QA / R&D Team Mobile Devices | "Any ideas, John?"
SUSE LINUX Products GmbH, Nürnberg | "Well, surrounding them's out."
More information about the Pm-utils