Skip to content

Commit

Permalink
[lipstick] Activate logind session. Contributes to JB#49519
Browse files Browse the repository at this point in the history
Activate logind session when lipstick starts.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Apr 15, 2020
1 parent a8f7b9b commit 0800843
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 4 deletions.
79 changes: 77 additions & 2 deletions src/compositor/lipstickcompositor.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
**
** Copyright (c) 2013-2019 Jolla Ltd.
** Copyright (c) 2019 Open Mobile Platform LLC.
** Copyright (c) 2013 - 2019 Jolla Ltd.
** Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand Down Expand Up @@ -35,10 +35,15 @@
#include <qpa/qwindowsysteminterface.h>
#include "alienmanager/alienmanager.h"
#include "hwcrenderstage.h"
#include "logging.h"
#include <private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformintegration.h>
#include <qmcenameowner.h>
#include <dbus/dbus-protocol.h>
#include <sys/types.h>
#include <systemd/sd-bus.h>
#include <systemd/sd-login.h>
#include <unistd.h>

LipstickCompositor *LipstickCompositor::m_instance = 0;

Expand All @@ -63,6 +68,7 @@ LipstickCompositor::LipstickCompositor()
, m_fakeRepaintTimerId(0)
, m_queuedSetUpdatesEnabledCalls()
, m_mceNameOwner(new QMceNameOwner(this))
, m_sessionActivationTries(0)
{
setColor(Qt::black);
setRetainedSelectionEnabled(true);
Expand Down Expand Up @@ -405,8 +411,77 @@ void LipstickCompositor::onSurfaceDying()
}
}

void LipstickCompositor::activateLogindSession()
{
m_sessionActivationTries++;

if (m_logindSession.isEmpty()) {
/* Find the current session based on uid */
uid_t uid = getuid();
char **sessions = NULL;
uid_t *uids = NULL;
uint count = 0;
if (sd_seat_get_sessions("seat0", &sessions, &uids, &count) > 0) {
for (uint i = 0; i < count; ++i) {
if (uids[i] == uid) {
m_logindSession = sessions[i];
break;
}
}
for (char **s = sessions; *s ; ++s)
free(*s);
}
free(sessions);
free(uids);

if (m_logindSession.isEmpty()) {
qCWarning(lcLipstickCoreLog) << "Could not read session id, could not activate session";
return;
}
}

if (sd_session_is_active(m_logindSession.toUtf8()) > 0) {
qCInfo(lcLipstickCoreLog) << "Session" << m_logindSession << "successfully activated";
return;
}

if (m_sessionActivationTries > 10) {
qCWarning(lcLipstickCoreLog) << "Could not activate session, giving up";
return;
}

QDBusInterface logind(QStringLiteral("org.freedesktop.login1"),
QStringLiteral("/org/freedesktop/login1"),
QStringLiteral("org.freedesktop.login1.Manager"),
QDBusConnection::systemBus());

if (!logind.isValid()) {
qCWarning(lcLipstickCoreLog) << "Logind manager is not a valid interface, could not activate session";
return;
}

qCDebug(lcLipstickCoreLog) << "Activating session on seat0";

QDBusPendingCall call = logind.asyncCall("ActivateSession", m_logindSession);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *call) {
QDBusPendingReply<void> reply = *call;
if (reply.isError()) {
qCWarning(lcLipstickCoreLog) << "Could not activate session:" << reply.error();
} else {
// VT switching may fail without notice, check status again a bit later
QTimer::singleShot(100, this, &LipstickCompositor::activateLogindSession);
}
call->deleteLater();
});

qCDebug(lcLipstickCoreLog) << "Session" << m_logindSession << "is activating";
}

void LipstickCompositor::initialize()
{
activateLogindSession();

TouchScreen *touchScreen = HomeApplication::instance()->touchScreen();
reactOnDisplayStateChanges(TouchScreen::DisplayUnknown, touchScreen->currentDisplayState());
connect(touchScreen, &TouchScreen::displayStateChanged, this, &LipstickCompositor::reactOnDisplayStateChanges);
Expand Down
9 changes: 7 additions & 2 deletions src/compositor/lipstickcompositor.h
@@ -1,7 +1,7 @@
/***************************************************************************
**
** Copyright (c) 2013-2019 Jolla Ltd.
** Copyright (c) 2019 Open Mobile Platform LLC.
** Copyright (c) 2013 - 2019 Jolla Ltd.
** Copyright (c) 2019 - 2020 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand Down Expand Up @@ -228,6 +228,8 @@ private slots:

QQmlComponent *shaderEffectComponent();

void activateLogindSession();

static LipstickCompositor *m_instance;

int m_totalWindowCount;
Expand Down Expand Up @@ -259,6 +261,9 @@ private slots:

QList<QueuedSetUpdatesEnabledCall> m_queuedSetUpdatesEnabledCalls;
QMceNameOwner *m_mceNameOwner;

QString m_logindSession;
uint m_sessionActivationTries;
};

#endif // LIPSTICKCOMPOSITOR_H

0 comments on commit 0800843

Please sign in to comment.