Merge lp:~azzar1/unity/lock-autologin into lp:unity

Proposed by Andrea Azzarone
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4216
Proposed branch: lp:~azzar1/unity/lock-autologin
Merge into: lp:unity
Diff against target: 262 lines (+88/-16)
8 files modified
UnityCore/GnomeSessionManager.cpp (+45/-0)
UnityCore/GnomeSessionManager.h (+1/-0)
UnityCore/GnomeSessionManagerImpl.h (+1/-0)
UnityCore/SessionManager.h (+1/-0)
plugins/unityshell/src/unityshell.cpp (+34/-16)
plugins/unityshell/src/unityshell.h (+4/-0)
shutdown/StandaloneSession.cpp (+1/-0)
tests/test_mock_session_manager.h (+1/-0)
To merge this branch: bzr merge lp:~azzar1/unity/lock-autologin
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+300119@code.launchpad.net

Commit message

Keep the screen locked if rebooting with autologin.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Nice work, some stuff to cleanup...

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) :
review: Needs Fixing
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Hey, could you please clean this up?

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Done.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/GnomeSessionManager.cpp'
2--- UnityCore/GnomeSessionManager.cpp 2016-11-02 16:38:47 +0000
3+++ UnityCore/GnomeSessionManager.cpp 2017-01-04 17:49:42 +0000
4@@ -575,13 +575,53 @@
5 auto group = getgrnam(group_name.c_str());
6
7 if (group && group->gr_mem)
8+ {
9 for (int i = 0; group->gr_mem[i]; ++i)
10+ {
11 if (g_strcmp0(group->gr_mem[i], user_name.c_str()) == 0)
12 return true;
13+ }
14+ }
15
16 return false;
17 }
18
19+bool GnomeManager::Impl::AutomaticLogin()
20+{
21+ glib::Error error;
22+ glib::Object<GDBusConnection> bus(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
23+
24+ if (error)
25+ {
26+ LOG_ERROR(logger) << "Impossible to get the system bus to know if auto-login is enabled: " << error;
27+ return false;
28+ }
29+
30+ glib::Variant user_path(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
31+ "/org/freedesktop/Accounts", "org.freedesktop.Accounts",
32+ "FindUserByName", g_variant_new("(s)",g_get_user_name()), nullptr,
33+ G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
34+
35+ if (error)
36+ {
37+ LOG_ERROR(logger) << "Impossible to get the user path: " << error;
38+ return false;
39+ }
40+
41+ glib::Variant autologin(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
42+ user_path.GetObjectPath().c_str(), "org.freedesktop.DBus.Properties",
43+ "Get", g_variant_new("(ss)", "org.freedesktop.Accounts.User", "AutomaticLogin"), nullptr,
44+ G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
45+
46+ if (error)
47+ {
48+ LOG_ERROR(logger) << "Impossible to get the AutomaticLogin property: " << error;
49+ return false;
50+ }
51+
52+ return autologin.GetBool();
53+}
54+
55 // Public implementation
56
57 GnomeManager::GnomeManager()
58@@ -620,6 +660,11 @@
59 impl_->UserIconFile(callback);
60 }
61
62+bool GnomeManager::AutomaticLogin() const
63+{
64+ return impl_->AutomaticLogin();
65+}
66+
67 void GnomeManager::ScreenSaverActivate()
68 {
69 screensaver_requested.emit(true);
70
71=== modified file 'UnityCore/GnomeSessionManager.h'
72--- UnityCore/GnomeSessionManager.h 2015-12-03 05:57:00 +0000
73+++ UnityCore/GnomeSessionManager.h 2017-01-04 17:49:42 +0000
74@@ -37,6 +37,7 @@
75 std::string UserName() const;
76 std::string HostName() const;
77 void UserIconFile(std::function<void(std::string const&)> const&) const;
78+ bool AutomaticLogin() const;
79
80 void ScreenSaverActivate();
81 void ScreenSaverDeactivate();
82
83=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
84--- UnityCore/GnomeSessionManagerImpl.h 2016-11-02 16:38:47 +0000
85+++ UnityCore/GnomeSessionManagerImpl.h 2017-01-04 17:49:42 +0000
86@@ -69,6 +69,7 @@
87 void UpdateHaveOtherOpenSessions();
88
89 bool IsUserInGroup(std::string const& user_name, std::string const& group_name);
90+ bool AutomaticLogin();
91
92 GnomeManager* manager_;
93 bool test_mode_;
94
95=== modified file 'UnityCore/SessionManager.h'
96--- UnityCore/SessionManager.h 2016-03-31 09:51:33 +0000
97+++ UnityCore/SessionManager.h 2017-01-04 17:49:42 +0000
98@@ -46,6 +46,7 @@
99 virtual std::string UserName() const = 0;
100 virtual std::string HostName() const = 0;
101 virtual void UserIconFile(std::function<void(std::string const&)> const&) const = 0;
102+ virtual bool AutomaticLogin() const = 0;
103
104 virtual void ScreenSaverActivate() = 0;
105 virtual void ScreenSaverDeactivate() = 0;
106
107=== modified file 'plugins/unityshell/src/unityshell.cpp'
108--- plugins/unityshell/src/unityshell.cpp 2016-11-28 23:40:15 +0000
109+++ plugins/unityshell/src/unityshell.cpp 2017-01-04 17:49:42 +0000
110@@ -197,6 +197,7 @@
111 , menus_(std::make_shared<menu::Manager>(std::make_shared<indicator::DBusIndicators>(), std::make_shared<key::GnomeGrabber>()))
112 , deco_manager_(std::make_shared<decoration::Manager>(menus_))
113 , debugger_(this)
114+ , session_(std::make_shared<session::GnomeManager>())
115 , needsRelayout(false)
116 , super_keypressed_(false)
117 , newFocusedWindow(nullptr)
118@@ -515,7 +516,10 @@
119 unity_a11y_finalize();
120 QuicklistManager::Destroy();
121 decoration::DataPool::Reset();
122- SaveLockStamp(false);
123+
124+ if (!session_->AutomaticLogin())
125+ SaveLockStamp(false);
126+
127 reset_glib_logging();
128
129 screen->addSupportedAtomsSetEnabled(this, false);
130@@ -4005,17 +4009,32 @@
131 UpdateGesturesSupport();
132 }
133
134+std::string UnityScreen::GetLockStampFile() const
135+{
136+ std::string cache_dir;
137+
138+ if (session_->AutomaticLogin())
139+ cache_dir = DesktopUtilities::GetUserCacheDirectory();
140+ else
141+ cache_dir = DesktopUtilities::GetUserRuntimeDirectory();
142+
143+ if (cache_dir.empty())
144+ return std::string();
145+
146+ return cache_dir+local::LOCKED_STAMP;
147+}
148+
149 void UnityScreen::SaveLockStamp(bool save)
150 {
151- auto const& cache_dir = DesktopUtilities::GetUserRuntimeDirectory();
152+ std::string file_path = GetLockStampFile();
153
154- if (cache_dir.empty())
155+ if (file_path.empty())
156 return;
157
158 if (save)
159 {
160 glib::Error error;
161- g_file_set_contents((cache_dir+local::LOCKED_STAMP).c_str(), "", 0, &error);
162+ g_file_set_contents(file_path.c_str(), "", 0, &error);
163
164 if (error)
165 {
166@@ -4024,7 +4043,7 @@
167 }
168 else
169 {
170- if (g_unlink((cache_dir+local::LOCKED_STAMP).c_str()) < 0)
171+ if (g_unlink(file_path.c_str()) < 0)
172 {
173 LOG_ERROR(logger) << "Impossible to delete the unity locked stamp file";
174 }
175@@ -4100,24 +4119,23 @@
176 ShowFirstRunHints();
177
178 // Setup Session Controller
179- auto session = std::make_shared<session::GnomeManager>();
180- session->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
181- session->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
182- session->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked));
183- session->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked));
184- session_dbus_manager_ = std::make_shared<session::DBusManager>(session);
185- session_controller_ = std::make_shared<session::Controller>(session);
186+ session_->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
187+ session_->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
188+ session_->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked));
189+ session_->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked));
190+ session_dbus_manager_ = std::make_shared<session::DBusManager>(session_);
191+ session_controller_ = std::make_shared<session::Controller>(session_);
192 LOG_INFO(logger) << "InitUnityComponents-Session " << timer.ElapsedSeconds() << "s";
193 Introspectable::AddChild(session_controller_.get());
194
195 // Setup Lockscreen Controller
196- screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session);
197- lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session, menus_->KeyGrabber());
198+ screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session_);
199+ lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session_, menus_->KeyGrabber());
200 UpdateActivateIndicatorsKey();
201 LOG_INFO(logger) << "InitUnityComponents-Lockscreen " << timer.ElapsedSeconds() << "s";
202
203- if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS))
204- session->PromptLockScreen();
205+ if (g_file_test(GetLockStampFile().c_str(), G_FILE_TEST_EXISTS))
206+ session_->PromptLockScreen();
207
208 auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) {
209 /* The launcher geometry includes 1px used to draw the right/top margin
210
211=== modified file 'plugins/unityshell/src/unityshell.h'
212--- plugins/unityshell/src/unityshell.h 2016-09-01 23:56:24 +0000
213+++ plugins/unityshell/src/unityshell.h 2017-01-04 17:49:42 +0000
214@@ -76,6 +76,7 @@
215 #include "UnityShowdesktopHandler.h"
216 #include "ThumbnailGenerator.h"
217 #include "MenuManager.h"
218+#include "UnityCore/SessionManager.h"
219
220 #include "compizminimizedwindowhandler.h"
221 #include "BGHash.h"
222@@ -231,6 +232,7 @@
223 void OnScreenLocked();
224 void OnScreenUnlocked();
225 void SaveLockStamp(bool);
226+ std::string GetLockStampFile() const;
227
228 bool DoesPointIntersectUnityGeos(nux::Point const& pt);
229
230@@ -344,6 +346,8 @@
231 std::unique_ptr<BGHash> bghash_;
232 spread::Widgets::Ptr spread_widgets_;
233
234+ session::Manager::Ptr session_;
235+
236 /* Subscription for gestures that manipulate Unity launcher */
237 std::unique_ptr<nux::GesturesSubscription> gestures_sub_launcher_;
238
239
240=== modified file 'shutdown/StandaloneSession.cpp'
241--- shutdown/StandaloneSession.cpp 2015-12-03 05:57:00 +0000
242+++ shutdown/StandaloneSession.cpp 2017-01-04 17:49:42 +0000
243@@ -40,6 +40,7 @@
244 std::string UserName() const { return "marco"; }
245 std::string HostName() const { return "tricky"; }
246 void UserIconFile(std::function<void(std::string const&)> const&) const { std::cout << "UserIconFile" << std::endl; }
247+ bool AutomaticLogin() const { return false; }
248
249 void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; }
250 void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; }
251
252=== modified file 'tests/test_mock_session_manager.h'
253--- tests/test_mock_session_manager.h 2016-03-31 09:51:33 +0000
254+++ tests/test_mock_session_manager.h 2017-01-04 17:49:42 +0000
255@@ -34,6 +34,7 @@
256 MOCK_CONST_METHOD0(UserName, std::string());
257 MOCK_CONST_METHOD0(HostName, std::string());
258 MOCK_CONST_METHOD1(UserIconFile, void(ReplyCallback const&));
259+ MOCK_CONST_METHOD0(AutomaticLogin, bool());
260
261 MOCK_METHOD0(ScreenSaverActivate, void());
262 MOCK_METHOD0(ScreenSaverDeactivate, void());