Commit graph

312 commits

Author SHA1 Message Date
Bastien Nocera
c68daf665f linux: Fix crash if logind doesn't return an error
For example, when using an incomplete mock logind.
2018-04-12 22:32:13 +02:00
Martin Szulecki
598fdbc5e0 linux: Check "HasBattery" key for newer iOS versions
This adds an extra check to query if the iOS device has a
battery at all before actually trying to retrieve the battery
status. Should still work for older iOS versions which do not
provide this key.

https://bugzilla.freedesktop.org/show_bug.cgi?id=105625
2018-03-20 15:28:36 +01:00
Martin Szulecki
9357aa60e7 linux: Prevent crash after attaching an Apple TV
As Apple TVs do not have a battery and do not provide the
"BatteryIsCharging" lockdown key, upower would crash due to a
missing check whether the retrieved node is actually valid.

https://bugzilla.freedesktop.org/show_bug.cgi?id=105625
2018-03-20 15:28:36 +01:00
Bastien Nocera
7771a57b81 linux: Add test for Bluetooth LE battery support
https://bugs.freedesktop.org/show_bug.cgi?id=92370
2017-11-02 15:37:39 +01:00
Bastien Nocera
ccb1b0ed96 linux: Add support for Bluetooth LE device batteries
As exported through BlueZ's org.bluez.Battery1 D-Bus interface. This
interface is only used for device where the battery information cannot
be processed in the kernel.

This is the first UpDevice type that doesn't use UdevDevice for the
Linux backend, and it is also the first that does not poll() status at
all.

https://bugs.freedesktop.org/show_bug.cgi?id=92370
2017-11-02 15:37:39 +01:00
Bastien Nocera
b3f39a5ca3 linux: Use g_clear_object() when possible
Rather than using != NULL, followed by unref().

https://bugs.freedesktop.org/show_bug.cgi?id=103380
2017-10-31 17:42:55 +01:00
Bastien Nocera
91c7f7c0f8 linux: Remove empty API docs
Those "API documentation" don't document the function below it, they
just name it, so aren't needed.

https://bugs.freedesktop.org/show_bug.cgi?id=103380
2017-10-31 17:42:55 +01:00
Bastien Nocera
2dd321fab7 linux: Fix compilation with libimobiledevice git
Since libimobiledevice 5a8449a, LOCKDOWN_E_NOT_ENOUGH_DATA was renamed
to LOCKDOWN_E_RECEIVE_TIMEOUT. We'll use "-7" to avoid having to use
build glue.
2017-09-21 17:17:22 +02:00
Miroslav Sustek
212599f0ee daemon: Fix critical action after resume from hibernate
The take_action_timeout_cb() function returns G_SOURCE_REMOVE which
makes GLib destroy the timeout. However the action_timeout_id
stayed != 0 so when warning level turned to "action" again the daemon
assumed that the timeout is already set and did nothing.
(It only logged: "Not taking action, timeout id already set")

https://bugs.freedesktop.org/show_bug.cgi?id=87791
2017-09-21 17:10:19 +02:00
Bastien Nocera
fb9f19c3b5 linux: Add test for crash when battery has funky name
https://bugs.freedesktop.org/show_bug.cgi?id=93095
2017-09-08 17:59:42 +02:00
Bastien Nocera
8898d2b9ac linux: Add better debug to sysfs_get_capacity_level()
Remove the trailing linefeed from the sysfs attribute to be able to
print it, and simplify the loop by the same token.
2017-09-08 17:10:40 +02:00
Bastien Nocera
359008b7b7 linux: Don't throw an error if there's no data to read
The initial "refresh" for devices would fail if there was no data to
read. Instead, we should set the level to unknown, so that the device
appears in the Power panel, and in the "upower -d" output.
2017-09-08 16:53:08 +02:00
Bastien Nocera
2ef05c4220 linux: Grab model name from device if unavailable from battery
The "model_name" and "serial_number" information that upower exports for
batteries that supply a laptop or UPS are supposed to be that of the
battery. But that's very unlikely to happen for devices, such as
wireless mice, keyboards or joysticks.

Look for a sibling input device if a device battery does not contain
model information so as to avoid generic names in UIs.

