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.
This commit is contained in:
Benjamin Berg
2021-08-09 13:23:02 +02:00
parent 96b911913e
commit 66e7df1105
2 changed files with 34 additions and 19 deletions

View File

@ -127,7 +127,7 @@ G_DEFINE_TYPE_WITH_CODE (FprintDevice, fprint_device,
enum fprint_device_properties { enum fprint_device_properties {
FPRINT_DEVICE_CONSTRUCT_DEV = 1, FPRINT_DEVICE_CONSTRUCT_DEV = 1,
FPRINT_DEVICE_IN_USE, FPRINT_DEVICE_BUSY,
}; };
enum fprint_device_signals { enum fprint_device_signals {
@ -293,8 +293,10 @@ fprint_device_get_property (GObject *object, guint property_id,
g_value_set_object (value, priv->dev); g_value_set_object (value, priv->dev);
break; break;
case FPRINT_DEVICE_IN_USE: case FPRINT_DEVICE_BUSY:
g_value_set_boolean (value, g_hash_table_size (priv->clients) != 0); g_value_set_boolean (value,
g_hash_table_size (priv->clients) != 0 ||
fp_device_get_temperature (priv->dev) > FP_TEMPERATURE_COLD);
break; break;
default: default:
@ -359,6 +361,14 @@ on_finger_status_changed (FprintDevice *rdev,
g_debug ("Finger needed %d", needed); 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 static void
fprint_device_constructed (GObject *object) fprint_device_constructed (GObject *object)
{ {
@ -383,6 +393,11 @@ fprint_device_constructed (GObject *object)
rdev, G_CONNECT_SWAPPED); rdev, G_CONNECT_SWAPPED);
on_finger_status_changed (rdev, NULL, priv->dev); 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); 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, g_object_class_install_property (gobject_class,
FPRINT_DEVICE_CONSTRUCT_DEV, pspec); FPRINT_DEVICE_CONSTRUCT_DEV, pspec);
pspec = g_param_spec_boolean ("in-use", "In use", pspec = g_param_spec_boolean ("busy", "Busy",
"Whether the device is currently in use", FALSE, "Whether the device is in use or too warm", FALSE,
G_PARAM_READABLE); G_PARAM_READABLE);
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
FPRINT_DEVICE_IN_USE, pspec); FPRINT_DEVICE_BUSY, pspec);
signals[SIGNAL_VERIFY_STATUS] = signals[SIGNAL_VERIFY_STATUS] =
g_signal_lookup ("verify-status", FPRINT_TYPE_DEVICE); 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); g_hash_table_remove (priv->clients, name);
if (g_hash_table_size (priv->clients) == 0) 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 static void
@ -911,7 +926,7 @@ _fprint_device_add_client (FprintDevice *rdev, const char *sender)
rdev, rdev,
NULL); NULL);
g_hash_table_insert (priv->clients, g_strdup (sender), GUINT_TO_POINTER (id)); 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");
} }
} }

View File

@ -152,14 +152,14 @@ fprint_manager_timeout_cb (FprintManager *manager)
} }
static void 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); FprintManagerPrivate *priv = fprint_manager_get_instance_private (manager);
guint num_devices_used = 0; guint num_devices_busy = 0;
g_autolist (GDBusObject) devices = NULL; g_autolist (GDBusObject) devices = NULL;
GList *l; GList *l;
gboolean in_use; gboolean busy;
if (priv->timeout_id > 0) if (priv->timeout_id > 0)
{ {
@ -177,12 +177,12 @@ fprint_manager_in_use_notified (FprintDevice *rdev, GParamSpec *spec, FprintMana
FprintDBusObjectSkeleton *object = l->data; FprintDBusObjectSkeleton *object = l->data;
dev = fprint_dbus_object_skeleton_get_device (object); dev = fprint_dbus_object_skeleton_get_device (object);
g_object_get (G_OBJECT (dev), "in-use", &in_use, NULL); g_object_get (G_OBJECT (dev), "busy", &busy, NULL);
if (in_use != FALSE) if (busy != FALSE)
num_devices_used++; 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); 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); rdev = fprint_device_new (device);
g_signal_connect (G_OBJECT (rdev), "notify::in-use", g_signal_connect (G_OBJECT (rdev), "notify::busy",
G_CALLBACK (fprint_manager_in_use_notified), manager); G_CALLBACK (fprint_manager_busy_notified), manager);
path = get_device_path (rdev); path = get_device_path (rdev);
@ -282,9 +282,9 @@ device_removed_cb (FprintManager *manager, FpDevice *device, FpContext *context)
break; 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? */ * 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 static void