diff --git a/src/fu-device.c b/src/fu-device.c index 9d4744adf..9e43974ab 100644 --- a/src/fu-device.c +++ b/src/fu-device.c @@ -721,6 +721,37 @@ fu_device_get_custom_flags (FuDevice *device) return fu_device_get_metadata (device, "CustomFlags"); } +/** + * fu_device_has_custom_flag: + * @device: A #FuDevice + * @hint: A string, e.g. "bootloader" + * + * Checks if the custom flag exists for the device from the quirk system. + * + * It may be more efficient to call fu_device_get_custom_flags() and split the + * string locally if checking for lots of different flags. + * + * Returns: %TRUE if the hint exists + * + * Since: 1.1.0 + **/ +gboolean +fu_device_has_custom_flag (FuDevice *device, const gchar *hint) +{ + const gchar *hint_str; + g_auto(GStrv) hints = NULL; + + g_return_val_if_fail (FU_IS_DEVICE (device), FALSE); + g_return_val_if_fail (hint != NULL, FALSE); + + /* no hint is perfectly valid */ + hint_str = fu_device_get_custom_flags (device); + if (hint_str == NULL) + return FALSE; + hints = g_strsplit (hint_str, ",", -1); + return g_strv_contains ((const gchar * const *) hints, hint); +} + /** * fu_device_set_platform_id: * @device: A #FuDevice diff --git a/src/fu-device.h b/src/fu-device.h index 5f3876c45..0d348569e 100644 --- a/src/fu-device.h +++ b/src/fu-device.h @@ -138,6 +138,8 @@ const gchar *fu_device_get_serial (FuDevice *device); void fu_device_set_serial (FuDevice *device, const gchar *serial); const gchar *fu_device_get_custom_flags (FuDevice *device); +gboolean fu_device_has_custom_flag (FuDevice *device, + const gchar *hint); void fu_device_set_custom_flags (FuDevice *device, const gchar *custom_flags); void fu_device_set_name (FuDevice *device,