Compare commits

..

8 Commits

Author SHA1 Message Date
Benjamin Berg
664126b431 elanspi: Do not allow image captures to be interrupted
Avoid unexpected state changes during image capture. This also means
that the old line handler does not need to check for cancellation.
2021-12-27 12:19:10 +01:00
Benjamin Berg
7b1fe6ec19 ssm: Allow marking an SSM as being critical
This way the SSM cannot be interrupted while it is running.
2021-12-27 12:13:12 +01:00
Dmitrii Shcherbakov
999bca076c Allow FpPrint data to be extended on enrollment.
* Allow FPI_PRINT_NBIS to be extended rather than overridden if a user
  supplies an existing FpPrint template with data;
* Prints will only be extended if a device has the required feature.
  For image-based devices this feature is added by default since they
  typically do not have storage (this can be overridden at the child
  class level).

Extending an existing FpPrint requires passing a template print with
existing data during the enrollment process. This is done because the
caller is responsible for maintaining the fingerprint database and doing
the necessary deserialization operations if needed. The existing
example program is updated to show how to do that.
2021-12-16 12:53:41 +01:00
Benjamin Berg
e198b04222 elanspi: Silence some SSMs that may log excessively otherwise 2021-12-02 13:54:59 +01:00
Benjamin Berg
3981c42d3e ssm: Add API to silence most state change debug messages
Otherwise tightly looping SSMs (primarily SPI transfers), will flood the
logs in inappropriate ways.
2021-12-02 13:54:59 +01:00
Benjamin Berg
31afd3ba5c elanspi: Move debug print so that it contains all information
Two of the printed variables were only calculated after the message was
printed, making the logged information less useful than it could be.
2021-12-02 13:53:54 +01:00
Benjamin Berg
05fd2c58cb context: Ensure mainloop is idle before enumeration completes
This ensures that we have processed all hotplug events before
considering enumeration to be complete. This is important due to USB
persist being turned off. At resume time, devices will disappear and
immediately re-appear. In this situatoin, enumerate could first see the
old state with a removed device resulting in it to not be discovered.

As a hotplug event is semingly emitted by the kernel immediately, we
can simply make sure to process this hotplug event before returning
from enumerate.

Closes: fprintd#119
2021-12-01 15:29:18 +00:00
Matthew Mirvish
a033154b2e doc: Fix broken documentation for FpiDeviceUdevSubtypeFlags enum
Added description and fixed incorrect name in comment, so now gtkdoc
actually shows useful information.
2021-11-15 17:10:44 -05:00
15 changed files with 392 additions and 78 deletions

View File

@@ -247,6 +247,7 @@ fpi_ssm_new_full
fpi_ssm_free
fpi_ssm_start
fpi_ssm_start_subsm
fpi_ssm_set_critical
fpi_ssm_next_state
fpi_ssm_next_state_delayed
fpi_ssm_jump_to_state
@@ -260,6 +261,7 @@ fpi_ssm_get_device
fpi_ssm_get_error
fpi_ssm_dup_error
fpi_ssm_get_cur_state
fpi_ssm_silence_debug
fpi_ssm_spi_transfer_cb
fpi_ssm_spi_transfer_with_weak_pointer_cb
fpi_ssm_usb_transfer_cb

View File

