device: Gracefully handle identify on devices with no support

We were crashing as trying to still call the identify vfunc, so check if
identification is supported and if not return a relative error.

Added test as well
This commit is contained in:
Marco Trevisan (Treviño) 2021-04-01 17:43:07 +02:00
parent 59767af552
commit 4031bb62d7
2 changed files with 17 additions and 0 deletions

View file

@ -1038,6 +1038,14 @@ fp_device_identify (FpDevice *device,
return; return;
} }
if (!fp_device_supports_identify (device))
{
g_task_return_error (task,
fpi_device_error_new_msg (FP_DEVICE_ERROR_NOT_SUPPORTED,
"Device has not identification support"));
return;
}
priv->current_action = FPI_DEVICE_ACTION_IDENTIFY; priv->current_action = FPI_DEVICE_ACTION_IDENTIFY;
priv->current_task = g_steal_pointer (&task); priv->current_task = g_steal_pointer (&task);
maybe_cancel_on_cancelled (device, cancellable); maybe_cancel_on_cancelled (device, cancellable);

View file

@ -849,6 +849,15 @@ class VirtualDevice(VirtualDeviceBase):
self.assertEqual(close_res.code, int(FPrint.DeviceError.BUSY)) self.assertEqual(close_res.code, int(FPrint.DeviceError.BUSY))
def test_identify_unsupported(self):
if self.dev.supports_identify():
self.skipTest('Device supports identification')
with self.assertRaises(GLib.Error) as error:
self.dev.identify_sync([FPrint.Print.new(self.dev)])
self.assertTrue(error.exception.matches(FPrint.DeviceError.quark(),
FPrint.DeviceError.NOT_SUPPORTED))
class VirtualDeviceClosed(VirtualDeviceBase): class VirtualDeviceClosed(VirtualDeviceBase):