Commit graph

1189 commits

Author SHA1 Message Date
Kate Hsuan
7bf275b263 linux: integration-test: Value blip for Macbook 2024-06-05 13:17:45 +08:00
M Caron
fc90fae0d3 Add quirk to always update energy_full when the current energy surpasses it. 2024-05-07 02:52:34 +00:00
Kate Hsuan
544eba5543 test: the test for CriticalPowerAction=Suspend
The test cases for AllowRiskyCriticalPowerAction=true and false when
CriticalPowerAction=Suspend.
2024-04-25 16:07:11 +08:00
Kate Hsuan
69436647c5 linux: up-backend: A safeguard for the risky CriticalPowerAction
If AllowRiskyCriticalPowerAction is true and the CriticalPowerAction
is "Suspend", The "Suspend" can be the CriticalPowerAction.
Otherwise, "HybridSleep" will be the CriticalPowerAction.
2024-04-25 16:07:11 +08:00
Kate Hsuan
469346b6bf up-config: set filename variable with g_autofree 2024-04-25 16:07:11 +08:00
Kate Hsuan
8cb9fb0231 up-config: The warning message for the risky CriticalPowerAction
The warning message will be shown when CriticalPowerAction is "Suspend".
One iwarning message is for enabling the risky CriticalPowerAction and
the other is to show the potential risk when
AllowRiskyCriticalPowerAction is true.
2024-04-25 16:07:11 +08:00
Alexander Couzens
18b4748435 linux: allow Suspend as CriticalPowerAction
When using UPower in a non-hybernate setup, the result of a
CriticalPowerAction would be PowerOff. Certain users prefer
Suspend instead, because this is the only way to recover
graceful from that state.
Suspend action will only used, when explicit configured.

Closes: #23
Closes: #59
Signed-off-by: Kate Hsuan <hpa@redhat.com>
2024-04-25 16:07:11 +08:00
Jelle van der Waa
1e58e8218a Stop using deprecated g_get_current_time
g_get_current_time was deprecated in 2.62 and can be directly replaced with
g_get_real_time.
2024-03-13 08:59:46 +01:00
Jelle van der Waa
3e808424b3 build: use install_emptydir for installing the history dir
This resolves the following deprecation warning, meson these days has a
special function for installing an empty directory:

* 0.60.0: {'install_subdir with empty directory'}
2024-03-11 14:53:53 +01:00
Kate Hsuan
bbb593d306 up-device: Remove history only on device id change
Remove the history when the device id was changed.
2024-03-05 16:27:16 +08:00
Kate Hsuan
76e2b9e571 up-device: a filter to ignore the unknown status from the devices
Ignore all the unknown events from the devices.
2024-03-05 16:27:16 +08:00
Kate Hsuan
ab50a2bb3e up-history: Compare the history id with a given string
up_history_is_device_id_equal() is used to compare the history device_id
with a given string.
2024-03-05 16:27:16 +08:00
Jelle van der Waa
17c14cc63f Revert "all: Remove Lid handling"
This reverts commit 07565ef6a1.

In the current systemd stable release 255 org.freedesktop.login1 does
not emit a LidisClosed event, this has added in systemd `main` and will
be availble in the next release.

As GNOME control panel still uses UPower's `LidIsclosed` property and
many other DE's such as Xfce/LXQt/Deepin as well revert this until the
systemd changes are available in all Distributions.

https://github.com/systemd/systemd/pull/30706

Resolve: https://gitlab.freedesktop.org/upower/upower/-/issues/260
2024-01-26 14:57:27 +00:00
Martin Pitt
bd1e4698f4 linux: Adjust test_bluetooth_le_device for dbusmock 0.30.1
dbusmock 0.30.1 changed the BlueZ template to set the default "Class"
property to `MOCK_PHONE_CLASS` right away instead of in PairDevice() [1].

test_bluetooth_le_device() relied on the previous implicit default of a
"0" Class value. Set this explicitly to expect a "generic" device. This
makes the test work with old and current dbusmock versions.

https://bugs.debian.org/1059467

[1] https://github.com/martinpitt/python-dbusmock/pull/192
2023-12-28 21:13:15 +01:00
Ratchanan Srirattanamet
dfde9e2274 linux: stop assuming power supply of unknown type as battery
Some vendor kernel (most notably Android devices) expose various types
of BMS (battery management system) as power supplies. This is something
UPower has never designed to deal with, and thus UPower should not
represent or consider it to be a battery.

Fortunately, most of the time the actual "battery" power supply has the
correct type, so we can safely ignore those devices which have unknown
type. Also, the code that assumes power supply of unknown type seems
pretty dated and probably doesn't make sense anymore. So, let's remove
this assumption altogether.
2023-11-09 15:51:14 +07:00
Jelle van der Waa
4baf9b8903 linux: drop f-literals without format string 2023-11-03 15:26:26 +01:00
Jelle van der Waa
d3a1d17d59 linux: prefer is not None over !=
Compare on object identity not equality.
2023-11-03 15:18:09 +01:00
Bastien Nocera
07565ef6a1 all: Remove Lid handling
It is now handled solely in logind to take power management decisions,
and in the compositor for making decisions related to available
displays.

See:
https://www.freedesktop.org/software/systemd/man/org.freedesktop.login1.html
2023-07-06 11:09:42 +02:00
Bastien Nocera
bdc5638627 linux: Add installed-tests manifest
This will allow running the tests to target installed binaries.
2023-07-06 10:31:46 +02:00
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