Compare commits

...

49 commits

Author SHA1 Message Date
Armin Wolf
25303ba527 up-device-battery: Prefer "Standard" over "Fast" charging
When disabling the charging threshold feature upower will change the
charging strategy from "Long Life" to "Fast" if a battery supports
"Long Life", "Standard" and "Fast". This behavior is suboptimal
because "Fast" charging might wear down the battery over time, while
"Standard" is supposed to be used as the safe default.

Fix this by preferring "Standard" over "Fast" charging in such
situations.

Resolves: #344
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
2026-04-20 12:29:27 +02:00
Kate Hsuan
17f9e8dc5a Release version 1.91.2
- Feature: Skip the systemd inhibitor when performing CriticalPowerAction
  (!309)
- Feature: Introduce "Auto" CriticalPowerAction using systemd-logind
  Sleep() (!309)
- Fix: Test CanPowerOff() availability before calling PowerOff() (!311)
- Fix: Add charge limit support for systems providing only
  charge_control_end_threshold (!310, #342, #285)

Co-Authored-By: Cursor and Claude-4.6-sonnet
Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-04-01 16:20:02 +08:00
Kate Hsuan
61654b84af linux: up-backend: Test availability before calling systemd-logind PowerOff
Call CanPowerOff() to find the availability before calling PowerOff().
The priority of the Sleep() call should be higher than Ignore. That is the
final fallback call when the other critical power actions aren't
available.

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-03-24 14:13:03 +08:00
Kate Hsuan
20a844b41e rules: 60-upower-battery: charge threshold is supported when start or end threshold is present
Add CHARGE_LIMIT support for systems only providing
charge_control_end_threshold. This allows UPower to configure charge
thresholds when the specific sysfs property is present.

Related: https://gitlab.freedesktop.org/upower/upower/-/merge_requests/308
Resolves: https://gitlab.freedesktop.org/upower/upower/-/issues/342

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-03-23 17:06:14 +08:00
Kate Hsuan
d75f2dbee4 policy: org.freedesktop.upower.rules: grant permission for skipping the inhibitor
The polkit rule gives upower the necessary permission to ignore the
systemd inhibitor when upower runs the CriticalPowerAction.

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-03-06 12:19:57 +08:00
Kate Hsuan
f4764ee174 linux: up-backend: Auto CriticalPowerAction
Systemd can be used to determine the better critical actions since systemd
knows which power actions are supported by the system. A "Auto" critical
action was introduced and that invoked the Sleep() systemd-logind API to
set the system power status when the battery level reaches PercentageAction
or TimeAction.

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-03-06 12:19:53 +08:00
Kate Hsuan
c098e60a59 linux: up-backend: skip systemd inhibitor when performing critical action
The API was changed to, for example, "HybriSleepWithFlags" to skip the
systemd inhibitor. The user apps can set the systemd inhibitor to
stop the power action, such as suspend, hibernate, etc., when playing
PC game or movie watching. The inhibitor may block the
CriticalPowerAction when the battery level is low.

Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-03-03 16:48:06 +08:00
Kate Hsuan
57f59b584e Release 1.91.1
- Fix: a resource leak (!294)
- Fix: a NULL exception caused by a Non-NULL GError pointer (!295, #331)
- Fix client API: crashing when printing the error message from a NULL GError pointer (!304)
- Feature: Skip CriticalPowerAction when performing battery recalibration (!285, #312)
- Deprecate: capacity_level and luminosity property (!293, !297 )
- CI: Add a tartan LLVM static analysis (!300)
- Feature: History supports voltage item (!299)

Bump up the libupower-glib release since (!304)
2026-02-10 20:01:59 +08:00
Kate Hsuan
988624350b linux: up-device-supply-battery: Fix ACPI reports -NaN capacity attribute
The user reported that the ACPI of a legacy system reports -NaN value for
its battery "capacity" attribute. This value causes upower crash with a
GLib assertion.

The -NaN was converted to 0.0 for the Percentage value to fix the issue.

Resolves: #339 #340
2026-02-10 16:16:42 +08:00
Kate Hsuan
09a8e63bae libupower-glib: up-client: Verify the UpClient pointer when invoking the API
Passing a NULL UpClient to up_client_get_devices2() led to the following
error message and crash since up_client_get_devices_full() returned
immediately, without properly setting up a GError with an error message.

The input UpClient pointer verification was moved from the internal
function to the API entry to ensure only a valid UpClient is passed
to the internal function. Moreover, GError will be properly set by the
GLib dbus APIs and the internal function.

(upower:21076): libupower-glib-CRITICAL **: 16:33:53.919: up_client_get_devices_full: assertion 'UP_IS_CLIENT (client)' failed
Segmentation fault         (core dumped) ./upower -d

Related: https://gitlab.freedesktop.org/upower/upower/-/merge_requests/296

Reported-by: Mathias Krause <minipli@grsecurity.net>
Signed-off-by: Kate Hsuan <hpa@redhat.com>
2026-02-03 21:42:03 +08:00
Kate Hsuan
f61735aa6d rules: 95-upower-hid: Update to the latest hwdb
Update NUT hwdb rules.
2026-01-21 12:11:32 +08:00
Kate Hsuan
eff769c65f Revert "lib: Mark lid related functions and properties as deprecated"
This reverts commit 4e962fdc8d.

Undeprecate lid APIs since upower continues to support lid DBus APIs.
2026-01-06 14:26:16 +08:00
Sicelo A. Mhlongo
37f7086983 up-self-test: Add historical voltage data support 2026-01-05 12:39:22 +02:00
Sicelo A. Mhlongo
8e424217f5 lib: up-device: Expose historical voltage data
Enable library users to access stored voltage data.
2026-01-05 12:39:13 +02:00
Sicelo A. Mhlongo
7d486c500c up-device: Implement storage and retrieval of historical voltage data 2026-01-05 12:34:44 +02:00
Sicelo A. Mhlongo
09c8bbb0f7 up-history: Store and retrieve historical data for voltage
Extend the history implementation to store and retrieve data about voltage
information for batteries.
2026-01-05 12:34:44 +02:00
Sicelo A. Mhlongo
1c052a378f dbus: Add voltage as a supported history item
In certain applications, access to historical voltage data might be useful, for
example to plot voltage curves. Add support for this property.
2026-01-05 12:34:26 +02:00
Kate Hsuan
bf3d20378f contrib: add a tartan static analysis script and description 2025-12-29 17:02:31 +08:00
Sicelo A. Mhlongo
f6e63cfc40 upower: deprecate luminosity property
Since d2053eff ("linux: Remove user-space support for Logitech Unifying
devices"), the luminosity property is no longer in use and no code for it
exists except in the lib. Deprecate and eventually drop it.
2025-12-17 16:46:28 +08:00
Kate Hsuan
0f57b6bf73 Drop the incorrect "since version" and mark the capacity_level property as deprecated
Fix: 09ada72 (dbus: org.freedesktop.UPower.Device: deprecate CapacityLevel property)
2025-12-17 16:19:55 +08:00
Kate Hsuan
38ab5417b7 linux: integration-test: test for the battery recalibration
Test case for ignoring the CriticalPowerAction when performing the battery
recalibration.
2025-12-15 14:19:13 +08:00
Kate Hsuan
d9f42cfc9d up-daemon: Report UP_DEVICE_LEVEL_NONE when battery is performing recalibration
If the battery is performing recalibration and AC is online,
UP_DEVICE_LEVEL_NONE is considered.
2025-12-15 14:19:13 +08:00
Kate Hsuan
4722fcfaac up-config: introduce the ExpectBatteryReCalibration for battery recalibration
ExpectBatteryReCalibration allows the user to ignore the
CriticalPowerAction when performing the battery recalibration.
2025-12-15 14:19:13 +08:00
Kate Hsuan
1ba5f3a55e linux: up-device-supply-battery: Fix assigning an error to a non-NULL GError pointer
As some systems only allow for one charge threshold setting, the overall
process is treated as a success as long as one of the values is set
correctly. We only treat it as an error (and return FALSE) if both the
start and end threshold settings fail. For this reason, we don't need
to track specific errors for every write, so the GError parameter in
g_file_set_contents_full() is set to NULL.

Fedora upowerd[1326]: g_file_set_contents_full: assertion 'error == NULL || *error == NULL' failed
Fedora upowerd[1326]: GError set over the top of a previous GError or uninitialized memory.
                      This indicates a bug in someone's code. You must ensure an error is NULL before it's set.
                      The overwriting error message was: Failed to set charge control thresholds

Resolves: #331
2025-12-12 20:14:04 +08:00
Kate Hsuan
c5df437cc1 linux: up-device-supply: fix the resource leak
1. free the udev parent node automatically.
2. free new_model_name variable in the same scope.
2025-11-28 15:00:22 +08:00
Kate Hsuan
d79841fe40 meson: Release 1.91.0
The major change includes:
1. Support multiple keyboard backlight LED control.
2025-11-25 16:39:56 +08:00
Kate Hsuan
a4d0d469f3 meson: so relase bump up due to recent property changes 2025-11-25 15:25:06 +08:00
Kate Hsuan
09ada726f7 dbus: org.freedesktop.UPower.Device: deprecate CapacityLevel property
This property is duplicated from BatteryLevel and confuses the user.
2025-11-25 14:33:55 +08:00
Kate Hsuan
391e3323f0 etc: UPower.conf.d: add UPower.conf.d
The configuration files in the UPower.conf.d will override the primary
configuration.
2025-11-12 15:46:00 +08:00
Manuel A. Fernandez Montecelo
46bbc8a602 Add support for conf.d style dirs (UPower.conf.d)
This change adds the feature to read config from conf.d style
directories (UPower.conf.d), commonly supported by other tools, as an
extension of the main config file.

This is useful and convenient in several situations, for example:

- distributions can set different values from the defaults shipped
  upstream without having to modify the main UPower.conf

- different packages or config-management tools can change config just
  by adding, removing or modifying files in that directory

The main config file, e.g. '/etc/UPower/UPower.conf', will be
processed first, and then files in the UPower.conf.d dir, if existing.

The directory to use is derived automatically, e.g.
'/etc/UPower/UPower.conf.d/' if the main config file is
'/etc/UPower/UPower.conf'.  Only files within that directory are
considered, and only those with valid config-group 'UPower' and with
the filename format: starting with '00-' to '99-', ending in '.conf'
and with alphanumeric characters, dash or underscore in between.

The candidate files within the given directory are sorted (with
g_strcmp0(), so the ordering will be as with strcmp()).  The
configuration in the files being processed later will override
previous config, in particular the main config, but also the one from
previous files processed, if the Group and Key coincide.

Add also relevant integration test: 'test_conf_d_support'
2025-11-12 15:45:56 +08:00
Luca Boccassi
5f572ffd9a polkit: fix config syntax
These fields do not start with an underscore. polkitd complains
about them:

 polkitd[2017783]: skipping unknown tag <_description> at line 18
 polkitd[2017783]: skipping unknown tag <_message> at line 19
2025-10-21 16:59:38 +08:00
Kate Hsuan
9c8769d7df ci: fix pre-commit test
Resolve the libatomic dependency issue.
2025-10-21 16:51:40 +08:00
Kate Hsuan
8ce78b7f9e meson_options: replace deprecated boolean variable 2025-09-17 12:27:42 +08:00
Kate Hsuan
f26409e925 rules: 95-upower-hid: update hwdb from upstream NUT
Update to the latest hwdb from NUT.

Link: https://networkupstools.org
Link: https://raw.githubusercontent.com/networkupstools/nut/master/scripts/upower/95-upower-hid.hwdb
2025-09-16 15:51:36 +08:00
Luciano Santos
5bf9cac60d build: Make installation of tests optional
Default to installing them, while letting people/distributors decide
what they want.
2025-09-16 15:25:49 +08:00
Sicelo A. Mhlongo
84aab7aefa linux: up-enumerator-udev: also permit lp5523:kb name
While common keyboard backlight devices use 'kbd_backlight' in the name, per
linux kernel include/dt-bindings/leds/common.h, there are a few legacy names,
including 'lp5523:kbN'. They cannot be easily changed now because it would
break userspace, hence the names are still provided in the kernel.  Support
them in upower as well. The lp5523 as used on the Nokia N900 exposes six
independent keyboard backlight LEDs, and UPower is able to manage them with
this patch in place.
2025-09-05 17:22:08 +08:00
Kate Hsuan
afb346cf77 linux: integration-test: Multiple keyboard backlight LED support
The integration test for multiple keyboard backlight support.
2025-09-05 17:22:08 +08:00
Kate Hsuan
e0baa3fdcb up-daemon: The implementation of EnumerateKbdBacklight
The implementation for enumerating all keyboard backlight LED objects
on the system.
2025-09-05 17:22:08 +08:00
Kate Hsuan
d316a111f7 dbus: org.freedesktop.UPower: Enumerate kbd backlight LEDs
Enumerate all keyboard backlight LED objects on the system.
2025-09-05 17:22:08 +08:00
Kate Hsuan
4ba78c54a9 linux: up-enumerator-udev: enumerate the LED subsystem
The LED udev subsystem was added to the list to watch the
keyboard backlight LED device events.
2025-09-05 17:22:08 +08:00
Kate Hsuan
6bfc3d6100 up-daemon: device-added and device-removed keyboard backlight device
The keyboard backlight device will be added to or removed from DeviceList
when receiving the "device-added" and "device-removed" signal.
2025-09-05 17:22:08 +08:00
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
39 changed files with 2128 additions and 150 deletions

View file

@ -55,6 +55,7 @@ image: $FEDORA_IMAGE
pre_commit: pre_commit:
stage: pre-commit stage: pre-commit
script: script:
- dnf install -y libatomic
- dnf install -y pre-commit - dnf install -y pre-commit
- pre-commit run --all-files - pre-commit run --all-files
@ -299,4 +300,4 @@ container_debian_build:
echo "deb-src http://deb.debian.org/debian/ trixie main contrib non-free" >> /etc/apt/sources.list && echo "deb-src http://deb.debian.org/debian/ trixie main contrib non-free" >> /etc/apt/sources.list &&
apt update && apt update &&
apt build-dep -y upower && apt build-dep -y upower &&
curl https://gitlab.freedesktop.org/hadess/check-abi/-/raw/main/contrib/check-abi-fedora.sh | bash curl https://gitlab.freedesktop.org/hadess/check-abi/-/raw/main/contrib/check-abi-fedora.sh | bash

31
NEWS
View file

@ -1,3 +1,34 @@
Version 1.91.2
--------------
Released: 2026-04-01
- Feature: Skip the systemd inhibitor when performing CriticalPowerAction (!309)
- Feature: Introduce "Auto" CriticalPowerAction using systemd-logind Sleep() (!309)
- Fix: Test CanPowerOff() availability before calling PowerOff() (!311)
- Fix: Add charge limit support for systems providing only charge_control_end_threshold (!310, #342, #285)
Version 1.91.1
--------------
Released: 2026-02-10
- Fix: a resource leak (!294)
- Fix: a NULL exception caused by a Non-NULL GError pointer (!295, #331)
- Fix client API: crashing when printing the error message from a NULL GError pointer (!304)
- Fix: ACPI reports -NaN capacity value (!306)
- Feature: Skip CriticalPowerAction when performing battery recalibration (!285, #312)
- Deprecate: capacity_level and luminosity property (!293, !297 )
- CI: Add a tartan LLVM static analysis (!300)
- Feature: History supports voltage item (!299)
Version 1.91.0
--------------
Released: 2025-11-25
- New feature: Support multiple keyboard backlight LED control. (#291 !203)
- Make installation of tests optional (!202)
- Support conf.d style config file (!286)
- Deprecate CapacityLevel property (!290 #333)
Version 1.90.10 Version 1.90.10
-------------- --------------
Released: 2025-08-26 Released: 2025-08-26

View file

@ -51,3 +51,15 @@ logs. There are two ways of doing so:
3. `sudo systemctl restart upower.service` 3. `sudo systemctl restart upower.service`
4. Grab logs using `journalctl -u upower.service` or similar 4. Grab logs using `journalctl -u upower.service` or similar
## Using tartan
[Tartan](https://gitlab.freedesktop.org/tartan/tartan/-/wikis/home) is a LLVM static
analysis plugin built to analyze GLib code. It can be installed and then run using:
```shell
mkdir build
cd build
meson setup ..
SCANBUILD=../contrib/tartan.sh ninja scan-build
```

11
contrib/tartan.sh Executable file
View file

@ -0,0 +1,11 @@
#!/bin/sh
/usr/bin/scan-build-20 \
-load-plugin /usr/lib64/tartan/20.1/libtartan.so \
-disable-checker core.CallAndMessage \
-disable-checker core.NullDereference \
-disable-checker deadcode.DeadStores \
-disable-checker unix.Malloc \
-enable-checker tartan.GErrorChecker \
--exclude meson-private \
--status-bugs -v "$@"

View file

@ -158,7 +158,7 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="type" direction="in" type="s"> <arg name="type" direction="in" type="s">
<doc:doc><doc:summary>The type of history. <doc:doc><doc:summary>The type of history.
Valid types are <doc:tt>rate</doc:tt> or <doc:tt>charge</doc:tt>.</doc:summary></doc:doc> Valid types are <doc:tt>rate</doc:tt>, <doc:tt>charge</doc:tt> and <doc:tt>voltage</doc:tt>.</doc:summary></doc:doc>
</arg> </arg>
<arg name="timespan" direction="in" type="u"> <arg name="timespan" direction="in" type="u">
<doc:doc><doc:summary>The amount of data to return in seconds, or 0 for all.</doc:summary></doc:doc> <doc:doc><doc:summary>The amount of data to return in seconds, or 0 for all.</doc:summary></doc:doc>
@ -186,7 +186,7 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
<doc:item> <doc:item>
<doc:term>value</doc:term> <doc:term>value</doc:term>
<doc:definition> <doc:definition>
The data value, for instance the rate in W or the charge in %. The data value, for instance the rate in W, the charge in % and the voltage in V.
</doc:definition> </doc:definition>
</doc:item> </doc:item>
<doc:item> <doc:item>
@ -572,11 +572,18 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
</property> </property>
<property name="Luminosity" type="d" access="read"> <property name="Luminosity" type="d" access="read">
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<doc:doc> <doc:doc>
<doc:description> <doc:description>
<doc:para> <doc:para>
Luminosity being recorded by the meter. Luminosity being recorded by the meter.
</doc:para> </doc:para>
<doc:para>
DEPRECATED
</doc:para>
<doc:para>
This property is deprecated since the code it depends on was removed in 0.99.12
</doc:para>
</doc:description> </doc:description>
</doc:doc> </doc:doc>
</property> </property>
@ -935,6 +942,7 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
</property> </property>
<property name="CapacityLevel" type="s" access="read"> <property name="CapacityLevel" type="s" access="read">
<annotation name="org.freedesktop.DBus.Deprecated" value="true"/>
<doc:doc> <doc:doc>
<doc:description> <doc:description>
<doc:para> <doc:para>
@ -960,6 +968,12 @@ method return sender=:1.386 -> dest=:1.477 reply_serial=2
<doc:term>Full</doc:term> <doc:term>Full</doc:term>
</doc:item> </doc:item>
</doc:list> </doc:list>
<doc:para>
DEPRECATED
</doc:para>
<doc:para>
This property is deprecated since it is duplicated from the 'BatteryLevel' property.
</doc:para>
</doc:description> </doc:description>
</doc:doc> </doc:doc>
</property> </property>

View file

@ -11,6 +11,12 @@
org.freedesktop.UPower.KbdBacklight is a DBus interface implemented org.freedesktop.UPower.KbdBacklight is a DBus interface implemented
by UPower. by UPower.
It allows the keyboard backlight (if present) to be controlled. It allows the keyboard backlight (if present) to be controlled.
The object path "/org/freedesktop/UPower/KbdBacklight" is going to be deprecated in the future.
The new object path is based on this, but the suffix of the path is the device name.
For example:
The interface is: org.freedesktop.UPower.KbdBacklight
The object path will be: /org/freedesktop/UPower/KbdBacklight/tpacpiookbd_backlight
</doc:para> </doc:para>
</doc:description> </doc:description>
</doc:doc> </doc:doc>
@ -78,6 +84,19 @@
</doc:doc> </doc:doc>
</method> </method>
<!-- ************************************************************ -->
<property name="NativePath" type="s" access="read">
<doc:doc>
<doc:description>
<doc:para>
OS specific native path of the keyboard backlight LED device. On Linux this
is the sysfs path, for
example <doc:tt>/sys/devices/platform/thinkpad_acpi/leds/tpacpi\:\:kbd_backlight</doc:tt>.
</doc:para>
</doc:description>
</doc:doc>
</property>
<!-- ************************************************************ --> <!-- ************************************************************ -->
<signal name="BrightnessChanged"> <signal name="BrightnessChanged">
<arg name="value" direction="out" type="i"> <arg name="value" direction="out" type="i">

View file

@ -51,6 +51,21 @@ method return sender=:1.386 -> dest=:1.451 reply_serial=2
</doc:doc> </doc:doc>
</method> </method>
<method name="EnumerateKbdBacklights">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="KbdBacklight" direction="out" type="ao">
<doc:doc><doc:summary>An array of object paths for keyboard backlight LEDs.</doc:summary></doc:doc>
</arg>
<doc:doc>
<doc:description>
<doc:para>
Enumerate all keyboard backlight LED objects on the system.
</doc:para>
</doc:description>
</doc:doc>
</method>
<method name="GetDisplayDevice"> <method name="GetDisplayDevice">
<annotation name="org.freedesktop.DBus.GLib.Async" value=""/> <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
<arg name="device" direction="out" type="o"> <arg name="device" direction="out" type="o">

View file

@ -88,6 +88,15 @@ TimeAction=120
# Default is false # Default is false
AllowRiskyCriticalPowerAction=false AllowRiskyCriticalPowerAction=false
# If the user performs the battery recalibration, the battery behavior
# will be set to "force discharge" and the user expects the battery will
# be fully discharged. However, upower performs the
# CriticalPowerAction earlier than the battery was fully discharged.
# ExpectBatteryRecalibration allows upower to ignore the
# CriticalPowerAction when the user attempts to perform the battery recalibration.
# Default is false
ExpectBatteryRecalibration=false
# The action to take when "TimeAction" or "PercentageAction" above has been # The action to take when "TimeAction" or "PercentageAction" above has been
# reached for the batteries (UPS or laptop batteries) supplying the computer # reached for the batteries (UPS or laptop batteries) supplying the computer
# #
@ -95,10 +104,11 @@ AllowRiskyCriticalPowerAction=false
# PowerOff # PowerOff
# Hibernate # Hibernate
# HybridSleep # HybridSleep
# Auto (The CriticalPowerAction will be determined by the system)
# Suspend (AllowRiskyCriticalPowerAction should be true to use this option but risky) # Suspend (AllowRiskyCriticalPowerAction should be true to use this option but risky)
# Ignore (AllowRiskyCriticalPowerAction should be true to use this option but risky) # Ignore (AllowRiskyCriticalPowerAction should be true to use this option but risky)
# #
# If Suspend isn't available or AllowRiskyCriticalPowerAction=false, HybridSleep will be used # If Suspend isn't available or AllowRiskyCriticalPowerAction=false, HybridSleep will be used
# If HybridSleep isn't available, Hibernate will be used # If HybridSleep isn't available, Hibernate will be used
# If Hibernate isn't available, PowerOff will be used # If Hibernate isn't available, PowerOff will be used
CriticalPowerAction=HybridSleep CriticalPowerAction=Auto

View file

@ -0,0 +1,83 @@
# UPower Configuration Override
The configuration in UPower.conf.d will override the primary configuration
in UPower.conf.
The primary method for overriding settings in the main UPower.conf file is by placing configuration snippets in the `/etc/UPower/UPower.conf.d/` directory.
## The format of filename
For a file to be correctly processed as an override, its filename must adhere to a strict format:
- It must start with a two-digit number between `00` and `99`.
- It must end with the `.conf` extension.
- The middle section can contain `alphanumeric characters`, `dashes`, and `underscores`.
This format is captured by the regular expression `^([0-9][0-9])-([a-zA-Z0-9-_])*\.conf$`.
- The valid examples
```text
01-upower-example.conf
02-upower-test-123.conf
03-upower-1a2b-3c4D__.conf
```
- The invalid examples
```text
0000-upower-abcd1234.conf
001-upower-@bcd.config
```
## The configuration override
UPower processes configuration files in sorted order, where settings in later files override identical settings (matching both Group and Key) from previous files, including the main UPower.conf. This hierarchy ensures that local, numerically-prefixed files in the drop-in directory (UPower.conf.d/) take precedence.
For example, consider `UPower.conf` that contains the defaults:
```text
PercentageLow=20.0
PercentageCritical=5.0
PercentageAction=2.0
```
and there is a file `UPower.conf.d/70-change-percentages.conf`
containing settings for all `Percentage*` keys:
```text
[UPower]
PercentageLow=15.0
PercentageCritical=10.0
PercentageAction=5.0
```
and another `UPower.conf.d/99-change-percentages-local.conf`
containing settings only for `PercentageAction`:
```text
[UPower]
PercentageAction=7.5
```
First the main `UPower.conf` will be processed, then
`UPower.conf.d/70-change-percentages.conf` overriding the defaults
of all percentages from the main config file with the given values,
and finally `UPower.conf.d/99-change-percentages-local.conf`
overriding once again only `PercentageAction`. The final, effective
values are:
```text
PercentageLow=15.0
PercentageCritical=10.0
PercentageAction=7.5
```
## The examples of overriding the default percentage policy values
```text
[UPower]
PercentageLow=25.0
PercentageCritical=10.0
PercentageAction=5.0
```

View file

@ -0,0 +1,5 @@
install_data(
'README.md',
install_tag: 'doc',
install_dir: get_option('sysconfdir') / 'UPower' / 'UPower.conf.d',
)

View file

@ -1 +1,2 @@
subdir('UPower.conf.d')
install_data('UPower.conf', install_dir: get_option('sysconfdir') / 'UPower') install_data('UPower.conf', install_dir: get_option('sysconfdir') / 'UPower')

View file

@ -106,8 +106,6 @@ up_client_get_devices_full (UpClient *client,
GPtrArray *array; GPtrArray *array;
guint i; guint i;
g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
if (up_exported_daemon_call_enumerate_devices_sync (client->priv->proxy, if (up_exported_daemon_call_enumerate_devices_sync (client->priv->proxy,
&devices, &devices,
cancellable, cancellable,
@ -148,6 +146,8 @@ up_client_get_devices2 (UpClient *client)
g_autoptr(GError) error = NULL; g_autoptr(GError) error = NULL;
GPtrArray *ret = NULL; GPtrArray *ret = NULL;
g_return_val_if_fail (UP_IS_CLIENT (client), NULL);
ret = up_client_get_devices_full (client, NULL, &error); ret = up_client_get_devices_full (client, NULL, &error);
if (!ret) { if (!ret) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
@ -192,6 +192,8 @@ up_client_get_devices_async (UpClient *client,
{ {
g_autoptr(GTask) task = NULL; g_autoptr(GTask) task = NULL;
g_return_if_fail (UP_IS_CLIENT (client));
task = g_task_new (client, cancellable, callback, user_data); task = g_task_new (client, cancellable, callback, user_data);
g_task_set_source_tag (task, (gpointer) G_STRFUNC); g_task_set_source_tag (task, (gpointer) G_STRFUNC);
@ -479,7 +481,7 @@ up_client_class_init (UpClientClass *klass)
"If the laptop lid is closed", "If the laptop lid is closed",
NULL, NULL,
FALSE, FALSE,
G_PARAM_READABLE | G_PARAM_DEPRECATED)); G_PARAM_READABLE));
/** /**
* UpClient:lid-is-present: * UpClient:lid-is-present:
* *
@ -493,7 +495,7 @@ up_client_class_init (UpClientClass *klass)
"If a laptop lid is present", "If a laptop lid is present",
NULL, NULL,
FALSE, FALSE,
G_PARAM_READABLE | G_PARAM_DEPRECATED)); G_PARAM_READABLE));
/** /**
* UpClient::device-added: * UpClient::device-added:

View file

@ -94,9 +94,7 @@ GPtrArray *up_client_get_devices_finish (UpClient *client,
GAsyncResult *res, GAsyncResult *res,
GError **error); GError **error);
const gchar *up_client_get_daemon_version (UpClient *client); const gchar *up_client_get_daemon_version (UpClient *client);
G_DEPRECATED
gboolean up_client_get_lid_is_closed (UpClient *client); gboolean up_client_get_lid_is_closed (UpClient *client);
G_DEPRECATED
gboolean up_client_get_lid_is_present (UpClient *client); gboolean up_client_get_lid_is_present (UpClient *client);
gboolean up_client_get_on_battery (UpClient *client); gboolean up_client_get_on_battery (UpClient *client);

View file

@ -349,7 +349,14 @@ up_device_to_text (UpDevice *device)
g_string_append_printf (string, " voltage-min-design: %g V\n", up_exported_device_get_voltage_min_design (priv->proxy_device)); g_string_append_printf (string, " voltage-min-design: %g V\n", up_exported_device_get_voltage_min_design (priv->proxy_device));
if (up_exported_device_get_voltage_max_design (priv->proxy_device) > 0) if (up_exported_device_get_voltage_max_design (priv->proxy_device) > 0)
g_string_append_printf (string, " voltage-max-design: %g V\n", up_exported_device_get_voltage_max_design (priv->proxy_device)); g_string_append_printf (string, " voltage-max-design: %g V\n", up_exported_device_get_voltage_max_design (priv->proxy_device));
/* Eliminate the display of the deprecation warning specific to the CapacityLevel property. */
/* DEPRECATED. This property is deprecated since it is duplicated from the 'BatteryLevel' property. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
capacity_level = up_exported_device_get_capacity_level (priv->proxy_device); capacity_level = up_exported_device_get_capacity_level (priv->proxy_device);
#pragma GCC diagnostic pop
if (capacity_level != NULL && capacity_level[0] != '\0') if (capacity_level != NULL && capacity_level[0] != '\0')
g_string_append_printf (string, " capacity-level: %s\n", capacity_level); g_string_append_printf (string, " capacity-level: %s\n", capacity_level);
} }
@ -369,8 +376,12 @@ up_device_to_text (UpDevice *device)
g_string_append_printf (string, " charge-cycles: %s\n", "N/A"); g_string_append_printf (string, " charge-cycles: %s\n", "N/A");
} }
if (kind == UP_DEVICE_KIND_KEYBOARD) { if (kind == UP_DEVICE_KIND_KEYBOARD) {
/* DEPRECATED. This property is deprecated since the code it depends on was removed in 0.99.12. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
if (up_exported_device_get_luminosity (priv->proxy_device) > 0) if (up_exported_device_get_luminosity (priv->proxy_device) > 0)
g_string_append_printf (string, " luminosity: %g lx\n", up_exported_device_get_luminosity (priv->proxy_device)); g_string_append_printf (string, " luminosity: %g lx\n", up_exported_device_get_luminosity (priv->proxy_device));
#pragma GCC diagnostic pop
} }
if (kind == UP_DEVICE_KIND_BATTERY || if (kind == UP_DEVICE_KIND_BATTERY ||
kind == UP_DEVICE_KIND_UPS) { kind == UP_DEVICE_KIND_UPS) {
@ -419,6 +430,7 @@ up_device_to_text (UpDevice *device)
if (up_exported_device_get_has_history (priv->proxy_device)) { if (up_exported_device_get_has_history (priv->proxy_device)) {
up_device_to_text_history (device, string, "charge"); up_device_to_text_history (device, string, "charge");
up_device_to_text_history (device, string, "rate"); up_device_to_text_history (device, string, "rate");
up_device_to_text_history (device, string, "voltage");
} }
return g_string_free (string, FALSE); return g_string_free (string, FALSE);
@ -450,7 +462,7 @@ up_device_refresh_sync (UpDevice *device, GCancellable *cancellable, GError **er
/** /**
* up_device_get_history_sync: * up_device_get_history_sync:
* @device: a #UpDevice instance. * @device: a #UpDevice instance.
* @type: The type of history, known values are "rate" and "charge". * @type: The type of history. Known values are "rate", "charge" and "voltage".
* @timespec: the amount of time to look back into time. * @timespec: the amount of time to look back into time.
* @resolution: the resolution of data. * @resolution: the resolution of data.
* @cancellable: a #GCancellable or %NULL * @cancellable: a #GCancellable or %NULL
@ -686,7 +698,11 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa
up_exported_device_set_voltage (device->priv->proxy_device, g_value_get_double (value)); up_exported_device_set_voltage (device->priv->proxy_device, g_value_get_double (value));
break; break;
case PROP_LUMINOSITY: case PROP_LUMINOSITY:
/* DEPRECATED. This property is deprecated since the code it depends on was removed in 0.99.12. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
up_exported_device_set_luminosity (device->priv->proxy_device, g_value_get_double (value)); up_exported_device_set_luminosity (device->priv->proxy_device, g_value_get_double (value));
#pragma GCC diagnostic pop
break; break;
case PROP_TIME_TO_EMPTY: case PROP_TIME_TO_EMPTY:
up_exported_device_set_time_to_empty (device->priv->proxy_device, g_value_get_int64 (value)); up_exported_device_set_time_to_empty (device->priv->proxy_device, g_value_get_int64 (value));
@ -733,9 +749,14 @@ up_device_set_property (GObject *object, guint prop_id, const GValue *value, GPa
case PROP_VOLTAGE_MAX_DESIGN: case PROP_VOLTAGE_MAX_DESIGN:
up_exported_device_set_voltage_max_design (device->priv->proxy_device, g_value_get_double (value)); up_exported_device_set_voltage_max_design (device->priv->proxy_device, g_value_get_double (value));
break; break;
/* Eliminate the display of the deprecation warning specific to the CapacityLevel property. */
/* DEPRECATED. This property is deprecated since it is duplicated from the 'BatteryLevel' property. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
case PROP_CAPACITY_LEVEL: case PROP_CAPACITY_LEVEL:
up_exported_device_set_capacity_level (device->priv->proxy_device, g_value_get_string (value)); up_exported_device_set_capacity_level (device->priv->proxy_device, g_value_get_string (value));
break; break;
#pragma GCC diagnostic pop
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -827,7 +848,11 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
g_value_set_double (value, up_exported_device_get_voltage (device->priv->proxy_device)); g_value_set_double (value, up_exported_device_get_voltage (device->priv->proxy_device));
break; break;
case PROP_LUMINOSITY: case PROP_LUMINOSITY:
/* DEPRECATED. This property is deprecated since the code it depends on was removed in 0.99.12. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
g_value_set_double (value, up_exported_device_get_luminosity (device->priv->proxy_device)); g_value_set_double (value, up_exported_device_get_luminosity (device->priv->proxy_device));
#pragma GCC diagnostic pop
break; break;
case PROP_TIME_TO_EMPTY: case PROP_TIME_TO_EMPTY:
g_value_set_int64 (value, up_exported_device_get_time_to_empty (device->priv->proxy_device)); g_value_set_int64 (value, up_exported_device_get_time_to_empty (device->priv->proxy_device));
@ -871,9 +896,14 @@ up_device_get_property (GObject *object, guint prop_id, GValue *value, GParamSpe
case PROP_VOLTAGE_MAX_DESIGN: case PROP_VOLTAGE_MAX_DESIGN:
g_value_set_double (value, up_exported_device_get_voltage_max_design (device->priv->proxy_device)); g_value_set_double (value, up_exported_device_get_voltage_max_design (device->priv->proxy_device));
break; break;
/* Eliminate the display of the deprecation warning specific to the CapacityLevel property. */
/* DEPRECATED. This property is deprecated since it is duplicated from the 'BatteryLevel' property. */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
case PROP_CAPACITY_LEVEL: case PROP_CAPACITY_LEVEL:
g_value_set_string (value, up_exported_device_get_capacity_level (device->priv->proxy_device)); g_value_set_string (value, up_exported_device_get_capacity_level (device->priv->proxy_device));
break; break;
#pragma GCC diagnostic pop
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -1173,13 +1203,16 @@ up_device_class_init (UpDeviceClass *klass)
* *
* The current luminosity of the device. * The current luminosity of the device.
* *
* NOTE: As of 1.91.1, this property is deprecated since the code it
* depends on was removed in 0.99.12.
*
* Since: 0.9.19 * Since: 0.9.19
**/ **/
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_LUMINOSITY, PROP_LUMINOSITY,
g_param_spec_double ("luminosity", NULL, NULL, g_param_spec_double ("luminosity", NULL, NULL,
0.0, G_MAXDOUBLE, 0.0, 0.0, G_MAXDOUBLE, 0.0,
G_PARAM_READWRITE)); G_PARAM_READWRITE | G_PARAM_DEPRECATED));
/** /**
* UpDevice:time-to-empty: * UpDevice:time-to-empty:
* *
@ -1381,12 +1414,15 @@ up_device_class_init (UpDeviceClass *klass)
* Unknown, Critical, Low, Normal, High, and Full. * Unknown, Critical, Low, Normal, High, and Full.
* *
* Since: 1.90.10 * Since: 1.90.10
*
* DEPRECATED.
* This property is deprecated since it is duplicated from the 'BatteryLevel' property.
**/ **/
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_CAPACITY_LEVEL, PROP_CAPACITY_LEVEL,
g_param_spec_string ("capacity-level", g_param_spec_string ("capacity-level",
NULL, NULL, NULL, NULL, NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE | G_PARAM_DEPRECATED));
} }
static void static void

View file

@ -1,5 +1,5 @@
project('upower', 'c', project('upower', 'c',
version: '1.90.10', version: '1.91.2',
license: 'GPLv2+', license: 'GPLv2+',
default_options: [ default_options: [
'buildtype=debugoptimized', 'buildtype=debugoptimized',
@ -10,7 +10,7 @@ project('upower', 'c',
soversion = 3 soversion = 3
current = 1 current = 1
revision = 0 revision = 2
libversion = '@0@.@1@.@2@'.format(soversion, current, revision) libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
gnome = import('gnome') gnome = import('gnome')
@ -30,7 +30,7 @@ cdata.set_quoted('PACKAGE_VERSION', meson.project_version())
cdata.set_quoted('VERSION', meson.project_version()) cdata.set_quoted('VERSION', meson.project_version())
cdata.set_quoted('PACKAGE_SYSCONF_DIR', get_option('sysconfdir')) cdata.set_quoted('PACKAGE_SYSCONF_DIR', get_option('sysconfdir'))
glib_min_version = '2.66' glib_min_version = '2.76'
glib_version_def = 'GLIB_VERSION_@0@_@1@'.format( glib_version_def = 'GLIB_VERSION_@0@_@1@'.format(
glib_min_version.split('.')[0], glib_min_version.split('.')[1]) glib_min_version.split('.')[0], glib_min_version.split('.')[1])

View file

@ -1,10 +1,10 @@
option('man', option('man',
type : 'boolean', type : 'boolean',
value : 'true', value : true,
description : 'Build manpages') description : 'Build manpages')
option('gtk-doc', option('gtk-doc',
type : 'boolean', type : 'boolean',
value : 'true', value : true,
description : 'Build developer documentation') description : 'Build developer documentation')
option('introspection', option('introspection',
type : 'feature', type : 'feature',
@ -44,3 +44,7 @@ option('zshcompletiondir',
type: 'string', type: 'string',
value: '', value: '',
description: 'Directory for zsh completion scripts ["no" disables]') description: 'Directory for zsh completion scripts ["no" disables]')
option('installed_tests',
type : 'boolean',
value : true,
description : 'Install integration tests')

View file

@ -1,3 +1,9 @@
install_data(
'org.freedesktop.upower.rules',
install_tag: 'runtime',
install_dir: join_paths(datadir, 'polkit-1', 'rules.d'),
)
if polkit.found() if polkit.found()
#newer polkit has the ITS rules included #newer polkit has the ITS rules included
if polkit.version().version_compare('>0.113') if polkit.version().version_compare('>0.113')

View file

@ -21,8 +21,8 @@ file are instantly applied.
<icon_name>system-suspend</icon_name> <icon_name>system-suspend</icon_name>
<action id="org.freedesktop.UPower.enable-charging-limit"> <action id="org.freedesktop.UPower.enable-charging-limit">
<_description>Enable battery charging limit</_description> <description>Enable battery charging limit</description>
<_message>Authentication is required to set battery charging start and end limit.</_message> <message>Authentication is required to set battery charging start and end limit.</message>
<defaults> <defaults>
<allow_inactive>no</allow_inactive> <allow_inactive>no</allow_inactive>
<allow_active>yes</allow_active> <allow_active>yes</allow_active>

View file

@ -0,0 +1,31 @@
/*
* Copyright (C) 2026 Kate Hsuan <hpa@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
polkit.addRule(function(action, subject) {
if ((action.id == "org.freedesktop.login1.power-off-ignore-inhibit" ||
action.id == "org.freedesktop.login1.reboot-ignore-inhibit" ||
action.id == "org.freedesktop.login1.halt-ignore-inhibit" ||
action.id == "org.freedesktop.login1.suspend-ignore-inhibit" ||
action.id == "org.freedesktop.login1.hibernate-ignore-inhibit") &&
subject.user == "root") {
return polkit.Result.YES;
}
});

View file

@ -4,4 +4,8 @@ SUBSYSTEM=="power_supply", ATTR{charge_control_start_threshold}!="", \
IMPORT{builtin}="hwdb 'battery:$kernel:$attr{model_name}:$attr{[dmi/id]modalias}'", \ IMPORT{builtin}="hwdb 'battery:$kernel:$attr{model_name}:$attr{[dmi/id]modalias}'", \
GOTO="battery_end" GOTO="battery_end"
SUBSYSTEM=="power_supply", ATTR{charge_control_end_threshold}!="", \
IMPORT{builtin}="hwdb 'battery:$kernel:$attr{model_name}:$attr{[dmi/id]modalias}'", \
GOTO="battery_end"
LABEL="battery_end" LABEL="battery_end"

View file

@ -72,6 +72,7 @@ usb:v051Dp0000*
usb:v051Dp0002* usb:v051Dp0002*
usb:v051Dp0003* usb:v051Dp0003*
usb:v051Dp0004* usb:v051Dp0004*
usb:v051Dp0005*
UPOWER_BATTERY_TYPE=ups UPOWER_BATTERY_TYPE=ups
UPOWER_VENDOR=APC UPOWER_VENDOR=APC
@ -92,10 +93,10 @@ usb:v06DApFFFF*
UPOWER_BATTERY_TYPE=ups UPOWER_BATTERY_TYPE=ups
UPOWER_VENDOR=Phoenixtec Power Co., Ltd UPOWER_VENDOR=Phoenixtec Power Co., Ltd
# iDowell # iDowell, Goldenmate
usb:v075Dp0300* usb:v075Dp0300*
UPOWER_BATTERY_TYPE=ups UPOWER_BATTERY_TYPE=ups
UPOWER_VENDOR=iDowell UPOWER_VENDOR=iDowell, Goldenmate
# Cyber Power Systems # Cyber Power Systems
usb:v0764p0005* usb:v0764p0005*

View file

@ -353,6 +353,45 @@ class Tests(dbusmock.DBusTestCase):
None, None,
) )
def get_kbd_backlight_brightness(self, kbd_backlight):
return self.dbus.call_sync(
UP,
kbd_backlight,
"org.freedesktop.UPower.KbdBacklight",
"GetBrightness",
None,
None,
Gio.DBusCallFlags.NO_AUTO_START,
-1,
None,
).unpack()[0]
def get_kbd_backlight_max_brightness(self, kbd_backlight):
return self.dbus.call_sync(
UP,
kbd_backlight,
"org.freedesktop.UPower.KbdBacklight",
"GetMaxBrightness",
None,
None,
Gio.DBusCallFlags.NO_AUTO_START,
-1,
None,
).unpack()[0]
def set_kbd_backlight_brightness(self, kbd_backlight, brightness):
self.dbus.call_sync(
UP,
kbd_backlight,
"org.freedesktop.UPower.KbdBacklight",
"SetBrightness",
GLib.Variant("(i)", (brightness,)),
None,
Gio.DBusCallFlags.NO_AUTO_START,
-1,
None,
)
def assertDevs(self, expected): def assertDevs(self, expected):
devs = self.proxy.EnumerateDevices() devs = self.proxy.EnumerateDevices()
names = sorted(n.split("/")[-1] for n in devs) names = sorted(n.split("/")[-1] for n in devs)
@ -699,6 +738,42 @@ class Tests(dbusmock.DBusTestCase):
) )
self.stop_daemon() self.stop_daemon()
def test_nan_percentage_battery_capacity(self):
"""ACPI returns NaN for capacity"""
self.testbed.add_device(
"power_supply",
"BAT0",
None,
[
"type",
"Battery",
"present",
"1",
"status",
"Discharging",
"capacity",
"-NaN",
"energy_full",
"60000000",
"energy_full_design",
"80000000",
"voltage_now",
"12000000",
],
[],
)
self.start_daemon()
devs = self.proxy.EnumerateDevices()
self.assertEqual(len(devs), 1)
bat0_up = devs[0]
self.assertEqual(self.get_dbus_dev_property(bat0_up, "Percentage"), 0.0)
# don't assert if nan percentage is reported
self.stop_daemon()
def test_multiple_batteries(self): def test_multiple_batteries(self):
"""Multiple batteries""" """Multiple batteries"""
@ -2289,10 +2364,10 @@ class Tests(dbusmock.DBusTestCase):
with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp: with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp:
self.assertEqual(fp.read(), "Standard") self.assertEqual(fp.read(), "Standard")
# Battery 2 switches to "Fast" # Battery 2 switches to "Standard"
battery_name = bat2_up.split("_")[-1] battery_name = bat2_up.split("_")[-1]
with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp: with open(f"/sys/class/power_supply/{battery_name}/charge_types") as fp:
self.assertEqual(fp.read(), "Fast") self.assertEqual(fp.read(), "Standard")
def test_battery_charge_limit_multiple_batteries_get_charge_threshold_settings_supported( def test_battery_charge_limit_multiple_batteries_get_charge_threshold_settings_supported(
self, self,
@ -3472,6 +3547,106 @@ class Tests(dbusmock.DBusTestCase):
os.unlink(config.name) os.unlink(config.name)
def test_critical_action_is_ignored_when_performing_battery_recalibration(self):
"""check that critical action is ignored when performing battery recalibration"""
ac0 = self.testbed.add_device(
"power_supply",
"AC0",
None,
["type", "Mains", "online", "1"],
[],
)
bat0 = self.testbed.add_device(
"power_supply",
"BAT0",
None,
[
"type",
"Battery",
"present",
"1",
"status",
"Discharging",
"energy_full",
"60000000",
"energy_full_design",
"80000000",
"energy_now",
"50000000",
"voltage_now",
"12000000",
"charge_behaviour",
"[auto] inhibit-charge force-discharge",
],
[],
)
config = tempfile.NamedTemporaryFile(delete=False, mode="w")
config.write("[UPower]\n")
config.write("UsePercentageForPolicy=true\n")
config.write("PercentageAction=5\n")
config.write("AllowRiskyCriticalPowerAction=true\n")
config.write("ExpectBatteryRecalibration=true\n")
config.close()
self.start_daemon(cfgfile=config.name, warns=True)
devs = self.proxy.EnumerateDevices()
self.assertEqual(len(devs), 2)
bat0_up = devs[1]
# check warning message when CriticalPowerAction=Suspend and AllowRiskyCriticalPowerAction=true
self.daemon_log.check_line(
'The "ExpectBatteryRecalibration" setting is considered risky:'
" abrupt power loss due to battery exhaustion may lead to data"
" corruption. The system will unexpected down when the AC is disconnected."
" Use AllowRiskyCriticalPowerAction=false to disable support for"
" risky settings.",
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
# simulate that battery has 0%
self.testbed.set_attribute(
bat0, "charge_behaviour", "auto inhibit-charge [force-discharge]"
)
self.testbed.set_attribute(bat0, "energy_now", "0")
self.testbed.uevent(bat0, "change")
time.sleep(0.5)
self.assertEqual(
self.get_dbus_display_property("WarningLevel"), UP_DEVICE_LEVEL_NONE
)
self.daemon_log.check_line(
"ExpectBatteryRecalibration is enabled and the AC is connected, so the battery level is not critical",
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.testbed.set_attribute(bat0, "status", "Not charging")
self.testbed.uevent(bat0, "change")
self.daemon_log.check_line(
"ExpectBatteryRecalibration is enabled and the AC is connected, so the battery level is not critical",
timeout=UP_DAEMON_ACTION_DELAY + 1.0,
)
self.testbed.set_attribute(
bat0, "charge_behaviour", "[auto] inhibit-charge force-discharge"
)
self.testbed.set_attribute(bat0, "energy_now", "800000")
self.testbed.set_attribute(bat0, "status", "Charging")
self.testbed.uevent(bat0, "change")
time.sleep(0.5)
self.assertEqual(
self.get_dbus_display_property("WarningLevel"), UP_DEVICE_LEVEL_NONE
)
self.stop_daemon()
os.unlink(config.name)
def test_low_battery_changes_history_save_interval(self): def test_low_battery_changes_history_save_interval(self):
"""check that we save the history more quickly on low battery""" """check that we save the history more quickly on low battery"""
@ -5728,6 +5903,97 @@ class Tests(dbusmock.DBusTestCase):
self.stop_daemon() self.stop_daemon()
#
# Single Keyboard backlight test
#
def test_single_kbd_backlight(self):
"""Set One Keyboard backlight"""
kbd0 = self.testbed.add_device(
"leds",
"tpacpi::kbd_backlight",
None,
[
"max_brightness",
"2",
"brightness",
"1",
],
[],
)
self.start_daemon()
kbds = self.proxy.EnumerateKbdBacklights()
self.assertEqual(len(kbds), 1)
kbd0_up = kbds[0]
self.assertEqual(self.get_kbd_backlight_brightness(kbd0_up), 1)
self.assertEqual(self.get_kbd_backlight_max_brightness(kbd0_up), 2)
# brightness is in the range 0 to max_brightness
self.set_kbd_backlight_brightness(kbd0_up, 0)
with open(f"/sys/class/leds/tpacpi::kbd_backlight/brightness") as fp:
self.assertEqual(fp.read(), "0")
# value is greater than max_brightness
self.set_kbd_backlight_brightness(kbd0_up, 200)
with open(f"/sys/class/leds/tpacpi::kbd_backlight/brightness") as fp:
self.assertEqual(fp.read(), "2")
self.stop_daemon()
#
# Two Keyboard backlight test
#
def test_two_kbd_backlight(self):
"""Set Two Keyboard backlight"""
kbd0 = self.testbed.add_device(
"leds",
"tpacpi::kbd_backlight",
None,
[
"max_brightness",
"2",
"brightness",
"1",
],
[],
)
kbd1 = self.testbed.add_device(
"leds",
"Katecatacpi::kbd_backlight",
None,
[
"max_brightness",
"255",
"brightness",
"100",
],
[],
)
self.start_daemon()
kbds = self.proxy.EnumerateKbdBacklights()
self.assertEqual(len(kbds), 2)
kbd0_up = kbds[0]
kbd1_up = kbds[1]
self.assertEqual(self.get_kbd_backlight_brightness(kbd0_up), 100)
self.assertEqual(self.get_kbd_backlight_max_brightness(kbd0_up), 255)
self.set_kbd_backlight_brightness(kbd0_up, 200)
with open(f"/sys/class/leds/Katecatacpi::kbd_backlight/brightness") as fp:
self.assertEqual(fp.read(), "200")
self.assertEqual(self.get_kbd_backlight_brightness(kbd1_up), 1)
self.assertEqual(self.get_kbd_backlight_max_brightness(kbd1_up), 2)
self.set_kbd_backlight_brightness(kbd1_up, 0)
with open(f"/sys/class/leds/tpacpi::kbd_backlight/brightness") as fp:
self.assertEqual(fp.read(), "0")
self.stop_daemon()
# #
# libupower-glib tests (through introspection) # libupower-glib tests (through introspection)
# #
@ -5774,6 +6040,144 @@ class Tests(dbusmock.DBusTestCase):
# client.get_devices_async(None, get_devices_cb) # client.get_devices_async(None, get_devices_cb)
# ml.run() # ml.run()
def test_conf_d_support(self):
"""Ensure support for conf.d style directories"""
base_dir = tempfile.TemporaryDirectory(delete=False, prefix="UPower-")
conf_d_dir_path = os.path.join(base_dir.name, "UPower.conf.d")
# Low, Critical and Action are all needed to avoid fallback to defaults
config = tempfile.NamedTemporaryFile(
delete=False, mode="w", dir=base_dir.name, suffix=".conf"
)
config.write("[UPower]\n")
config.write("PercentageLow=20.0\n")
config.write("PercentageCritical=3.0\n")
config.write("PercentageAction=2.0\n")
config.write("AllowRiskyCriticalPowerAction=false\n")
config.write("CriticalPowerAction=HybridSleep\n")
config.close()
# UPower.conf.d directory does not exist
self.start_daemon(cfgfile=config.name)
self.daemon_log.check_line(
"failed to find files in 'UPower.conf.d': Error opening directory",
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.stop_daemon()
# empty UPower.conf.d directory
conf_d_dir = os.mkdir(path=conf_d_dir_path)
self.start_daemon(cfgfile=config.name)
self.stop_daemon()
# override config (in a UPower.conf.d/10-*.conf file)
config2 = tempfile.NamedTemporaryFile(
delete=False, mode="w", dir=conf_d_dir_path, prefix="10-", suffix=".conf"
)
config2.write("[UPower]\n")
config2.write("AllowRiskyCriticalPowerAction=true\n")
config2.write("CriticalPowerAction=Suspend\n")
config2.close()
# check warning message when CriticalPowerAction=Suspend and
# AllowRiskyCriticalPowerAction=true, meaning that support of
# UPower.conf.d dir is working
self.start_daemon(cfgfile=config.name, warns=True)
self.daemon_log.check_line(
'The "Suspend" CriticalPowerAction setting is considered risky:',
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.stop_daemon()
# override config (in a UPower.conf.d/90-*.conf file)
config3 = tempfile.NamedTemporaryFile(
delete=False, mode="w", dir=conf_d_dir_path, prefix="90-", suffix=".conf"
)
config3.write("[UPower]\n")
config3.write("CriticalPowerAction=Ignore\n")
config3.close()
# check warning message when CriticalPowerAction=Ignore and
# AllowRiskyCriticalPowerAction=true, meaning that support of
# UPower.conf.d dir is working
self.start_daemon(cfgfile=config.name, warns=True)
self.daemon_log.check_line(
'The "Ignore" CriticalPowerAction setting is considered risky:',
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.stop_daemon()
# config with invalid name 99-*.conf~ file (not actually overriding)
config_inv1 = tempfile.NamedTemporaryFile(
delete=False, mode="w", dir=conf_d_dir_path, prefix="99-", suffix=".conf~"
)
config_inv1.write("[UPower]\n")
config_inv1.write("CriticalPowerAction=HybridSleep\n")
config_inv1.close()
# check warning message when CriticalPowerAction=Ignore and
# AllowRiskyCriticalPowerAction=true, because the config file
# (config_inv1) setting it to the safe 'HybridSleep' is not activated
# due to wrong name
self.start_daemon(cfgfile=config.name, warns=True)
self.daemon_log.check_line(
'The "Ignore" CriticalPowerAction setting is considered risky:',
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.stop_daemon()
# config with invalid name 999-*.conf file (not actually overriding)
config_inv2 = tempfile.NamedTemporaryFile(
delete=False, mode="w", dir=conf_d_dir_path, prefix="999-", suffix=".conf"
)
config_inv2.write("[UPower]\n")
config_inv2.write("CriticalPowerAction=HybridSleep\n")
config_inv2.close()
# check warning message when CriticalPowerAction=Ignore and
# AllowRiskyCriticalPowerAction=true, because the config files
# (config_inv1 and config_inv2) setting it to the safe 'HybridSleep' are
# not activated due to wrong names
self.start_daemon(cfgfile=config.name, warns=True)
self.daemon_log.check_line(
'The "Ignore" CriticalPowerAction setting is considered risky:',
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.stop_daemon()
# config with invalid name 99-badname+*.conf file (not actually overriding)
config_inv3 = tempfile.NamedTemporaryFile(
delete=False,
mode="w",
dir=conf_d_dir_path,
prefix="99-badname+",
suffix=".conf",
)
config_inv3.write("[UPower]\n")
config_inv3.write("CriticalPowerAction=HybridSleep\n")
config_inv3.close()
# check warning message when CriticalPowerAction=Ignore and
# AllowRiskyCriticalPowerAction=true, because the config files
# (config_inv1, 2 and 3) setting it to the safe 'HybridSleep' are not
# activated due to wrong names
self.start_daemon(cfgfile=config.name, warns=True)
self.daemon_log.check_line(
'The "Ignore" CriticalPowerAction setting is considered risky:',
timeout=UP_DAEMON_ACTION_DELAY + 0.5,
)
self.stop_daemon()
os.unlink(config_inv3.name)
os.unlink(config_inv2.name)
os.unlink(config_inv1.name)
os.unlink(config3.name)
os.unlink(config2.name)
os.unlink(config.name)
os.rmdir(conf_d_dir_path)
os.rmdir(base_dir.name)
# #
# Helper methods # Helper methods
# #

View file

@ -18,6 +18,8 @@ upshared += { 'linux': static_library('upshared',
'up-device-wup.h', 'up-device-wup.h',
'up-device-bluez.c', 'up-device-bluez.c',
'up-device-bluez.h', 'up-device-bluez.h',
'up-kbd-backlight-led.c',
'up-kbd-backlight-led.h',
'up-input.c', 'up-input.c',
'up-input.h', 'up-input.h',
'up-backend.c', 'up-backend.c',

View file

@ -33,6 +33,7 @@
#include "up-backend.h" #include "up-backend.h"
#include "up-daemon.h" #include "up-daemon.h"
#include "up-device.h" #include "up-device.h"
#include "up-device-kbd-backlight.h"
#include "up-enumerator-udev.h" #include "up-enumerator-udev.h"
@ -421,9 +422,13 @@ up_device_disconnected_cb (GObject *gobject,
NULL); NULL);
if (disconnected) { if (disconnected) {
g_debug("Device %s became disconnected, hiding device", path); g_debug("Device %s became disconnected, hiding device", path);
if (up_device_is_registered (UP_DEVICE (gobject))) { if (UP_IS_DEVICE (gobject)) {
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, gobject); if (up_device_is_registered (UP_DEVICE (gobject))) {
up_device_unregister (UP_DEVICE (gobject)); g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, gobject);
up_device_unregister (UP_DEVICE (gobject));
}
} else if (UP_IS_DEVICE_KBD_BACKLIGHT (gobject)) {
up_device_kbd_backlight_unregister (UP_DEVICE_KBD_BACKLIGHT (gobject));
} }
} else { } else {
g_debug ("Device %s became connected, showing device", path); g_debug ("Device %s became connected, showing device", path);
@ -433,20 +438,28 @@ up_device_disconnected_cb (GObject *gobject,
} }
static void static void
udev_device_added_cb (UpBackend *backend, UpDevice *device) udev_device_added_cb (UpBackend *backend, GObject *device)
{ {
g_debug ("Got new device from udev enumerator: %p", device); g_debug ("Got new device from udev enumerator: %p", device);
g_signal_connect (device, "notify::disconnected", g_signal_connect (device, "notify::disconnected",
G_CALLBACK (up_device_disconnected_cb), backend); G_CALLBACK (up_device_disconnected_cb), backend);
if (update_added_duplicate_device (backend, device)) if (UP_IS_DEVICE (device)) {
if (update_added_duplicate_device (backend, UP_DEVICE (device)))
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
} else if (UP_IS_DEVICE_KBD_BACKLIGHT (device)) {
g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device); g_signal_emit (backend, signals[SIGNAL_DEVICE_ADDED], 0, device);
} else {
g_warning ("Unknown device type");
}
} }
static void static void
udev_device_removed_cb (UpBackend *backend, UpDevice *device) udev_device_removed_cb (UpBackend *backend, GObject *device)
{ {
g_debug ("Removing device from udev enumerator: %p", device); g_debug ("Removing device from udev enumerator: %p", device);
update_removed_duplicate_device (backend, device);
if (UP_IS_DEVICE (device))
update_removed_duplicate_device (backend, UP_DEVICE (device));
g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, device); g_signal_emit (backend, signals[SIGNAL_DEVICE_REMOVED], 0, device);
} }
@ -553,10 +566,15 @@ up_backend_get_critical_action (UpBackend *backend)
const gchar *method; const gchar *method;
const gchar *can_method; const gchar *can_method;
} actions[] = { } actions[] = {
/*
* The fallback order is
* Suspend -> HybridSleep -> Hibernate -> PowerOff -> Sleep -> Ignore
*/
{ "Suspend", "CanSuspend" }, { "Suspend", "CanSuspend" },
{ "HybridSleep", "CanHybridSleep" }, { "HybridSleep", "CanHybridSleep" },
{ "Hibernate", "CanHibernate" }, { "Hibernate", "CanHibernate" },
{ "PowerOff", NULL }, { "PowerOff", "CanPowerOff" },
{ "Sleep", "CanSleep"},
{ "Ignore", NULL }, { "Ignore", NULL },
}; };
g_autofree gchar *action = NULL; g_autofree gchar *action = NULL;
@ -579,6 +597,12 @@ up_backend_get_critical_action (UpBackend *backend)
} }
} }
/* if "Auto", use "Sleep()" */
if (!g_strcmp0 (action, "Auto")) {
g_free (action);
action = g_strdup_printf ("Sleep");
}
if (action != NULL) { if (action != NULL) {
for (i = 0; i < G_N_ELEMENTS (actions); i++) for (i = 0; i < G_N_ELEMENTS (actions); i++)
if (g_str_equal (actions[i].method, action)) if (g_str_equal (actions[i].method, action))
@ -620,6 +644,9 @@ up_backend_get_critical_action (UpBackend *backend)
void void
up_backend_take_action (UpBackend *backend) up_backend_take_action (UpBackend *backend)
{ {
GVariant *res = NULL;
g_autoptr (GError) error = NULL;
g_autofree gchar *action = NULL;
const char *method; const char *method;
method = up_backend_get_critical_action (backend); method = up_backend_get_critical_action (backend);
@ -633,14 +660,43 @@ up_backend_take_action (UpBackend *backend)
return; return;
} }
g_dbus_proxy_call (backend->priv->logind_proxy, if (!g_strcmp0 (method, "Sleep"))
method, action = g_strdup ("Sleep");
g_variant_new ("(b)", FALSE), else
G_DBUS_CALL_FLAGS_NONE, action = g_strdup_printf ("%sWithFlags", method);
G_MAXINT,
NULL, /* flag 16 is SD_LOGIND_SKIP_INHIBITORS */
NULL, res = g_dbus_proxy_call_sync (backend->priv->logind_proxy,
NULL); action,
g_variant_new ("(t)", 16),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
/* if the new API doesn't work, use old one */
if (error != NULL) {
g_autofree gchar *action_old = NULL;
g_debug ("The new power action API doesn't work, using old one.");
if (!g_strcmp0 (method, "Sleep")) {
/* Sleep() is not available, so PowerOff instead */
g_debug ("Sleep() is not available, using PowerOff instead");
action_old = g_strdup ("PowerOff");
} else {
action_old = g_strdup (method);
}
g_dbus_proxy_call (backend->priv->logind_proxy,
action_old,
g_variant_new ("(b)", FALSE),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
NULL,
NULL);
}
if (res != NULL)
g_variant_unref (res);
} }
/** /**
@ -775,13 +831,13 @@ up_backend_class_init (UpBackendClass *klass)
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_added), G_STRUCT_OFFSET (UpBackendClass, device_added),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 1, UP_TYPE_DEVICE); G_TYPE_NONE, 1, G_TYPE_OBJECT);
signals [SIGNAL_DEVICE_REMOVED] = signals [SIGNAL_DEVICE_REMOVED] =
g_signal_new ("device-removed", g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (UpBackendClass, device_removed), G_STRUCT_OFFSET (UpBackendClass, device_removed),
NULL, NULL, NULL, NULL, NULL, NULL,
G_TYPE_NONE, 1, UP_TYPE_DEVICE); G_TYPE_NONE, 1, G_TYPE_OBJECT);
} }
static void static void

View file

@ -302,12 +302,12 @@ up_device_battery_charge_find_available_charge_types_for_charging (UpDevice *dev
UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device); UpDeviceSupplyBattery *self = UP_DEVICE_SUPPLY_BATTERY (device);
UpDeviceSupplyBatteryChargeTypes charge_types = self->supported_charge_types; UpDeviceSupplyBatteryChargeTypes charge_types = self->supported_charge_types;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD) if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD; return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_STANDARD;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_FAST;
if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE) if (charge_types & UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE)
return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE; return UP_DEVICE_SUPPLY_BATTERY_CHARGE_TYPES_ADAPTIVE;
@ -513,6 +513,8 @@ up_device_supply_battery_refresh (UpDevice *device,
if (!self->ignore_system_percentage) { if (!self->ignore_system_percentage) {
values.percentage = g_udev_device_get_sysfs_attr_as_double_uncached (native, "capacity"); values.percentage = g_udev_device_get_sysfs_attr_as_double_uncached (native, "capacity");
if (isnan (values.percentage))
values.percentage = 0.0f;
values.percentage = CLAMP(values.percentage, 0.0f, 100.0f); values.percentage = CLAMP(values.percentage, 0.0f, 100.0f);
} }
@ -711,9 +713,8 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
if (start != G_MAXUINT) { if (start != G_MAXUINT) {
g_string_printf (start_str, "%d", CLAMP (start, 0, 100)); g_string_printf (start_str, "%d", CLAMP (start, 0, 100));
if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len, if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) { G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL))
err_count++; err_count++;
}
} else { } else {
g_debug ("Ignore charge_control_start_threshold setting"); g_debug ("Ignore charge_control_start_threshold setting");
} }
@ -721,9 +722,8 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s
if (end != G_MAXUINT) { if (end != G_MAXUINT) {
g_string_printf (end_str, "%d", CLAMP (end, 0, 100)); g_string_printf (end_str, "%d", CLAMP (end, 0, 100));
if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len, if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) { G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL))
err_count++; err_count++;
}
} else { } else {
g_debug ("Ignore charge_control_end_threshold setting"); g_debug ("Ignore charge_control_end_threshold setting");
} }

View file

@ -331,7 +331,9 @@ static void
up_device_supply_sibling_discovered_guess_type (UpDevice *device, up_device_supply_sibling_discovered_guess_type (UpDevice *device,
GObject *sibling) GObject *sibling)
{ {
GUdevDevice *input, *native_device, *parent_device, *parent_sibling; GUdevDevice *input, *native_device;
g_autoptr (GUdevDevice) parent_device = NULL;
g_autoptr (GUdevDevice) parent_sibling = NULL;
UpDeviceKind cur_type, new_type; UpDeviceKind cur_type, new_type;
gboolean is_same_parent = FALSE; gboolean is_same_parent = FALSE;
char *new_model_name; char *new_model_name;
@ -492,9 +494,10 @@ up_device_supply_sibling_discovered_guess_type (UpDevice *device,
"type", new_type, "type", new_type,
"model", new_model_name, "model", new_model_name,
NULL); NULL);
g_free (new_model_name); } else {
} else
g_object_set (device, "type", new_type, NULL); g_object_set (device, "type", new_type, NULL);
}
g_free (new_model_name);
} }
} }

View file

@ -31,6 +31,7 @@
#include "up-device-supply-battery.h" #include "up-device-supply-battery.h"
#include "up-device-hid.h" #include "up-device-hid.h"
#include "up-device-wup.h" #include "up-device-wup.h"
#include "up-kbd-backlight-led.h"
#ifdef HAVE_IDEVICE #ifdef HAVE_IDEVICE
#include "up-device-idevice.h" #include "up-device-idevice.h"
#endif /* HAVE_IDEVICE */ #endif /* HAVE_IDEVICE */
@ -216,13 +217,102 @@ emit_changes_for_siblings (UpEnumeratorUdev *self,
} }
} }
static void
power_supply_add_helper (UpEnumeratorUdev *self,
const gchar *action,
GUdevDevice *device,
GUdevClient *client,
GObject *obj,
const gchar *device_key)
{
g_autoptr(UpDevice) up_dev = NULL;
g_autofree char *parent_id = NULL;
up_dev = device_new (self, device);
/* We work with `obj` further down, which is the UpDevice
* if we have it, or the GUdevDevice if not. */
if (up_dev)
obj = G_OBJECT (up_dev);
else
obj = G_OBJECT (device);
g_hash_table_insert (self->known, (char*) device_key, g_object_ref (obj));
/* Fire relevant sibling events and insert into lookup table */
parent_id = device_parent_id (device);
g_debug ("device %s has parent id: %s", device_key, parent_id);
if (parent_id) {
GPtrArray *devices = NULL;
char *parent_id_key = NULL;
int i;
g_hash_table_lookup_extended (self->siblings, parent_id,
(gpointer*)&parent_id_key, (gpointer*)&devices);
if (!devices)
devices = g_ptr_array_new_with_free_func (g_object_unref);
for (i = 0; i < devices->len; i++) {
GObject *sibling = g_ptr_array_index (devices, i);
if (up_dev) {
g_autoptr(GUdevDevice) d = get_latest_udev_device (self, sibling);
if (d)
up_device_sibling_discovered (up_dev, G_OBJECT (d));
}
if (UP_IS_DEVICE (sibling))
up_device_sibling_discovered (UP_DEVICE (sibling), obj);
}
g_ptr_array_add (devices, g_object_ref (obj));
if (!parent_id_key) {
parent_id_key = g_strdup (parent_id);
g_hash_table_insert (self->siblings, parent_id_key, devices);
}
/* Just a reference to the hash table key */
g_object_set_data (obj, "udev-parent-id", parent_id_key);
}
if (up_dev)
g_signal_emit_by_name (self, "device-added", up_dev);
}
static void
kbd_backlight_add_helper (UpEnumeratorUdev *self,
const gchar *action,
GUdevDevice *device,
GUdevClient *client,
GObject *obj,
const char *device_key)
{
UpDaemon *daemon;
g_autoptr(UpDeviceKbdBacklight) up_kbd = NULL;
g_autofree char *parent_id = NULL;
daemon = up_enumerator_get_daemon (UP_ENUMERATOR (self));
up_kbd = g_initable_new (UP_TYPE_KBD_BACKLIGHT_LED, NULL, NULL,
"daemon", daemon,
"native", device,
NULL);
if (up_kbd)
obj = G_OBJECT (up_kbd);
else
obj = G_OBJECT (device);
g_hash_table_insert (self->known, (char*) device_key, g_object_ref (obj));
if (up_kbd)
g_signal_emit_by_name (self, "device-added", G_OBJECT (up_kbd));
}
static void static void
uevent_signal_handler_cb (UpEnumeratorUdev *self, uevent_signal_handler_cb (UpEnumeratorUdev *self,
const gchar *action, const gchar *action,
GUdevDevice *device, GUdevDevice *device,
GUdevClient *client) GUdevClient *client)
{ {
const char *device_key = g_udev_device_get_sysfs_path (device); const char *device_key = g_udev_device_get_sysfs_path (device);
gboolean is_kbd_backlight = FALSE;
g_debug ("Received uevent %s on device %s", action, device_key); g_debug ("Received uevent %s on device %s", action, device_key);
@ -230,6 +320,19 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self,
if (g_strcmp0 (g_udev_device_get_subsystem (device), "power_supply") == 0) if (g_strcmp0 (g_udev_device_get_subsystem (device), "power_supply") == 0)
device_key = g_udev_device_get_name (device); device_key = g_udev_device_get_name (device);
/* Consider both 'kbd_backlight' and 'lp5523:kb' as keyboard backlight
* devices. See include/dt-bindings/leds/common.h. 'lp5523:kb' is still
* in use, despite being marked as obsolete/legacy.
*/
if (g_strcmp0 (g_udev_device_get_subsystem (device), "leds") == 0) {
if (g_strrstr (device_key, "kbd_backlight") == NULL &&
g_strrstr (device_key, "lp5523:kb") == NULL)
return;
is_kbd_backlight = TRUE;
}
g_debug ("uevent subsystem %s", g_udev_device_get_subsystem (device));
/* It appears that we may not always receive an "add" event. As such, /* It appears that we may not always receive an "add" event. As such,
* treat "add"/"change" in the same way, by first checking if we have * treat "add"/"change" in the same way, by first checking if we have
* seen the device. * seen the device.
@ -250,56 +353,10 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self,
} }
if (!obj) { if (!obj) {
g_autoptr(UpDevice) up_dev = NULL; if (is_kbd_backlight)
g_autofree char *parent_id = NULL; kbd_backlight_add_helper (self, action, device, client, obj, device_key);
up_dev = device_new (self, device);
/* We work with `obj` further down, which is the UpDevice
* if we have it, or the GUdevDevice if not. */
if (up_dev)
obj = G_OBJECT (up_dev);
else else
obj = G_OBJECT (device); power_supply_add_helper (self, action, device, client, obj, device_key);
g_hash_table_insert (self->known, (char*) device_key, g_object_ref (obj));
/* Fire relevant sibling events and insert into lookup table */
parent_id = device_parent_id (device);
g_debug ("device %s has parent id: %s", device_key, parent_id);
if (parent_id) {
GPtrArray *devices = NULL;
char *parent_id_key = NULL;
int i;
g_hash_table_lookup_extended (self->siblings, parent_id,
(gpointer*)&parent_id_key, (gpointer*)&devices);
if (!devices)
devices = g_ptr_array_new_with_free_func (g_object_unref);
for (i = 0; i < devices->len; i++) {
GObject *sibling = g_ptr_array_index (devices, i);
if (up_dev) {
g_autoptr(GUdevDevice) d = get_latest_udev_device (self, sibling);
if (d)
up_device_sibling_discovered (up_dev, G_OBJECT (d));
}
if (UP_IS_DEVICE (sibling))
up_device_sibling_discovered (UP_DEVICE (sibling), obj);
}
g_ptr_array_add (devices, g_object_ref (obj));
if (!parent_id_key) {
parent_id_key = g_strdup (parent_id);
g_hash_table_insert (self->siblings, parent_id_key, devices);
}
/* Just a reference to the hash table key */
g_object_set_data (obj, "udev-parent-id", parent_id_key);
}
if (up_dev)
g_signal_emit_by_name (self, "device-added", up_dev);
} else { } else {
if (!UP_IS_DEVICE (obj)) { if (!UP_IS_DEVICE (obj)) {
@ -326,6 +383,11 @@ uevent_signal_handler_cb (UpEnumeratorUdev *self,
g_debug ("removing device for path %s", g_udev_device_get_sysfs_path (device)); g_debug ("removing device for path %s", g_udev_device_get_sysfs_path (device));
if (is_kbd_backlight) {
g_signal_emit_by_name (self, "device-removed", obj);
return;
}
parent_id = g_object_get_data (obj, "udev-parent-id"); parent_id = g_object_get_data (obj, "udev-parent-id");
/* Remove from siblings table. */ /* Remove from siblings table. */
@ -367,8 +429,8 @@ up_enumerator_udev_initable_init (UpEnumerator *enumerator)
guint i; guint i;
const gchar **subsystems; const gchar **subsystems;
/* List "input" first just to avoid some sibling hotplugging later */ /* List "input" first just to avoid some sibling hotplugging later */
const gchar *subsystems_no_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", NULL}; const gchar *subsystems_no_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", "leds", NULL};
const gchar *subsystems_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", "tty", NULL}; const gchar *subsystems_wup[] = {"input", "power_supply", "usb", "usbmisc", "sound", "tty", "leds", NULL};
config = up_config_new (); config = up_config_new ();
if (up_config_get_boolean (config, "EnableWattsUpPro")) if (up_config_get_boolean (config, "EnableWattsUpPro"))

View file

@ -0,0 +1,323 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <glib.h>
#include <glib/gi18n.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include "up-kbd-backlight-led.h"
#include "up-native.h"
#include "up-types.h"
static void up_kbd_backlight_led_finalize (GObject *object);
struct UpKbdBacklightLedPrivate
{
gint max_brightness;
guint brightness;
gint fd_hw_changed;
GIOChannel *channel_hw_changed;
};
G_DEFINE_TYPE_WITH_PRIVATE (UpKbdBacklightLed, up_kbd_backlight_led, UP_TYPE_DEVICE_KBD_BACKLIGHT)
/**
* up_kbd_backlight_led_brightness_write:
*
* Write the brightness value to the LED device with a given path.
**/
static gboolean
up_kbd_backlight_led_brightness_write (UpDeviceKbdBacklight *kbd_backlight, const gchar *native_path, gint value)
{
UpKbdBacklightLed *kbd;
UpKbdBacklightLedPrivate *priv;
g_autoptr (GString) value_str = g_string_new (NULL);
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
priv = up_kbd_backlight_led_get_instance_private (kbd);
g_string_printf (value_str, "%d", CLAMP (value, 0, priv->max_brightness));
if (!g_file_set_contents_full (native_path, value_str->str, value_str->len,
G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, NULL)) {
g_debug ("Failed on setting keyboard backlight LED brightness: %s", native_path);
return FALSE;
}
return TRUE;
}
/**
* up_kbd_backlight_led_brightness_read:
*
* Read the brightness value from the LED device with a given path.
**/
static gint
up_kbd_backlight_led_brightness_read (UpDeviceKbdBacklight *kbd_backlight, const gchar *native_path)
{
g_autofree gchar *buf = NULL;
gint64 brightness = -1;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), brightness);
if (!g_file_get_contents (native_path, &buf, NULL, NULL))
return -1;
g_strstrip (buf);
g_debug ("brightness: %s", buf);
brightness = g_ascii_strtoll (buf, NULL, 10);
if (brightness < 0) {
g_warning ("failed to convert brightness.");
return -1;
}
return brightness;
}
/**
* up_kbd_backlight_led_set_brightness:
*
* Set the brightness.
**/
static gboolean
up_kbd_backlight_led_set_brightness (UpDeviceKbdBacklight *kbd_backlight, gint value)
{
GObject *native;
g_autofree gchar *filename = NULL;
const gchar *native_path;
gboolean ret = FALSE;
native = up_device_kbd_backlight_get_native (UP_DEVICE_KBD_BACKLIGHT (kbd_backlight));
g_return_val_if_fail (native != NULL, FALSE);
native_path = up_native_get_native_path (native);
g_return_val_if_fail (native_path != NULL, FALSE);
filename = g_build_filename (native_path, "brightness", NULL);
ret = up_kbd_backlight_led_brightness_write (kbd_backlight, filename, value);
return ret;
}
/**
* up_kbd_backlight_led_get_brightness:
*
* Get the brightness.
**/
static gint
up_kbd_backlight_led_get_brightness (UpDeviceKbdBacklight *kbd_backlight)
{
GObject *native;
const gchar *native_path;
g_autofree gchar *filename = NULL;
gint brightness = -1;
native = up_device_kbd_backlight_get_native (UP_DEVICE_KBD_BACKLIGHT (kbd_backlight));
g_return_val_if_fail (native != NULL, brightness);
native_path = up_native_get_native_path (native);
g_return_val_if_fail (native_path != NULL, brightness);
filename = g_build_filename (native_path, "brightness", NULL);
brightness = up_kbd_backlight_led_brightness_read (kbd_backlight, filename);
return brightness;
}
/**
* up_kbd_backlight_led_get_max_brightness:
*
* Gets the max brightness.
**/
static gint
up_kbd_backlight_led_get_max_brightness (UpDeviceKbdBacklight *kbd_backlight)
{
UpKbdBacklightLed *kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
UpKbdBacklightLedPrivate *priv = up_kbd_backlight_led_get_instance_private (kbd);
return priv->max_brightness;
}
/**
* up_kbd_backlight_led_event_io:
*
* This function is called when the brightness of the LED device changes.
**/
static gboolean
up_kbd_backlight_led_event_io (GIOChannel *channel, GIOCondition condition, gpointer data)
{
UpDeviceKbdBacklight *kbd_backlight = UP_DEVICE_KBD_BACKLIGHT (data);
UpKbdBacklightLed *kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
UpKbdBacklightLedPrivate *priv = up_kbd_backlight_led_get_instance_private (kbd);
gint brightness = 0;
gchar buf[16];
g_autofree gchar *ret_str = NULL;
glong len;
gchar *end = NULL;
if (priv->fd_hw_changed < 0)
return FALSE;
if (!(condition & G_IO_PRI))
return FALSE;
lseek (priv->fd_hw_changed, 0, SEEK_SET);
len = read (priv->fd_hw_changed, buf, G_N_ELEMENTS (buf) - 1);
if (len > 0) {
buf[len] = '\0';
g_strstrip (buf);
brightness = g_ascii_strtoll (buf, &end, 10);
if (brightness < 0 ||
brightness > priv->max_brightness ||
end == buf) {
brightness = -1;
g_warning ("kbd eventio: failed to convert brightness.");
}
}
g_debug ("kbd eventio: brightness: %d", brightness);
if (brightness < 0)
return FALSE;
if (brightness >= 0)
up_device_kbd_backlight_emit_change (kbd_backlight, brightness, "internal");
return TRUE;
}
/**
* up_kbd_backlight_led_coldplug:
*
* Update the LED settings to UpKbdBacklightLed device.
**/
static gboolean
up_kbd_backlight_led_coldplug (UpDeviceKbdBacklight *kbd_backlight)
{
UpKbdBacklightLed *kbd;
UpKbdBacklightLedPrivate *priv;
GObject *native;
g_autofree gchar *filename = NULL;
g_autofree gchar *path_hw_changed = NULL;
const gchar *native_path = NULL;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
kbd = UP_KBD_BACKLIGHT_LED (kbd_backlight);
priv = up_kbd_backlight_led_get_instance_private (kbd);
native = up_device_kbd_backlight_get_native (kbd_backlight);
if (native == NULL) {
priv->max_brightness = 0;
return FALSE;
}
native_path = up_native_get_native_path (native);
filename = g_build_filename (native_path, "max_brightness", NULL);
priv->max_brightness = up_kbd_backlight_led_brightness_read (kbd_backlight, filename);
/* Set up device watcher */
path_hw_changed = g_build_filename (native_path, "brightness_hw_changed", NULL);
priv->fd_hw_changed = open (path_hw_changed, O_RDONLY);
if (priv->fd_hw_changed >= 0) {
priv->channel_hw_changed = g_io_channel_unix_new (priv->fd_hw_changed);
g_io_add_watch (priv->channel_hw_changed,
G_IO_PRI, up_kbd_backlight_led_event_io, kbd_backlight);
}
return TRUE;
}
/**
* up_kbd_backlight_led_finalize:
**/
static void
up_kbd_backlight_led_finalize (GObject *object)
{
UpKbdBacklightLed *kbd_backlight;
UpKbdBacklightLedPrivate *priv;
g_return_if_fail (object != NULL);
g_return_if_fail (UP_IS_KBD_BACKLIGHT_LED (object));
kbd_backlight = UP_KBD_BACKLIGHT_LED (object);
priv = up_kbd_backlight_led_get_instance_private (kbd_backlight);
if (priv->channel_hw_changed) {
g_io_channel_shutdown (priv->channel_hw_changed, FALSE, NULL);
g_io_channel_unref (priv->channel_hw_changed);
}
if (priv->fd_hw_changed >= 0)
close (priv->fd_hw_changed);
G_OBJECT_CLASS (up_kbd_backlight_led_parent_class)->finalize (object);
}
/**
* up_kbd_backlight_led_class_init:
**/
static void
up_kbd_backlight_led_class_init (UpKbdBacklightLedClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
UpDeviceKbdBacklightClass *dev_kbd_klass = UP_DEVICE_KBD_BACKLIGHT_CLASS (klass);
object_class->finalize = up_kbd_backlight_led_finalize;
dev_kbd_klass->coldplug = up_kbd_backlight_led_coldplug;
dev_kbd_klass->get_max_brightness = up_kbd_backlight_led_get_max_brightness;
dev_kbd_klass->get_brightness = up_kbd_backlight_led_get_brightness;
dev_kbd_klass->set_brightness = up_kbd_backlight_led_set_brightness;
}
/**
* up_kbd_backlight_led_init:
**/
static void
up_kbd_backlight_led_init (UpKbdBacklightLed *kbd_backlight)
{
kbd_backlight->priv = up_kbd_backlight_led_get_instance_private (kbd_backlight);
}
/**
* up_kbd_backlight_led_new:
**/
UpKbdBacklightLed *
up_kbd_backlight_led_new (void)
{
return g_object_new (UP_TYPE_KBD_BACKLIGHT_LED, NULL);
}

View file

@ -0,0 +1,55 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* Licensed under the GNU General Public License Version 2
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __UP_KBD_BACKLIGHT_LED_H
#define __UP_KBD_BACKLIGHT_LED_H
#include <glib-object.h>
#include "up-device-kbd-backlight.h"
G_BEGIN_DECLS
#define UP_TYPE_KBD_BACKLIGHT_LED (up_kbd_backlight_led_get_type ())
#define UP_KBD_BACKLIGHT_LED(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_KBD_BACKLIGHT_LED, UpKbdBacklightLed))
#define UP_KBD_BACKLIGHT_LED_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_KBD_BACKLIGHT_LED, UpKbdBacklightLedClass))
#define UP_IS_KBD_BACKLIGHT_LED(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_KBD_BACKLIGHT_LED))
#define UP_IS_KBD_BACKLIGHT_LED_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), UP_TYPE_KBD_BACKLIGHT_LED))
#define UP_KBD_BACKLIGHT_LED_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), UP_TYPE_KBD_BACKLIGHT_LED, UpKbdBacklightLedClass))
typedef struct UpKbdBacklightLedPrivate UpKbdBacklightLedPrivate;
typedef struct
{
UpDeviceKbdBacklight parent;
UpKbdBacklightLedPrivate *priv;
} UpKbdBacklightLed;
typedef struct
{
UpDeviceKbdBacklightClass parent_class;
} UpKbdBacklightLedClass;
UpKbdBacklightLed *up_kbd_backlight_led_new (void);
GType up_kbd_backlight_led_get_type (void);
G_END_DECLS
#endif /* __UP_KBD_BACKLIGHT_LED_H */

View file

@ -40,6 +40,8 @@ upowerd_private = static_library('upowerd-private',
'up-enumerator.h', 'up-enumerator.h',
'up-kbd-backlight.h', 'up-kbd-backlight.h',
'up-kbd-backlight.c', 'up-kbd-backlight.c',
'up-device-kbd-backlight.c',
'up-device-kbd-backlight.h',
'up-history.h', 'up-history.h',
'up-history.c', 'up-history.c',
'up-backend.h', 'up-backend.h',
@ -146,20 +148,23 @@ if os_backend == 'linux' and gobject_introspection.found()
) )
endforeach endforeach
install_data( [ installed_tests = get_option('installed_tests')
'linux/integration-test.py', if installed_tests
'linux/output_checker.py', install_data( [
], 'linux/integration-test.py',
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower' 'linux/output_checker.py',
) ],
install_subdir('linux/tests/', install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower' )
) install_subdir('linux/tests/',
install_dir: get_option('prefix') / get_option('libexecdir') / 'upower'
)
configure_file( configure_file(
input: 'upower-integration.test.in', input: 'upower-integration.test.in',
output: 'upower-integration.test', output: 'upower-integration.test',
install_dir: get_option('datadir') / 'installed-tests' / 'upower', install_dir: get_option('datadir') / 'installed-tests' / 'upower',
configuration: cdata configuration: cdata
) )
endif
endif endif

View file

@ -104,6 +104,142 @@ up_config_class_init (UpConfigClass *klass)
object_class->finalize = up_config_finalize; object_class->finalize = up_config_finalize;
} }
/**
* up_config_list_compare_files:
**/
static gint
up_config_list_compare_files (gconstpointer a, gconstpointer b)
{
return g_strcmp0 ((const gchar*)a, (const gchar*)b);
}
/**
* up_config_list_confd_files:
*
* The format of the filename should be '^([0-9][0-9])-([a-zA-Z0-9-_])*\.conf$',
* that is, starting with "00-" to "99-", ending in ".conf", and with a mix of
* alphanumeric characters with dashes and underscores in between. For example:
* '01-upower-override.conf'.
*
* Files named differently, or containing invalid groups (currently only
* 'UPower' is valid), will not be considered.
*
* The candidate files within the given directory are sorted (with g_strcmp0(),
* so the ordering will be as with strcmp()). The configuration in the files
* being processed later will override previous config, in particular the main
* config, but also the one from previous files processed, if the Group and Key
* coincide.
*
* For example, consider 'UPower.conf' that contains the defaults:
* PercentageLow=20.0
* PercentageCritical=5.0
* PercentageAction=2.0
*
* and there is a file 'UPower.conf.d/70-change-percentages.conf'
* containing settings for all 'Percentage*' keys:
* [UPower]
* PercentageLow=15.0
* PercentageCritical=10.0
* PercentageAction=5.0
*
* and another 'UPower.conf.d/99-change-percentages-local.conf'
* containing settings only for 'PercentageAction':
* [UPower]
* PercentageAction=7.5
*
* First the main 'UPower.conf' will be processed, then
* 'UPower.conf.d/70-change-percentages.conf' overriding the defaults
* of all percentages from the main config file with the given values,
* and finally 'UPower.conf.d/99-change-percentages-local.conf'
* overriding once again only 'PercentageAction'. The final, effective
* values are:
* PercentageLow=15.0
* PercentageCritical=10.0
* PercentageAction=7.5
**/
static GPtrArray*
up_config_list_confd_files (const gchar* conf_d_path, GError** error)
{
g_autoptr (GPtrArray) ret_conf_d_files = NULL;
GDir *dir = NULL;
const gchar *filename = NULL;
const char *regex_pattern = "^([0-9][0-9])-([a-zA-Z0-9-_])*\\.conf$";
g_autoptr (GRegex) regex = NULL;
dir = g_dir_open (conf_d_path, 0, error);
if (dir == NULL)
return NULL;
regex = g_regex_new (regex_pattern, G_REGEX_DEFAULT, G_REGEX_MATCH_DEFAULT, NULL);
g_assert (regex != NULL);
ret_conf_d_files = g_ptr_array_new_full (0, g_free);
while ((filename = g_dir_read_name (dir)) != NULL) {
g_autofree gchar *file_path = NULL;
g_autoptr (GFile) file = NULL;
g_autoptr (GFileInfo) file_info = NULL;
if (!g_regex_match (regex, filename, G_REGEX_MATCH_DEFAULT, NULL))
continue;
file_path = g_build_filename (conf_d_path, filename, NULL);
file = g_file_new_for_path (file_path);
file_info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_TYPE,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL,
NULL);
if (file_info != NULL) {
g_debug ("Will consider additional config file '%s'", file_path);
g_ptr_array_add (ret_conf_d_files, g_strdup (file_path));
}
}
g_dir_close (dir);
g_ptr_array_sort_values (ret_conf_d_files, up_config_list_compare_files);
return g_ptr_array_ref (ret_conf_d_files);
}
/**
* up_config_override_from_confd:
**/
static void
up_config_override_from_confd (GKeyFile *key_file, const gchar* new_config_path)
{
g_autoptr (GKeyFile) new_keyfile = NULL;
gchar **keys = NULL;
gsize keys_size = 0;
new_keyfile = g_key_file_new();
if (!g_key_file_load_from_file (new_keyfile, new_config_path, G_KEY_FILE_NONE, NULL))
return;
if (!g_key_file_has_group (new_keyfile, "UPower"))
return;
keys = g_key_file_get_keys (new_keyfile, "UPower", &keys_size, NULL);
if (keys == NULL)
return;
for (gsize i = 0; i < keys_size; i++) {
g_autofree gchar *value = NULL;
g_autofree gchar *old_value = NULL;
value = g_key_file_get_value (new_keyfile, "UPower", keys[i], NULL);
if (value == NULL)
continue;
old_value = g_key_file_get_value (key_file, "UPower", keys[i], NULL);
if (old_value != NULL)
g_key_file_set_value (key_file, "UPower", keys[i], value);
}
g_strfreev (keys);
}
/** /**
* up_config_init: * up_config_init:
**/ **/
@ -111,17 +247,26 @@ static void
up_config_init (UpConfig *config) up_config_init (UpConfig *config)
{ {
gboolean allow_risky_critical_action = FALSE; gboolean allow_risky_critical_action = FALSE;
gboolean expect_battery_recalibration = FALSE;
g_autofree gchar *critical_action = NULL; g_autofree gchar *critical_action = NULL;
GError *error = NULL; g_autoptr (GError) error = NULL;
g_autofree gchar *filename = NULL; g_autofree gchar *filename = NULL;
gboolean ret; gboolean ret;
g_autofree gchar *conf_dir = NULL;
g_autofree gchar *conf_d_path = NULL;
g_autoptr (GPtrArray) conf_d_files = NULL;
config->priv = up_config_get_instance_private (config); config->priv = up_config_get_instance_private (config);
config->priv->keyfile = g_key_file_new (); config->priv->keyfile = g_key_file_new ();
filename = g_strdup (g_getenv ("UPOWER_CONF_FILE_NAME")); filename = g_strdup (g_getenv ("UPOWER_CONF_FILE_NAME"));
if (filename == NULL) if (filename == NULL) {
filename = g_build_filename (PACKAGE_SYSCONF_DIR,"UPower", "UPower.conf", NULL); filename = g_build_filename (PACKAGE_SYSCONF_DIR,"UPower", "UPower.conf", NULL);
conf_d_path = g_build_filename (PACKAGE_SYSCONF_DIR, "UPower", "UPower.conf.d", NULL);
} else {
conf_dir = g_path_get_dirname (filename);
conf_d_path = g_build_filename (conf_dir, "UPower.conf.d", NULL);
}
/* load */ /* load */
ret = g_key_file_load_from_file (config->priv->keyfile, ret = g_key_file_load_from_file (config->priv->keyfile,
@ -132,7 +277,18 @@ up_config_init (UpConfig *config)
if (!ret) { if (!ret) {
g_warning ("failed to load config file '%s': %s", g_warning ("failed to load config file '%s': %s",
filename, error->message); filename, error->message);
g_error_free (error); g_clear_error (&error);
}
conf_d_files = up_config_list_confd_files (conf_d_path, &error);
if (conf_d_files != NULL) {
for (guint i = 0; i < conf_d_files->len; i++) {
const gchar* conf_d_file = (const gchar*)(g_ptr_array_index (conf_d_files, i));
up_config_override_from_confd (config->priv->keyfile,
conf_d_file);
}
} else {
g_debug ("failed to find files in 'UPower.conf.d': %s", error->message);
} }
/* Warn for any dangerous configurations */ /* Warn for any dangerous configurations */
@ -153,6 +309,17 @@ up_config_init (UpConfig *config)
" risky settings.", critical_action); " risky settings.", critical_action);
} }
} }
expect_battery_recalibration = up_config_get_boolean (config, "ExpectBatteryRecalibration");
if (expect_battery_recalibration) {
if (allow_risky_critical_action) {
g_warning ("The \"ExpectBatteryRecalibration\" setting is considered risky:"
" abrupt power loss due to battery exhaustion may lead to data"
" corruption. The system will unexpected down when the AC is disconnected."
" Use AllowRiskyCriticalPowerAction=false to disable support for"
" risky settings.");
}
}
} }
/** /**

View file

@ -33,6 +33,7 @@
#include "up-polkit.h" #include "up-polkit.h"
#include "up-device-list.h" #include "up-device-list.h"
#include "up-device.h" #include "up-device.h"
#include "up-device-kbd-backlight.h"
#include "up-backend.h" #include "up-backend.h"
#include "up-daemon.h" #include "up-daemon.h"
@ -43,6 +44,7 @@ struct UpDaemonPrivate
UpPolkit *polkit; UpPolkit *polkit;
UpBackend *backend; UpBackend *backend;
UpDeviceList *power_devices; UpDeviceList *power_devices;
UpDeviceList *kbd_backlight_devices;
guint action_timeout_id; guint action_timeout_id;
guint refresh_batteries_id; guint refresh_batteries_id;
guint warning_level_id; guint warning_level_id;
@ -497,6 +499,38 @@ up_daemon_enumerate_devices (UpExportedDaemon *skeleton,
return TRUE; return TRUE;
} }
static gboolean
up_daemon_enumerate_kbd_backlights (UpExportedDaemon *skeleton,
GDBusMethodInvocation *invocation,
UpDaemon *daemon)
{
guint i;
GPtrArray *array;
GPtrArray *object_paths;
UpDeviceKbdBacklight *kbd_backlight;
/* build a pointer array of the object paths */
object_paths = g_ptr_array_new_with_free_func (g_free);
array = up_device_list_get_array (daemon->priv->kbd_backlight_devices);
for (i = 0; i < array->len; i++) {
const char *object_path;
kbd_backlight = (UpDeviceKbdBacklight *) g_ptr_array_index (array, i);
object_path = up_device_kbd_backlight_get_object_path (kbd_backlight);
if (object_path != NULL)
g_ptr_array_add (object_paths, g_strdup (object_path));
}
g_ptr_array_unref (array);
g_ptr_array_add (object_paths, NULL);
/* return it on the bus */
up_exported_daemon_complete_enumerate_kbd_backlights (skeleton, invocation,
(const gchar **) object_paths->pdata);
/* free */
g_ptr_array_unref (object_paths);
return TRUE;
}
/** /**
* up_daemon_get_display_device: * up_daemon_get_display_device:
**/ **/
@ -601,6 +635,7 @@ up_daemon_shutdown (UpDaemon *daemon)
/* forget about discovered devices */ /* forget about discovered devices */
up_device_list_clear (daemon->priv->power_devices); up_device_list_clear (daemon->priv->power_devices);
up_device_list_clear (daemon->priv->kbd_backlight_devices);
/* release UpDaemon reference */ /* release UpDaemon reference */
g_object_run_dispose (G_OBJECT (daemon->priv->display_device)); g_object_run_dispose (G_OBJECT (daemon->priv->display_device));
@ -734,6 +769,8 @@ up_daemon_compute_warning_level (UpDaemon *daemon,
gdouble percentage, gdouble percentage,
gint64 time_to_empty) gint64 time_to_empty)
{ {
gboolean can_risky = FALSE;
gboolean expect_battery_recalibration = FALSE;
gboolean use_percentage = TRUE; gboolean use_percentage = TRUE;
UpDeviceLevel default_level = UP_DEVICE_LEVEL_NONE; UpDeviceLevel default_level = UP_DEVICE_LEVEL_NONE;
@ -756,6 +793,21 @@ up_daemon_compute_warning_level (UpDaemon *daemon,
default_level = UP_DEVICE_LEVEL_DISCHARGING; default_level = UP_DEVICE_LEVEL_DISCHARGING;
} }
/* Check if the battery is performing the battery recalibration and
* AC is online, the battery level is UP_DEVICE_LEVEL_NONE. */
can_risky = up_config_get_boolean (daemon->priv->config,
"AllowRiskyCriticalPowerAction");
expect_battery_recalibration = up_config_get_boolean (daemon->priv->config,
"ExpectBatteryRecalibration");
if (can_risky && kind == UP_DEVICE_KIND_BATTERY) {
if (expect_battery_recalibration &&
up_daemon_get_on_ac_local (daemon, NULL)) {
g_debug ("ExpectBatteryRecalibration is enabled and the AC is connected, so the battery level is not critical");
return UP_DEVICE_LEVEL_NONE;
}
}
if (power_supply && if (power_supply &&
!daemon->priv->use_percentage_for_policy && !daemon->priv->use_percentage_for_policy &&
time_to_empty > 0.0) time_to_empty > 0.0)
@ -1034,35 +1086,50 @@ up_daemon_get_env_override (UpDaemon *self)
* up_daemon_device_added_cb: * up_daemon_device_added_cb:
**/ **/
static void static void
up_daemon_device_added_cb (UpBackend *backend, UpDevice *device, UpDaemon *daemon) up_daemon_device_added_cb (UpBackend *backend, GObject *device, UpDaemon *daemon)
{ {
const gchar *object_path; const gchar *object_path;
UpDaemonPrivate *priv = daemon->priv; UpDaemonPrivate *priv = daemon->priv;
g_return_if_fail (UP_IS_DAEMON (daemon)); g_return_if_fail (UP_IS_DAEMON (daemon));
g_return_if_fail (UP_IS_DEVICE (device)); g_return_if_fail (UP_IS_DEVICE (device) || UP_IS_DEVICE_KBD_BACKLIGHT (device));
/* add to device list */ if (UP_IS_DEVICE (device)) {
up_device_list_insert (priv->power_devices, device); /* power_supply */
/* add to device list */
up_device_list_insert (priv->power_devices, device);
/* connect, so we get changes */ /* connect, so we get changes */
g_signal_connect (device, "notify", g_signal_connect (device, "notify",
G_CALLBACK (up_daemon_device_changed_cb), daemon); G_CALLBACK (up_daemon_device_changed_cb), daemon);
/* emit */ /* emit */
object_path = up_device_get_object_path (device); object_path = up_device_get_object_path (UP_DEVICE (device));
if (object_path == NULL) { if (object_path == NULL) {
g_debug ("Device %s was unregistered before it was on the bus", g_debug ("Device %s was unregistered before it was on the bus",
up_exported_device_get_native_path (UP_EXPORTED_DEVICE (device))); up_exported_device_get_native_path (UP_EXPORTED_DEVICE (device)));
return; return;
}
/* Ensure we poll the new device if needed */
g_source_set_ready_time (daemon->priv->poll_source, 0);
g_debug ("emitting added: %s", object_path);
up_daemon_update_warning_level (daemon);
up_exported_daemon_emit_device_added (UP_EXPORTED_DAEMON (daemon), object_path);
} else {
/*leds*/
g_debug ("Add a led device to the device list");
/* emit */
object_path = up_device_kbd_backlight_get_object_path (UP_DEVICE_KBD_BACKLIGHT (device));
if (object_path == NULL) {
g_debug ("Device %s was unregistered before it was on the bus",
up_exported_kbd_backlight_get_native_path (UP_EXPORTED_KBD_BACKLIGHT (device)));
return;
}
up_device_list_insert (priv->kbd_backlight_devices, G_OBJECT (device));
up_exported_daemon_emit_device_added (UP_EXPORTED_DAEMON (daemon), object_path);
} }
/* Ensure we poll the new device if needed */
g_source_set_ready_time (daemon->priv->poll_source, 0);
g_debug ("emitting added: %s", object_path);
up_daemon_update_warning_level (daemon);
up_exported_daemon_emit_device_added (UP_EXPORTED_DAEMON (daemon), object_path);
} }
/** /**
@ -1075,15 +1142,22 @@ up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *dae
UpDaemonPrivate *priv = daemon->priv; UpDaemonPrivate *priv = daemon->priv;
g_return_if_fail (UP_IS_DAEMON (daemon)); g_return_if_fail (UP_IS_DAEMON (daemon));
g_return_if_fail (UP_IS_DEVICE (device)); g_return_if_fail (UP_IS_DEVICE (device) || UP_IS_DEVICE_KBD_BACKLIGHT (device));
g_signal_handlers_disconnect_by_data (device, daemon); g_signal_handlers_disconnect_by_data (device, daemon);
/* remove from list (device remains valid during the function call) */
up_device_list_remove (priv->power_devices, device);
/* emit */ /* emit */
object_path = up_device_get_object_path (device); if (UP_IS_DEVICE (device)) {
/* remove from list (device remains valid during the function call) */
up_device_list_remove (priv->power_devices, device);
object_path = up_device_get_object_path (device);
} else if (UP_IS_DEVICE_KBD_BACKLIGHT (device)) {
/* remove from list (device remains valid during the function call) */
up_device_list_remove (priv->kbd_backlight_devices, device);
object_path = up_device_kbd_backlight_get_object_path (UP_DEVICE_KBD_BACKLIGHT (device));
} else {
return;
}
/* don't crash the session */ /* don't crash the session */
if (object_path == NULL) { if (object_path == NULL) {
@ -1094,6 +1168,10 @@ up_daemon_device_removed_cb (UpBackend *backend, UpDevice *device, UpDaemon *dae
g_debug ("emitting device-removed: %s", object_path); g_debug ("emitting device-removed: %s", object_path);
up_exported_daemon_emit_device_removed (UP_EXPORTED_DAEMON (daemon), object_path); up_exported_daemon_emit_device_removed (UP_EXPORTED_DAEMON (daemon), object_path);
/* Unregister keyboard backlight dbus path */
if (UP_IS_DEVICE_KBD_BACKLIGHT (device))
up_device_kbd_backlight_unregister (UP_DEVICE_KBD_BACKLIGHT (device));
/* In case a battery was removed */ /* In case a battery was removed */
up_daemon_refresh_battery_devices (daemon); up_daemon_refresh_battery_devices (daemon);
up_daemon_update_warning_level (daemon); up_daemon_update_warning_level (daemon);
@ -1154,6 +1232,7 @@ up_daemon_init (UpDaemon *daemon)
daemon->priv->polkit = up_polkit_new (); daemon->priv->polkit = up_polkit_new ();
daemon->priv->config = up_config_new (); daemon->priv->config = up_config_new ();
daemon->priv->power_devices = up_device_list_new (); daemon->priv->power_devices = up_device_list_new ();
daemon->priv->kbd_backlight_devices = up_device_list_new ();
daemon->priv->display_device = up_device_new (daemon, NULL); daemon->priv->display_device = up_device_new (daemon, NULL);
daemon->priv->poll_source = g_source_new (&poll_source_funcs, sizeof (GSource)); daemon->priv->poll_source = g_source_new (&poll_source_funcs, sizeof (GSource));
@ -1180,6 +1259,8 @@ up_daemon_init (UpDaemon *daemon)
g_signal_connect (daemon, "handle-enumerate-devices", g_signal_connect (daemon, "handle-enumerate-devices",
G_CALLBACK (up_daemon_enumerate_devices), daemon); G_CALLBACK (up_daemon_enumerate_devices), daemon);
g_signal_connect (daemon, "handle-enumerate-kbd_backlights",
G_CALLBACK (up_daemon_enumerate_kbd_backlights), daemon);
g_signal_connect (daemon, "handle-get-critical-action", g_signal_connect (daemon, "handle-get-critical-action",
G_CALLBACK (up_daemon_get_critical_action), daemon); G_CALLBACK (up_daemon_get_critical_action), daemon);
g_signal_connect (daemon, "handle-get-display-device", g_signal_connect (daemon, "handle-get-display-device",
@ -1238,6 +1319,7 @@ up_daemon_finalize (GObject *object)
g_clear_pointer (&daemon->priv->poll_source, g_source_destroy); g_clear_pointer (&daemon->priv->poll_source, g_source_destroy);
g_object_unref (priv->power_devices); g_object_unref (priv->power_devices);
g_object_unref (priv->kbd_backlight_devices);
g_object_unref (priv->display_device); g_object_unref (priv->display_device);
g_object_unref (priv->polkit); g_object_unref (priv->polkit);
g_object_unref (priv->config); g_object_unref (priv->config);

View file

@ -0,0 +1,410 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "config.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n-lib.h>
#include <glib-object.h>
#include "up-native.h"
#include "up-device-kbd-backlight.h"
#include "up-stats-item.h"
typedef struct
{
UpDaemon *daemon;
GObject *native;
} UpDeviceKbdBacklightPrivate;
static void up_device_kbd_backlight_initable_iface_init (GInitableIface *iface);
G_DEFINE_TYPE_EXTENDED (UpDeviceKbdBacklight, up_device_kbd_backlight, UP_TYPE_EXPORTED_KBD_BACKLIGHT_SKELETON, 0,
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
up_device_kbd_backlight_initable_iface_init)
G_ADD_PRIVATE (UpDeviceKbdBacklight))
enum {
PROP_0,
PROP_DAEMON,
PROP_NATIVE,
N_PROPS
};
/* Upower keeps the legacy keyboard backlight DBus API (/org/freedesktop/UPower/KbdBacklight/)
* for backward compatibility.
* The new API path is based on the legacy one and the suffix is the name of the keyboard
* backlight device. For example, the path of the keyboard backlight device
* "tpacpiookbd_backlight" is
* "/org/freedesktop/UPower/KbdBacklight/tpacpiookbd_backlight".*/
#define UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH "/org/freedesktop/UPower/KbdBacklight"
static GParamSpec *properties[N_PROPS];
/**
* up_kbd_backlight_emit_change:
**/
void
up_device_kbd_backlight_emit_change(UpDeviceKbdBacklight *kbd_backlight, int value, const char *source)
{
up_exported_kbd_backlight_emit_brightness_changed (UP_EXPORTED_KBD_BACKLIGHT (kbd_backlight), value);
up_exported_kbd_backlight_emit_brightness_changed_with_source (UP_EXPORTED_KBD_BACKLIGHT (kbd_backlight), value, source);
}
/**
* up_kbd_backlight_get_brightness:
*
* Gets the current brightness
**/
static gboolean
up_kbd_backlight_get_brightness (UpExportedKbdBacklight *skeleton,
GDBusMethodInvocation *invocation,
UpDeviceKbdBacklight *kbd_backlight)
{
UpDeviceKbdBacklightClass *klass;
gint brightness = 0;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (kbd_backlight);
brightness = klass->get_brightness (kbd_backlight);
if (brightness >= 0) {
up_exported_kbd_backlight_complete_get_brightness (skeleton, invocation,
brightness);
} else {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"error reading brightness");
}
return TRUE;
}
/**
* up_kbd_backlight_get_max_brightness:
*
* Gets the max brightness
**/
static gboolean
up_kbd_backlight_get_max_brightness (UpExportedKbdBacklight *skeleton,
GDBusMethodInvocation *invocation,
UpDeviceKbdBacklight *kbd_backlight)
{
UpDeviceKbdBacklightClass *klass;
gint brightness = -1;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (kbd_backlight);
if (klass->get_max_brightness != NULL)
brightness = klass->get_max_brightness (kbd_backlight);
if (brightness >= 0) {
up_exported_kbd_backlight_complete_get_max_brightness (skeleton, invocation,
brightness);
} else {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"error reading max brightness");
}
return TRUE;
}
/**
* up_kbd_backlight_set_brightness:
*
* Sets the kbd backlight LED brightness.
**/
static gboolean
up_kbd_backlight_set_brightness (UpExportedKbdBacklight *skeleton,
GDBusMethodInvocation *invocation,
gint value,
UpDeviceKbdBacklight *kbd_backlight)
{
UpDeviceKbdBacklightClass *klass;
gboolean ret = FALSE;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (kbd_backlight), FALSE);
klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (kbd_backlight);
if (klass->set_brightness == NULL) {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"setting brightness is unsupported");
return TRUE;
}
ret = klass->set_brightness (kbd_backlight, value);
if (ret) {
up_exported_kbd_backlight_complete_set_brightness (skeleton, invocation);
up_device_kbd_backlight_emit_change (kbd_backlight, value, "external");
} else {
g_dbus_method_invocation_return_error (invocation,
UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL,
"error writing brightness %d", value);
}
return TRUE;
}
GObject *
up_device_kbd_backlight_get_native (UpDeviceKbdBacklight *device)
{
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (device), NULL);
return priv->native;
}
static gchar *
up_device_kbd_backlight_compute_object_path (UpDeviceKbdBacklight *device)
{
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
g_autofree gchar *basename = NULL;
g_autofree gchar *id = NULL;
gchar *object_path;
const gchar *native_path;
guint i;
if (priv->native == NULL) {
return g_build_filename (UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH, "KbdBacklight", NULL);
}
native_path = up_exported_kbd_backlight_get_native_path (UP_EXPORTED_KBD_BACKLIGHT (device));
basename = g_path_get_basename (native_path);
id = g_strjoin ("_", basename, NULL);
/* make DBUS valid path */
for (i=0; id[i] != '\0'; i++) {
if (id[i] == '-')
id[i] = '_';
if (id[i] == '.')
id[i] = 'x';
if (id[i] == ':')
id[i] = 'o';
if (id[i] == '@')
id[i] = '_';
}
object_path = g_build_filename (UP_DEVICES_KBD_BACKLIGHT_DBUS_PATH, id, NULL);
return object_path;
}
static void
up_device_kbd_backlight_export_skeleton (UpDeviceKbdBacklight *device,
const gchar *object_path)
{
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
GError *error = NULL;
g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (device),
g_dbus_interface_skeleton_get_connection (G_DBUS_INTERFACE_SKELETON (priv->daemon)),
object_path,
&error);
if (error != NULL) {
g_critical ("error registering device on system bus: %s", error->message);
g_error_free (error);
}
}
gboolean
up_device_kbd_backlight_register (UpDeviceKbdBacklight *device)
{
g_autofree char *computed_object_path = NULL;
if (g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device)) != NULL)
return FALSE;
computed_object_path = up_device_kbd_backlight_compute_object_path (device);
g_debug ("Exported Keyboard backlight with path %s", computed_object_path);
up_device_kbd_backlight_export_skeleton (device, computed_object_path);
return TRUE;
}
void
up_device_kbd_backlight_unregister (UpDeviceKbdBacklight *device)
{
g_autofree char *object_path = NULL;
object_path = g_strdup (g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device)));
if (object_path != NULL) {
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (device));
g_debug ("Unexported UpDeviceKbdBacklight with path %s", object_path);
}
}
const gchar *
up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device)
{
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (device), NULL);
return g_dbus_interface_skeleton_get_object_path (G_DBUS_INTERFACE_SKELETON (device));
}
static void
up_device_kbd_backlight_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (object);
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
switch (prop_id)
{
case PROP_DAEMON:
priv->daemon = g_value_dup_object (value);
break;
case PROP_NATIVE:
priv->native = g_value_dup_object (value);
if (priv->native == NULL)
g_warning ("KBD native is NULL");
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
up_device_kbd_backlight_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
switch (prop_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static gboolean
up_device_kbd_backlight_initable_init (GInitable *initable,
GCancellable *cancellable,
GError **error)
{
UpDeviceKbdBacklight *device = UP_DEVICE_KBD_BACKLIGHT (initable);
UpDeviceKbdBacklightPrivate *priv = up_device_kbd_backlight_get_instance_private (device);
const gchar *native_path = NULL;
UpDeviceKbdBacklightClass *klass = UP_DEVICE_KBD_BACKLIGHT_GET_CLASS (device);
int ret;
g_return_val_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (device), FALSE);
if (priv->native) {
native_path = up_native_get_native_path (priv->native);
up_exported_kbd_backlight_set_native_path (UP_EXPORTED_KBD_BACKLIGHT (device), native_path);
}
/* coldplug source */
if (klass->coldplug != NULL) {
ret = klass->coldplug (device);
if (!ret) {
g_debug ("failed to coldplug %s", native_path);
g_propagate_error (error, g_error_new (G_IO_ERROR, G_IO_ERROR_FAILED,
"Failed to coldplug %s", native_path));
return FALSE;
}
}
up_device_kbd_backlight_register (device);
return TRUE;
}
static void
up_device_kbd_backlight_initable_iface_init (GInitableIface *iface)
{
iface->init = up_device_kbd_backlight_initable_init;
}
/**
* up_kbd_backlight_init:
**/
static void
up_device_kbd_backlight_init (UpDeviceKbdBacklight *kbd_backlight)
{
g_signal_connect (kbd_backlight, "handle-get-brightness",
G_CALLBACK (up_kbd_backlight_get_brightness), kbd_backlight);
g_signal_connect (kbd_backlight, "handle-get-max-brightness",
G_CALLBACK (up_kbd_backlight_get_max_brightness), kbd_backlight);
g_signal_connect (kbd_backlight, "handle-set-brightness",
G_CALLBACK (up_kbd_backlight_set_brightness), kbd_backlight);
}
/**
* up_kbd_backlight_finalize:
**/
static void
up_device_kbd_backlight_finalize (GObject *object)
{
g_return_if_fail (object != NULL);
g_return_if_fail (UP_IS_DEVICE_KBD_BACKLIGHT (object));
G_OBJECT_CLASS (up_device_kbd_backlight_parent_class)->finalize (object);
}
static void
up_device_kbd_backlight_class_init (UpDeviceKbdBacklightClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = up_device_kbd_backlight_finalize;
object_class->set_property = up_device_kbd_backlight_set_property;
object_class->get_property = up_device_kbd_backlight_get_property;
properties[PROP_DAEMON] =
g_param_spec_object ("daemon",
"UpDaemon",
"UpDaemon reference",
UP_TYPE_DAEMON,
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
properties[PROP_NATIVE] =
g_param_spec_object ("native",
"Native",
"Native Object",
G_TYPE_OBJECT,
G_PARAM_STATIC_STRINGS | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY);
g_object_class_install_properties (object_class, N_PROPS, properties);
}
/**
* up_kbd_backlight_new:
**/
UpDeviceKbdBacklight *
up_device_kbd_backlight_new (UpDaemon *daemon, GObject *native)
{
return UP_DEVICE_KBD_BACKLIGHT (g_object_new (UP_TYPE_DEVICE_KBD_BACKLIGHT,
"daemon", daemon,
"native", native,
NULL));
}

View file

@ -0,0 +1,60 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2025 Kate Hsuan <p.hsuan@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __UP_DEVICE_KBD_BACKLIGHT_H__
#define __UP_DEVICE_KBD_BACKLIGHT_H__
#include <dbus/up-kbd-backlight-generated.h>
#include "up-daemon.h"
G_BEGIN_DECLS
#define UP_TYPE_DEVICE_KBD_BACKLIGHT (up_device_kbd_backlight_get_type ())
G_DECLARE_DERIVABLE_TYPE (UpDeviceKbdBacklight, up_device_kbd_backlight, UP, DEVICE_KBD_BACKLIGHT, UpExportedKbdBacklightSkeleton)
struct _UpDeviceKbdBacklightClass
{
UpExportedKbdBacklightSkeletonClass parent_class;
gboolean (*coldplug) (UpDeviceKbdBacklight *device);
gint (*get_max_brightness) (UpDeviceKbdBacklight *device);
gint (*get_brightness) (UpDeviceKbdBacklight *device);
gboolean (*set_brightness) (UpDeviceKbdBacklight *device, gint brightness);
};
GType up_device_kbd_backlight_get_type (void);
void up_device_kbd_backlight_emit_change (UpDeviceKbdBacklight *kbd_backlight,
int value,
const char *source);
const gchar *up_device_kbd_backlight_get_object_path (UpDeviceKbdBacklight *device);
GObject *up_device_kbd_backlight_get_native (UpDeviceKbdBacklight *device);
UpDeviceKbdBacklight *up_device_kbd_backlight_new (UpDaemon *daemon,
GObject *native);
gboolean up_device_kbd_backlight_register (UpDeviceKbdBacklight *device);
void up_device_kbd_backlight_unregister (UpDeviceKbdBacklight *device);
G_END_DECLS
#endif /* __UP_DEVICE_KBD_BACKLIGHT_H__ */

View file

@ -28,6 +28,7 @@
#include "up-native.h" #include "up-native.h"
#include "up-device-list.h" #include "up-device-list.h"
#include "up-device.h" #include "up-device.h"
#include "up-device-kbd-backlight.h"
static void up_device_list_finalize (GObject *object); static void up_device_list_finalize (GObject *object);
@ -80,7 +81,10 @@ up_device_list_insert (UpDeviceList *list, gpointer device)
g_return_val_if_fail (UP_IS_DEVICE_LIST (list), FALSE); g_return_val_if_fail (UP_IS_DEVICE_LIST (list), FALSE);
g_return_val_if_fail (device != NULL, FALSE); g_return_val_if_fail (device != NULL, FALSE);
native = up_device_get_native (UP_DEVICE (device)); if (UP_IS_DEVICE_KBD_BACKLIGHT (device))
native = up_device_kbd_backlight_get_native (UP_DEVICE_KBD_BACKLIGHT (device));
else
native = up_device_get_native (UP_DEVICE (device));
g_return_val_if_fail (native != NULL, FALSE); g_return_val_if_fail (native != NULL, FALSE);
native_path = up_native_get_native_path (native); native_path = up_native_get_native_path (native);

View file

@ -213,6 +213,7 @@ update_history (UpDevice *device)
up_history_set_rate_data (priv->history, up_exported_device_get_energy_rate (skeleton)); up_history_set_rate_data (priv->history, up_exported_device_get_energy_rate (skeleton));
up_history_set_time_full_data (priv->history, up_exported_device_get_time_to_full (skeleton)); up_history_set_time_full_data (priv->history, up_exported_device_get_time_to_full (skeleton));
up_history_set_time_empty_data (priv->history, up_exported_device_get_time_to_empty (skeleton)); up_history_set_time_empty_data (priv->history, up_exported_device_get_time_to_empty (skeleton));
up_history_set_voltage_data (priv->history, up_exported_device_get_voltage (skeleton));
} }
static void static void
@ -669,6 +670,8 @@ up_device_get_history (UpExportedDevice *skeleton,
type = UP_HISTORY_TYPE_TIME_FULL; type = UP_HISTORY_TYPE_TIME_FULL;
else if (g_strcmp0 (type_string, "time-empty") == 0) else if (g_strcmp0 (type_string, "time-empty") == 0)
type = UP_HISTORY_TYPE_TIME_EMPTY; type = UP_HISTORY_TYPE_TIME_EMPTY;
else if (g_strcmp0 (type_string, "voltage") == 0)
type = UP_HISTORY_TYPE_VOLTAGE;
/* something recognized */ /* something recognized */
if (type != UP_HISTORY_TYPE_UNKNOWN) { if (type != UP_HISTORY_TYPE_UNKNOWN) {

View file

@ -45,11 +45,13 @@ struct UpHistoryPrivate
gint64 time_full_last; gint64 time_full_last;
gint64 time_empty_last; gint64 time_empty_last;
gdouble percentage_last; gdouble percentage_last;
gdouble voltage_last;
UpDeviceState state; UpDeviceState state;
GPtrArray *data_rate; GPtrArray *data_rate;
GPtrArray *data_charge; GPtrArray *data_charge;
GPtrArray *data_time_full; GPtrArray *data_time_full;
GPtrArray *data_time_empty; GPtrArray *data_time_empty;
GPtrArray *data_voltage;
GSource *save_source; GSource *save_source;
guint max_data_age; guint max_data_age;
gchar *dir; gchar *dir;
@ -254,6 +256,8 @@ up_history_get_data (UpHistory *history, UpHistoryType type, guint timespan, gui
array_data = history->priv->data_time_full; array_data = history->priv->data_time_full;
else if (type == UP_HISTORY_TYPE_TIME_EMPTY) else if (type == UP_HISTORY_TYPE_TIME_EMPTY)
array_data = history->priv->data_time_empty; array_data = history->priv->data_time_empty;
else if (type == UP_HISTORY_TYPE_VOLTAGE)
array_data = history->priv->data_voltage;
/* not recognized */ /* not recognized */
if (array_data == NULL) if (array_data == NULL)
@ -549,6 +553,7 @@ up_history_save_data (UpHistory *history)
gchar *filename_charge = NULL; gchar *filename_charge = NULL;
gchar *filename_time_full = NULL; gchar *filename_time_full = NULL;
gchar *filename_time_empty = NULL; gchar *filename_time_empty = NULL;
gchar *filename_voltage = NULL;
/* we have an ID? */ /* we have an ID? */
if (history->priv->id == NULL) { if (history->priv->id == NULL) {
@ -561,6 +566,7 @@ up_history_save_data (UpHistory *history)
filename_charge = up_history_get_filename (history, "charge"); filename_charge = up_history_get_filename (history, "charge");
filename_time_full = up_history_get_filename (history, "time-full"); filename_time_full = up_history_get_filename (history, "time-full");
filename_time_empty = up_history_get_filename (history, "time-empty"); filename_time_empty = up_history_get_filename (history, "time-empty");
filename_voltage = up_history_get_filename (history, "voltage");
/* save to disk */ /* save to disk */
ret = up_history_array_to_file (history, history->priv->data_rate, filename_rate); ret = up_history_array_to_file (history, history->priv->data_rate, filename_rate);
@ -575,11 +581,15 @@ up_history_save_data (UpHistory *history)
ret = up_history_array_to_file (history, history->priv->data_time_empty, filename_time_empty); ret = up_history_array_to_file (history, history->priv->data_time_empty, filename_time_empty);
if (!ret) if (!ret)
goto out; goto out;
ret = up_history_array_to_file (history, history->priv->data_voltage, filename_voltage);
if (!ret)
goto out;
out: out:
g_free (filename_rate); g_free (filename_rate);
g_free (filename_charge); g_free (filename_charge);
g_free (filename_time_full); g_free (filename_time_full);
g_free (filename_time_empty); g_free (filename_time_empty);
g_free (filename_voltage);
return ret; return ret;
} }
@ -693,6 +703,11 @@ up_history_load_data (UpHistory *history)
up_history_array_from_file (history->priv->data_time_empty, filename); up_history_array_from_file (history->priv->data_time_empty, filename);
g_free (filename); g_free (filename);
/* load voltage history from disk */
filename = up_history_get_filename (history, "voltage");
up_history_array_from_file (history->priv->data_voltage, filename);
g_free (filename);
/* save a marker so we don't use incomplete percentages */ /* save a marker so we don't use incomplete percentages */
item = up_history_item_new (); item = up_history_item_new ();
up_history_item_set_time_to_present (item); up_history_item_set_time_to_present (item);
@ -700,6 +715,7 @@ up_history_load_data (UpHistory *history)
g_ptr_array_add (history->priv->data_charge, g_object_ref (item)); g_ptr_array_add (history->priv->data_charge, g_object_ref (item));
g_ptr_array_add (history->priv->data_time_full, g_object_ref (item)); g_ptr_array_add (history->priv->data_time_full, g_object_ref (item));
g_ptr_array_add (history->priv->data_time_empty, g_object_ref (item)); g_ptr_array_add (history->priv->data_time_empty, g_object_ref (item));
g_ptr_array_add (history->priv->data_voltage, g_object_ref (item));
g_object_unref (item); g_object_unref (item);
up_history_schedule_save (history); up_history_schedule_save (history);
@ -870,6 +886,37 @@ up_history_set_time_empty_data (UpHistory *history, gint64 time_s)
return TRUE; return TRUE;
} }
/**
* up_history_set_voltage_data:
**/
gboolean
up_history_set_voltage_data (UpHistory *history, gdouble voltage)
{
UpHistoryItem *item;
g_return_val_if_fail (UP_IS_HISTORY (history), FALSE);
if (history->priv->id == NULL)
return FALSE;
if (history->priv->state == UP_DEVICE_STATE_UNKNOWN)
return FALSE;
if (history->priv->voltage_last == voltage)
return FALSE;
/* add to array and schedule save file */
item = up_history_item_new ();
up_history_item_set_time_to_present (item);
up_history_item_set_value (item, voltage);
up_history_item_set_state (item, history->priv->state);
g_ptr_array_add (history->priv->data_voltage, item);
up_history_schedule_save (history);
/* save last value */
history->priv->voltage_last = voltage;
return TRUE;
}
/** /**
* up_history_is_device_id_equal: * up_history_is_device_id_equal:
**/ **/
@ -907,6 +954,7 @@ up_history_init (UpHistory *history)
history->priv->data_charge = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); history->priv->data_charge = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
history->priv->data_time_full = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); history->priv->data_time_full = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
history->priv->data_time_empty = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); history->priv->data_time_empty = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
history->priv->data_voltage = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
history->priv->max_data_age = UP_HISTORY_DEFAULT_MAX_DATA_AGE; history->priv->max_data_age = UP_HISTORY_DEFAULT_MAX_DATA_AGE;
if (g_getenv ("UPOWER_HISTORY_DIR")) if (g_getenv ("UPOWER_HISTORY_DIR"))
@ -937,6 +985,7 @@ up_history_finalize (GObject *object)
g_ptr_array_unref (history->priv->data_charge); g_ptr_array_unref (history->priv->data_charge);
g_ptr_array_unref (history->priv->data_time_full); g_ptr_array_unref (history->priv->data_time_full);
g_ptr_array_unref (history->priv->data_time_empty); g_ptr_array_unref (history->priv->data_time_empty);
g_ptr_array_unref (history->priv->data_voltage);
g_free (history->priv->id); g_free (history->priv->id);
g_free (history->priv->dir); g_free (history->priv->dir);

