Commit graph

126 commits

Author SHA1 Message Date
Martin Pitt
7105ed8a04 integration-test: Move to using umockdev
Setting $SYSFS_PATH does not work any more with recent libudev versions, our
homwbrew sysfs sandbox building limits us to coldplug tests only. umockdev
works with both old and new libudevs and can also emulate uevents for future
hotplugging tests.

Skip the test if umockdev is not available, so that check and distcheck don't
bail out.
2013-02-20 14:38:25 +01:00
Richard Hughes
8bbf566dc8 Also deprecate running the powersave scripts
Over the years we've moved all the quirks to the kernel (and fixed most of the
issues properly) so on Fedora we've not actually been shipping any rules in
pm-utils for a couple of releaes now.

Dropping this functionality allows us to finally drop the pm-utils dep for upower.
2013-02-12 11:18:31 +00:00
Richard Hughes
372c2f8d29 Add a --enable-deprecated configure argument
This is turned off by default. If this is not set, then any calls to Suspend(),
SuspendAllowed(), Hibernate() or HibernateAllowed() will fail with an error.
The error mesage tells the user what new method to port to in logind.

I'm expecting to set --enable-deprecated for Fedora 17 and 18, but turn it off
for Fedora 19, so other distributions probably want to follow suit to find out
what other stuff needs to be ported to the new APIs early. GNOME should already
be fine, but KDE will need some solid porting as I understand it.

See http://lists.freedesktop.org/archives/devkit-devel/2013-January/001339.html
for more information on future plans and for rationale.
2013-02-12 11:08:35 +00:00
Martin Pitt
275644a1b8 linux: Bump maximum accepted "time to empty" to 10 days
In the days of low-power ARM devices and large laptop batteries, imposing a 20
hour plausibility limit on "time to full" is not appropriate any more. Bump it
to 240 hours to still keep a plausibility check against "factor 1000" errors.

https://bugs.freedesktop.org/show_bug.cgi?id=60110
2013-01-31 12:24:14 +01:00
Martin Pitt
66f8f80023 Add test case for previous commit
Add test case for a battery which reports the current energy, but only the full
charge (no energy_full). This reproduces
https://bugs.freedesktop.org/show_bug.cgi?id=60104
2013-01-31 10:24:35 +01:00
Alex Hornung
cff4f578e5 linux: Fix batteries which report current energy but full charge
The condition should be for energy_full, not energy, since we aim to find some
way of finding energy_full and energy_full_design irrespective of the way we
find energy.

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

Signed-off-by: Alex Hornung <alex@alexhornung.com>
2013-01-31 10:24:13 +01:00
Colin Watson
b59d9848d4 Fix two memory leaks
up_device_supply_get_design_voltage(): up_device_supply_get_string() returns a
newly allocated copy.

up_history_finalize(): Forgot to free history->priv->dir

https://bugs.freedesktop.org/show_bug.cgi?id=60019
2013-01-29 15:08:18 +01:00
Richard Hughes
5be743c910 Don't use the deprecated INCLUDES in Makefile.am 2013-01-14 09:21:30 +00:00
Richard Hughes
b1f12feb1f Factor out the Logitech Unifying support to support other devices 2013-01-10 12:08:46 +00:00
Julien Danjou
35b0d25b49 lg-unifying: fix K750 features name, use 1 second interval
I've recently got access to some spec on this, so I'm now able to document
his a bit better. Also, change the 0x78 value for the function sending
BattLightMeasureBroadcastEvent to 0x1 since this is the number of event we
want, and one is enough.

