diff --git a/policy/org.freedesktop.upower.policy.in b/policy/org.freedesktop.upower.policy.in index b1d02b2..58da2d3 100644 --- a/policy/org.freedesktop.upower.policy.in +++ b/policy/org.freedesktop.upower.policy.in @@ -29,4 +29,12 @@ file are instantly applied. + + Change the battery charging strategy + Authentication is required to set battery charging strategy. + + no + yes + + diff --git a/src/up-device-battery.c b/src/up-device-battery.c index d60a18e..6bc4b4b 100644 --- a/src/up-device-battery.c +++ b/src/up-device-battery.c @@ -669,7 +669,7 @@ up_device_battery_set_charge_threshold (UpExportedDevice *skeleton, return FALSE; } - if (!up_device_polkit_is_allowed (device, invocation)) { + if (!up_device_polkit_is_allowed (device, invocation, "org.freedesktop.UPower.enable-charging-limit")) { g_dbus_method_invocation_return_error (invocation, UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, "Operation is not allowed."); @@ -805,8 +805,10 @@ up_device_battery_set_charge_strategy (UpExportedDevice *skeleton, return FALSE; } - if (!up_device_polkit_is_allowed (device, invocation)) { - + if (!up_device_polkit_is_allowed (device, invocation, "org.freedesktop.UPower.set-charge-strategy")) { + g_dbus_method_invocation_return_error (invocation, + UP_DAEMON_ERROR, UP_DAEMON_ERROR_GENERAL, + "Operation is not allowed."); return TRUE; } diff --git a/src/up-device.c b/src/up-device.c index 2a5ff1a..7deafd8 100644 --- a/src/up-device.c +++ b/src/up-device.c @@ -407,12 +407,14 @@ up_device_get_daemon (UpDevice *device) * up_device_polkit_is_allowed **/ gboolean -up_device_polkit_is_allowed (UpDevice *device, GDBusMethodInvocation *invocation) +up_device_polkit_is_allowed (UpDevice *device, GDBusMethodInvocation *invocation, const gchar *action_id) { UpDevicePrivate *priv = up_device_get_instance_private (device); + g_return_val_if_fail (UP_IS_DEVICE (device), FALSE); + g_return_val_if_fail (action_id != NULL, FALSE); if (!up_daemon_polkit_is_allowed (priv->daemon, - "org.freedesktop.UPower.enable-charging-limit", + action_id, invocation)) return FALSE; diff --git a/src/up-device.h b/src/up-device.h index 5e6ad61..1828ce0 100644 --- a/src/up-device.h +++ b/src/up-device.h @@ -69,7 +69,8 @@ gboolean up_device_get_online (UpDevice *device, gboolean *online); const gchar *up_device_get_state_dir_override (UpDevice *device); gboolean up_device_polkit_is_allowed (UpDevice *device, - GDBusMethodInvocation *invocation); + GDBusMethodInvocation *invocation, + const gchar *action_id); void up_device_sibling_discovered (UpDevice *device, GObject *sibling); gboolean up_device_refresh_internal (UpDevice *device,