Compare commits

...

59 Commits

Author SHA1 Message Date
Benjamin Berg
c96958582f Release 1.90.6 2020-12-09 13:30:53 +01:00
Marco Trevisan (Treviño)
c02771d16b goodixmoc: Add async identification test using on-owned deseralized prints
This simulates what fprintd does
2020-12-09 13:30:37 +01:00
Marco Trevisan (Treviño)
989d498eb9 goodix: Don't leak the templates array during verify
When verifying we initialize a temporary templates array but we never
release it.
2020-12-09 12:55:26 +01:00
Benjamin Berg
91ee03eb7a device: Fix memory management of gallery passed to identify
We cannot make any assumptions about the passed GPtrArray. As such, we
must copy the content and grab our own reference for each of the prints.
2020-12-09 11:47:33 +01:00
Benjamin Berg
28ba6a0de9 test-fpi-device: Do deep comparison of gallery
The gallery needs to be copied, as such we must do a deep comparison
instead of comparing the pointers. We also can't do the comparison
afterwards, as the gallery is owned by the operation and that operation
is finished already.
2020-12-09 11:47:33 +01:00
Marco Trevisan (Treviño)
faade91c39 test-fpi-device: Add function to create fake FpPrint's and galleries 2020-12-09 11:47:33 +01:00
Benjamin Berg
499de3e442 print: Return sunk reference from deserialize function
This function was always documented to return a sunk reference, but it
did not do so. This change is technically backward incompatible.

However, it only has an effect if anything is doing a g_object_ref_sink.
Which may happen inside libfprint itself. With the change, most API
users (including fprintd) are fixed to do refcounting correctly. Any API
user which worked around this will have a memory leak now.

That is not ideal, but it is not really that bad overall. And returning
a floating reference for FpPrint creation was a bad idea in the first
place. And it really only makes sense for fp_print_new as the only
(public) use case is to create the template for enrollment.
2020-12-09 11:47:33 +01:00
fengqiangguo
0ff7a07671 goodixmoc: fix package crc error
fix package length type convert error
2020-12-09 10:07:39 +00:00
Marco Trevisan (Treviño)
0d9d7dcb46 fp-print: Don't deference the passed error, use g_set_error instead
It still may be NULL, but we don't protect from that.
2020-12-09 10:38:38 +01:00
Marco Trevisan (Treviño)
fb23f8690f fp-print: Return NULL on error
not really different from FALSE, but still..
2020-12-09 10:38:38 +01:00
Marco Trevisan (Treviño)
6ca8441df9 umockdev-tests: Don't fail when trying to save other errors 2020-12-09 10:26:58 +01:00
Marco Trevisan (Treviño)
8112da0358 umockdev-tests: Still raise an error when storing the exception output
Otherwise we won't ever fail
2020-12-09 10:26:58 +01:00
Marco Trevisan (Treviño)
f2ea3e784e fp-print: Delete not-defined anymore functions 2020-12-09 10:26:58 +01:00
Benjamin Berg
74810a8472 image: Fix warning about uninitialized variable
The variable is only initialized later in the function. This is
harmless, as there is no return, but it causes a warning due to the
automatic free.
2020-12-08 13:33:30 +01:00
Benjamin Berg
91fb8d8cb4 compat: Add GFlagsClass autopointer
It was added to GLib at the same time as GEnumClass. We did not list it
though and are now using it in a test.
2020-12-08 13:27:50 +01:00
Marco Trevisan (Treviño)
0688288c6d .git-blame-ignore-revs: Ignore formatting commit and add hint how to use it 2020-12-07 19:01:10 +01:00
Marco Trevisan (Treviño)
c1e832e7a7 fp-device: Return valid finger status value on error
Not that the two enums have different value, but indeed the type is
wrong.
2020-12-04 12:15:22 +00:00
Marco Trevisan (Treviño)
b5496fd257 fp-device: Ensure finger status is set to proper type on property getter
Finger status is a flag not an enum.

Add tests.
2020-12-04 12:15:22 +00:00
Marco Trevisan (Treviño)
de271a0e8d fp-print: Don't byte-swap two times the NBIS array contents
When serializing an image print in big endian machine we ended up
swapping the arrays contents two times, first when adding the values and
eventually when calling g_variant_byteswap which already handles this
properly.

With this, we get the test passing into s390x.

Fixes: #236
2020-12-02 16:40:10 +00:00
Marco Trevisan (Treviño)
12b0120a3d test-fpi-device: Always check the return values for the API calls
Ensure that the return value of the API calls match the expected one,
as we need to ensure that it also matches with the error/no-error case.
2020-12-02 16:28:36 +00:00
Marco Trevisan (Treviño)
2783ac3e60 fpi-device: Return proper type on identification success
Identify function is supposed to propagate a boolean value, but we make
it return an integer instead on idle, this can be normally the same in
most of architectures, but not in BE ones.

So, make it return the proper type.
Fixes test failures in s390x.

Related to #236
2020-12-02 16:28:36 +00:00
Aris Lin
abb0b1267c synaptics: add support PID 0xE7 2020-12-02 10:21:39 +08:00
Benjamin Berg
5cb91a4189 Release 1.90.5 2020-12-01 10:14:26 +01:00
Benjamin Berg
0bb132b167 NEWS: Fix release date of 1.90.4 2020-12-01 10:14:02 +01:00
Benjamin Berg
ce39f27b5e vfs301_proto: Remove usless break after return
Closes: #341
2020-11-30 20:22:18 +00:00
Benjamin Berg
7d0956513b upekts: Remove duplicated err handling path
Closes: #342
2020-11-30 20:22:17 +00:00
Marco Trevisan (Treviño)
2b7cfa751a list-udev-rules: Remove Wrongly added well-known USB controller vid/pid combo
This was causing USB controllers to use power-saving mode, breaking usb
devices usage.

Related to: https://gitlab.freedesktop.org/libfprint/libfprint/-/issues/327
2020-11-30 20:03:32 +01:00
Vincent Huang
0eee6a56dd synaptics: add support to sensor PID 0xC9 2020-11-30 13:53:07 +08:00
Benjamin Berg
8962e14fde Release 1.90.4 2020-11-27 13:55:49 +01:00
tt83
e246e00ba3 elan: added 0c4d device to the array of supported devices 2020-11-26 12:39:19 +01:00
Marco Trevisan (Treviño)
fa3bdb874d udev-rules: Regenerate from wiki to include VFS495 2020-11-25 18:28:41 +01:00
Benjamin Berg
2caeb8cbb3 udev-rules: Add unsupported devices from wiki page to rules
This ensures we are putting all these devices (which are unusable) into
power save mode.
2020-11-25 14:56:06 +00:00
Marco Trevisan (Treviño)
dda3587b76 identify: Use stored print to show identify information
The stored print may contain more metadata, so let's use that for
device-stored print, if available.
2020-11-23 17:00:01 +00:00
Marco Trevisan (Treviño)
fb5854213a examples: Add Identify example
It was the only main action left in the examples, we use the gallery
from the device if available, otherwise the local one.
2020-11-23 17:00:01 +00:00
Benjamin Berg
21ee241f0c virtual-image: Add command to trigger device removal
This is primarily useful for fprintd testing.
2020-11-23 17:47:03 +01:00
Benjamin Berg
280f916ace image-device: Fix incorrect g_free of error
GError needs to be free'ed using g_error_free, fix this.
2020-11-23 17:47:03 +01:00
Benjamin Berg
1b5dd0057f tests: Add device removal test
This tests all relevant scenarios of device removal, i.e.:
 * device is not open
 * device is currently closing
 * device is open and idle
 * device is currently opening
 * device is open and active

The test ensures that in all scenarios the following holds true:
 * device "removed" signal is only emitted after the action completes
 * context "device-removed" signal is only emitted after the device has
   been closed

Note that the "opening" case is special. Here we confirm that a success
from "open" will not be overriden by a FP_DEVICE_ERROR_REMOVED error, in
order to correctly signal that the internal device state is open and it
needs to be closed.
2020-11-23 17:47:03 +01:00
Benjamin Berg
8a6f1932f8 virtual-image: Add a notify::removed handler
In general, we rely on the underlying transport layer to throw errors
which will abort the current operation. This does not work for the
virtual image device though, but we need it there for testing purposes.

Add a notify::removed handler that makes things work as expected. Let it
throw a protocol error which should not be visible to the outside.
2020-11-23 17:47:03 +01:00
Benjamin Berg
0051ff6352 device: Treat devices as closed even after a close failure
We require the close call, but as the underlying transport layer is
gone, it will generally just return an error.

In principle, it makes sense to think of close as a function that always
succeeds (i.e. it makes no sense to try again). Should the device be in
a bad state, then a subsequent open() will simply fail.
2020-11-23 17:47:03 +01:00
Benjamin Berg
b6dd522459 Rework device removal to have a nice API
This enhances the device removal to create a well defined behaviour.

Primarily, it means that:
 * "device-removed" will only be called for closed devices
 * "removed" will be called only when no operation is active

Note that all actions will fail with FP_DEVICE_ERROR_REMOVED, *except*
for open which will only return this error if it failed.

Resolves: #330
2020-11-23 17:47:03 +01:00
Benjamin Berg
656bf3d175 elan: Add a few comments that stopping/callibrating helps
Apparently stopping/callibrating helps with the reliability of these
sensors. Add a few comments so that this information is known.

See https://gitlab.freedesktop.org/libfprint/libfprint/-/issues/216#note_619467
2020-11-18 15:18:11 +01:00
Benjamin Berg
fe498c56c7 virtual-image: Fix race condition closing new connection
When a new connection came in we would close the old connection. This in
turn would trigger a receive error causing the *new* connection to be
closed from the error handler.

Fix this by simply cancelling any pending transfers when a new
connection comes in. Also change the error handling code to catch issues
like partial writes correctly.

This fixes an issue for the fprintd test where some tests were flaky.
2020-11-10 15:59:53 +01:00
Marco Trevisan (Treviño)
251ccef9ba fpi-device: Add debug information about the enrolled finger 2020-11-08 22:19:23 +01:00
Marco Trevisan (Treviño)
3b993fabb6 verify/enroll: Save and use locally saved prints also for devices with storage
Some devices have storage but that's is limited enough not to be able
to store all the metadata, but just a fingerprint id.

In such case we also need to use the local storage to be able to verify.
Fprintd does this already, but we don't do it in the libfprint examples.

So, in in case we enroll, always save the print information to the disk,
while in case we verify we try to load the print from disk and we use
that in case its private data matches the one provided by the device.
2020-11-08 22:19:23 +01:00
Marco Trevisan (Treviño)
0c56e0de6d synaptics: Report finger status to libfprint
The inactivation in case would be set back by libfprint
2020-11-07 13:23:30 +00:00
Marco Trevisan (Treviño)
893ff9c033 fp-image-device: Report finger status changes to the device
While the image device has its own finger status tracking, we use a simpler
version as public data information, so let's just report the finger-on/off
and when a finger is expected to the parent class.

Verify that this happens as expected using the virtual-image class
2020-11-07 13:23:30 +00:00
Marco Trevisan (Treviño)
3c382cac7f fp-device: Reset the finger status on complete
Devices should handle the finger status internally, but if they don't do it
we need to handle it on actions completion
2020-11-07 13:23:30 +00:00
Marco Trevisan (Treviño)
42e4506b1b fp-device: Add finger-status property
It can be used by drivers to report the state of the finger on sensor
2020-11-07 13:23:30 +00:00
Benjamin Berg
ae3baadcf9 tests: Add a new test for vfs301
See: #320
2020-11-05 15:55:09 +01:00
Benjamin Berg
4f29a32da8 tests: Store temporary directory on failure
It is not very useful to just delete the data again after a failure, as
it might be useful for debugging. Just store it into an "errors"
subdirectory of the PWD in the hope that this is a sane location.

Note that it'll error out if the directory already exists, but that
should be acceptable in all cases. i.e. it won't exist in the CI and
developers can just wipe the directory.
2020-11-05 15:52:54 +01:00
Benjamin Berg
e5fa54e8e7 vfs301: Start capture only on state change to AWAIT_FINGER_ON
Start the capture when the state changes to AWAIT_FINGER_ON instead of
assuming that the device should always be active.

Closes: #320
2020-11-04 14:13:00 +01:00
Benjamin Berg
d3076039d0 vfs301: Fix device pointer handling in callback
When porting the driver to the new libfprint 1.90.0 a mistake was made
where the device was not passed through user_data anymore but it was
still read from there. Stop using user_data in the callback to fix this.

See: #320
2020-11-04 14:13:00 +01:00
Benjamin Berg
a748f4d30f elan: Simplify elan driver internal state machine
The elan driver always "deactivates" the device after a cpature run. We
can simplify the while internal state into a single "active" state and
rely on the image device driving this state machine correctly.

i.e.:
 * We start a callibrate/capture/deactivate when we go into the
   AWAIT_FINGER_ON state
 * We only store the fact that we are active and want to deactivate
 * We rely on the image device never going into the AWAIT_FINGER_ON
   state without first waiting for the finger to be off (which implies
   deactivation).
2020-11-04 14:13:00 +01:00
Benjamin Berg
3ee5536a13 image-device: Redefine internal states and valid transitions
This adds a number of new internal states to better capture what is
going on. Also added are checks that all transitions we make are in the
set of expected and valid transitions.

Only three drivers use the state_change notification. These drivers are
updated accordingly.
2020-11-04 14:13:00 +01:00
Benjamin Berg
f56aacc7ef image-device: Remove cancelling boolean from private data
The boolean is just used to emit a warning for unexpected state
transitions. It is sufficient to pass it to the deactivate function
directly for that purpose.
2020-11-04 14:13:00 +01:00
Benjamin Berg
96fa0a96eb uru4000: Fix missing reference to image transfer
We might redo image transfers, but we only ever had one reference that
was implicitly removed after the transfer completed. Add a new reference
each time it is submitted and only free the last reference in the stop
handler.
2020-10-19 17:41:26 +02:00
Benjamin Berg
1754bd0204 synaptics: Always submit interrupt transfer without a timeout
For some reason we re-submitted the interrupt transfer with a timeout of
1s while the original submission was without a timeout. This looks like
typo, remove the timeout.
2020-10-19 17:14:24 +02:00
Benjamin Berg
90a1abf2f8 synaptics: Fix missing reference to interrupt transfer
When resubmitting the interrupt transfer we need to add a new reference
as the submit function will steal it again.
2020-10-19 17:13:58 +02:00
Benjamin Berg
59824d2122 synaptics: Remove useless code
There is never a fall through if error is not NULL.
2020-10-19 16:59:07 +02:00
47 changed files with 2636 additions and 486 deletions

10
.git-blame-ignore-revs Normal file
View File

@@ -0,0 +1,10 @@
# The commits that did automated reformatting. You can ignore them
# during git-blame with `--ignore-rev` or `--ignore-revs-file`.
#
# $ git config --add 'blame.ignoreRevsFile' '.git-blame-ignore-revs'
#
d1fb1e26f3b79e54febc94496c1184763cf2af3d
e4f9935706be4c0e3253afe251c182019ff7ccef
65e602d8c72baa7020efb62d10bf28e621feb05d
4115ae7ced77d392ee11ea55212206d9404356f0

49
NEWS
View File

