powerd: trivial style fixups

This commit is contained in:
Richard Hughes 2021-07-20 20:46:30 +01:00 committed by Daniel Campello
parent 357bfd07da
commit 56bf223a0f

View File

@ -34,19 +34,10 @@ gboolean
fu_plugin_startup (FuPlugin *plugin, GError **error) fu_plugin_startup (FuPlugin *plugin, GError **error)
{ {
FuPluginData *data = fu_plugin_get_data (plugin); FuPluginData *data = fu_plugin_get_data (plugin);
g_autoptr(GDBusConnection) connection = NULL;
g_autofree gchar *name_owner = NULL; g_autofree gchar *name_owner = NULL;
/* establishing DBus connection and proxy for method call to powerd */ /* establish proxy for method call to powerd */
connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error); data->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
if (connection == NULL) {
g_prefix_error (error,
"Connection with system was not established: ");
return FALSE;
}
data->proxy = g_dbus_proxy_new_sync (connection,
G_DBUS_PROXY_FLAGS_NONE, G_DBUS_PROXY_FLAGS_NONE,
NULL, NULL,
"org.chromium.PowerManager", "org.chromium.PowerManager",
@ -56,18 +47,15 @@ fu_plugin_startup (FuPlugin *plugin, GError **error)
error); error);
if (data->proxy == NULL) { if (data->proxy == NULL) {
g_prefix_error ( g_prefix_error (error, "failed to establish proxy: ");
error,
"Failed to establish proxy for power manager server: ");
return FALSE; return FALSE;
} }
name_owner = g_dbus_proxy_get_name_owner (data->proxy); name_owner = g_dbus_proxy_get_name_owner (data->proxy);
if (name_owner == NULL) { if (name_owner == NULL) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_NOT_SUPPORTED, FWUPD_ERROR_NOT_SUPPORTED,
"No service that owns the name for %s", "no service that owns the name for %s",
g_dbus_proxy_get_name (data->proxy)); g_dbus_proxy_get_name (data->proxy));
return FALSE; return FALSE;
} }
@ -82,8 +70,8 @@ fu_plugin_update_prepare (FuPlugin *plugin,
{ {
FuPluginData *data = fu_plugin_get_data (plugin); FuPluginData *data = fu_plugin_get_data (plugin);
guint32 power_type = 0; guint32 power_type = 0;
guint32 current_status = 0; guint32 current_state = 0;
gdouble current_percentage = 0; gdouble current_level = 0;
g_autoptr(GVariant) powerd_response = NULL; g_autoptr(GVariant) powerd_response = NULL;
/* making method call to "GetBatteryState" through the proxy */ /* making method call to "GetBatteryState" through the proxy */
@ -94,28 +82,22 @@ fu_plugin_update_prepare (FuPlugin *plugin,
-1, -1,
NULL, NULL,
error); error);
if (powerd_response == NULL) { if (powerd_response == NULL) {
g_prefix_error ( g_prefix_error (error, "battery information was not loaded: ");
error,
"Battery information from powerd was not loaded "
"successfully: ");
return FALSE; return FALSE;
} }
/* parsing data in powerd_response and inputting it into battery-check /* parse and use for battery-check conditions */
* conditions */
g_variant_get (powerd_response, g_variant_get (powerd_response,
"(uud)", "(uud)",
&power_type, &power_type,
&current_status, &current_state,
&current_percentage); &current_level);
/* blocking updates if there is no AC power or if battery /* blocking updates if there is no AC power or if battery
* percentage is too low * percentage is too low */
*/
if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_REQUIRE_AC) && if (fu_device_has_flag (device, FWUPD_DEVICE_FLAG_REQUIRE_AC) &&
current_status == FU_BATTERY_STATE_DISCHARGING) { current_state == FU_BATTERY_STATE_DISCHARGING) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_AC_POWER_REQUIRED, FWUPD_ERROR_AC_POWER_REQUIRED,
@ -123,8 +105,7 @@ fu_plugin_update_prepare (FuPlugin *plugin,
"unless forced "); "unless forced ");
return FALSE; return FALSE;
} }
if (current_level < MINIMUM_BATTERY_PERCENTAGE_FALLBACK) {
if (current_percentage < MINIMUM_BATTERY_PERCENTAGE_FALLBACK) {
g_set_error (error, g_set_error (error,
FWUPD_ERROR, FWUPD_ERROR,
FWUPD_ERROR_BATTERY_LEVEL_TOO_LOW, FWUPD_ERROR_BATTERY_LEVEL_TOO_LOW,