Commit graph

1589 commits

Author SHA1 Message Date
Bastien Nocera
4be148688f ci: Run upower inside catchsegv 2022-09-05 13:18:13 +02:00
Bastien Nocera
f2f5e45345 ci: Build catchsegv in CI
Build crash catcher "catchsegv"[1] in CI.

[1]: https://github.com/zatrazz/glibc-tools
2022-09-05 13:17:58 +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
Landry Breuil
cb4193ff9d openbsd: initialize new_state with a default value before using it
otherwise the native build on openbsd complains:

../src/openbsd/up-backend.c:278:23: warning: variable 'new_state' is uninitialized when used here [-Wuninitialized]
        new_time_to_empty = (new_state == UP_DEVICE_STATE_DISCHARGING && a.minutes_left > 0 ? a.minutes_left : 0);
                             ^~~~~~~~~

regression from 8be73b98 ?
2022-08-25 11:43:05 +00:00
Landry Breuil
b643f272a7 openbsd: move most initialization code from _init to _coldplug (fixes #201)
regression from the refactoring in bd488fac
2022-08-10 09:02:47 +02:00
Benjamin Berg
d4259c009b Release 1.90.0 with larger refactorings
The version number has been bumped to be able to maintain multiple
branches without conflict. This version bump is not associated with a
API/ABI break.
2022-07-21 11:06:49 +02:00
Benjamin Berg
c2d77ae251 battery: User power/current reading from battery
This switches to always use the power/current reading if we had a
sensible reading at some point in the past.

In contrast to the older UPower code, will will however ignore the
reading for 10 seconds after a discontinuity (power plug/unplug or
resume) unless we read an explicit zero value after the event happened.

We do this under the assumption that the readings may be wildly off, and
it is better to not show an estimate rather than one that is wildly
incorrect.

Note that this commit also normalises negative power readings while
discharging to be positive.

Closes: #199
2022-07-21 11:06:49 +02:00
Benjamin Berg
1ab1b70d4a battery: Make repolling more explicit
Estimation code can request a battery poll if the value is not good
enough at the point. Make this a little bit more explicit by renaming
the intenral variable to "repoll_needed" and automatically resetting it
to FALSE.
2022-07-21 11:06:49 +02:00
Benjamin Berg
9dd78a74dd battery: Better separate power usage estimation code
The up_device_battery_estimate function did more than just estimating
the current power consumption (and doing some state guessing). Move the
time to full/empty checking out of the function. Also, let it directly
modify the reported state before it is pushed into the ring-buffer.
2022-07-21 11:06:49 +02:00
NorwayFun
e6a5d9a7f5 Add Georgian translaton 2022-07-21 08:01:24 +00:00
Benjamin Berg
e88e90fafa daemon: Reevaluate polling timeout after resume
When polling is resumed the timeout needs to be reevaluated. This
requires running the polling handler once (in the next mainloop
iteration).

Set the ready time to zero to ensure this is happening. Without this, we
would be stuck without actually polling until we get a uevent from the
kernel on one of the power supplies.

Fixes: #198
2022-07-12 14:15:22 +02:00
Benjamin Berg
54166e86a8 doc: Remove website
It now has its own repository.
2022-07-11 17:12:10 +02:00
Benjamin Berg
204fa25488 ci: Expose documentation as artifact 2022-07-08 15:26:06 +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
46b5eb5fe7 device: Reload history when the ID changes
When a battery is swapped the old history needs to be saved and the
other history should be loaded.

Change the code to load the history lazily when needed. Then, to reload,
we purely need to clear the history object and it'll be loaded again
when required.
2022-06-22 18:37:46 +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
9097b57b3b battery: Guess charging/discharging state based on energy rate
This should be quite robust, in particular as we should be getting
notifications about AC plug/unplug.

The value for the battery will lag a few seconds. However, the
DisplayDevice will do some guessing taking the AC state into account,
and as such the user should get at least some immediate feedback.

Closes: #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
d672eb1d90 Add generic UpDeviceBattery base class
This class can handle laptop battery related quirks and estimations.
2022-06-21 11:15:57 +02:00
Benjamin Berg
c6cd9beff3 daemon: Iterate mainloop during coldplug
This ensures that all idle handlers have run and we report a consistent
state on the bus.
2022-06-15 16:29:28 +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
1a9541814e Add some debugging information to the README
We keep giving people these commands for bug triaging. So, lets hope
that adding them to the README removes some of the overhead and can be
helpful to users.
2022-06-15 11:54:24 +00: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
e6d4b8cd4a daemon: Guess state for multiple batteries without AC
There is no reason to not guess the state if the device has no AC power
and there is more than one battery. Remove the corresponding constraint.

Related: #146
2022-06-14 17:50:54 +02:00
Benjamin Berg
2a1ab444e8 daemon: Move state guessing after percentage calculation
Otherwise we may not have the percentage to work with, rendering the
guessing useless. This also moves the time estimation down (after the
state guessing) and does it unconditionally. This is, however, not an
issue, as the calculation matches with other places.

Related: #146
2022-06-14 17:32:36 +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
e9d73a3115 Release 0.99.19 2022-06-08 14:16:46 +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
7ed8d0e9ef freebsd: Use correct up_make_safe_string definition 2022-06-03 10:35:58 +02:00
Benjamin Berg
e61bed3b90 common: Return original pointer from up_make_safe_string
This fixes the previous commmit to 190d12e292 ("common: Add a file
with common helper") which broke the string handling for the freebsd
backend.

Related: !144
2022-05-27 11:05:07 +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
Benjamin Berg
6d947c0532 test: Do not redirect helper stdout
There is no need to do so, so drop the redirection.
2022-05-20 14:37:02 +02:00
Benjamin Berg
f1c00e50c2 test: Allow daemon to take 5 seconds for shutdown
It seems like shutdown can take more than 2 seconds on some slow
systems. So increase to 5 seconds which hopefully is long enough.

Closes: #188
2022-05-20 14:35:23 +02:00