@@ -1,6 +1,55 @@
This file lists notable changes in each release. For the full history of all
changes, see ChangeLog.
2020-12-01: v1.90.6 release
This release is primarily a bugfix release for some older issues.
The major change is that fp_print_deserialize will now correctly return a
sunken reference rather than a floating one. Most API users will have
assumed this was true, and issues could happen at a later point.
If any API user worked around this libfprint bug, they will now leak the
returned print.
Highlights:
* Object reference management fixes for FpPrint and identify
* Fixed issues that caused problem on non-x86 machines (#236)
* Fix building with older GLib versions
* synaptics: Support PID 00e7
* goodix: Fix issue with long USB packages
2020-12-01: v1.90.5 release
The 1.90.4 release caused a major regression, as it included a USB hub in
UDEV the autosupend rule list.
Highlights:
* Remove USB hub from udev autosupend rules
* synaptics: Add PID 0x00c9 which is used in some HP laptops
2020-11-27: v1.90.4 release
This release contains a number of important bugfixes. On the feature side,
the USB hotplug support was improved. A lot of drivers received fixes and
improvements.
Highlights:
* Work around GUsb cancellation issue
* Redefine internal image device state machine for more robustness
* Add public finger-status reporting to FpDevice
* Rework device removal API to be convenient (#330)
* Enable powersave for unsupported USB devices
* Improvements to examples
* synaptics: Support identify operation
* synaptics: Fix possible crash when the interrupt transfer is resubmitted
* synaptics: Add support for PIDs 0x00f9, 0x00fc and 0x00c2
* elan: Add PID 0x0c4d to supported device list
* aes3k: Fix driver and add CI test (#306)
* uru4000: Fix reference counting of image transfer
* vfs301: Fix driver and add CI test (#320)
2020-06-08: v1.90.3 release
This release mostly contains support for a number of new match-on-chip

View File

@@ -91,8 +91,6 @@ FP_TYPE_PRINT
FpFinger
FpPrint
fp_print_new
fp_print_new_from_data
fp_print_to_data
fp_print_get_driver
fp_print_get_device_id
fp_print_get_device_stored

View File

@@ -76,15 +76,19 @@ on_enroll_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
{
enroll_data->ret_value = EXIT_SUCCESS;
if (!fp_device_has_storage (dev))
if (fp_device_has_storage (dev))
g_debug ("Device has storage, saving a print reference locally");
else
g_debug ("Device has not storage, saving print only locally");
/* 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);
if (r < 0)
{
g_debug ("Device has not storage, saving locally");
int r = print_data_save (print, enroll_data->finger);
if (r < 0)
{
g_warning ("Data save failed, code %d", r);
enroll_data->ret_value = EXIT_FAILURE;
}
g_warning ("Data save failed, code %d", r);
enroll_data->ret_value = EXIT_FAILURE;
}
}
else

319
examples/identify.c Normal file
View File

@@ -0,0 +1,319 @@
/*
* Example fingerprint verification program, which verifies the
* finger which has been previously enrolled to disk.
* Copyright (C) 2020 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define FP_COMPONENT "example-identify"
#include <stdio.h>
#include <libfprint/fprint.h>
#include <glib-unix.h>
#include "storage.h"
#include "utilities.h"
typedef struct _IdentifyData
{
GMainLoop *loop;
GCancellable *cancellable;
unsigned int sigint_handler;
int ret_value;
} IdentifyData;
static void
identify_data_free (IdentifyData *identify_data)
{
g_clear_handle_id (&identify_data->sigint_handler, g_source_remove);
g_clear_object (&identify_data->cancellable);
g_main_loop_unref (identify_data->loop);
g_free (identify_data);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdentifyData, identify_data_free)
static void
on_device_closed (FpDevice *dev, GAsyncResult *res, void *user_data)
{
IdentifyData *identify_data = user_data;
g_autoptr(GError) error = NULL;
fp_device_close_finish (dev, res, &error);
if (error)
g_warning ("Failed closing device %s", error->message);
g_main_loop_quit (identify_data->loop);
}
static void
identify_quit (FpDevice *dev,
IdentifyData *identify_data)
{
if (!fp_device_is_open (dev))
{
g_main_loop_quit (identify_data->loop);
return;
}
fp_device_close (dev, NULL, (GAsyncReadyCallback) on_device_closed, identify_data);
}
static void start_identification (FpDevice *dev,
IdentifyData *identify_data);
static void
on_identify_completed (FpDevice *dev, GAsyncResult *res, void *user_data)
{
IdentifyData *identify_data = user_data;
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) match = NULL;
g_autoptr(GError) error = NULL;
char buffer[20];
if (!fp_device_identify_finish (dev, res, &match, &print, &error))
{
g_warning ("Failed to identify print: %s", error->message);
identify_data->ret_value = EXIT_FAILURE;
if (error->domain != FP_DEVICE_RETRY)
{
identify_quit (dev, identify_data);
return;
}
}
g_print ("Identify again? [Y/n]? ");
if (fgets (buffer, sizeof (buffer), stdin) &&
(buffer[0] == 'Y' || buffer[0] == 'y' || buffer[0] == '\n'))
{
start_identification (dev, identify_data);
return;
}
identify_quit (dev, identify_data);
}
static FpPrint *
get_stored_print (FpDevice *dev, FpPrint *print)
{
g_autoptr(GPtrArray) gallery = gallery_data_load (dev);
guint index;
if (g_ptr_array_find_with_equal_func (gallery, print,
(GEqualFunc) fp_print_equal,
&index))
return g_object_ref (g_ptr_array_index (gallery, index));
return NULL;
}
static void
on_identify_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
gpointer user_data, GError *error)
{
IdentifyData *identify_data = user_data;
if (error)
{
g_warning ("Identify report: No finger matched, retry error reported: %s",
error->message);
return;
}
if (print && fp_print_get_image (print) &&
print_image_save (print, "identify.pgm"))
g_print ("Print image saved as identify.pgm\n");
if (match)
{
g_autoptr(FpPrint) matched_print = g_object_ref (match);
char date_str[128] = {};
identify_data->ret_value = EXIT_SUCCESS;
if (fp_print_get_device_stored (match))
{
FpPrint *stored_print = get_stored_print (dev, match);
if (stored_print)
matched_print = g_steal_pointer (&stored_print);
}
if (fp_print_get_enroll_date (matched_print))
g_date_strftime (date_str, G_N_ELEMENTS (date_str), "%Y-%m-%d\0",
fp_print_get_enroll_date (matched_print));
else
strcpy (date_str, "<unknown>");
g_debug ("Identify report: device %s matched finger %s successfully "
"with print '%s', enrolled on date %s by user %s",
fp_device_get_name (dev),
finger_to_string (fp_print_get_finger (matched_print)),
fp_print_get_description (matched_print), date_str,
fp_print_get_username (matched_print));
g_print ("IDENTIFIED!\n");
}
else
{
g_debug ("Identification report: No finger matched");
g_print ("NOT IDENTIFIED!\n");
}
}
static void
on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
{
IdentifyData *identify_data = user_data;
g_autoptr(GPtrArray) gallery = NULL;
g_autoptr(GError) error = NULL;
gallery = fp_device_list_prints_finish (dev, res, &error);
if (!error)
{
if (!gallery->len)
{
g_warning ("No prints saved on device");
identify_quit (dev, identify_data);
return;
}
g_debug ("Identifying with %u prints in gallery", gallery->len);
fp_device_identify (dev, gallery, identify_data->cancellable,
on_identify_cb, identify_data, NULL,
(GAsyncReadyCallback) on_identify_completed,
identify_data);
}
else
{
g_warning ("Loading prints failed with error %s", error->message);
identify_quit (dev, identify_data);
}
}
static void
start_identification (FpDevice *dev, IdentifyData *identify_data)
{
if (fp_device_has_storage (dev))
{
g_print ("Creating finger template, using device storage...\n");
fp_device_list_prints (dev, NULL,
(GAsyncReadyCallback) on_list_completed,
identify_data);
}
else
{
g_autoptr(GPtrArray) gallery = gallery_data_load (dev);
if (!gallery)
{
identify_quit (dev, identify_data);
return;
}
g_print ("Gallery loaded. Time to identify!\n");
fp_device_identify (dev, gallery, identify_data->cancellable,
on_identify_cb, identify_data, NULL,
(GAsyncReadyCallback) on_identify_completed,
identify_data);
}
}
static void
on_device_opened (FpDevice *dev, GAsyncResult *res, void *user_data)
{
IdentifyData *identify_data = user_data;
g_autoptr(GError) error = NULL;
if (!fp_device_open_finish (dev, res, &error))
{
g_warning ("Failed to open device: %s", error->message);
identify_quit (dev, identify_data);
return;
}
g_print ("Opened device. ");
start_identification (dev, identify_data);
}
static gboolean
sigint_cb (void *user_data)
{
IdentifyData *identify_data = user_data;
g_cancellable_cancel (identify_data->cancellable);
return G_SOURCE_CONTINUE;
}
int
main (void)
{
g_autoptr(FpContext) ctx = NULL;
g_autoptr(IdentifyData) identify_data = NULL;
GPtrArray *devices;
FpDevice *dev;
setenv ("G_MESSAGES_DEBUG", "all", 0);
setenv ("LIBUSB_DEBUG", "3", 0);
ctx = fp_context_new ();
devices = fp_context_get_devices (ctx);
if (!devices)
{
g_warning ("Impossible to get devices");
return EXIT_FAILURE;
}
dev = discover_device (devices);
if (!dev)
{
g_warning ("No devices detected.");
return EXIT_FAILURE;
}
if (!fp_device_supports_identify (dev))
{
g_warning ("Device %s does not support identification.",
fp_device_get_name (dev));
return EXIT_FAILURE;
}
identify_data = g_new0 (IdentifyData, 1);
identify_data->ret_value = EXIT_FAILURE;
identify_data->loop = g_main_loop_new (NULL, FALSE);
identify_data->cancellable = g_cancellable_new ();
identify_data->sigint_handler = g_unix_signal_add_full (G_PRIORITY_HIGH,
SIGINT,
sigint_cb,
identify_data,
NULL);
fp_device_open (dev, identify_data->cancellable,
(GAsyncReadyCallback) on_device_opened,
identify_data);
g_main_loop_run (identify_data->loop);
return identify_data->ret_value;
}

View File

@@ -1,5 +1,12 @@
examples = [ 'enroll', 'verify', 'manage-prints', 'img-capture' ]
examples = [
'enroll',
'identify',
'img-capture',
'manage-prints',
'verify',
]
foreach example: examples
executable(example,
[ example + '.c', 'storage.c', 'utilities.c' ],

View File

@@ -2,7 +2,7 @@
* Trivial storage driver for example programs
*
* Copyright (C) 2019 Benjamin Berg <bberg@redhat.com>
* Copyright (C) 2019 Marco Trevisan <marco.trevisan@canonical.com>
* Copyright (C) 2019-2020 Marco Trevisan <marco.trevisan@canonical.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -160,6 +160,52 @@ print_data_load (FpDevice *dev, FpFinger finger)
return NULL;
}
GPtrArray *
gallery_data_load (FpDevice *dev)
{
g_autoptr(GVariantDict) dict = NULL;
g_autoptr(GVariant) dict_variant = NULL;
g_autofree char *dev_prefix = NULL;
GPtrArray *gallery;
const char *driver;
const char *dev_id;
GVariantIter iter;
GVariant *value;
gchar *key;
gallery = g_ptr_array_new_with_free_func (g_object_unref);
dict = load_data ();
dict_variant = g_variant_dict_end (dict);
driver = fp_device_get_driver (dev);
dev_id = fp_device_get_device_id (dev);
dev_prefix = g_strdup_printf ("%s/%s/", driver, dev_id);
g_variant_iter_init (&iter, dict_variant);
while (g_variant_iter_loop (&iter, "{sv}", &key, &value))
{
FpPrint *print;
const guchar *stored_data;
g_autoptr(GError) error = NULL;
gsize stored_len;
if (!g_str_has_prefix (key, dev_prefix))
continue;
stored_data = (const guchar *) g_variant_get_fixed_array (value, &stored_len, 1);
print = fp_print_deserialize (stored_data, stored_len, &error);
if (error)
{
g_warning ("Error deserializing data: %s", error->message);
continue;
}
g_ptr_array_add (gallery, print);
}
return gallery;
}
FpPrint *
print_create_template (FpDevice *dev, FpFinger finger)
{

View File

@@ -24,6 +24,7 @@ int print_data_save (FpPrint *print,
FpFinger finger);
FpPrint * print_data_load (FpDevice *dev,
FpFinger finger);
GPtrArray * gallery_data_load (FpDevice *dev);
FpPrint * print_create_template (FpDevice *dev,
FpFinger finger);
gboolean print_image_save (FpPrint *print,

View File

@@ -152,6 +152,26 @@ on_match_cb (FpDevice *dev, FpPrint *match, FpPrint *print,
}
}
static FpPrint *
get_stored_print (FpDevice *dev, VerifyData *verify_data)
{
FpPrint *verify_print;
g_print ("Loading previously enrolled %s finger data...\n",
finger_to_string (verify_data->finger));
verify_print = print_data_load (dev, verify_data->finger);
if (!verify_print)
{
g_warning ("Failed to load fingerprint data");
g_warning ("Did you remember to enroll your %s finger first?",
finger_to_string (verify_data->finger));
}
return verify_print;
}
static void
on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
{
@@ -165,15 +185,27 @@ on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
if (!error)
{
FpPrint *verify_print = NULL;
g_autoptr(FpPrint) stored_print = NULL;
guint i;
if (!prints->len)
g_warning ("No prints saved on device");
{
g_warning ("No prints saved on device");
verify_quit (dev, verify_data);
return;
}
stored_print = get_stored_print (dev, verify_data);
for (i = 0; i < prints->len; ++i)
{
FpPrint *print = prints->pdata[i];
if (stored_print && fp_print_equal (stored_print, print))
/* If the private print data matches, let's use the stored print
* as it contains more metadata to show */
print = stored_print;
if (fp_print_get_finger (print) == verify_data->finger &&
g_strcmp0 (fp_print_get_username (print), g_get_user_name ()) == 0)
{
@@ -191,8 +223,6 @@ on_list_completed (FpDevice *dev, GAsyncResult *res, gpointer user_data)
if (!verify_print)
{
g_warning ("Did you remember to enroll your %s finger first?",
finger_to_string (verify_data->finger));
verify_quit (dev, verify_data);
return;
}
@@ -239,17 +269,10 @@ start_verification (FpDevice *dev, VerifyData *verify_data)
}
else
{
g_print ("Loading previously enrolled %s finger data...\n",
finger_to_string (verify_data->finger));
g_autoptr(FpPrint) verify_print = NULL;
verify_print = print_data_load (dev, verify_data->finger);
g_autoptr(FpPrint) verify_print = get_stored_print (dev, verify_data);
if (!verify_print)
{
g_warning ("Failed to load fingerprint data");
g_warning ("Did you remember to enroll your %s finger first?",
finger_to_string (verify_data->finger));
verify_quit (dev, verify_data);
return;
}

View File

@@ -73,22 +73,19 @@ struct _FpiDeviceElan
/* end commands */
/* state */
gboolean deactivating;
FpiImageDeviceState dev_state;
FpiImageDeviceState dev_state_next;
unsigned char *last_read;
unsigned char calib_atts_left;
unsigned char calib_status;
unsigned short *background;
unsigned char frame_width;
unsigned char frame_height;
unsigned char raw_frame_height;
int num_frames;
GSList *frames;
gboolean active;
gboolean deactivating;
unsigned char *last_read;
unsigned char calib_atts_left;
unsigned char calib_status;
unsigned short *background;
unsigned char frame_width;
unsigned char frame_height;
unsigned char raw_frame_height;
int num_frames;
GSList *frames;
/* end state */
};
G_DECLARE_FINAL_TYPE (FpiDeviceElan, fpi_device_elan, FPI, DEVICE_ELAN,
FpImageDevice);
G_DEFINE_TYPE (FpiDeviceElan, fpi_device_elan, FP_TYPE_IMAGE_DEVICE);
static int
@@ -487,7 +484,7 @@ stop_capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
/* The device is inactive at this point. */
self->dev_state = FPI_IMAGE_DEVICE_STATE_INACTIVE;
self->active = FALSE;
if (self->deactivating)
{
@@ -505,16 +502,14 @@ stop_capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
}
static void
elan_stop_capture (FpDevice *dev)
elan_stop_capture (FpiDeviceElan *self)
{
FpiDeviceElan *self = FPI_DEVICE_ELAN (dev);
G_DEBUG_HERE ();
elan_dev_reset_state (self);
FpiSsm *ssm =
fpi_ssm_new (dev, stop_capture_run_state, STOP_CAPTURE_NUM_STATES);
fpi_ssm_new (FP_DEVICE (self), stop_capture_run_state, STOP_CAPTURE_NUM_STATES);
fpi_ssm_start (ssm, stop_capture_complete);
}
@@ -545,8 +540,6 @@ capture_run_state (FpiSsm *ssm, FpDevice *dev)
break;
case CAPTURE_READ_DATA:
self->dev_state = FPI_IMAGE_DEVICE_STATE_CAPTURE;
/* 0x55 - finger present
* 0xff - device not calibrated (probably) */
if (self->last_read && self->last_read[0] == 0x55)
@@ -614,18 +607,21 @@ capture_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
fpi_image_device_session_error (dev, error);
}
/* Note: We always stop capturing even if that may not be needed always.
* Doing this between captures appears to make it at least less likely for
* devices to end up in a bad state.
*/
elan_stop_capture (self);
}
static void
elan_capture (FpDevice *dev)
elan_capture (FpiDeviceElan *self)
{
FpiDeviceElan *self = FPI_DEVICE_ELAN (dev);
G_DEBUG_HERE ();
elan_dev_reset_state (self);
FpiSsm *ssm =
fpi_ssm_new (dev, capture_run_state, CAPTURE_NUM_STATES);
fpi_ssm_new (FP_DEVICE (self), capture_run_state, CAPTURE_NUM_STATES);
fpi_ssm_start (ssm, capture_complete);
}
@@ -777,33 +773,31 @@ calibrate_run_state (FpiSsm *ssm, FpDevice *dev)
static void
calibrate_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
{
FpiDeviceElan *self = FPI_DEVICE_ELAN (dev);
G_DEBUG_HERE ();
if (error)
{
self->dev_state = FPI_IMAGE_DEVICE_STATE_INACTIVE;
fpi_image_device_session_error (FP_IMAGE_DEVICE (dev), error);
elan_stop_capture (FPI_DEVICE_ELAN (dev));
}
else
{
elan_capture (dev);
elan_capture (FPI_DEVICE_ELAN (dev));
}
}
static void
elan_calibrate (FpDevice *dev)
elan_calibrate (FpiDeviceElan *self)
{
FpiDeviceElan *self = FPI_DEVICE_ELAN (dev);
G_DEBUG_HERE ();
elan_dev_reset_state (self);
g_return_if_fail (!self->active);
self->active = TRUE;
self->calib_atts_left = ELAN_CALIBRATION_ATTEMPTS;
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (dev), calibrate_run_state,
FpiSsm *ssm = fpi_ssm_new (FP_DEVICE (self), calibrate_run_state,
CALIBRATE_NUM_STATES);
fpi_ssm_start (ssm, calibrate_complete);
@@ -958,98 +952,19 @@ dev_activate (FpImageDevice *dev)
elan_activate (dev);
}
static void
elan_change_state (FpImageDevice *idev)
{
FpDevice *dev = FP_DEVICE (idev);
FpiDeviceElan *self = FPI_DEVICE_ELAN (dev);
FpiImageDeviceState next_state = self->dev_state_next;
if (self->dev_state == next_state)
{
fp_dbg ("already in %d", next_state);
return;
}
else
{
fp_dbg ("changing to %d", next_state);
}
switch (next_state)
{
case FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON:
/* activation completed or another enroll stage started */
self->dev_state = FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON;
elan_calibrate (dev);
break;
case FPI_IMAGE_DEVICE_STATE_CAPTURE:
/* not used */
break;
case FPI_IMAGE_DEVICE_STATE_INACTIVE:
case FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF:
elan_stop_capture (dev);
break;
}
}
static void
elan_change_state_async (FpDevice *dev,
void *data)
{
fp_dbg ("state change dev: %p", dev);
elan_change_state (FP_IMAGE_DEVICE (dev));
}
static void
dev_change_state (FpImageDevice *dev, FpiImageDeviceState state)
{
FpiDeviceElan *self = FPI_DEVICE_ELAN (dev);
GSource *timeout;
G_DEBUG_HERE ();
/* Inactive and await finger off are equivalent for the elan driver. */
if (state == FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF)
state = FPI_IMAGE_DEVICE_STATE_INACTIVE;
if (self->dev_state_next == state)
{
fp_dbg ("change to state %d already queued", state);
return;
}
switch (state)
{
case FPI_IMAGE_DEVICE_STATE_INACTIVE:
case FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON:
case FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF: {
char *name;
/* schedule state change instead of calling it directly to allow all actions
* related to the previous state to complete */
self->dev_state_next = state;
timeout = fpi_device_add_timeout (FP_DEVICE (dev), 10,
elan_change_state_async,
NULL, NULL);
name = g_strdup_printf ("dev_change_state to %d", state);
g_source_set_name (timeout, name);
g_free (name);
break;
}
case FPI_IMAGE_DEVICE_STATE_CAPTURE:
/* TODO MAYBE: split capture ssm into smaller ssms and use this state */
self->dev_state = state;
self->dev_state_next = state;
break;
default:
g_assert_not_reached ();
}
/* Note: We always calibrate even if that may not be needed always.
* Doing this for each capture appears to make it at least less likely for
* devices to end up in a bad state.
*/
if (state == FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON)
elan_calibrate (self);
}
static void
@@ -1059,19 +974,14 @@ dev_deactivate (FpImageDevice *dev)
G_DEBUG_HERE ();
if (self->dev_state == FPI_IMAGE_DEVICE_STATE_INACTIVE)
{
/* The device is inactive already, complete the operation immediately. */
fpi_image_device_deactivate_complete (dev, NULL);
}
if (!self->active)
/* The device is inactive already, complete the operation immediately. */
fpi_image_device_deactivate_complete (dev, NULL);
else
{
/* The device is not yet inactive, flag that we are deactivating (and
* need to signal back deactivation) and then ensure we will change
* to the inactive state eventually. */
self->deactivating = TRUE;
dev_change_state (dev, FPI_IMAGE_DEVICE_STATE_INACTIVE);
}
/* The device is not yet inactive, flag that we are deactivating (and
* need to signal back deactivation).
* Note that any running capture will be cancelled already if needed. */
self->deactivating = TRUE;
}
static void

View File

@@ -70,6 +70,9 @@
#define ELAN_CMD_TIMEOUT 10000
#define ELAN_FINGER_TIMEOUT 200
G_DECLARE_FINAL_TYPE (FpiDeviceElan, fpi_device_elan, FPI, DEVICE_ELAN,
FpImageDevice);
struct elan_cmd
{
unsigned char cmd[ELAN_CMD_LEN];
@@ -211,6 +214,7 @@ static const FpIdEntry elan_id_table[] = {
{.vid = ELAN_VEND_ID, .pid = 0x0c32, .driver_data = ELAN_ALL_DEV},
{.vid = ELAN_VEND_ID, .pid = 0x0c33, .driver_data = ELAN_ALL_DEV},
{.vid = ELAN_VEND_ID, .pid = 0x0c42, .driver_data = ELAN_0C42},
{.vid = ELAN_VEND_ID, .pid = 0x0c4d, .driver_data = ELAN_ALL_DEV},
{.vid = 0, .pid = 0, .driver_data = 0},
};
@@ -218,8 +222,8 @@ static void elan_cmd_done (FpiSsm *ssm);
static void elan_cmd_read (FpiSsm *ssm,
FpDevice *dev);
static void elan_calibrate (FpDevice *dev);
static void elan_capture (FpDevice *dev);
static void elan_calibrate (FpiDeviceElan *self);
static void elan_capture (FpiDeviceElan *self);
static void dev_change_state (FpImageDevice *dev,
FpiImageDeviceState state);

View File

@@ -350,9 +350,9 @@ fp_verify_cb (FpiDeviceGoodixMoc *self,
gxfp_cmd_response_t *resp,
GError *error)
{
g_autoptr(GPtrArray) templates = NULL;
FpDevice *device = FP_DEVICE (self);
FpPrint *print = NULL;
GPtrArray *templates = NULL;
gint cnt = 0;
gboolean find = false;
@@ -365,15 +365,14 @@ fp_verify_cb (FpiDeviceGoodixMoc *self,
{
if (fpi_device_get_current_action (device) == FPI_DEVICE_ACTION_VERIFY)
{
templates = g_ptr_array_new_with_free_func (g_object_unref);
templates = g_ptr_array_sized_new (1);
fpi_device_get_verify_data (device, &print);
g_ptr_array_add (templates, g_object_ref_sink (print));
g_ptr_array_add (templates, print);
}
else
{
fpi_device_get_identify_data (device, &templates);
g_ptr_array_ref (templates);
}
for (cnt = 0; cnt < templates->len; cnt++)
{

View File

@@ -229,7 +229,7 @@ gx_proto_parse_header (
memcpy (pheader, buffer, sizeof (pack_header));
pheader->len = GUINT16_FROM_LE (*(buffer + 4));
pheader->len = GUINT16_FROM_LE ( *(uint16_t *) (buffer + 4));
pheader->len -= PACKAGE_CRC_SIZE;
return 0;

View File

@@ -34,6 +34,8 @@ static const FpIdEntry id_table[] = {
{ .vid = SYNAPTICS_VENDOR_ID, .pid = 0xF9, },
{ .vid = SYNAPTICS_VENDOR_ID, .pid = 0xFC, },
{ .vid = SYNAPTICS_VENDOR_ID, .pid = 0xC2, },
{ .vid = SYNAPTICS_VENDOR_ID, .pid = 0xC9, },
{ .vid = SYNAPTICS_VENDOR_ID, .pid = 0xE7, },
{ .vid = 0, .pid = 0, .driver_data = 0 }, /* terminating entry */
};
@@ -82,10 +84,17 @@ cmd_receive_cb (FpiUsbTransfer *transfer,
if (msg_resp.payload[0] == 0x01)
{
self->finger_on_sensor = TRUE;
fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_PRESENT,
FP_FINGER_STATUS_NONE);
}
else
{
self->finger_on_sensor = FALSE;
fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_NONE,
FP_FINGER_STATUS_PRESENT);
if (self->cmd_complete_on_removal)
{
fpi_ssm_mark_completed (transfer->ssm);
@@ -197,12 +206,19 @@ cmd_interrupt_cb (FpiUsbTransfer *transfer,
fpi_ssm_mark_failed (transfer->ssm, error);
return;
}
g_clear_pointer (&error, g_error_free);
if (transfer->buffer[0] & USB_ASYNC_MESSAGE_PENDING || error)
fpi_ssm_next_state (transfer->ssm);
if (transfer->buffer[0] & USB_ASYNC_MESSAGE_PENDING)
{
fpi_ssm_next_state (transfer->ssm);
}
else
fpi_usb_transfer_submit (transfer, 1000, NULL, cmd_interrupt_cb, NULL);
{
fpi_usb_transfer_submit (fpi_usb_transfer_ref (transfer),
0,
NULL,
cmd_interrupt_cb,
NULL);
}
}
static void
@@ -589,6 +605,9 @@ verify_msg_cb (FpiDeviceSynaptics *self,
switch (resp->response_id)
{
case BMKT_RSP_VERIFY_READY:
fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_NEEDED,
FP_FINGER_STATUS_NONE);
fp_info ("Place Finger on the Sensor!");
break;
@@ -832,6 +851,9 @@ enroll_msg_cb (FpiDeviceSynaptics *self,
case BMKT_RSP_ENROLL_READY:
{
self->enroll_stage = 0;
fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_NEEDED,
FP_FINGER_STATUS_NONE);
fp_info ("Place Finger on the Sensor!");
break;
}

View File

@@ -527,15 +527,6 @@ initsm_read_msg_response_cb (FpiSsm *ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
"Unexpected response subcommand"));
}
else if (seq != upekdev->seq)
{
fp_err ("expected response to cmd seq=%02x, got response to %02x "
"in state %d", upekdev->seq, seq,
fpi_ssm_get_cur_state (ssm));
fpi_ssm_mark_failed (ssm,
fpi_device_error_new_msg (FP_DEVICE_ERROR_PROTO,
"Unexpected sequence number in response"));
}
else
{
fpi_ssm_next_state (ssm);

View File

@@ -412,18 +412,6 @@ dev_change_state (FpImageDevice *dev, FpiImageDeviceState state)
{
FpiDeviceUru4000 *self = FPI_DEVICE_URU4000 (dev);
switch (state)
{
case FPI_IMAGE_DEVICE_STATE_INACTIVE:
case FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON:
case FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF:
case FPI_IMAGE_DEVICE_STATE_CAPTURE:
break;
default:
g_assert_not_reached ();
}
self->activate_state = state;
if (self->img_transfer != NULL)
return;
@@ -663,7 +651,11 @@ imaging_run_state (FpiSsm *ssm, FpDevice *_dev)
case IMAGING_CAPTURE:
self->img_lines_done = 0;
self->img_block = 0;
fpi_usb_transfer_submit (self->img_transfer, 0, NULL, image_transfer_cb, NULL);
fpi_usb_transfer_submit (fpi_usb_transfer_ref (self->img_transfer),
0,
NULL,
image_transfer_cb,
NULL);
break;
@@ -799,8 +791,7 @@ imaging_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
if (error)
fpi_image_device_session_error (FP_IMAGE_DEVICE (dev), error);
/* Freed by callback or cancellation */
self->img_transfer = NULL;
g_clear_pointer (&self->img_transfer, fpi_usb_transfer_unref);
g_free (self->img_data);
self->img_data = NULL;
@@ -1182,7 +1173,10 @@ deactivate_write_reg_cb (FpiUsbTransfer *transfer, FpDevice *dev,
static void
dev_deactivate (FpImageDevice *dev)
{
dev_change_state (dev, FPI_IMAGE_DEVICE_STATE_INACTIVE);
/* This is started/handled by execute_state_change in order to delay the
* action until after the image transfer has completed.
* We just need to override the function so that the complete handler is
* not called automatically. */
}
static void
@@ -1193,7 +1187,7 @@ execute_state_change (FpImageDevice *dev)
switch (self->activate_state)
{
case FPI_IMAGE_DEVICE_STATE_INACTIVE:
case FPI_IMAGE_DEVICE_STATE_DEACTIVATING:
fp_dbg ("deactivating");
self->irq_cb = NULL;
self->irq_cb_data = NULL;
@@ -1248,6 +1242,12 @@ execute_state_change (FpImageDevice *dev)
write_reg (dev, REG_MODE, MODE_AWAIT_FINGER_OFF,
change_state_write_reg_cb, NULL);
break;
/* Ignored states */
case FPI_IMAGE_DEVICE_STATE_IDLE:
case FPI_IMAGE_DEVICE_STATE_ACTIVATING:
case FPI_IMAGE_DEVICE_STATE_INACTIVE:
break;
}
}

View File

@@ -147,18 +147,6 @@ m_loop_state (FpiSsm *ssm, FpDevice *_dev)
}
}
/* Complete loop sequential state machine */
static void
m_loop_complete (FpiSsm *ssm, FpDevice *_dev, GError *error)
{
if (error)
{
g_warning ("State machine completed with an error: %s", error->message);
g_error_free (error);
}
/* Free sequential state machine */
}
/* Exec init sequential state machine */
static void
m_init_state (FpiSsm *ssm, FpDevice *_dev)
@@ -176,19 +164,7 @@ m_init_state (FpiSsm *ssm, FpDevice *_dev)
static void
m_init_complete (FpiSsm *ssm, FpDevice *dev, GError *error)
{
FpiSsm *ssm_loop;
fpi_image_device_activate_complete (FP_IMAGE_DEVICE (dev), error);
if (!error)
{
/* Notify activate complete */
/* Start loop ssm */
ssm_loop = fpi_ssm_new (dev, m_loop_state, M_LOOP_NUM_STATES);
fpi_ssm_start (ssm_loop, m_loop_complete);
}
/* Free sequential state machine */
}
/* Activate device */
@@ -213,6 +189,19 @@ dev_deactivate (FpImageDevice *dev)
fpi_image_device_deactivate_complete (dev, NULL);
}
static void
dev_change_state (FpImageDevice *dev, FpiImageDeviceState state)
{
FpiSsm *ssm_loop;
if (state != FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON)
return;
/* Start a capture operation. */
ssm_loop = fpi_ssm_new (FP_DEVICE (dev), m_loop_state, M_LOOP_NUM_STATES);
fpi_ssm_start (ssm_loop, NULL);
}
static void
dev_open (FpImageDevice *dev)
{
@@ -273,6 +262,7 @@ fpi_device_vfs301_class_init (FpDeviceVfs301Class *klass)
img_class->img_close = dev_close;
img_class->activate = dev_activate;
img_class->deactivate = dev_deactivate;
img_class->change_state = dev_change_state;
img_class->bz3_threshold = 24;

View File

@@ -213,11 +213,9 @@ vfs301_proto_generate (int type, int subtype, gssize *len)
*len = 1;
return data;
}
break;
case 0x0B:
return vfs301_proto_generate_0B (subtype, len);
break;
case 0x02D0:
{
@@ -233,22 +231,18 @@ vfs301_proto_generate (int type, int subtype, gssize *len)
g_assert ((int) subtype <= G_N_ELEMENTS (dataLs));
return translate_str (dataLs[subtype - 1], len);
}
break;
case 0x0220:
switch (subtype)
{
case 1:
return translate_str (vfs301_0220_01, len);
break;
case 2:
return translate_str (vfs301_0220_02, len);
break;
case 3:
return translate_str (vfs301_0220_03, len);
break;
case 0xFA00:
case 0x2C01:
@@ -271,7 +265,6 @@ vfs301_proto_generate (int type, int subtype, gssize *len)
field[3] = field[1];
return data;
break;
}
default:
@@ -509,30 +502,30 @@ vfs301_proto_process_event_cb (FpiUsbTransfer *transfer,
FpDevice *device,
gpointer user_data, GError *error)
{
FpDeviceVfs301 *dev = user_data;
FpDeviceVfs301 *self = FPI_DEVICE_VFS301 (device);
if (error)
{
g_warning ("Error receiving data: %s", error->message);
g_error_free (error);
dev->recv_progress = VFS301_FAILURE;
self->recv_progress = VFS301_FAILURE;
return;
}
else if (transfer->actual_length < transfer->length)
{
/* TODO: process the data anyway? */
dev->recv_progress = VFS301_ENDED;
self->recv_progress = VFS301_ENDED;
return;
}
else
{
FpiUsbTransfer *new;
if (!vfs301_proto_process_data (dev,
if (!vfs301_proto_process_data (self,
transfer->length == VFS301_FP_RECV_LEN_1,
transfer->buffer,
transfer->actual_length))
{
dev->recv_progress = VFS301_ENDED;
self->recv_progress = VFS301_ENDED;
return;
}

View File

@@ -73,14 +73,21 @@ recv_image_img_recv_cb (GObject *source_object,
success = g_input_stream_read_all_finish (G_INPUT_STREAM (source_object), res, &bytes, &error);
if (!success || bytes == 0)
/* Can't use self if the operation was cancelled. */
if (!success && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
device = FP_IMAGE_DEVICE (self);
/* Consider success if we received the right amount of data, otherwise
* an error must have happened. */
if (bytes < self->recv_img->width * self->recv_img->height)
{
if (!success)
{
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
return;
g_warning ("Error receiving header for image data: %s", error->message);
}
g_warning ("Error receiving image data: %s", error->message);
else
g_warning ("Error receiving image data: end of stream before all data was read");
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
@@ -88,9 +95,6 @@ recv_image_img_recv_cb (GObject *source_object,
return;
}
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
device = FP_IMAGE_DEVICE (self);
if (self->automatic_finger)
fpi_image_device_report_finger_status (device, TRUE);
fpi_image_device_image_captured (device, g_steal_pointer (&self->recv_img));
@@ -113,7 +117,7 @@ recv_image_hdr_recv_cb (GObject *source_object,
success = g_input_stream_read_all_finish (G_INPUT_STREAM (source_object), res, &bytes, &error);
if (!success || bytes == 0)
if (!success || bytes != sizeof (self->recv_img_hdr))
{
if (!success)
{
@@ -122,6 +126,10 @@ recv_image_hdr_recv_cb (GObject *source_object,
return;
g_warning ("Error receiving header for image data: %s", error->message);
}
else if (bytes != 0)
{
g_warning ("Received incomplete header before end of stream.");
}
self = FPI_DEVICE_VIRTUAL_IMAGE (user_data);
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
@@ -163,6 +171,11 @@ recv_image_hdr_recv_cb (GObject *source_object,
!!self->recv_img_hdr[1]);
break;
case -5:
/* -5 causes the device to disappear (no further data) */
fpi_device_remove (FP_DEVICE (self));
break;
default:
/* disconnect client, it didn't play fair */
g_io_stream_close (G_IO_STREAM (self->connection), NULL, NULL);
@@ -195,7 +208,7 @@ recv_image (FpDeviceVirtualImage *self, GInputStream *stream)
g_debug ("Starting image receive (if active), state is: %i", state);
/* Only register if the state is active. */
if (state != FPI_IMAGE_DEVICE_STATE_INACTIVE)
if (state >= FPI_IMAGE_DEVICE_STATE_IDLE)
{
g_input_stream_read_all_async (stream,
self->recv_img_hdr,
@@ -235,10 +248,12 @@ new_connection_cb (GObject *source_object, GAsyncResult *res, gpointer user_data
if (dev->connection)
{
/* We may not have noticed that the stream was closed,
* if the device is deactivated. Double check here. */
g_input_stream_is_closed (g_io_stream_get_input_stream (G_IO_STREAM (dev->connection)));
* if the device is deactivated.
* Cancel any ongoing operation on the old connection. */
g_cancellable_cancel (dev->cancellable);
g_clear_object (&dev->cancellable);
dev->cancellable = g_cancellable_new ();
g_io_stream_close (G_IO_STREAM (dev->connection), NULL, NULL);
g_clear_object (&dev->connection);
}
@@ -338,10 +353,10 @@ dev_activate (FpImageDevice *dev)
{
FpDeviceVirtualImage *self = FPI_DEVICE_VIRTUAL_IMAGE (dev);
fpi_image_device_activate_complete (dev, NULL);
if (self->connection)
recv_image (self, g_io_stream_get_input_stream (G_IO_STREAM (self->connection)));
fpi_image_device_activate_complete (dev, NULL);
}
static void
@@ -357,9 +372,36 @@ dev_deactivate (FpImageDevice *dev)
fpi_device_add_timeout (FP_DEVICE (dev), 10, (FpTimeoutFunc) fpi_image_device_deactivate_complete, NULL, NULL);
}
static void
dev_notify_removed_cb (FpDevice *dev)
{
FpiImageDeviceState state;
gboolean removed;
g_object_get (dev,
"fpi-image-device-state", &state,
"removed", &removed,
NULL);
if (!removed || state == FPI_IMAGE_DEVICE_STATE_INACTIVE)
return;
/* This error will be converted to an FP_DEVICE_ERROR_REMOVED by the
* surrounding layers. */
fpi_image_device_session_error (FP_IMAGE_DEVICE (dev),
fpi_device_error_new (FP_DEVICE_ERROR_PROTO));
}
static void
fpi_device_virtual_image_init (FpDeviceVirtualImage *self)
{
/* NOTE: This is not nice, but we can generally rely on the underlying
* system to throw errors on the transport layer.
*/
g_signal_connect (self,
"notify::removed",
G_CALLBACK (dev_notify_removed_cb),
NULL);
}
static const FpIdEntry driver_ids[] = {

View File

@@ -86,6 +86,60 @@ is_driver_allowed (const gchar *driver)
return FALSE;
}
typedef struct
{
FpContext *context;
FpDevice *device;
} RemoveDeviceData;
static gboolean
remove_device_idle_cb (RemoveDeviceData *data)
{
FpContextPrivate *priv = fp_context_get_instance_private (data->context);
guint idx = 0;
g_return_val_if_fail (g_ptr_array_find (priv->devices, data->device, &idx), G_SOURCE_REMOVE);
g_signal_emit (data->context, signals[DEVICE_REMOVED_SIGNAL], 0, data->device);
g_ptr_array_remove_index_fast (priv->devices, idx);
g_free (data);
return G_SOURCE_REMOVE;
}
static void
remove_device (FpContext *context, FpDevice *device)
{
RemoveDeviceData *data;
data = g_new (RemoveDeviceData, 1);
data->context = context;
data->device = device;
g_idle_add ((GSourceFunc) remove_device_idle_cb, data);
}
static void
device_remove_on_notify_open_cb (FpContext *context, GParamSpec *pspec, FpDevice *device)
{
remove_device (context, device);
}
static void
device_removed_cb (FpContext *context, FpDevice *device)
{
gboolean open = FALSE;
g_object_get (device, "open", &open, NULL);
/* Wait for device close if the device is currently still open. */
if (open)
g_signal_connect_swapped (device, "notify::open", (GCallback) device_remove_on_notify_open_cb, context);
else
remove_device (context, device);
}
static void
async_device_init_done_cb (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
@@ -110,6 +164,9 @@ async_device_init_done_cb (GObject *source_object, GAsyncResult *res, gpointer u
}
g_ptr_array_add (priv->devices, device);
g_signal_connect_swapped (device, "removed", (GCallback) device_removed_cb, context);
g_signal_emit (context, signals[DEVICE_ADDED_SIGNAL], 0, device);
}
@@ -189,12 +246,7 @@ usb_device_removed_cb (FpContext *self, GUsbDevice *device, GUsbContext *usb_ctx
continue;
if (fpi_device_get_usb_device (dev) == device)
{
g_signal_emit (self, signals[DEVICE_REMOVED_SIGNAL], 0, dev);
g_ptr_array_remove_index_fast (priv->devices, i);
return;
}
fpi_device_remove (dev);
}
}
@@ -248,6 +300,10 @@ fp_context_class_init (FpContextClass *klass)
* @device: A #FpDevice
*
* This signal is emitted when a fingerprint reader is removed.
*
* It is guaranteed that the device has been closed before this signal
* is emitted. See the #FpDevice removed signal documentation for more
* information.
**/
signals[DEVICE_REMOVED_SIGNAL] = g_signal_new ("device-removed",
G_TYPE_FROM_CLASS (klass),

View File

@@ -29,6 +29,7 @@ typedef struct
GUsbDevice *usb_device;
const gchar *virtual_env;
gboolean is_removed;
gboolean is_open;
gchar *device_id;
@@ -49,7 +50,8 @@ typedef struct
GSource *current_task_idle_return_source;
/* State for tasks */
gboolean wait_for_finger;
gboolean wait_for_finger;
FpFingerStatusFlags finger_status;
} FpDevicePrivate;

View File

@@ -44,8 +44,10 @@ enum {
PROP_DEVICE_ID,
PROP_NAME,
PROP_OPEN,
PROP_REMOVED,
PROP_NR_ENROLL_STAGES,
PROP_SCAN_TYPE,
PROP_FINGER_STATUS,
PROP_FPI_ENVIRON,
PROP_FPI_USB_DEVICE,
PROP_FPI_DRIVER_DATA,
@@ -54,6 +56,13 @@ enum {
static GParamSpec *properties[N_PROPS];
enum {
REMOVED_SIGNAL,
N_SIGNALS
};
static guint signals[N_SIGNALS] = { 0, };
/**
* fp_device_retry_quark:
*
@@ -84,6 +93,8 @@ fp_device_cancel_in_idle_cb (gpointer user_data)
cls->cancel (self);
fpi_device_report_finger_status (self, FP_FINGER_STATUS_NONE);
return G_SOURCE_REMOVE;
}
@@ -181,6 +192,10 @@ fp_device_get_property (GObject *object,
g_value_set_enum (value, priv->scan_type);
break;
case PROP_FINGER_STATUS:
g_value_set_flags (value, priv->finger_status);
break;
case PROP_DRIVER:
g_value_set_static_string (value, FP_DEVICE_GET_CLASS (priv)->id);
break;
@@ -197,6 +212,10 @@ fp_device_get_property (GObject *object,
g_value_set_boolean (value, priv->is_open);
break;
case PROP_REMOVED:
g_value_set_boolean (value, priv->is_removed);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -310,6 +329,13 @@ fp_device_class_init (FpDeviceClass *klass)
FP_TYPE_SCAN_TYPE, FP_SCAN_TYPE_SWIPE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
properties[PROP_FINGER_STATUS] =
g_param_spec_flags ("finger-status",
"FingerStatus",
"The status of the finger",
FP_TYPE_FINGER_STATUS_FLAGS, FP_FINGER_STATUS_NONE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
properties[PROP_DRIVER] =
g_param_spec_string ("driver",
"Driver",
@@ -337,6 +363,41 @@ fp_device_class_init (FpDeviceClass *klass)
"Whether the device is open or not", FALSE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
properties[PROP_REMOVED] =
g_param_spec_boolean ("removed",
"Removed",
"Whether the device has been removed from the system", FALSE,
G_PARAM_STATIC_STRINGS | G_PARAM_READABLE);
/**
* FpDevice::removed:
* @device: the #FpDevice instance that emitted the signal
*
* This signal is emitted after the device has been removed and no operation
* is pending anymore.
*
* The API user is still required to close a removed device. The above
* guarantee means that the call to close the device can be made immediately
* from the signal handler.
*
* The close operation will return FP_DEVICE_ERROR_REMOVED, but the device
* will still be considered closed afterwards.
*
* The device will only be removed from the #FpContext after it has been
* closed by the API user.
**/
signals[REMOVED_SIGNAL] = g_signal_new ("removed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
/* Private properties */
/**
* FpDevice::fpi-environ: (skip)
*
@@ -469,6 +530,26 @@ fp_device_get_scan_type (FpDevice *device)
return priv->scan_type;
}
/**
* fp_device_get_finger_status:
* @device: A #FpDevice
*
* Retrieves the finger status flags for the device.
* This can be used by the UI to present the relevant feedback, although it
* is not guaranteed to be a relevant value when not performing any action.
*
* Returns: The current #FpFingerStatusFlags
*/
FpFingerStatusFlags
fp_device_get_finger_status (FpDevice *device)
{
FpDevicePrivate *priv = fp_device_get_instance_private (device);
g_return_val_if_fail (FP_IS_DEVICE (device), FP_FINGER_STATUS_NONE);
return priv->finger_status;
}
/**
* fp_device_get_nr_enroll_stages:
* @device: A #FpDevice
@@ -603,6 +684,7 @@ fp_device_open (FpDevice *device,
priv->current_action = FPI_DEVICE_ACTION_OPEN;
priv->current_task = g_steal_pointer (&task);
maybe_cancel_on_cancelled (device, cancellable);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
FP_DEVICE_GET_CLASS (device)->open (device);
}
@@ -936,6 +1018,7 @@ fp_device_identify (FpDevice *device,
g_autoptr(GTask) task = NULL;
FpDevicePrivate *priv = fp_device_get_instance_private (device);
FpMatchData *data;
int i;
task = g_task_new (device, cancellable, callback, user_data);
if (g_task_return_error_if_cancelled (task))
@@ -960,7 +1043,13 @@ fp_device_identify (FpDevice *device,
maybe_cancel_on_cancelled (device, cancellable);
data = g_new0 (FpMatchData, 1);
data->gallery = g_ptr_array_ref (prints);
/* We cannot store the gallery directly, because the ptr array may not own
* a reference to each print. Also, the caller could in principle modify the
* GPtrArray afterwards.
*/
data->gallery = g_ptr_array_new_full (prints->len, g_object_unref);
for (i = 0; i < prints->len; i++)
g_ptr_array_add (data->gallery, g_object_ref (g_ptr_array_index (prints, i)));
data->match_cb = match_cb;
data->match_data = match_data;
data->match_destroy = match_destroy;

View File

@@ -91,6 +91,7 @@ typedef enum {
* @FP_DEVICE_ERROR_DATA_NOT_FOUND: Requested print was not found on device
* @FP_DEVICE_ERROR_DATA_FULL: No space on device available for operation
* @FP_DEVICE_ERROR_DATA_DUPLICATE: Enrolling template duplicates storaged templates
* @FP_DEVICE_ERROR_REMOVED: The device has been removed.
*
* Error codes for device operations. More specific errors from other domains
* such as #G_IO_ERROR or #G_USB_DEVICE_ERROR may also be reported.
@@ -106,6 +107,8 @@ typedef enum {
FP_DEVICE_ERROR_DATA_NOT_FOUND,
FP_DEVICE_ERROR_DATA_FULL,
FP_DEVICE_ERROR_DATA_DUPLICATE,
/* Leave some room to add more DATA related errors */
FP_DEVICE_ERROR_REMOVED = 0x100,
} FpDeviceError;
GQuark fp_device_retry_quark (void);
@@ -170,6 +173,7 @@ const gchar *fp_device_get_device_id (FpDevice *device);
const gchar *fp_device_get_name (FpDevice *device);
gboolean fp_device_is_open (FpDevice *device);
FpScanType fp_device_get_scan_type (FpDevice *device);
FpFingerStatusFlags fp_device_get_finger_status (FpDevice *device);
gint fp_device_get_nr_enroll_stages (FpDevice *device);
gboolean fp_device_supports_identify (FpDevice *device);

View File

@@ -27,7 +27,6 @@ typedef struct
{
FpiImageDeviceState state;
gboolean active;
gboolean cancelling;
gboolean finger_present;
@@ -42,4 +41,5 @@ typedef struct
void fpi_image_device_activate (FpImageDevice *image_device);
void fpi_image_device_deactivate (FpImageDevice *image_device);
void fpi_image_device_deactivate (FpImageDevice *image_device,
gboolean cancelling);

View File

@@ -82,7 +82,6 @@ static void
fp_image_device_cancel_action (FpDevice *device)
{
FpImageDevice *self = FP_IMAGE_DEVICE (device);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpiDeviceAction action;
action = fpi_device_get_current_action (device);
@@ -93,11 +92,7 @@ fp_image_device_cancel_action (FpDevice *device)
action == FPI_DEVICE_ACTION_VERIFY ||
action == FPI_DEVICE_ACTION_IDENTIFY ||
action == FPI_DEVICE_ACTION_CAPTURE)
{
priv->cancelling = TRUE;
fpi_image_device_deactivate (self);
priv->cancelling = FALSE;
}
fpi_image_device_deactivate (self, TRUE);
}
static void

View File

@@ -281,7 +281,7 @@ fp_image_detect_minutiae_thread_func (GTask *task,
gint map_w, map_h;
gint bw, bh, bd;
gint r;
g_autofree LFSPARMS *lfsparms;
g_autofree LFSPARMS *lfsparms = NULL;
/* Normalize the image first */
if (data->flags & FPI_IMAGE_H_FLIPPED)

View File

@@ -667,36 +667,25 @@ fp_print_serialize (FpPrint *print,
for (i = 0; i < print->prints->len; i++)
{
struct xyt_struct *xyt = g_ptr_array_index (print->prints, i);
gint j;
gint32 *col = g_new (gint32, xyt->nrows);
g_variant_builder_open (&nested, G_VARIANT_TYPE ("(aiaiai)"));
for (j = 0; j < xyt->nrows; j++)
col[j] = GINT32_TO_LE (xyt->xcol[j]);
g_variant_builder_add_value (&nested,
g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
col,
xyt->xcol,
xyt->nrows,
sizeof (col[0])));
for (j = 0; j < xyt->nrows; j++)
col[j] = GINT32_TO_LE (xyt->ycol[j]);
sizeof (xyt->xcol[0])));
g_variant_builder_add_value (&nested,
g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
col,
xyt->ycol,
xyt->nrows,
sizeof (col[0])));
for (j = 0; j < xyt->nrows; j++)
col[j] = GINT32_TO_LE (xyt->thetacol[j]);
sizeof (xyt->ycol[0])));
g_variant_builder_add_value (&nested,
g_variant_new_fixed_array (G_VARIANT_TYPE_INT32,
col,
xyt->thetacol,
xyt->nrows,
sizeof (col[0])));
sizeof (xyt->thetacol[0])));
g_variant_builder_close (&nested);
g_free (col);
}
g_variant_builder_close (&nested);
@@ -819,6 +808,7 @@ fp_print_deserialize (const guchar *data,
"device-id", device_id,
"device-stored", device_stored,
NULL);
g_object_ref_sink (result);
fpi_print_set_type (result, FPI_PRINT_NBIS);
for (i = 0; i < g_variant_n_children (prints); i++)
{
@@ -868,6 +858,7 @@ fp_print_deserialize (const guchar *data,
"device-stored", device_stored,
"fpi-data", fp_data,
NULL);
g_object_ref_sink (result);
}
else
{
@@ -886,8 +877,7 @@ fp_print_deserialize (const guchar *data,
return g_steal_pointer (&result);
invalid_format:
*error = g_error_new_literal (G_IO_ERROR,
G_IO_ERROR_INVALID_DATA,
"Data could not be parsed");
return FALSE;
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
"Data could not be parsed");
return NULL;
}

View File

@@ -66,12 +66,19 @@ typedef enum {
FP_FINGER_LAST = FP_FINGER_RIGHT_LITTLE,
} FpFinger;
FpPrint *fp_print_new (FpDevice *device);
/**
* FpFingerStatusFlags:
* @FP_FINGER_STATUS_NONE: Sensor has not the finger on it, nor requires it
* @FP_FINGER_STATUS_NEEDED: Sensor waits for the finger
* @FP_FINGER_STATUS_PRESENT: Sensor has the finger on it
*/
typedef enum {
FP_FINGER_STATUS_NONE = 0,
FP_FINGER_STATUS_NEEDED = 1 << 0,
FP_FINGER_STATUS_PRESENT = 1 << 1,
} FpFingerStatusFlags;
FpPrint *fp_print_new_from_data (guchar *data,
gsize length);
gboolean fp_print_to_data (guchar **data,
gsize length);
FpPrint *fp_print_new (FpDevice *device);
const gchar *fp_print_get_driver (FpPrint *print);
const gchar *fp_print_get_device_id (FpPrint *print);

View File

@@ -23,6 +23,7 @@
#if !GLIB_CHECK_VERSION (2, 57, 0)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GTypeClass, g_type_class_unref);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GEnumClass, g_type_class_unref);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GFlagsClass, g_type_class_unref);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (GParamSpec, g_param_spec_unref);
#else
/* Re-define G_SOURCE_FUNC as we are technically not allowed to use it with

View File

@@ -139,6 +139,10 @@ fpi_device_error_new (FpDeviceError error)
msg = "This finger has already enrolled, please try a different finger";
break;
case FP_DEVICE_ERROR_REMOVED:
msg = "This device has been removed from the system.";
break;
default:
g_warning ("Unsupported error, returning general error instead!");
error = FP_DEVICE_ERROR_GENERAL;
@@ -576,6 +580,49 @@ fpi_device_get_cancellable (FpDevice *device)
return g_task_get_cancellable (priv->current_task);
}
static void
emit_removed_on_task_completed (FpDevice *device)
{
g_signal_emit_by_name (device, "removed");
}
/**
* fpi_device_remove:
* @device: The #FpDevice
*
* Called to signal to the #FpDevice that it has been unplugged (physically
* removed from the system).
*
* For USB devices, this API is called automatically by #FpContext.
*/
void
fpi_device_remove (FpDevice *device)
{
FpDevicePrivate *priv = fp_device_get_instance_private (device);
g_return_if_fail (FP_IS_DEVICE (device));
g_return_if_fail (!priv->is_removed);
priv->is_removed = TRUE;
g_object_notify (G_OBJECT (device), "removed");
/* If there is a pending action, we wait for it to fail, otherwise we
* immediately emit the "removed" signal. */
if (priv->current_task)
{
g_signal_connect_object (priv->current_task,
"notify::completed",
(GCallback) emit_removed_on_task_completed,
device,
G_CONNECT_SWAPPED);
}
else
{
g_signal_emit_by_name (device, "removed");
}
}
/**
* fpi_device_action_error:
* @device: The #FpDevice
@@ -691,6 +738,7 @@ fp_device_task_return_in_idle_cb (gpointer user_data)
FpDeviceTaskReturnData *data = user_data;
FpDevicePrivate *priv = fp_device_get_instance_private (data->device);
g_autofree char *action_str = NULL;
FpiDeviceAction action;
g_autoptr(GTask) task = NULL;
@@ -699,9 +747,24 @@ fp_device_task_return_in_idle_cb (gpointer user_data)
g_debug ("Completing action %s in idle!", action_str);
task = g_steal_pointer (&priv->current_task);
action = priv->current_action;
priv->current_action = FPI_DEVICE_ACTION_NONE;
priv->current_task_idle_return_source = NULL;
/* Return FP_DEVICE_ERROR_REMOVED if the device is removed,
* with the exception of a successful open, which is an odd corner case. */
if (priv->is_removed &&
((action != FPI_DEVICE_ACTION_OPEN) ||
(action == FPI_DEVICE_ACTION_OPEN && data->type == FP_DEVICE_TASK_RETURN_ERROR)))
{
g_task_return_error (task, fpi_device_error_new (FP_DEVICE_ERROR_REMOVED));
/* NOTE: The removed signal will be emitted from the GTask
* notify::completed if that is neccessary. */
return G_SOURCE_REMOVE;
}
switch (data->type)
{
case FP_DEVICE_TASK_RETURN_INT:
@@ -713,16 +776,17 @@ fp_device_task_return_in_idle_cb (gpointer user_data)
break;
case FP_DEVICE_TASK_RETURN_OBJECT:
g_task_return_pointer (task, data->result, g_object_unref);
g_task_return_pointer (task, g_steal_pointer (&data->result),
g_object_unref);
break;
case FP_DEVICE_TASK_RETURN_PTR_ARRAY:
g_task_return_pointer (task, data->result,
g_task_return_pointer (task, g_steal_pointer (&data->result),
(GDestroyNotify) g_ptr_array_unref);
break;
case FP_DEVICE_TASK_RETURN_ERROR:
g_task_return_error (task, data->result);
g_task_return_error (task, g_steal_pointer (&data->result));
break;
default:
@@ -735,6 +799,30 @@ fp_device_task_return_in_idle_cb (gpointer user_data)
static void
fpi_device_task_return_data_free (FpDeviceTaskReturnData *data)
{
if (data->result)
{
switch (data->type)
{
case FP_DEVICE_TASK_RETURN_INT:
case FP_DEVICE_TASK_RETURN_BOOL:
break;
case FP_DEVICE_TASK_RETURN_OBJECT:
g_clear_object ((GObject **) &data->result);
break;
case FP_DEVICE_TASK_RETURN_PTR_ARRAY:
g_clear_pointer ((GPtrArray **) &data->result, g_ptr_array_unref);
break;
case FP_DEVICE_TASK_RETURN_ERROR:
g_clear_error ((GError **) &data->result);
break;
default:
g_assert_not_reached ();
}
}
g_object_unref (data->device);
g_free (data);
}
@@ -787,6 +875,7 @@ fpi_device_probe_complete (FpDevice *device,
g_debug ("Device reported probe completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
{
@@ -829,6 +918,7 @@ fpi_device_open_complete (FpDevice *device, GError *error)
g_debug ("Device reported open completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
{
@@ -862,6 +952,7 @@ fpi_device_close_complete (FpDevice *device, GError *error)
g_debug ("Device reported close completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
switch (priv->type)
{
@@ -885,17 +976,17 @@ fpi_device_close_complete (FpDevice *device, GError *error)
return;
}
/* Always consider the device closed. Drivers should try hard to close the
* device. Generally, e.g. cancellations should be ignored.
*/
priv->is_open = FALSE;
g_object_notify (G_OBJECT (device), "open");
if (!error)
{
priv->is_open = FALSE;
g_object_notify (G_OBJECT (device), "open");
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL,
GUINT_TO_POINTER (TRUE));
}
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL,
GUINT_TO_POINTER (TRUE));
else
{
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_ERROR, error);
}
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_ERROR, error);
}
/**
@@ -918,12 +1009,14 @@ fpi_device_enroll_complete (FpDevice *device, FpPrint *print, GError *error)
g_debug ("Device reported enroll completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
{
if (FP_IS_PRINT (print))
{
FpiPrintType print_type;
g_autofree char *finger_str = NULL;
g_object_get (print, "fpi-type", &print_type, NULL);
if (print_type == FPI_PRINT_UNDEFINED)
@@ -937,6 +1030,9 @@ fpi_device_enroll_complete (FpDevice *device, FpPrint *print, GError *error)
return;
}
finger_str = g_enum_to_string (FP_TYPE_FINGER, fp_print_get_finger (print));
g_debug ("Print for finger %s enrolled", finger_str);
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_OBJECT, print);
}
else
@@ -985,6 +1081,7 @@ fpi_device_verify_complete (FpDevice *device,
data = g_task_get_task_data (priv->current_task);
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
{
@@ -1044,6 +1141,7 @@ fpi_device_identify_complete (FpDevice *device,
data = g_task_get_task_data (priv->current_task);
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
{
@@ -1059,7 +1157,7 @@ fpi_device_identify_complete (FpDevice *device,
}
else
{
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_INT, GINT_TO_POINTER (TRUE));
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL, GUINT_TO_POINTER (TRUE));
}
}
else
@@ -1100,6 +1198,7 @@ fpi_device_capture_complete (FpDevice *device,
g_debug ("Device reported capture completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
{
@@ -1145,6 +1244,7 @@ fpi_device_delete_complete (FpDevice *device,
g_debug ("Device reported deletion completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (!error)
fpi_device_return_task_in_idle (device, FP_DEVICE_TASK_RETURN_BOOL,
@@ -1179,6 +1279,7 @@ fpi_device_list_complete (FpDevice *device,
g_debug ("Device reported listing completion");
clear_device_cancel_action (device);
fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE);
if (prints && error)
{
@@ -1394,3 +1495,59 @@ fpi_device_identify_report (FpDevice *device,
if (call_cb && data->match_cb)
data->match_cb (device, data->match, data->print, data->match_data, data->error);
}
/**
* fpi_device_report_finger_status:
* @device: The #FpDevice
* @finger_status: The current #FpFingerStatusFlags to report
*
* Report the finger status for the @device.
* This can be used by UI to give a feedback
*
* Returns: %TRUE if changed
*/
gboolean
fpi_device_report_finger_status (FpDevice *device,
FpFingerStatusFlags finger_status)
{
FpDevicePrivate *priv = fp_device_get_instance_private (device);
g_autofree char *status_string = NULL;
if (priv->finger_status == finger_status)
return FALSE;
status_string = g_flags_to_string (FP_TYPE_FINGER_STATUS_FLAGS, finger_status);
fp_dbg ("Device reported finger status change: %s", status_string);
priv->finger_status = finger_status;
g_object_notify (G_OBJECT (device), "finger-status");
return TRUE;
}
/**
* fpi_device_report_finger_status_changes:
* @device: The #FpDevice
* @added_status: The #FpFingerStatusFlags to add
* @added_status: The #FpFingerStatusFlags to remove
*
* Report the finger status for the @device adding the @added_status flags
* and removing the @removed_status flags.
*
* This can be used by UI to give a feedback
*
* Returns: %TRUE if changed
*/
gboolean
fpi_device_report_finger_status_changes (FpDevice *device,
FpFingerStatusFlags added_status,
FpFingerStatusFlags removed_status)
{
FpDevicePrivate *priv = fp_device_get_instance_private (device);
FpFingerStatusFlags finger_status = priv->finger_status;
finger_status |= added_status;
finger_status &= ~removed_status;
return fpi_device_report_finger_status (device, finger_status);
}

View File

@@ -202,6 +202,7 @@ void fpi_device_get_delete_data (FpDevice *device,
FpPrint **print);
GCancellable *fpi_device_get_cancellable (FpDevice *device);
void fpi_device_remove (FpDevice *device);
GSource * fpi_device_add_timeout (FpDevice *device,
gint interval,
@@ -255,4 +256,10 @@ void fpi_device_identify_report (FpDevice *device,
FpPrint *print,
GError *error);
gboolean fpi_device_report_finger_status (FpDevice *device,
FpFingerStatusFlags finger_status);
gboolean fpi_device_report_finger_status_changes (FpDevice *device,
FpFingerStatusFlags added_status,
FpFingerStatusFlags removed_status);
G_END_DECLS

View File

@@ -41,6 +41,9 @@ fp_image_device_get_instance_private (FpImageDevice *self)
g_type_class_get_instance_private_offset (img_class));
}
static void fp_image_device_change_state (FpImageDevice *self,
FpiImageDeviceState state);
/* Private shared functions */
void
@@ -51,59 +54,105 @@ fpi_image_device_activate (FpImageDevice *self)
g_assert (!priv->active);
/* We don't have a neutral ACTIVE state, but we always will
* go into WAIT_FINGER_ON afterwards. */
priv->state = FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON;
g_object_notify (G_OBJECT (self), "fpi-image-device-state");
fp_dbg ("Activating image device");
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_ACTIVATING);
cls->activate (self);
}
void
fpi_image_device_deactivate (FpImageDevice *self)
fpi_image_device_deactivate (FpImageDevice *self, gboolean cancelling)
{
FpDevice *device = FP_DEVICE (self);
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpImageDeviceClass *cls = FP_IMAGE_DEVICE_GET_CLASS (device);
if (!priv->active || priv->state == FPI_IMAGE_DEVICE_STATE_INACTIVE)
if (!priv->active || priv->state == FPI_IMAGE_DEVICE_STATE_DEACTIVATING)
{
/* XXX: We currently deactivate both from minutiae scan result
* and finger off report. */
fp_dbg ("Already deactivated, ignoring request.");
return;
}
if (!priv->cancelling && priv->state == FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON)
g_warning ("Deactivating image device while waiting for finger, this should not happen.");
priv->state = FPI_IMAGE_DEVICE_STATE_INACTIVE;
g_object_notify (G_OBJECT (self), "fpi-image-device-state");
if (!cancelling && priv->state != FPI_IMAGE_DEVICE_STATE_IDLE)
g_warning ("Deactivating image device while it is not idle, this should not happen.");
fp_dbg ("Deactivating image device");
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_DEACTIVATING);
cls->deactivate (self);
}
/* Static helper functions */
/* This should not be called directly to activate/deactivate the device! */
static void
fp_image_device_change_state (FpImageDevice *self, FpiImageDeviceState state)
{
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
g_autofree char *prev_state_str = NULL;
g_autofree char *state_str = NULL;
gboolean transition_is_valid = FALSE;
gint i;
/* Cannot change to inactive using this function. */
g_assert (state != FPI_IMAGE_DEVICE_STATE_INACTIVE);
struct
{
FpiImageDeviceState from;
FpiImageDeviceState to;
} valid_transitions[] = {
{ FPI_IMAGE_DEVICE_STATE_INACTIVE, FPI_IMAGE_DEVICE_STATE_ACTIVATING },
{ FPI_IMAGE_DEVICE_STATE_ACTIVATING, FPI_IMAGE_DEVICE_STATE_IDLE },
{ FPI_IMAGE_DEVICE_STATE_ACTIVATING, FPI_IMAGE_DEVICE_STATE_INACTIVE },
{ FPI_IMAGE_DEVICE_STATE_IDLE, FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON },
{ FPI_IMAGE_DEVICE_STATE_IDLE, FPI_IMAGE_DEVICE_STATE_CAPTURE }, /* raw mode -- currently not supported */
{ FPI_IMAGE_DEVICE_STATE_IDLE, FPI_IMAGE_DEVICE_STATE_DEACTIVATING },
{ FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON, FPI_IMAGE_DEVICE_STATE_CAPTURE },
{ FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON, FPI_IMAGE_DEVICE_STATE_DEACTIVATING }, /* cancellation */
{ FPI_IMAGE_DEVICE_STATE_CAPTURE, FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF },
{ FPI_IMAGE_DEVICE_STATE_CAPTURE, FPI_IMAGE_DEVICE_STATE_IDLE }, /* raw mode -- currently not supported */
{ FPI_IMAGE_DEVICE_STATE_CAPTURE, FPI_IMAGE_DEVICE_STATE_DEACTIVATING }, /* cancellation */
{ FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF, FPI_IMAGE_DEVICE_STATE_IDLE },
{ FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF, FPI_IMAGE_DEVICE_STATE_DEACTIVATING }, /* cancellation */
{ FPI_IMAGE_DEVICE_STATE_DEACTIVATING, FPI_IMAGE_DEVICE_STATE_INACTIVE },
};
prev_state_str = g_enum_to_string (FPI_TYPE_IMAGE_DEVICE_STATE, priv->state);
state_str = g_enum_to_string (FPI_TYPE_IMAGE_DEVICE_STATE, state);
fp_dbg ("Image device internal state change from %s to %s",
prev_state_str, state_str);
for (i = 0; i < G_N_ELEMENTS (valid_transitions); i++)
{
if (valid_transitions[i].from == priv->state && valid_transitions[i].to == state)
{
transition_is_valid = TRUE;
break;
}
}
if (!transition_is_valid)
g_warning ("Internal state machine issue: transition from %s to %s should not happen!",
prev_state_str, state_str);
priv->state = state;
g_object_notify (G_OBJECT (self), "fpi-image-device-state");
g_signal_emit_by_name (self, "fpi-image-device-state-changed", priv->state);
if (state == FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON)
{
fpi_device_report_finger_status_changes (FP_DEVICE (self),
FP_FINGER_STATUS_NEEDED,
FP_FINGER_STATUS_NONE);
}
else if (state == FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF)
{
fpi_device_report_finger_status_changes (FP_DEVICE (self),
FP_FINGER_STATUS_NONE,
FP_FINGER_STATUS_NEEDED);
}
}
static void
@@ -132,7 +181,7 @@ fp_image_device_maybe_complete_action (FpImageDevice *self, GError *error)
if (priv->action_error && !(priv->action_error->domain == FP_DEVICE_RETRY))
{
g_warning ("Will complete with first error, new error was: %s", error->message);
g_free (error);
g_clear_error (&error);
}
else
{
@@ -204,7 +253,7 @@ fpi_image_device_minutiae_detected (GObject *source_object, GAsyncResult *res, g
if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
{
fp_image_device_maybe_complete_action (self, g_steal_pointer (&error));
fpi_image_device_deactivate (self);
fpi_image_device_deactivate (self, TRUE);
return;
}
@@ -236,7 +285,7 @@ fpi_image_device_minutiae_detected (GObject *source_object, GAsyncResult *res, g
{
fp_image_device_maybe_complete_action (self, g_steal_pointer (&error));
/* We might not yet be deactivating, if we are enrolling. */
fpi_image_device_deactivate (self);
fpi_image_device_deactivate (self, TRUE);
return;
}
}
@@ -260,7 +309,7 @@ fpi_image_device_minutiae_detected (GObject *source_object, GAsyncResult *res, g
if (priv->enroll_stage == IMG_ENROLL_STAGES)
{
fp_image_device_maybe_complete_action (self, g_steal_pointer (&error));
fpi_image_device_deactivate (self);
fpi_image_device_deactivate (self, FALSE);
}
else
{
@@ -359,6 +408,19 @@ fpi_image_device_report_finger_status (FpImageDevice *self,
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
FpiDeviceAction action;
if (present)
{
fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_PRESENT,
FP_FINGER_STATUS_NONE);
}
else
{
fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_NONE,
FP_FINGER_STATUS_PRESENT);
}
if (priv->state == FPI_IMAGE_DEVICE_STATE_INACTIVE)
{
/* Do we really want to always ignore such reports? We could
@@ -390,8 +452,10 @@ fpi_image_device_report_finger_status (FpImageDevice *self,
* In the enroll case, the decision can only be made after minutiae
* detection has finished.
*/
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_IDLE);
if (action != FPI_DEVICE_ACTION_ENROLL)
fpi_image_device_deactivate (self);
fpi_image_device_deactivate (self, FALSE);
else
fp_image_device_enroll_maybe_await_finger_on (self);
}
@@ -437,6 +501,7 @@ fpi_image_device_image_captured (FpImageDevice *self, FpImage *image)
fpi_image_device_minutiae_detected,
self);
/* XXX: This is wrong if we add support for raw capture mode. */
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF);
}
@@ -479,27 +544,21 @@ fpi_image_device_retry_scan (FpImageDevice *self, FpDeviceRetry retry)
{
fpi_device_verify_report (FP_DEVICE (self), FPI_MATCH_ERROR, NULL, error);
fp_image_device_maybe_complete_action (self, NULL);
priv->cancelling = TRUE;
fpi_image_device_deactivate (self);
priv->cancelling = FALSE;
fpi_image_device_deactivate (self, TRUE);
}
else if (action == FPI_DEVICE_ACTION_IDENTIFY)
{
fpi_device_identify_report (FP_DEVICE (self), NULL, NULL, error);
fp_image_device_maybe_complete_action (self, NULL);
priv->cancelling = TRUE;
fpi_image_device_deactivate (self);
priv->cancelling = FALSE;
fpi_image_device_deactivate (self, TRUE);
}
else
{
/* The capture case where there is no early reporting. */
g_debug ("Abort current operation due to retry (no early-reporting)");
fp_image_device_maybe_complete_action (self, error);
priv->cancelling = TRUE;
fpi_image_device_deactivate (self);
priv->cancelling = FALSE;
fpi_image_device_deactivate (self, TRUE);
}
}
@@ -558,10 +617,8 @@ fpi_image_device_session_error (FpImageDevice *self, GError *error)
if (error->domain == FP_DEVICE_RETRY)
g_warning ("Driver should report retries using fpi_image_device_retry_scan!");
priv->cancelling = TRUE;
fp_image_device_maybe_complete_action (self, error);
fpi_image_device_deactivate (self);
priv->cancelling = FALSE;
fpi_image_device_deactivate (self, TRUE);
}
/**
@@ -580,6 +637,7 @@ fpi_image_device_activate_complete (FpImageDevice *self, GError *error)
action = fpi_device_get_current_action (FP_DEVICE (self));
g_return_if_fail (priv->active == FALSE);
g_return_if_fail (priv->state == FPI_IMAGE_DEVICE_STATE_ACTIVATING);
g_return_if_fail (action == FPI_DEVICE_ACTION_ENROLL ||
action == FPI_DEVICE_ACTION_VERIFY ||
action == FPI_DEVICE_ACTION_IDENTIFY ||
@@ -598,6 +656,7 @@ fpi_image_device_activate_complete (FpImageDevice *self, GError *error)
/* We always want to capture at this point, move to AWAIT_FINGER
* state. */
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_IDLE);
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON);
}
@@ -614,7 +673,7 @@ fpi_image_device_deactivate_complete (FpImageDevice *self, GError *error)
FpImageDevicePrivate *priv = fp_image_device_get_instance_private (self);
g_return_if_fail (priv->active == TRUE);
g_return_if_fail (priv->state == FPI_IMAGE_DEVICE_STATE_INACTIVE);
g_return_if_fail (priv->state == FPI_IMAGE_DEVICE_STATE_DEACTIVATING);
g_debug ("Image device deactivation completed");
@@ -623,6 +682,8 @@ fpi_image_device_deactivate_complete (FpImageDevice *self, GError *error)
/* Assume finger was removed. */
priv->finger_present = FALSE;
fp_image_device_change_state (self, FPI_IMAGE_DEVICE_STATE_INACTIVE);
fp_image_device_maybe_complete_action (self, error);
}
@@ -649,6 +710,8 @@ fpi_image_device_open_complete (FpImageDevice *self, GError *error)
priv->state = FPI_IMAGE_DEVICE_STATE_INACTIVE;
g_object_notify (G_OBJECT (self), "fpi-image-device-state");
fpi_device_report_finger_status (FP_DEVICE (self), FP_FINGER_STATUS_NONE);
fpi_device_open_complete (FP_DEVICE (self), error);
}

View File

@@ -25,6 +25,9 @@
/**
* FpiImageDeviceState:
* @FPI_IMAGE_DEVICE_STATE_INACTIVE: inactive
* @FPI_IMAGE_DEVICE_STATE_ACTIVATING: State during activate callback
* @FPI_IMAGE_DEVICE_STATE_IDLE: Activated but idle
* @FPI_IMAGE_DEVICE_STATE_DEACTIVATING: State during deactivate callback
* @FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON: waiting for the finger to be pressed or swiped
* @FPI_IMAGE_DEVICE_STATE_CAPTURE: capturing an image
* @FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF: waiting for the finger to be removed
@@ -35,9 +38,33 @@
* The driver needs to call fpi_image_device_report_finger_status() to move
* between the different states. Note that the capture state might be entered
* unconditionally if the device supports raw capturing.
*
* A usual run would look like:
* - inactive -> activating: activate vfunc is called
* - activating -> idle: fpi_image_device_activate_complete()
* - idle -> await-finger-on
* - await-finger-on -> capture: fpi_image_device_report_finger_status()
* - capture -> await-finger-off: fpi_image_device_image_captured()
* - await-finger-off -> idle: fpi_image_device_report_finger_status()
* - idle -> deactivating: deactivate vfunc is called
* - deactivating -> inactive: fpi_image_device_deactivate_complete()
*
* Raw mode is currently not supported (not waiting for finger), but in that
* case the following transitions are valid:
* - idle -> capture
* - capture -> idle
*
* Also valid are these transitions in case of errors or cancellations:
* - activating -> inactive: fpi_image_device_activate_complete()
* - await-finger-on -> deactivating: deactivate vfunc is called
* - capture -> deactivating: deactivate vfunc is called
* - await-finger-off -> deactivating: deactivate vfunc is called
*/
typedef enum {
FPI_IMAGE_DEVICE_STATE_INACTIVE,
FPI_IMAGE_DEVICE_STATE_ACTIVATING,
FPI_IMAGE_DEVICE_STATE_DEACTIVATING,
FPI_IMAGE_DEVICE_STATE_IDLE,
FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_ON,
FPI_IMAGE_DEVICE_STATE_CAPTURE,
FPI_IMAGE_DEVICE_STATE_AWAIT_FINGER_OFF,
@@ -58,11 +85,6 @@ typedef enum {
* finger or image capture). Implementing this is optional, it can e.g. be
* used to flash an LED when waiting for a finger.
*
* These are the main entry points for image based drivers. For all but the
* change_state vfunc, implementations *must* eventually call the corresponding
* function to finish the operation. It is also acceptable to call the generic
*
*
* These are the main entry points for drivers to implement. Drivers may not
* implement all of these entry points if they do not support the operation
* (or a default implementation is sufficient).

View File

@@ -25,11 +25,78 @@
#include "fpi-device.h"
static const FpIdEntry whitelist_id_table[] = {
/* Unsupported (for now) Validity Sensors finger print readers */
{ .vid = 0x138a, .pid = 0x0090 }, /* Found on e.g. Lenovo T460s */
/* Currently known and unsupported devices.
* You can generate this list from the wiki page using e.g.:
* gio cat https://gitlab.freedesktop.org/libfprint/wiki/-/wikis/Unsupported-Devices.md | sed -n 's!|.*\([0-9a-fA-F]\{4\}\):\([0-9a-fA-F]\{4\}\).*|.*! { .vid = 0x\1, .pid = 0x\2 },!p'
*/
{ .vid = 0x04f3, .pid = 0x036b },
{ .vid = 0x04f3, .pid = 0x0c00 },
{ .vid = 0x04f3, .pid = 0x0c4b },
{ .vid = 0x04f3, .pid = 0x0c4c },
{ .vid = 0x04f3, .pid = 0x0c4f },
{ .vid = 0x04f3, .pid = 0x0c57 },
{ .vid = 0x04f3, .pid = 0x2706 },
{ .vid = 0x06cb, .pid = 0x0081 },
{ .vid = 0x06cb, .pid = 0x0088 },
{ .vid = 0x06cb, .pid = 0x008a },
{ .vid = 0x06cb, .pid = 0x009a },
{ .vid = 0x06cb, .pid = 0x009b },
{ .vid = 0x06cb, .pid = 0x00a2 },
{ .vid = 0x06cb, .pid = 0x00b7 },
{ .vid = 0x06cb, .pid = 0x00bb },
{ .vid = 0x06cb, .pid = 0x00be },
{ .vid = 0x06cb, .pid = 0x00c2 },
{ .vid = 0x06cb, .pid = 0x00c9 },
{ .vid = 0x06cb, .pid = 0x00cb },
{ .vid = 0x06cb, .pid = 0x00d8 },
{ .vid = 0x06cb, .pid = 0x00da },
{ .vid = 0x06cb, .pid = 0x00e7 },
{ .vid = 0x0a5c, .pid = 0x5801 },
{ .vid = 0x0a5c, .pid = 0x5805 },
{ .vid = 0x0a5c, .pid = 0x5834 },
{ .vid = 0x0a5c, .pid = 0x5843 },
{ .vid = 0x10a5, .pid = 0x0007 },
{ .vid = 0x1188, .pid = 0x9545 },
{ .vid = 0x138a, .pid = 0x0007 },
{ .vid = 0x138a, .pid = 0x003a },
{ .vid = 0x138a, .pid = 0x003c },
{ .vid = 0x138a, .pid = 0x003d },
{ .vid = 0x138a, .pid = 0x003f },
{ .vid = 0x138a, .pid = 0x0090 },
{ .vid = 0x138a, .pid = 0x0091 },
{ .vid = 0x138a, .pid = 0x0092 },
{ .vid = 0x138a, .pid = 0x0094 },
{ .vid = 0x138a, .pid = 0x0097 }, /* Found on e.g. Lenovo T470s */
{ .vid = 0x138a, .pid = 0x0097 },
{ .vid = 0x138a, .pid = 0x009d },
{ .vid = 0x138a, .pid = 0x00ab },
{ .vid = 0x147e, .pid = 0x1002 },
{ .vid = 0x1491, .pid = 0x0088 },
{ .vid = 0x16d1, .pid = 0x1027 },
{ .vid = 0x1c7a, .pid = 0x0300 },
{ .vid = 0x1c7a, .pid = 0x0570 },
{ .vid = 0x1c7a, .pid = 0x0575 },
{ .vid = 0x27c6, .pid = 0x5042 },
{ .vid = 0x27c6, .pid = 0x5110 },
{ .vid = 0x27c6, .pid = 0x5117 },
{ .vid = 0x27c6, .pid = 0x5201 },
{ .vid = 0x27c6, .pid = 0x521d },
{ .vid = 0x27c6, .pid = 0x5301 },
{ .vid = 0x27c6, .pid = 0x530c },
{ .vid = 0x27c6, .pid = 0x532d },
{ .vid = 0x27c6, .pid = 0x533c },
{ .vid = 0x27c6, .pid = 0x5381 },
{ .vid = 0x27c6, .pid = 0x5385 },
{ .vid = 0x27c6, .pid = 0x538c },
{ .vid = 0x27c6, .pid = 0x538d },
{ .vid = 0x27c6, .pid = 0x5395 },
{ .vid = 0x27c6, .pid = 0x5584 },
{ .vid = 0x27c6, .pid = 0x55a2 },
{ .vid = 0x27c6, .pid = 0x55a4 },
{ .vid = 0x27c6, .pid = 0x55b4 },
{ .vid = 0x27c6, .pid = 0x5740 },
{ .vid = 0x2808, .pid = 0x9338 },
{ .vid = 0x298d, .pid = 0x2033 },
{ .vid = 0x3538, .pid = 0x0930 },
{ .vid = 0 },
};

View File

@@ -1,5 +1,5 @@
project('libfprint', [ 'c', 'cpp' ],
version: '1.90.3',
version: '1.90.6',
license: 'LGPLv2.1+',
default_options: [
'buildtype=debugoptimized',

View File

@@ -22,6 +22,13 @@ template = FPrint.Print.new(d)
def enroll_progress(*args):
print('enroll progress: ' + str(args))
def identify_done(dev, res):
global identified
identified = True
identify_match, identify_print = dev.identify_finish(res)
print('indentification_done: ', identify_match, identify_print)
assert identify_match.equal(identify_print)
# List, enroll, list, verify, identify, delete
print("enrolling")
p = d.enroll_sync(template, None, enroll_progress, None)
@@ -35,15 +42,27 @@ assert stored[0].equal(p)
print("verifying")
verify_res, verify_print = d.verify_sync(p)
print("verify done")
del p
assert verify_res == True
print("identifying")
identify_match, identify_print = d.identify_sync(stored)
print("identify done")
assert identify_match.equal(identify_print)
identified = False
deserialized_prints = []
for p in stored:
deserialized_prints.append(FPrint.Print.deserialize(p.serialize()))
assert deserialized_prints[-1].equal(p)
del stored
print('async identifying')
d.identify(deserialized_prints, callback=identify_done)
del deserialized_prints
while not identified:
ctx.iteration(True)
print("deleting")
d.delete_print_sync(p)
print("delete done")
d.close_sync()
del d

View File

@@ -21,6 +21,7 @@ drivers_tests = [
'elan',
'synaptics',
'vfs0050',
'vfs301',
'vfs5011',
'goodixmoc',
]

View File

@@ -20,11 +20,14 @@ d.open_sync()
template = FPrint.Print.new(d)
def enroll_progress(*args):
assert d.get_finger_status() == FPrint.FingerStatusFlags.NEEDED
print('enroll progress: ' + str(args))
# List, enroll, list, verify, delete, list
print("enrolling")
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
p = d.enroll_sync(template, None, enroll_progress, None)
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
print("enroll done")
print("listing")
@@ -33,7 +36,9 @@ print("listing done")
assert len(stored) == 1
assert stored[0].equal(p)
print("verifying")
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
verify_res, verify_print = d.verify_sync(p)
assert d.get_finger_status() == FPrint.FingerStatusFlags.NONE
print("verify done")
assert verify_res == True

View File

@@ -20,6 +20,7 @@
#include <libfprint/fprint.h>
#include "test-utils.h"
#include "fpi-device.h"
static void
test_context_new (void)
@@ -92,6 +93,296 @@ test_context_enumerates_new_devices (void)
fpt_teardown_virtual_device_environment ();
}
#define DEV_REMOVED_CB 1
#define CTX_DEVICE_REMOVED_CB 2
static void
device_removed_cb (FpDevice *device, FptContext *tctx)
{
g_assert_nonnull (device);
g_assert_true (device == tctx->device);
g_assert_null (tctx->user_data);
tctx->user_data = GINT_TO_POINTER (DEV_REMOVED_CB);
}
static void
context_device_removed_cb (FpContext *ctx, FpDevice *device, FptContext *tctx)
{
g_assert_nonnull (device);
g_assert_true (device == tctx->device);
/* "device-removed" on context is always after "removed" on device */
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
tctx->user_data = GINT_TO_POINTER (CTX_DEVICE_REMOVED_CB);
}
static void
test_context_remove_device_closed (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_imgdev ();
gboolean removed;
tctx->user_data = NULL;
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx);
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
/* Triggering remove on closed device. */
fpi_device_remove (tctx->device);
g_assert_nonnull (tctx->device);
g_object_get (tctx->device, "removed", &removed, NULL);
g_assert_true (removed);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* device-removed is dispatched from idle. */
while (g_main_context_iteration (NULL, FALSE))
{
}
/* The device is now destroyed and device-removed was called. */
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
fpt_teardown_virtual_device_environment ();
}
static void
close_done_cb (GObject *device, GAsyncResult *res, gpointer user_data)
{
g_autoptr(FpPrint) print = NULL;
GError **error = user_data;
g_assert_nonnull (error);
g_assert_false (fp_device_close_finish (FP_DEVICE (device), res, error));
g_assert_null (print);
g_assert_nonnull (*error);
}
static void
test_context_remove_device_closing (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_imgdev ();
g_autoptr(GError) close_error = NULL;
g_autoptr(GError) error = NULL;
gboolean removed;
tctx->user_data = NULL;
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx);
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
fp_device_open_sync (tctx->device, NULL, &error);
g_assert_no_error (error);
/* Triggering remove on device that is being closed. */
fp_device_close (tctx->device, NULL, close_done_cb, &close_error);
fpi_device_remove (tctx->device);
/* Removed but not yet notified*/
g_assert_nonnull (tctx->device);
g_object_get (tctx->device, "removed", &removed, NULL);
g_assert_true (removed);
g_assert_null (tctx->user_data);
/* Running the mainloop now will cause the close to fail eventually. */
while (!close_error)
g_main_context_iteration (NULL, TRUE);
g_assert_error (close_error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
/* Now the removed callback has been called already. */
g_assert_nonnull (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* While device-removed needs another idle iteration. */
while (g_main_context_iteration (NULL, FALSE))
{
}
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
fpt_teardown_virtual_device_environment ();
}
static void
test_context_remove_device_open (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_imgdev ();
g_autoptr(GError) error = NULL;
gboolean removed = FALSE;
tctx->user_data = NULL;
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx);
fp_device_open_sync (tctx->device, NULL, &error);
g_assert_no_error (error);
/* Triggering remove on open device. */
fpi_device_remove (tctx->device);
g_assert_nonnull (tctx->device);
g_object_get (tctx->device, "removed", &removed, NULL);
g_assert_true (removed);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* At this point, the "removed" cb on the device should have been called!
* Iterating the mainloop will not change anything.
*/
while (g_main_context_iteration (NULL, FALSE))
{
}
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* On close, the device will be removed from the context,
* but only a main loop iteration later. */
fp_device_close_sync (tctx->device, NULL, &error);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
g_assert_nonnull (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
while (g_main_context_iteration (NULL, FALSE))
{
}
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
fpt_teardown_virtual_device_environment ();
}
static void
open_done_cb (GObject *device, GAsyncResult *res, gpointer user_data)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpPrint) print = NULL;
gboolean *data = user_data;
g_assert_true (fp_device_open_finish (FP_DEVICE (device), res, &error));
g_assert_null (print);
g_assert_null (error);
*data = TRUE;
}
static void
test_context_remove_device_opening (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_imgdev ();
g_autoptr(GError) close_error = NULL;
gboolean open_done = FALSE;
gboolean removed;
tctx->user_data = NULL;
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx);
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
fp_device_open (tctx->device, NULL, open_done_cb, &open_done);
g_assert_false (open_done);
fpi_device_remove (tctx->device);
/* Removed but not yet notified*/
g_assert_nonnull (tctx->device);
g_object_get (tctx->device, "removed", &removed, NULL);
g_assert_true (removed);
g_assert_null (tctx->user_data);
/* Running the mainloop now will cause the open to *succeed* dispite removal! */
while (!open_done)
g_main_context_iteration (NULL, TRUE);
/* Now the removed callback has been called already. */
g_assert_nonnull (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
fp_device_close_sync (tctx->device, NULL, &close_error);
g_assert_error (close_error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
g_assert_nonnull (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* The device-removed signal needs an idle iteration. */
while (g_main_context_iteration (NULL, FALSE))
{
}
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
fpt_teardown_virtual_device_environment ();
}
static void
enroll_done_cb (GObject *device, GAsyncResult *res, gpointer user_data)
{
g_autoptr(FpPrint) print = NULL;
GError **error = user_data;
g_assert_nonnull (error);
print = fp_device_enroll_finish (FP_DEVICE (device), res, error);
g_assert_null (print);
g_assert_nonnull (*error);
}
static void
test_context_remove_device_active (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_imgdev ();
g_autoptr(GError) error = NULL;
g_autoptr(GCancellable) cancellable = NULL;
g_autoptr(GError) enroll_error = NULL;
FpPrint *template;
gboolean removed = FALSE;
tctx->user_data = NULL;
g_signal_connect (tctx->fp_context, "device-removed", (GCallback) context_device_removed_cb, tctx);
g_signal_connect (tctx->device, "removed", (GCallback) device_removed_cb, tctx);
fp_device_open_sync (tctx->device, NULL, &error);
g_assert_no_error (error);
/* Start an enroll that we can cancel/fail later.
* NOTE: We need to cancel explicitly as remove() does not trigger a failure!
*/
template = fp_print_new (tctx->device);
cancellable = g_cancellable_new ();
fp_device_enroll (tctx->device, template, cancellable, NULL, NULL, NULL, enroll_done_cb, &enroll_error);
/* Triggering remove on active device. */
fpi_device_remove (tctx->device);
/* The removed property has changed, but the cb has *not* been called yet. */
g_assert_nonnull (tctx->device);
g_object_get (tctx->device, "removed", &removed, NULL);
g_assert_true (removed);
g_assert_null (tctx->user_data);
/* Running the mainloop now will cause the operation to fail eventually. */
while (!enroll_error)
g_main_context_iteration (NULL, TRUE);
/* The virtual image device throws an PROTO error internally,
* but we should still receive a REMOVED error here. */
g_assert_error (enroll_error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* Now we close the device, state remains unchanged mostly. */
fp_device_close_sync (tctx->device, NULL, &error);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_REMOVED);
g_assert_nonnull (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, DEV_REMOVED_CB);
/* And "device-removed" is called */
while (g_main_context_iteration (NULL, FALSE))
{
}
g_assert_null (tctx->device);
g_assert_cmpint (GPOINTER_TO_INT (tctx->user_data), ==, CTX_DEVICE_REMOVED_CB);
fpt_teardown_virtual_device_environment ();
}
int
main (int argc, char *argv[])
{
@@ -101,6 +392,11 @@ main (int argc, char *argv[])
g_test_add_func ("/context/no-devices", test_context_has_no_devices);
g_test_add_func ("/context/has-virtual-device", test_context_has_virtual_device);
g_test_add_func ("/context/enumerates-new-devices", test_context_enumerates_new_devices);
g_test_add_func ("/context/remove-device-closed", test_context_remove_device_closed);
g_test_add_func ("/context/remove-device-closing", test_context_remove_device_closing);
g_test_add_func ("/context/remove-device-open", test_context_remove_device_open);
g_test_add_func ("/context/remove-device-opening", test_context_remove_device_opening);
g_test_add_func ("/context/remove-device-active", test_context_remove_device_active);
return g_test_run ();
}

View File

@@ -178,6 +178,15 @@ test_device_get_scan_type (void)
g_assert_cmpint (fp_device_get_scan_type (tctx->device), ==, FP_SCAN_TYPE_SWIPE);
}
static void
test_device_get_finger_status (void)
{
g_autoptr(FptContext) tctx = fpt_context_new_with_virtual_imgdev ();
fp_device_open_sync (tctx->device, NULL, NULL);
g_assert_cmpint (fp_device_get_finger_status (tctx->device), ==, FP_FINGER_STATUS_NONE);
}
static void
test_device_get_nr_enroll_stages (void)
{
@@ -229,6 +238,7 @@ main (int argc, char *argv[])
g_test_add_func ("/device/sync/get_device_id", test_device_get_device_id);
g_test_add_func ("/device/sync/get_name", test_device_get_name);
g_test_add_func ("/device/sync/get_scan_type", test_device_get_scan_type);
g_test_add_func ("/device/sync/get_finger_status", test_device_get_finger_status);
g_test_add_func ("/device/sync/get_nr_enroll_stages", test_device_get_nr_enroll_stages);
g_test_add_func ("/device/sync/supports_identify", test_device_supports_identify);
g_test_add_func ("/device/sync/supports_capture", test_device_supports_capture);

View File

@@ -89,6 +89,29 @@ auto_reset_device_class_cleanup (FpAutoResetClass *dev_class)
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC (FpAutoResetClass, auto_reset_device_class_cleanup)
static void
assert_equal_galleries (GPtrArray *g1,
GPtrArray *g2)
{
unsigned i;
g_assert ((g1 && g2) || (!g1 || !g1));
if (g1 == g2)
return;
g_assert_cmpuint (g1->len, ==, g2->len);
for (i = 0; i < g1->len; i++)
{
FpPrint *print = g_ptr_array_index (g1, i);
g_assert_true (g_ptr_array_find_with_equal_func (g2, print, (GEqualFunc)
fp_print_equal, NULL));
}
}
static void
on_device_notify (FpDevice *device, GParamSpec *spec, gpointer user_data)
{
@@ -98,6 +121,43 @@ on_device_notify (FpDevice *device, GParamSpec *spec, gpointer user_data)
fake_dev->user_data = g_param_spec_ref (spec);
}
static FpPrint *
make_fake_print (FpDevice *device,
GVariant *print_data)
{
FpPrint *enrolled_print = fp_print_new (device);
fpi_print_set_type (enrolled_print, FPI_PRINT_RAW);
if (!print_data)
print_data = g_variant_new_string ("Test print private data");
g_object_set (G_OBJECT (enrolled_print), "fpi-data", print_data, NULL);
return enrolled_print;
}
static FpPrint *
make_fake_print_reffed (FpDevice *device,
GVariant *print_data)
{
return g_object_ref_sink (make_fake_print (device, print_data));
}
static GPtrArray *
make_fake_prints_gallery (FpDevice *device,
size_t size)
{
GPtrArray *array;
size_t i;
array = g_ptr_array_new_full (size, g_object_unref);
for (i = 0; i < size; i++)
g_ptr_array_add (array, make_fake_print_reffed (device, g_variant_new_uint64 (i)));
return array;
}
/* Tests */
static void
@@ -200,6 +260,160 @@ test_driver_set_scan_type_swipe (void)
g_assert_cmpstr (pspec->name, ==, "scan-type");
}
static void
test_driver_finger_status_inactive (void)
{
g_autoptr(FpDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
FpFingerStatusFlags finger_status;
g_signal_connect (device, "notify::finger-status", G_CALLBACK (on_device_notify), NULL);
g_assert_false (fpi_device_report_finger_status (device, FP_FINGER_STATUS_NONE));
g_assert_cmpuint (fp_device_get_finger_status (device), ==, FP_FINGER_STATUS_NONE);
g_object_get (fake_dev, "finger-status", &finger_status, NULL);
g_assert_cmpuint (finger_status, ==, FP_FINGER_STATUS_NONE);
g_assert (fake_dev->last_called_function != on_device_notify);
g_assert_null (g_steal_pointer (&fake_dev->user_data));
}
static void
test_driver_finger_status_needed (void)
{
g_autoptr(FpDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_autoptr(GParamSpec) pspec = NULL;
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
FpFingerStatusFlags finger_status;
g_signal_connect (device, "notify::finger-status", G_CALLBACK (on_device_notify), NULL);
g_assert_true (fpi_device_report_finger_status (device, FP_FINGER_STATUS_NEEDED));
g_assert_cmpuint (fp_device_get_finger_status (device), ==, FP_FINGER_STATUS_NEEDED);
g_object_get (fake_dev, "finger-status", &finger_status, NULL);
g_assert_cmpuint (finger_status, ==, FP_FINGER_STATUS_NEEDED);
g_assert (fake_dev->last_called_function == on_device_notify);
pspec = g_steal_pointer (&fake_dev->user_data);
g_assert_cmpstr (pspec->name, ==, "finger-status");
fake_dev->last_called_function = NULL;
g_assert_false (fpi_device_report_finger_status (device, FP_FINGER_STATUS_NEEDED));
g_assert_null (fake_dev->last_called_function);
g_assert_null (g_steal_pointer (&fake_dev->user_data));
}
static void
test_driver_finger_status_present (void)
{
g_autoptr(FpDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_autoptr(GParamSpec) pspec = NULL;
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
FpFingerStatusFlags finger_status;
g_signal_connect (device, "notify::finger-status", G_CALLBACK (on_device_notify), NULL);
g_assert_true (fpi_device_report_finger_status (device, FP_FINGER_STATUS_PRESENT));
g_assert_cmpuint (fp_device_get_finger_status (device), ==, FP_FINGER_STATUS_PRESENT);
g_object_get (fake_dev, "finger-status", &finger_status, NULL);
g_assert_cmpuint (finger_status, ==, FP_FINGER_STATUS_PRESENT);
g_assert (fake_dev->last_called_function == on_device_notify);
pspec = g_steal_pointer (&fake_dev->user_data);
g_assert_cmpstr (pspec->name, ==, "finger-status");
fake_dev->last_called_function = NULL;
g_assert_false (fpi_device_report_finger_status (device, FP_FINGER_STATUS_PRESENT));
g_assert_null (fake_dev->last_called_function);
g_assert_null (g_steal_pointer (&fake_dev->user_data));
}
static void
driver_finger_status_changes_check (FpDevice *device, gboolean add)
{
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
g_autoptr(GFlagsClass) status_class = g_type_class_ref (FP_TYPE_FINGER_STATUS_FLAGS);
guint expected_status;
guint initial_value;
guint i;
gulong signal_id;
if (add)
initial_value = FP_FINGER_STATUS_NONE;
else
initial_value = status_class->mask;
g_assert_cmpuint (fp_device_get_finger_status (device), ==, initial_value);
signal_id = g_signal_connect (device, "notify::finger-status",
G_CALLBACK (on_device_notify), NULL);
for (i = 0, expected_status = initial_value; i < status_class->n_values; ++i)
{
g_autoptr(GParamSpec) pspec = NULL;
FpFingerStatusFlags finger_status = status_class->values[i].value;
FpFingerStatusFlags added_status = add ? finger_status : FP_FINGER_STATUS_NONE;
FpFingerStatusFlags removed_status = add ? FP_FINGER_STATUS_NONE : finger_status;
gboolean ret;
fake_dev->last_called_function = NULL;
ret = fpi_device_report_finger_status_changes (device,
added_status,
removed_status);
if (finger_status != FP_FINGER_STATUS_NONE)
g_assert_true (ret);
else
g_assert_false (ret);
expected_status |= added_status;
expected_status &= ~removed_status;
g_assert_cmpuint (fp_device_get_finger_status (device), ==, expected_status);
if (finger_status != FP_FINGER_STATUS_NONE)
{
g_assert (fake_dev->last_called_function == on_device_notify);
pspec = g_steal_pointer (&fake_dev->user_data);
g_assert_cmpstr (pspec->name, ==, "finger-status");
}
fake_dev->last_called_function = NULL;
g_assert_false (fpi_device_report_finger_status_changes (device,
added_status,
removed_status));
g_assert_null (fake_dev->last_called_function);
g_assert_null (g_steal_pointer (&fake_dev->user_data));
}
if (add)
g_assert_cmpuint (fp_device_get_finger_status (device), ==, status_class->mask);
else
g_assert_cmpuint (fp_device_get_finger_status (device), ==, FP_FINGER_STATUS_NONE);
fake_dev->last_called_function = NULL;
g_assert_false (fpi_device_report_finger_status_changes (device,
FP_FINGER_STATUS_NONE,
FP_FINGER_STATUS_NONE));
g_assert_null (fake_dev->last_called_function);
g_assert_null (g_steal_pointer (&fake_dev->user_data));
g_signal_handler_disconnect (device, signal_id);
}
static void
test_driver_finger_status_changes (void)
{
g_autoptr(FpDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
driver_finger_status_changes_check (device, TRUE);
driver_finger_status_changes_check (device, FALSE);
}
static void
test_driver_get_nr_enroll_stages (void)
{
@@ -393,12 +607,12 @@ test_driver_open (void)
g_assert (fake_dev->last_called_function != dev_class->probe);
fp_device_open_sync (device, NULL, &error);
g_assert_true (fp_device_open_sync (device, NULL, &error));
g_assert (fake_dev->last_called_function == dev_class->open);
g_assert_no_error (error);
g_assert_true (fp_device_is_open (device));
fp_device_close_sync (FP_DEVICE (device), NULL, &error);
g_assert_true (fp_device_close_sync (FP_DEVICE (device), NULL, &error));
g_assert_no_error (error);
}
@@ -411,7 +625,7 @@ test_driver_open_error (void)
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
fp_device_open_sync (device, NULL, &error);
g_assert_false (fp_device_open_sync (device, NULL, &error));
g_assert (fake_dev->last_called_function == dev_class->open);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
g_assert_false (fp_device_is_open (device));
@@ -426,7 +640,7 @@ test_driver_close (void)
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
fp_device_close_sync (device, NULL, &error);
g_assert_true (fp_device_close_sync (device, NULL, &error));
g_assert (fake_dev->last_called_function == dev_class->close);
g_assert_no_error (error);
@@ -442,12 +656,12 @@ test_driver_close_error (void)
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
fp_device_close_sync (device, NULL, &error);
g_assert_false (fp_device_close_sync (device, NULL, &error));
g_assert (fake_dev->last_called_function == dev_class->close);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
g_assert (error == g_steal_pointer (&fake_dev->ret_error));
g_assert_true (fp_device_is_open (device));
g_assert_false (fp_device_is_open (device));
}
static void
@@ -529,7 +743,7 @@ test_driver_enroll_error_no_print (void)
"*Driver passed an error but also provided a print, returning error*");
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
fake_dev->ret_print = fp_print_new (device);
fake_dev->ret_print = make_fake_print_reffed (device, NULL);
g_object_add_weak_pointer (G_OBJECT (fake_dev->ret_print),
(gpointer) (&fake_dev->ret_print));
out_print =
@@ -620,7 +834,8 @@ test_driver_enroll_progress_vfunc (FpDevice *device)
expected_data->completed_stages =
g_random_int_range (fp_device_get_nr_enroll_stages (device), G_MAXINT32);
expected_data->print = fp_print_new (device);
expected_data->print = make_fake_print_reffed (device,
g_variant_new_int32 (expected_data->completed_stages));
expected_data->error = NULL;
error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
@@ -678,10 +893,11 @@ test_driver_enroll_progress (void)
typedef struct
{
gboolean called;
FpPrint *match;
FpPrint *print;
GError *error;
gboolean called;
FpPrint *match;
FpPrint *print;
GPtrArray *gallery;
GError *error;
} MatchCbData;
static void
@@ -724,6 +940,14 @@ test_driver_match_cb (FpDevice *device,
if (match)
g_assert_no_error (error);
/* Compar gallery if this is an identify operation */
if (data->gallery)
{
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
g_assert_false (fake_dev->action_data == data->gallery);
assert_equal_galleries (fake_dev->action_data, data->gallery);
}
}
static void
@@ -731,7 +955,7 @@ test_driver_verify (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
g_autoptr(FpPrint) out_print = NULL;
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
@@ -739,9 +963,9 @@ test_driver_verify (void)
gboolean match;
fake_dev->ret_result = FPI_MATCH_SUCCESS;
fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error);
g_assert_true (fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error));
g_assert (fake_dev->last_called_function == dev_class->verify);
g_assert (fake_dev->action_data == enrolled_print);
@@ -761,17 +985,18 @@ test_driver_verify_fail (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
g_autoptr(FpPrint) enrolled_print = NULL;
g_autoptr(FpPrint) out_print = NULL;
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
gboolean match;
enrolled_print = make_fake_print_reffed (device, g_variant_new_uint64 (3));
fake_dev->ret_result = FPI_MATCH_FAIL;
fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error);
g_assert_true (fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error));
g_assert (fake_dev->last_called_function == dev_class->verify);
g_assert_no_error (error);
@@ -790,7 +1015,7 @@ test_driver_verify_retry (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
g_autoptr(FpPrint) out_print = NULL;
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
@@ -799,9 +1024,9 @@ test_driver_verify_retry (void)
fake_dev->ret_result = FPI_MATCH_ERROR;
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL);
fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error));
g_assert_true (match_data->called);
g_assert_null (match_data->match);
@@ -818,7 +1043,7 @@ test_driver_verify_error (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
g_autoptr(FpPrint) out_print = NULL;
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
@@ -827,9 +1052,9 @@ test_driver_verify_error (void)
fake_dev->ret_result = FPI_MATCH_ERROR;
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &out_print, &error));
g_assert_false (match_data->called);
g_assert_null (match_data->match);
@@ -857,16 +1082,16 @@ test_driver_verify_not_reported (void)
dev_class->verify = fake_device_verify_immediate_complete;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
enrolled_print = g_object_ref_sink (fp_print_new (device));
enrolled_print = make_fake_print_reffed (device, NULL);
g_assert_true (fp_device_open_sync (device, NULL, NULL));
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*reported successful verify complete*not report*result*");
fp_device_verify_sync (device, enrolled_print, NULL,
NULL, NULL,
NULL, NULL, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL,
NULL, NULL,
NULL, NULL, &error));
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
@@ -900,7 +1125,7 @@ test_driver_verify_report_no_callback (void)
dev_class->verify = fake_device_verify_complete_error;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
fake_dev = FPI_DEVICE_FAKE (device);
enrolled_print = g_object_ref_sink (fp_print_new (device));
enrolled_print = make_fake_print_reffed (device, NULL);
g_assert_true (fp_device_open_sync (device, NULL, NULL));
@@ -909,9 +1134,9 @@ test_driver_verify_report_no_callback (void)
fake_dev->ret_result = FPI_MATCH_ERROR;
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED);
fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL,
test_driver_match_cb, match_data,
&match, &print, &error));
g_test_assert_expected_messages ();
@@ -940,7 +1165,7 @@ test_driver_verify_complete_retry (void)
dev_class->verify = fake_device_verify_complete_error;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
fake_dev = FPI_DEVICE_FAKE (device);
enrolled_print = g_object_ref_sink (fp_print_new (device));
enrolled_print = make_fake_print_reffed (device, NULL);
g_assert_true (fp_device_open_sync (device, NULL, NULL));
@@ -950,8 +1175,8 @@ test_driver_verify_complete_retry (void)
test_driver_match_data_clear (match_data);
fake_dev->ret_result = FPI_MATCH_FAIL;
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_TOO_SHORT);
fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error));
g_test_assert_expected_messages ();
g_assert_true (error == g_steal_pointer (&fake_dev->ret_error));
@@ -972,8 +1197,8 @@ test_driver_verify_complete_retry (void)
fake_dev->ret_result = FPI_MATCH_FAIL;
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_TOO_SHORT);
fake_dev->user_data = g_error_copy (fake_dev->ret_error);
fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error));
g_test_assert_expected_messages ();
g_assert_true (error != g_steal_pointer (&fake_dev->ret_error));
@@ -994,8 +1219,8 @@ test_driver_verify_complete_retry (void)
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_TOO_SHORT);
fake_dev->user_data = g_error_copy (fake_dev->ret_error);
fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error));
g_test_assert_expected_messages ();
g_assert_true (error != g_steal_pointer (&fake_dev->ret_error));
@@ -1014,8 +1239,8 @@ test_driver_verify_complete_retry (void)
test_driver_match_data_clear (match_data);
fake_dev->ret_result = FPI_MATCH_ERROR;
fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error));
g_test_assert_expected_messages ();
g_assert_true (error != g_steal_pointer (&fake_dev->ret_error));
@@ -1033,12 +1258,12 @@ test_driver_verify_complete_retry (void)
test_driver_match_data_clear (match_data);
fake_dev->ret_result = FPI_MATCH_ERROR;
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_TOO_SHORT);
fake_dev->ret_print = fp_print_new (device);
fake_dev->ret_print = make_fake_print (device, NULL);
g_object_add_weak_pointer (G_OBJECT (fake_dev->ret_print),
(gpointer) (&fake_dev->ret_print));
fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error);
g_assert_false (fp_device_verify_sync (device, enrolled_print, NULL, test_driver_match_cb,
match_data, &match, &print, &error));
g_test_assert_expected_messages ();
g_assert_error (error, FP_DEVICE_RETRY, FP_DEVICE_RETRY_TOO_SHORT);
@@ -1087,25 +1312,23 @@ test_driver_identify (void)
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 500);
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
FpPrint *expected_matched;
unsigned int i;
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_print = fp_print_new (device);
fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error);
match_data->gallery = prints;
fake_dev->ret_print = make_fake_print (device, NULL);
g_assert_true (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error));
g_assert_true (match_data->called);
g_assert_nonnull (match_data->match);
@@ -1113,7 +1336,6 @@ test_driver_identify (void)
g_assert_true (match_data->print == print);
g_assert (fake_dev->last_called_function == dev_class->identify);
g_assert (fake_dev->action_data == prints);
g_assert_no_error (error);
g_assert (print != NULL && print == fake_dev->ret_print);
@@ -1127,21 +1349,17 @@ test_driver_identify_fail (void)
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 500);
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
unsigned int i;
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_print = fp_print_new (device);
fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error);
fake_dev->ret_print = make_fake_print (device, NULL);
g_assert_true (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error));
g_assert_true (match_data->called);
g_assert_null (match_data->match);
@@ -1163,15 +1381,11 @@ test_driver_identify_retry (void)
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 500);
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
FpPrint *expected_matched;
unsigned int i;
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
@@ -1179,9 +1393,9 @@ test_driver_identify_retry (void)
g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_GENERAL);
fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error);
g_assert_false (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error));
g_assert_true (match_data->called);
g_assert_null (match_data->match);
@@ -1201,15 +1415,11 @@ test_driver_identify_error (void)
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) matched_print = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 500);
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
FpPrint *expected_matched;
unsigned int i;
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
expected_matched = g_ptr_array_index (prints, g_random_int_range (0, 499));
fp_print_set_description (expected_matched, "fake-verified");
@@ -1217,9 +1427,9 @@ test_driver_identify_error (void)
g_assert_true (fp_device_supports_identify (device));
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_GENERAL);
fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error);
g_assert_false (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&matched_print, &print, &error));
g_assert_false (match_data->called);
g_assert_null (match_data->match);
@@ -1243,24 +1453,21 @@ test_driver_identify_not_reported (void)
{
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(FpAutoCloseDevice) device = NULL;
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = NULL;
g_autoptr(GError) error = NULL;
unsigned int i;
dev_class->identify = fake_device_identify_immediate_complete;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
prints = make_fake_prints_gallery (device, 500);
g_assert_true (fp_device_open_sync (device, NULL, NULL));
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*reported successful identify complete*not report*result*");
fp_device_identify_sync (device, prints, NULL,
NULL, NULL,
NULL, NULL, &error);
g_assert_false (fp_device_identify_sync (device, prints, NULL,
NULL, NULL,
NULL, NULL, &error));
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
@@ -1283,21 +1490,18 @@ static void
test_driver_identify_complete_retry (void)
{
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = NULL;
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
g_autoptr(FpAutoCloseDevice) device = NULL;
g_autoptr(FpPrint) print = NULL;
g_autoptr(FpPrint) match = NULL;
g_autoptr(GError) error = NULL;
FpiDeviceFake *fake_dev;
int i;
dev_class->identify = fake_device_identify_complete_error;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
fake_dev = FPI_DEVICE_FAKE (device);
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, g_object_ref_sink (fp_print_new (device)));
prints = make_fake_prints_gallery (device, 500);
g_assert_true (fp_device_open_sync (device, NULL, NULL));
@@ -1309,8 +1513,9 @@ test_driver_identify_complete_retry (void)
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_TOO_SHORT);
fake_dev->user_data = g_error_copy (fake_dev->ret_error);
fp_device_identify_sync (device, prints, NULL, test_driver_match_cb, match_data,
&match, &print, &error);
g_assert_false (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&match, &print, &error));
g_test_assert_expected_messages ();
g_assert_true (error != g_steal_pointer (&fake_dev->ret_error));
@@ -1326,11 +1531,12 @@ test_driver_identify_complete_retry (void)
"*Driver reported a match to a print that was not in the gallery*");
test_driver_match_data_clear (match_data);
fake_dev->ret_match = fp_print_new (device);
fake_dev->ret_match = make_fake_print_reffed (device, NULL);
g_object_add_weak_pointer (G_OBJECT (fake_dev->ret_match),
(gpointer) (&fake_dev->ret_match));
fp_device_identify_sync (device, prints, NULL, test_driver_match_cb, match_data,
&match, &print, &error);
g_assert_true (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&match, &print, &error));
g_test_assert_expected_messages ();
g_object_unref (fake_dev->ret_match);
@@ -1349,11 +1555,12 @@ test_driver_identify_complete_retry (void)
test_driver_match_data_clear (match_data);
fake_dev->ret_error = fpi_device_retry_new (FP_DEVICE_RETRY_REMOVE_FINGER);
fake_dev->ret_match = prints->pdata[0];
fake_dev->ret_print = fp_print_new (device);
fake_dev->ret_print = make_fake_print (device, NULL);
g_object_add_weak_pointer (G_OBJECT (fake_dev->ret_print),
(gpointer) (&fake_dev->ret_print));
fp_device_identify_sync (device, prints, NULL, test_driver_match_cb, match_data,
&match, &print, &error);
g_assert_false (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&match, &print, &error));
g_test_assert_expected_messages ();
g_assert_error (error, FP_DEVICE_RETRY, FP_DEVICE_RETRY_REMOVE_FINGER);
@@ -1371,7 +1578,7 @@ test_driver_identify_report_no_callback (void)
{
g_autoptr(FpAutoResetClass) dev_class = auto_reset_device_class ();
g_autoptr(MatchCbData) match_data = g_new0 (MatchCbData, 1);
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(GPtrArray) prints = NULL;
g_autoptr(FpAutoCloseDevice) device = NULL;
G_GNUC_UNUSED g_autoptr(FpPrint) enrolled_print = NULL;
g_autoptr(FpPrint) print = NULL;
@@ -1382,7 +1589,8 @@ test_driver_identify_report_no_callback (void)
dev_class->identify = fake_device_identify_complete_error;
device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
fake_dev = FPI_DEVICE_FAKE (device);
enrolled_print = g_object_ref_sink (fp_print_new (device));
prints = make_fake_prints_gallery (device, 0);
enrolled_print = make_fake_print_reffed (device, NULL);
g_assert_true (fp_device_open_sync (device, NULL, NULL));
@@ -1390,9 +1598,9 @@ test_driver_identify_report_no_callback (void)
"*Driver reported a verify error that was not in the retry domain*");
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_NOT_SUPPORTED);
fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&match, &print, &error);
g_assert_false (fp_device_identify_sync (device, prints, NULL,
test_driver_match_cb, match_data,
&match, &print, &error));
g_test_assert_expected_messages ();
@@ -1509,15 +1717,10 @@ test_driver_list (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 500);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
unsigned int i;
for (i = 0; i < 500; ++i)
g_ptr_array_add (prints, fp_print_new (device));
fake_dev->ret_list = g_steal_pointer (&prints);
prints = fp_device_list_prints_sync (device, NULL, &error);
@@ -1570,7 +1773,7 @@ test_driver_delete (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(FpPrint) enrolled_print = fp_print_new (device);
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
gboolean ret;
@@ -1587,7 +1790,7 @@ test_driver_delete_error (void)
{
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(FpPrint) enrolled_print = fp_print_new (device);
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
gboolean ret;
@@ -1655,7 +1858,7 @@ test_driver_cancel (void)
device = auto_close_fake_device_new ();
fake_dev = FPI_DEVICE_FAKE (device);
cancellable = g_cancellable_new ();
enrolled_print = fp_print_new (device);
enrolled_print = make_fake_print_reffed (device, NULL);
fp_device_delete_print (device, enrolled_print, cancellable,
on_driver_cancel_delete, &completed);
@@ -1673,11 +1876,11 @@ test_driver_cancel_fail (void)
g_autoptr(GError) error = NULL;
g_autoptr(FpAutoCloseDevice) device = auto_close_fake_device_new ();
g_autoptr(GCancellable) cancellable = g_cancellable_new ();
g_autoptr(FpPrint) enrolled_print = fp_print_new (device);
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev = FPI_DEVICE_FAKE (device);
fp_device_delete_print_sync (device, enrolled_print, cancellable, &error);
g_assert_true (fp_device_delete_print_sync (device, enrolled_print, cancellable, &error));
g_assert (fake_dev->last_called_function == dev_class->delete);
g_cancellable_cancel (cancellable);
@@ -1748,7 +1951,7 @@ test_driver_action_get_cancellable_open (void)
fake_dev = FPI_DEVICE_FAKE (device);
cancellable = g_cancellable_new ();
fp_device_open_sync (device, cancellable, NULL);
g_assert_true (fp_device_open_sync (device, cancellable, NULL));
g_assert (fake_dev->last_called_function == test_driver_action_get_cancellable_open_vfunc);
}
@@ -1907,8 +2110,8 @@ static void
test_driver_action_error_all (void)
{
g_autoptr(FpAutoCloseDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 0);
g_autoptr(GError) error = NULL;
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev;
@@ -1928,12 +2131,6 @@ test_driver_action_error_all (void)
fake_dev->return_action_error = TRUE;
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
g_assert_false (fp_device_close_sync (device, NULL, &error));
g_assert_true (fake_dev->last_called_function == dev_class->close);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
g_clear_error (&error);
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
g_assert_null (fp_device_enroll_sync (device, fp_print_new (device), NULL,
NULL, NULL, &error));
@@ -1972,14 +2169,21 @@ test_driver_action_error_all (void)
g_assert_true (fake_dev->last_called_function == dev_class->delete);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
g_clear_error (&error);
/* Test close last, as we can't operate on a closed device. */
fake_dev->ret_error = fpi_device_error_new (FP_DEVICE_ERROR_DATA_INVALID);
g_assert_false (fp_device_close_sync (device, NULL, &error));
g_assert_true (fake_dev->last_called_function == dev_class->close);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_DATA_INVALID);
g_clear_error (&error);
}
static void
test_driver_action_error_fallback_all (void)
{
g_autoptr(FpAutoCloseDevice) device = g_object_new (FPI_TYPE_DEVICE_FAKE, NULL);
g_autoptr(FpPrint) enrolled_print = g_object_ref_sink (fp_print_new (device));
g_autoptr(GPtrArray) prints = g_ptr_array_new_with_free_func (g_object_unref);
g_autoptr(FpPrint) enrolled_print = make_fake_print_reffed (device, NULL);
g_autoptr(GPtrArray) prints = make_fake_prints_gallery (device, 0);
g_autoptr(GError) error = NULL;
FpDeviceClass *dev_class = FP_DEVICE_GET_CLASS (device);
FpiDeviceFake *fake_dev;
@@ -2005,16 +2209,6 @@ test_driver_action_error_fallback_all (void)
"error function*");
fake_dev->return_action_error = TRUE;
g_assert_false (fp_device_close_sync (device, NULL, &error));
g_test_assert_expected_messages ();
g_assert_true (fake_dev->last_called_function == dev_class->close);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
g_clear_error (&error);
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Device failed to pass an error to generic action "
"error function*");
g_assert_null (fp_device_enroll_sync (device, fp_print_new (device), NULL,
NULL, NULL, &error));
g_test_assert_expected_messages ();
@@ -2074,6 +2268,17 @@ test_driver_action_error_fallback_all (void)
g_assert_true (fake_dev->last_called_function == dev_class->delete);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
g_clear_error (&error);
/* Test close last, as we can't operate on a closed device. */
g_test_expect_message (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
"*Device failed to pass an error to generic action "
"error function*");
g_assert_false (fp_device_close_sync (device, NULL, &error));
g_test_assert_expected_messages ();
g_assert_true (fake_dev->last_called_function == dev_class->close);
g_assert_error (error, FP_DEVICE_ERROR, FP_DEVICE_ERROR_GENERAL);
g_clear_error (&error);
}
static void
@@ -2207,6 +2412,10 @@ main (int argc, char *argv[])
g_test_add_func ("/driver/get_scan_type/swipe", test_driver_get_scan_type_swipe);
g_test_add_func ("/driver/set_scan_type/press", test_driver_set_scan_type_press);
g_test_add_func ("/driver/set_scan_type/swipe", test_driver_set_scan_type_swipe);
g_test_add_func ("/driver/finger_status/inactive", test_driver_finger_status_inactive);
g_test_add_func ("/driver/finger_status/waiting", test_driver_finger_status_needed);
g_test_add_func ("/driver/finger_status/present", test_driver_finger_status_present);
g_test_add_func ("/driver/finger_status/changes", test_driver_finger_status_changes);
g_test_add_func ("/driver/get_nr_enroll_stages", test_driver_get_nr_enroll_stages);
g_test_add_func ("/driver/set_nr_enroll_stages", test_driver_set_nr_enroll_stages);
g_test_add_func ("/driver/supports_identify", test_driver_supports_identify);

