Commit graph

1270 commits

Author SHA1 Message Date
Bastien Nocera
e4e498e198 linux: Fix integration test to work under jhbuild
Fixes: 648abe9c27 ("tests: Test a client running while daemon restarts")
2023-07-06 10:07:08 +02:00
Bastien Nocera
f8fe036331 linux: Work-around potential race in test_headset_hotplug 2023-07-05 17:39:19 +02:00
Bastien Nocera
38576a9bd7 linux: Emit added/removed signals when duplicates change 2023-07-05 17:39:19 +02:00
Bastien Nocera
53ccc01be9 linux: Add test for device signals with wireless_status 2023-07-05 17:39:19 +02:00
Bastien Nocera
4d3d8759db linux: Add wait_for_mainloop() test helper 2023-07-05 17:39:19 +02:00
Bastien Nocera
faa5a560f9 linux: Emit added/removed signals when wireless_status changes
Closes: #240
2023-07-05 17:39:19 +02:00
Bastien Nocera
8dd86689fa device: Add up_device_is_registered()
So we can know whether a device was registered when hiding it and
eventually send the appropriate "device-removed" signal.
2023-07-05 17:39:19 +02:00
Bastien Nocera
0ed632daab device: Return success after up_device_register
Return whether up_device_register() registered a device, so we can
announce it through a device-added signal.
2023-07-05 15:33:20 +00:00
Michael Biebl
dec9468136 linux: Fix integration test to work with system installed upower binary
Fixes: 648abe9c27 ("tests: Test a client running while daemon restarts")
Closes: #241
2023-07-05 15:30:47 +00:00
Bastien Nocera
95de7181dd linux: Add test for is-present changes at runtime 2023-07-04 15:20:20 +02:00
Stuart Hayhurst
d74536fa0e linux: Update present property on refresh
Some devices change the 'present' sysfs attribute after upower
registers them. This should be updated in upower, otherwise
applications will ignore present devices, or listen to absent devices.

Fixes: 0b7d7cfc08 ("linux: Fix is-present for devices at startup")
2023-07-04 15:18:31 +02:00
Bastien Nocera
648abe9c27 tests: Test a client running while daemon restarts 2023-07-04 10:25:44 +02:00
Bastien Nocera
f82c55b416 linux: Lower debug severity 2023-07-03 17:15:24 +02:00
Bastien Nocera
80bc0d7c79 linux: Add test for "wireless_status" sysfs attribute 2023-07-03 17:15:07 +02:00
Bastien Nocera
5ddc7c8bc5 linux: Set the "disconnected" property on events
When a sibling device has its "wireless_status" attribute changing,
change the "disconnected" property appropriately.
2023-07-03 16:10:13 +02:00
Bastien Nocera
570d6cdf27 linux: Track "disconnected" property to hide devices
Hide "disconnected" devices.
2023-07-03 16:10:13 +02:00
Bastien Nocera
20c5e83f12 device: Add disconnected property
The property will be FALSE and stay FALSE for all devices, except for
the Linux ones that have a "wireless_status" attribute set to
"disconnected". This will then be used by the backend to hide the device
until the wireless device is turned on again.
2023-07-03 16:10:13 +02:00
Bastien Nocera
f7142fe567 daemon: Don't prepare a poll for a hidden device
We don't need to poll a device that's not registered to be visible on
the bus, so check the visibility before setting that poll.
2023-07-03 16:10:13 +02:00
Bastien Nocera
babe81a871 linux: Add headset hotplug test 2023-07-03 16:07:46 +02:00
Bastien Nocera
3487e804af linux: Add debug to audio sub-type detection 2023-07-03 16:07:46 +02:00
Bastien Nocera
5656939590 linux: Add debug to uevent handler 2023-07-03 16:07:46 +02:00
Bastien Nocera
801463a630 linux: Don't overwrite detected type with another less precise one
Fix a problem where if the input node of a headset appears after the
headset type has been detected, the type would get overwritten to be a
keyboard.
2023-07-03 16:07:46 +02:00
Bastien Nocera
ffe33934ae linux: Another fix for headsets type detection when hotplugged
Also handle the case where the sibling device changes after the main
battery device has been created.
2023-07-03 16:07:46 +02:00
Bastien Nocera
ac68136b41 linux: Fix headsets type detection when hotplugged
When a UpDevice is finally created, it's possible that we've seen "add"
events as well as "change" events for siblings. But as the "change"
events don't create new unknown siblings to store, we have GUdevDevices
from the original "add" event in that store.

As the GUdevDevice documentation mentions:
"By design, GUdevDevice will not react to changes for a device – it
only contains a snapshot of information when the GUdevDevice object
was created. To work with changes, you typically connect to the
“uevent” signal on a GUdevClient and get a new GUdevDevice
whenever an event happens."

