Commit graph

1819 commits

Author SHA1 Message Date
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
Kate Hsuan
df51aef98a rules: 95-upower-hid.hwdb: update hwdb for HID devices
Update HID hwdb.
2025-03-25 17:08:40 +08:00
Kate Hsuan
71e473902f linux: integration-test: Handle connecting the low-power charger
Add a scenario for connecting a low-power charger.
1. The AC is online.
2. The battery is discharging.
3. The percentage drops to 2.5%.
4. The warning level will become UP_DEVICE_LEVEL_CRITICAL.

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2025-02-24 06:13:47 +00:00
Kate Hsuan
d7ff457784 linux: up-device-supply-battery: reset the status to discharging when current_now is negative
For some USB battery solutions, the kernel reports charging when
connecting a charger but in reality, the battery discharges and
current_now is negative. This work reset the battery status to
"Discharging" when current_now is negative and line power is
online.

Resolves: #276

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2025-02-24 06:13:47 +00:00
Kate Hsuan
9d754d8b2f up-daemon: Handle the AC is online but the battery is discharging
If a low-power charger connects to the system, the battery still reports
discharging since the AC charger can't provide enough power to make      
the system runs and charges the battery at the same time. In this situation,
we estimate the warning level to trigger the CriticalPowerAction until
the battery status is changed to charging.

Resolves: #276

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2025-02-24 06:13:47 +00:00
Jelle van der Waa
6f9d84694d linux: rules: fix warnings from udevadm verify
rules/60-upower-battery.rules:5 style: whitespace after comma is expected.
rules/60-upower-battery.rules:5 style: a comma between tokens is expected.
2025-02-22 15:20:12 +01:00
Kate Hsuan
4f1ef04475 linux: integration-test: a test case for Dualshock4 with a headphone jack 2025-02-08 07:58:03 +00:00
Kate Hsuan
f17d3bfcd0 linux: up-device-supply: Update the model name after changing the device type
The model name of a device component may be different. For example,
Dualshock joystick owns "Sony Interactive Entertainment DualSense
Wireless Controller" for the joystick and "Sony Interactive
Entertainment DualSense Wireless Controller Motion Sensors" for the
accelerometer. If the device type is changed based on the device
priority, the corresponding model name have to be changed.

Resolves: #295

Tested-by: Mateus Rodrigues Costa <mateusrodcosta@gmail.com>
Signed-off-by: Kate Hsuan <hpa@redhat.com>
2025-02-08 07:58:03 +00:00
Mateus Rodrigues Costa
351affe12f linux: device_supply: Prioritize Gaming Input
The DualSense and DualShock 4 have 3 main components: the gamepad proper,
a touchpad and motion sensors. They also have an extra component in the
form of a headphone jack, which is only available via BT on the
PlayStation consoles but can be used on other devices via USB.

Commit 00eb31a63c increased the priority of
Gaming Input so the controllers weren't accidentally identified as only
the Touchpad, which works on BT. This commit prioritizes Gaming Input over
Audio Device, fixing an issue that only happens on USB.

Resolves: #296
2025-02-08 07:58:03 +00:00
Sicelo A. Mhlongo
a16c752e85 dbus: UPower.xml: Update GetCriticalAction Values
UPower now supports Suspend and Ignore as possible actions. Update the
documentation accordingly.
2025-02-06 10:46:33 +02:00
Kate Hsuan
478c51e4ea linux: integration-test: test case for the removable battery 2025-01-24 17:39:54 +08:00
Kate Hsuan
3452140a6c src: up-device-battery: Reset values when the battery is not present
If the battery is not present, reset the attribute values.

Resolves: #292
2025-01-24 17:39:37 +08:00
Kate Hsuan
6bd8cd90b3 src: up-daemon: skip the battery if present = 0
If the battery is not present, skip it when estimating the battery
percentage.

Resolves: #292
2025-01-24 17:39:03 +08:00
NorwayFun
eb5a327127 Update LINGUAS 2025-01-17 02:11:22 +00:00