Commit graph

1046 commits

Author SHA1 Message Date
Benjamin Berg
b4e9cd9739 daemon: Only refresh batteries when the "online" state changes
There is no need to refresh batteries if we just re-read the status of a
line power supply without actually seeing a change ("online" vs.
"update-time" property).

Fixes: #184
2022-05-16 09:14:07 +00:00
Benjamin Berg
4cccf81cad supply: Avoid emitting notification for line power changes
Setting the property will create a notification, which in turn causes
the daemon code to trigger a battery refresh. As such, avoid actually
setting the property if it still has the same value.

Note that we shouldn't usually get spurious notifications, but it is
good to be safe here in case e.g. a bad firmware just sends out
notifications when the battery capacity changes.

Related: #184
2022-05-16 09:14:07 +00:00
Benjamin Berg
2d6080d253 supply: Drop is_power_supply attriute that never changes
The class kept track of the power-supply property internally. However,
the value is static, and it is only needed to be queried in very few
cases.

Move the property setting to an earlier time and stop touching it when
it is not needed.
2022-05-16 09:14:07 +00:00
Benjamin Berg
6cfccef2ad device-supply: Assume USB type supplies the system
The USB device type for power supplies are always USB ports of the
system. As such, we should be able to assume that they are power
supplies.

Fixes: #183
2022-05-16 09:07:57 +00:00
Benjamin Berg
b342964400 linux: Re-poll batteries after a line power change
When a change on a line power occurs, then re-poll all batteries
aggressively for a while. It is very common for batteries to take about
a second to refresh their state and many will not send appropriate
notifications in this case.

Closes: #179, #159
2022-05-13 16:07:38 +02:00
Benjamin Berg
90c84ea95c linux: Ensure clean shutdown after tests
Instead of just killing upower, try to send SIGTERM for a clean
shut-down. Kill the process if it doesn't quit within two seconds, and
check that the service exits cleanly.
2022-05-12 14:42:35 +02:00
Benjamin Berg
24917a4b66 main: Handle SIGTERM in addition to SIGINT
It is common to stop services using SIGTERM. Add an appropriate handler
that stops upower.
2022-05-12 14:39:16 +02:00
Benjamin Berg
76b4c31ee9 linux: Add non-hid parent to hidpp tests
While not needed currently, there is a discussion to ignore the "hid"
subsystem parents when searching for siblings. Add in appropriate
parents to the tests so that such a change will not result in a failure.
2022-05-12 11:16:42 +02:00
Benjamin Berg
4fca99a819 device-supply: Fix leak of serial_number string 2022-05-12 11:09:33 +02:00
Benjamin Berg
71f1908683 daemon: Fix reference counting at daemon shutdown
Commit b78a2ab980 ("daemon: Stop passing UpDevice reference to the
daemon") fixed the fact that the signal passed a reference to the
daemon. This fix also implied that the UpDaemon object does not own a
reference to the device itself, instead relying on the UpDeviceList to
keep it alive.

With this change, there is no need to drop the extra reference when
clearing the device list, remove the code accordingly.

Reported-by: Alberts Muktupāvels <alberts.muktupavels@gmail.com>
2022-05-12 10:13:15 +02:00
Benjamin Berg
565b3531d6 linux: Test changes after BT HID power_supply subtree move
This causes an add that we ignore, after that we should still see
updates from the device (and the add itself should trigger an update).

Verify that this works by setting the capacity to 20.
2022-05-11 10:16:50 +02:00
Benjamin Berg
dac0e3bc11 linux: Remove/add device if the sysfs path changed 2022-05-11 10:16:50 +02:00
Benjamin Berg
b78a2ab980 daemon: Stop passing UpDevice reference to the daemon
There is no need to do so, in particular as the signal emission code
will keep a reference to the object internally.
2022-05-10 19:19:08 +02:00
Benjamin Berg
4651088391 device: Use modern macros for class declaration
This removes the priv member from the struct, but also means that
g_autoptr works with the class.
2022-05-10 17:14:09 +02:00
Benjamin Berg
baa14729a0 meson: Bump meson version and fix deprecations 2022-05-10 15:39:24 +02:00
Benjamin Berg
a87cb420cd linux: Store lid input device outside of device list
The device list class now assumes that contained objects are UpDevice
and we cannot store UpInput objects inside it anymore. Switch the lid
switch to be stored in the linux backend directly rather than allocating
a UpDeviceList just for that.

This fixes commit ddc739f38b ("device-list: Remove unnecessary native
argument")
2022-05-10 11:06:25 +02:00
Benjamin Berg
3c520fb590 linux: Use OutputChecker to inspect daemon log
This also means the daemon log is stored even when succeeding, making it
a bit easier to inspect tests overall.
2022-05-10 11:06:18 +02:00
Benjamin Berg
b0f1e28b42 linux/freebsd: Do not print invalid characters into log
Instead, just hex-encode them, they are invalid, it is not like having
them in raw in the log is helpful.
2022-05-10 11:06:18 +02:00
Benjamin Berg
26dee1fe3f daemon: Push internal refreshes into idle handler
As these are triggered by property changes, they may happen numerous
times for a single update. Avoid executing these (potentially expensive)
updates multiple times by pushing them into the next main loop
iteration.
2022-05-10 11:06:18 +02:00
Benjamin Berg
b9bf475459 linux: Enable fatal-warnings for most tests 2022-05-10 11:06:18 +02:00
Benjamin Berg
7f846bcee6 linux: Provide temporary history directory in tests
This avoids a warning when history files need to be saved.
2022-05-10 11:06:18 +02:00
Benjamin Berg
f2da5678f3 linux: Create an empty configuration file for every test
This avoids a warning during startup, allowing enabling fatal-warnings
in more cases.
2022-05-10 11:06:18 +02:00
Benjamin Berg
0a1edd7916 history: Allow overriding history directory for testing
Read UP_HISTORY_DIR for the history directory so that it can be made
writeable during testing.
2022-05-10 11:06:18 +02:00
Benjamin Berg
5fd3c9988c linux: Always start logind during test
This avoids a warning on daemon startup and is a step towards turning on
fatal-warnings most of the time.
2022-05-10 11:06:18 +02:00
Benjamin Berg
dc252aba71 idevice: Simplify startup handling
The startup polling just creates the idevice_t. It is trivial to detect
that, so move it into the refresh handler and set the initial polling to
the shorter period, increasing the poll interval later on.
2022-05-10 11:06:18 +02:00
Benjamin Berg
a69c009748 wup: Use new polling infrastructure 2022-05-10 11:06:18 +02:00
Benjamin Berg
1cf7e32987 hid: Use new polling infrastructure 2022-05-10 11:06:18 +02:00
Benjamin Berg
df14a9bf72 linux: Remove duplicate refresh during initilization
The main coldplug routine already does an explicit refresh. Remove the
duplication in the WUP and power supply classes.
2022-05-10 11:06:18 +02:00
Benjamin Berg
3f6e621d96 freebsd: Use new polling infrastructure 2022-05-10 11:06:18 +02:00
Benjamin Berg
89c5630eaa daemon: Disconnect all signal handlers from devices
This is just so that we don't rely on the object being destroyed at the
time we remove it. Usually the call should not be needed.
2022-05-10 11:06:18 +02:00
Benjamin Berg
f753b7302f daemon: Remove old polling code
The new code is more concise and allows devices to configure the polling
frequency.
2022-05-10 11:06:18 +02:00
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