Merge lp:~3v1n0/indicator-session/unity-session into lp:indicator-session/14.04

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Charles Kerr
Approved revision: 441
Merged at revision: 445
Proposed branch: lp:~3v1n0/indicator-session/unity-session
Merge into: lp:indicator-session/14.04
Diff against target: 417 lines (+223/-8)
8 files modified
src/backend-dbus/CMakeLists.txt (+5/-1)
src/backend-dbus/actions.c (+70/-5)
src/backend-dbus/com.canonical.Unity.Session.xml (+12/-0)
tests/backend-dbus/CMakeLists.txt (+2/-0)
tests/backend-dbus/gtest-mock-dbus-fixture.h (+4/-0)
tests/backend-dbus/mock-unity-session.cc (+71/-0)
tests/backend-dbus/mock-unity-session.h (+53/-0)
tests/backend-dbus/test-actions.cc (+6/-2)
To merge this branch: bzr merge lp:~3v1n0/indicator-session/unity-session
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Charles Kerr (community) Approve
Sebastien Bacher Needs Fixing
Lars Karlitski (community) Approve
Review via email: mp+215076@code.launchpad.net

Commit message

DBusActions: use unity session APIs when unity is running

Use Immediate lock when switching, and rely to standard lock (with fade) in normal cases.

Description of the change

Fixes the unity fade-to-lock that might happen after switching a session, and thus that could quickly present user informations to others (that just switch tty).

To post a comment you must log in.
438. By Marco Trevisan (Treviño)

actions: cleanup spacing

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
439. By Marco Trevisan (Treviño)

ScreenSaver API: add SimulateUserActivity back

440. By Marco Trevisan (Treviño)

DBusActions: use if/else instead of returning in lock_current_session

Revision history for this message
Lars Karlitski (larsu) wrote :

Looks good to me, thanks.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Sebastien Bacher (seb128) wrote :

the CI says tests are unhappy
"[ FAILED ] Actions.SwitchToScreensaver"

review: Needs Fixing
441. By Marco Trevisan (Treviño)

MockUnitySession: add new mock for unity session, and use it in tests

Revision history for this message
Charles Kerr (charlesk) wrote :

Looks good.

