Commit graph

1015 commits

Author SHA1 Message Date
Benjamin Berg
37f8fa2699 linux: Test fast-polling stops after 5 seconds
In some cases we fast-poll for 5 seconds after a uevent. Check that this
type of fast-polling stops when appropriate.
2022-05-10 11:06:18 +02:00
Benjamin Berg
3243ff2a56 supply: Use new polling infrastructure
This means we do the fast-repoll and normal polling with the same method
(no timeout registrations within the supply code anymore).
2022-05-10 11:06:18 +02:00
Benjamin Berg
ce15fa1507 idevice: Use new polling property 2022-05-10 09:31:46 +02:00
Benjamin Berg
2a3da575d1 daemon: Trigger device refresh based on new properties
This uses a GSource and a simple looping approach to trigger device
refresh when needed. We don't use the g_timeout_add_seconds rounding
again to synchronize with other applications, but we will eventually
poll everything at the same time. Also, we will not do wakeups if an
update happens regularily enough due to e.g. a uevent.
2022-05-10 09:31:46 +02:00
Benjamin Berg
3b287504ce device: Add polling related properties
Add last-refresh and poll-timeout properties. Update the last-refresh
property automatically from the internal refresh method. Note that it is
fine if we miss (some) updates for now, as the polling code which uses
the property will update it.
2022-05-09 22:59:17 +02:00
Benjamin Berg
8080119e02 device: Remove useless comments 2022-05-09 17:47:38 +02:00
Benjamin Berg
dc72b0cb00 daemon: Change start_poll API to refresh the device
There are two users, and both simply force a device refresh. We also
simply force-refresh devices after resume, which ties into
pausing/resuming polling.
2022-05-09 17:47:38 +02:00
Benjamin Berg
7f7839bdde device: Flag refresh reason
The reason of a refresh may be interesting to special case certain
situation (e.g. discontinuity of charge after wakeup, polling again
after an event). As such, add an enum parameter that signals the reason
for the refresh.
2022-05-09 17:47:38 +02:00
Benjamin Berg
5836099ad7 freebsd: Fix a few minor warnings 2022-04-20 14:30:01 +02:00
Benjamin Berg
25ddb11f08 device: Handle device coldplug using GInitable
There are only a few cases where we separate construction and coldplug.
Porting to GInitable is relatively natural here and makes the code a
little nicer overall. In the case that immediate coldplug/initialization
is not desired, we can still split the operations.
2022-04-20 14:30:00 +02:00
Benjamin Berg
20fed261f1 device: Register display device the same way as other devices
We can just assume that a device with a NULL native device is the
display device. Using this, we can special case the naming and rely on
the normal internal up_device_register_device function to register the
display device.
2022-04-20 14:26:50 +02:00
Benjamin Berg
388de9c1eb openbsd: Fix incorrect FD check
FD 0 is valid in principle, as such, we shouldn't use it as the default
for knowing whether the FD has been open'ed. Instead, use -2 so that -1
can still be used after open failed.
2022-04-20 14:26:50 +02:00
Benjamin Berg
ddc739f38b device-list: Remove unnecessary native argument
We can simply look it up from within the function.
2022-04-20 14:26:50 +02:00
Bastien Nocera
f961ec6154 linux: Detect drawing tablets correctly
See discussion at:
https://patchwork.kernel.org/project/linux-input/patch/20220407115406.115112-1-hadess@hadess.net/
2022-04-20 10:50:19 +02:00
Bastien Nocera
d0ebbe32bb device: Only handle Refresh() method if in debug mode
The Refresh D-Bus method could be used by clients to force re-reading
the state of batteries in the upower backends. This is not needed as
all the backends should be sending events when their states changes,
removing the need for an explicit refresh.

This is also a potential security problem if applications keep on
refreshing their data.

We now only allow access to the Refresh() method if the daemon was
started in debugging mode. This should make it clearer that it is a
debug tool.

