Skip to content

Commit

Permalink
Move the DBus enablers to nemo-qml-plugin-dbus.
Browse files Browse the repository at this point in the history
  • Loading branch information
adenexter committed Oct 7, 2016
1 parent 267337a commit 592aee5
Show file tree
Hide file tree
Showing 32 changed files with 238 additions and 740 deletions.
7 changes: 5 additions & 2 deletions rpm/nemo-qml-plugin-devicelock.spec
Expand Up @@ -11,8 +11,9 @@ BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(keepalive)
BuildRequires: pkgconfig(mce)
BuildRequires: pkgconfig(libsystemd-daemon)
BuildRequires: pkgconfig(mce)
BuildRequires: pkgconfig(nemodbus)
Obsoletes: nemo-qml-plugin-devicelock-default < 0.2.0
Requires: nemo-devicelock-daemon

Expand All @@ -32,6 +33,7 @@ Provides: nemo-devicelock-daemon = %{version}-%{release}
Summary: Development libraries for device lock
Group: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: pkgconfig(nemodbus)

%description devel
%{summary}.
Expand All @@ -41,8 +43,9 @@ Summary: Development libraries for device lock daemons
Group: Development/Libraries
Requires: %{name}-devel = %{version}-%{release}
Requires: pkgconfig(keepalive)
Requires: pkgconfig(mce)
Requires: pkgconfig(libsystemd-daemon)
Requires: pkgconfig(mce)
Requires: pkgconfig(nemodbus)

%description host-devel
%{summary}.
Expand Down
1 change: 1 addition & 0 deletions src/daemon/daemon.pro
Expand Up @@ -11,6 +11,7 @@ CONFIG += \
PKGCONFIG += \
dbus-1 \
keepalive \
nemodbus \
libsystemd-daemon

INCLUDEPATH += \
Expand Down
14 changes: 7 additions & 7 deletions src/nemo-devicelock/authenticator.cpp
Expand Up @@ -79,8 +79,13 @@ Authenticator::Authenticator(QObject *parent)
connect(m_settings.data(), &SettingsWatcher::inputIsKeyboardChanged,
this, &Authenticator::codeInputIsKeyboardChanged);

connect(m_connection.data(), &Connection::connected, this, &Authenticator::connected);
connect(m_connection.data(), &Connection::disconnected, this, &Authenticator::disconnected);
m_connection->onConnected(this, [this] {
connected();
});

m_connection->onDisconnected(this, [this] {
handleError(SoftwareError);
});

if (m_connection->isConnected()) {
connected();
Expand Down Expand Up @@ -224,9 +229,4 @@ void Authenticator::connected()
});
}

void Authenticator::disconnected()
{
handleError(SoftwareError);
}

}
1 change: 0 additions & 1 deletion src/nemo-devicelock/authenticator.h
Expand Up @@ -131,7 +131,6 @@ class NEMODEVICELOCK_EXPORT Authenticator : public QObject, private ConnectionCl
friend class AuthenticatorAdaptor;

inline void connected();
inline void disconnected();

inline void handleAuthentication(const QVariant &authenticationToken);
inline void handleFeedback(Feedback feedback, int attemptsRemaining, Methods utilizedMethods);
Expand Down
6 changes: 4 additions & 2 deletions src/nemo-devicelock/devicelock.cpp
Expand Up @@ -24,7 +24,7 @@ DeviceLock::DeviceLock(QObject *parent)
: QObject(parent)
, ConnectionClient(
this, QStringLiteral("/devicelock/lock"), QStringLiteral("org.nemomobile.devicelock.DeviceLock"))
, m_authorization(m_localPath, m_remotePath)
, m_authorization(m_localPath, path())
, m_authorizationAdaptor(&m_authorization, this)
, m_settings(SettingsWatcher::instance())
, m_state(Undefined)
Expand All @@ -35,7 +35,9 @@ DeviceLock::DeviceLock(QObject *parent)
connect(this, &DeviceLock::enabledChanged,
this, &DeviceLock::automaticLockingChanged);

