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
=== modified file 'UnityCore/GnomeSessionManager.cpp'
--- UnityCore/GnomeSessionManager.cpp 2016-11-02 16:38:47 +0000
+++ UnityCore/GnomeSessionManager.cpp 2017-01-04 17:49:42 +0000
@@ -575,13 +575,53 @@
575 auto group = getgrnam(group_name.c_str());575 auto group = getgrnam(group_name.c_str());
576576
577 if (group && group->gr_mem)577 if (group && group->gr_mem)
578 {
578 for (int i = 0; group->gr_mem[i]; ++i)579 for (int i = 0; group->gr_mem[i]; ++i)
580 {
579 if (g_strcmp0(group->gr_mem[i], user_name.c_str()) == 0)581 if (g_strcmp0(group->gr_mem[i], user_name.c_str()) == 0)
580 return true;582 return true;
583 }
584 }
581585
582 return false;586 return false;
583}587}
584588
589bool GnomeManager::Impl::AutomaticLogin()
590{
591 glib::Error error;
592 glib::Object<GDBusConnection> bus(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error));
593
594 if (error)
595 {
596 LOG_ERROR(logger) << "Impossible to get the system bus to know if auto-login is enabled: " << error;
597 return false;
598 }
599
600 glib::Variant user_path(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
601 "/org/freedesktop/Accounts", "org.freedesktop.Accounts",
602 "FindUserByName", g_variant_new("(s)",g_get_user_name()), nullptr,
603 G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
604
605 if (error)
606 {
607 LOG_ERROR(logger) << "Impossible to get the user path: " << error;
608 return false;
609 }
610
611 glib::Variant autologin(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
612 user_path.GetObjectPath().c_str(), "org.freedesktop.DBus.Properties",
613 "Get", g_variant_new("(ss)", "org.freedesktop.Accounts.User", "AutomaticLogin"), nullptr,
614 G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
615
616 if (error)
617 {
618 LOG_ERROR(logger) << "Impossible to get the AutomaticLogin property: " << error;
619 return false;
620 }
621
622 return autologin.GetBool();
623}
624
585// Public implementation625// Public implementation
586626
587GnomeManager::GnomeManager()627GnomeManager::GnomeManager()
@@ -620,6 +660,11 @@
620 impl_->UserIconFile(callback);660 impl_->UserIconFile(callback);
621}661}
622662
663bool GnomeManager::AutomaticLogin() const
664{
665 return impl_->AutomaticLogin();
666}
667
623void GnomeManager::ScreenSaverActivate()668void GnomeManager::ScreenSaverActivate()
624{669{
625 screensaver_requested.emit(true);670 screensaver_requested.emit(true);
626671
=== modified file 'UnityCore/GnomeSessionManager.h'
--- UnityCore/GnomeSessionManager.h 2015-12-03 05:57:00 +0000
+++ UnityCore/GnomeSessionManager.h 2017-01-04 17:49:42 +0000
@@ -37,6 +37,7 @@
37 std::string UserName() const;37 std::string UserName() const;
38 std::string HostName() const;38 std::string HostName() const;
39 void UserIconFile(std::function<void(std::string const&)> const&) const;39 void UserIconFile(std::function<void(std::string const&)> const&) const;
40 bool AutomaticLogin() const;
4041
41 void ScreenSaverActivate();42 void ScreenSaverActivate();
42 void ScreenSaverDeactivate();43 void ScreenSaverDeactivate();
4344
=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
--- UnityCore/GnomeSessionManagerImpl.h 2016-11-02 16:38:47 +0000
+++ UnityCore/GnomeSessionManagerImpl.h 2017-01-04 17:49:42 +0000
@@ -69,6 +69,7 @@
69 void UpdateHaveOtherOpenSessions();69 void UpdateHaveOtherOpenSessions();
7070
71 bool IsUserInGroup(std::string const& user_name, std::string const& group_name);71 bool IsUserInGroup(std::string const& user_name, std::string const& group_name);
72 bool AutomaticLogin();
7273
73 GnomeManager* manager_;74 GnomeManager* manager_;
74 bool test_mode_;75 bool test_mode_;
7576
=== modified file 'UnityCore/SessionManager.h'
--- UnityCore/SessionManager.h 2016-03-31 09:51:33 +0000
+++ UnityCore/SessionManager.h 2017-01-04 17:49:42 +0000
@@ -46,6 +46,7 @@
46 virtual std::string UserName() const = 0;46 virtual std::string UserName() const = 0;
47 virtual std::string HostName() const = 0;47 virtual std::string HostName() const = 0;
48 virtual void UserIconFile(std::function<void(std::string const&)> const&) const = 0;48 virtual void UserIconFile(std::function<void(std::string const&)> const&) const = 0;
49 virtual bool AutomaticLogin() const = 0;
4950
50 virtual void ScreenSaverActivate() = 0;51 virtual void ScreenSaverActivate() = 0;
51 virtual void ScreenSaverDeactivate() = 0;52 virtual void ScreenSaverDeactivate() = 0;
5253
=== modified file 'plugins/unityshell/src/unityshell.cpp'
--- plugins/unityshell/src/unityshell.cpp 2016-11-28 23:40:15 +0000
+++ plugins/unityshell/src/unityshell.cpp 2017-01-04 17:49:42 +0000
@@ -197,6 +197,7 @@
197 , menus_(std::make_shared<menu::Manager>(std::make_shared<indicator::DBusIndicators>(), std::make_shared<key::GnomeGrabber>()))197 , menus_(std::make_shared<menu::Manager>(std::make_shared<indicator::DBusIndicators>(), std::make_shared<key::GnomeGrabber>()))
198 , deco_manager_(std::make_shared<decoration::Manager>(menus_))198 , deco_manager_(std::make_shared<decoration::Manager>(menus_))
199 , debugger_(this)199 , debugger_(this)
200 , session_(std::make_shared<session::GnomeManager>())
200 , needsRelayout(false)201 , needsRelayout(false)
201 , super_keypressed_(false)202 , super_keypressed_(false)
202 , newFocusedWindow(nullptr)203 , newFocusedWindow(nullptr)
@@ -515,7 +516,10 @@
515 unity_a11y_finalize();516 unity_a11y_finalize();
516 QuicklistManager::Destroy();517 QuicklistManager::Destroy();
517 decoration::DataPool::Reset();518 decoration::DataPool::Reset();
518 SaveLockStamp(false);519
520 if (!session_->AutomaticLogin())
521 SaveLockStamp(false);
522
519 reset_glib_logging();523 reset_glib_logging();
520524
521 screen->addSupportedAtomsSetEnabled(this, false);525 screen->addSupportedAtomsSetEnabled(this, false);
@@ -4005,17 +4009,32 @@
4005 UpdateGesturesSupport();4009 UpdateGesturesSupport();
4006}4010}
40074011
4012std::string UnityScreen::GetLockStampFile() const
4013{
4014 std::string cache_dir;
4015
4016 if (session_->AutomaticLogin())
4017 cache_dir = DesktopUtilities::GetUserCacheDirectory();
4018 else
4019 cache_dir = DesktopUtilities::GetUserRuntimeDirectory();
4020
4021 if (cache_dir.empty())
4022 return std::string();
4023
4024 return cache_dir+local::LOCKED_STAMP;
4025}
4026
4008void UnityScreen::SaveLockStamp(bool save)4027void UnityScreen::SaveLockStamp(bool save)
4009{4028{
4010 auto const& cache_dir = DesktopUtilities::GetUserRuntimeDirectory();4029 std::string file_path = GetLockStampFile();
40114030
4012 if (cache_dir.empty())4031 if (file_path.empty())
4013 return;4032 return;
40144033
4015 if (save)4034 if (save)
4016 {4035 {
4017 glib::Error error;4036 glib::Error error;
4018 g_file_set_contents((cache_dir+local::LOCKED_STAMP).c_str(), "", 0, &error);4037 g_file_set_contents(file_path.c_str(), "", 0, &error);
40194038
4020 if (error)4039 if (error)
4021 {4040 {
@@ -4024,7 +4043,7 @@
4024 }4043 }
4025 else4044 else
4026 {4045 {
4027 if (g_unlink((cache_dir+local::LOCKED_STAMP).c_str()) < 0)4046 if (g_unlink(file_path.c_str()) < 0)
4028 {4047 {
4029 LOG_ERROR(logger) << "Impossible to delete the unity locked stamp file";4048 LOG_ERROR(logger) << "Impossible to delete the unity locked stamp file";
4030 }4049 }
@@ -4100,24 +4119,23 @@
4100 ShowFirstRunHints();4119 ShowFirstRunHints();
41014120
4102 // Setup Session Controller4121 // Setup Session Controller
4103 auto session = std::make_shared<session::GnomeManager>();4122 session_->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
4104 session->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));4123 session_->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));
4105 session->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested));4124 session_->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked));
4106 session->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked));4125 session_->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked));
4107 session->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked));4126 session_dbus_manager_ = std::make_shared<session::DBusManager>(session_);
4108 session_dbus_manager_ = std::make_shared<session::DBusManager>(session);4127 session_controller_ = std::make_shared<session::Controller>(session_);
4109 session_controller_ = std::make_shared<session::Controller>(session);
4110 LOG_INFO(logger) << "InitUnityComponents-Session " << timer.ElapsedSeconds() << "s";4128 LOG_INFO(logger) << "InitUnityComponents-Session " << timer.ElapsedSeconds() << "s";
4111 Introspectable::AddChild(session_controller_.get());4129 Introspectable::AddChild(session_controller_.get());
41124130
4113 // Setup Lockscreen Controller4131 // Setup Lockscreen Controller
4114 screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session);4132 screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session_);
4115 lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session, menus_->KeyGrabber());4133 lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session_, menus_->KeyGrabber());
4116 UpdateActivateIndicatorsKey();4134 UpdateActivateIndicatorsKey();
4117 LOG_INFO(logger) << "InitUnityComponents-Lockscreen " << timer.ElapsedSeconds() << "s";4135 LOG_INFO(logger) << "InitUnityComponents-Lockscreen " << timer.ElapsedSeconds() << "s";
41184136
4119 if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS))4137 if (g_file_test(GetLockStampFile().c_str(), G_FILE_TEST_EXISTS))
4120 session->PromptLockScreen();4138 session_->PromptLockScreen();
41214139
4122 auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) {4140 auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) {
4123 /* The launcher geometry includes 1px used to draw the right/top margin4141 /* The launcher geometry includes 1px used to draw the right/top margin
41244142
=== modified file 'plugins/unityshell/src/unityshell.h'
--- plugins/unityshell/src/unityshell.h 2016-09-01 23:56:24 +0000
+++ plugins/unityshell/src/unityshell.h 2017-01-04 17:49:42 +0000
@@ -76,6 +76,7 @@
76#include "UnityShowdesktopHandler.h"76#include "UnityShowdesktopHandler.h"
77#include "ThumbnailGenerator.h"77#include "ThumbnailGenerator.h"
78#include "MenuManager.h"78#include "MenuManager.h"
79#include "UnityCore/SessionManager.h"
7980
80#include "compizminimizedwindowhandler.h"81#include "compizminimizedwindowhandler.h"
81#include "BGHash.h"82#include "BGHash.h"
@@ -231,6 +232,7 @@
231 void OnScreenLocked();232 void OnScreenLocked();
232 void OnScreenUnlocked();233 void OnScreenUnlocked();
233 void SaveLockStamp(bool);234 void SaveLockStamp(bool);
235 std::string GetLockStampFile() const;
234236
235 bool DoesPointIntersectUnityGeos(nux::Point const& pt);237 bool DoesPointIntersectUnityGeos(nux::Point const& pt);
236238
@@ -344,6 +346,8 @@
344 std::unique_ptr<BGHash> bghash_;346 std::unique_ptr<BGHash> bghash_;
345 spread::Widgets::Ptr spread_widgets_;347 spread::Widgets::Ptr spread_widgets_;
346348
349 session::Manager::Ptr session_;
350
347 /* Subscription for gestures that manipulate Unity launcher */351 /* Subscription for gestures that manipulate Unity launcher */
348 std::unique_ptr<nux::GesturesSubscription> gestures_sub_launcher_;352 std::unique_ptr<nux::GesturesSubscription> gestures_sub_launcher_;
349353
350354
=== modified file 'shutdown/StandaloneSession.cpp'
--- shutdown/StandaloneSession.cpp 2015-12-03 05:57:00 +0000
+++ shutdown/StandaloneSession.cpp 2017-01-04 17:49:42 +0000
@@ -40,6 +40,7 @@
40 std::string UserName() const { return "marco"; }40 std::string UserName() const { return "marco"; }
41 std::string HostName() const { return "tricky"; }41 std::string HostName() const { return "tricky"; }
42 void UserIconFile(std::function<void(std::string const&)> const&) const { std::cout << "UserIconFile" << std::endl; }42 void UserIconFile(std::function<void(std::string const&)> const&) const { std::cout << "UserIconFile" << std::endl; }
43 bool AutomaticLogin() const { return false; }
4344
44 void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; }45 void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; }
45 void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; }46 void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; }
4647
=== modified file 'tests/test_mock_session_manager.h'
--- tests/test_mock_session_manager.h 2016-03-31 09:51:33 +0000
+++ tests/test_mock_session_manager.h 2017-01-04 17:49:42 +0000
@@ -34,6 +34,7 @@
34 MOCK_CONST_METHOD0(UserName, std::string());34 MOCK_CONST_METHOD0(UserName, std::string());
35 MOCK_CONST_METHOD0(HostName, std::string());35 MOCK_CONST_METHOD0(HostName, std::string());
36 MOCK_CONST_METHOD1(UserIconFile, void(ReplyCallback const&));36 MOCK_CONST_METHOD1(UserIconFile, void(ReplyCallback const&));
37 MOCK_CONST_METHOD0(AutomaticLogin, bool());
3738
38 MOCK_METHOD0(ScreenSaverActivate, void());39 MOCK_METHOD0(ScreenSaverActivate, void());
39 MOCK_METHOD0(ScreenSaverDeactivate, void());40 MOCK_METHOD0(ScreenSaverDeactivate, void());