Also remove a mention of the never implemented refresh-power-source
polkit authorisation.
2022-04-19 15:27:36 +02:00
Bastien Nocera
2f3ccee059 main: Add debug flag
This will be used to restrict some D-Bus methods to when debugging is
enabled.
2022-04-19 15:27:36 +02:00
Benjamin Berg
eeaaddbcdd bsd*: Allow building on linux
Guard platform specific code and add in a few extra definitions so that
the backends can at least be partially compiled on linux. This is for
testing purposes, if we could build against a proper image that would
also be acceptable.
2022-04-01 18:36:50 +02:00
Benjamin Berg
8be73b986a openbsd: Fix compilation and compiler warnings
It didn't even compile, and one warning about an uninitialised variable
was actually relevant.
2022-04-01 18:29:20 +02:00
Benjamin Berg
65f2aa5c24 freebsd: Remove unused swap detection code 2022-04-01 18:28:01 +02:00
Benjamin Berg
bd488facf1 device: Move daemon/native object into construct only properties
Rather than this weird situation where they are immediately passed in
through the "coldplug" method. Doing this is the first step to make
UpDevice into an initable object (removing the "coldplug" method).
2022-04-01 18:25:20 +02:00
Benjamin Berg
77a20b84e4 device: Remove unplug, moving cycle breaking into dispose
Might as well use g_object_run_dispose to break the cycle to the display
device.
2022-04-01 18:25:20 +02:00
Benjamin Berg
51b4a39a81 native: Remove unused up_native_test declaration 2022-04-01 11:47:41 +02:00
Benjamin Berg
e995ebddc4 linux: Remove unused RefreshResult enum
The refresh functions only ever returned whether data was successfully
fetched or not. The failure return code was unused and the corresponding
code can be removed.
2022-04-01 11:47:41 +02:00
Benjamin Berg
f09a6e209d linux: Fix initial enumeration of Whats Up! device
We would not scan the TTY subsystem during coldplug, which means that
the device would not be detected if it is plugged in at daemon startup
time.
i
2022-04-01 11:47:41 +02:00
Benjamin Berg
1550d50f20 linux: Remove "usb" subsystem match
The hiddev driver has been in the "usbmisc" subsystem since kernel 3.7.0
or so. As such, we can simply drop the "usb" subsystem from our matches
at this point.
2022-04-01 11:47:41 +02:00
Benjamin Berg
888b1afc6d freebsd: Drop TODO referencing battery recall feature
The feature was removed a long time ago. So the TODO is obsolete.
2022-03-28 15:30:05 +02:00
Benjamin Berg
9058d45685 Remove Wakeups API
The API relied on /proc/timer_stats which has been removed from the
kernel in 2017. Since then, the API has been non-functional (yet
incorrectly reporting support because the support test was buggy).

Just remove it completely. The debian codesearch does not uncover any
API users. Also, I doubt that any new API (based on tracing scheduler
events as perf would do) would map well to what exists now. i.e. if
something like this is re-implemented in UPower or elsewhere, then the
API should likely look different.

And, realistically, if this does need root privileges (i.e. can't be
moved to use BPF programs or so on user units), then we can also create
a new small daemon that is launched on-demand just for that.
2022-03-24 17:02:27 +01:00
Benjamin Berg
2f81d69014 daemon: Initialize FD to -1 to avoid incorrect close
Also add an assert that the FD is -1 when we are about to grab the
inhibitor. Previously, we would just set the value early enough before
trying to close the FD, overwriting the incorrect initialization.
2022-02-25 10:27:33 +01:00
Benjamin Berg
72469426b7 input: Fix FD handling and let input stream close it
The open() call needs to check against the FD being <0 for error
detection. Also, add a missing close in one of the error paths and
change the code to let the input stream close the FD when it is not
needed anymore.

We still open() it manually just because we need to do an ioctl once.
2022-02-25 10:27:33 +01:00
Benjamin Berg
7192ff481b linux: Set FD to -1 rather than 0 when closing delay inhibitor 2022-02-25 10:08:19 +01:00
Benjamin Berg
4b5b8a451b daemon: Fix action timeout abortion
Aborting the critical action would not clear the ID. Which in turn meant
that we would never re-arm the timer if such an event occured.

Fixes: #172
2022-02-22 15:00:50 +01:00
Bastien Nocera
72cf3e637d daemon: Move logic to update_warning_level()
As a follow-up to dc891bd506