https://bugs.freedesktop.org/show_bug.cgi?id=102493
2017-09-04 14:05:15 +02:00
Bastien Nocera
623a6bfc57 linux: Move function to prepare for new use
Move up_device_supply_get_sibling_with_subsystem() so we can use
it in up_device_supply_refresh_device()

https://bugs.freedesktop.org/show_bug.cgi?id=102493
2017-08-31 16:21:25 +02:00
Bastien Nocera
320cc87811 linux: Detect joysticks as gaming input devices
https://bugs.freedesktop.org/show_bug.cgi?id=102493
2017-08-31 16:21:21 +02:00
Bastien Nocera
1dc2b96eec linux: Add test for wireless joypad connected via USB
Mostly for the type of device rather than the connections.

https://bugs.freedesktop.org/show_bug.cgi?id=102493
2017-08-31 16:21:14 +02:00
Benjamin Berg
502c63b549 linux: Correctly close inhibitor FD
The unref of the FD list for the inhibitor was missing which means that
the FD was leaked and the lock was never released. This means that for
each suspend/resume cycle a new inhibitor would be added.

Signed-off-by: Richard Hughes <richard@hughsie.com>
2017-08-03 16:21:12 +01:00
Bastien Nocera
660c8f3268 daemon: Move a number of constants to a shared file
https://bugs.freedesktop.org/show_bug.cgi?id=100359
2017-04-06 16:33:38 +02:00
Bastien Nocera
499d05b837 all: Add BatteryLevel property
Export approximate battery levels that devices can use, exported by
the kernel as POWER_SUPPLY_CAPACITY_LEVEL_* values.

This avoids bizarrely accurate values showing up in UIs when we only
have ok/warning levels of accuracy in some cases.

https://bugs.freedesktop.org/show_bug.cgi?id=100359
2017-04-06 16:33:38 +02:00
Bastien Nocera
4f9230900b lib: Add more members to UpDeviceLevel struct
Those levels will not be used to cover warning levels, but approximate
battery levels that devices can use, exported by the kernel as
POWER_SUPPLY_CAPACITY_LEVEL_* values.

See linux/power_supply.h

https://bugs.freedesktop.org/show_bug.cgi?id=100359
2017-04-06 14:18:10 +02:00
Bastien Nocera
6b14798281 linux: Add support for "capacity_level" attribute
Some devices, such as a number of wireless Logitech unifying devices
don't have a precise battery level reporting, and use the Linux
POWER_SUPPLY_CAPACITY_LEVEL_* values.

This minimal fix matches the levels against approximate percentage
values. This is good enough to make the Logitech T650 report battery
again when using the kernel HID++ battery support.

https://bugs.freedesktop.org/show_bug.cgi?id=100359
2017-04-06 14:18:10 +02:00
Christian Kellner
c237298297 integration-test: Fix path for unparented device
Paths supplied to testbed.add_device() are relative to /sys/devices
already and therefore must not start with /sys/devices.

This does not change the result of the test.

https://bugs.freedesktop.org/show_bug.cgi?id=100539
2017-04-06 14:16:15 +02:00
Christian Kellner
90aec997ce integration-test: enable running from JHBuild
https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-25 18:08:50 +01:00
Christian Kellner
b292ee2035 integration-test: Check NoPollbatteries is followed
The NoPollbatteries option should disable battery polling. Create
a config file with 'NoPollBatteries=true' and ensure we don't get
polling setup for the virtual battery.

https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-25 18:08:35 +01:00
Christian Kellner
a4d7d84b34 integration-test: Add test for refresh after sleep
This also tests suspending and resuming polling as a
by-product.

https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-25 18:07:57 +01:00
Christian Kellner
09cdb0ccfc linux: Use inhibitor lock to guard poll pausing
Use an inhibitor lock obtained via logind to make sure the polling
is paused before the system is put to sleep, rather than racing with
the suspension.

https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-25 18:07:02 +01:00
Christian Kellner
01cd65c1a7 linux: Refresh devices after waking up from sleep
The battery levels might have changed drastically compared to
before sleep. Since we poll batteries at set intervals, it can
take quite some time for the new level to be picked up by the
polling code.

Listen to the "PrepareForSleep" signal emitted by logind, that
gets emitted on suspend and wake up. Pause polling globally on
suspend, and refresh all devices manually and resume polling when
waking up.