This is actually a very timely patch: it also helps with bug #1296814 as paulliu's going to reuse com.canonical.Unity.Session for bug #1302213 :)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/backend-dbus/CMakeLists.txt'
2--- src/backend-dbus/CMakeLists.txt 2013-07-02 02:00:17 +0000
3+++ src/backend-dbus/CMakeLists.txt 2014-04-10 15:11:29 +0000
4@@ -14,7 +14,7 @@
5 add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-accounts
6 org.freedesktop
7 ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Accounts.xml)
8-
9+
10 add_gdbus_codegen (BACKEND_GENERATED_SOURCES dbus-user
11 org.freedesktop
12 ${CMAKE_CURRENT_SOURCE_DIR}/org.freedesktop.Accounts.User.xml)
13@@ -43,6 +43,10 @@
14 org.gnome.SessionManager
15 ${CMAKE_CURRENT_SOURCE_DIR}/org.gnome.SessionManager.EndSessionDialog.xml)
16
17+add_gdbus_codegen (BACKEND_GENERATED_SOURCES unity-session
18+ com.canonical
19+ ${CMAKE_CURRENT_SOURCE_DIR}/com.canonical.Unity.Session.xml)
20+
21 set (SOURCES actions.c guest.c users.c backend-dbus.c utils.c)
22
23 # add warnings/coverage info on handwritten files
24
25=== modified file 'src/backend-dbus/actions.c'
26--- src/backend-dbus/actions.c 2014-01-21 21:31:50 +0000
27+++ src/backend-dbus/actions.c 2014-04-10 15:11:29 +0000
28@@ -25,6 +25,7 @@
29 #include "dbus-webcredentials.h"
30 #include "gnome-screen-saver.h"
31 #include "gnome-session-manager.h"
32+#include "unity-session.h"
33
34 #include "actions.h"
35
36@@ -43,6 +44,7 @@
37 GSettings * indicator_settings;
38 GnomeScreenSaver * screen_saver;
39 GnomeSessionManager * session_manager;
40+ UnitySession * unity_session;
41 Login1Manager * login1_manager;
42 GCancellable * login1_manager_cancellable;
43 Login1Seat * login1_seat;
44@@ -197,6 +199,22 @@
45 }
46
47 static void
48+on_unity_proxy_ready (GObject * o G_GNUC_UNUSED, GAsyncResult * res, gpointer gself)
49+{
50+ GError * err;
51+ UnitySession * us;
52+
53+ err = NULL;
54+ us = unity_session_proxy_new_for_bus_finish (res, &err);
55+ if (err == NULL)
56+ {
57+ INDICATOR_SESSION_ACTIONS_DBUS(gself)->priv->unity_session = us;
58+ }
59+
60+ log_and_clear_error (&err, G_STRLOC, G_STRFUNC);
61+}
62+
63+static void
64 on_can_suspend_ready (GObject * o, GAsyncResult * res, gpointer gself)
65 {
66 char * str;
67@@ -758,20 +776,54 @@
68 ****
69 ***/
70
71+static gboolean
72+have_unity_session (IndicatorSessionActions * self)
73+{
74+ priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
75+ gchar * name_owner;
76+
77+ if (G_IS_DBUS_PROXY (p->unity_session))
78+ {
79+ name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (p->unity_session));
80+
81+ if (name_owner)
82+ {
83+ g_free (name_owner);
84+ return TRUE;
85+ }
86+ }
87+
88+ return FALSE;
89+}
90+
91 static void
92-lock_current_session (IndicatorSessionActions * self)
93+lock_current_session (IndicatorSessionActions * self, gboolean immediate)
94 {
95 priv_t * p = INDICATOR_SESSION_ACTIONS_DBUS(self)->priv;
96
97- g_return_if_fail (p->screen_saver != NULL);
98+ if (have_unity_session (self))
99+ {
100+ if (immediate)
101+ {
102+ unity_session_call_prompt_lock (p->unity_session, p->cancellable, NULL, NULL);
103+ }
104+ else
105+ {
106+ unity_session_call_lock (p->unity_session, p->cancellable, NULL, NULL);
107+ }
108+ }
109+ else
110+ {
111+ g_return_if_fail (p->screen_saver != NULL);
112
113- gnome_screen_saver_call_lock (p->screen_saver, p->cancellable, NULL, NULL);
114+ gnome_screen_saver_call_lock (p->screen_saver, p->cancellable, NULL, NULL);
115+ }
116 }
117
118 static void
119 my_switch_to_screensaver (IndicatorSessionActions * self)
120 {
121- lock_current_session (self);
122+ lock_current_session (self, FALSE);
123 }
124
125 static void
126@@ -781,6 +833,8 @@
127
128 g_return_if_fail (p->dm_seat != NULL);
129
130+ lock_current_session (self, TRUE);
131+
132 display_manager_seat_call_switch_to_greeter (p->dm_seat,
133 p->dm_seat_cancellable,
134 NULL, NULL);
135@@ -793,7 +847,7 @@
136
137 g_return_if_fail (p->dm_seat != NULL);
138
139- lock_current_session (self);
140+ lock_current_session (self, TRUE);
141
142 display_manager_seat_call_switch_to_guest (p->dm_seat, "",
143 p->dm_seat_cancellable,
144@@ -807,6 +861,8 @@
145
146 g_return_if_fail (p->dm_seat != NULL);
147
148+ lock_current_session (self, TRUE);
149+
150 display_manager_seat_call_switch_to_user (p->dm_seat, username, "",
151 p->dm_seat_cancellable,
152 NULL, NULL);
153@@ -850,6 +906,7 @@
154
155 g_clear_object (&p->screen_saver);
156 g_clear_object (&p->session_manager);
157+ g_clear_object (&p->unity_session);
158 set_dm_seat (self, NULL);
159 set_login1_manager (self, NULL);
160 set_login1_seat (self, NULL);
161@@ -952,6 +1009,14 @@
162 on_screensaver_proxy_ready,
163 self);
164
165+ unity_session_proxy_new_for_bus (G_BUS_TYPE_SESSION,
166+ G_DBUS_PROXY_FLAGS_NONE,
167+ "com.canonical.Unity",
168+ "/com/canonical/Unity/Session",
169+ p->cancellable,
170+ on_unity_proxy_ready,
171+ self);
172+
173 gnome_session_manager_proxy_new_for_bus (G_BUS_TYPE_SESSION,
174 G_DBUS_PROXY_FLAGS_NONE,
175 "org.gnome.SessionManager",
176
177=== added file 'src/backend-dbus/com.canonical.Unity.Session.xml'
178--- src/backend-dbus/com.canonical.Unity.Session.xml 1970-01-01 00:00:00 +0000
179+++ src/backend-dbus/com.canonical.Unity.Session.xml 2014-04-10 15:11:29 +0000
180@@ -0,0 +1,12 @@
181+<!DOCTYPE node PUBLIC
182+"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
183+"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
184+<node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd">
185+ <interface name="com.canonical.Unity.Session">
186+ <method name="Lock" />
187+ <method name="PromptLock" />
188+ <method name="RequestLogout" />
189+ <method name="RequestReboot" />
190+ <method name="RequestShutdown" />
191+ </interface>
192+</node>
193
194=== modified file 'tests/backend-dbus/CMakeLists.txt'
195--- tests/backend-dbus/CMakeLists.txt 2013-06-25 04:14:57 +0000
196+++ tests/backend-dbus/CMakeLists.txt 2014-04-10 15:11:29 +0000
197@@ -23,6 +23,8 @@
198 mock-object.h
199 mock-screen-saver.cc
200 mock-screen-saver.h
201+ mock-unity-session.cc
202+ mock-unity-session.h
203 mock-session-manager.cc
204 mock-session-manager.h
205 mock-user.cc
206
207=== modified file 'tests/backend-dbus/gtest-mock-dbus-fixture.h'
208--- tests/backend-dbus/gtest-mock-dbus-fixture.h 2013-06-25 04:14:57 +0000
209+++ tests/backend-dbus/gtest-mock-dbus-fixture.h 2014-04-10 15:11:29 +0000
210@@ -25,6 +25,7 @@
211 #include "mock-display-manager-seat.h"
212 #include "mock-end-session-dialog.h"
213 #include "mock-screen-saver.h"
214+#include "mock-unity-session.h"
215 #include "mock-session-manager.h"
216 #include "mock-user.h"
217 #include "mock-webcredentials.h"
218@@ -42,6 +43,7 @@
219 protected:
220
221 MockScreenSaver * screen_saver;
222+ MockUnitySession * unity_session;
223 MockSessionManager * session_manager;
224 MockDisplayManagerSeat * dm_seat;
225 MockAccounts * accounts;
226@@ -60,6 +62,7 @@
227 end_session_dialog = new MockEndSessionDialog (loop, conn);
228 session_manager = new MockSessionManager (loop, conn);
229 screen_saver = new MockScreenSaver (loop, conn);
230+ unity_session = new MockUnitySession (loop, conn);
231 dm_seat = new MockDisplayManagerSeat (loop, conn);
232 g_setenv ("XDG_SEAT_PATH", dm_seat->path(), TRUE);
233 dm_seat->set_guest_allowed (false);
234@@ -83,6 +86,7 @@
235 delete login1_manager;
236 delete dm_seat;
237 delete screen_saver;
238+ delete unity_session;
239 delete session_manager;
240 delete end_session_dialog;
241 delete webcredentials;
242
243=== added file 'tests/backend-dbus/mock-unity-session.cc'
244--- tests/backend-dbus/mock-unity-session.cc 1970-01-01 00:00:00 +0000
245+++ tests/backend-dbus/mock-unity-session.cc 2014-04-10 15:11:29 +0000
246@@ -0,0 +1,71 @@
247+/*
248+ * Copyright 2014 Canonical Ltd.
249+ *
250+ * Authors:
251+ * Marco Trevisan <marco.trevisan@canonical.com>
252+ *
253+ * This program is free software: you can redistribute it and/or modify it
254+ * under the terms of the GNU General Public License version 3, as published
255+ * by the Free Software Foundation.
256+ *
257+ * This program is distributed in the hope that it will be useful, but
258+ * WITHOUT ANY WARRANTY; without even the implied warranties of
259+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
260+ * PURPOSE. See the GNU General Public License for more details.
261+ *
262+ * You should have received a copy of the GNU General Public License along
263+ * with this program. If not, see <http://www.gnu.org/licenses/>.
264+ */
265+
266+#include "mock-unity-session.h"
267+
268+
269+gboolean
270+MockUnitySession :: handle_lock (UnitySession * us,
271+ GDBusMethodInvocation * inv,
272+ gpointer gself)
273+{
274+ static_cast<MockUnitySession*>(gself)->my_last_action = Lock;
275+ unity_session_complete_lock (us, inv);
276+ return true;
277+}
278+
279+gboolean
280+MockUnitySession :: handle_prompt_lock (UnitySession * us,
281+ GDBusMethodInvocation * inv,
282+ gpointer gself)
283+{
284+ static_cast<MockUnitySession*>(gself)->my_last_action = PromptLock;
285+ unity_session_complete_prompt_lock (us, inv);
286+ return true;
287+}
288+
289+/***
290+****
291+***/
292+
293+namespace
294+{
295+ const char * const UNITY_SESSION_NAME = "com.canonical.Unity";
296+ const char * const UNITY_SESSION_PATH = "/com/canonical/Unity/Session";
297+
298+}
299+
300+MockUnitySession :: MockUnitySession (GMainLoop * loop,
301+ GDBusConnection * bus_connection):
302+ MockObject (loop, bus_connection, UNITY_SESSION_NAME, UNITY_SESSION_PATH),
303+ my_skeleton (unity_session_skeleton_new ()),
304+ my_last_action (None)
305+{
306+ g_signal_connect (my_skeleton, "handle-lock",
307+ G_CALLBACK(handle_lock), this);
308+ g_signal_connect (my_skeleton, "handle-prompt-lock",
309+ G_CALLBACK(handle_prompt_lock), this);
310+
311+ set_skeleton (G_DBUS_INTERFACE_SKELETON(my_skeleton));
312+}
313+
314+MockUnitySession :: ~MockUnitySession ()
315+{
316+ g_clear_object (&my_skeleton);
317+}
318
319=== added file 'tests/backend-dbus/mock-unity-session.h'
320--- tests/backend-dbus/mock-unity-session.h 1970-01-01 00:00:00 +0000
321+++ tests/backend-dbus/mock-unity-session.h 2014-04-10 15:11:29 +0000
322@@ -0,0 +1,53 @@
323+/*
324+ * Copyright 2014 Canonical Ltd.
325+ *
326+ * Authors:
327+ * Marco Trevisan <marco.trevisan@canonical.com>
328+ *
329+ * This program is free software: you can redistribute it and/or modify it
330+ * under the terms of the GNU General Public License version 3, as published
331+ * by the Free Software Foundation.
332+ *
333+ * This program is distributed in the hope that it will be useful, but
334+ * WITHOUT ANY WARRANTY; without even the implied warranties of
335+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
336+ * PURPOSE. See the GNU General Public License for more details.
337+ *
338+ * You should have received a copy of the GNU General Public License along
339+ * with this program. If not, see <http://www.gnu.org/licenses/>.
340+ */
341+
342+#ifndef MOCK_UNITY_SESSION_H
343+#define MOCK_UNITY_SESSION_H
344+
345+#include "mock-object.h" // parent class
346+#include "backend-dbus/unity-session.h" // Unity Session
347+
348+class MockUnitySession: public MockObject
349+{
350+ public:
351+
352+ MockUnitySession (GMainLoop * loop,
353+ GDBusConnection * bus_connection);
354+ virtual ~MockUnitySession ();
355+
356+ public:
357+
358+ enum Action { None, Lock, PromptLock, RequestLogout, RequestShutdown, RequestReboot };
359+ Action last_action () { return my_last_action; }
360+
361+ private:
362+
363+ UnitySession * my_skeleton;
364+ Action my_last_action;
365+
366+ static gboolean handle_lock (UnitySession *,
367+ GDBusMethodInvocation *,
368+ gpointer);
369+ static gboolean handle_prompt_lock (UnitySession *,
370+ GDBusMethodInvocation *,
371+ gpointer);
372+
373+};
374+
375+#endif
376
377=== modified file 'tests/backend-dbus/test-actions.cc'
378--- tests/backend-dbus/test-actions.cc 2013-07-12 07:05:35 +0000
379+++ tests/backend-dbus/test-actions.cc 2014-04-10 15:11:29 +0000
380@@ -316,17 +316,19 @@
381
382 TEST_F (Actions, SwitchToScreensaver)
383 {
384- ASSERT_EQ (MockScreenSaver::None, screen_saver->last_action());
385+ ASSERT_EQ (MockUnitySession::None, unity_session->last_action());
386 indicator_session_actions_switch_to_screensaver (actions);
387 wait_msec (50);
388- ASSERT_EQ (MockScreenSaver::Lock, screen_saver->last_action());
389+ ASSERT_EQ (MockUnitySession::Lock, unity_session->last_action());
390 }
391
392 TEST_F (Actions, SwitchToGreeter)
393 {
394 ASSERT_NE (MockDisplayManagerSeat::GREETER, dm_seat->last_action());
395+ ASSERT_EQ (MockUnitySession::None, unity_session->last_action());
396 indicator_session_actions_switch_to_greeter (actions);
397 wait_msec (50);
398+ ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action());
399 ASSERT_EQ (MockDisplayManagerSeat::GREETER, dm_seat->last_action());
400 }
401
402@@ -346,6 +348,7 @@
403 wait_for_signal (login1_seat->skeleton(), "notify::active-session");
404 ASSERT_EQ (guest_session_tag, login1_seat->active_session());
405 wait_msec (50);
406+ ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action());
407 }
408
409 TEST_F (Actions, SwitchToUsername)
410@@ -367,6 +370,7 @@
411 wait_for_signal (login1_seat->skeleton(), "notify::active-session");
412 ASSERT_EQ (dr1_session, login1_seat->active_session());
413 wait_msec (50);
414+ ASSERT_EQ (MockUnitySession::PromptLock, unity_session->last_action());
415
416 indicator_session_actions_switch_to_username (actions, dr2_username);
417 wait_for_signal (login1_seat->skeleton(), "notify::active-session");

Subscribers

People subscribed via source and target branches