Skip to content

Commit

Permalink
[lipstick] Listen to user-managerd for user switching. Contributes to…
Browse files Browse the repository at this point in the history
… JB#49640

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Apr 21, 2020
1 parent 6852d39 commit 1be3c2c
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 3 deletions.
2 changes: 2 additions & 0 deletions rpm/lipstick-qt5.spec
Expand Up @@ -14,6 +14,7 @@ Source0: %{name}-%{version}.tar.bz2
Source1: %{name}.privileges
Requires: mce >= 1.87.0
Requires: pulseaudio-modules-nemo-mainvolume >= 6.0.19
Requires: user-managerd >= 0.3.0
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
BuildRequires: pkgconfig(Qt5Core)
Expand All @@ -40,6 +41,7 @@ BuildRequires: pkgconfig(wayland-server)
BuildRequires: pkgconfig(usb-moded-qt5) >= 1.8
BuildRequires: pkgconfig(systemsettings) >= 0.5.28
BuildRequires: pkgconfig(nemodevicelock)
BuildRequires: pkgconfig(sailfishusermanager)
BuildRequires: qt5-qttools-linguist
BuildRequires: qt5-qtgui-devel >= 5.2.1+git24
BuildRequires: qt5-qtwayland-wayland_egl-devel >= 5.4.0+git26
Expand Down
43 changes: 43 additions & 0 deletions src/devicestate/devicestate.cpp
Expand Up @@ -31,10 +31,13 @@
#include "devicestate_p.h"

#include <dsme/thermalmanager_dbus_if.h>
#include <sailfishusermanagerinterface.h>

#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDBusReply>
#include <QDBusServiceWatcher>
#include <QMetaMethod>


Expand All @@ -46,13 +49,17 @@ DeviceState::DeviceState(QObject *parent)

connect(priv, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)),
this, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)));
connect(priv, SIGNAL(nextUserChanged(uint)),
this, SIGNAL(nextUserChanged(uint)));
}

DeviceState::~DeviceState() {
MEEGO_PRIVATE(DeviceState)

disconnect(priv, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)),
this, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)));
disconnect(priv, SIGNAL(nextUserChanged(uint)),
this, SIGNAL(nextUserChanged(uint)));

MEEGO_UNINITIALIZE(DeviceState);
}
Expand Down Expand Up @@ -101,6 +108,17 @@ void DeviceState::connectNotify(const QMetaMethod &signal) {
thermalmanager_state_change_ind,
priv,
SLOT(emitThermalShutdown(QString)));
priv->userManagerWatcher = new QDBusServiceWatcher(SAILFISH_USERMANAGER_DBUS_INTERFACE,
QDBusConnection::systemBus(),
QDBusServiceWatcher::WatchForRegistration
| QDBusServiceWatcher::WatchForUnregistration,
this);
connect(priv->userManagerWatcher, &QDBusServiceWatcher::serviceRegistered,
this, &DeviceState::connectUserManager);
connect(priv->userManagerWatcher, &QDBusServiceWatcher::serviceUnregistered,
this, &DeviceState::disconnectUserManager);
if (QDBusConnection::systemBus().interface()->isServiceRegistered(SAILFISH_USERMANAGER_DBUS_INTERFACE))
connectUserManager();
}
priv->connectCount[SIGNAL_SYSTEM_STATE]++;
}
Expand Down Expand Up @@ -152,8 +170,33 @@ void DeviceState::disconnectNotify(const QMetaMethod &signal) {
thermalmanager_state_change_ind,
priv,
SLOT(emitThermalShutdown(QString)));
disconnectUserManager();
priv->userManagerWatcher->deleteLater();
priv->userManagerWatcher = nullptr;
}
}
}

void DeviceState::connectUserManager()
{
MEEGO_PRIVATE(DeviceState)
QDBusConnection::systemBus().connect(SAILFISH_USERMANAGER_DBUS_INTERFACE,
SAILFISH_USERMANAGER_DBUS_OBJECT_PATH,
SAILFISH_USERMANAGER_DBUS_INTERFACE,
"aboutToChangeCurrentUser",
priv,
SLOT(emitUserSwitching(uint)));
}

void DeviceState::disconnectUserManager()
{
MEEGO_PRIVATE(DeviceState)
QDBusConnection::systemBus().disconnect(SAILFISH_USERMANAGER_DBUS_INTERFACE,
SAILFISH_USERMANAGER_DBUS_OBJECT_PATH,
SAILFISH_USERMANAGER_DBUS_INTERFACE,
"aboutToChangeCurrentUser",
priv,
SLOT(emitUserChanging(uint)));
}

} // DeviceState namespace
13 changes: 12 additions & 1 deletion src/devicestate/devicestate.h
Expand Up @@ -65,7 +65,8 @@ class DeviceState : public QObject
SaveData, //!< Save data
RebootDeniedUSB, //!< Reboot denied because USB is connected in mass storage mode
ShutdownDeniedUSB, //!< Shutdown denied because USB is connected in mass storage mode
Reboot //!< Reboot
Reboot, //!< Reboot
UserSwitching //!< User switching
};

public:
Expand All @@ -83,10 +84,20 @@ class DeviceState : public QObject
*/
void systemStateChanged(DeviceState::DeviceState::StateIndication what);

/*!
* @brief Sent when user switching happens.
* @param uid User id of the user to switch to
*/
void nextUserChanged(uint uid);

