Compare commits

...

No commits in common. 'c8' and 'c9-beta' have entirely different histories.
c8 ... c9-beta

2
.gitignore vendored

@ -1 +1 @@
SOURCES/gnome-settings-daemon-3.32.0.tar.xz
SOURCES/gnome-settings-daemon-40.0.1.tar.xz

@ -1 +1 @@
92145a7a5714ebf3aeb90baaacb7e6955335731b SOURCES/gnome-settings-daemon-3.32.0.tar.xz
5c9249cc5e89627bd548d7cfc9f839c7524ad85f SOURCES/gnome-settings-daemon-40.0.1.tar.xz

@ -1,47 +0,0 @@
From bd0488fe501bae74fae1fbb21566aa35f38aa6fc Mon Sep 17 00:00:00 2001
From: Felipe Borges <felipeborges@gnome.org>
Date: Wed, 15 Feb 2023 15:27:59 +0100
Subject: [PATCH] Make power-button-action always power off when chassis=server
Servers often don't support hibernation/suspend.
---
...rg.gnome.settings-daemon.plugins.power.gschema.xml.in | 2 +-
plugins/media-keys/gsd-media-keys-manager.c | 9 ++++++---
2 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
index fc61d133..952104ed 100644
--- a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
+++ b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
@@ -39,7 +39,7 @@
<key name="power-button-action" enum="org.gnome.settings-daemon.GsdPowerButtonActionType">
<default>'suspend'</default>
<summary>Power button action</summary>
- <description>The action to take when the system power button is pressed. Virtual machines only honor the 'nothing' action, and will shutdown otherwise. Tablets always suspend, ignoring all the other action options.</description>
+ <description>The action to take when the system power button is pressed. Virtual machines and servers only honor the 'nothing' action, and will shutdown otherwise. Tablets always suspend, ignoring all the other action options.</description>
</key>
</schema>
</schemalist>
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index ac6f7ab4..46bdade6 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -2083,9 +2083,12 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
if (manager->priv->power_button_disabled)
return;
- action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
- /* Always power off VMs, except when power-button-action is "nothing" */
- if (g_strcmp0 (manager->priv->chassis_type, "vm") == 0) {
+ action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
+ /* Always power off VMs and servers, except when power-button-action is "nothing" */
+ if (g_strcmp0 (manager->priv->chassis_type, "vm") == 0 ||
+ g_strcmp0 (manager->priv->chassis_type, "server")) {
+ g_warning ("Virtual machines and servers only honor the 'nothing' power-button-action, and will shutdown otherwise");
+
if (action_type != GSD_POWER_BUTTON_ACTION_NOTHING)
power_action (manager, "PowerOff", !in_lock_screen);
--
2.37.1

File diff suppressed because it is too large Load Diff

@ -1,125 +0,0 @@
From a8115378fd876bfd4c3871428cdc16134ed484b1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
Date: Tue, 5 Jan 2021 11:11:18 +0100
Subject: [PATCH] media-keys: Mark screen cast as stopped if it was signalled
as such
gnome-shell now sends a 'Stopped' signal if it was stopped without
gsd-media-keys itself being the stopper.
---
plugins/media-keys/gsd-media-keys-manager.c | 52 +++++++++++++++++++--
1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index 4d251f08..a526d5cf 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -210,6 +210,7 @@ struct GsdMediaKeysManagerPrivate
guint screencast_timeout_id;
gboolean screencast_recording;
GCancellable *screencast_cancellable;
+ guint screencast_stopped_signal_id;
/* Rotation */
guint iio_sensor_watch_id;
@@ -2346,20 +2347,26 @@ do_rfkill_action (GsdMediaKeysManager *manager,
}
static void
-screencast_stop (GsdMediaKeysManager *manager)
+screencast_stopped (GsdMediaKeysManager *manager)
{
if (manager->priv->screencast_timeout_id > 0) {
g_source_remove (manager->priv->screencast_timeout_id);
manager->priv->screencast_timeout_id = 0;
}
+ manager->priv->screencast_recording = FALSE;
+}
+
+static void
+screencast_stop (GsdMediaKeysManager *manager)
+{
+ screencast_stopped (manager);
+
g_dbus_proxy_call (manager->priv->screencast_proxy,
"StopScreencast", NULL,
G_DBUS_CALL_FLAGS_NONE, -1,
manager->priv->screencast_cancellable,
NULL, NULL);
-
- manager->priv->screencast_recording = FALSE;
}
static gboolean
@@ -2835,6 +2842,21 @@ initialize_volume_handler (GsdMediaKeysManager *manager)
gnome_settings_profile_end ("gvc_mixer_control_new");
}
+
+static void
+on_screencast_stopped (GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer data)
+{
+ GsdMediaKeysManager *manager = data;
+
+ screencast_stopped (manager);
+}
+
static void
on_screencast_proxy_ready (GObject *source,
GAsyncResult *result,
@@ -2850,7 +2872,20 @@ on_screencast_proxy_ready (GObject *source,
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
g_warning ("Failed to create proxy for screencast: %s", error->message);
g_error_free (error);
+ return;
}
+
+ manager->priv->screencast_stopped_signal_id =
+ g_dbus_connection_signal_subscribe (manager->priv->connection,
+ SHELL_DBUS_NAME ".Screencast",
+ SHELL_DBUS_NAME ".Screencast",
+ "Stopped",
+ SHELL_DBUS_PATH "/Screencast",
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ on_screencast_stopped,
+ manager,
+ NULL);
}
static void
@@ -2901,6 +2936,11 @@ shell_presence_changed (GsdMediaKeysManager *manager)
on_screencast_proxy_ready, manager);
g_free (name_owner);
} else {
+ if (manager->priv->screencast_stopped_signal_id)
+ g_dbus_connection_signal_unsubscribe (manager->priv->connection,
+ manager->priv->screencast_stopped_signal_id);
+ manager->priv->screencast_stopped_signal_id = 0;
+
g_ptr_array_set_size (manager->priv->keys, 0);
g_clear_object (&manager->priv->key_grabber);
g_clear_object (&manager->priv->screencast_proxy);
@@ -3091,6 +3131,12 @@ gsd_media_keys_manager_stop (GsdMediaKeysManager *manager)
priv->reenable_power_button_timer_id = 0;
}
+ if (priv->screencast_stopped_signal_id) {
+ g_dbus_connection_signal_unsubscribe (priv->connection,
+ priv->screencast_stopped_signal_id);
+ priv->screencast_stopped_signal_id = 0;
+ }
+
g_clear_pointer (&manager->priv->ca, ca_context_destroy);
#if HAVE_GUDEV
--
2.27.0

