From 296fe5fb468190e98250fd96adf62ebb0f08de14 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Mon, 23 Jan 2023 17:30:11 +0000 Subject: [PATCH] trivial: Add a device flag specifying it is emulated --- libfwupd/fwupd-enums.c | 4 ++++ libfwupd/fwupd-enums.h | 8 ++++++++ libfwupdplugin/fu-usb-device.c | 6 ++++++ src/fu-util-common.c | 4 ++++ 4 files changed, 22 insertions(+) diff --git a/libfwupd/fwupd-enums.c b/libfwupd/fwupd-enums.c index 96839b960..933766aeb 100644 --- a/libfwupd/fwupd-enums.c +++ b/libfwupd/fwupd-enums.c @@ -209,6 +209,8 @@ fwupd_device_flag_to_string(FwupdDeviceFlags device_flag) return "signed-payload"; if (device_flag == FWUPD_DEVICE_FLAG_UNSIGNED_PAYLOAD) return "unsigned-payload"; + if (device_flag == FWUPD_DEVICE_FLAG_EMULATED) + return "emulated"; if (device_flag == FWUPD_DEVICE_FLAG_UNKNOWN) return "unknown"; return NULL; @@ -328,6 +330,8 @@ fwupd_device_flag_from_string(const gchar *device_flag) return FWUPD_DEVICE_FLAG_SIGNED_PAYLOAD; if (g_strcmp0(device_flag, "unsigned-payload") == 0) return FWUPD_DEVICE_FLAG_UNSIGNED_PAYLOAD; + if (g_strcmp0(device_flag, "emulated") == 0) + return FWUPD_DEVICE_FLAG_EMULATED; return FWUPD_DEVICE_FLAG_UNKNOWN; } diff --git a/libfwupd/fwupd-enums.h b/libfwupd/fwupd-enums.h index 23490bf47..af96ab6e3 100644 --- a/libfwupd/fwupd-enums.h +++ b/libfwupd/fwupd-enums.h @@ -527,6 +527,14 @@ typedef enum { * Since: 1.7.6 */ #define FWUPD_DEVICE_FLAG_UNSIGNED_PAYLOAD (1llu << 48) +/** + * FWUPD_DEVICE_FLAG_EMULATED: + * + * The device is emulated and should not be recorded by the backend. + * + * Since: 1.8.11 + */ +#define FWUPD_DEVICE_FLAG_EMULATED (1llu << 49) /** * FWUPD_DEVICE_FLAG_UNKNOWN: * diff --git a/libfwupdplugin/fu-usb-device.c b/libfwupdplugin/fu-usb-device.c index c91de4ea3..94c03f539 100644 --- a/libfwupdplugin/fu-usb-device.c +++ b/libfwupdplugin/fu-usb-device.c @@ -695,6 +695,12 @@ fu_usb_device_set_dev(FuUsbDevice *device, GUsbDevice *usb_device) } #ifdef HAVE_GUSB +#if G_USB_CHECK_VERSION(0, 4, 4) + /* propagate emulated flag */ + if (usb_device != NULL && g_usb_device_is_emulated(usb_device)) + fu_device_add_flag(FU_DEVICE(device), FWUPD_DEVICE_FLAG_EMULATED); +#endif + /* set device ID automatically */ fu_device_set_physical_id(FU_DEVICE(device), g_usb_device_get_platform_id(usb_device)); #endif diff --git a/src/fu-util-common.c b/src/fu-util-common.c index 125cdfad5..630cc16c3 100644 --- a/src/fu-util-common.c +++ b/src/fu-util-common.c @@ -1312,6 +1312,10 @@ fu_util_device_flag_to_string(guint64 device_flag) /* TRANSLATORS: firmware payload is unsigned and it is possible to modify it */ return _("Unsigned Payload"); } + if (device_flag == FWUPD_DEVICE_FLAG_EMULATED) { + /* TRANSLATORS: this device is not actually real */ + return _("Emulated"); + } if (device_flag == FWUPD_DEVICE_FLAG_SKIPS_RESTART) { /* skip */ return NULL;