Commit graph

83 commits

Author SHA1 Message Date
Richard Hughes
2d8358ae4e Fix how we estimate the device rate for batteries that do not provide this data
Based on a patch from Andy Eyre <andrew.eyre@medschool.ox.ac.uk>, many thanks.
2011-07-01 17:14:58 +01:00
Martin Pitt
a1fe30811d Linux integration tests: check energy vs. charge
So far the test cases only covered drivers which reported energy (µWh). Add
checks that the Energy* properties are correct, and add a test case for drivers
which report charge (µAh).
2011-05-14 14:39:16 +02:00
Martin Pitt
5c37df249b trivial: Fix Linux integration test dependency on upowerd
With nested Makefiles we can't depend on a generated file in a different
directory (breaks "make clean && make check"). Thus move the call of the Linux
integration test suite into src/Makefile.am, and only run it if we build the
Linux backend.
2011-04-26 14:31:00 +02:00
Martin Pitt
37fdb2c959 trivial: Fix Linux integration-test for distcheck
distcheck uses a separate build tree, thus call the script from the right
directory. Also actually ship it in release tarballs.
2011-04-26 12:48:23 +02:00
Martin Pitt
5cb1f4a9a3 Consider a discharging UPS as "on battery"
Implement get_{on,low}_battery() methods on HID devices for Linux. This will
treat discharging UPSes like batteries and set the "on-battery" and
"on-low-battery" properties accordingly.

This also fixes the test_ups_ac() case in the Linux integration tests.
2011-04-26 11:50:36 +02:00
Martin Pitt
a786d2fd16 Fix "unknown" battery status guessing to not be recursive
Stop querying the global "on-battery" property when trying to guess the status
of a battery which reports as "unknown", as "on-battery" is itself defined in
terms of the states of the individual batteries. Instead, guess the state based
on whether we have any AC available; if so, we can reasonably assume
charging/discharging based on whether any AC is online. If no AC is present,
assume discharging (as we did before), but only if we have only one battery.

Stop guessing for the case where we don't have any AC device, "unknown" battery
state, and multiple batteries, as then we can't know which battery is currently
discharging.

https://bugs.freedesktop.org/show_bug.cgi?id=24371
2011-04-26 11:50:36 +02:00
Martin Pitt
7c617ba6f1 Run Linux integration tests in "make check"
If possible, run the tests under dbus-launch to ensure that there is a private
D-BUS session bus. This allows the tests to work in e. g. a clean package build
environment, and also avoids messing with the real user session bus.
2011-04-26 11:50:36 +02:00
Martin Pitt
e1f4aa38de Add integration test suite for Linux
Add src/linux/integration-test: This is a Python unittest based test suite
which provides methods for building a sandbox sysfs tree, runs upowerd
in it, and checks for correct properties.

As it is really hard to provide fake uevents, this currently only works for
properties which do not depend on dynamic system changes, i. e. you can
currently only check the status after coldplugging.

However, this already provides enough possibilities for functionality and
regression testing, and exposes some bugs with determining the "OnBattery"
property under certain conditions like the ones described in
<https://bugs.freedesktop.org/show_bug.cgi?id=24371>.

If any of the tests fails, the daemon log will be printed to stderr for easier
debugging.

With the previous commit that adds "upowerd --test", we can also run
the integration tests as non-root. If they are called as root, start upowerd
normally on the system bus, otherwise on the session bus with --test.
2011-04-26 11:50:36 +02:00
Martin Pitt
f65aa4dbf2 Support virtual UPS devices for testing
If a HID device is marked with the UPOWER_FAKE_DEVICE udev property, don't send
ioctl commands to it, but instead read status and percentage from udev
properties as well (UPOWER_FAKE_HID_CHARGING and UPOWER_FAKE_HID_PERCENTAGE).

This allows developers or a test suite to test the behaviour of UPSes without
actually having one.
2011-04-26 11:28:32 +02:00
Richard Hughes
b458ef8250 trivial: fix whitespace issue with the last patch 2011-03-30 19:23:35 +01:00
Benson Leung
95ecdb25b2 Support batteries that report both energy and charge.
More cleanly support batteries that report both energy and charge,
but do not report power_now. One battery driver in drivers/power
(bq20z75) supports reporting energy and charge natively from the
fuel gauge, but does not report power_now. The previous legacy behavior
would ignore the existence of charge and treat current_now as
being in units of power.

Signed-off-by: Benson Leung <bleung@chromium.org>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2011-03-30 14:16:21 +01:00
Richard Hughes
b0bbb29df1 Add a config option 'EnableWattsUpPro' to disable the Watts Up Pro device
Annoyingly, the device used in the Watts Up Pro device seems to be a generic
USB->serial adaptor, which means it doesn't have a unique vendor and product
ID. If we try to probe for the WUP device, we can actually upset other devices
that are not expecing to be probed. This fixes #33846 although we actually
still need to be more strict in detecting a true WUP device.
2011-03-14 11:01:12 +00:00
Michael Biebl
d1e5f6a4da Depend on stable GUdev API
The GUdev API was declared stable in udev release 147.
Bump the version in the configure check and drop the
G_UDEV_API_IS_SUBJECT_TO_CHANGE defines.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2011-03-09 11:03:44 +00:00
Arnaud Patard
8b9ee53133 up-input.c: fix bitmap check
In up_input_coldplug(), some checks are done on the input device found in order
to detect if it's a lid switch or not.

