Require AC power before scheduling some types of firmware update

Fixes half of https://github.com/hughsie/fwupd/issues/42
This commit is contained in:
Richard Hughes 2016-02-20 20:22:00 +00:00
parent 778c6b62d0
commit b75c92db47
4 changed files with 45 additions and 0 deletions

View File

@ -71,6 +71,7 @@ typedef enum {
FU_DEVICE_FLAG_INTERNAL = 1 << 0, /* Since: 0.1.3 */ FU_DEVICE_FLAG_INTERNAL = 1 << 0, /* Since: 0.1.3 */
FU_DEVICE_FLAG_ALLOW_ONLINE = 1 << 1, /* Since: 0.1.3 */ FU_DEVICE_FLAG_ALLOW_ONLINE = 1 << 1, /* Since: 0.1.3 */
FU_DEVICE_FLAG_ALLOW_OFFLINE = 1 << 2, /* Since: 0.1.3 */ FU_DEVICE_FLAG_ALLOW_OFFLINE = 1 << 2, /* Since: 0.1.3 */
FU_DEVICE_FLAG_REQUIRE_AC = 1 << 3, /* Since: 0.6.3 */
/* private */ /* private */
FU_DEVICE_FLAG_LAST FU_DEVICE_FLAG_LAST
} FwupdDeviceFlags; } FwupdDeviceFlags;

View File

@ -326,6 +326,36 @@ fu_main_helper_free (FuMainAuthHelper *helper)
g_free (helper); g_free (helper);
} }
/**
* fu_main_on_battery:
**/
static gboolean
fu_main_on_battery (void)
{
g_autoptr(GDBusProxy) proxy = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GVariant) value = NULL;
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
NULL,
"org.freedesktop.UPower",
"/org/freedesktop/UPower",
"org.freedesktop.UPower",
NULL,
&error);
if (proxy == NULL) {
g_warning ("Failed to conect UPower: %s", error->message);
return FALSE;
}
value = g_dbus_proxy_get_cached_property (proxy, "OnBattery");
if (value == NULL) {
g_warning ("Failed to get OnBattery property value");
return FALSE;
}
return g_variant_get_boolean (value);
}
/** /**
* fu_main_provider_update_authenticated: * fu_main_provider_update_authenticated:
**/ **/
@ -345,6 +375,18 @@ fu_main_provider_update_authenticated (FuMainAuthHelper *helper, GError **error)
return FALSE; return FALSE;
} }
/* can we only do this on AC power */
if (fu_device_get_flags (item->device) & FU_DEVICE_FLAG_REQUIRE_AC) {
if (fu_main_on_battery ()) {
g_set_error_literal (error,
FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED,
"Cannot install update "
"when not on AC power");
return FALSE;
}
}
/* run the correct provider that added this */ /* run the correct provider that added this */
if (!fu_provider_update (item->provider, if (!fu_provider_update (item->provider,
item->device, item->device,

View File

@ -301,6 +301,7 @@ fu_provider_rpi_coldplug (FuProvider *provider, GError **error)
fu_device_add_flag (device, FU_DEVICE_FLAG_INTERNAL); fu_device_add_flag (device, FU_DEVICE_FLAG_INTERNAL);
fu_device_add_flag (device, FU_DEVICE_FLAG_ALLOW_OFFLINE); fu_device_add_flag (device, FU_DEVICE_FLAG_ALLOW_OFFLINE);
fu_device_add_flag (device, FU_DEVICE_FLAG_ALLOW_ONLINE); fu_device_add_flag (device, FU_DEVICE_FLAG_ALLOW_ONLINE);
fu_device_add_flag (device, FU_DEVICE_FLAG_REQUIRE_AC);
/* get the VC build info */ /* get the VC build info */
if (!fu_provider_rpi_parse_firmware (device, fwfn, error)) if (!fu_provider_rpi_parse_firmware (device, fwfn, error))

View File

@ -337,6 +337,7 @@ fu_provider_uefi_coldplug (FuProvider *provider, GError **error)
} }
fu_device_add_flag (dev, FU_DEVICE_FLAG_INTERNAL); fu_device_add_flag (dev, FU_DEVICE_FLAG_INTERNAL);
fu_device_add_flag (dev, FU_DEVICE_FLAG_ALLOW_OFFLINE); fu_device_add_flag (dev, FU_DEVICE_FLAG_ALLOW_OFFLINE);
fu_device_add_flag (dev, FU_DEVICE_FLAG_REQUIRE_AC);
fu_provider_device_add (provider, dev); fu_provider_device_add (provider, dev);
} }
fwup_resource_iter_destroy (&iter); fwup_resource_iter_destroy (&iter);