From 356805168637666c758fbc2a2f436d6418c7e5f4 Mon Sep 17 00:00:00 2001 From: Devyn Cairns Date: Fri, 5 Nov 2021 07:27:56 -0700 Subject: [PATCH] goodixmoc: support for clear_storage The internal storage of this device can get messed up by other operating systems, so it's handy to be able to clear it. I'm not 100% sure whether the commands I've sent to the device are exactly what is supposed to be used (just a guess), but it did seem to work, and it even fixed another issue I had. --- libfprint/drivers/goodixmoc/goodix.c | 40 ++++++++++++++++++++++++++++ tests/goodixmoc/custom.py | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/libfprint/drivers/goodixmoc/goodix.c b/libfprint/drivers/goodixmoc/goodix.c index 43f63259..4eeb7215 100644 --- a/libfprint/drivers/goodixmoc/goodix.c +++ b/libfprint/drivers/goodixmoc/goodix.c @@ -1160,6 +1160,32 @@ fp_template_delete_cb (FpiDeviceGoodixMoc *self, fp_info ("Successfully deleted enrolled user"); fpi_device_delete_complete (device, NULL); } + +static void +fp_template_delete_all_cb (FpiDeviceGoodixMoc *self, + gxfp_cmd_response_t *resp, + GError *error) +{ + FpDevice *device = FP_DEVICE (self); + + if (error) + { + fpi_device_clear_storage_complete (device, error); + return; + } + if ((resp->result >= GX_FAILED) && (resp->result != GX_ERROR_FINGER_ID_NOEXIST)) + { + fpi_device_clear_storage_complete (FP_DEVICE (self), + fpi_device_error_new_msg (FP_DEVICE_ERROR_GENERAL, + "Failed clear storage, result: 0x%x", + resp->result)); + return; + } + + fp_info ("Successfully cleared storage"); + fpi_device_clear_storage_complete (device, NULL); +} + /****************************************************************************** * * fp_template_list Function @@ -1483,6 +1509,19 @@ gx_fp_template_delete (FpDevice *device) } +static void +gx_fp_template_delete_all (FpDevice *device) +{ + FpiDeviceGoodixMoc *self = FPI_DEVICE_GOODIXMOC (device); + + goodix_sensor_cmd (self, MOC_CMD0_DELETETEMPLATE, MOC_CMD1_DELETE_ALL, + false, + NULL, + 0, + fp_template_delete_all_cb); + +} + static void fpi_device_goodixmoc_init (FpiDeviceGoodixMoc *self) { @@ -1526,6 +1565,7 @@ fpi_device_goodixmoc_class_init (FpiDeviceGoodixMocClass *klass) dev_class->probe = gx_fp_probe; dev_class->enroll = gx_fp_enroll; dev_class->delete = gx_fp_template_delete; + dev_class->clear_storage = gx_fp_template_delete_all; dev_class->list = gx_fp_template_list; dev_class->verify = gx_fp_verify_identify; dev_class->identify = gx_fp_verify_identify; diff --git a/tests/goodixmoc/custom.py b/tests/goodixmoc/custom.py index 2fe6edd9..1fb513a1 100755 --- a/tests/goodixmoc/custom.py +++ b/tests/goodixmoc/custom.py @@ -21,7 +21,7 @@ assert d.has_feature(FPrint.DeviceFeature.DUPLICATES_CHECK) assert d.has_feature(FPrint.DeviceFeature.STORAGE) assert d.has_feature(FPrint.DeviceFeature.STORAGE_LIST) assert d.has_feature(FPrint.DeviceFeature.STORAGE_DELETE) -assert not d.has_feature(FPrint.DeviceFeature.STORAGE_CLEAR) +assert d.has_feature(FPrint.DeviceFeature.STORAGE_CLEAR) d.open_sync()