Signed-off-by: Julien Danjou <julien@danjou.info>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2013-01-03 09:45:59 +00:00
Peter Hurley
9f31068707 Fix device matching for recent kernels
In recent kernels, hiddev* devices now have class "usbmisc", rather
than "usb" (see http://www.spinics.net/lists/linux-usb/msg62276.html).
This change translates into a change in SUBSYSTEM matching for hiddev*
devices. This fix addresses this for recent kernels while retaining
existing behavior. For reference, here is an attribute-walk for a
CyberPower CPS 1500C on kernel 3.7.0:

[Ubuntu bug #1091702: udev rules fail to match hid devices with new kernels]

udevadm info --attribute-walk --path=/devices/pci0000:00/0000:00:1d.2/usb4/4-1/4-1:1.0/usbmisc/hiddev0

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1/4-1:1.0/usbmisc/hiddev0':
    KERNEL=="hiddev0"
    SUBSYSTEM=="usbmisc"
    DRIVER==""

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1/4-1:1.0':
    KERNELS=="4-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usbhid"
    ATTRS{bInterfaceClass}=="03"
    ATTRS{bInterfaceSubClass}=="00"
    ATTRS{bInterfaceProtocol}=="00"
    ATTRS{bNumEndpoints}=="01"
    ATTRS{supports_autosuspend}=="1"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bInterfaceNumber}=="00"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4/4-1':
    KERNELS=="4-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="1"
    ATTRS{idVendor}=="0764"
    ATTRS{speed}=="1.5"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="8"
    ATTRS{busnum}=="4"
    ATTRS{devnum}=="2"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}==" 50mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="c0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="0"
    ATTRS{bcdDevice}=="0001"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="36"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="CPS"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0501"
    ATTRS{bDeviceClass}=="00"
    ATTRS{product}==" CP 1500C"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2/usb4':
    KERNELS=="usb4"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{devpath}=="0"
    ATTRS{idVendor}=="1d6b"
    ATTRS{speed}=="12"
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{authorized_default}=="1"
    ATTRS{busnum}=="4"
    ATTRS{devnum}=="1"
    ATTRS{configuration}==""
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{authorized}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{maxchild}=="2"
    ATTRS{bcdDevice}=="0307"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{serial}=="0000:00:1d.2"
    ATTRS{version}==" 1.10"
    ATTRS{urbnum}=="50"
    ATTRS{ltm_capable}=="no"
    ATTRS{manufacturer}=="Linux 3.7.0-030700-generic uhci_hcd"
    ATTRS{removable}=="unknown"
    ATTRS{idProduct}=="0001"
    ATTRS{bDeviceClass}=="09"
    ATTRS{product}=="UHCI Host Controller"

  looking at parent device '/devices/pci0000:00/0000:00:1d.2':
    KERNELS=="0000:00:1d.2"
    SUBSYSTEMS=="pci"
    DRIVERS=="uhci_hcd"
    ATTRS{irq}=="18"
    ATTRS{subsystem_vendor}=="0x1028"
    ATTRS{broken_parity_status}=="0"
    ATTRS{class}=="0x0c0300"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,000000ff"
    ATTRS{device}=="0x268a"
    ATTRS{msi_bus}==""
    ATTRS{local_cpulist}=="0-7"
    ATTRS{vendor}=="0x8086"
    ATTRS{subsystem_device}=="0x021e"
    ATTRS{numa_node}=="-1"
    ATTRS{d3cold_allowed}=="0"

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

Signed-off-by: Peter Hurley <peter@hurleysoftware.com>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-12-29 13:13:56 +00:00
Julien Danjou
9518459350 Add support for Logitech Unifying devices
This had support for Logitech devices working with an USB Unifying receiver.
This has been tested for at least the Logitech K750 solar keyboard, the M705
and the M505 mouses. Multiple receivers are also supported.

Signed-off-by: Julien Danjou <julien@danjou.info>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-10-30 20:05:30 +00:00
Jan Alexander Steffens (heftig)
ac4042ffaf Send resume signal when built with systemd and using pm-utils suspend
This case was apparently overlooked when adding systemd support.

Signed-off-by: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-09-03 08:33:37 +01:00
Matthias Clasen
44189f8129 Use systemd for suspend and hibernate
When running under systemd, call into systemd for suspend and
hibernate instead of pm-utils. To capture resume events, install
a small script that gets executed by systemd after resume and
sends a dbus signal back to upower.

