Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'jb43785_updates_enabled_permissions' into 'master'
Accept setUpdatesEnabled calls only from mce

See merge request mer-core/lipstick!131
  • Loading branch information
spiiroin committed Dec 3, 2019
2 parents df532ed + f8d94a7 commit 64545be
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rpm/lipstick-qt5.spec
Expand Up @@ -26,7 +26,7 @@ BuildRequires: pkgconfig(Qt5Sensors)
BuildRequires: pkgconfig(contentaction5)
BuildRequires: pkgconfig(mlite5) >= 0.2.19
BuildRequires: pkgconfig(mce) >= 1.22.0
BuildRequires: pkgconfig(mce-qt5) >= 1.2.0
BuildRequires: pkgconfig(mce-qt5) >= 1.4.0
BuildRequires: pkgconfig(keepalive)
BuildRequires: pkgconfig(dsme_dbus_if) >= 0.63.2
BuildRequires: pkgconfig(thermalmanager_dbus_if)
Expand Down
51 changes: 47 additions & 4 deletions src/compositor/lipstickcompositor.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Aaron Kennedy <aaron.kennedy@jollamobile.com>
** Copyright (c) 2013-2019 Jolla Ltd.
** Copyright (c) 2019 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand Down Expand Up @@ -37,6 +37,8 @@
#include "hwcrenderstage.h"
#include <private/qguiapplication_p.h>
#include <QtGui/qpa/qplatformintegration.h>
#include <qmcenameowner.h>
#include <dbus/dbus-protocol.h>

LipstickCompositor *LipstickCompositor::m_instance = 0;

Expand All @@ -59,6 +61,8 @@ LipstickCompositor::LipstickCompositor()
, m_onUpdatesDisabledUnfocusedWindowId(0)
, m_keymap(0)
, m_fakeRepaintTimerId(0)
, m_queuedSetUpdatesEnabledCalls()
, m_mceNameOwner(new QMceNameOwner(this))
{
setColor(Qt::black);
setRetainedSelectionEnabled(true);
Expand Down Expand Up @@ -97,7 +101,12 @@ LipstickCompositor::LipstickCompositor()

HwcRenderStage::initialize(this);

setUpdatesEnabled(false);
QObject::connect(m_mceNameOwner, &QMceNameOwner::validChanged,
this, &LipstickCompositor::processQueuedSetUpdatesEnabledCalls);
QObject::connect(m_mceNameOwner, &QMceNameOwner::nameOwnerChanged,
this, &LipstickCompositor::processQueuedSetUpdatesEnabledCalls);

setUpdatesEnabledNow(false);
QTimer::singleShot(0, this, SLOT(initialize()));

setClientFullScreenHint(true);
Expand Down Expand Up @@ -759,7 +768,7 @@ void LipstickCompositor::clipboardDataChanged()
overrideSelection(const_cast<QMimeData *>(mimeData));
}

void LipstickCompositor::setUpdatesEnabled(bool enabled)
void LipstickCompositor::setUpdatesEnabledNow(bool enabled)
{
if (m_updatesEnabled != enabled) {
m_updatesEnabled = enabled;
Expand Down Expand Up @@ -801,6 +810,40 @@ void LipstickCompositor::setUpdatesEnabled(bool enabled)
}
}

void LipstickCompositor::setUpdatesEnabled(bool enabled)
{
if (!calledFromDBus()) {
setUpdatesEnabledNow(enabled);
} else {
if (message().isReplyRequired())
setDelayedReply(true);
m_queuedSetUpdatesEnabledCalls.append(QueuedSetUpdatesEnabledCall(connection(), message(), enabled));
QMetaObject::invokeMethod(this, "processQueuedSetUpdatesEnabledCalls", Qt::QueuedConnection);
}
}

void LipstickCompositor::processQueuedSetUpdatesEnabledCalls()
{
if (m_mceNameOwner->valid()) {
while (!m_queuedSetUpdatesEnabledCalls.isEmpty()) {
QueuedSetUpdatesEnabledCall queued(m_queuedSetUpdatesEnabledCalls.takeFirst());
if (queued.m_message.service() != m_mceNameOwner->nameOwner()) {
if (queued.m_message.isReplyRequired()) {
QDBusMessage reply(queued.m_message.createErrorReply(DBUS_ERROR_ACCESS_DENIED,
"Only mce is allowed to call this method"));
queued.m_connection.send(reply);
}
} else {
setUpdatesEnabledNow(queued.m_enable);
if (queued.m_message.isReplyRequired()) {
QDBusMessage reply(queued.m_message.createReply());
queued.m_connection.send(reply);
}
}
}
}
}