6
tests/umockdev-test.py Executable file → Normal file
View File

@@ -87,6 +87,12 @@ try:
if os.path.exists(os.path.join(ddir, "custom.ioctl")):
custom()
except Exception as e:
# Store created output files for inspection (in the build directory)
outdir = os.path.join('errors', os.path.basename(ddir))
shutil.copytree(tmpdir, outdir, dirs_exist_ok=True)
raise e
finally:
shutil.rmtree(tmpdir)

File diff suppressed because one or more lines are too long

199
tests/vfs301/capture.ioctl Normal file

File diff suppressed because one or more lines are too long

BIN
tests/vfs301/capture.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

307
tests/vfs301/device Normal file
View File

@@ -0,0 +1,307 @@
P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3
N: bus/usb/002/005=12011001FF10FF088A130500900C0000000109022700010100A0320904000003FF000000070501024000000705810240000007058202400000
E: DEVNAME=/dev/bus/usb/002/005
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=138a/5/c90
E: TYPE=255/16/255
E: BUSNUM=002
E: DEVNUM=005
E: MAJOR=189
E: MINOR=132
E: SUBSYSTEM=usb
E: ID_VENDOR=138a
E: ID_VENDOR_ENC=138a
E: ID_VENDOR_ID=138a
E: ID_MODEL=0005
E: ID_MODEL_ENC=0005
E: ID_MODEL_ID=0005
E: ID_REVISION=0c90
E: ID_SERIAL=138a_0005
E: ID_BUS=usb
E: ID_USB_INTERFACES=:ff0000:
E: ID_VENDOR_FROM_DATABASE=Validity Sensors, Inc.
E: ID_MODEL_FROM_DATABASE=VFS301 Fingerprint Reader
E: ID_PATH=pci-0000:00:1d.0-usb-0:1.3
E: ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1_3
E: LIBFPRINT_DRIVER=Validity VFS301
A: authorized=1
A: avoid_reset_quirk=0
A: bConfigurationValue=1
A: bDeviceClass=ff
A: bDeviceProtocol=ff
A: bDeviceSubClass=10
A: bMaxPacketSize0=8
A: bMaxPower=100mA
A: bNumConfigurations=1
A: bNumInterfaces= 1
A: bcdDevice=0c90
A: bmAttributes=a0
A: busnum=2
A: configuration=
H: descriptors=12011001FF10FF088A130500900C0000000109022700010100A0320904000003FF000000070501024000000705810240000007058202400000
A: dev=189:132
A: devnum=5
A: devpath=1.3
L: driver=../../../../../../bus/usb/drivers/usb
A: idProduct=0005
A: idVendor=138a
A: ltm_capable=no
A: maxchild=0
L: port=../2-1:1.0/2-1-port3
A: power/active_duration=1612976
A: power/async=enabled
A: power/autosuspend=2
A: power/autosuspend_delay_ms=2000
A: power/connected_duration=2159928
A: power/control=auto
A: power/level=auto
A: power/persist=1
A: power/runtime_active_kids=0
A: power/runtime_active_time=1612851
A: power/runtime_enabled=enabled
A: power/runtime_status=active
A: power/runtime_suspended_time=546887
A: power/runtime_usage=0
A: power/wakeup=disabled
A: power/wakeup_abort_count=
A: power/wakeup_active=
A: power/wakeup_active_count=
A: power/wakeup_count=
A: power/wakeup_expire_count=
A: power/wakeup_last_time_ms=
A: power/wakeup_max_time_ms=
A: power/wakeup_total_time_ms=
A: quirks=0x0
A: removable=fixed
A: rx_lanes=1
A: speed=12
A: tx_lanes=1
A: urbnum=7
A: version= 1.10
P: /devices/pci0000:00/0000:00:1d.0/usb2/2-1
N: bus/usb/002/002=12010002090001408780200000000000000109021900010100E0000904000001090000000705810302000C
E: DEVNAME=/dev/bus/usb/002/002
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=8087/20/0
E: TYPE=9/0/1
E: BUSNUM=002
E: DEVNUM=002
E: MAJOR=189
E: MINOR=129
E: SUBSYSTEM=usb
E: ID_VENDOR=8087
E: ID_VENDOR_ENC=8087
E: ID_VENDOR_ID=8087
E: ID_MODEL=0020
E: ID_MODEL_ENC=0020
E: ID_MODEL_ID=0020
E: ID_REVISION=0000
E: ID_SERIAL=8087_0020
E: ID_BUS=usb
E: ID_USB_INTERFACES=:090000:
E: ID_VENDOR_FROM_DATABASE=Intel Corp.
E: ID_MODEL_FROM_DATABASE=Integrated Rate Matching Hub
E: ID_PATH=pci-0000:00:1d.0-usb-0:1
E: ID_PATH_TAG=pci-0000_00_1d_0-usb-0_1
E: ID_FOR_SEAT=usb-pci-0000_00_1d_0-usb-0_1
E: TAGS=:seat:
A: authorized=1
A: avoid_reset_quirk=0
A: bConfigurationValue=1
A: bDeviceClass=09
A: bDeviceProtocol=01
A: bDeviceSubClass=00
A: bMaxPacketSize0=64
A: bMaxPower=0mA
A: bNumConfigurations=1
A: bNumInterfaces= 1
A: bcdDevice=0000
A: bmAttributes=e0
A: busnum=2
A: configuration=
H: descriptors=12010002090001408780200000000000000109021900010100E0000904000001090000000705810302000C
A: dev=189:129
A: devnum=2
A: devpath=1
L: driver=../../../../../bus/usb/drivers/usb
A: idProduct=0020
A: idVendor=8087
A: ltm_capable=no
A: maxchild=8
L: port=../2-0:1.0/usb2-port1
A: power/active_duration=2160820
A: power/async=enabled
A: power/autosuspend=0
A: power/autosuspend_delay_ms=0
A: power/connected_duration=2160824
A: power/control=auto
A: power/level=auto
A: power/runtime_active_kids=3
A: power/runtime_active_time=2160531
A: power/runtime_enabled=enabled
A: power/runtime_status=active
A: power/runtime_suspended_time=0
A: power/runtime_usage=0
A: power/wakeup=disabled
A: power/wakeup_abort_count=
A: power/wakeup_active=
A: power/wakeup_active_count=
A: power/wakeup_count=
A: power/wakeup_expire_count=
A: power/wakeup_last_time_ms=
A: power/wakeup_max_time_ms=
A: power/wakeup_total_time_ms=
A: quirks=0x0
A: removable=fixed
A: rx_lanes=1
A: speed=480
A: tx_lanes=1
A: urbnum=75
A: version= 2.00
P: /devices/pci0000:00/0000:00:1d.0/usb2
N: bus/usb/002/001=12010002090000406B1D020004050302010109021900010100E0000904000001090000000705810304000C
E: DEVNAME=/dev/bus/usb/002/001
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=1d6b/2/504
E: TYPE=9/0/0
E: BUSNUM=002
E: DEVNUM=001
E: MAJOR=189
E: MINOR=128
E: SUBSYSTEM=usb
E: ID_VENDOR=Linux_5.4.0-48-generic_ehci_hcd
E: ID_VENDOR_ENC=Linux\x205.4.0-48-generic\x20ehci_hcd
E: ID_VENDOR_ID=1d6b
E: ID_MODEL=EHCI_Host_Controller
E: ID_MODEL_ENC=EHCI\x20Host\x20Controller
E: ID_MODEL_ID=0002
E: ID_REVISION=0504
E: ID_SERIAL=Linux_5.4.0-48-generic_ehci_hcd_EHCI_Host_Controller_0000:00:1d.0
E: ID_SERIAL_SHORT=0000:00:1d.0
E: ID_BUS=usb
E: ID_USB_INTERFACES=:090000:
E: ID_VENDOR_FROM_DATABASE=Linux Foundation
E: ID_MODEL_FROM_DATABASE=2.0 root hub
E: ID_PATH=pci-0000:00:1d.0
E: ID_PATH_TAG=pci-0000_00_1d_0
E: ID_FOR_SEAT=usb-pci-0000_00_1d_0
E: TAGS=:seat:
A: authorized=1
A: authorized_default=1
A: avoid_reset_quirk=0
A: bConfigurationValue=1
A: bDeviceClass=09
A: bDeviceProtocol=00
A: bDeviceSubClass=00
A: bMaxPacketSize0=64
A: bMaxPower=0mA
A: bNumConfigurations=1
A: bNumInterfaces= 1
A: bcdDevice=0504
A: bmAttributes=e0
A: busnum=2
A: configuration=
H: descriptors=12010002090000406B1D020004050302010109021900010100E0000904000001090000000705810304000C
A: dev=189:128
A: devnum=1
A: devpath=0
L: driver=../../../../bus/usb/drivers/usb
A: idProduct=0002
A: idVendor=1d6b
A: interface_authorized_default=1
A: ltm_capable=no
A: manufacturer=Linux 5.4.0-48-generic ehci_hcd
A: maxchild=3
A: power/active_duration=2161060
A: power/async=enabled
A: power/autosuspend=0
A: power/autosuspend_delay_ms=0
A: power/connected_duration=2161060
A: power/control=auto
A: power/level=auto
A: power/runtime_active_kids=1
A: power/runtime_active_time=2161035
A: power/runtime_enabled=enabled
A: power/runtime_status=active
A: power/runtime_suspended_time=0
A: power/runtime_usage=0
A: power/wakeup=disabled
A: power/wakeup_abort_count=
A: power/wakeup_active=
A: power/wakeup_active_count=
A: power/wakeup_count=
A: power/wakeup_expire_count=
A: power/wakeup_last_time_ms=
A: power/wakeup_max_time_ms=
A: power/wakeup_total_time_ms=
A: product=EHCI Host Controller
A: quirks=0x0
A: removable=unknown
A: rx_lanes=1
A: serial=0000:00:1d.0
A: speed=480
A: tx_lanes=1
A: urbnum=26
A: version= 2.00
P: /devices/pci0000:00/0000:00:1d.0
E: DRIVER=ehci-pci
E: PCI_CLASS=C0320
E: PCI_ID=8086:3B34
E: PCI_SUBSYS_ID=103C:7001
E: PCI_SLOT_NAME=0000:00:1d.0
E: MODALIAS=pci:v00008086d00003B34sv0000103Csd00007001bc0Csc03i20
E: SUBSYSTEM=pci
E: ID_PCI_CLASS_FROM_DATABASE=Serial bus controller
E: ID_PCI_SUBCLASS_FROM_DATABASE=USB controller
E: ID_PCI_INTERFACE_FROM_DATABASE=EHCI
E: ID_VENDOR_FROM_DATABASE=Intel Corporation
E: ID_MODEL_FROM_DATABASE=5 Series/3400 Series Chipset USB2 Enhanced Host Controller
A: ari_enabled=0
A: broken_parity_status=0
A: class=0x0c0320
A: companion=
H: config=8680343B060090020520030C00000000005810DB0000000000000000000000000000000000000000000000003C1001700000000050000000000000000B010000
A: consistent_dma_mask_bits=32
A: d3cold_allowed=1
A: device=0x3b34
A: dma_mask_bits=32
L: driver=../../../bus/pci/drivers/ehci-pci
A: driver_override=(null)
A: enable=1
A: irq=21
A: local_cpulist=0-7
A: local_cpus=ff
A: modalias=pci:v00008086d00003B34sv0000103Csd00007001bc0Csc03i20
A: msi_bus=1
A: numa_node=-1
A: pools=poolinfo - 0.1\nehci_sitd 0 0 96 0\nehci_itd 0 0 192 0\nehci_qh 12 42 96 1\nehci_qtd 13 84 96 2\nbuffer-2048 0 0 2048 0\nbuffer-512 0 0 512 0\nbuffer-128 2 32 128 1\nbuffer-32 0 0 32 0
A: power/async=enabled
A: power/control=on
A: power/runtime_active_kids=1
A: power/runtime_active_time=2161633
A: power/runtime_enabled=forbidden
A: power/runtime_status=active
A: power/runtime_suspended_time=0
A: power/runtime_usage=1
A: power/wakeup=enabled
A: power/wakeup_abort_count=0
A: power/wakeup_active=0
A: power/wakeup_active_count=0
A: power/wakeup_count=0
A: power/wakeup_expire_count=0
A: power/wakeup_last_time_ms=0
A: power/wakeup_max_time_ms=0
A: power/wakeup_total_time_ms=0
A: resource=0x00000000db105800 0x00000000db105bff 0x0000000000040200\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000\n0x0000000000000000 0x0000000000000000 0x0000000000000000
A: revision=0x05
A: subsystem_device=0x7001
A: subsystem_vendor=0x103c
A: uframe_periodic_max=100
A: vendor=0x8086

