From 66e7df1105bf4edffce4bf2458f113295780449b Mon Sep 17 00:00:00 2001 From: Benjamin Berg Date: Mon, 9 Aug 2021 13:23:02 +0200 Subject: [PATCH] Keep alive fprintd if any device is WARM or HOT This renames the internal "in-use" property to "busy" and redefines the value to be TRUE either if a client is connected or if the device is considered WARM or HOT. This prevents fprintd shutdown while devices are warm in order to ensure that the libfprint hardware protection is functional. --- src/device.c | 31 +++++++++++++++++++++++-------- src/manager.c | 22 +++++++++++----------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/device.c b/src/device.c index f8469b1..defaee2 100644 --- a/src/device.c +++ b/src/device.c @@ -127,7 +127,7 @@ G_DEFINE_TYPE_WITH_CODE (FprintDevice, fprint_device, enum fprint_device_properties { FPRINT_DEVICE_CONSTRUCT_DEV = 1, - FPRINT_DEVICE_IN_USE, + FPRINT_DEVICE_BUSY, }; enum fprint_device_signals { @@ -293,8 +293,10 @@ fprint_device_get_property (GObject *object, guint property_id, g_value_set_object (value, priv->dev); break; - case FPRINT_DEVICE_IN_USE: - g_value_set_boolean (value, g_hash_table_size (priv->clients) != 0); + case FPRINT_DEVICE_BUSY: + g_value_set_boolean (value, + g_hash_table_size (priv->clients) != 0 || + fp_device_get_temperature (priv->dev) > FP_TEMPERATURE_COLD); break; default: @@ -359,6 +361,14 @@ on_finger_status_changed (FprintDevice *rdev, g_debug ("Finger needed %d", needed); } +static void +on_temperature_changed (FprintDevice *rdev, + GParamSpec *spec, + FpDevice *device) +{ + g_object_notify (G_OBJECT (rdev), "busy"); +} + static void fprint_device_constructed (GObject *object) { @@ -383,6 +393,11 @@ fprint_device_constructed (GObject *object) rdev, G_CONNECT_SWAPPED); on_finger_status_changed (rdev, NULL, priv->dev); + g_signal_connect_object (priv->dev, "notify::temperature", + G_CALLBACK (on_temperature_changed), + rdev, G_CONNECT_SWAPPED); + on_temperature_changed (rdev, NULL, priv->dev); + G_OBJECT_CLASS (fprint_device_parent_class)->constructed (object); } @@ -405,11 +420,11 @@ fprint_device_class_init (FprintDeviceClass *klass) g_object_class_install_property (gobject_class, FPRINT_DEVICE_CONSTRUCT_DEV, pspec); - pspec = g_param_spec_boolean ("in-use", "In use", - "Whether the device is currently in use", FALSE, + pspec = g_param_spec_boolean ("busy", "Busy", + "Whether the device is in use or too warm", FALSE, G_PARAM_READABLE); g_object_class_install_property (gobject_class, - FPRINT_DEVICE_IN_USE, pspec); + FPRINT_DEVICE_BUSY, pspec); signals[SIGNAL_VERIFY_STATUS] = g_signal_lookup ("verify-status", FPRINT_TYPE_DEVICE); @@ -891,7 +906,7 @@ _fprint_device_client_vanished (GDBusConnection *connection, g_hash_table_remove (priv->clients, name); if (g_hash_table_size (priv->clients) == 0) - g_object_notify (G_OBJECT (rdev), "in-use"); + g_object_notify (G_OBJECT (rdev), "busy"); } static void @@ -911,7 +926,7 @@ _fprint_device_add_client (FprintDevice *rdev, const char *sender) rdev, NULL); g_hash_table_insert (priv->clients, g_strdup (sender), GUINT_TO_POINTER (id)); - g_object_notify (G_OBJECT (rdev), "in-use"); + g_object_notify (G_OBJECT (rdev), "busy"); } } diff --git a/src/manager.c b/src/manager.c index 7e49953..38c5a54 100644 --- a/src/manager.c +++ b/src/manager.c @@ -152,14 +152,14 @@ fprint_manager_timeout_cb (FprintManager *manager) } static void -fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintManager *manager) +fprint_manager_busy_notified (FprintDevice *rdev, GParamSpec *spec, FprintManager *manager) { FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager); - guint num_devices_used = 0; + guint num_devices_busy = 0; g_autolist (GDBusObject) devices = NULL; GList *l; - gboolean in_use; + gboolean busy; if (priv->timeout_id > 0) { @@ -177,12 +177,12 @@ fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintMana FprintDBusObjectSkeleton *object = l->data; dev = fprint_dbus_object_skeleton_get_device (object); - g_object_get (G_OBJECT (dev), "in-use", &in_use, NULL); - if (in_use != FALSE) - num_devices_used++; + g_object_get (G_OBJECT (dev), "busy", &busy, NULL); + if (busy != FALSE) + num_devices_busy++; } - if (num_devices_used == 0) + if (num_devices_busy == 0) priv->timeout_id = g_timeout_add_seconds (TIMEOUT, (GSourceFunc) fprint_manager_timeout_cb, manager); } @@ -238,8 +238,8 @@ device_added_cb (FprintManager *manager, FpDevice *device, FpContext *context) rdev = fprint_device_new (device); - g_signal_connect (G_OBJECT (rdev), "notify::in-use", - G_CALLBACK (fprint_manager_in_use_notified), manager); + g_signal_connect (G_OBJECT (rdev), "notify::busy", + G_CALLBACK (fprint_manager_busy_notified), manager); path = get_device_path (rdev); @@ -282,9 +282,9 @@ device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context) break; } - /* The device that disappeared might have been in-use. + /* The device that disappeared might have been busy. * Do we need to do anything else in this case to clean up more gracefully? */ - fprint_manager_in_use_notified (NULL, NULL, manager); + fprint_manager_busy_notified (NULL, NULL, manager); } static void