trivial: Allow plugins to add metadata to the uploaded reports

This commit is contained in:
Richard Hughes 2018-01-11 21:11:06 +00:00
parent 473c520e38
commit 80b79bb9aa
6 changed files with 54 additions and 0 deletions

View File

@ -29,6 +29,16 @@
#include "fu-colorhug-device.h"
void
fu_plugin_init (FuPlugin *plugin)
{
g_autofree gchar *tmp = g_strdup_printf ("%i.%i.%i",
CH_MAJOR_VERSION,
CH_MINOR_VERSION,
CH_MICRO_VERSION);
fu_plugin_add_report_metadata (plugin, "ColorhugVersion", tmp);
}
gboolean
fu_plugin_update_detach (FuPlugin *plugin, FuDevice *device, GError **error)
{

View File

@ -37,6 +37,7 @@ void
fu_plugin_init (FuPlugin *plugin)
{
fu_plugin_add_rule (plugin, FU_PLUGIN_RULE_RUN_AFTER, "upower");
//fu_plugin_add_report_metadata (plugin, "FwupdateVersion", LIBFWUP_VERSION);
}
static gchar *

View File

@ -1489,6 +1489,8 @@ fu_engine_install (FuEngine *self,
/* build the version metadata */
metadata_hash = fu_engine_get_report_metadata (self);
fwupd_release_add_metadata (release_history, metadata_hash);
fwupd_release_add_metadata (release_history,
fu_plugin_get_report_metadata (plugin));
/* add device to database */
checksum = g_compute_checksum_for_bytes (G_CHECKSUM_SHA1, blob_cab);

View File

@ -49,6 +49,7 @@ void fu_plugin_set_name (FuPlugin *plugin,
const gchar *name);
GPtrArray *fu_plugin_get_rules (FuPlugin *plugin,
FuPluginRule rule);
GHashTable *fu_plugin_get_report_metadata (FuPlugin *plugin);
gboolean fu_plugin_open (FuPlugin *plugin,
const gchar *filename,
GError **error);

View File

@ -61,6 +61,7 @@ typedef struct {
FuSmbios *smbios;
GHashTable *devices; /* platform_id:GObject */
GHashTable *devices_delay; /* FuDevice:FuPluginHelper */
GHashTable *report_metadata; /* key:value */
FuPluginData *data;
} FuPluginPrivate;
@ -1426,6 +1427,40 @@ fu_plugin_get_rules (FuPlugin *plugin, FuPluginRule rule)
return priv->rules[rule];
}
/**
* fu_plugin_add_report_metadata:
* @plugin: a #FuPlugin
* @key: a string, e.g. `FwupdateVersion`
* @value: a string, e.g. `10`
*
* Sets any additional metadata to be included in the firmware report to aid
* debugging problems.
*
* Any data included here will be sent to the metadata server after user
* confirmation.
**/
void
fu_plugin_add_report_metadata (FuPlugin *plugin, const gchar *key, const gchar *value)
{
FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
g_hash_table_insert (priv->report_metadata, g_strdup (key), g_strdup (value));
}
/**
* fu_plugin_get_report_metadata:
* @plugin: a #FuPlugin
*
* Returns the list of additional metadata to be added when filing a report.
*
* Returns: (transfer none): the map of report metadata
**/
GHashTable *
fu_plugin_get_report_metadata (FuPlugin *plugin)
{
FuPluginPrivate *priv = fu_plugin_get_instance_private (plugin);
return priv->report_metadata;
}
static void
fu_plugin_class_init (FuPluginClass *klass)
{
@ -1471,6 +1506,7 @@ fu_plugin_init (FuPlugin *plugin)
priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_object_unref);
priv->devices_delay = g_hash_table_new (g_direct_hash, g_direct_equal);
priv->report_metadata = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
for (guint i = 0; i < FU_PLUGIN_RULE_LAST; i++)
priv->rules[i] = g_ptr_array_new_with_free_func (g_free);
}
@ -1510,6 +1546,7 @@ fu_plugin_finalize (GObject *object)
#endif
g_hash_table_unref (priv->devices);
g_hash_table_unref (priv->devices_delay);
g_hash_table_unref (priv->report_metadata);
g_free (priv->name);
g_free (priv->data);

View File

@ -144,6 +144,9 @@ const gchar *fu_plugin_lookup_quirk_by_id (FuPlugin *plugin,
const gchar *fu_plugin_lookup_quirk_by_usb_device (FuPlugin *plugin,
const gchar *prefix,
GUsbDevice *dev);
void fu_plugin_add_report_metadata (FuPlugin *plugin,
const gchar *key,
const gchar *value);
G_END_DECLS