View File

@@ -172,6 +172,7 @@ class VirtualImage(unittest.TestCase):
def done_cb(dev, res):
print("Enroll done")
fp = dev.enroll_finish(res)
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE)
self._enrolled = fp
template = FPrint.Print.new(self.dev)
@@ -182,6 +183,7 @@ class VirtualImage(unittest.TestCase):
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)
# Note: Assumes 5 enroll steps for this device!
@@ -192,25 +194,36 @@ class VirtualImage(unittest.TestCase):
# Test the image-device path where the finger is removed after
# the minutiae scan is completed.
self.send_finger_automatic(False)
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NEEDED)
self.send_finger_report(True)
self.assertEqual(self.dev.get_finger_status(),
FPrint.FingerStatusFlags.NEEDED | FPrint.FingerStatusFlags.PRESENT)
self.send_image(image)
while self._step < 2:
ctx.iteration(True)
self.send_finger_report(False)
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NEEDED)
self.send_finger_automatic(True)
self.send_image(image)
while self._step < 3:
ctx.iteration(True)
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NEEDED)
self.send_image(image)
while self._step < 4:
ctx.iteration(True)
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NEEDED)
self.send_image(image)
while self._enrolled is None:
ctx.iteration(True)
self.assertEqual(self.dev.get_finger_status(), FPrint.FingerStatusFlags.NONE)
return self._enrolled
def test_enroll_verify(self):