The following one is problematic :

         /* convert to a bitmask */
         num_bits = up_input_str_to_bitmask (contents, bitmask, sizeof (bitmask));
         if (num_bits != 1) {
                 g_debug ("not one bitmask entry for %s", native_path);
                 ret = FALSE;
                 goto out;
         }

Checking if there's only 1 bit set is wrong. It's nice if you have a x86 with
acpi using 1 input device for the lid switch but it's not always nice.
One can create input devices with gpios-keys like this:

 static struct gpio_keys_button keys[] = {
         {
                 .code = SW_LID,
                 .gpio = ...,
                 .type = EV_SW,
                 .desc = "Lid Switch",
         },
         {
                 .code = SW_RFKILL_ALL,
                 .gpio = ...,
                 .type = EV_SW,
                 .desc = "rfkill",
         },
 };

The resulting SW bitmap will be 9 and thus there are 2 bits sets and due to the
mentionned check, the device is ignored by upower.

As a fix, I'm checking if the number of bits is between 0 and SW_CNT
bits.

Signed-off-by: Arnaud Patard <arnaud.patard@rtp-net.org>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2011-03-04 17:29:44 +00:00
Richard Hughes
38199e44ff Add an option for polling dock devices in UPower.conf, defaulting to false 2011-03-03 14:02:27 +00:00
Richard Hughes
17b7aef701 linux: use the number of active DRM devices to determine the system docked status
Not ideal, but better than relying on ACPI.
2011-01-04 18:05:09 +00:00
Richard Hughes
2af7a6e091 Support the power_now sysfs attribute to get time remaining on new kernels
The kernel has removed the insanity of providing current_now in either
(and unspecified) units of uVh or uWh and instead provides power_now
for the power rate value.

Related commits:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=b137b9942a07843c64a934cfdb7d43155e507e13
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7faa144a518c456e2057918f030f50100144ccc6

Thanks to Florian Eitel for the initial patch.
2011-01-04 09:30:22 +00:00
Martin Pitt
04dd349103 Fix compilation eror against Linux 2.6.36
Include <stdint.h> so that <linux/fs.h> can use uint64_t. Arguably a bug in the
kernel headers, but it costs us nothing to safeguard against it.

  CC     libupshared_la-up-device-idevice.lo
In file included from sysfs-utils.c:39:0:
/usr/include/linux/fs.h:37:2: error: expected specifier-qualifier-list before ‘uint64_t’
2010-11-04 18:45:10 -04:00
Richard Hughes
59893663fb Port from EggDebug to the GLib built-in logging framework 2010-11-01 11:28:31 +00:00
Michal Schmidt
e76b05967b remove the UP_DEVICE_SUPPLY_CHARGED_THRESHOLD heuristic
When a full battery starts to discharge, but reports its status as 'Unknown',
it takes a few minutes before g-p-m notices any change.
upowerd guesses the battery is fully charged as long as it has over 90% charge.

I see no reason to delay the reporting of discharging of the battery.
Let's remove this heuristic.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2010-10-21 16:18:44 +01:00
Richard Hughes
163d5fc355 Do not continue to poll the serial port if there is no Watts Up Pro adaptor 2010-09-20 16:22:45 +01:00
Richard Hughes
7e45ad91ed trivial: fix make distcheck 2010-09-17 16:10:39 +01:00
Martin Pitt
c4a1c15d0c Fix UP_DAEMON_WATERLINE harder
Commmit fc7c6e003 had a thinko, UP_DAEMON_WATERLINE specifies (active
memory)/(available swap), not the other way around. So replace it with 99%
instead.

Also update the documentation of up_backend_get_used_swap() to explain what the
returned percentage actually means.
2010-07-07 15:08:43 +02:00
Martin Pitt
04eefe984c src/linux/up-backend.c: Add missing #include
We need sys/wait.h to get the WEXITSTATUS (and related) macros.
2010-07-07 11:20:47 +02:00
Richard Hughes
6118ac82ec Get the powersave command from the backend rather than hardcoding Linux specifics 2010-07-07 10:07:37 +01:00
Mariusz Ceier
ac8fa9d5be up-device-supply.c: Fix #27902 Bug - Daemon Segmentation Fault
In linux backend, g_object_set was called with wrong
argument types for time-to-empty,time-to-full and percentage
properties. This patch uses explicit casts in the same way as freebsd
backend.

