Commit graph

1832 commits

Author SHA1 Message Date
Kate Hsuan
796ce9e579 up-daemon: DeviceList for keyboard backlight LED devices
The DeviceList was created to store the keyboard backlight LED devices.
2025-09-05 17:22:08 +08:00
Kate Hsuan
fd6eebb397 linux: up-enumerator-udev: Process add, change, and remove udev events for keyboard backlight device
Add, update, and remove the keyboard backlight LED device when receiving
add, change, and remove udev events.
2025-09-05 17:18:17 +08:00
Kate Hsuan
e01aa7c903 linux: up-kbd-backlight-led: the keyboard backlight control implementation for Linux
The implementation for Linux included:
1. Set and get brightness.
2. Get max brightness.
3. Signal if the brightness was changed by the device.
2025-09-05 16:47:11 +08:00
Kate Hsuan
1d40bc2027 linux: up-backend: Add and remove keyboard backlight LED device
These are the callback functions for the signals "device-added" and
"device-removed" to add and remove keyboard backlight devices.
2025-09-05 11:49:38 +08:00
Kate Hsuan
9f9b8478bd up-device-list: Introduce the UpDeviceKbdBacklight object
This commit makes UpDeviceList store the UpDeviceKbdBacklight objects and
sets the udev native path property of UpDevice and UpDeviceKbdBacklight.
2025-09-05 11:49:38 +08:00
Kate Hsuan
aaf52de8dc up-device-kbd-backlight: The parent class for keyboard backlight control
This parent class can be used for multiple implementations, such as freebsd
and Linux. The child class inherits it to register the device to upower
and access the dbus services.
2025-09-05 11:49:38 +08:00
Kate Hsuan
0dcb46475f dbus: org.freedesktop.UPower.KbdBacklight: Description for deprecating the KbdBacklight object path
The object path /org/freedesktop/UPower/KbdBacklight is going to be deprecated in the future.
The upper-layer app should migrate to the new API instead.
2025-09-05 11:49:38 +08:00
Kate Hsuan
40a4498454 dbus: KbdBacklight: Add a native path attribute
The DBus property shows the udev native path.
2025-09-05 11:49:38 +08:00
Kate Hsuan
c56ff5f207 Release 1.90.10
- Fix wrong model name of the devices (!267, #309)
- Switch charge_types to "Custom" when charging threshold is enabled (!268, #275)
- Fix invalid command line arguments (!269)
- Fix leak when reporting daemon usage error (!270)
- OpenBSD: support battery status from qcpas (!272)
- Fix history progression (!274, #316)
- Add a battery filter to the upower command line (!275)
- Change the charging behaviors using charge_types (!276, !46, #275)
- Fix integration tests issues, including floating point value and race between umockdev and upower (!277, !278)
- Rework upower command (!280)
- Propagate charge-threshold-enabled to display device (!281)
2025-08-26 16:04:24 +08:00
Josh Triplett
3369d31472 upower: Add a -b/--battery option to dump only battery information
This is useful when asking people to give information about battery
health. It avoids having to give two-step instructions of first
enumerating devices with `upower -e`, then looking for a device whose
name starts with `/org/freedesktop/UPower/devices/battery_`, then
running `upower -i` on that device.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
2025-08-26 13:29:52 +08:00
Florian Müllner
ff605e51c1
up-daemon: Propagate charge-threshold-enabled to display device
The property indicates that a device is plugged-in but not charging
because of the charging threshold. Desktops may want to indicate
that state, but the property is currently only exposed on actual
devices, not the virtual display device that is usually exposed
in the interface.

To address this, propagate the property to the display device
if at least one device has charge thresholds enabled.

Related: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5228
2025-08-21 14:30:45 +02:00
Kate Hsuan
4d6da1bb0f tools: up-tool: rework upower dump and enumerate
1. Move dump and enumerate to the separated functions.
2. Introduce an output filter.

Co-work-with: Cursor
Reviewed-by: Kate Hsuan <hpa@redhat.com>
2025-08-20 14:25:37 +08:00
Kate Hsuan
e1d25fa549 linux: integration-test: The type of percentage property is double
The data type of the "Percentage" property is double, so the value is a
floating point number, ex, 100.0
2025-08-12 16:10:52 +08:00
Michael Biebl
12a165e153 linux: integration-test: fix comparison of floating point values
Use assertAlmostEqual for all values that are floating point numbers:

https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertAlmostEqual

This avoids issues with excessive precision on i386.
More information https://wiki.debian.org/ArchitectureSpecificsMemo#i386

See also the corresponding downstream bug report
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1050436

The patch was generated using:

for i in Capacity Energy EnergyEmpty EnergyFull EnergyFullDesign EnergyRate Luminosity Percentage Temperature Voltage ; do
    sed -i -r "s/(assertEqual)(.*$i)/assertAlmostEqual\2/g" src/linux/integration-test.py
done

Fixes: #251
2025-08-12 15:46:23 +08:00
Kate Hsuan
903a8278f8 linux: integration-test: the settings discovery for charge threshold
The test case for settings discovery for charge threshold.
The test cases include:
1. only charge_types (4)
2. charge_control_start_threshold + charge_control_end_threshold +
   charge_types (7)
3. charge_control_end_threshold + charge_types (6)
2025-08-11 15:05:10 +08:00
Kate Hsuan
3a2fe524d0 linux: up-device-supply-battery: Discover the settings of charge threshold
This commit discovers the settings, including charge_control_start_threshold,
charge_control_end_threshold, and charge_types and update the results to
the battery information.
2025-08-11 15:05:10 +08:00
Kate Hsuan
1bf86b5483 up-device-battery: set up charge-threshold-settings-supported property
Setup and update the charge-threshold-settings-supported property.
2025-08-11 15:05:10 +08:00
Kate Hsuan
1c7b9d8bae dbus: org.freedesktop.UPower.Device: the ChargeThresholdSettingsSupported property
The types of settings for charge thresholds that are supported. The value
is a bitmask value and it is the sum of the supported types.

1: The system supports charge start threshold. The battery discharges to a
   percentage, then starts charging.
2: The system supports charge end threshold. The battery charges to a
   percentage, then stops charging.
4: The system supports optimized charging behaviors controlled by the
   system firmware.

Examples:

If the system supports charge start threshold and charge end threshold,
the value is 3.

If the system supports charge end threshold and the battery charging
behavior is controlled by the system firmware, the value is 6.
2025-08-11 15:05:10 +08:00
Kate Hsuan
2afc3c62ca linux: integration-test: Switch between Long_Life, Fast, Standard, and Adaptive
Charge_types has to be "Long_Life" if charging threshold is enabled.
Charge_types has to be "Fast", "Standard", or "Adaptive" if charging
threshold is disabled.
2025-08-11 15:05:04 +08:00
Kate Hsuan
33efe441f6 linux: up-device-supply-battery: Set charge_types to enable/disable the charge threshold
If the charge threshold is enabled, the charge_types set "Long_Life". If
the charge threshold is disabled, the charge_types set to any of
charge_types for charging, such as "Fast", "Standard", and "Adaptive".
This commit is only for the system that only has the charge_types attribute
to control the battery behaviour.
2025-08-07 14:06:06 +08:00
Kate Hsuan
a97c3ceaf5 linux: up-device-supply-battery: Using charge_types Long_Life and Standard to manage charging threshold
We found some systems, such as Lenovo ideapad that don't support
charge_control_start_threshold  and charge_control_end_threshold but it
provide the charge_types Long_Life and Standard. The chatre_types
Long_Life operate the battery in the conservation mode. That means
if Long_Life and Standard are found, the system supports the
charge threshold feature.

Co-work-with: Cursor
Reviewed-by: Kate Hsuan <hpa@redhat.com>
2025-08-07 14:06:06 +08:00
Kate Hsuan
0e6493ce22 linux: up-device-supply-battery: Set charge_types through an enum
The charge enum is used to set the charge_types and namespacing the
emum to prevent varaible name conflicts.
2025-08-07 14:06:06 +08:00
Kate Hsuan
e8fa017be4 linux: integration-test: reduce the test failure for the slow system
On a slow system like riscv64, the test_daemon_version and
test_daemon_restart tests sometimes failed. A delay was added after the
daemon starts to give it enough time to fully initialize, which has
reduced the chance of these tests failing.
2025-08-07 12:38:18 +08:00
Kate Hsuan
fe36d9ee4a linux: integration-test: fix random test failure for test_bluetooth_hidpp_mouse
Sometime we found the errors shows below when pipeline test was running.

379s ERROR: test_bluetooth_hidpp_mouse (__main__.Tests.test_bluetooth_hidpp_mouse)
379s Logitech Bluetooth LE mouse with HID++ kernel support
379s ----------------------------------------------------------------------
379s Traceback (most recent call last):
379s   File "/usr/libexec/upower/integration-test.py", line 4380, in test_bluetooth_hidpp_mouse
379s     self.assertEventually(
379s     ~~~~~~~~~~~~~~~~~~~~~^
379s         lambda: self.get_dbus_dev_property(bat0_up, "Model"), value=alias
379s         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
379s     )
379s     ^
379s   File "/usr/libexec/upower/integration-test.py", line 399, in assertEventually
379s     if condition() == value:
379s        ~~~~~~~~~^^
379s   File "/usr/libexec/upower/integration-test.py", line 4381, in <lambda>
379s     lambda: self.get_dbus_dev_property(bat0_up, "Model"), value=alias
379s             ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
379s   File "/usr/libexec/upower/integration-test.py", line 316, in get_dbus_dev_property
379s     return self.dbus.call_sync(
379s            ~~~~~~~~~~~~~~~~~~~^
379s         UP,
379s         ^^^
379s     ...<7 lines>...
379s         None,
379s         ^^^^^
379s     ).unpack()[0]
379s     ^
379s gi.repository.GLib.GError: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod: Object does not exist at path “/org/freedesktop/UPower/devices/mouse_dev_11_22_33_44_AA_BB” (19)
379s

The upower and bluez daemons were started after the udev was
initialized to avoid the random errors.
2025-08-07 12:34:35 +08:00
Kate Hsuan
bdb05da4a1 linux: integration-test: Switch the charge_types between Custom and Fast with charging threshold status
The charge_types is set to "Custom" when the charging threshold is
enabled. If the charging threshold is disabled, it will be reset
to "Fast".
2025-07-23 11:06:45 +08:00
Kate Hsuan
559b4ac208 linux: up-device-supply-battery: Set charge_types to "Custom" when enabling charging threshold
If the charge_types isn't set to "Custom" on a Dell laptop, the charging
threshold doesn't work. This commit sets the charge_types to "Custom" if
the charging threshold is enabled. Also, the charge_types will be set to
"Fast", "Standard", or "Adaptive" when the charging threshold is disabled.

This commit reads and writes the battery udev attribute "charge_types".
However, this attribute can't be found on some of the systems, so the error
on reading and writing charge_types attribute is ignored.
2025-07-23 11:06:38 +08:00
Fabrice Bellet
e7893f4624 up-history: reverse preset progression 2025-06-25 17:04:48 +08:00
Landry Breuil
fd4aaf3c65 openbsd: add support to fetch battery status from qcpas 2025-06-05 17:03:02 +08:00
Ula Shipman
2724566a2a tools: Reorder upower(1) command-line options to match manual page 2025-06-04 10:45:49 -07:00
Ula Shipman
9efac77ae7 docs: Document all upower(1) command-line options 2025-06-04 10:45:41 -07:00
Ula Shipman
ec6631a11e tools: Handle invalid command-line arguments 2025-05-29 13:53:09 +08:00
Ula Shipman
8f870fc3d2 daemon: Fix memory leak when reporting usage error 2025-05-27 19:20:53 -07:00
Kate Hsuan
a2bf0200f2 linux: integration-test: Two mice were paired with a unifying receiver
The model name of the two mice should be displayed when paired with one
unifying receiver.
2025-05-13 11:08:48 +08:00
Kate Hsuan
38317a118d linux: up-enumerator-udev: Prevent reading the sysfs path from a non-GUdevDevice object
A non-GUdevDevice object may be included in the sibling device list,
since the udev information was created slowly. This object triggers
errors when upower tries to get udev information. Therefore,
get_latest_udev_device() returns NULL, when it receives a non-GUdevDevice
object.

The error messages are shown as follows:
(upowerd:2026931): GUdev-CRITICAL **: 10:38:29.775: g_udev_device_get_sysfs_path: assertion 'G_UDEV_IS_DEVICE (device)' failed

(upowerd:2026931): GUdev-CRITICAL **: 10:38:29.775: g_udev_client_query_by_sysfs_path: assertion 'sysfs_path != NULL' failed
2025-05-13 11:06:24 +08:00
Kate Hsuan
7ae19b529f linux: up-device-supply: Only update model name when the device is under the same parent
f17d3bf fixed the unstable joypad model name but led the hid++ devices
to show the incorrect model name if more than one device is paired to a
unifying receiver. The patch only updates the model name when the device
is under the same parent.

Resolves: #309
2025-04-30 15:44:07 +08:00
Sicelo A. Mhlongo
0f1506b61a linux: integration-test: Test exporting sysfs attributes
Add test for DBus exporting of the following sysfs attributes:
1. capacity_level
2. voltage_min_design
3. voltage_max_design

Related: #301

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
2025-04-16 15:08:48 +08:00
Sicelo A. Mhlongo
240fa30ab5 lib: up-device: Expose CapacityLevel, VoltageMinDesign, and VoltageMaxDesign
For supplies that report the voltage_min_design, voltage_max_design, and
capacity_level attributes on sysfs, expose them via libupower for possible
use by clients.

Related: #301

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
2025-04-16 15:08:39 +08:00
Sicelo A. Mhlongo
c4b32387b0 linux: up-device-supply-battery: read values of capacity_level and voltage_min/max
For Linux systems that provide these attributes, extend the implementation by
reading the values for the design maximum and minimum voltage for the battery,
as well as the coarse capacity level reported by the kernel.

Related: #301

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
2025-04-16 14:39:47 +08:00
Sicelo A. Mhlongo
1decdd53f4 up-device-battery: Define capacity-level, voltage-min-design and voltage-max-design properties
Extend the parent class of the battery to support reporting the design maximum
and minimum voltage, as well as the kernel-derived capacity level.

Related: #301

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
2025-04-16 14:39:02 +08:00
Sicelo A. Mhlongo
9ee3a36a6e dbus: Define CapacityLevel, VoltageMinDesign and VoltageMaxDesign properties
Some drivers provide capacity_level, voltage_min_design, and voltage_max_design
properties on sysfs even for system supplies. Expose these properties over DBus
for consumption by clients.

Related: #301

Signed-off-by: Sicelo A. Mhlongo <absicsz@gmail.com>
2025-04-16 14:38:56 +08:00
Kate Hsuan
89c6d2726e linux: integration_test: Wait 5 seconds for bluez to set up the device information 2025-04-11 15:33:31 +08:00
Kate Hsuan
c9ee32e5d5 src: meson: extend the timeout for test_battery_state_guessing
Wait longer for the state guessing. It runs much slower on the CI than on
a local host.
2025-04-11 15:02:14 +08:00
Kate Hsuan
bdbd99b809 Release 1.90.9
- Fix unstable OnBattery status (#306 #307)
2025-04-10 14:35:54 +08:00
initramfs
ebcefcea55
linux: up-device-supply-battery: Don't mark fully charged batteries as discharging
This commit addresses the changes from commit d7ff457784
by excluding fully charged batteries even if their current_now is
negative.
2025-04-09 14:37:26 +00:00
initramfs
a86d2d059c
linux: integration-test: Update test case for "state_all_discharging" support
Updates the "test_battery_ac" test case with the changes introduced by
the addition of the "state_all_discharging" field.

Namely, we now assert that the "OnBattery" property is False while
still checking that the correct "WarningLevel" property is set.
2025-04-09 00:58:28 +00:00
initramfs
485ca6f20e
up-daemon: introduce state_all_discharging member to allow critical action dispatch on external power
In order to handle a situation where external power is connected but
all batteries are still discharging, introduce a new field
"state_all_discharging" that tracks if all batteries are currently
discharging irrespective of external power availability.

By predicating the warning level check and dispatch on this new
parameter we can ensure critical actions are still dispatched when we
have external power available, but the batteries are still draining.

Resolves: #276
2025-04-09 00:58:27 +00:00
initramfs
51b30dae8b
Revert "up-daemon: Handle the AC is online but the battery is discharging"
The commit being reverted introduces the bug #306 by claiming external
power is not available when the device battery begins to discharge for
any reason.

We fix this issue by reverting to the old behaviour of reporting
external power being available as long as it's online. We then fix
issue #276 via alternative means.

Resolves: #306

This reverts commit 9d754d8b2f.
2025-04-09 00:58:02 +00:00
Kate Hsuan
707af75194 Release 1.90.8
- Fix the incorrect percentage value of a removed battery. (#292) (!246)
- Fix device type for the gaming device. (#296 #295) (!247)
- Determine the battery discharging status when connecting a low-power
  charger. (#276) (!244)
- Fix memory leak when refreshing battery info. (#305) (!261)
- Fix memory leak when getting device id. (!261)
2025-03-31 14:58:25 +08:00
Kate Hsuan
51550b912f up-device: Fix mem leak when get device id
The up_device_get_id() returns a string, and the caller has to free it.
A comment is also left in the code to inform the behavior.

...
<snip>
...
=229301== 1,280 bytes in 10 blocks are definitely lost in loss record 1,837 of 1,852
==229301==    at 0x4849347: realloc (vg_replace_malloc.c:1801)
==229301==    by 0x48E7D6A: g_realloc (gmem.c:171)
==229301==    by 0x4907239: g_string_expand (gstring.c:82)
==229301==    by 0x49072B0: g_string_sized_new (gstring.c:113)
==229301==    by 0x10E287: up_device_get_id (up-device.c:347)
==229301==    by 0x10ED55: up_device_notify (up-device.c:241)
==229301==    by 0x49F67D9: g_closure_invoke (gclosure.c:833)
==229301==    by 0x4A26A1F: signal_emit_unlocked_R.isra.0 (gsignal.c:3720)
==229301==    by 0x4A173E8: signal_emit_valist_unlocked (gsignal.c:3519)
==229301==    by 0x4A17670: g_signal_emit_valist (gsignal.c:3262)
==229301==    by 0x4A17732: g_signal_emit (gsignal.c:3582)
==229301==    by 0x4A02973: g_object_dispatch_properties_changed.lto_priv.0 (gobject.c:1819)
2025-03-28 16:00:59 +08:00
Kate Hsuan
2ebaa01347 linux: up-device-supply-battery: Fix mem leak when refreshing battery info
The AC was plugged and unplugged repeatedly, and hit this leak in
up_device_supply_battery_refresh(). Four variables in UpBatteryInfo
need to be free.

...
<snip>
...
==2825085== 1,152 bytes in 9 blocks are definitely lost in loss record 1,851 of 1,865
==2825085==    at 0x484CE40: realloc (vg_replace_malloc.c:1801)
==2825085==    by 0x4916ADA: g_realloc (gmem.c:171)
==2825085==    by 0x4939E06: g_string_expand (gstring.c:82)
==2825085==    by 0x4939EA1: g_string_sized_new (gstring.c:113)
==2825085==    by 0x11262C: up_device_get_id (up-device.c:347)
==2825085==    by 0x113136: up_device_notify (up-device.c:241)
==2825085==    by 0x4A1B811: g_closure_invoke (gclosure.c:833)
==2825085==    by 0x4A4C0C1: signal_emit_unlocked_R.isra.0 (gsignal.c:3735)
==2825085==    by 0x4A3CCE8: signal_emit_valist_unlocked (gsignal.c:3534)
==2825085==    by 0x4A3CF71: g_signal_emit_valist (gsignal.c:3277)
==2825085==    by 0x4A3D033: g_signal_emit (gsignal.c:3597)
==2825085==    by 0x4A27C75: g_object_dispatch_properties_changed.lto_priv.0 (gobject.c:1827)
==2825085==
==2825085== LEAK SUMMARY:
==2825085==    definitely lost: 3,663 bytes in 333 blocks
==2825085==    indirectly lost: 0 bytes in 0 blocks
==2825085==      possibly lost: 960 bytes in 3 blocks
==2825085==    still reachable: 172,351 bytes in 2,205 blocks
==2825085==         suppressed: 0 bytes in 0 blocks
==2825085== Reachable blocks (those to which a pointer was found) are not shown.
==2825085== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2825085==
==2825085== For lists of detected and suppressed errors, rerun with: -s
==2825085== ERROR SUMMARY: 20 errors from 20 contexts (suppressed: 0 from 0)

Resolves: #305
2025-03-28 16:00:26 +08:00