diff --git a/src/device.c b/src/device.c index 41b9939..53668d6 100644 --- a/src/device.c +++ b/src/device.c @@ -306,8 +306,11 @@ on_nr_enroll_stages_changed (FprintDevice *rdev, FprintDBusDevice *dbus_dev = FPRINT_DBUS_DEVICE (rdev); gint nr_enroll_stages; + nr_enroll_stages = fp_device_get_nr_enroll_stages (device); + /* One extra step for our internal identification. */ - nr_enroll_stages = fp_device_get_nr_enroll_stages (device) + 1; + if (fp_device_supports_identify (device)) + nr_enroll_stages += 1; g_debug ("Device %s enroll stages changed to %d", fp_device_get_name (device), @@ -1829,6 +1832,21 @@ enroll_cb (FpDevice *dev, GAsyncResult *res, void *user_data) stoppable_action_completed (rdev); } +static void +enroll_start (FprintDevice *rdev) +{ + FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev); + + fp_device_enroll (priv->dev, + fprint_device_create_enroll_template (rdev, priv->enroll_data), + priv->current_cancellable, + enroll_progress_cb, + rdev, + NULL, + (GAsyncReadyCallback) enroll_cb, + rdev); +} + static void enroll_identify_cb (FpDevice *dev, GAsyncResult *res, void *user_data) { @@ -1917,14 +1935,7 @@ enroll_identify_cb (FpDevice *dev, GAsyncResult *res, void *user_data) g_signal_emit (rdev, signals[SIGNAL_ENROLL_STATUS], 0, "enroll-stage-passed", FALSE); /* We are good and can start to enroll. */ - fp_device_enroll (priv->dev, - fprint_device_create_enroll_template (rdev, priv->enroll_data), - priv->current_cancellable, - enroll_progress_cb, - rdev, - NULL, - (GAsyncReadyCallback) enroll_cb, - rdev); + enroll_start (rdev); } static gboolean @@ -1933,7 +1944,6 @@ fprint_device_enroll_start (FprintDBusDevice *dbus_dev, const char *finger_name) { g_autoptr(GError) error = NULL; - g_autoptr(GPtrArray) all_prints = NULL; FprintDevice *rdev = FPRINT_DEVICE (dbus_dev); FprintDevicePrivate *priv = fprint_device_get_instance_private (rdev); FpFinger finger = finger_name_to_fp_finger (finger_name); @@ -1964,22 +1974,36 @@ fprint_device_enroll_start (FprintDBusDevice *dbus_dev, priv->enroll_data = finger; priv->current_action = ACTION_ENROLL; - /* We (now) have the policy that there must be no duplicate prints. - * We need to do this for MoC devices, as their "identify" function - * will generally just identify across all device stored prints. - * For MoH, we also do it. For consistency and because it allows us - * to implement new features in the future (i.e. logging in/unlocking - * the correct user without selecting it first). - */ - all_prints = load_all_prints (rdev); - fp_device_identify (priv->dev, - all_prints, - priv->current_cancellable, - NULL, - NULL, - NULL, - (GAsyncReadyCallback) enroll_identify_cb, - rdev); + if (fp_device_supports_identify (priv->dev)) + { + g_autoptr(GPtrArray) all_prints = load_all_prints (rdev); + + /* We (now) have the policy that there must be no duplicate prints. + * We need to do this for MoC devices, as their "identify" function + * will generally just identify across all device stored prints. + * For MoH, we also do it. For consistency and because it allows us + * to implement new features in the future (i.e. logging in/unlocking + * the correct user without selecting it first). + */ + fp_device_identify (priv->dev, + all_prints, + priv->current_cancellable, + NULL, + NULL, + NULL, + (GAsyncReadyCallback) enroll_identify_cb, + rdev); + } + else + { + /* We may still want to try to use verification to check for duplicates + * if only one fingerprint was previously enrolled, or add more verify + * stages up to a predefined limit */ + g_warning ("Device %s does not support duplicate identification and so " + "fprintd duplicate detection won't work", + fp_device_get_name (priv->dev)); + enroll_start (rdev); + } fprint_dbus_device_complete_enroll_start (dbus_dev, invocation); diff --git a/tests/fprintd.py b/tests/fprintd.py index 37a7bfa..940e5e9 100644 --- a/tests/fprintd.py +++ b/tests/fprintd.py @@ -567,6 +567,7 @@ class FPrintdVirtualImageDeviceBaseTests(FPrintdTest): socket_env = 'FP_VIRTUAL_IMAGE' device_driver = 'virtual_image' driver_name = 'Virtual image device for debugging' + has_identification = True class FPrintdVirtualDeviceBaseTest(FPrintdVirtualImageDeviceBaseTests): @@ -882,10 +883,12 @@ class FPrintdVirtualStorageDeviceBaseTest(FPrintdVirtualDeviceBaseTest): def _maybe_reduce_enroll_stages(self, stages=-1): # Reduce the number of default enroll stages, we can go a bit faster stages = stages if stages > 0 else self.enroll_stages - stages += 1 # Adding the extra stage for duplicates-check + if self.has_identification: + stages += 1 # Adding the extra stage for duplicates-check if self.num_enroll_stages == stages: return - self.send_command('SET_ENROLL_STAGES', stages - 1) + device_stages = stages -1 if self.has_identification else stages + self.send_command('SET_ENROLL_STAGES', device_stages) while self.num_enroll_stages != stages: ctx.iteration(True) self.assertIn({'num-enroll-stages': stages}, self._changed_properties) @@ -1004,10 +1007,8 @@ class FPrintdVirtualNoStorageDeviceBaseTest(FPrintdVirtualStorageDeviceBaseTest) socket_env = 'FP_VIRTUAL_DEVICE' device_driver = 'virtual_device' driver_name = 'Virtual device for debugging' + has_identification = False - def enroll_image(self, img, device=None, finger='right-index-finger', - expected_result='enroll-completed', claim_user=None): - self.skipTest('Identification not supported, thus is the enrolling') class FPrintdVirtualNoStorageDeviceTest(FPrintdVirtualNoStorageDeviceBaseTest): @@ -2212,8 +2213,9 @@ class FPrintdVirtualDeviceEnrollTests(FPrintdVirtualDeviceBaseTest): self.assertEnrollError(FPrint.DeviceError.DATA_INVALID, 'enroll-unknown-error') def test_enroll_error_data_not_found(self): - self.assertEnrollError( - FPrint.DeviceError.DATA_NOT_FOUND, 'enroll-stage-passed') + if self.has_identification: + self.assertEnrollError( + FPrint.DeviceError.DATA_NOT_FOUND, 'enroll-stage-passed') self.assertEnrollError(FPrint.DeviceError.DATA_NOT_FOUND, 'enroll-unknown-error') def test_enroll_error_data_full(self):