Signed-off-by: Mariusz Ceier <mceier@gmail.com>
2010-07-02 14:04:42 +01:00
Victor Lowther
6770e8cb34 Use pm-is-supported to test if various sleep modes are supported.
pm-is-supported does all the work upower was duplicating, and it handles more
use cases than the old upower code did.  No point in duplicating functionality.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2010-06-14 08:59:40 +01:00
Victor Lowther
da3a51d2e8 Cast cnt to int to stop gcc from complaining.
GCC was complaining about int and ssize_t being differnt types.
Make it quit doing that.
2010-06-14 08:56:27 +01:00
Richard Hughes
82a6a882d0 Assign names to our idle sources when using new versions of glib2
This makes it possible to profile more accurately using systemtap
2010-06-05 15:55:29 +01:00
Richard Hughes
34add0cfe2 Add UP_DEVICE_KIND_COMPUTER as we'll need UP_DEVICE_KIND_TABLET for wacom tablets 2010-06-01 14:25:10 +01:00
Steven Walter
6bb6602c06 When calculating used swap space, only use anonymous pages
up_daemon_check_swap_space uses the Active: line from /proc/meminfo to
determine the amount of swap the system needs to be able to suspend.  However,
because Active: includes both anonymous and file-backed pages, this greatly
overestimates the amount of swap needed.  File-backed pages can be written back
to disk and so do not consume swap.

Instead, up_daemon_check_swap_space should use Active(anon): from /proc/meminfo
because only anonymous pages need to be written out to swap during a suspend.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2010-05-29 13:12:57 +01:00
Richard Hughes
37504601f3 trivial: print the specific error from libusb1 2010-05-28 15:15:11 +01:00
Bastien Nocera
18c8d26b02 Fix compilation of the idevice device
My fault :(
2010-05-28 14:39:16 +01:00
Bastien Nocera
5cec5b180f Fix up a few leaks Richard introduced...
Signed-off-by: Richard Hughes <richard@hughsie.com>
2010-05-28 14:11:04 +01:00
Richard Hughes
36bf9c5cde trivial: fix a tiny warning reported by clang with the capacity code intial value 2010-05-28 14:10:22 +01:00
Richard Hughes
5c17b5a147 Fix up a potential crasher in the CSR device code 2010-05-28 14:03:56 +01:00
Bastien Nocera
7019d214f8 Add battery query support for iDevices
https://bugs.freedesktop.org/show_bug.cgi?id=28286
Signed-off-by: Richard Hughes <richard@hughsie.com>
2010-05-28 13:49:56 +01:00
Richard Hughes
2b826a3169 Port UPower to libusb1 to avoid crappy unfixable crashes 2010-05-18 09:37:17 +01:00
Kyle McMartin
5881e7435f Detect when the kernel changes the reported charge units. Fixes rh#587112
Signed-off-by: Richard Hughes <richard@hughsie.com>
2010-05-11 15:53:48 +01:00
Sascha Silbe
4baf27ae15 fix recognition of lithium iron phosphate (LiFePO4) batteries
The linux kernel returns "LiFe" for lithium iron phosphate batteries,
not LiFo.
2010-05-03 15:18:44 +01:00
Richard Hughes
3dee7b22f8 Provide UpDaemon with C setters rather than relying on GObject properties 2010-04-19 17:05:59 +01:00
Richard Hughes
d1bd4d42fd Get the suspend and hibernate commands from the backend, rather than hardcoding Linux specifics 2010-03-29 16:42:35 +01:00
Richard Hughes
4b5dc883e6 Get the swap size from the backend, rather than hardcoding Linux specifics 2010-03-29 14:21:51 +01:00
Richard Hughes
0198498350 Get the encrypted swap status from the backend, rather than hardcoding Linux specifics 2010-03-29 14:18:42 +01:00
Richard Hughes
4620a9d122 Get the kernel sleep capabilities from the backend, rather than hardcoding Linux specifics 2010-03-29 14:16:11 +01:00
Richard Hughes
daa2d5f3b7 Do not warn what we are correcting energy-full when there is no data to copy 2010-03-26 11:29:38 +00:00
Michael Biebl
9f26b3f866 Remove libdevkit-power-gobject dependency from backends
The backends [linux/freebsd/dummy] no longer require
libdevkit-power-gobject, so
- remove -I$(top_srcdir)/devkit-power-gobject from the include path
- don't link the backends against libdevkit-power-gobject but upowerd
  (which unfortunately still needs it).

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
2010-03-26 11:15:26 +01:00
Michael Biebl
8e3791afe4 devkit-power-gobject/up-enum.h be gone
Port from devkit-power-gobject/up-enum.h to libupower-glib/up-types.h
2010-02-06 13:46:03 +00:00
Michael Biebl
83c0574466 Remove EGG_* log define.
The EGG_* log defines don't seem to be used and still reference the old
DeviceKit-power name. So just remove it.
2010-02-05 08:35:11 +00:00
Richard Hughes
acfe9c3089 Update the Free Software Foundation address 2010-01-27 16:27:15 +00:00