Commit graph

492 commits

Author SHA1 Message Date
Bastien Nocera
27541a6130 linux: Remove unused code in test suite
There's no need to create a udev device, the metadata comes from bluez.
2019-10-23 13:32:08 +02:00
Bastien Nocera
ed0dfe4427 linux: Fix warning when bluez Appearance property isn't set
The Appearance property might not be available, and would cause
warnings like:
upowerd[17733]: g_variant_get_type: assertion 'value != NULL' failed
upowerd[17733]: g_variant_type_is_subtype_of: assertion 'g_variant_type_check (type)' failed
upowerd[17733]: g_variant_get_uint16: assertion 'g_variant_is_of_type (value, G_VARIANT_TYPE_UINT16)' failed
2019-10-17 16:43:15 +02:00
Bastien Nocera
8e6cb06ff6 linux: Fix memory leak in Bluez backend
g_dbus_proxy_get_cached_property() returns transfer full GVariants.
2019-10-17 16:42:22 +02:00
Bastien Nocera
fccc47114a linux: Use symbolic names for device types in test suite 2019-05-09 11:17:02 +02:00
Bastien Nocera
f16a8feea0 linux: Add gaming input type to the test suite
The enum member was missing.
2019-05-09 11:17:02 +02:00
Bastien Nocera
8ead05234c linux: Add test for Logitech unknown device races
Check that external devices which show up as "battery" types have their
capacity_level correctly read, and that the device's type will be
correctly read after an input node is attached.
2019-05-07 11:44:22 +00:00
Bastien Nocera
71efbf00ca linux: Start polling for unknown device batteries too
This check is supposed to start a poll for 1) batteries embedded in
external devices 2) batteries when battery polling is not disabled.

Make sure to start the poll for all batteries embedded in devices even
the ones that are just detected as "battery".
2019-05-07 11:44:22 +00:00
Bastien Nocera
61028d84d8 linux: Retry to get a battery type if it's unknown
On some devices the power_supply node will show up before a related node
such as "input", making it impossible to know which type of device we're
attached to without waiting. Try to detect the device type again if the
device type is still "battery".

This fixes some Logitech devices appearing as "Battery" instead of their
respective device type, such as "mouse".
2019-05-07 11:44:22 +00:00
Bastien Nocera
057238a04d linux: Don't treat device batteries like laptop batteries
Use the correct refresh function for device batteries which aren't of a
known type. This fixes battery information not getting updated on many
Logitech wireless devices.

Reproducer:
- Unplug Logitech receiver
- Replug Logitech receiver
- Press button on Logitech keyboard
- Move mouse/touchpad

The touchpad battery would be stuck in "unknown" and with a "type" of
battery. This commit forces the correct refresh function to be used, one
that reads the capacity_level on those devices, and will update the
overall battery level.

Closes: #72
2019-05-07 11:44:22 +00:00
Christian Kellner
9b7ce3dea3 Replace use of G_TYPE_INSTANCE_GET_PRIVATE
G_TYPE_INSTANCE_GET_PRIVATE has been deprecated since glib version
2.58 and should be replaced with the xxx_get_instance_private (obj)
which is generated by G_ADD_PRIVATE.
2019-02-21 12:09:06 +01:00
Christian Kellner
8da188b303 Replace use of deprecated g_type_class_add_private
Use G_DEFINE_TYPE_WITH_CODE (..., G_PRIVATE_ADD (...)) instead of
the (deprecated since glib 2.58) function g_type_class_add_private
to add a private structure for a type.
Bump the minimal required version of glib to 2.38.0, the version
where G_PRIVATE_ADD was added.
2019-02-21 12:07:59 +01:00
João Paulo Rechi Vita
c4e561f54d integration-test: Test mapping pending-charge to fully-charged 2018-12-18 17:19:01 -08:00
João Paulo Rechi Vita
a953401420 linux: Map pending-charge to fully-charged when charge is 100%
Some devices report "Not charging" when the battery is full and AC power
is connected. In this situation we should report fully-charged instead
of pending-charge.