@@ -35,6 +35,7 @@ typedef struct _EnrollData
unsigned int sigint_handler;
FpFinger finger;
int ret_value;
gboolean update_fingerprint;
} EnrollData;
static void
@@ -84,7 +85,8 @@ on_enroll_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
/* Even if the device has storage, it may not be able to save all the
* metadata that the print contains, so we can always save a local copy
* containing the handle to the device print */
int r = print_data_save (print, enroll_data->finger);
int r = print_data_save (print, enroll_data->finger,
enroll_data->update_fingerprint);
if (r < 0)
{
g_warning ("Data save failed, code %d", r);
@@ -124,6 +126,40 @@ on_enroll_progress (FpDevice *device,
fp_device_get_nr_enroll_stages (device));
}
static gboolean
should_update_fingerprint (void)
{
int update_choice;
gboolean update_fingerprint = FALSE;
printf ("Should an existing fingerprint be updated instead of being replaced (if present)? "
"Enter Y/y or N/n to make a choice.\n");
update_choice = getchar ();
if (update_choice == EOF)
{
g_warning ("EOF encountered while reading a character");
return EXIT_FAILURE;
}
switch (update_choice)
{
case 'y':
case 'Y':
update_fingerprint = TRUE;
break;
case 'n':
case 'N':
update_fingerprint = FALSE;
break;
default:
g_warning ("Invalid choice %c, should be Y/y or N/n.", update_choice);
return EXIT_FAILURE;
}
return update_fingerprint;
}
static void
on_device_opened (FpDevice *dev, GAsyncResult *res, void *user_data)
{
@@ -139,13 +175,26 @@ on_device_opened (FpDevice *dev, GAsyncResult *res, void *user_data)
return;
}
printf ("Opened device. It's now time to enroll your finger.\n\n");
printf ("Opened device.\n");
if (fp_device_has_feature (dev, FP_DEVICE_FEATURE_UPDATE_PRINT))
{
printf ("The device supports fingerprint updates.\n");
enroll_data->update_fingerprint = should_update_fingerprint ();
}
else
{
printf ("The device doesn't support fingerprint updates. Old prints will be erased.\n");
enroll_data->update_fingerprint = FALSE;
}
printf ("It's now time to enroll your finger.\n\n");
printf ("You will need to successfully scan your %s finger %d times to "
"complete the process.\n\n", finger_to_string (enroll_data->finger),
fp_device_get_nr_enroll_stages (dev));
printf ("Scan your finger now.\n");
print_template = print_create_template (dev, enroll_data->finger);
print_template = print_create_template (dev, enroll_data->finger, enroll_data->update_fingerprint);
fp_device_enroll (dev, print_template, enroll_data->cancellable,
on_enroll_progress, NULL, NULL,
(GAsyncReadyCallback) on_enroll_completed,
@@ -171,11 +220,9 @@ main (void)
FpDevice *dev;
FpFinger finger;
g_print ("This program will enroll the selected finger, unconditionally "
"overwriting any print for the same finger that was enrolled "
"previously. If you want to continue, press enter, otherwise hit "
"Ctrl+C\n");
getchar ();
g_print ("This program will enroll the selected finger overwriting any print for the same"
" finger that was enrolled previously. Fingerprint updates without erasing old data"
" are possible on devices supporting that. Ctrl+C interrupts program execution.\n");
g_print ("Choose the finger to enroll:\n");
finger = finger_chooser ();

View File

@@ -102,8 +102,23 @@ save_data (GVariant *data)
return 0;
}
static FpPrint *
load_print_from_data (GVariant *data)
{
const guchar *stored_data = NULL;
gsize stored_len;
FpPrint *print;
g_autoptr(GError) error = NULL;
stored_data = (const guchar *) g_variant_get_fixed_array (data, &stored_len, 1);
print = fp_print_deserialize (stored_data, stored_len, &error);
if (error)
g_warning ("Error deserializing data: %s", error->message);
return print;
}
int
print_data_save (FpPrint *print, FpFinger finger)
print_data_save (FpPrint *print, FpFinger finger, gboolean update_fingerprint)
{
g_autofree gchar *descr = get_print_data_descriptor (print, NULL, finger);
@@ -137,25 +152,12 @@ print_data_load (FpDevice *dev, FpFinger finger)
g_autoptr(GVariant) val = NULL;
g_autoptr(GVariantDict) dict = NULL;
const guchar *stored_data = NULL;
gsize stored_len;
dict = load_data ();
val = g_variant_dict_lookup_value (dict, descr, G_VARIANT_TYPE ("ay"));
if (val)
{
FpPrint *print;
g_autoptr(GError) error = NULL;
stored_data = (const guchar *) g_variant_get_fixed_array (val, &stored_len, 1);
print = fp_print_deserialize (stored_data, stored_len, &error);
if (error)
g_warning ("Error deserializing data: %s", error->message);
return print;
}
return load_print_from_data (val);
return NULL;
}
@@ -207,16 +209,30 @@ gallery_data_load (FpDevice *dev)
}
FpPrint *
print_create_template (FpDevice *dev, FpFinger finger)
print_create_template (FpDevice *dev, FpFinger finger, gboolean load_existing)
{
g_autoptr(GVariantDict) dict = NULL;
g_autoptr(GDateTime) datetime = NULL;
g_autoptr(GDate) date = NULL;
g_autoptr(GVariant) existing_val = NULL;
g_autofree gchar *descr = get_print_data_descriptor (NULL, dev, finger);
FpPrint *template = NULL;
gint year, month, day;
template = fp_print_new (dev);
fp_print_set_finger (template, finger);
fp_print_set_username (template, g_get_user_name ());
if (load_existing)
{
dict = load_data ();
existing_val = g_variant_dict_lookup_value (dict, descr, G_VARIANT_TYPE ("ay"));
if (existing_val != NULL)
template = load_print_from_data (existing_val);
}
if (template == NULL)
{
template = fp_print_new (dev);
fp_print_set_finger (template, finger);
fp_print_set_username (template, g_get_user_name ());
}
datetime = g_date_time_new_now_local ();
g_date_time_get_ymd (datetime, &year, &month, &day);
date = g_date_new_dmy (day, month, year);

View File

@@ -21,12 +21,14 @@
#pragma once
int print_data_save (FpPrint *print,
FpFinger finger);
FpFinger finger,
gboolean update_fingerprint);
FpPrint * print_data_load (FpDevice *dev,
FpFinger finger);
GPtrArray * gallery_data_load (FpDevice *dev);
FpPrint * print_create_template (FpDevice *dev,
FpFinger finger);
FpPrint * print_create_template (FpDevice *dev,
FpFinger finger,
const gboolean load_existing);
gboolean print_image_save (FpPrint *print,
const char *path);
gboolean save_image_to_pgm (FpImage *img,

View File

@@ -434,21 +434,9 @@ elanspi_capture_old_line_handler (FpiSpiTransfer *transfer, FpDevice *dev, gpoin
self->old_data.line_ptr += 1;
/* if there is still data, continue from check lineready */
if (self->old_data.line_ptr < self->sensor_height)
{
fpi_ssm_jump_to_state (transfer->ssm, ELANSPI_CAPTOLD_CHECK_LINEREADY);
}
fpi_ssm_jump_to_state (transfer->ssm, ELANSPI_CAPTOLD_CHECK_LINEREADY);
else
{
/* check for cancellation */
if (fpi_device_action_is_cancelled (dev))
{
g_cancellable_set_error_if_cancelled (fpi_device_get_cancellable (dev), &error);
fpi_ssm_mark_failed (transfer->ssm, error);
return;
}
/* otherwise finish succesfully */
fpi_ssm_mark_completed (transfer->ssm);
}
fpi_ssm_mark_completed (transfer->ssm);
}
static void
@@ -606,6 +594,8 @@ elanspi_calibrate_old_handler (FpiSsm *ssm, FpDevice *dev)
case ELANSPI_CALIBOLD_CHECKFIN_CAPTURE:
case ELANSPI_CALIBOLD_DACFINE_CAPTURE:
chld = fpi_ssm_new (dev, elanspi_capture_old_handler, ELANSPI_CAPTOLD_NSTATES);
fpi_ssm_silence_debug (chld);
fpi_ssm_set_critical (chld);
fpi_ssm_start_subsm (ssm, chld);
return;
@@ -860,6 +850,8 @@ elanspi_calibrate_hv_handler (FpiSsm *ssm, FpDevice *dev)
case ELANSPI_CALIBHV_CAPTURE:
chld = fpi_ssm_new (dev, elanspi_capture_hv_handler, ELANSPI_CAPTHV_NSTATES);
fpi_ssm_silence_debug (chld);
fpi_ssm_set_critical (chld);
fpi_ssm_start_subsm (ssm, chld);
return;
@@ -1115,6 +1107,8 @@ do_sw_reset:
chld = fpi_ssm_new_full (dev, elanspi_calibrate_hv_handler, ELANSPI_CALIBHV_NSTATES, ELANSPI_CALIBHV_PROTECT, "HV calibrate");
else
chld = fpi_ssm_new_full (dev, elanspi_calibrate_old_handler, ELANSPI_CALIBOLD_NSTATES, ELANSPI_CALIBOLD_PROTECT, "old calibrate");
fpi_ssm_silence_debug (chld);
fpi_ssm_set_critical (chld);
fpi_ssm_start_subsm (ssm, chld);
return;
@@ -1123,6 +1117,8 @@ do_sw_reset:
chld = fpi_ssm_new (dev, elanspi_capture_hv_handler, ELANSPI_CAPTHV_NSTATES);
else
chld = fpi_ssm_new (dev, elanspi_capture_old_handler, ELANSPI_CAPTOLD_NSTATES);
fpi_ssm_silence_debug (chld);
fpi_ssm_set_critical (chld);
fpi_ssm_start_subsm (ssm, chld);
return;
@@ -1219,8 +1215,6 @@ elanspi_guess_image (FpiDeviceElanSpi *self, guint16 *raw_image)
sq_stddev /= (frame_width * frame_height);
fp_dbg ("<guess> stddev=%" G_GUINT64_FORMAT "d, ip=%d, is_fp=%d, is_empty=%d", sq_stddev, invalid_percent, is_fp, is_empty);
if (invalid_percent < ELANSPI_MAX_REAL_INVALID_PERCENT)
is_fp += 1;
if (invalid_percent > ELANSPI_MIN_EMPTY_INVALID_PERCENT)
@@ -1231,6 +1225,8 @@ elanspi_guess_image (FpiDeviceElanSpi *self, guint16 *raw_image)
if (sq_stddev < ELANSPI_MAX_EMPTY_STDDEV)
is_empty += 1;
fp_dbg ("<guess> stddev=%" G_GUINT64_FORMAT "d, ip=%d, is_fp=%d, is_empty=%d", sq_stddev, invalid_percent, is_fp, is_empty);
if (is_fp > is_empty)
return ELANSPI_GUESS_FINGERPRINT;
else if (is_empty > is_fp)
@@ -1495,6 +1491,8 @@ elanspi_fp_capture_ssm_handler (FpiSsm *ssm, FpDevice *dev)
chld = fpi_ssm_new (dev, elanspi_capture_hv_handler, ELANSPI_CAPTHV_NSTATES);
else
chld = fpi_ssm_new (dev, elanspi_capture_old_handler, ELANSPI_CAPTOLD_NSTATES);
fpi_ssm_silence_debug (chld);
fpi_ssm_set_critical (chld);
fpi_ssm_start_subsm (ssm, chld);
return;

View File

@@ -426,6 +426,7 @@ void
fp_context_enumerate (FpContext *context)
{
FpContextPrivate *priv = fp_context_get_instance_private (context);
gboolean dispatched;
gint i;
g_return_if_fail (FP_IS_CONTEXT (context));
@@ -564,8 +565,19 @@ fp_context_enumerate (FpContext *context)
}
#endif
while (priv->pending_devices)
g_main_context_iteration (NULL, TRUE);
/* Iterate until 1. we have no pending devices, and 2. the mainloop is idle
* This takes care of processing hotplug events that happened during
* enumeration.
* This is important due to USB `persist` being turned off. At resume time,
* devices will disappear and immediately re-appear. In this situation,
* enumerate could first see the old state with a removed device resulting
* in it to not be discovered.
* As a hotplug event is seemingly emitted by the kernel immediately, we can
* simply make sure to process all events before returning from enumerate.
*/
dispatched = TRUE;
while (priv->pending_devices || dispatched)
dispatched = g_main_context_iteration (NULL, !!priv->pending_devices);
}
/**

View File

@@ -1189,10 +1189,11 @@ fp_device_resume_finish (FpDevice *device,
* fp_device_enroll_finish().
*
* The @template_print parameter is a #FpPrint with available metadata filled
* in. The driver may make use of this metadata, when e.g. storing the print on
* device memory. It is undefined whether this print is filled in by the driver
* and returned, or whether the driver will return a newly created print after
* enrollment succeeded.
* in and, optionally, with existing fingerprint data to be updated with newly
* enrolled fingerprints if a device driver supports it. The driver may make use
* of the metadata, when e.g. storing the print on device memory. It is undefined
* whether this print is filled in by the driver and returned, or whether the
* driver will return a newly created print after enrollment succeeded.
*/
void
fp_device_enroll (FpDevice *device,
@@ -1229,19 +1230,30 @@ fp_device_enroll (FpDevice *device,
if (!FP_IS_PRINT (template_print))
{
g_warning ("User did not pass a print template!");
g_task_return_error (task,
fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
"User did not pass a print template!"));
return;
}
g_object_get (template_print, "fpi-type", &print_type, NULL);
if (print_type != FPI_PRINT_UNDEFINED)
{
g_warning ("Passed print template must be newly created and blank!");
g_task_return_error (task,
fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID));
return;
if (!fp_device_has_feature (device, FP_DEVICE_FEATURE_UPDATE_PRINT))
{
g_task_return_error (task,
fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
"A device does not support print updates!"));
return;
}
if (!fp_print_compatible (template_print, device))
{
g_task_return_error (task,
fpi_device_error_new_msg (FP_DEVICE_ERROR_DATA_INVALID,
"The print and device must have a matching driver and device id"
" for a fingerprint update to succeed"));
return;
}
}
priv->current_action = FPI_DEVICE_ACTION_ENROLL;

