diff options
author | Stuart Hayhurst <stuart.a.hayhurst@gmail.com> | 2023-06-21 15:06:35 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2023-07-04 15:18:31 +0200 |
commit | d74536fa0ede7822f2db671a5e1785121d5b1946 (patch) | |
tree | 2ca37d7490d42ae49a3172ee8eec04e1a1a11a37 | |
parent | 648abe9c274271db18496b45c83545e24993a326 (diff) |
linux: Update present property on refresh
Some devices change the 'present' sysfs attribute after upower
registers them. This should be updated in upower, otherwise
applications will ignore present devices, or listen to absent devices.
Fixes: 0b7d7cfc08bf ("linux: Fix is-present for devices at startup")
-rw-r--r-- | src/linux/up-device-supply.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/linux/up-device-supply.c b/src/linux/up-device-supply.c index 8d0151e..4081322 100644 --- a/src/linux/up-device-supply.c +++ b/src/linux/up-device-supply.c @@ -255,6 +255,7 @@ up_device_supply_refresh_device (UpDeviceSupply *supply, GUdevDevice *native; gdouble percentage = 0.0f; UpDeviceLevel level = UP_DEVICE_LEVEL_NONE; + gboolean is_present = TRUE; native = G_UDEV_DEVICE (up_device_get_native (device)); @@ -262,10 +263,6 @@ up_device_supply_refresh_device (UpDeviceSupply *supply, if (!supply->priv->has_coldplug_values) { gchar *model_name; gchar *serial_number; - gboolean is_present = TRUE; - - if (g_udev_device_has_sysfs_attr_uncached (native, "present")) - is_present = g_udev_device_get_sysfs_attr_as_boolean_uncached (native, "present"); /* get values which may be blank */ model_name = up_device_supply_get_string (native, "model_name"); @@ -276,7 +273,6 @@ up_device_supply_refresh_device (UpDeviceSupply *supply, up_make_safe_string (serial_number); g_object_set (device, - "is-present", is_present, "model", model_name, "serial", serial_number, "is-rechargeable", TRUE, @@ -291,6 +287,10 @@ up_device_supply_refresh_device (UpDeviceSupply *supply, g_free (serial_number); } + /* Some devices change whether they're present or not */ + if (g_udev_device_has_sysfs_attr_uncached (native, "present")) + is_present = g_udev_device_get_sysfs_attr_as_boolean_uncached (native, "present"); + /* get a precise percentage */ percentage = g_udev_device_get_sysfs_attr_as_double_uncached (native, "capacity"); if (percentage == 0.0f) @@ -299,7 +299,10 @@ up_device_supply_refresh_device (UpDeviceSupply *supply, if (percentage < 0.0) { /* Probably talking to the device over Bluetooth */ state = UP_DEVICE_STATE_UNKNOWN; - g_object_set (device, "state", state, NULL); + g_object_set (device, + "state", state, + "is-present", is_present, + NULL); return FALSE; } @@ -314,6 +317,7 @@ up_device_supply_refresh_device (UpDeviceSupply *supply, "percentage", percentage, "battery-level", level, "state", state, + "is-present", is_present, NULL); return TRUE; |