void LipstickCompositor::readContent()
{
m_recorder->recordFrame(this);
Expand Down
33 changes: 29 additions & 4 deletions src/compositor/lipstickcompositor.h
@@ -1,7 +1,7 @@
/***************************************************************************
**
** Copyright (C) 2013 Jolla Ltd.
** Contact: Aaron Kennedy <aaron.kennedy@jollamobile.com>
** Copyright (c) 2013-2019 Jolla Ltd.
** Copyright (c) 2019 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
Expand All @@ -25,20 +25,41 @@
#include <QPointer>
#include <QTimer>
#include <MGConfItem>
#include <QDBusConnection>
#include <QDBusContext>
#include <QDBusMessage>

class WindowModel;
class LipstickCompositorWindow;
class LipstickCompositorProcWindow;
class QOrientationSensor;
class LipstickRecorderManager;
class LipstickKeymap;
class QMceNameOwner;

namespace ContentAction {
class Action;
}

class LIPSTICK_EXPORT LipstickCompositor : public QQuickWindow, public QWaylandQuickCompositor,
public QQmlParserStatus
struct QueuedSetUpdatesEnabledCall
{
QueuedSetUpdatesEnabledCall(const QDBusConnection &connection, const QDBusMessage &message, bool enable)
: m_connection(connection)
, m_message(message)
, m_enable(enable)
{
}

QDBusConnection m_connection;
QDBusMessage m_message;
bool m_enable;
};

class LIPSTICK_EXPORT LipstickCompositor
: public QQuickWindow
, public QWaylandQuickCompositor
, public QQmlParserStatus
, public QDBusContext
{
Q_OBJECT
Q_INTERFACES(QQmlParserStatus)
Expand Down Expand Up @@ -118,6 +139,7 @@ class LIPSTICK_EXPORT LipstickCompositor : public QQuickWindow, public QWaylandQ

bool completed();

void setUpdatesEnabledNow(bool enabled);
void setUpdatesEnabled(bool enabled);
QWaylandSurfaceView *createView(QWaylandSurface *surf) Q_DECL_OVERRIDE;

Expand Down Expand Up @@ -183,6 +205,7 @@ private slots:
void onSurfaceDying();
void updateKeymap();
void initialize();
void processQueuedSetUpdatesEnabledCalls();

private:
friend class LipstickCompositorWindow;
Expand Down Expand Up @@ -234,6 +257,8 @@ private slots:
LipstickKeymap *m_keymap;
int m_fakeRepaintTimerId;

QList<QueuedSetUpdatesEnabledCall> m_queuedSetUpdatesEnabledCalls;
QMceNameOwner *m_mceNameOwner;
};

#endif // LIPSTICKCOMPOSITOR_H
20 changes: 19 additions & 1 deletion tests/stubs/lipstickcompositor_stub.h
@@ -1,3 +1,18 @@
/***************************************************************************
**
** Copyright (c) 2013-2019 Jolla Ltd.
** Copyright (c) 2019 Open Mobile Platform LLC.
**
** This file is part of lipstick.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#ifndef LIPSTICKCOMPOSITOR_STUB
#define LIPSTICKCOMPOSITOR_STUB

Expand Down Expand Up @@ -374,7 +389,6 @@ QWaylandSurfaceView *LipstickCompositorStub::createView(QWaylandSurface *surf)
LipstickCompositorStub gDefaultLipstickCompositorStub;
LipstickCompositorStub *gLipstickCompositorStub = &gDefaultLipstickCompositorStub;


// 4. CREATE A PROXY WHICH CALLS THE STUB
LipstickCompositor::LipstickCompositor()
{
Expand Down Expand Up @@ -633,4 +647,8 @@ QWaylandQuickCompositor::QWaylandQuickCompositor(QQuickWindow *, const char *, Q
{
}

void LipstickCompositor::processQueuedSetUpdatesEnabledCalls()
{
}

#endif

0 comments on commit 64545be

Please sign in to comment.