View File

@@ -59,6 +59,7 @@ typedef enum {
* @FP_DEVICE_FEATURE_STORAGE_CLEAR: Supports clearing the whole storage
* @FP_DEVICE_FEATURE_DUPLICATES_CHECK: Natively supports duplicates detection
* @FP_DEVICE_FEATURE_ALWAYS_ON: Whether the device can run continuously
* @FP_DEVICE_FEATURE_UPDATE_PRINT: Supports updating an existing print record using new scans
*/
typedef enum /*< flags >*/ {
FP_DEVICE_FEATURE_NONE = 0,
@@ -71,6 +72,7 @@ typedef enum /*< flags >*/ {
FP_DEVICE_FEATURE_STORAGE_CLEAR = 1 << 6,
FP_DEVICE_FEATURE_DUPLICATES_CHECK = 1 << 7,
FP_DEVICE_FEATURE_ALWAYS_ON = 1 << 8,
FP_DEVICE_FEATURE_UPDATE_PRINT = 1 << 9,
} FpDeviceFeature;
/**

View File

@@ -101,6 +101,7 @@ fp_image_device_start_capture_action (FpDevice *device)
FpImageDevice *self = FP_IMAGE_DEVICE (device);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpiDeviceAction action;
FpiPrintType print_type;
/* There is just one action that we cannot support out
* of the box, which is a capture without first waiting
@@ -124,7 +125,9 @@ fp_image_device_start_capture_action (FpDevice *device)
FpPrint *enroll_print = NULL;
fpi_device_get_enroll_data (device, &enroll_print);
fpi_print_set_type (enroll_print, FPI_PRINT_NBIS);
g_object_get (enroll_print, "fpi-type", &print_type, NULL);
if (print_type != FPI_PRINT_NBIS)
fpi_print_set_type (enroll_print, FPI_PRINT_NBIS);
}
priv->enroll_stage = 0;
@@ -221,6 +224,7 @@ fp_image_device_class_init (FpImageDeviceClass *klass)
fp_device_class->cancel = fp_image_device_cancel_action;
fpi_device_class_auto_initialize_features (fp_device_class);
fp_device_class->features |= FP_DEVICE_FEATURE_UPDATE_PRINT;
/* Default implementations */
klass->activate = fp_image_device_default_activate;

View File

@@ -61,6 +61,7 @@ enum {
/* Private property*/
PROP_FPI_TYPE,
PROP_FPI_DATA,
PROP_FPI_PRINTS,
N_PROPS
};
@@ -133,6 +134,10 @@ fp_print_get_property (GObject *object,
g_value_set_variant (value, self->data);
break;
case PROP_FPI_PRINTS:
g_value_set_pointer (value, self->prints);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -188,6 +193,11 @@ fp_print_set_property (GObject *object,
self->data = g_value_dup_variant (value);
break;
case PROP_FPI_PRINTS:
g_clear_pointer (&self->prints, g_ptr_array_unref);
self->prints = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -299,6 +309,19 @@ fp_print_class_init (FpPrintClass *klass)
NULL,
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
/**
* FpPrint::fpi-prints: (skip)
*
* This property is only for internal purposes.
*
* Stability: private
*/
properties[PROP_FPI_PRINTS] =
g_param_spec_pointer ("fpi-prints",
"Prints",
"Prints for internal use only",
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
g_object_class_install_properties (object_class, N_PROPS, properties);
}

View File

@@ -25,9 +25,11 @@
#include "fpi-print.h"
/**
* FpiDeviceUdevSubtype:
* FpiDeviceUdevSubtypeFlags:
* @FPI_DEVICE_UDEV_SUBTYPE_SPIDEV: The device requires an spidev node
* @FPI_DEVICE_UDEV_SUBTYPE_HIDRAW: The device requires a hidraw node
*
* Bitfield of required hardware resources for a udev-backed device.
*/
typedef enum {
FPI_DEVICE_UDEV_SUBTYPE_SPIDEV = 1 << 0,

View File

@@ -81,6 +81,8 @@ struct _FpiSsm
int start_cleanup;
int cur_state;
gboolean completed;
gboolean critical;
gboolean silence;
GSource *timeout;
GError *error;
FpiSsmCompletedCallback callback;
@@ -245,10 +247,11 @@ fpi_ssm_free (FpiSsm *machine)
/* Invoke the state handler */
static void
__ssm_call_handler (FpiSsm *machine)
__ssm_call_handler (FpiSsm *machine, gboolean force_msg)
{
fp_dbg ("[%s] %s entering state %d", fp_device_get_driver (machine->dev),
machine->name, machine->cur_state);
if (force_msg || !machine->silence)
fp_dbg ("[%s] %s entering state %d", fp_device_get_driver (machine->dev),
machine->name, machine->cur_state);
machine->handler (machine, machine->dev);
}
@@ -275,7 +278,11 @@ fpi_ssm_start (FpiSsm *ssm, FpiSsmCompletedCallback callback)
ssm->cur_state = 0;
ssm->completed = FALSE;
ssm->error = NULL;
__ssm_call_handler (ssm);
if (ssm->critical)
fpi_device_critical_enter (ssm->dev);
__ssm_call_handler (ssm, TRUE);
}
static void
@@ -346,7 +353,7 @@ fpi_ssm_mark_completed (FpiSsm *machine)
if (next_state < machine->nr_states)
{
machine->cur_state = next_state;
__ssm_call_handler (machine);
__ssm_call_handler (machine, TRUE);
return;
}
@@ -364,6 +371,10 @@ fpi_ssm_mark_completed (FpiSsm *machine)
machine->callback (machine, machine->dev, error);
}
if (machine->critical)
fpi_device_critical_leave (machine->dev);
fpi_ssm_free (machine);
}
@@ -460,7 +471,7 @@ fpi_ssm_next_state (FpiSsm *machine)
if (machine->cur_state == machine->nr_states)
fpi_ssm_mark_completed (machine);
else
__ssm_call_handler (machine);
__ssm_call_handler (machine, FALSE);
}
void
@@ -537,7 +548,7 @@ fpi_ssm_jump_to_state (FpiSsm *machine, int state)
if (machine->cur_state == machine->nr_states)
fpi_ssm_mark_completed (machine);
else
__ssm_call_handler (machine);
__ssm_call_handler (machine, FALSE);
}
typedef struct
@@ -642,6 +653,39 @@ fpi_ssm_dup_error (FpiSsm *machine)
return NULL;
}
/**
* fpi_ssm_silence_debug:
* @machine: an #FpiSsm state machine
*
* Turn off state change debug messages from this SSM. This does not disable
* all messages, as e.g. the initial state, SSM completion and cleanup states
* are still printed out.
*
* Use if the SSM loops and would flood the debug log otherwise.
*/
void
fpi_ssm_silence_debug (FpiSsm *machine)
{
machine->silence = TRUE;
}
/**
* fpi_ssm_set_critical:
* @machine: an #FpiSsm state machine
*
* Sets up the SSM to hold a critical section in the driver code. See
* fpi_device_critical_enter() for more details. This is useful if the SSM must
* not be interrupted in order to keep the device in a good state. You can e.g.
* guarantee that an image transfer is completed.
*
* This function must be called before starting the SSM.
*/
void
fpi_ssm_set_critical (FpiSsm *machine)
{
machine->critical = TRUE;
}
/**
* fpi_ssm_usb_transfer_cb:
* @transfer: a #FpiUsbTransfer

View File

@@ -96,6 +96,9 @@ GError * fpi_ssm_get_error (FpiSsm *machine);
GError * fpi_ssm_dup_error (FpiSsm *machine);
int fpi_ssm_get_cur_state (FpiSsm *machine);
void fpi_ssm_silence_debug (FpiSsm *machine);
void fpi_ssm_set_critical (FpiSsm *machine);
/* Callbacks to be used by the driver instead of implementing their own
* logic.
*/

