Commit graph

514 commits

Author SHA1 Message Date
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
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
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
Bastien Nocera
b2cbf01090 linux: Test for "present" sysfs attribute handling 2023-02-21 15:19:46 +01:00
Mario Limonciello
0b7d7cfc08 linux: Fix is-present for devices at startup
As will be documented in the kernel through this patch:
https://patchwork.kernel.org/project/linux-pm/patch/20230220131018.1708991-1-hadess@hadess.net/
2023-02-21 15:19:46 +01:00
Bastien Nocera
4051aa8f80 idevice: Simplify setting the model 2022-11-16 16:14:40 +01:00
Kai Uwe Broulik
a795750a2e idevice: Prefer the user-chosen name when available
Use the device name as model name when the user-chosen device name is available.
This matches what the Bluez backend does.
2022-11-16 16:13:38 +01:00
Maciej S. Szmigiero
dcb4600b33 enumerator-udev: also check for an idevice on "usb" subsystem
Commit 1550d50f ("linux: Remove "usb" subsystem match") broke detection of
some idevices, since it left just the "usbmisc" subsystem match while some
idevice / kernel combinations (at least an iPhone 11 on a 6.0 kernel) don't
present any such udev usbmisc devices.
However, they do present "usb" subsystem ones, so add this match back.

Leave idevice detection also for the "usbmisc" match since that's what the
original (known working) code before aforementioned commit did - it is
possible that it is required for some kernel / idevice combinations.
2022-10-29 15:32:04 +02:00
Maciej S. Szmigiero
81a89385a4 enumerator-udev: actually check for an idevice
up-enumerator-udev.c forgot to include the build config file, resulting in
HAVE_IDEVICE macro always being undefined.

This meant that the idevice backend was never actually instantiated - as
evidenced by the file not even compiling when this was fixed, due to
missing "up-device-idevice.h" include.

Fix both of these issues.
2022-10-21 00:35:13 +02:00
Benjamin Berg
c2e48aa9c2 supply-battery: Assume battery is present if the attr is missing
Fixes: #208
2022-09-09 16:28:11 +02:00
Bastien Nocera
b1edcc7cbb linux: Test whether BT mice get de-duplicated 2022-09-05 17:47:08 +02:00
Bastien Nocera
7f28aa5525 linux: Make BT mouse export its serial number
As a real mouse would.
2022-09-05 17:47:08 +02:00
Bastien Nocera
3265ce3ca6 linux: Make BT mice use the same address in tests
So we can use, one, the other, or both, and still see a single device.
2022-09-05 17:47:08 +02:00
Bastien Nocera
778b93a336 linux: Hide duplicate Logitech Bluetooth devices
A lot of newer Logitech devices support both the BATT Bluetooth LE
service as well the HID++ protocol. This advertises 2 separate battery
interfaces, one HID++ one through the kernel, one BATT one through
BlueZ.

Avoid confusing UIs and hide the Bluetooth battery from the interface by
checking for duplicates each time a new device is added.

Closes: #166
2022-09-05 17:47:08 +02:00
Bastien Nocera
6bfe66a390 linux: Fix reading capacity_level with newer libgudev
Newer development versions of libgudev now strip the linefeeds by
themselves, so fix our naive linefeed-stripping which munched on the
last character of the string if there was no linefeed.

Could not find a percentage for capacity level 'Ful'

See https://gitlab.gnome.org/GNOME/libgudev/-/merge_requests/26
2022-09-05 10:34:36 +02:00
Bastien Nocera
5c8e74b76b linux: Allow filling only the serial from sibling
This fixes the serial number not being set on Bluetooth devices which
might not have a serial number but should always have a Bluetooth
address to differentiate them.
2022-09-05 10:34:03 +02:00
Bastien Nocera
29ecd92f9c linux: Fix BlueZ device names not synchronising
We were correctly handling an "Alias" property changing, but never
passed the property to that code as we were dropping anything that
wasn't a battery related update.
2022-09-02 11:38:39 +02:00
Benjamin Berg
3c4f902fbd test: Add battery ID changing test for history loading/saving 2022-06-22 18:38:49 +02:00
Benjamin Berg
8817dec73f test: Fix flaky battery aggregation test
It seems that the test was still flaky, the reason for that would be
that we did not explicitly wait for the log line saying that the
aggregate state was calculated.

The only reason that it did not consistently fail appears to be that
searching for the state conflict caused messages to be skipped. That is
wrong, we should account for every "Calculating percentage" message to
ensure that upowerd and the test is in sync.
2022-06-21 13:26:39 +02:00
Benjamin Berg
0b462e41d1 supply-battery: Fixup comment 2022-06-21 11:59:06 +02:00
Benjamin Berg
7e73f5a246 supply-battery: Stop reading voltage_present
It appears this is an old property name. The string does not appear
anywhere in the Linux kernel as of 5.18.0.
2022-06-21 11:26:00 +02:00
Benjamin Berg
8ec7362e93 battery: Add full/empty guessing based on capacity
Assuming we have some estimation for the current battery capacity (i.e.
percentage), we can infer a FULL/EMPTY state. Do so if the battery state
is unknown.

