Merge lp:~3v1n0/unity-settings-daemon/automount-monitor-lockscreen-trusty into lp:unity-settings-daemon/14.04

Proposed by Marco Trevisan (Treviño) on 2015-09-10
Status: Merged
Merged at revision: 4044
Proposed branch: lp:~3v1n0/unity-settings-daemon/automount-monitor-lockscreen-trusty
Merge into: lp:unity-settings-daemon/14.04
Diff against target: 237 lines (+169/-8)
1 file modified
plugins/automount/gsd-automount-manager.c (+169/-8)
To merge this branch: bzr merge lp:~3v1n0/unity-settings-daemon/automount-monitor-lockscreen-trusty
Reviewer Review Type Date Requested Status
Unity Settings Daemon Development Team 2015-09-10 Pending
Review via email: mp+270655@code.launchpad.net

Commit message

AutoMount: also try to connect to Unity Session and delay automounts when locked

Unity has a different concept from GNOME when it comes to the Screensaver: this one
is only responsible of blanking the screen, not to lock the session.
So, when unity is running we need to avoid to automount any volume when Unity is Locked
or when the Screensaver is Active (in some scenarios unity might still use the GNOME screensaver)

To post a comment you must log in.
Iain Lane (laney) wrote :

I just pushed this since it got uploaded as a security update.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/automount/gsd-automount-manager.c'
2--- plugins/automount/gsd-automount-manager.c 2013-11-13 01:59:14 +0000
3+++ plugins/automount/gsd-automount-manager.c 2015-09-10 11:12:28 +0000
4@@ -45,8 +45,11 @@
5 GDBusProxy *session;
6 gboolean session_is_active;
7 gboolean screensaver_active;
8+ gboolean lockscreen_active;
9 guint ss_watch_id;
10+ guint us_watch_id;
11 GDBusProxy *ss_proxy;
12+ GDBusProxy *us_proxy;
13
14 GList *volume_queue;
15 };
16@@ -178,7 +181,7 @@
17 GList *l;
18 GVolume *volume;
19
20- if (manager->priv->screensaver_active)
21+ if (manager->priv->screensaver_active || manager->priv->lockscreen_active)
22 return;
23
24 l = manager->priv->volume_queue;
25@@ -198,13 +201,23 @@
26 }
27
28 static void
29+clear_volume_queue (GsdAutomountManager *manager)
30+{
31+ if (!manager->priv->volume_queue)
32+ return;
33+
34+ g_list_free_full (manager->priv->volume_queue, g_object_unref);
35+ manager->priv->volume_queue = NULL;
36+}
37+
38+static void
39 check_screen_lock_and_mount (GsdAutomountManager *manager,
40 GVolume *volume)
41 {
42 if (!manager->priv->session_is_active)
43 return;
44
45- if (manager->priv->screensaver_active) {
46+ if (manager->priv->screensaver_active || manager->priv->lockscreen_active) {
47 /* queue the volume, to mount it after the screensaver state changed */
48 g_debug ("Queuing volume %p", volume);
49 manager->priv->volume_queue = g_list_prepend (manager->priv->volume_queue,
50@@ -470,12 +483,11 @@
51 manager->priv->screensaver_active = FALSE;
52 g_clear_object (&manager->priv->ss_proxy);
53
54- /* in this case force a clear of the volume queue, without
55- * mounting them.
56- */
57- if (manager->priv->volume_queue != NULL) {
58- g_list_free_full (manager->priv->volume_queue, g_object_unref);
59- manager->priv->volume_queue = NULL;
60+ if (!manager->priv->ss_proxy && !manager->priv->us_proxy) {
61+ /* in this case force a clear of the volume queue, without
62+ * mounting them.
63+ */
64+ clear_volume_queue (manager);
65 }
66 }
67
68@@ -494,11 +506,158 @@
69 NULL);
70 }
71
72+#define UNITY_NAME "com.canonical.Unity"
73+#define UNITY_SESSION_PATH "/com/canonical/Unity/Session"
74+#define UNITY_SESSION_INTERFACE "com.canonical.Unity.Session"
75+
76+static void
77+unity_session_signal_callback (GDBusProxy *proxy,
78+ const gchar *sender_name,
79+ const gchar *signal_name,
80+ GVariant *parameters,
81+ gpointer user_data)
82+{
83+ GsdAutomountManager *manager = user_data;
84+
85+ if (g_strcmp0 (signal_name, "Locked") == 0) {
86+ manager->priv->lockscreen_active = TRUE;
87+ check_volume_queue (manager);
88+ g_debug ("Unity.Session Locked");
89+ } else if (g_strcmp0 (signal_name, "Unlocked") == 0) {
90+ manager->priv->lockscreen_active = FALSE;
91+ check_volume_queue (manager);
92+ g_debug ("Unity.Session Unlocked");
93+ }
94+}
95+
96+static void
97+unity_session_is_locked_cb (GObject *source,
98+ GAsyncResult *res,
99+ gpointer user_data)
100+{
101+ GsdAutomountManager *manager = user_data;
102+ GDBusProxy *proxy = manager->priv->us_proxy;
103+ GVariant *result;
104+ GError *error = NULL;
105+
106+ result = g_dbus_proxy_call_finish (proxy,
107+ res,
108+ &error);
109+
110+ if (error != NULL) {
111+ g_warning ("Can't call IsLocked() on the Unity.Session object: %s",
112+ error->message);
113+ g_error_free (error);
114+
115+ return;
116+ }
117+
118+ g_variant_get (result, "(b)", &manager->priv->lockscreen_active);
119+ g_variant_unref (result);
120+
121+ g_debug ("Unity Session IsLocked() returned %d", manager->priv->lockscreen_active);
122+}
123+
124+static void
125+unity_session_proxy_ready_cb (GObject *source,
126+ GAsyncResult *res,
127+ gpointer user_data)
128+{
129+ GsdAutomountManager *manager = user_data;
130+ GError *error = NULL;
131+ GDBusProxy *us_proxy;
132+
133+ us_proxy = g_dbus_proxy_new_finish (res, &error);
134+
135+ if (error != NULL) {
136+ g_warning ("Can't get proxy for the Unity Session object: %s",
137+ error->message);
138+ g_error_free (error);
139+
140+ return;
141+ }
142+
143+ g_debug ("Unity Session proxy ready");
144+
145+ manager->priv->us_proxy = us_proxy;
146+
147+ g_signal_connect (us_proxy, "g-signal",
148+ G_CALLBACK (unity_session_signal_callback), manager);
149+
150+ g_dbus_proxy_call (us_proxy,
151+ "IsLocked",
152+ NULL,
153+ G_DBUS_CALL_FLAGS_NO_AUTO_START,
154+ -1,
155+ NULL,
156+ unity_session_is_locked_cb,
157+ manager);
158+}
159+
160+static void
161+unity_appeared_callback (GDBusConnection *connection,
162+ const gchar *name,
163+ const gchar *name_owner,
164+ gpointer user_data)
165+{
166+ GsdAutomountManager *manager = user_data;
167+
168+ g_debug ("Unity name appeared");
169+
170+ manager->priv->lockscreen_active = FALSE;
171+
172+ g_dbus_proxy_new (connection,
173+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
174+ NULL,
175+ name,
176+ UNITY_SESSION_PATH,
177+ UNITY_SESSION_INTERFACE,
178+ NULL,
179+ unity_session_proxy_ready_cb,
180+ manager);
181+}
182+
183+static void
184+unity_vanished_callback (GDBusConnection *connection,
185+ const gchar *name,
186+ gpointer user_data)
187+{
188+ GsdAutomountManager *manager = user_data;
189+
190+ g_debug ("Unity name vanished");
191+
192+ manager->priv->lockscreen_active = FALSE;
193+ g_clear_object (&manager->priv->us_proxy);
194+
195+ if (!manager->priv->ss_proxy && !manager->priv->us_proxy) {
196+ /* in this case force a clear of the volume queue, without
197+ * mounting them.
198+ */
199+ clear_volume_queue (manager);
200+ }
201+}
202+
203+static void
204+do_initialize_lockscreen (GsdAutomountManager *manager)
205+{
206+ GsdAutomountManagerPrivate *p = manager->priv;
207+
208+ p->us_watch_id =
209+ g_bus_watch_name (G_BUS_TYPE_SESSION,
210+ UNITY_NAME,
211+ G_BUS_NAME_WATCHER_FLAGS_NONE,
212+ unity_appeared_callback,
213+ unity_vanished_callback,
214+ manager,
215+ NULL);
216+}
217+
218 static void
219 setup_automounter (GsdAutomountManager *manager)
220 {
221 do_initialize_session (manager);
222 do_initialize_screensaver (manager);
223+ do_initialize_lockscreen (manager);
224
225 manager->priv->volume_monitor = g_volume_monitor_get ();
226 g_signal_connect_object (manager->priv->volume_monitor, "mount-added",
227@@ -540,8 +699,10 @@
228 g_clear_object (&p->volume_monitor);
229 g_clear_object (&p->settings);
230 g_clear_object (&p->ss_proxy);
231+ g_clear_object (&p->us_proxy);
232
233 g_bus_unwatch_name (p->ss_watch_id);
234+ g_bus_unwatch_name (p->us_watch_id);
235
236 if (p->volume_queue != NULL) {
237 g_list_free_full (p->volume_queue, g_object_unref);

Subscribers

People subscribed via source and target branches