Compare commits

...

7 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
9 changed files with 110 additions and 16 deletions

9
NEWS
View file

@ -1,3 +1,12 @@
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 Version 1.91.1
-------------- --------------
Released: 2026-02-10 Released: 2026-02-10

View file

@ -104,10 +104,11 @@ ExpectBatteryRecalibration=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

@ -1,5 +1,5 @@
project('upower', 'c', project('upower', 'c',
version: '1.91.1', version: '1.91.2',
license: 'GPLv2+', license: 'GPLv2+',
default_options: [ default_options: [
'buildtype=debugoptimized', 'buildtype=debugoptimized',

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

@ -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

@ -2364,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,

View file

@ -566,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;
@ -592,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))
@ -633,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);
@ -646,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);
} }
/** /**

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;