connect(m_connection.data(), &Connection::connected, this, &DeviceLock::connected);
m_connection->onConnected(this, [this] {
connected();
});

if (m_connection->isConnected()) {
connected();
Expand Down
6 changes: 4 additions & 2 deletions src/nemo-devicelock/devicelocksettings.cpp
Expand Up @@ -43,7 +43,7 @@ DeviceLockSettings::DeviceLockSettings(QObject *parent)
this,
QStringLiteral("/devicelock/settings"),
QStringLiteral("org.nemomobile.devicelock.DeviceLock.Settings"))
, m_authorization(m_localPath, m_remotePath)
, m_authorization(m_localPath, path())
, m_authorizationAdaptor(&m_authorization, this)
, m_settings(SettingsWatcher::instance())
{
Expand All @@ -62,7 +62,9 @@ DeviceLockSettings::DeviceLockSettings(QObject *parent)
connect(m_settings.data(), &SettingsWatcher::currentCodeIsDigitOnlyChanged,
this, &DeviceLockSettings::currentCodeIsDigitOnlyChanged);

connect(m_connection.data(), &Connection::connected, this, &DeviceLockSettings::connected);
m_connection->onConnected(this, [this] {
connected();
});

if (m_connection->isConnected()) {
connected();
Expand Down
12 changes: 7 additions & 5 deletions src/nemo-devicelock/devicereset.cpp
Expand Up @@ -41,14 +41,16 @@ DeviceReset::DeviceReset(QObject *parent)
this,
QStringLiteral("/devicereset"),
QStringLiteral("org.nemomobile.devicelock.DeviceReset"))
, m_authorization(m_localPath, m_remotePath)
, m_authorization(m_localPath, path())
, m_authorizationAdaptor(&m_authorization, this)
{
connect(m_connection.data(), &Connection::connected, this, &DeviceReset::connected);
m_connection->onConnected(this, [this] {
connected();
});

if (m_connection->isConnected()) {
connected();
}
if (m_connection->isConnected()) {
connected();
}
}

DeviceReset::~DeviceReset()
Expand Down
16 changes: 14 additions & 2 deletions src/nemo-devicelock/encryptionsettings.cpp
Expand Up @@ -42,11 +42,14 @@ EncryptionSettings::EncryptionSettings(QObject *parent)
this,
QStringLiteral("/encryption"),
QStringLiteral("org.nemomobile.devicelock.EncryptionSettings"))
, m_authorization(m_localPath, m_remotePath)
, m_authorization(m_localPath, path())
, m_authorizationAdaptor(&m_authorization, this)
, m_settings(SettingsWatcher::instance())
, m_supported(false)
{
connect(m_connection.data(), &Connection::connected, this, &EncryptionSettings::connected);
m_connection->onConnected(this, [this] {
connected();
});

if (m_connection->isConnected()) {
connected();
Expand All @@ -67,6 +70,11 @@ bool EncryptionSettings::isHomeEncrypted() const
return m_settings->isHomeEncrypted;
}

bool EncryptionSettings::isSupported() const
{
return m_supported;
}

void EncryptionSettings::encryptHome(const QVariant &authenticationToken)
{
if (m_authorization.status() == Authorization::ChallengeIssued) {
Expand All @@ -84,6 +92,10 @@ void EncryptionSettings::encryptHome(const QVariant &authenticationToken)
void EncryptionSettings::connected()
{
void registerObject();

subscribeToProperty<bool>(QStringLiteral("Supported"), [this](bool supported) {
m_supported = supported;
});
}

}
5 changes: 5 additions & 0 deletions src/nemo-devicelock/encryptionsettings.h
Expand Up @@ -45,12 +45,16 @@ class NEMODEVICELOCK_EXPORT EncryptionSettings : public QObject, private Connect
Q_OBJECT
Q_PROPERTY(NemoDeviceLock::Authorization *authorization READ authorization CONSTANT)
Q_PROPERTY(bool homeEncrypted READ isHomeEncrypted CONSTANT) // One way operation, determined at startup.
Q_PROPERTY(bool supported READ isSupported CONSTANT)

public:
explicit EncryptionSettings(QObject *parent = nullptr);
~EncryptionSettings();

Authorization *authorization();

bool isSupported() const;

bool isHomeEncrypted() const;

Q_INVOKABLE void encryptHome(const QVariant &authenticationToken);
Expand All @@ -65,6 +69,7 @@ class NEMODEVICELOCK_EXPORT EncryptionSettings : public QObject, private Connect
ClientAuthorization m_authorization;
ClientAuthorizationAdaptor m_authorizationAdaptor;
QExplicitlySharedDataPointer<SettingsWatcher> m_settings;
bool m_supported;
};

}
Expand Down
39 changes: 21 additions & 18 deletions src/nemo-devicelock/fingerprintsensor.cpp
Expand Up @@ -71,10 +71,12 @@ FingerprintModel::FingerprintModel(QObject *parent)
this,
QStringLiteral("/fingerprint/settings"),
QStringLiteral("org.nemomobile.devicelock.Fingerprint.Settings"))
, m_authorization(m_localPath, m_remotePath)
, m_authorization(m_localPath, path())
, m_authorizationAdaptor(&m_authorization, this)
{
connect(m_connection.data(), &Connection::connected, this, &FingerprintModel::connected);
m_connection->onConnected(this, [this] {
connected();
});

if (m_connection->isConnected()) {
connected();
Expand Down Expand Up @@ -142,8 +144,9 @@ void FingerprintModel::connected()
{
registerObject();

subscribeToProperty<QVector<Fingerprint>>(
QStringLiteral("Fingerprints"), [this](const QVector<Fingerprint> fingerprints) {
subscribeToProperty<QVector<NemoDeviceLock::Fingerprint>>(
QStringLiteral("Fingerprints"), [this](const QVector<Fingerprint> &fingerprints) {

int index;
for (index = 0; index < fingerprints.count(); ++index) {
const auto &fingerprint = fingerprints.at(index);
Expand Down Expand Up @@ -220,16 +223,27 @@ FingerprintSensor::FingerprintSensor(QObject *parent)
this,
QStringLiteral("/fingerprint/sensor"),
QStringLiteral("org.nemomobile.devicelock.Fingerprint.Sensor"))
, m_authorization(m_localPath, m_remotePath)
, m_authorization(m_localPath, path())
, m_authorizationAdaptor(&m_authorization, this)
, m_settingsAdaptor(this)
, m_samplesRemaining(0)
, m_samplesRequired(0)
, m_hasSensor(false)
, m_isAcquiring(false)
{
connect(m_connection.data(), &Connection::connected, this, &FingerprintSensor::connected);
connect(m_connection.data(), &Connection::disconnected, this, &FingerprintSensor::disconnected);
m_connection->onConnected(this, [this] {
connected();
});

m_connection->onDisconnected(this, [this] {
m_samplesRemaining = 0;
m_samplesRequired = 0;
m_isAcquiring = false;

emit acquiringChanged();
emit samplesRequiredChanged();
emit samplesRemainingChanged();
});

if (m_connection->isConnected()) {
connected();
Expand Down Expand Up @@ -357,15 +371,4 @@ void FingerprintSensor::connected()
});
}

void FingerprintSensor::disconnected()
{
m_samplesRemaining = 0;
m_samplesRequired = 0;
m_isAcquiring = false;

emit acquiringChanged();
emit samplesRequiredChanged();
emit samplesRemainingChanged();
}

}
1 change: 0 additions & 1 deletion src/nemo-devicelock/fingerprintsensor.h
Expand Up @@ -165,7 +165,6 @@ class NEMODEVICELOCK_EXPORT FingerprintSensor : public QObject, private Connecti
friend class FingerprintSensorAdaptor;

inline void connected();
inline void disconnected();

inline void handleSampleAcquired(int samplesRemaining);
inline void handleAcquisitionCompleted();
Expand Down
4 changes: 2 additions & 2 deletions src/nemo-devicelock/host/cli/cliauthenticator.cpp
Expand Up @@ -32,7 +32,6 @@

#include "cliauthenticator.h"

#include "dbusutilities.h"
#include "lockcodewatcher.h"

#include <QDBusMessage>
Expand Down Expand Up @@ -92,7 +91,8 @@ Authenticator::Methods CliAuthenticator::authenticate(

// Send the reply first then follow up with the authenticated message.
QDBusContext::setDelayedReply(true);
QDBusContext::connection().send(QDBusContext::message().createReply(marshallArguments(uint(0))));
QDBusContext::connection().send(QDBusContext::message().createReply(
NemoDBus::marshallArguments(uint(0))));

sendAuthenticated(connection, authenticator, QStringLiteral("12345"));
return Authenticator::Methods();
Expand Down
17 changes: 17 additions & 0 deletions src/nemo-devicelock/host/cli/cliencryptionsettings.cpp
Expand Up @@ -43,13 +43,30 @@ namespace NemoDeviceLock
CliEncryptionSettings::CliEncryptionSettings(QObject *parent)
: HostEncryptionSettings(Authenticator::LockCode, parent)
, m_watcher(LockCodeWatcher::instance())
, m_supportQuery(m_watcher->runPlugin(this, QStringList() << QStringLiteral("--is-encryption-supported")))
, m_supported(false)
{
m_supportQuery->onSuccess([this]() {
m_supportQuery = nullptr;
m_supported = true;
});
m_supportQuery->onFailure([this](int) {
m_supportQuery = nullptr;
});
}

CliEncryptionSettings::~CliEncryptionSettings()
{
}

bool CliEncryptionSettings::isSupported() const
{
if (m_supportQuery) {
m_supportQuery->waitForFinished();
}
return m_supported;
}

void CliEncryptionSettings::encryptHome(const QString &, const QVariant &authenticationToken)
{
if (PluginCommand *command = m_watcher->runPlugin(this, QStringList()
Expand Down
4 changes: 4 additions & 0 deletions src/nemo-devicelock/host/cli/cliencryptionsettings.h
Expand Up @@ -41,17 +41,21 @@ namespace NemoDeviceLock
{

class LockCodeWatcher;
class PluginCommand;

class CliEncryptionSettings : public HostEncryptionSettings
{
public:
explicit CliEncryptionSettings(QObject *parent = nullptr);
~CliEncryptionSettings();

bool isSupported() const override;
void encryptHome(const QString &requestor, const QVariant &authenticationToken) override;

private:
QExplicitlySharedDataPointer<LockCodeWatcher> m_watcher;
PluginCommand *m_supportQuery;
bool m_supported;
};

}
Expand Down
7 changes: 3 additions & 4 deletions src/nemo-devicelock/host/hostauthenticator.cpp
Expand Up @@ -32,7 +32,6 @@

#include "hostauthenticator.h"

#include "dbusutilities.h"
#include "settingswatcher.h"

namespace NemoDeviceLock
Expand Down Expand Up @@ -92,7 +91,7 @@ int HostAuthenticator::currentAttempts() const
void HostAuthenticator::sendAuthenticated(
const QString &connection, const QString &path, const QVariant &authenticationToken)
{
send(connection, path, clientInterface, QStringLiteral("Authenticated"), authenticationToken);
NemoDBus::send(connection, path, clientInterface, QStringLiteral("Authenticated"), authenticationToken);
}

void HostAuthenticator::sendFeedback(
Expand All @@ -102,7 +101,7 @@ void HostAuthenticator::sendFeedback(
int attemptsRemaining,
Authenticator::Methods utilizedMethods)
{
send(connection,
NemoDBus::send(connection,
path,
clientInterface,
QStringLiteral("Feedback"),
Expand All @@ -114,7 +113,7 @@ void HostAuthenticator::sendFeedback(
void HostAuthenticator::sendError(
const QString &connection, const QString &path, Authenticator::Error error)
{
send(connection, path, clientInterface, QStringLiteral("Error"), uint(error));
NemoDBus::send(connection, path, clientInterface, QStringLiteral("Error"), uint(error));
}

void HostAuthenticator::availableMethodsChanged()
Expand Down

0 comments on commit 592aee5

Please sign in to comment.