@ -1,34 +0,0 @@
From 77b52a04c9154a7e7b2434f6c70ba6b4fd84c9f1 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Thu, 15 Oct 2020 15:18:35 +0200
Subject: [PATCH] power: Avoid automatic logout in GDM/greeter
In GDM sessions (greeter, initial-setup), it does not make sense to
automatically logout. This can happen if the system wide default is
changed to default to the "logout" action.
Note that we already use the RUNNING_UNDER_GDM environment variable in
the keyboard plugin currently. So doing this is likely sane, even if we
probably want a more elegant strategy to detect whether we are in a
"login" session.
---
plugins/power/gsd-power-manager.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index e103a8a7..b100ff9e 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -872,6 +872,9 @@ static void
gnome_session_logout (GsdPowerManager *manager,
guint logout_mode)
{
+ if (g_getenv("RUNNING_UNDER_GDM"))
+ return;
+
g_dbus_proxy_call (G_DBUS_PROXY (manager->priv->session),
"Logout",
g_variant_new ("(u)", logout_mode),
--
2.26.2

@ -0,0 +1,458 @@
From 8dd4c164f6ce166a5767588bd6fb8e4c3e8e1a09 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Fri, 16 Jul 2021 13:40:10 +0200
Subject: [PATCH 1/4] power: Enable power-saver profile when low on battery
When low on battery, and if the feature is enabled, hold the power
profile to "power-saver" until the battery is sufficiently recharged.
---
...ttings-daemon.plugins.power.gschema.xml.in | 5 +
plugins/power/gsd-power-manager.c | 128 ++++++++++++++++++
plugins/power/test.py | 32 +++++
3 files changed, 165 insertions(+)
diff --git a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
index 93c704e9..04b287bd 100644
--- a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
+++ b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
@@ -41,5 +41,10 @@
<summary>Power button action</summary>
<description>The action to take when the system power button is pressed. This action is hard-coded (and the setting ignored) on virtual machines (power off) and tablets (suspend).</description>
</key>
+ <key name="power-saver-profile-on-low-battery" type="b">
+ <default>true</default>
+ <summary>Enable power-saver profile when battery is low</summary>
+ <description>Automatically enable the "power-saver" profile using power-profiles-daemon if the battery is low.</description>
+ </key>
</schema>
</schemalist>
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 95cec9c3..1f125a6f 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -59,6 +59,10 @@
#define UPOWER_DBUS_INTERFACE "org.freedesktop.UPower"
#define UPOWER_DBUS_INTERFACE_KBDBACKLIGHT "org.freedesktop.UPower.KbdBacklight"
+#define PPD_DBUS_NAME "net.hadess.PowerProfiles"
+#define PPD_DBUS_PATH "/net/hadess/PowerProfiles"
+#define PPD_DBUS_INTERFACE "net.hadess.PowerProfiles"
+
#define GSD_POWER_SETTINGS_SCHEMA "org.gnome.settings-daemon.plugins.power"
#define GSD_POWER_DBUS_NAME GSD_DBUS_NAME ".Power"
@@ -185,6 +189,10 @@ struct _GsdPowerManager
gdouble ambient_last_absolute;
gint64 ambient_last_time;
+ /* Power Profiles */
+ GDBusProxy *power_profiles_proxy;
+ guint32 power_saver_cookie;
+
/* Sound */
guint32 critical_alert_timeout_id;
@@ -1927,6 +1935,67 @@ idle_configure (GsdPowerManager *manager)
}
}
+static void
+hold_profile_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GsdPowerManager *manager = user_data;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GVariant) result = NULL;
+
+ result = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object),
+ res,
+ &error);
+ if (result == NULL) {
+ g_warning ("Couldn't hold power-saver profile: %s", error->message);
+ return;
+ }
+
+ if (g_variant_is_of_type (result, G_VARIANT_TYPE ("(u)"))) {
+ g_variant_get (result, "(u)", &manager->power_saver_cookie);
+ g_debug ("Holding power-saver profile with cookie %u", manager->power_saver_cookie);
+ } else {
+ g_warning ("Calling HoldProfile() did not return a uint32");
+ }
+}
+
+static void
+enable_power_saver (GsdPowerManager *manager)
+{
+ if (!manager->power_profiles_proxy)
+ return;
+ if (!g_settings_get_boolean (manager->settings, "power-saver-profile-on-low-battery"))
+ return;
+
+ g_debug ("Starting hold of power-saver profile");
+
+ g_dbus_proxy_call (manager->power_profiles_proxy,
+ "HoldProfile",
+ g_variant_new("(sss)",
+ "power-saver",
+ "Power saver profile when low on battery",
+ GSD_POWER_DBUS_NAME),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, manager->cancellable, hold_profile_cb, manager);
+}
+
+static void
+disable_power_saver (GsdPowerManager *manager)
+{
+ if (!manager->power_profiles_proxy || manager->power_saver_cookie == 0)
+ return;
+
+ g_debug ("Releasing power-saver profile");
+
+ g_dbus_proxy_call (manager->power_profiles_proxy,
+ "ReleaseProfile",
+ g_variant_new ("(u)", manager->power_saver_cookie),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, dbus_call_log_error, "ReleaseProfile failed");
+ manager->power_saver_cookie = 0;
+}
+
static void
main_battery_or_ups_low_changed (GsdPowerManager *manager,
gboolean is_low)
@@ -1935,6 +2004,10 @@ main_battery_or_ups_low_changed (GsdPowerManager *manager,
return;
manager->battery_is_low = is_low;
idle_configure (manager);
+ if (is_low)
+ enable_power_saver (manager);
+ else
+ disable_power_saver (manager);
}
static gboolean
@@ -2078,6 +2151,39 @@ screensaver_signal_cb (GDBusProxy *proxy,
handle_wake_up_screen (GSD_POWER_MANAGER (user_data));
}
+static void
+power_profiles_proxy_signal_cb (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ GsdPowerManager *manager = GSD_POWER_MANAGER (user_data);
+
+ if (g_strcmp0 (signal_name, "ProfileReleased") != 0)
+ return;
+ manager->power_saver_cookie = 0;
+}
+
+static void
+power_profiles_proxy_ready_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ g_autoptr(GError) error = NULL;
+ GsdPowerManager *manager = GSD_POWER_MANAGER (user_data);
+
+ manager->power_profiles_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
+ if (manager->power_profiles_proxy == NULL) {
+ g_debug ("Could not connect to power-profiles-daemon: %s", error->message);
+ return;
+ }
+
+ g_signal_connect (manager->power_profiles_proxy, "g-signal",
+ G_CALLBACK (power_profiles_proxy_signal_cb),
+ manager);
+}
+
static void
power_keyboard_proxy_ready_cb (GObject *source_object,
GAsyncResult *res,
@@ -2289,6 +2395,14 @@ engine_settings_key_changed_cb (GSettings *settings,
idle_configure (manager);
return;
}
+ if (g_str_equal (key, "power-saver-profile-on-low-battery")) {
+ if (manager->battery_is_low &&
+ g_settings_get_boolean (settings, key))
+ enable_power_saver (manager);
+ else
+ disable_power_saver (manager);
+ return;
+ }
}
static void
@@ -2599,6 +2713,17 @@ on_rr_screen_acquired (GObject *object,
g_signal_connect (manager->up_client, "notify::on-battery",
G_CALLBACK (up_client_on_battery_cb), manager);
+ /* connect to power-profiles-daemon */
+ g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ PPD_DBUS_NAME,
+ PPD_DBUS_PATH,
+ PPD_DBUS_INTERFACE,
+ manager->cancellable,
+ power_profiles_proxy_ready_cb,
+ manager);
+
/* connect to UPower for keyboard backlight control */
manager->kbd_brightness_now = -1;
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
@@ -2862,6 +2987,9 @@ gsd_power_manager_stop (GsdPowerManager *manager)
g_clear_object (&manager->screensaver_proxy);
+ disable_power_saver (manager);
+ g_clear_object (&manager->power_profiles_proxy);
+
play_loop_stop (&manager->critical_alert_timeout_id);
g_clear_object (&manager->idle_monitor);
diff --git a/plugins/power/test.py b/plugins/power/test.py
index bb5861a4..f554400e 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -76,6 +76,13 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
'gnome_screensaver', stdout=subprocess.PIPE)
gsdtestcase.set_nonblock(self.screensaver.stdout)
+ # start mock power-profiles-daemon
+ try:
+ (self.ppd, self.obj_ppd) = self.spawn_server_template('power_profiles_daemon')
+ self.addCleanup(self.stop_process, self.ppd)
+ except ModuleNotFoundError:
+ self.ppd = None
+
self.session_log = OutputChecker()
self.session = subprocess.Popen(['gnome-session', '-f',
'-a', os.path.join(self.workdir, 'autostart'),
@@ -1302,5 +1309,30 @@ class PowerPluginTest8(PowerPluginBase):
self.assertEqual(exc.exception.get_dbus_message(), 'No usable backlight could be found!')
+ def test_power_saver_on_low_battery(self):
+ '''Check that the power-saver profile gets held when low on battery'''
+
+ if not self.ppd:
+ self.skipTest("power-profiles-daemon dbusmock support is not available")
+
+ obj_props = dbus.Interface(self.obj_ppd, dbus.PROPERTIES_IFACE)
+
+ self.set_composite_battery_discharging()
+ time.sleep(0.5)
+ holds = obj_props.Get('net.hadess.PowerProfiles', 'ActiveProfileHolds')
+ self.assertEqual(len(holds), 0)
+
+ self.set_composite_battery_critical()
+ time.sleep(0.5)
+ holds = obj_props.Get('net.hadess.PowerProfiles', 'ActiveProfileHolds')
+ self.assertEqual(len(holds), 1)
+ self.assertEqual(holds[0]['Profile'], 'power-saver')
+ self.assertEqual(holds[0]['ApplicationId'], 'org.gnome.SettingsDaemon.Power')
+
+ self.set_composite_battery_discharging()
+ time.sleep(0.5)
+ holds = obj_props.Get('net.hadess.PowerProfiles', 'ActiveProfileHolds')
+ self.assertEqual(len(holds), 0)
+
# avoid writing to stderr
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))
--
2.31.1
From 74ed476d1a37a43eeba8c8bee8f5be5d499b0805 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 28 Jul 2021 16:40:24 +0200
Subject: [PATCH 2/4] power: Dim screen faster if power saver mode is on
As done on other platforms, aggressively dim the screen after a
short period when the user has selected to enter power saver mode.
The same aggressive screen dim will be used if the battery is low and
power-profiles-daemon is not available. If it is available, then it
fixes a screen dim happening when the battery was low which might
have been unwanted.
See https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/232
Prior art:
https://support.apple.com/en-us/HT205234
---
plugins/power/gsd-power-manager.c | 46 +++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 1f125a6f..cfef9718 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -192,6 +192,7 @@ struct _GsdPowerManager
/* Power Profiles */
GDBusProxy *power_profiles_proxy;
guint32 power_saver_cookie;
+ gboolean power_saver_enabled;
/* Sound */
guint32 critical_alert_timeout_id;
@@ -1780,6 +1781,20 @@ clear_idle_watch (GnomeIdleMonitor *monitor,
*id = 0;
}
+static gboolean
+is_power_save_active (GsdPowerManager *manager)
+{
+ /*
+ * If we have power-profiles-daemon, then we follow its setting,
+ * otherwise we go into power-save mode when the battery is low.
+ */
+ if (manager->power_profiles_proxy &&
+ g_dbus_proxy_get_name_owner (manager->power_profiles_proxy))
+ return manager->power_saver_enabled;
+ else
+ return manager->battery_is_low;
+}
+
static void
idle_configure (GsdPowerManager *manager)
{
@@ -1903,8 +1918,8 @@ idle_configure (GsdPowerManager *manager)
/* Don't dim when the screen lock is active */
} else if (!on_battery) {
/* Don't dim when charging */
- } else if (manager->battery_is_low) {
- /* Aggressively blank when battery is low */
+ } else if (is_power_save_active (manager)) {
+ /* Try to save power by dimming agressively */
timeout_dim = SCREENSAVER_TIMEOUT_BLANK;
} else {
if (g_settings_get_boolean (manager->settings, "idle-dim")) {
@@ -2165,6 +2180,27 @@ power_profiles_proxy_signal_cb (GDBusProxy *proxy,
manager->power_saver_cookie = 0;
}
+static void
+update_active_power_profile (GsdPowerManager *manager)
+{
+ g_autoptr(GVariant) v = NULL;
+ const char *active_profile;
+ gboolean power_saver_enabled;
+
+ v = g_dbus_proxy_get_cached_property (manager->power_profiles_proxy, "ActiveProfile");
+ if (v) {
+ active_profile = g_variant_get_string (v, NULL);
+ power_saver_enabled = g_strcmp0 (active_profile, "power-saver") == 0;
+ if (power_saver_enabled != manager->power_saver_enabled) {
+ manager->power_saver_enabled = power_saver_enabled;
+ idle_configure (manager);
+ }
+ } else {
+ /* p-p-d might have disappeared from the bus */
+ idle_configure (manager);
+ }
+}
+
static void
power_profiles_proxy_ready_cb (GObject *source_object,
GAsyncResult *res,
@@ -2179,9 +2215,15 @@ power_profiles_proxy_ready_cb (GObject *source_object,
return;
}
+ g_signal_connect_swapped (manager->power_profiles_proxy,
+ "g-properties-changed",
+ G_CALLBACK (update_active_power_profile),
+ manager);
g_signal_connect (manager->power_profiles_proxy, "g-signal",
G_CALLBACK (power_profiles_proxy_signal_cb),
manager);
+
+ update_active_power_profile (manager);
}
static void
--
2.31.1
From 89e25ed7871258aa6df7f824e226a7b8a28f23f3 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Thu, 29 Jul 2021 12:05:40 +0200
Subject: [PATCH 3/4] power: Respect dim screen settings when not on battery
The dim screen settings in the UI was not well respected as it only
worked on discharging laptops.
Closes: https://gitlab.gnome.org/GNOME/gnome-control-center/-/issues/837
---
plugins/power/gsd-power-manager.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index cfef9718..e7b9752f 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -1916,8 +1916,6 @@ idle_configure (GsdPowerManager *manager)
timeout_dim = 0;
if (manager->screensaver_active) {
/* Don't dim when the screen lock is active */
- } else if (!on_battery) {
- /* Don't dim when charging */
} else if (is_power_save_active (manager)) {
/* Try to save power by dimming agressively */
timeout_dim = SCREENSAVER_TIMEOUT_BLANK;
--
2.31.1
From f91abc0033b9cf17fd0e171cb7d652f88edac294 Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Mon, 9 Aug 2021 17:57:11 +0200
Subject: [PATCH 4/4] power: When dimming the screen, dim it quicker by default
Now that we respect the "dim when idle" setting[1], dim quicker to try
and save more power. 4/5 of the timeout to the screensaver was always a
bit too undecided as a fraction, even when using the dimming as a
warning that the screen was going to go to the screensaver (see commit
7bc750a5).
[1]: Except in power-saver mode where we always dim aggressively
---
plugins/power/gsd-power-constants.h | 2 +-
plugins/power/gsdpowerconstants.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/plugins/power/gsd-power-constants.h b/plugins/power/gsd-power-constants.h
index 91e2296a..8bf9c641 100644
--- a/plugins/power/gsd-power-constants.h
+++ b/plugins/power/gsd-power-constants.h
@@ -25,7 +25,7 @@
#define IDLE_DIM_BLANK_DISABLED_MIN 60 /* seconds */
/* Which fraction of the idle-delay is the idle-dim delay */
-#define IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER 4.0/5.0
+#define IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER 1.0/2.0
/* The dim delay under which we do not bother dimming */
#define MINIMUM_IDLE_DIM_DELAY 10 /* seconds */
diff --git a/plugins/power/gsdpowerconstants.py b/plugins/power/gsdpowerconstants.py
index a07798ee..26fa5bfc 100644
--- a/plugins/power/gsdpowerconstants.py
+++ b/plugins/power/gsdpowerconstants.py
@@ -8,7 +8,7 @@
SCREENSAVER_TIMEOUT_BLANK = 15;
IDLE_DIM_BLANK_DISABLED_MIN = 60;
-IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER = 4.0/5.0;
+IDLE_DELAY_TO_IDLE_DIM_MULTIPLIER = 1.0/2.0;
MINIMUM_IDLE_DIM_DELAY = 10;
POWER_UP_TIME_ON_AC = 15;
GSD_MOCK_DEFAULT_BRIGHTNESS = 50;
--
2.31.1

@ -1,53 +0,0 @@
From fbe9b7dba44cb284f649a1e916b2cf3ce8281211 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Tue, 7 May 2019 15:40:20 +0200
Subject: [PATCH] power: Only disable Suspend/Hibernate actions inside VM
While we theoretically only want a different default value inside a VM,
we currently hack this by never doing a suspend action inside VMs.
However, that also breaks automatic logout, which is an unintended side
effect.
Move the check to not install the corresponding timeout (preventing
sleep warnings from being displayed) and also only enforce the VM
specific hack for the Suspend and Hibernate actions.
---
plugins/power/gsd-power-manager.c | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index f965f6f..dbaa262 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -1520,13 +1520,6 @@ idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode)
return;
}
- /* don't do any power saving if we're a VM */
- if (manager->priv->is_virtual_machine) {
- g_debug ("ignoring state transition to %s as virtual machine",
- idle_mode_to_string (mode));
- return;
- }
-
manager->priv->current_idle_mode = mode;
g_debug ("Doing a state transition: %s", idle_mode_to_string (mode));
@@ -1727,6 +1720,14 @@ idle_configure (GsdPowerManager *manager)
clear_idle_watch (manager->priv->idle_monitor,
&manager->priv->idle_sleep_warning_id);
+ /* don't do any power saving if we're a VM */
+ if (manager->priv->is_virtual_machine &&
+ (action_type == GSD_POWER_ACTION_SUSPEND ||
+ action_type == GSD_POWER_ACTION_HIBERNATE)) {
+ g_debug ("Ignoring sleep timeout with suspend action inside VM");
+ timeout_sleep = 0;
+ }
+
if (timeout_sleep != 0) {
g_debug ("setting up sleep callback %is", timeout_sleep);
--
2.31.1

@ -1,6 +1,6 @@
From 0e2c4aec104b65d2f8ea7167269e91c303908a6f Mon Sep 17 00:00:00 2001
From f71fb47c3f783f3405bd910e1e170dc5e1f10e7c Mon Sep 17 00:00:00 2001
From: Felipe Borges <felipeborges@gnome.org>
Date: Wed, 4 Jan 2023 15:30:15 +0100
Date: Wed, 4 Jan 2023 13:41:31 +0100
Subject: [PATCH] power: Respect the "nothing" power-button-action for VMs
There are use-cases when one wants to forcefully make the guest ignore
@ -10,12 +10,12 @@ See https://bugzilla.redhat.com/2062051
See also https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/46
---
...org.gnome.settings-daemon.plugins.power.gschema.xml.in | 2 +-
plugins/media-keys/gsd-media-keys-manager.c | 8 +++++---
2 files changed, 6 insertions(+), 4 deletions(-)
....gnome.settings-daemon.plugins.power.gschema.xml.in | 2 +-
plugins/media-keys/gsd-media-keys-manager.c | 10 +++++++---
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
index 93c704e9..fc61d133 100644
index 04b287bd..e1a8787b 100644
--- a/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
+++ b/data/org.gnome.settings-daemon.plugins.power.gschema.xml.in
@@ -39,7 +39,7 @@
@ -25,32 +25,30 @@ index 93c704e9..fc61d133 100644
- <description>The action to take when the system power button is pressed. This action is hard-coded (and the setting ignored) on virtual machines (power off) and tablets (suspend).</description>
+ <description>The action to take when the system power button is pressed. Virtual machines only honor the 'nothing' action, and will shutdown otherwise. Tablets always suspend, ignoring all the other action options.</description>
</key>
</schema>
</schemalist>
<key name="power-saver-profile-on-low-battery" type="b">
<default>true</default>
diff --git a/plugins/media-keys/gsd-media-keys-manager.c b/plugins/media-keys/gsd-media-keys-manager.c
index a526d5cf..ac6f7ab4 100644
index 15e96e0e..60ff2ced 100644
--- a/plugins/media-keys/gsd-media-keys-manager.c
+++ b/plugins/media-keys/gsd-media-keys-manager.c
@@ -2083,9 +2083,12 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
if (manager->priv->power_button_disabled)
@@ -2041,13 +2041,17 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
if (priv->power_button_disabled)
return;
- /* Always power off VMs when power off is pressed in the menus */
+ action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
+ action_type = g_settings_get_enum (priv->power_settings, "power-button-action");
+ /* Always power off VMs, except when power-button-action is "nothing" */
if (g_strcmp0 (manager->priv->chassis_type, "vm") == 0) {
if (g_strcmp0 (priv->chassis_type, "vm") == 0) {
- power_action (manager, "PowerOff", !in_lock_screen);
+ g_warning_once ("Virtual machines only honor the 'nothing' power-button-action, and will shutdown otherwise");
+
+ if (action_type != GSD_POWER_BUTTON_ACTION_NOTHING)
+ power_action (manager, "PowerOff", !in_lock_screen);
+ power_action (manager, "PowerOff", FALSE);
+
return;
}
@@ -2095,7 +2098,6 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
return;
}
- action_type = g_settings_get_enum (manager->priv->power_settings, "power-button-action");
- action_type = g_settings_get_enum (priv->power_settings, "power-button-action");
switch (action_type) {
case GSD_POWER_BUTTON_ACTION_SUSPEND:
action = GSD_POWER_ACTION_SUSPEND;

@ -1,58 +0,0 @@
From a1c2685bc6b255f22b6ce4645c001d428cb67907 Mon Sep 17 00:00:00 2001
From: Marek Kasik <mkasik@redhat.com>
Date: Wed, 22 May 2019 14:56:42 +0200
Subject: [PATCH] smartcard: Cancel cancellable when stopping
self->cancellable in GsdSmartcardManager is not cancelled
at gsd_smartcard_manager_stop() and hence some callbacks are
still called after unload_nss() which clears SECMODListLock
which is used by SECMOD_GetReadLock() / SECMOD_ReleaseReadLock().
This leads to crashes in NSSRWLock_LockRead_Util() and
NSSRWLock_UnlockRead_Util() probably.
Also check for return value of g_cancellable_connect()
and initialize pointer to PK11SlotInfo.
See https://bugzilla.redhat.com/show_bug.cgi?id=1646359,
https://bugzilla.redhat.com/show_bug.cgi?id=1688791 and
their duplicates for additional info.
---
plugins/smartcard/gsd-smartcard-manager.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletion(-)
diff --git a/plugins/smartcard/gsd-smartcard-manager.c b/plugins/smartcard/gsd-smartcard-manager.c
index 014c17be..da1e0d6d 100644
--- a/plugins/smartcard/gsd-smartcard-manager.c
+++ b/plugins/smartcard/gsd-smartcard-manager.c
@@ -184,7 +184,7 @@
GError **error)
{
GsdSmartcardManagerPrivate *priv = self->priv;
- PK11SlotInfo *card, *old_card;
+ PK11SlotInfo *card = NULL, *old_card;
CK_SLOT_ID slot_id;
gulong handler_id;
int old_slot_series = -1, slot_series;
@@ -190,7 +190,8 @@ watch_one_event_from_driver (GsdSmartcardManager *self,
operation,
NULL);
- card = SECMOD_WaitForAnyTokenEvent (operation->driver, 0, PR_SecondsToInterval (1));
+ if (handler_id != 0)
+ card = SECMOD_WaitForAnyTokenEvent (operation->driver, 0, PR_SecondsToInterval (1));
g_cancellable_disconnect (cancellable, handler_id);
@@ -773,6 +774,8 @@ gsd_smartcard_manager_stop (GsdSmartcardManager *self)
g_debug ("Stopping smartcard manager");
+ g_cancellable_cancel (priv->cancellable);
+
unload_nss (self);
g_clear_object (&priv->settings);
--
2.23.0

@ -1,25 +0,0 @@
From 6e790966c2b6e1db8dd2c145119d3fdd19e0c18f Mon Sep 17 00:00:00 2001
From: Matthias Clasen <mclasen@redhat.com>
Date: Wed, 22 May 2019 16:04:42 -0400
Subject: [PATCH] xsettings: Add an entry for the overlay scrolling setting
This will be used by GTK.
---
plugins/xsettings/gsd-xsettings-manager.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/plugins/xsettings/gsd-xsettings-manager.c b/plugins/xsettings/gsd-xsettings-manager.c
index c3ac7892..4164de40 100644
--- a/plugins/xsettings/gsd-xsettings-manager.c
+++ b/plugins/xsettings/gsd-xsettings-manager.c
@@ -478,6 +478,7 @@ static TranslationEntry translations [] = {
{ "org.gnome.desktop.interface", "icon-theme", "Net/IconThemeName", translate_string_string },
{ "org.gnome.desktop.interface", "cursor-theme", "Gtk/CursorThemeName", translate_string_string },
{ "org.gnome.desktop.interface", "gtk-enable-primary-paste", "Gtk/EnablePrimaryPaste", translate_bool_int },
+ { "org.gnome.desktop.interface", "overlay-scrolling", "Gtk/OverlayScrolling", translate_bool_int },
/* cursor-size is handled via the Xft side as it needs the scaling factor */
{ "org.gnome.desktop.sound", "theme-name", "Net/SoundThemeName", translate_string_string },
--
2.23.0

@ -1,271 +0,0 @@
From ad0fd6c905011b7bb9eac9fa8cb91f58d71e4a29 Mon Sep 17 00:00:00 2001
From: Ray Strode <rstrode@redhat.com>
Date: Mon, 6 Nov 2017 15:49:58 -0500
Subject: [PATCH 2/4] account: reshow the notification when screen unlocks
---
plugins/account/gsd-account-manager.c | 48 ++++++++++++++++++++++++---
1 file changed, 43 insertions(+), 5 deletions(-)
diff --git a/plugins/account/gsd-account-manager.c b/plugins/account/gsd-account-manager.c
index 40b91cb6..cb37f466 100644
--- a/plugins/account/gsd-account-manager.c
+++ b/plugins/account/gsd-account-manager.c
@@ -11,72 +11,75 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <locale.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <glib/gstdio.h>
#include <cups/cups.h>
#include <cups/ppd.h>
#include <libnotify/notify.h>
#include "gnome-settings-profile.h"
+#include "gnome-settings-bus.h"
#include "gsd-account-manager.h"
#include "org.freedesktop.Accounts.h"
#include "org.freedesktop.Accounts.User.h"
#define GSD_ACCOUNT_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_ACCOUNT_MANAGER, GsdAccountManagerPrivate))
struct GsdAccountManagerPrivate
{
GsdAccounts *accounts_proxy;
GsdAccountsUser *accounts_user_proxy;
GCancellable *cancellable;
+ GsdScreenSaver *screensaver_proxy;
+
gint64 expiration_time;
gint64 last_change_time;
gint64 min_days_between_changes;
gint64 max_days_between_changes;
gint64 days_to_warn;
gint64 days_after_expiration_until_lock;
NotifyNotification *notification;
};
static void gsd_account_manager_class_init (GsdAccountManagerClass *klass);
static void gsd_account_manager_init (GsdAccountManager *account_manager);
static void gsd_account_manager_finalize (GObject *object);
G_DEFINE_TYPE (GsdAccountManager, gsd_account_manager, G_TYPE_OBJECT)
static gpointer manager_object = NULL;
static void
on_notification_closed (NotifyNotification *notification,
gpointer user_data)
{
GsdAccountManager *manager = user_data;
g_clear_object (&manager->priv->notification);
}
static void
hide_notification (GsdAccountManager *manager)
{
@@ -221,77 +224,111 @@ on_got_password_expiration_policy (GsdAccountsUser *accounts_user_proxy,
gint64 days_after_expiration_until_lock;
gnome_settings_profile_start (NULL);
succeeded = gsd_accounts_user_call_get_password_expiration_policy_finish (accounts_user_proxy,
&expiration_time,
&last_change_time,
&min_days_between_changes,
&max_days_between_changes,
&days_to_warn,
&days_after_expiration_until_lock,
res,
&error);
if (!succeeded) {
g_warning ("Failed to get password expiration policy for user: %s", error->message);
goto out;
}
set_policy_number (&manager->priv->expiration_time, expiration_time);
set_policy_number (&manager->priv->last_change_time, last_change_time);
set_policy_number (&manager->priv->min_days_between_changes, min_days_between_changes);
set_policy_number (&manager->priv->max_days_between_changes, max_days_between_changes);
set_policy_number (&manager->priv->days_to_warn, days_to_warn);
set_policy_number (&manager->priv->days_after_expiration_until_lock, days_after_expiration_until_lock);
update_password_notification (manager);
out:
gnome_settings_profile_end (NULL);
}
+static void
+fetch_password_expiration_policy (GsdAccountManager *manager)
+{
+ gsd_accounts_user_call_get_password_expiration_policy (manager->priv->accounts_user_proxy,
+ manager->priv->cancellable,
+ (GAsyncReadyCallback)
+ on_got_password_expiration_policy,
+ manager);
+}
+
+static void
+on_screensaver_signal (GDBusProxy *proxy,
+ const gchar *sender_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ GsdAccountManager *manager = user_data;
+
+ if (g_strcmp0 (signal_name, "ActiveChanged") == 0) {
+ gboolean active;
+
+ g_variant_get (parameters, "(b)", &active);
+
+ if (!active) {
+ fetch_password_expiration_policy (manager);
+ }
+ }
+}
+
static void
on_got_accounts_user_proxy (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
GsdAccountManager *manager = user_data;
g_autoptr(GError) error = NULL;
gnome_settings_profile_start (NULL);
manager->priv->accounts_user_proxy = gsd_accounts_user_proxy_new_finish (res, &error);
if (manager->priv->accounts_user_proxy != NULL) {
- gsd_accounts_user_call_get_password_expiration_policy (manager->priv->accounts_user_proxy,
- manager->priv->cancellable,
- (GAsyncReadyCallback)
- on_got_password_expiration_policy,
- manager);
+ fetch_password_expiration_policy (manager);
+
+ manager->priv->screensaver_proxy = gnome_settings_bus_get_screen_saver_proxy ();
+
+ g_signal_connect (manager->priv->screensaver_proxy,
+ "g-signal",
+ G_CALLBACK (on_screensaver_signal),
+ manager);
+
} else {
g_warning ("Failed to get user proxy to accounts service: %s", error->message);
goto out;
}
out:
gnome_settings_profile_end (NULL);
}
static void
on_got_user_object_path (GsdAccounts *accounts_proxy,
GAsyncResult *res,
gpointer user_data)
{
GsdAccountManager *manager = user_data;
g_autoptr(GError) error = NULL;
gboolean succeeded;
gchar *object_path;
GDBusConnection *connection;
gnome_settings_profile_start (NULL);
succeeded = gsd_accounts_call_find_user_by_id_finish (accounts_proxy,
&object_path,
res,
&error);
if (!succeeded) {
g_warning ("Unable to find current user in accounts service: %s",
error->message);
@@ -343,60 +380,61 @@ gsd_account_manager_start (GsdAccountManager *manager,
g_debug ("Starting accounts manager");
gnome_settings_profile_start (NULL);
manager->priv->cancellable = g_cancellable_new ();
gsd_accounts_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
G_DBUS_PROXY_FLAGS_NONE,
"org.freedesktop.Accounts",
"/org/freedesktop/Accounts",
manager->priv->cancellable,
(GAsyncReadyCallback)
on_got_accounts_proxy,
manager);
gnome_settings_profile_end (NULL);
return TRUE;
}
void
gsd_account_manager_stop (GsdAccountManager *manager)
{
g_debug ("Stopping accounts manager");
if (manager->priv->cancellable != NULL) {
g_cancellable_cancel (manager->priv->cancellable);
g_clear_object (&manager->priv->cancellable);
}
g_clear_object (&manager->priv->accounts_proxy);
g_clear_object (&manager->priv->accounts_user_proxy);
g_clear_object (&manager->priv->notification);
+ g_clear_object (&manager->priv->screensaver_proxy);
}
static void
gsd_account_manager_class_init (GsdAccountManagerClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gsd_account_manager_finalize;
notify_init ("gnome-settings-daemon");
g_type_class_add_private (klass, sizeof (GsdAccountManagerPrivate));
}
static void
gsd_account_manager_init (GsdAccountManager *manager)
{
manager->priv = GSD_ACCOUNT_MANAGER_GET_PRIVATE (manager);
}
static void
gsd_account_manager_finalize (GObject *object)
{
GsdAccountManager *manager;
g_return_if_fail (object != NULL);
g_return_if_fail (GSD_IS_ACCOUNT_MANAGER (object));
manager = GSD_ACCOUNT_MANAGER (object);
--
2.21.0

@ -1,49 +0,0 @@
From f2cd5fb30892e3868732fca1d38fc15fdb73ec18 Mon Sep 17 00:00:00 2001
From: Benjamin Berg <bberg@redhat.com>
Date: Tue, 27 Oct 2020 10:20:34 +0100
Subject: [PATCH 2/2] power: Never register sleep timeout for logout in GDM
We already suppress logout actions in GDM (10aa1714b05b, power: Avoid
automatic logout in GDM/greeter). However, while this prevents the
action, we may still warn.
Change it so that the corresponding timeouts will never be registered.
Leave the guard in gnome_session_logout but add a warning as we should
never be hitting that code path.
---
plugins/power/gsd-power-manager.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 9f2e858e..ed855b6b 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -872,8 +872,10 @@ static void
gnome_session_logout (GsdPowerManager *manager,
guint logout_mode)
{
- if (g_getenv("RUNNING_UNDER_GDM"))
+ if (g_getenv ("RUNNING_UNDER_GDM")) {
+ g_warning ("Prevented logout from GDM session! This indicates an issue in gsd-power.");
return;
+ }
g_dbus_proxy_call (G_DBUS_PROXY (manager->priv->session),
"Logout",
@@ -1773,6 +1775,13 @@ idle_configure (GsdPowerManager *manager)
timeout_sleep = 0;
}
+ /* don't do any automatic logout if we are in GDM */
+ if (g_getenv ("RUNNING_UNDER_GDM") &&
+ (action_type == GSD_POWER_ACTION_LOGOUT)) {
+ g_debug ("Ignoring sleep timeout with logout action inside GDM");
+ timeout_sleep = 0;
+ }
+
if (timeout_sleep != 0) {
g_debug ("setting up sleep callback %is", timeout_sleep);
--
2.26.2

@ -1,768 +0,0 @@
From f723ed1078e050c4d966d40b2aea74970c74279c Mon Sep 17 00:00:00 2001
From: Kalev Lember <klember@redhat.com>
Date: Thu, 27 Jun 2019 16:12:00 +0200
Subject: [PATCH 02/15] subman: Add InstalledProducts dbus property for g-c-c
---
plugins/subman/gsd-subscription-manager.c | 135 ++++++++++++++++++++++
1 file changed, 135 insertions(+)
diff --git a/plugins/subman/gsd-subscription-manager.c b/plugins/subman/gsd-subscription-manager.c
index 08b13fa6..a8c18a26 100644
--- a/plugins/subman/gsd-subscription-manager.c
+++ b/plugins/subman/gsd-subscription-manager.c
@@ -1,186 +1,304 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
*
* Copyright (C) 2019 Richard Hughes <richard@hughsie.com>
+ * Copyright (C) 2019 Kalev Lember <klember@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <json-glib/json-glib.h>
#include <libnotify/notify.h>
#include "gnome-settings-profile.h"
#include "gsd-subman-common.h"
#include "gsd-subscription-manager.h"
#define GSD_DBUS_NAME "org.gnome.SettingsDaemon"
#define GSD_DBUS_PATH "/org/gnome/SettingsDaemon"
#define GSD_DBUS_BASE_INTERFACE "org.gnome.SettingsDaemon"
#define GSD_SUBSCRIPTION_DBUS_NAME GSD_DBUS_NAME ".Subscription"
#define GSD_SUBSCRIPTION_DBUS_PATH GSD_DBUS_PATH "/Subscription"
#define GSD_SUBSCRIPTION_DBUS_INTERFACE GSD_DBUS_BASE_INTERFACE ".Subscription"
static const gchar introspection_xml[] =
"<node>"
" <interface name='org.gnome.SettingsDaemon.Subscription'>"
" <method name='Register'>"
" <arg type='a{sv}' name='options' direction='in'/>"
" </method>"
" <method name='Unregister'/>"
+" <property name='InstalledProducts' type='aa{sv}' access='read'/>"
" <property name='SubscriptionStatus' type='u' access='read'/>"
" </interface>"
"</node>";
#define GSD_SUBSCRIPTION_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_SUBSCRIPTION_MANAGER, GsdSubscriptionManagerPrivate))
typedef enum {
_RHSM_INTERFACE_CONFIG,
_RHSM_INTERFACE_REGISTER_SERVER,
_RHSM_INTERFACE_ATTACH,
_RHSM_INTERFACE_ENTITLEMENT,
_RHSM_INTERFACE_PRODUCTS,
_RHSM_INTERFACE_CONSUMER,
_RHSM_INTERFACE_SYSPURPOSE,
_RHSM_INTERFACE_LAST
} _RhsmInterface;
struct GsdSubscriptionManagerPrivate
{
/* D-Bus */
guint name_id;
GDBusNodeInfo *introspection_data;
GDBusConnection *connection;
GCancellable *bus_cancellable;
GDBusProxy *proxies[_RHSM_INTERFACE_LAST];
const gchar *userlang; /* owned by GLib internally */
GHashTable *config; /* str:str */
+ GPtrArray *installed_products;
gchar *address;
GTimer *timer_last_notified;
NotifyNotification *notification_expired;
NotifyNotification *notification_registered;
NotifyNotification *notification_registration_required;
GsdSubmanSubscriptionStatus subscription_status;
GsdSubmanSubscriptionStatus subscription_status_last;
};
enum {
PROP_0,
};
static void gsd_subscription_manager_class_init (GsdSubscriptionManagerClass *klass);
static void gsd_subscription_manager_init (GsdSubscriptionManager *subscription_manager);
static void gsd_subscription_manager_finalize (GObject *object);
G_DEFINE_TYPE (GsdSubscriptionManager, gsd_subscription_manager, G_TYPE_OBJECT)
+typedef struct
+{
+ gchar *product_name;
+ gchar *product_id;
+ gchar *version;
+ gchar *arch;
+ gchar *status;
+ gchar *starts;
+ gchar *ends;
+} ProductData;
+
+static void
+product_data_free (ProductData *product)
+{
+ g_free (product->product_name);
+ g_free (product->product_id);
+ g_free (product->version);
+ g_free (product->arch);
+ g_free (product->status);
+ g_free (product->starts);
+ g_free (product->ends);
+ g_free (product);
+}
+
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (ProductData, product_data_free);
+
static gpointer manager_object = NULL;
GQuark
gsd_subscription_manager_error_quark (void)
{
static GQuark quark = 0;
if (!quark)
quark = g_quark_from_static_string ("gsd_subscription_manager_error");
return quark;
}
static GsdSubmanSubscriptionStatus
_client_subscription_status_from_text (const gchar *status_txt)
{
if (g_strcmp0 (status_txt, "Unknown") == 0)
return GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
if (g_strcmp0 (status_txt, "Current") == 0)
return GSD_SUBMAN_SUBSCRIPTION_STATUS_VALID;
if (g_strcmp0 (status_txt, "Invalid") == 0)
return GSD_SUBMAN_SUBSCRIPTION_STATUS_INVALID;
if (g_strcmp0 (status_txt, "Disabled") == 0)
return GSD_SUBMAN_SUBSCRIPTION_STATUS_DISABLED;
if (g_strcmp0 (status_txt, "Insufficient") == 0)
return GSD_SUBMAN_SUBSCRIPTION_STATUS_PARTIALLY_VALID;
g_warning ("Unknown subscription status: %s", status_txt); // 'Current'?
return GSD_SUBMAN_SUBSCRIPTION_STATUS_UNKNOWN;
}
+static GVariant *
+_make_installed_products_variant (GPtrArray *installed_products)
+{
+ GVariantBuilder builder;
+ g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
+
+ for (guint i = 0; i < installed_products->len; i++) {
+ ProductData *product = g_ptr_array_index (installed_products, i);
+ g_auto(GVariantDict) dict;
+
+ g_variant_dict_init (&dict, NULL);
+
+ g_variant_dict_insert (&dict, "product-name", "s", product->product_name);
+ g_variant_dict_insert (&dict, "product-id", "s", product->product_id);
+ g_variant_dict_insert (&dict, "version", "s", product->version);
+ g_variant_dict_insert (&dict, "arch", "s", product->arch);
+ g_variant_dict_insert (&dict, "status", "s", product->status);
+ g_variant_dict_insert (&dict, "starts", "s", product->starts);
+ g_variant_dict_insert (&dict, "ends", "s", product->ends);
+
+ g_variant_builder_add_value (&builder, g_variant_dict_end (&dict));
+ }
+
+ return g_variant_builder_end (&builder);
+}
+
static void
_emit_property_changed (GsdSubscriptionManager *manager,
const gchar *property_name,
GVariant *property_value)
{
GsdSubscriptionManagerPrivate *priv = manager->priv;
GVariantBuilder builder;
GVariantBuilder invalidated_builder;
/* not yet connected */
if (priv->connection == NULL)
return;
/* build the dict */
g_variant_builder_init (&invalidated_builder, G_VARIANT_TYPE ("as"));
g_variant_builder_init (&builder, G_VARIANT_TYPE_ARRAY);
g_variant_builder_add (&builder,
"{sv}",
property_name,
property_value);
g_dbus_connection_emit_signal (priv->connection,
NULL,
GSD_SUBSCRIPTION_DBUS_PATH,
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
g_variant_new ("(sa{sv}as)",
GSD_SUBSCRIPTION_DBUS_INTERFACE,
&builder,
&invalidated_builder),
NULL);
g_variant_builder_clear (&builder);
g_variant_builder_clear (&invalidated_builder);
}
+static gboolean
+_client_installed_products_update (GsdSubscriptionManager *manager, GError **error)
+{
+ GsdSubscriptionManagerPrivate *priv = manager->priv;
+ JsonNode *json_root;
+ JsonArray *json_products_array;
+ const gchar *json_txt = NULL;
+ g_autoptr(GVariant) val = NULL;
+ g_autoptr(JsonParser) json_parser = json_parser_new ();
+
+ val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_PRODUCTS],
+ "ListInstalledProducts",
+ g_variant_new ("(sa{sv}s)",
+ "" /* filter_string */,
+ NULL /* proxy_options */,
+ priv->userlang),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, error);
+ if (val == NULL)
+ return FALSE;
+ g_variant_get (val, "(&s)", &json_txt);
+ g_debug ("Products.ListInstalledProducts JSON: %s", json_txt);
+ if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
+ return FALSE;
+ json_root = json_parser_get_root (json_parser);
+ json_products_array = json_node_get_array (json_root);
+ if (json_products_array == NULL) {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA,
+ "no InstalledProducts array in %s", json_txt);
+ return FALSE;
+ }
+
+ g_ptr_array_set_size (priv->installed_products, 0);
+
+ for (guint i = 0; i < json_array_get_length (json_products_array); i++) {
+ JsonArray *json_product = json_array_get_array_element (json_products_array, i);
+ g_autoptr(ProductData) product = g_new0 (ProductData, 1);
+
+ if (json_product == NULL)
+ continue;
+ if (json_array_get_length (json_product) < 8) {
+ g_debug ("Unexpected number of array elements in InstalledProducts JSON");
+ continue;
+ }
+
+ product->product_name = g_strdup (json_array_get_string_element (json_product, 0));
+ product->product_id = g_strdup (json_array_get_string_element (json_product, 1));
+ product->version = g_strdup (json_array_get_string_element (json_product, 2));
+ product->arch = g_strdup (json_array_get_string_element (json_product, 3));
+ product->status = g_strdup (json_array_get_string_element (json_product, 4));
+ product->starts = g_strdup (json_array_get_string_element (json_product, 6));
+ product->ends = g_strdup (json_array_get_string_element (json_product, 7));
+
+ g_ptr_array_add (priv->installed_products, g_steal_pointer (&product));
+ }
+
+ /* emit notification for g-c-c */
+ _emit_property_changed (manager, "InstalledProducts",
+ _make_installed_products_variant (priv->installed_products));
+
+ return TRUE;
+}
+
static gboolean
_client_subscription_status_update (GsdSubscriptionManager *manager, GError **error)
{
GsdSubscriptionManagerPrivate *priv = manager->priv;
JsonNode *json_root;
JsonObject *json_obj;
const gchar *json_txt = NULL;
const gchar *status_txt = NULL;
g_autoptr(GVariant) val = NULL;
g_autoptr(JsonParser) json_parser = json_parser_new ();
/* save old value */
priv->subscription_status_last = priv->subscription_status;
val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_ENTITLEMENT],
"GetStatus",
g_variant_new ("(ss)",
"", /* assumed as 'now' */
priv->userlang),
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, error);
if (val == NULL)
return FALSE;
g_variant_get (val, "(&s)", &json_txt);
g_debug ("Entitlement.GetStatus JSON: %s", json_txt);
if (!json_parser_load_from_data (json_parser, json_txt, -1, error))
return FALSE;
json_root = json_parser_get_root (json_parser);
json_obj = json_node_get_object (json_root);
if (!json_object_has_member (json_obj, "status")) {
@@ -423,185 +541,195 @@ _client_register_with_keys (GsdSubscriptionManager *manager,
GError **error)
{
GsdSubscriptionManagerPrivate *priv = manager->priv;
g_autoptr(GSubprocess) subprocess = NULL;
/* apparently: "we can't send registration credentials over the regular
* system or session bus since those aren't really locked down..." */
if (!_client_register_start (manager, error))
return FALSE;
g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
"pkexec", LIBEXECDIR "/gsd-subman-helper",
"--kind", "register-with-key",
"--address", priv->address,
"--hostname", hostname,
"--organisation", organisation,
"--activation-key", activation_key,
NULL);
if (subprocess == NULL) {
g_prefix_error (error, "failed to find pkexec: ");
return FALSE;
}
if (!_client_subprocess_wait_check (subprocess, error))
return FALSE;
/* FIXME: also do on error? */
if (!_client_register_stop (manager, error))
return FALSE;
if (!_client_subscription_status_update (manager, error))
return FALSE;
+ if (!_client_installed_products_update (manager, error))
+ return FALSE;
_client_maybe__show_notification (manager);
/* success */
return TRUE;
}
static gboolean
_client_register (GsdSubscriptionManager *manager,
const gchar *hostname,
const gchar *organisation,
const gchar *username,
const gchar *password,
GError **error)
{
GsdSubscriptionManagerPrivate *priv = manager->priv;
g_autoptr(GSubprocess) subprocess = NULL;
/* fallback */
if (organisation == NULL)
organisation = "";
/* apparently: "we can't send registration credentials over the regular
* system or session bus since those aren't really locked down..." */
if (!_client_register_start (manager, error))
return FALSE;
g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
"pkexec", LIBEXECDIR "/gsd-subman-helper",
"--kind", "register-with-username",
"--address", priv->address,
"--hostname", hostname,
"--organisation", organisation,
"--username", username,
"--password", password,
NULL);
if (subprocess == NULL) {
g_prefix_error (error, "failed to find pkexec: ");
return FALSE;
}
if (!_client_subprocess_wait_check (subprocess, error))
return FALSE;
/* FIXME: also do on error? */
if (!_client_register_stop (manager, error))
return FALSE;
if (!_client_subscription_status_update (manager, error))
return FALSE;
+ if (!_client_installed_products_update (manager, error))
+ return FALSE;
_client_maybe__show_notification (manager);
return TRUE;
}
static gboolean
_client_unregister (GsdSubscriptionManager *manager, GError **error)
{
g_autoptr(GSubprocess) subprocess = NULL;
/* apparently: "we can't send registration credentials over the regular
* system or session bus since those aren't really locked down..." */
if (!_client_register_start (manager, error))
return FALSE;
g_debug ("spawning %s", LIBEXECDIR "/gsd-subman-helper");
subprocess = g_subprocess_new (G_SUBPROCESS_FLAGS_STDERR_PIPE, error,
"pkexec", LIBEXECDIR "/gsd-subman-helper",
"--kind", "unregister",
NULL);
if (subprocess == NULL) {
g_prefix_error (error, "failed to find pkexec: ");
return FALSE;
}
if (!_client_subprocess_wait_check (subprocess, error))
return FALSE;
if (!_client_subscription_status_update (manager, error))
return FALSE;
+ if (!_client_installed_products_update (manager, error))
+ return FALSE;
_client_maybe__show_notification (manager);
return TRUE;
}
static gboolean
_client_update_config (GsdSubscriptionManager *manager, GError **error)
{
GsdSubscriptionManagerPrivate *priv = manager->priv;
g_autoptr(GVariant) val = NULL;
g_autoptr(GVariant) val_server = NULL;
g_autoptr(GVariantDict) dict = NULL;
GVariantIter iter;
gchar *key;
gchar *value;
val = g_dbus_proxy_call_sync (priv->proxies[_RHSM_INTERFACE_CONFIG],
"GetAll",
g_variant_new ("(s)", priv->userlang),
G_DBUS_CALL_FLAGS_NONE,
-1, NULL, error);
if (val == NULL)
return FALSE;
dict = g_variant_dict_new (g_variant_get_child_value (val, 0));
val_server = g_variant_dict_lookup_value (dict, "server", G_VARIANT_TYPE("a{ss}"));
if (val_server != NULL) {
g_variant_iter_init (&iter, val_server);
while (g_variant_iter_next (&iter, "{ss}", &key, &value)) {
g_debug ("%s=%s", key, value);
g_hash_table_insert (priv->config,
g_steal_pointer (&key),
g_steal_pointer (&value));
}
}
return TRUE;
}
static void
_subman_proxy_signal_cb (GDBusProxy *proxy,
const gchar *sender_name,
const gchar *signal_name,
GVariant *parameters,
GsdSubscriptionManager *manager)
{
g_autoptr(GError) error = NULL;
if (!_client_syspurpose_update (manager, &error)) {
g_warning ("failed to update syspurpose: %s", error->message);
g_clear_error (&error);
}
if (!_client_subscription_status_update (manager, &error)) {
g_warning ("failed to update subscription status: %s", error->message);
g_clear_error (&error);
}
+ if (!_client_installed_products_update (manager, &error)) {
+ g_warning ("failed to update installed products: %s", error->message);
+ g_clear_error (&error);
+ }
_client_maybe__show_notification (manager);