Closes: #173
2022-02-21 15:26:29 +01:00
Bastien Nocera
92b38e7420 up-daemon: Fix DisplayDevice state on battery hotplug
When a device is added, make sure to recompute the DisplayDevice state
so as not to wait for the first refresh.
2022-02-16 18:22:53 +01:00
Bastien Nocera
dc891bd506 daemon: Remove warning_level variable
It was only used in one function. The value should be kept in the
DisplayDevice instead, but we need to make sure that the UpDevice code
never changes the warning-level, only the daemon does.
2022-02-16 18:21:59 +01:00
Bastien Nocera
b6b3847466 daemon: Simplify up_daemon_startup()
This portion of up_daemon_startup() contains the exact same code as
up_daemon_update_warning_level(), so call
up_daemon_update_warning_level() instead.
2022-02-16 18:12:49 +01:00
Bastien Nocera
d753df7427 daemon: Remove duplicated check
No need to guard up_daemon_set_warning_level() with a check for the
value changing, up_daemon_set_warning_level() already checks for
that exact same equality.
2022-02-16 18:12:49 +01:00
Bastien Nocera
fc93b49a6d daemon: Fix return type of up_daemon_get_warning_level_local() 2022-02-16 13:30:55 +01:00
Dominique Leuenberger
55f4b165a5 build: link libplist 2022-02-15 10:52:06 +00:00
Pablo Correa Gómez
fe79199cac
meson: Increase test timeout to avoid failures in slow architectures
The test test_critical_action_is_taken_repeatedly has two long sleeps
of UP_DAEMON_ACTION_DELAY, which is currently set in the tests to 20 seconds.
As the global timeout for meson tests is 50 seconds, failures are likely
to occur, specially in slow architectures. Increase the timeout to 60
seconds to avoid this problem.

Closes #171
2022-02-14 13:13:56 +01:00
Benjamin Berg
13aed812fd linux: Only warn about event type if an action was taken
At least for "change" events the device is most likely simply one that
we are not handling at all. For these, we will convert the event to
"add" and continue to ignore it later on.
2022-02-11 15:26:24 +01:00
Bastien Nocera
13157bce08 linux: Update Bluetooth device alias when it changes
Closes: #169
2022-02-07 15:16:50 +00:00
Bastien Nocera
f596bd0164 build: Fix missing libm link on some platforms
This should fix the PPC64 and ARMv7 builds.
2022-02-07 13:57:27 +01:00
Benjamin Berg
dd3d63b274 history: Remove unused and bogus define 2022-01-27 14:50:47 +01:00
Benjamin Berg
d113f62727 history: Delay saving history even on low power
Otherwise we flush out the data much more often than needed. With this
change, we'll also wait up to 5 seconds even on lower power. Loosing 5s
of data shouldn't be too bad, and it may prevent additional disk writes.

But, more importantly, we need to deferre writing the data to a later
main loop iteration. If we did not do this, then we have an
write-amplification scenario where the history is written at least 4
times instead of once.

Closes: #150
2022-01-27 14:48:51 +01:00
Benjamin Berg
94af9d6f3d linux: Make test compatible with older dbusmock versions
The changes from 37b6d4b039 ("linux: Fix Bluetooth tests for
python-dbusmock changes") require a not-yet-released dbusmock version.
Simply catch the error and fall back to adding the properties in order
to be compatible with both old and new dbusmock versions of the bluez
service.
2022-01-27 13:11:45 +01:00
Benjamin Berg
50bdbe7e65 history: Fix time compression of data points
The algorithm tries to use floating point timestamps. However, the
precision of floating point is too low for unix time, causing rounding
issues. This can cause extra points to be inserted (or too few) under
some conditions, creating a scenario where the test-suite fails
randomly.

Do this properly by using 64bit integers for the time. The 64bit integer
should have enough head-room even for very long histories.

Closes: #167
2022-01-25 10:36:20 +00:00
Thomas Weißschuh
1b1f8f375c linux: explicitly recognize USB power supplies
Prevents a spurious warning:
"did not recognise USB path /sys/devices/platform/USBC000:00/power_supply/ucsi-source-psy-USBC000:001, please report"

This does not actually change any functionality, as the heuristic for
the attribute "online" in up_device_supply_coldplug() would have
matches id, too.

Fixes #148
2022-01-24 14:09:24 +00:00
John Sheu
545e54713a up-daemon: fix inhibitor lock leak
The inhibitor lock should also be released when a critical action
timeout is cancelled, to avoid leaking the lock.
2022-01-24 14:03:46 +00:00
Bastien Nocera
1fdc0824b6 lib: Implement up_client_get_devices_async() 2022-01-23 23:26:33 +01:00
Bastien Nocera
95618dfad4 linux: Remove libtool support from test suite 2022-01-23 23:04:26 +01:00