Closes: #86.
2018-12-18 17:17:32 -08:00
João Paulo Rechi Vita
888c9121f0 linux: Don't set out_state before state is final
Currently up_device_supply_refresh_battery sets out_state before the
state value is definitive, so the wrong state value is returned to the
caller. Luckily the only caller does not make use of this value at the
moment, so there are no user-visible consequences. Nonetheless this is a
bug, so this commit fixes it.
2018-12-18 17:16:49 -08:00
João Paulo Rechi Vita
f3f4c6e0b4 integration-test: Test DisplayDevice pending-charge
Test relaying the pending-charge state to the DisplayDevice. This commit
adds three tests: only one battery pending-charge, one battery
pending-charge and another one discharging, and one battery
pending-charge and another one charging.
2018-11-14 12:57:15 -08:00
João Paulo Rechi Vita
eb02827015 integration-test: Define PENDING_CHARGE and PENDING_DISCHARGE states
Add definitions for UP_DEVICE_STATE_PENDING_CHARGE and
UP_DEVICE_STATE_PENDING_DISCHARGE.
2018-11-14 12:57:15 -08:00
Laurent Bigonville
2f4df9174e src/linux/up-device-hid.c: usage_code is defined as an unsigned integer
Also define "value" as a signed 32 bits integer
2018-10-25 11:52:06 +02:00
Bastien Nocera
1c9892d763 linux: Add test for MacBook uevent behaviour
See https://gitlab.freedesktop.org/upower/upower/issues/56
2018-06-19 13:01:52 +00:00
Bastien Nocera
7188cc0417 linux: Refresh for 5 seconds after plug/unplug on MacBooks
Pull the 2 previous changes together to refresh the battery status for a
couple of seconds after receiving an event on the power line. This fixes
charge status being inaccurate for up to 120 seconds (the normal poll
timeout on MacBooks).

https://gitlab.freedesktop.org/upower/upower/issues/56
2018-06-19 13:01:52 +00:00
Bastien Nocera
6ab61bac9d linux: Detect hardware that needs more polling after event
When an event happens on the power line, and we are using a particular
device (in this case a MacBook or MacBookAir), we might need to poll
more aggressively after the event.

This adds a function to detect and export this.
2018-06-19 13:01:52 +00:00
Bastien Nocera
79017e432d linux: Make sure unknown poll lasts 5 seconds
Rather than 5 calls to up_device_supply_setup_unknown_poll(), which
can happen pretty quickly together after receiving a uevent.
2018-06-19 13:01:52 +00:00
Bastien Nocera
054cb3f4b8 linux: Fix possible double-close on exit
Fix double-close on exit. If we created a GIOChannel from the file
descriptor, then g_io_channel_shutdown() will close that file descriptor
as well. Close the channel first, so that the file descriptor is only
closed manually if we didn't manage to create a GIOChannel from it.

https://gitlab.freedesktop.org/upower/upower/issues/60
2018-06-19 12:48:39 +00:00
Bastien Nocera
c937dabd1e linux: Clean up after running test suite in "distcheck"
Don't leave the history files installed when running "make uninstall".
Those files will likely have been created by the test suite when running
"make distcheck"
2018-06-18 18:21:55 +02:00
Bastien Nocera
21dcc00cdb linux: Remove extra linefeed 2018-06-18 17:45:40 +02:00
Bastien Nocera
c4ca520f24 linux: Better error reporting from sysfs_get_double_with_error()
sysfs_get_double_with_error() used to return -1.0 for errors, but in
some cases, we might want -1.0 to be a valid value, such as for negative
discharge rates. Return FALSE on error instead.
2018-06-18 17:45:40 +02:00
Bastien Nocera
096121740f linux: Add a test for Logitech HID++ charging states
The current power_supply support in the kernel will advertise an unknown
capacity when a device is being charged. This tests this state as well
as the expected behaviour when the device is fully charged.

https://bugs.freedesktop.org/show_bug.cgi?id=97484
2018-04-19 03:40:40 +02:00
Bastien Nocera
33e9039eb0 linux: Add support for "Unknown" capacity level
Rather than leaving the percentage untouched, set the battery level at
50.0 as a "middle-ground".

This percentage is supposed to be ignored if a BatteryLevel is set so
this is better than showing "0%" which makes it look like a bug.

https://bugs.freedesktop.org/show_bug.cgi?id=97484
2018-04-19 03:11:29 +02:00
Bastien Nocera
0840bb266e linux: Add a README with a couple of debugging commands 2018-04-18 16:34:42 +02:00
Dmitry Torokhov
40e525edbd linux: lower severity of "unhandled action" messages
Newer kernels emit bind/unbind uevents that are not of interest to
powerd. To avoid littering logs with scary messages, let's lower their
severity to "debug".

https://bugs.freedesktop.org/show_bug.cgi?id=106018
2018-04-12 22:34:30 +02:00
Bastien Nocera
17dba403e7 linux: Fix memory leak if logind returns an error 2018-04-12 22:34:04 +02:00
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