From 4722fcfaac7a78221c538f03def2252af2af02ba Mon Sep 17 00:00:00 2001 From: Kate Hsuan Date: Thu, 18 Sep 2025 16:18:52 +0800 Subject: [PATCH] up-config: introduce the ExpectBatteryReCalibration for battery recalibration ExpectBatteryReCalibration allows the user to ignore the CriticalPowerAction when performing the battery recalibration. --- etc/UPower.conf | 9 +++++++++ src/up-config.c | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/etc/UPower.conf b/etc/UPower.conf index 76ddda4..6472186 100644 --- a/etc/UPower.conf +++ b/etc/UPower.conf @@ -88,6 +88,15 @@ TimeAction=120 # Default is 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 # reached for the batteries (UPS or laptop batteries) supplying the computer # diff --git a/src/up-config.c b/src/up-config.c index 836c993..fa4c717 100644 --- a/src/up-config.c +++ b/src/up-config.c @@ -247,6 +247,7 @@ static void up_config_init (UpConfig *config) { gboolean allow_risky_critical_action = FALSE; + gboolean expect_battery_recalibration = FALSE; g_autofree gchar *critical_action = NULL; g_autoptr (GError) error = NULL; g_autofree gchar *filename = NULL; @@ -308,6 +309,17 @@ up_config_init (UpConfig *config) " 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."); + } + } } /**