diff options
author | Benjamin Berg <bberg@redhat.com> | 2022-05-12 19:09:16 +0200 |
---|---|---|
committer | Benjamin Berg <bberg@redhat.com> | 2022-05-13 16:07:38 +0200 |
commit | b34296440009ffb5621ac5cfc944b919e1eccbcc (patch) | |
tree | 985c8732402ad537e9f662925f645687f9feb05c | |
parent | 90c84ea95c45aedb2b778634871fdbbed572b327 (diff) |
linux: Re-poll batteries after a line power change
When a change on a line power occurs, then re-poll all batteries
aggressively for a while. It is very common for batteries to take about
a second to refresh their state and many will not send appropriate
notifications in this case.
Closes: #179, #159
-rw-r--r-- | src/linux/meson.build | 1 | ||||
-rw-r--r-- | src/linux/up-backend-linux-private.h | 29 | ||||
-rw-r--r-- | src/linux/up-backend.c | 9 | ||||
-rw-r--r-- | src/linux/up-device-supply.c | 23 | ||||
-rw-r--r-- | src/up-daemon.c | 2 | ||||
-rw-r--r-- | src/up-device.h | 2 |
6 files changed, 13 insertions, 53 deletions
diff --git a/src/linux/meson.build b/src/linux/meson.build index e952f3d..b77cd29 100644 --- a/src/linux/meson.build +++ b/src/linux/meson.build @@ -19,7 +19,6 @@ upshared += { 'linux': static_library('upshared', 'up-input.c', 'up-input.h', 'up-backend.c', - 'up-backend-linux-private.h', 'up-native.c', idevice_sources ], diff --git a/src/linux/up-backend-linux-private.h b/src/linux/up-backend-linux-private.h deleted file mode 100644 index 0e6e77c..0000000 --- a/src/linux/up-backend-linux-private.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2018 Bastien Nocera <hadess@hadess.net> - * - * 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_BACKEND_LINUX_PRIVATE_H -#define __UP_BACKEND_LINUX_PRIVATE_H - -#include <glib.h> - -gboolean up_backend_needs_poll_after_uevent (void); - -#endif /* __UP_BACKEND_LINUX_PRIVATE_H */ diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index 613e912..e183825 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -31,7 +31,6 @@ #include <gudev/gudev.h> #include "up-backend.h" -#include "up-backend-linux-private.h" #include "up-daemon.h" #include "up-device.h" @@ -101,14 +100,6 @@ is_macbook (gpointer data) return GINT_TO_POINTER(g_str_has_prefix (product, "MacBook")); } -gboolean -up_backend_needs_poll_after_uevent (void) -{ - static GOnce dmi_once = G_ONCE_INIT; - g_once (&dmi_once, is_macbook, NULL); - return GPOINTER_TO_INT(dmi_once.retval); -} - static UpDevice * up_backend_device_new (UpBackend *backend, GUdevDevice *native) { diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index 0aea9cb..41bf94b 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -35,7 +35,6 @@ #include "up-types.h" #include "up-constants.h" #include "up-device-supply.h" -#include "up-backend-linux-private.h" enum { PROP_0, @@ -1161,15 +1160,20 @@ up_device_supply_update_poll_frequency (UpDevice *device, return; /* We start fast-polling if the reason to update was not a normal POLL - * and the state is either unknown or we are in quirk mode and expect - * the battery to return unstable values for a while. + * and one of the following holds true: + * 1. The current stat is unknown; we hope that this is transient + * and re-poll. + * 2. A change occured on a line power supply. This likely means that + * batteries switch between charging/discharging which does not + * always result in a separate uevent. * - * We stop again when: - * 1. The state is known and we are NOT in quirk mode - * 2. The timeout elapsed + * For simplicity, we do the fast polling for a specific period of time. + * If the reason to do fast-polling was an unknown state, then it would + * also be reasonable to stop as soon as we got a proper state. */ if (reason != UP_REFRESH_POLL && - (state == UP_DEVICE_STATE_UNKNOWN || up_backend_needs_poll_after_uevent ())) { + (state == UP_DEVICE_STATE_UNKNOWN || + reason == UP_REFRESH_LINE_POWER)) { g_debug ("unknown_poll: setting up fast re-poll"); g_object_set (device, "poll-timeout", UP_DAEMON_UNKNOWN_TIMEOUT, NULL); supply->priv->fast_repoll_until = g_get_monotonic_time () + UP_DAEMON_UNKNOWN_POLL_TIME * G_USEC_PER_SEC; @@ -1177,11 +1181,6 @@ up_device_supply_update_poll_frequency (UpDevice *device, } else if (supply->priv->fast_repoll_until == 0) { /* Not fast-repolling, no need to check whether to stop */ - } else if (state != UP_DEVICE_STATE_UNKNOWN && !up_backend_needs_poll_after_uevent ()) { - g_debug ("unknown_poll: stopping fast repoll (not needed anymore)"); - supply->priv->fast_repoll_until = 0; - g_object_set (device, "poll-timeout", UP_DAEMON_SHORT_TIMEOUT, NULL); - } else if (supply->priv->fast_repoll_until < g_get_monotonic_time ()) { g_debug ("unknown_poll: stopping fast repoll (giving up)"); supply->priv->fast_repoll_until = 0; diff --git a/src/up-daemon.c b/src/up-daemon.c index c99da96..52264f3 100644 --- a/src/up-daemon.c +++ b/src/up-daemon.c @@ -375,7 +375,7 @@ up_daemon_refresh_battery_devices_idle (UpDaemon *daemon) NULL); if (type == UP_DEVICE_KIND_BATTERY && power_supply) - up_device_refresh_internal (device, UP_REFRESH_CHANGES); + up_device_refresh_internal (device, UP_REFRESH_LINE_POWER); } g_ptr_array_unref (array); diff --git a/src/up-device.h b/src/up-device.h index d8bcd33..8f0c0c6 100644 --- a/src/up-device.h +++ b/src/up-device.h @@ -36,7 +36,7 @@ typedef enum { UP_REFRESH_POLL, UP_REFRESH_RESUME, UP_REFRESH_EVENT, - UP_REFRESH_CHANGES, + UP_REFRESH_LINE_POWER, } UpRefreshReason; struct _UpDeviceClass |