To avoid having to try and update the siblings store, fetch an updated
GUdevDevice for the sibling we want to tell the core about, with the
properties all updated.

This fixes headsets plugged in after the daemon start being detected as
keyboards when the sound card device is tagged with the form factor
in a change event before the battery is exported.

Closes: https://gitlab.freedesktop.org/upower/upower/-/issues/239
2023-07-03 15:54:51 +02:00
Bastien Nocera
ab116cda4a linux: Remove unused variable
../src/linux/up-backend.c:158:19: warning: unused variable 'name' [-Wunused-variable]
        g_autofree char *name = NULL;
                         ^
2023-04-18 16:39:07 +02:00
Landry Breuil
99d2659efc battery: Fix some warnings
building natively on OpenBSD with clang 13, i get those warnings:

../src/up-device-battery.c:128:53: warning: absolute value function 'abs' given an argument of type 'gint64' (aka 'long long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                  ^
../src/up-device-battery.c:128:53: note: use function 'llabs' instead
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                  ^~~
                                                                  llabs

../src/up-device-battery.c:128:65: warning: absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                              ^
../src/up-device-battery.c:128:65: note: use function 'llabs' instead
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                              ^~~
                                                                              llabs
2023-04-18 16:38:59 +02:00
Bastien Nocera
5aabeb7067 linux: Guard against devices with no serial
Avoid warning if one of the devices doesn't have a serial:
GLib-CRITICAL **: g_ascii_strcasecmp: assertion 's2 != NULL' failed

 #1  0x00007fbe1b7c0b6d in g_log (log_domain=log_domain@entry=0x7fbe1b81300e "GLib", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7fbe1b81e9dd "%s: assertion '%s' failed") at ../../../../Projects/jhbuild/glib/glib/gmessages.c:1460
 #2  0x00007fbe1b7c1af9 in g_return_if_fail_warning (log_domain=log_domain@entry=0x7fbe1b81300e "GLib", pretty_function=pretty_function@entry=0x7fbe1b8238c0 <__func__.24> "g_ascii_strcasecmp", expression=expression@entry=0x7fbe1b815e0e "s2 != NULL") at ../../../../Projects/jhbuild/glib/glib/gmessages.c:2930
 #3  0x00007fbe1b7dad3a in g_ascii_strcasecmp (s1=<optimized out>, s2=<optimized out>) at ../../../../Projects/jhbuild/glib/glib/gstrfuncs.c:1878
 #4  0x0000000000411025 in find_duplicate_device (backend=backend@entry=0xc3dc00, device=device@entry=0xc782e0) at ../../../../Projects/jhbuild/upower/src/linux/up-backend.c:139
2023-04-18 12:31:19 +02:00
Bastien Nocera
b83b0ff568 linux: Add test for duplicate USB/Unifying devices 2023-04-18 12:31:12 +02:00
Bastien Nocera
8ebee50744 linux: Hide duplicate USB devices
Make our unduplicating code a bit more clever and hide the non-BlueZ
devices with the "unknown" battery state.

When Logitech devices are connected through Unifying and USB, with the
correct Linux patches[1], their serial numbers match, but the Unifying
connection stops exporting the battery information, so hide that one
from the export.

Closes: #206

[1]: https://patchwork.kernel.org/project/linux-input/list/?series=726116
2023-04-17 15:19:10 +02:00
Bastien Nocera
5806125d80 device: Don't warn if the device is already registered 2023-04-17 15:19:10 +02:00
Bastien Nocera
8c8c6315f9 device: Export up_device_register()
It will be useful when we want to show some devices that aren't
duplicated any more.
2023-04-17 15:19:10 +02:00
stuarthayhurst
8356dd01d6 tests: Add test for siblings overwiting good type guesses 2023-04-17 15:02:44 +02:00
stuarthayhurst
8052220fb3 linux: Don't overwrite guesses from previous siblings
If a power supply has multiple siblings, any guesses to device type
from previous siblings will be overwritten by a sibling with no guess,
as it defaults to keyboard, the highest priority. Instead, while
guessing, use UNKNOWN, and only default to keyboard at the end.

Could also be fixed by changing the keyboard's priority, but that
might have side effects for otherwise working devices.

Closes: #221
2023-04-17 15:01:29 +02:00
Bastien Nocera
5dbd51c47a linux: Add test about headset devices detection 2023-04-15 15:17:13 +02:00
Bastien Nocera
0ffb3d5e64 linux: Remove unused variable 2023-04-15 15:12:10 +02:00
Bastien Nocera
12e97ebba3 linux: Detect headset devices with kernel batteries
The code that handles battery information coming from the kernel didn't
have any code to set audio type of devices. As we add support for USB
wireless headsets in the kernel, add code to detect those and set the
UPDevice kind to the right value.

Closes: #229
2023-04-15 15:12:10 +02:00
Bastien Nocera
fa58832bd1 tests: Fix charging test in test_battery_state_guessing
Wait longer for the state guessing to actually kick in, 25 seconds was
too slow and we were getting the old state instead.
2023-04-15 14:10:23 +02:00
Bastien Nocera
40828daa8b tests: Remove assertion in test_battery_state_guessing
The history clearing doesn't work, see:
https://gitlab.freedesktop.org/upower/upower/-/issues/230
2023-04-15 13:17:59 +02:00
Bastien Nocera
b773285d5e battery: Fix power rate checks for amount < 1W
Fix the power rate check, energy_rate is a float, and abs() handles ints,
so any rate under 1W would have been truncated to 0.
2023-04-15 13:17:46 +02:00
Bastien Nocera
5db1bce65f tests: Fix discharge rates in test_battery_state_guessing
up_device_battery_estimate_power() expects a charge/discharge rate of
0.5W to be significant, but the existing code yielded a rate of
-0.000240W.

Fix the units so that the amount of change in energy_now is at least
1W/s converted to µWh.
2023-04-15 12:16:19 +02:00
Bastien Nocera
b3c439ab4a linux: Fix getting properties in assertDevs()
Now that device loop is fixed, we also need to fix the D-Bus object
path for the devices themselves to match what UPower generates so
we can get its properties.

As we iterate over the expected array, the elements are the basenames
of those object paths. Reconstruct the full object paths by prepending
/org/freedesktop/UPower/devices/
2023-04-14 13:50:49 +02:00
Bastien Nocera
32e2cd5eb9 linux: Fix broken assertDevs() device loop
The test uses a generator to get the list of basenames for the devices:
names = (n.split('/')[-1] for n in devs)

Unfortunately, using that "names" varible will consume the generator,
and our array will be lost.

When passing a device dictionary, this code:
print(sorted(names))
print(sorted(names))
will yield:
['battery_hidpp_battery_0']
[]

Save the sorted array, and use that to test for properties equality.
2023-04-14 13:50:19 +02:00
Bastien Nocera
810c1214a5 linux: Test fix for warning when a duplicate device appears
Make the Bluetooth device appear first.
2023-02-28 14:14:59 +01:00
Bastien Nocera
32b0e098a1 linux: Test adding Bluetooth devices after daemon start
As is usually the case in reality, as bluez must be started for
Bluetooth devices to be able to connect.
2023-02-28 14:14:59 +01:00
Bastien Nocera
b6143527ef linux: Fix dbusmock addition of fake battery
We need to send the InterfacesAdded signal in case upower is already
started, so it can properly keep track of the interesting bluez devices.
2023-02-28 13:42:36 +01:00
Bastien Nocera
46257ff36e linux: Fix warning when a duplicate device appears
When a kernel device appears after the Bluetooth device, we could be
trying to bind the model property onto itself on the Bluetooth device.
Avoid this possibility by always binding the property from the bluez
device to the non-bluez device.

GLib-GObject-WARNING **: 20:20:50.644: Unable to bind the same property on the same instance

Fixes: 778b93a336 ("linux: Hide duplicate Logitech Bluetooth devices")
2023-02-28 13:05:28 +01:00
Bastien Nocera
b7e406d9f9 linux: Add test for Logitech HID++/Bluetooth deduplication
This tests for the device-removed g_warning(), following the Alias
property on bluez devices, and the "Unhandled key" warnings.
2023-02-27 14:39:36 +01:00
Bastien Nocera
81c97eef9d main: Fix warning for hidden device
Some Bluetooth devices can be hidden if they also export their battery
info through the kernel, so make sure to not throw a warning when they
go away.

(upowerd:133931): UPower-WARNING **: 02:49:48.012: INTERNAL STATE CORRUPT (device-removed): not sending NULL, device:0x1f5dae0

Fixes: 778b93a336 ("linux: Hide duplicate Logitech Bluetooth devices")
2023-02-27 14:12:39 +01:00
Bastien Nocera
7df5f2907c linux: Demote warning to debug
Fixes warnings like:
(upowerd:133931): UPower-Linux-WARNING **: 02:49:48.011: Unhandled key: ServicesResolved value: false
(upowerd:133931): UPower-Linux-WARNING **: 02:49:48.012: Unhandled key: Connected value: false

Fixes: 29ecd92f9c ("linux: Fix BlueZ device names not synchronising")
2023-02-27 14:12:39 +01:00
Bastien Nocera
3bf5a095ac linux: Fix device paths in tests
add_device() doesn't need the full sysfs path if there's a parent,
otherwise this section of the path will be duplicated.
2023-02-27 14:12:39 +01:00