To make this work, the upower backends gain a new signal, ::resuming,
that they can optionally emit to signal that a resume happened.
Backends opt in to this by returning TRUE from up_backend_emits_resuming().
In this case, upower doesn't assume the sleep command to block until
resume, but instead waits for the ::resuming signal from the backend.

The only backend that uses this mechanism is the linux backend when
built with systemd support.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-07-11 18:11:39 +01:00
Daniel Nicoletti
098a5e129a linux: Remove obsolete check for magicmouse_ and duplicated wacom_ checks
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-06-18 15:10:54 +01:00
Daniel Nicoletti
23f6127327 linux: Don't allow non-power-supply devices to set the OnBattery property
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-06-18 13:10:08 +01:00
Martin Pitt
48edf2f1a8 Fix wrong PowerSupply property for devices without a scope sysfs attribute
Fix NULL pointer comparison in up_device_supply_coldplug(). This caused

  (lt-upowerd:5754): GLib-CRITICAL **: g_ascii_strcasecmp: assertion `s1 != NULL' failed

when a device does not have a "scope" sysfs attribute, and erroneously
considering that device to not power the system.

https://launchpad.net/bugs/1012578
2012-06-14 13:18:10 +02:00
Martin Pitt
55569ac40f integration-test: fail on CRITICALs
Crash the daemon on any CRITICAL message, and also set WARNING and CRITICAL
messages to be fatal on the client side. On the server side we might have some
legitimate warnings, such as failing to load the config file from
/usr/local/etc (if you build a tree without passing correct --sysconfdir
options, etc.).

This exposes the current CRITICAL the daemon raises at startup. As with that
the daemon never starts up, fix the "wait for the daemon" loop to time out
after 10 seconds.
2012-06-14 13:07:30 +02:00
Richard Hughes
a75501f9d1 linux: Treat the battery state 'not charging' as PENDING_CHARGE
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=826215
2012-05-30 16:17:01 +01:00
Gary Ching-Pang Lin
c17a3f0d70 Correct the cap on the energy rate
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-04-27 16:05:39 +01:00
Richard Hughes
28c8653ed8 Never detect HID devices with batteries as power supplies
Some HID devices with batteries (like bluetooth keyboards) have been creating
power supply devices in sysfs since Linux 3.3.
UPower thinks that they are system devices and shuts down the system if they
get low. This is bad.

This is fixed in Linux 3.4, where there is a new 'scope' file that defines if
the device is powering the system.
Helpfully ACPI batteries don't populate the scope value, but soon will.

Add support for the scope attribute now, and default to system devices if it's
missing. Note, you need to be running a 3.4 kernel or a 3.3 with the patch
backported for this to work.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=806295
2012-04-18 16:46:46 +01:00
Evan Broder
6fb36eb5eb Re-coldplug dock status when resuming from sleep
It's possible for the docked state of a laptop (i.e. the display
connectivity state) to change while the laptop is asleep.

Signed-off-by: Evan Broder <evan@ebroder.net>
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-04-11 17:54:11 +01:00
Martin Pitt
1bb2b11b24 Fix crash in up_device_csr_finalize()
Commit 46f1c7f028 has a typo which prevents the fix from actually working.

https://launchpad.net/bugs/972300
2012-04-03 12:28:27 +02:00
Richard Hughes
2c02598806 Clamp the UPS percentage from 0 to 100 to fix syslog spam
This device bug seems to happen with CPS UPS units.
2012-02-17 10:30:47 +00:00
Kelly Anderson
5b2211cb23 Do not print error message for missing /etc/crypttab.
Signed-off-by: Richard Hughes <richard@hughsie.com>
2012-01-18 10:29:48 +00:00
Martin Pitt
6bb3623d46 src/linux/integration-test: Fail gracefully if GI is not available 2011-12-05 10:44:35 +01:00
Martin Pitt
492a8c2283 Revert "src/linux/integration-test: Do not crash on absent _outcomeForDoCleanups"
This reverts commit 14761c09d2.

The real reason for the failure is that Makefile.am calls the script with
"python" which is Python 2, but we need Python 3.
2011-12-05 10:30:14 +01:00
Martin Pitt
14761c09d2 src/linux/integration-test: Do not crash on absent _outcomeForDoCleanups
unittest.TestCase unfortunately does not have any public API to check whether
a test case succeeded, so we use the private self._outcomeForDoCleanups. This
does not seem to exist every time, so avoid a crash if it doesn't.
2011-12-05 10:24:37 +01:00
Heiko Stübner
88c6d141ef upower: Handle Linux power supplies not exporting a present property
According to Anton Vorontsov (Linux power supply maintainer) power
supplies should not export a present property when they are not
hotpluggable and users of the properties should handle supplies
without present-property as always present.

This patch implements this feature using an additional
sysfs_file_exists call before sysfs_get_bool.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2011-12-03 13:10:08 +00:00
Richard Hughes
6b685799cc trivial: USB devices are assumed to be 5V 2011-11-29 15:59:36 +00:00
Richard Hughes
21da4824a7 trivial: fix the name of the percentage file 2011-11-29 15:47:26 +00:00
Richard Hughes
c7cf8aa16a Don't assert when the power_supply device type is usb 2011-11-29 15:42:24 +00:00
Richard Hughes
3901d902fd Move the wacom hack to allow us to support other types of USB device 2011-11-29 14:05:18 +00:00
Richard Hughes
d4ea1cb566 If a power-supply device doesn't report charge or energy, try to read the percentage 2011-11-29 14:04:22 +00:00
Martin Pitt
46f1c7f028 Fix crash in up_device_csr_finalize()
Spotted when running regression tests in KVM. There, initializing a HID device
causes a "could not initialize libusb: -99" warning, but the device is created
nevertheless. Do not crash in _finalize() by trying to call libusb_exit(NULL).
2011-11-11 15:50:15 +01:00
Martin Pitt
d92aec6520 src/linux/integration-test: Port to Python 3 2011-11-11 15:19:04 +01:00
Leonardo Robol
b971b43c45 Use linear regression to get better predicted battery times
For hardware that has no rate data we use the differences in charge over a time
period to work out the effective rate. Using linear regression this estimation
is much more realistic.

To do this, introduce a simple circular buffer and use an index to calculate
the rate on each update.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2011-10-19 17:13:51 +01:00
Richard Hughes
58f77e8aa6 Don't spam the log when we're saving history when on low power
Resolves: https://bugs.freedesktop.org/show_bug.cgi?id=41486
2011-10-06 09:12:04 +01:00
Richard Hughes
fe643d6fc0 trivial: remove an overzealous warning when starting up 2011-09-28 16:12:40 +01:00
Christian Seiler
ff23a9c6e2 Fix linux up_backend_supports_sleep_state() return code.
Under Linux, regardless of the exit code of /usr/bin/pm-is-supported, it will
always set CanSuspend and CanHibernate to true due to a logic error in
up_backend_supports_sleep_state in src/linux/up-backend.c: The 'ret' variable
is re-used for the return code without being re-initialized to false after the
call to g_spawn_command_line_sync.

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
2011-09-22 17:34:45 +02:00
Martin Pitt
75d8c449cd src/linux/integration-test: Fully port to GI
Move from static glib to GI GLib module, to avoid mixing static and dynamic
bindings.

This fixes the tests to work with pygobject 3.
2011-09-05 14:38:31 +02:00
Richard Hughes
cb37dcc2e8 Hardcode wacom battery devices as not power-supply devices
We'll switch to a kernel property when the power_supply interface is fixed.
2011-07-19 16:14:20 +01:00
Richard Hughes
b19fca9637 Use git.mk and remove the manual .gitignore files 2011-07-19 12:40:21 +01:00
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