View file

@ -55,6 +55,7 @@ typedef enum {
UP_HISTORY_TYPE_RATE, UP_HISTORY_TYPE_RATE,
UP_HISTORY_TYPE_TIME_FULL, UP_HISTORY_TYPE_TIME_FULL,
UP_HISTORY_TYPE_TIME_EMPTY, UP_HISTORY_TYPE_TIME_EMPTY,
UP_HISTORY_TYPE_VOLTAGE,
UP_HISTORY_TYPE_UNKNOWN UP_HISTORY_TYPE_UNKNOWN
} UpHistoryType; } UpHistoryType;
@ -81,6 +82,8 @@ gboolean up_history_set_time_full_data (UpHistory *history,
gint64 time); gint64 time);
gboolean up_history_set_time_empty_data (UpHistory *history, gboolean up_history_set_time_empty_data (UpHistory *history,
gint64 time); gint64 time);
gboolean up_history_set_voltage_data (UpHistory *history,
gdouble voltage);
void up_history_set_max_data_age (UpHistory *history, void up_history_set_max_data_age (UpHistory *history,
guint max_data_age); guint max_data_age);
gboolean up_history_save_data (UpHistory *history); gboolean up_history_save_data (UpHistory *history);

View file

@ -139,6 +139,9 @@ up_test_history_remove_temp_files (void)
filename = g_build_filename (history_dir, "history-rate-test.dat", NULL); filename = g_build_filename (history_dir, "history-rate-test.dat", NULL);
g_unlink (filename); g_unlink (filename);
g_free (filename); g_free (filename);
filename = g_build_filename (history_dir, "history-voltage-test.dat", NULL);
g_unlink (filename);
g_free (filename);
} }
static void static void
@ -178,18 +181,21 @@ up_test_history_func (void)
up_history_set_rate_data (history, 0.99f); up_history_set_rate_data (history, 0.99f);
up_history_set_time_empty_data (history, 12346); up_history_set_time_empty_data (history, 12346);
up_history_set_time_full_data (history, 54322); up_history_set_time_full_data (history, 54322);
up_history_set_voltage_data (history, 3.7f);
g_usleep (2 * G_USEC_PER_SEC); g_usleep (2 * G_USEC_PER_SEC);
up_history_set_charge_data (history, 90); up_history_set_charge_data (history, 90);
up_history_set_rate_data (history, 1.00f); up_history_set_rate_data (history, 1.00f);
up_history_set_time_empty_data (history, 12345); up_history_set_time_empty_data (history, 12345);
up_history_set_time_full_data (history, 54321); up_history_set_time_full_data (history, 54321);
up_history_set_voltage_data (history, 3.9f);
g_usleep (2 * G_USEC_PER_SEC); g_usleep (2 * G_USEC_PER_SEC);
up_history_set_charge_data (history, 95); up_history_set_charge_data (history, 95);
up_history_set_rate_data (history, 1.01f); up_history_set_rate_data (history, 1.01f);
up_history_set_time_empty_data (history, 12344); up_history_set_time_empty_data (history, 12344);
up_history_set_time_full_data (history, 54320); up_history_set_time_full_data (history, 54320);
up_history_set_voltage_data (history, 4.1f);
/* get data for last 10 seconds */ /* get data for last 10 seconds */
array = up_history_get_data (history, UP_HISTORY_TYPE_CHARGE, 10, 100); array = up_history_get_data (history, UP_HISTORY_TYPE_CHARGE, 10, 100);