protected:
void connectNotify(const QMetaMethod &signal);
void disconnectNotify(const QMetaMethod &signal);

private slots:
void connectUserManager();
void disconnectUserManager();

private:
Q_DISABLE_COPY(DeviceState)
MEEGO_DECLARE_PRIVATE(DeviceState)
Expand Down
10 changes: 10 additions & 0 deletions src/devicestate/devicestate_p.h
Expand Up @@ -33,6 +33,8 @@

#include <QMutex>

class QDBusServiceWatcher;

#define SIGNAL_SYSTEM_STATE 0

namespace DeviceState
Expand All @@ -46,17 +48,20 @@ namespace DeviceState
public:
DeviceStatePrivate() {
connectCount[SIGNAL_SYSTEM_STATE] = 0;
userManagerWatcher = nullptr;
}

~DeviceStatePrivate() {
}

QMutex connectMutex;
size_t connectCount[1];
QDBusServiceWatcher *userManagerWatcher;

Q_SIGNALS:

void systemStateChanged(DeviceState::DeviceState::StateIndication what);
void nextUserChanged(uint uid);

private Q_SLOTS:

Expand Down Expand Up @@ -96,6 +101,11 @@ namespace DeviceState
emit systemStateChanged(DeviceState::Reboot);
}
}

void emitUserSwitching(uint uid) {
emit nextUserChanged(uid);
emit systemStateChanged(DeviceState::UserSwitching);
}
};
}
#endif // DEVICESTATE_P_H
21 changes: 21 additions & 0 deletions src/shutdownscreen.cpp
Expand Up @@ -25,6 +25,8 @@
#include "homeapplication.h"
#include "shutdownscreen.h"
#include "lipstickqmlpath.h"
#include <pwd.h>
#include <sys/types.h>

ShutdownScreen::ShutdownScreen(QObject *parent) :
QObject(parent),
Expand All @@ -33,6 +35,7 @@ ShutdownScreen::ShutdownScreen(QObject *parent) :
m_systemState(new DeviceState::DeviceState(this))
{
connect(m_systemState, SIGNAL(systemStateChanged(DeviceState::DeviceState::StateIndication)), this, SLOT(applySystemState(DeviceState::DeviceState::StateIndication)));
connect(m_systemState, SIGNAL(nextUserChanged(uint)), this, SLOT(setNextUser(uint)));
}

void ShutdownScreen::setWindowVisible(bool visible)
Expand All @@ -46,6 +49,7 @@ void ShutdownScreen::setWindowVisible(bool visible)
m_window->setContextProperty("initialSize", QGuiApplication::primaryScreen()->size());
m_window->setContextProperty("shutdownScreen", this);
m_window->setContextProperty("shutdownMode", m_shutdownMode);
m_window->setContextProperty("nextUser", m_nextUser);
m_window->setSource(QmlPath::to("system/ShutdownScreen.qml"));
m_window->installEventFilter(new CloseEventEater(this));
}
Expand Down Expand Up @@ -97,11 +101,28 @@ void ShutdownScreen::applySystemState(DeviceState::DeviceState::StateIndication
}
break;

case DeviceState::DeviceState::UserSwitching:
m_shutdownMode = "userswitch";
applySystemState(DeviceState::DeviceState::Shutdown);
break;

default:
break;
}
}

void ShutdownScreen::setNextUser(uint uid)
{
struct passwd *pwd = getpwuid((uid_t)uid);
if (pwd) {
QString name = QString::fromUtf8(pwd->pw_gecos);
int i = name.indexOf(QStringLiteral(","));
if (i != -1)
name.truncate(i);
m_nextUser = name;
}
}

void ShutdownScreen::createAndPublishNotification(const QString &category, const QString &body)
{
NotificationManager *manager = NotificationManager::instance();
Expand Down
10 changes: 10 additions & 0 deletions src/shutdownscreen.h
Expand Up @@ -64,6 +64,13 @@ private slots:
*/
void applySystemState(DeviceState::DeviceState::StateIndication what);

/*!
* Sets nextUser to name of the user that is about to be switched to.
*
* \param uid user id of the user
*/
void setNextUser(uint uid);

private:
/*!
* Shows a system notification.
Expand All @@ -82,6 +89,9 @@ private slots:
//! The shutdown mode to be communicated to the UI
QString m_shutdownMode;

//! Next user to login, empty if the user session is not about to end
QString m_nextUser;

#ifdef UNIT_TEST
friend class Ut_ShutdownScreen;
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/src.pro
Expand Up @@ -154,7 +154,8 @@ PKGCONFIG += \
ngf-qt5 \
systemsettings \
thermalmanager_dbus_if \
usb-moded-qt5
usb-moded-qt5 \
sailfishusermanager

LIBS += -lrt -lEGL

Expand Down
2 changes: 1 addition & 1 deletion tests/ut_shutdownscreen/ut_shutdownscreen.pro
Expand Up @@ -4,7 +4,7 @@ INCLUDEPATH += $$SRCDIR $$NOTIFICATIONSRCDIR $$TOUCHSCREENSRCDIR $$UTILITYSRCDIR
QT += qml quick dbus

CONFIG += link_pkgconfig
PKGCONFIG += dsme_dbus_if thermalmanager_dbus_if usb_moded
PKGCONFIG += dsme_dbus_if thermalmanager_dbus_if usb_moded sailfishusermanager

# unit test and unit
SOURCES += \
Expand Down

0 comments on commit 1be3c2c

Please sign in to comment.