Related: #196
2022-06-21 11:16:27 +02:00
Benjamin Berg
14f06728b5 test: Add test for charging/discharging guessing based on rate
See: #196
2022-06-21 11:16:01 +02:00
Benjamin Berg
6fedd0f20a linux: Use new battery class and drop unused code
This makes the switch. There are a few behaviour changes with regard to
estimations (which hopefully got both simpler and more robust at the
same time).
2022-06-21 11:16:01 +02:00
Benjamin Berg
ed2d5a25b3 linux: Add new UpDeviceSupplyBattery class
This split the functionality found in UpDeviceSupply to handle batteries
out and is based on the previously added UpDeviceBattery class.
2022-06-21 11:16:01 +02:00
Benjamin Berg
54e396e7ae test: Disable battery polling to make test more stable
Otherwise the fast repolling can get in-between, cause extra logging and
trigger a failure.
2022-06-15 14:09:14 +02:00
Benjamin Berg
4dac45e53a test: Test state guessing for one and two batteries
The state guessing code based on the AC state was not tested well.
Improve the test by testing both 1 and 2 batteries and checking the
reported state in more detail.
2022-06-14 17:51:06 +02:00
Benjamin Berg
ce24787165 supply: Use percentage to guess empty STATE
Using energy is broken as the value might be zero if it is not provided.
However, either energy or percentage ("capacity") should have been read
from the sysfs. And, in both cases the percentage should reflect
something reasonable.

Related: #146
2022-06-14 17:02:45 +02:00
Benjamin Berg
a78ee60390 test: Properly wait for idle handler after uevents
The state aggregation test requires an idle handler to run, which can be
a bit unreliable as it may or may not run twice.

Force running it twice and add code to wait for it to complete. Do so
properly by waiting for the correct log messages rather than sleeping so
that everything is ordered nicely while not slowing down the test a lot.

Closes: #193
2022-06-09 12:38:34 +02:00
Benjamin Berg
c6a851d798 test: Add test for mice that have keys
These should not be detected as keyboards.
2022-06-08 12:55:59 +02:00
Benjamin Berg
a57c2b1e1e supply: Use differing priority within input node and between them
If we have an input node with both a keyboard and a mouse in one node,
then prefer the mouse. However, if we have separate mouse and keyboard
device nodes, prefer the keyboard.

Closes: #189
2022-06-08 12:55:34 +02:00
Benjamin Berg
115b756eaf supply: Remove ID_INPUT_TABLET_PAD check as it implies ID_INPUT_TABLET
No need to test for ID_INPUT_TABLET_PAD separately.
2022-06-08 12:38:02 +02:00
Benjamin Berg
68d4f3702d Move battery type decoding into common file 2022-06-07 16:07:03 +02:00
Benjamin Berg
1587b37707 test: Test all possible inputs for daemon state aggregation
This adds a test that checks all possible inputs for the battery state
aggregation. Not all states are actually tested in this case, as some
states may be handled through state inference and others might not be
well defined.
2022-06-07 16:07:03 +02:00
Benjamin Berg
13f7cc7bb5 daemon: Update aggregate state matching and handle UNKNOWN state
Stop trying to guess a battery state based on the AC information for a
single battery. Instead, just do the guessing in the display device.

This means that cases with more than one battery work fine. It also
means that we still report an UNKNOWN state for the battery itself.

Also get the on_battery information from the display devices discharging
state, there is no need to iterate all of the batteries to figure that
out.

Note that we don't really have a well defined state for the display
device in all cases. We'll add a test in the next step, marking those
cases as TBD or ANY to show where the issues are. AFAICT we do not have
a regression though, so this should be fine for now.

Fixes: #146
2022-06-07 15:35:03 +02:00
Benjamin Berg
792fc7bb1b supply: Consistently use 90% threshold to consider a battery full 2022-06-03 10:36:02 +02:00
Benjamin Berg
c330351937 test: Disable systemd v251 sysfs verification
The umockdev code to disable it by setting the variable does not
propagate through python. Set the variable here until there is a more
permament solution available.
2022-05-25 16:57:21 +02:00
Benjamin Berg
190d12e292 common: Add a file with common helper
This removes some code duplication between the linux and freebsd
backend. And, this file could become home to other small helper
functions in the future.
2022-05-25 15:32:29 +02:00
Benjamin Berg
66eb9b9d7a test: Stop processes using cleanup function
Using tearDown is brittle, as an assertion will stop it from running
through completely. So move cleanup into a helper that is called via
addCleanup for logind and bluez.
2022-05-20 14:41:52 +02:00
Benjamin Berg
41bceac6ef test: Only assert daemon log is closed if daemon is started 2022-05-20 14:37:23 +02:00