From e8886dbc6b88badfd1311ba8c5105f6ab1917640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Sun, 24 Jan 2021 02:02:05 +0100 Subject: [PATCH] virtual-device: Support all the configured enrolling stages --- libfprint/drivers/virtual-device-private.h | 1 + libfprint/drivers/virtual-device.c | 49 +++++++++++++++++----- tests/virtual-device.py | 12 +++++- 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/libfprint/drivers/virtual-device-private.h b/libfprint/drivers/virtual-device-private.h index 5f2371d..08d6736 100644 --- a/libfprint/drivers/virtual-device-private.h +++ b/libfprint/drivers/virtual-device-private.h @@ -78,6 +78,7 @@ struct _FpDeviceVirtualDevice GHashTable *prints_storage; guint wait_command_id; + guint enroll_stages_passed; }; /* Not really final here, but we can do this to share the FpDeviceVirtualDevice diff --git a/libfprint/drivers/virtual-device.c b/libfprint/drivers/virtual-device.c index cf36d0d..5f193d6 100644 --- a/libfprint/drivers/virtual-device.c +++ b/libfprint/drivers/virtual-device.c @@ -352,24 +352,53 @@ dev_enroll (FpDevice *dev) { GVariant *data; - fpi_print_set_type (print, FPI_PRINT_RAW); - data = g_variant_new_string (id); - g_object_set (print, "fpi-data", data, NULL); - - if (self->prints_storage) + if (self->enroll_stages_passed == 0) { - g_hash_table_add (self->prints_storage, g_strdup (id)); - fpi_print_set_device_stored (print, TRUE); + fpi_print_set_type (print, FPI_PRINT_RAW); + data = g_variant_new_string (id); + g_object_set (print, "fpi-data", data, NULL); + } + else + { + gboolean changed; + + g_object_get (print, "fpi-data", &data, NULL); + changed = !g_str_equal (id, g_variant_get_string (data, NULL)); + g_variant_unref (data); + + if (changed) + { + g_set_error (&error, FP_DEVICE_RETRY, FP_DEVICE_RETRY_GENERAL, "ID Mismatch"); + fpi_device_enroll_progress (dev, self->enroll_stages_passed, NULL, error); + return; + } } - fpi_device_enroll_complete (dev, g_object_ref (print), NULL); + self->enroll_stages_passed++; + fpi_device_enroll_progress (dev, self->enroll_stages_passed, print, NULL); + if (self->enroll_stages_passed == FP_DEVICE_GET_CLASS (self)->nr_enroll_stages) + { + if (self->prints_storage) + { + fpi_print_set_device_stored (print, TRUE); + g_hash_table_add (self->prints_storage, g_strdup (id)); + } + + fpi_device_enroll_complete (dev, g_object_ref (print), NULL); + self->enroll_stages_passed = 0; + } } else { if (error && error->domain == FP_DEVICE_RETRY) - fpi_device_enroll_progress (dev, 0, NULL, g_steal_pointer (&error)); + { + fpi_device_enroll_progress (dev, self->enroll_stages_passed, NULL, g_steal_pointer (&error)); + } else - fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error)); + { + self->enroll_stages_passed = 0; + fpi_device_enroll_complete (dev, NULL, g_steal_pointer (&error)); + } } } diff --git a/tests/virtual-device.py b/tests/virtual-device.py index 570e3be..f2399bd 100644 --- a/tests/virtual-device.py +++ b/tests/virtual-device.py @@ -120,6 +120,10 @@ class VirtualDevice(unittest.TestCase): print("Enroll done") self._enrolled = dev.enroll_finish(res) + def progress_cb(dev, stage, pnt, data, error): + self._enroll_stage = stage + self._enroll_progress_error = error + self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE) self.send_command('SCAN', nick) @@ -128,14 +132,20 @@ class VirtualDevice(unittest.TestCase): template.set_finger(finger) template.set_username(username) - self.dev.enroll(template, None, None, tuple(), done_cb) + stage = 1 + self.dev.enroll(template, callback=done_cb, progress_cb=progress_cb) while self._enrolled is None: ctx.iteration(False) if not self._enrolled: self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NEEDED) + self.assertEqual(self._enroll_stage, stage) + self.assertLess(self._enroll_stage, self.dev.get_nr_enroll_stages()) + self.send_command('SCAN', nick) + stage += 1 + self.assertEqual(self._enroll_stage, self.dev.get_nr_enroll_stages()) self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE) self.assertEqual(self._enrolled.get_device_stored(),