virtual-device: Add support for changing the device scan type

This commit is contained in:
Marco Trevisan (Treviño) 2021-01-24 17:35:29 +01:00
parent be0b4ae2bb
commit 81e53c422d
2 changed files with 36 additions and 1 deletions

View file

@ -41,6 +41,7 @@ G_DEFINE_TYPE (FpDeviceVirtualDevice, fpi_device_virtual_device, FP_TYPE_DEVICE)
#define RETRY_CMD_PREFIX "RETRY "
#define FINGER_CMD_PREFIX "FINGER "
#define SET_ENROLL_STAGES_PREFIX "SET_ENROLL_STAGES "
#define SET_SCAN_TYPE_PREFIX "SET_SCAN_TYPE "
#define LIST_CMD "LIST"
@ -204,6 +205,17 @@ recv_instruction_cb (GObject *source_object,
stages = g_ascii_strtoull (cmd + strlen (SET_ENROLL_STAGES_PREFIX), NULL, 10);
fpi_device_set_nr_enroll_stages (FP_DEVICE (self), stages);
}
else if (g_str_has_prefix (cmd, SET_SCAN_TYPE_PREFIX))
{
const char *scan_type = cmd + strlen (SET_SCAN_TYPE_PREFIX);
g_autoptr(GEnumClass) scan_types = g_type_class_ref (fp_scan_type_get_type ());
GEnumValue *value = g_enum_get_value_by_nick (scan_types, scan_type);
if (value)
fpi_device_set_scan_type (FP_DEVICE (self), value->value);
else
g_warning ("Scan type '%s' not found", scan_type);
}
else
{
g_ptr_array_add (self->pending_commands, g_steal_pointer (&cmd));

View file

@ -94,7 +94,7 @@ class VirtualDevice(unittest.TestCase):
def send_command(self, command, *args):
self.assertIn(command, ['INSERT', 'REMOVE', 'SCAN', 'ERROR', 'RETRY',
'FINGER', 'SET_ENROLL_STAGES'])
'FINGER', 'SET_ENROLL_STAGES', 'SET_SCAN_TYPE'])
with Connection(self.sockaddr) as con:
params = ' '.join(str(p) for p in args)
@ -292,6 +292,29 @@ class VirtualDevice(unittest.TestCase):
self.assertEqual(matching.get_username(), 'testuser')
self.assertEqual(matching.get_finger(), FPrint.Finger.LEFT_LITTLE)
def test_change_scan_type(self):
notified_spec = None
def on_scan_type_changed(dev, spec):
nonlocal notified_spec
notified_spec = spec
self.dev.connect('notify::scan-type', on_scan_type_changed)
for scan_type in [FPrint.ScanType.PRESS, FPrint.ScanType.SWIPE]:
notified_spec = None
self.send_command('SET_SCAN_TYPE', scan_type.value_nick)
self.assertEqual(self.dev.get_scan_type(), scan_type)
self.assertEqual(notified_spec.name, 'scan-type')
GLib.test_expect_message('libfprint-virtual_device',
GLib.LogLevelFlags.LEVEL_WARNING, '*Scan type*not found')
notified_spec = None
self.send_command('SET_SCAN_TYPE', 'eye-contact')
self.assertEqual(self.dev.get_scan_type(), FPrint.ScanType.SWIPE)
self.assertIsNone(notified_spec)
GLib.test_assert_expected_messages_internal('libfprint-device',
__file__, 0, 'test_change_scan_type')
class VirtualDeviceStorage(VirtualDevice):
def cleanup_device_storage(self):