diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2016-12-20 16:54:28 +0000 |
|---|---|---|
| committer | Andrea Azzarone <azzaronea@gmail.com> | 2016-12-20 16:54:28 +0000 |
| commit | 3c343a0393d50413fc428245dada79a40dccab4c (patch) | |
| tree | cca3d2d852780e7ede814ee8cace36b27d7494c1 | |
| parent | c9ea395d1e6218fbd709fa32256a03b3905efafc (diff) | |
| parent | 7a89ba2107a2f3ea02536aaac3dc63ab9201c4e1 (diff) | |
Merge with trunk.
(bzr r4213.2.1)
| -rw-r--r-- | UnityCore/GnomeSessionManager.cpp | 50 | ||||
| -rw-r--r-- | UnityCore/GnomeSessionManager.h | 1 | ||||
| -rw-r--r-- | UnityCore/GnomeSessionManagerImpl.h | 1 | ||||
| -rw-r--r-- | UnityCore/SessionManager.h | 1 | ||||
| -rw-r--r-- | UnityCore/Variant.cpp | 5 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.cpp | 52 | ||||
| -rw-r--r-- | plugins/unityshell/src/unityshell.h | 4 | ||||
| -rw-r--r-- | shutdown/StandaloneSession.cpp | 1 | ||||
| -rw-r--r-- | tests/test_mock_session_manager.h | 1 |
9 files changed, 99 insertions, 17 deletions
diff --git a/UnityCore/GnomeSessionManager.cpp b/UnityCore/GnomeSessionManager.cpp index 9fb1eb98c..b739b3663 100644 --- a/UnityCore/GnomeSessionManager.cpp +++ b/UnityCore/GnomeSessionManager.cpp @@ -575,13 +575,58 @@ bool GnomeManager::Impl::IsUserInGroup(std::string const& user_name, std::string auto group = getgrnam(group_name.c_str()); if (group && group->gr_mem) + { for (int i = 0; group->gr_mem[i]; ++i) + { if (g_strcmp0(group->gr_mem[i], user_name.c_str()) == 0) return true; + } + } return false; } +bool GnomeManager::Impl::GetAutomaticLogin() +{ + auto proxy = std::make_shared<glib::DBusProxy>("org.freedesktop.Accounts", + "/org/freedesktop/Accounts", + "org.freedesktop.Accounts", + G_BUS_TYPE_SYSTEM); + + glib::Error error; + glib::Object<GDBusConnection> bus(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, &error)); + + if (error) + { + LOG_ERROR(logger) << "Impossible to get the system bus, to know if auto-login is enabled: " << error; + return false; + } + + glib::Variant user_path(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts", + "/org/freedesktop/Accounts", "org.freedesktop.Accounts", + "FindUserByName", g_variant_new("(s)",g_get_user_name()), nullptr, + G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error)); + + if (error) + { + LOG_ERROR(logger) << "Impossible to get the user path: " << error; + return false; + } + + glib::Variant autologin(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts", + user_path.GetString().c_str(), "org.freedesktop.DBus.Properties", + "Get", g_variant_new("(ss)", "org.freedesktop.Accounts.User", "AutomaticLogin"), nullptr, + G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error)); + + if (error) + { + LOG_ERROR(logger) << "Impossible to get the AutomaticLogin property: " << error; + return false; + } + + return autologin.GetBool(); +} + // Public implementation GnomeManager::GnomeManager() @@ -620,6 +665,11 @@ void GnomeManager::UserIconFile(std::function<void(std::string const&)> const& c impl_->UserIconFile(callback); } +bool GnomeManager::GetAutomaticLogin() const +{ + return impl_->GetAutomaticLogin(); +} + void GnomeManager::ScreenSaverActivate() { screensaver_requested.emit(true); diff --git a/UnityCore/GnomeSessionManager.h b/UnityCore/GnomeSessionManager.h index c0894b087..a9e9d82eb 100644 --- a/UnityCore/GnomeSessionManager.h +++ b/UnityCore/GnomeSessionManager.h @@ -37,6 +37,7 @@ public: std::string UserName() const; std::string HostName() const; void UserIconFile(std::function<void(std::string const&)> const&) const; + bool GetAutomaticLogin() const; void ScreenSaverActivate(); void ScreenSaverDeactivate(); diff --git a/UnityCore/GnomeSessionManagerImpl.h b/UnityCore/GnomeSessionManagerImpl.h index f3904e7eb..2cef5ad41 100644 --- a/UnityCore/GnomeSessionManagerImpl.h +++ b/UnityCore/GnomeSessionManagerImpl.h @@ -69,6 +69,7 @@ struct GnomeManager::Impl void UpdateHaveOtherOpenSessions(); bool IsUserInGroup(std::string const& user_name, std::string const& group_name); + bool GetAutomaticLogin(); GnomeManager* manager_; bool test_mode_; diff --git a/UnityCore/SessionManager.h b/UnityCore/SessionManager.h index 7a816f7c4..624f9ceed 100644 --- a/UnityCore/SessionManager.h +++ b/UnityCore/SessionManager.h @@ -46,6 +46,7 @@ public: virtual std::string UserName() const = 0; virtual std::string HostName() const = 0; virtual void UserIconFile(std::function<void(std::string const&)> const&) const = 0; + virtual bool GetAutomaticLogin() const = 0; virtual void ScreenSaverActivate() = 0; virtual void ScreenSaverDeactivate() = 0; diff --git a/UnityCore/Variant.cpp b/UnityCore/Variant.cpp index 9de1d42e5..57cdb0fc8 100644 --- a/UnityCore/Variant.cpp +++ b/UnityCore/Variant.cpp @@ -161,6 +161,11 @@ std::string Variant::GetString() const // As we're using the '&' prefix we don't need to free the string! g_variant_get(variant_, "(&s)", &result); } + else if (g_variant_is_of_type(variant_, G_VARIANT_TYPE("(o)"))) + { + // As we're using the '&' prefix we don't need to free the string! + g_variant_get(variant_, "(&o)", &result); + } else { auto const& variant = get_variant(variant_); diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index c08c44f83..70ffab1e9 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -27,7 +27,6 @@ #include <UnityCore/DBusIndicators.h> #include <UnityCore/DesktopUtilities.h> -#include <UnityCore/GnomeSessionManager.h> #include <UnityCore/ScopeProxyInterface.h> #include "CompizUtils.h" @@ -515,7 +514,10 @@ UnityScreen::~UnityScreen() unity_a11y_finalize(); QuicklistManager::Destroy(); decoration::DataPool::Reset(); - SaveLockStamp(false); + + if (!session_->GetAutomaticLogin()) + SaveLockStamp(false); + reset_glib_logging(); screen->addSupportedAtomsSetEnabled(this, false); @@ -4005,17 +4007,33 @@ void UnityScreen::OnScreenUnlocked() UpdateGesturesSupport(); } -void UnityScreen::SaveLockStamp(bool save) +std::string UnityScreen::GetLockStampFile() const { - auto const& cache_dir = DesktopUtilities::GetUserRuntimeDirectory(); + std::string user_name = session_->UserName(); + std::string cache_dir; + + if (session_->GetAutomaticLogin()) + cache_dir = DesktopUtilities::GetUserConfigDirectory(); + else + cache_dir = DesktopUtilities::GetUserRuntimeDirectory(); if (cache_dir.empty()) + return std::string(); + + return cache_dir+local::LOCKED_STAMP; +} + +void UnityScreen::SaveLockStamp(bool save) +{ + std::string file_path = GetLockStampFile(); + + if (file_path.empty()) return; if (save) { glib::Error error; - g_file_set_contents((cache_dir+local::LOCKED_STAMP).c_str(), "", 0, &error); + g_file_set_contents(file_path.c_str(), "", 0, &error); if (error) { @@ -4024,7 +4042,7 @@ void UnityScreen::SaveLockStamp(bool save) } else { - if (g_unlink((cache_dir+local::LOCKED_STAMP).c_str()) < 0) + if (g_unlink(file_path.c_str()) < 0) { LOG_ERROR(logger) << "Impossible to delete the unity locked stamp file"; } @@ -4100,24 +4118,24 @@ void UnityScreen::InitUnityComponents() ShowFirstRunHints(); // Setup Session Controller - auto session = std::make_shared<session::GnomeManager>(); - session->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); - session->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); - session->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked)); - session->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked)); - session_dbus_manager_ = std::make_shared<session::DBusManager>(session); - session_controller_ = std::make_shared<session::Controller>(session); + session_ = std::make_shared<session::GnomeManager>(); + session_->lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); + session_->prompt_lock_requested.connect(sigc::mem_fun(this, &UnityScreen::OnLockScreenRequested)); + session_->locked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenLocked)); + session_->unlocked.connect(sigc::mem_fun(this, &UnityScreen::OnScreenUnlocked)); + session_dbus_manager_ = std::make_shared<session::DBusManager>(session_); + session_controller_ = std::make_shared<session::Controller>(session_); LOG_INFO(logger) << "InitUnityComponents-Session " << timer.ElapsedSeconds() << "s"; Introspectable::AddChild(session_controller_.get()); // Setup Lockscreen Controller - screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session); - lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session, menus_->KeyGrabber()); + screensaver_dbus_manager_ = std::make_shared<lockscreen::DBusManager>(session_); + lockscreen_controller_ = std::make_shared<lockscreen::Controller>(screensaver_dbus_manager_, session_, menus_->KeyGrabber()); UpdateActivateIndicatorsKey(); LOG_INFO(logger) << "InitUnityComponents-Lockscreen " << timer.ElapsedSeconds() << "s"; - if (g_file_test((DesktopUtilities::GetUserRuntimeDirectory()+local::LOCKED_STAMP).c_str(), G_FILE_TEST_EXISTS)) - session->PromptLockScreen(); + if (g_file_test(GetLockStampFile().c_str(), G_FILE_TEST_EXISTS)) + session_->PromptLockScreen(); auto on_launcher_size_changed = [this] (nux::Area* area, int w, int h) { /* The launcher geometry includes 1px used to draw the right/top margin diff --git a/plugins/unityshell/src/unityshell.h b/plugins/unityshell/src/unityshell.h index 43df66e72..a1b9704c7 100644 --- a/plugins/unityshell/src/unityshell.h +++ b/plugins/unityshell/src/unityshell.h @@ -76,6 +76,7 @@ #include "UnityShowdesktopHandler.h" #include "ThumbnailGenerator.h" #include "MenuManager.h" +#include "UnityCore/GnomeSessionManager.h" #include "compizminimizedwindowhandler.h" #include "BGHash.h" @@ -231,6 +232,7 @@ private: void OnScreenLocked(); void OnScreenUnlocked(); void SaveLockStamp(bool); + std::string GetLockStampFile() const; bool DoesPointIntersectUnityGeos(nux::Point const& pt); @@ -344,6 +346,8 @@ private: std::unique_ptr<BGHash> bghash_; spread::Widgets::Ptr spread_widgets_; + session::Manager::Ptr session_; + /* Subscription for gestures that manipulate Unity launcher */ std::unique_ptr<nux::GesturesSubscription> gestures_sub_launcher_; diff --git a/shutdown/StandaloneSession.cpp b/shutdown/StandaloneSession.cpp index ade557cee..b45b269f9 100644 --- a/shutdown/StandaloneSession.cpp +++ b/shutdown/StandaloneSession.cpp @@ -40,6 +40,7 @@ public: std::string UserName() const { return "marco"; } std::string HostName() const { return "tricky"; } void UserIconFile(std::function<void(std::string const&)> const&) const { std::cout << "UserIconFile" << std::endl; } + bool GetAutomaticLogin() const { return false; } void ScreenSaverActivate() { std::cout << "ScreenSaverActivate" << std::endl; } void ScreenSaverDeactivate() { std::cout << "ScreenSaverDeactivate" << std::endl; } diff --git a/tests/test_mock_session_manager.h b/tests/test_mock_session_manager.h index 97f5e26ee..844f5dbe3 100644 --- a/tests/test_mock_session_manager.h +++ b/tests/test_mock_session_manager.h @@ -34,6 +34,7 @@ struct MockManager : Manager MOCK_CONST_METHOD0(UserName, std::string()); MOCK_CONST_METHOD0(HostName, std::string()); MOCK_CONST_METHOD1(UserIconFile, void(ReplyCallback const&)); + MOCK_CONST_METHOD0(GetAutomaticLogin, bool()); MOCK_METHOD0(ScreenSaverActivate, void()); MOCK_METHOD0(ScreenSaverDeactivate, void()); |
