diff options
author | Kate Hsuan <hpa@redhat.com> | 2024-08-21 14:54:32 +0800 |
---|---|---|
committer | Kate Hsuan <hpa@redhat.com> | 2024-08-22 14:20:33 +0800 |
commit | 399ec5d1ec969b476fb2691d2a9526f8055ba7dc (patch) | |
tree | dfeb63bcabccbd5a41ab3f3f153ee9f1ad2954fd | |
parent | 5882721f19c872726842b90538698df64e15a211 (diff) |
linux: up-device-supply-battery: Don't report error when one of the start/stop charge threshold isn't writable
One of the charge_control_start|end_threshold isn't writable for some
systems, for example, Macbook Air. Therefore, if both files can't be
written, the error is returned.
-rw-r--r-- | src/linux/up-device-supply-battery.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/linux/up-device-supply-battery.c b/src/linux/up-device-supply-battery.c index 770ad2c..85e04dc 100644 --- a/src/linux/up-device-supply-battery.c +++ b/src/linux/up-device-supply-battery.c @@ -395,6 +395,7 @@ up_device_supply_device_path (GUdevDevice *device) static gboolean up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint start, guint end, GError **error) { + guint err_count = 0; GUdevDevice *native; g_autofree gchar *native_path = NULL; g_autofree gchar *start_filename = NULL; @@ -411,7 +412,7 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s g_string_printf (start_str, "%d", CLAMP (start, 0, 100)); if (!g_file_set_contents_full (start_filename, start_str->str, start_str->len, G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) { - return FALSE; + err_count++; } } else { g_debug ("Ignore charge_control_start_threshold setting"); @@ -421,12 +422,18 @@ up_device_supply_battery_set_battery_charge_thresholds(UpDevice *device, guint s g_string_printf (end_str, "%d", CLAMP (end, 0, 100)); if (!g_file_set_contents_full (end_filename, end_str->str, end_str->len, G_FILE_SET_CONTENTS_ONLY_EXISTING, 0644, error)) { - return FALSE; + err_count++; } } else { g_debug ("Ignore charge_control_end_threshold setting"); } + if (err_count == 2) { + g_set_error_literal (error, G_IO_ERROR, + G_IO_ERROR_FAILED, "Failed to set charge control thresholds"); + return FALSE; + } + return TRUE; } |