up-config: introduce the ExpectBatteryReCalibration for battery recalibration

ExpectBatteryReCalibration allows the user to ignore the
CriticalPowerAction when performing the battery recalibration.
This commit is contained in:
Kate Hsuan 2025-09-18 16:18:52 +08:00
parent 1ba5f3a55e
commit 4722fcfaac
2 changed files with 21 additions and 0 deletions

View file

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

View file

@ -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.");
}
}
}
/**