https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-25 18:04:59 +01:00
Bastien Nocera
c885c4c886 integration-test: Add test for unparented input devices
The test would fail without the fix from commit 86e5237, and succeed
with it.
2017-03-24 17:16:32 +01:00
Bastien Nocera
86e5237807 linux: Fix critical when searching for sibling devices
GUdev-CRITICAL **: g_udev_device_get_sysfs_path: assertion 'G_UDEV_IS_DEVICE (device)' failed

This is caused by looking for devices in a particular subsystem which
don't have parents. This can happen with virtual devices, such as the
ones created by test suites.
2017-03-24 17:14:06 +01:00
Bastien Nocera
a2eecff867 integration-test: Use symbolic names for device types
Instead of using comments to explain the magic values.
2017-03-24 17:03:36 +01:00
Christian Kellner
d69121971f integration-test: add get_critical_action() test
https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-24 15:46:40 +01:00
Christian Kellner
305a24a115 integration-test: use dbusmock to mock logind
Derive from dbusmock.DBusTestCase and add {start,stop}_logind
to enable tests that need logind.

https://bugs.freedesktop.org/show_bug.cgi?id=99763
2017-03-24 15:46:40 +01:00
Bastien Nocera
4292226e5c linux: Fix compilation warning
duplicate ‘const’ declaration specifier

We can't use a const char const because we actually want to assign
values to elements of the array.
2017-03-24 15:46:40 +01:00
Bastien Nocera
4be1efe819 integration-test: HID++ mouse is a mouse 2017-03-24 15:19:12 +01:00
Bastien Nocera
12d34b8a8b Revert "linux: Disable crashing test"
This reverts commit 8aff086b48.

The crash is fixed in umockdev 0.8.13
2017-01-26 11:35:34 +01:00
Bastien Nocera
1de37eb958 linux: Get a serial number for device batteries
And not just for batteries that power the machine itself.
2017-01-24 18:08:52 +01:00
Bastien Nocera
d5c05515a8 linux: Add a serial number to mouse battery test
Which will fail, as the device code doesn't even try to get a serial
number.
2017-01-24 18:08:24 +01:00
Bastien Nocera
efe589a8ce linux: Add a test for HID++ devices 2017-01-24 17:48:47 +01:00
Bastien Nocera
d47f3eb84b linux: Simplify getting the device type
1) Get the sibling device
2) Check its type

This fixes the test_bluetooth_hid_mouse_no_legacy_subdevice test.
2017-01-24 17:45:58 +01:00
Bastien Nocera
8aff086b48 linux: Disable crashing test
Filed as an issue against umockdev:
https://github.com/martinpitt/umockdev/issues/53
2017-01-24 17:45:58 +01:00
Bastien Nocera
f711bc3865 linux: Always stop daemon when started in tests 2017-01-24 17:45:58 +01:00
Bastien Nocera
c5d1660b5c linux: Allow running upowerd under valgrind in tests 2017-01-24 17:45:58 +01:00
Bastien Nocera
caf53bd982 linux: Parent the keyboard device correctly in tests 2017-01-24 17:45:58 +01:00
Bastien Nocera
89a3baad69 linux: Add test without the "mouse" legacy node
Which currently fails. Which is what will happen with an older UPower on
a newer kernel with that removed.
2017-01-24 17:45:58 +01:00
Bastien Nocera
e8e20ac64a linux: Parent Bluetooth mouse test devices properly 2017-01-24 17:45:58 +01:00
Bastien Nocera
e3b6e1426b linux: Simplify up_device_supply_guess_type()
By exiting early.
2017-01-24 17:45:58 +01:00
Bastien Nocera
140b18f8f4 linux: Remove unneeded goto 2017-01-24 17:45:58 +01:00
Bastien Nocera
5b217179be linux: Split off device type detection
The code is far too deep to be left in this function, let's split it
off to make it more readable.
2017-01-24 17:45:58 +01:00
Bastien Nocera
f0ec467d00 linux: Move declaration of variables closer to use
Will make it easier to move to a separate function.
2017-01-24 12:59:43 +01:00
Bastien Nocera
402640bee0 linux: Lower initial power usage when iDevice isn't accessible
When starting up, we would try to connect to the iDevice repeatedly,
once a second. But the process takes between a quarter and half a
second, and is CPU heavy. Lower this timeout to once every 5 seconds to
reduce the initial CPU consumption.
2016-06-08 14:50:23 +02:00