View File

@@ -27,6 +27,7 @@
#include "fpi-compat.h"
#include "fpi-log.h"
#include "test-device-fake.h"
#include "fp-print-private.h"
/* Utility functions */
@@ -142,6 +143,16 @@ make_fake_print (FpDevice *device,
return enrolled_print;
}
static FpPrint *
make_fake_nbis_print (FpDevice *device)
{
FpPrint *enrolled_print = fp_print_new (device);
fpi_print_set_type (enrolled_print, FPI_PRINT_NBIS);
return enrolled_print;
}
static FpPrint *
make_fake_print_reffed (FpDevice *device,
GVariant *print_data)
@@ -1045,7 +1056,6 @@ test_driver_enroll_error_no_print (void)
out_print =
fp_device_enroll_sync (device, fp_print_new (device), NULL, NULL, NULL, &error);
g_test_assert_expected_messages ();
g_assert (fake_dev->last_called_function == dev_class->enroll);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
g_assert_null (out_print);
@@ -1053,6 +1063,111 @@ test_driver_enroll_error_no_print (void)
g_clear_error (&error);
}
static void
test_driver_enroll_update_nbis (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(FpAutoCloseDevice) device = NULL;
g_autoptr(FpPrint) template_print = NULL;
FpiDeviceFake *fake_dev = NULL;
FpPrint *out_print = NULL;
dev_class->features |= FP_DEVICE_FEATURE_UPDATE_PRINT;
device = auto_close_fake_device_new ();
fake_dev = FPI_DEVICE_FAKE (device);
template_print = make_fake_nbis_print (device);
fake_dev->ret_print = template_print;
out_print =
fp_device_enroll_sync (device, template_print, NULL, NULL, NULL, &error);
g_assert (fake_dev->last_called_function == dev_class->enroll);
g_assert (fake_dev->action_data == template_print);
g_assert_no_error (error);
g_assert (out_print == template_print);
}
static void
test_driver_enroll_update_nbis_wrong_device (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(FpAutoCloseDevice) device = NULL;
g_autoptr(FpPrint) template_print = NULL;
FpiDeviceFake *fake_dev = NULL;
FpPrint *out_print = NULL;
dev_class->features |= FP_DEVICE_FEATURE_UPDATE_PRINT;
device = auto_close_fake_device_new ();
fake_dev = FPI_DEVICE_FAKE (device);
template_print = make_fake_nbis_print (device);
template_print->device_id = g_strdup ("wrong_device");
fake_dev->ret_print = template_print;
out_print =
fp_device_enroll_sync (device, template_print, NULL, NULL, NULL, &error);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
g_assert (out_print == NULL);
}
static void
test_driver_enroll_update_nbis_wrong_driver (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(FpAutoCloseDevice) device = NULL;
g_autoptr(FpPrint) template_print = NULL;
FpiDeviceFake *fake_dev = NULL;
FpPrint *out_print = NULL;
dev_class->features |= FP_DEVICE_FEATURE_UPDATE_PRINT;
device = auto_close_fake_device_new ();
fake_dev = FPI_DEVICE_FAKE (device);
template_print = make_fake_nbis_print (device);
template_print->driver = g_strdup ("wrong_driver");
fake_dev->ret_print = template_print;
out_print =
fp_device_enroll_sync (device, template_print, NULL, NULL, NULL, &error);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
g_assert (out_print == NULL);
}
static void
test_driver_enroll_update_nbis_missing_feature (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(FpAutoCloseDevice) device = NULL;
g_autoptr(FpPrint) template_print = NULL;
FpiDeviceFake *fake_dev = NULL;
FpPrint *out_print = NULL;
device = auto_close_fake_device_new ();
fake_dev = FPI_DEVICE_FAKE (device);
template_print = make_fake_nbis_print (device);
fake_dev->ret_print = template_print;
out_print =
fp_device_enroll_sync (device, template_print, NULL, NULL, NULL, &error);
g_assert (fake_dev->last_called_function == dev_class->open);
g_assert (fake_dev->action_data == NULL);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
g_assert (out_print == NULL);
}
typedef struct
{
gint completed_stages;
@@ -3306,6 +3421,13 @@ main (int argc, char *argv[])
g_test_add_func ("/driver/enroll/error", test_driver_enroll_error);
g_test_add_func ("/driver/enroll/error/no_print", test_driver_enroll_error_no_print);
g_test_add_func ("/driver/enroll/progress", test_driver_enroll_progress);
g_test_add_func ("/driver/enroll/update_nbis", test_driver_enroll_update_nbis);
g_test_add_func ("/driver/enroll/update_nbis_wrong_device",
test_driver_enroll_update_nbis_wrong_device);
g_test_add_func ("/driver/enroll/update_nbis_wrong_driver",
test_driver_enroll_update_nbis_wrong_driver);
g_test_add_func ("/driver/enroll/update_nbis_missing_feature",
test_driver_enroll_update_nbis_missing_feature);
g_test_add_func ("/driver/verify", test_driver_verify);
g_test_add_func ("/driver/verify/fail", test_driver_verify_fail);
g_test_add_func ("/driver/verify/retry", test_driver_verify_retry);

View File

@@ -136,6 +136,7 @@ class VirtualImage(unittest.TestCase):
self.assertTrue(self.dev.has_feature(FPrint.DeviceFeature.CAPTURE))
self.assertTrue(self.dev.has_feature(FPrint.DeviceFeature.IDENTIFY))
self.assertTrue(self.dev.has_feature(FPrint.DeviceFeature.VERIFY))
self.assertTrue(self.dev.has_feature(FPrint.DeviceFeature.UPDATE_PRINT))
self.assertFalse(self.dev.has_feature(FPrint.DeviceFeature.DUPLICATES_CHECK))
self.assertFalse(self.dev.has_feature(FPrint.DeviceFeature.STORAGE))
self.assertFalse(self.dev.has_feature(FPrint.DeviceFeature.STORAGE_LIST))
@@ -144,7 +145,8 @@ class VirtualImage(unittest.TestCase):
self.assertEqual(self.dev.get_features(),
FPrint.DeviceFeature.CAPTURE |
FPrint.DeviceFeature.IDENTIFY |
FPrint.DeviceFeature.VERIFY)
FPrint.DeviceFeature.VERIFY |
FPrint.DeviceFeature.UPDATE_PRINT)
def test_capture_prevents_close(self):
cancel = Gio.Cancellable()
@@ -167,7 +169,7 @@ class VirtualImage(unittest.TestCase):
while not self._cancelled:
ctx.iteration(True)
def enroll_print(self, image):
def enroll_print(self, image, template=None):
self._step = 0
self._enrolled = None
@@ -181,14 +183,15 @@ class VirtualImage(unittest.TestCase):
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE)
self._enrolled = fp
template = FPrint.Print.new(self.dev)
template.props.finger = FPrint.Finger.LEFT_THUMB
template.props.username = "testuser"
template.props.description = "test print"
datetime = GLib.DateTime.new_now_local()
date = GLib.Date()
date.set_dmy(*datetime.get_ymd()[::-1])
template.props.enroll_date = date
if template is None:
template = FPrint.Print.new(self.dev)
template.props.finger = FPrint.Finger.LEFT_THUMB
template.props.username = "testuser"
template.props.description = "test print"
datetime = GLib.DateTime.new_now_local()
date = GLib.Date()
date.set_dmy(*datetime.get_ymd()[::-1])
template.props.enroll_date = date
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE)
self.dev.enroll(template, None, progress_cb, tuple(), done_cb)
@@ -264,6 +267,28 @@ class VirtualImage(unittest.TestCase):
ctx.iteration(True)
assert(not self._verify_match)
# Test fingerprint updates
# Enroll a second print
fp_whorl_tended_arch = self.enroll_print('tented_arch', fp_whorl)
# Make sure the first print verifies successfully after the update
self._verify_match = None
self._verify_fp = None
self.dev.verify(fp_whorl_tended_arch, callback=verify_cb)
self.send_image('whorl')
while self._verify_match is None:
ctx.iteration(True)
assert(self._verify_match)
# Make sure the second print verifies successfully after the update
self._verify_match = None
self._verify_fp = None
self.dev.verify(fp_whorl_tended_arch, callback=verify_cb)
self.send_image('tented_arch')
while self._verify_match is None:
ctx.iteration(True)
assert(self._verify_match)
# Test verify error cases
self._verify_fp = None
self._verify_error = None