Commit 37788969 authored by Andrew den Exter's avatar Andrew den Exter Committed by Andrew den Exter

[devicelock] Migrate device lock functionality to its own plugin. Contributes to JB#34961

A more comprehensive device lock API will be available from
nemo-qml-plugin-devicelock.
parent 2bc39328
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#include <QObject>
#include <QSettings>
#include <QProcess>
#include <QDebug>
#include "devicelockiface.h"
static bool runPlugin(QStringList args)
{
QSettings s("/usr/share/lipstick/devicelock/devicelock.conf", QSettings::IniFormat);
QString pluginName = s.value("DeviceLock/pluginName").toString();
if (pluginName.isEmpty()) {
qWarning("DeviceLock: no plugin configuration set in /usr/share/lipstick/devicelock/devicelock.conf");
return false;
}
QProcess p;
p.start(pluginName, args);
if (!p.waitForFinished()) {
qWarning("DeviceLock: plugin did not finish in time");
return false;
}
qDebug() << p.readAllStandardOutput();
qWarning() << p.readAllStandardError();
return p.exitCode() == 0;
}
DeviceLockInterface::DeviceLockInterface(QObject *parent)
: QObject(parent),
m_cacheRefreshNeeded(true)
{
}
DeviceLockInterface::~DeviceLockInterface()
{
}
bool DeviceLockInterface::checkCode(const QString &code)
{
return runPlugin(QStringList() << "--check-code" << code);
}
bool DeviceLockInterface::setCode(const QString &oldCode, const QString &newCode)
{
bool return_value = runPlugin(QStringList() << "--set-code" << oldCode << newCode);
if (return_value) {
m_cacheRefreshNeeded = true;
emit isSetChanged();
}
return return_value;
}
bool DeviceLockInterface::clearCode(const QString &currentCode)
{
bool return_value = runPlugin(QStringList() << "--clear-code" << currentCode);
if (return_value) {
m_cacheRefreshNeeded = true;
emit isSetChanged();
}
return return_value;
}
bool DeviceLockInterface::isSet() {
if (m_cacheRefreshNeeded) {
m_codeSet = runPlugin(QStringList() << "--is-set" << "lockcode");
m_cacheRefreshNeeded = false;
}
return m_codeSet;
}
void DeviceLockInterface::refresh()
{
bool wasCodeSet = m_codeSet;
m_codeSet = runPlugin(QStringList() << "--is-set" << "lockcode");
m_cacheRefreshNeeded = false;
if (wasCodeSet != m_codeSet) {
emit isSetChanged();
}
}
bool DeviceLockInterface::clearDevice(const QString &code, ResetMode mode)
{
QStringList parameters;
parameters << "--clear-device" << code;
if (mode == DeviceLockInterface::Reboot) {
parameters << "--reboot";
}
return runPlugin(parameters);
}
/*
* Copyright (C) 2013 Jolla Ltd. <pekka.vuorela@jollamobile.com>
*
* You may use this file under the terms of the BSD license as follows:
*
* "Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Nemo Mobile nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
*/
#ifndef DEVICELOCKINTERFACE_H
#define DEVICELOCKINTERFACE_H
#include <QObject>
#include <QSettings>
#include <QProcess>
#include <QDebug>
#include <systemsettingsglobal.h>
class SYSTEMSETTINGS_EXPORT DeviceLockInterface : public QObject
{
Q_OBJECT
Q_ENUMS(ResetMode)
Q_PROPERTY(bool isSet READ isSet NOTIFY isSetChanged)
public:
enum ResetMode {
Shutdown,
Reboot
};
explicit DeviceLockInterface(QObject *parent = 0);
virtual ~DeviceLockInterface();
Q_INVOKABLE bool checkCode(const QString &code);
Q_INVOKABLE bool setCode(const QString &oldCode, const QString &newCode);
Q_INVOKABLE bool clearCode(const QString &currentCode);
Q_INVOKABLE bool isSet();
Q_INVOKABLE void refresh();
Q_INVOKABLE bool clearDevice(const QString &code, ResetMode mode = Shutdown);
signals:
void isSetChanged();
private:
bool m_codeSet;
bool m_cacheRefreshNeeded;
};
#endif
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
#include "alarmtonemodel.h" #include "alarmtonemodel.h"
#include "displaysettings.h" #include "displaysettings.h"
#include "aboutsettings.h" #include "aboutsettings.h"
#include "devicelockiface.h"
#include "developermodesettings.h" #include "developermodesettings.h"
#include "diskusage.h" #include "diskusage.h"
#include "partitionmodel.h" #include "partitionmodel.h"
...@@ -71,7 +70,6 @@ public: ...@@ -71,7 +70,6 @@ public:
qmlRegisterType<QUsbModed>(uri, 1, 0, "USBSettings"); qmlRegisterType<QUsbModed>(uri, 1, 0, "USBSettings");
qmlRegisterType<AboutSettings>(uri, 1, 0, "AboutSettings"); qmlRegisterType<AboutSettings>(uri, 1, 0, "AboutSettings");
qmlRegisterType<PartitionModel>(uri, 1, 0, "PartitionModel"); qmlRegisterType<PartitionModel>(uri, 1, 0, "PartitionModel");
qmlRegisterType<DeviceLockInterface>(uri, 1, 0, "DeviceLockInterface");
qmlRegisterType<DeveloperModeSettings>(uri, 1, 0, "DeveloperModeSettings"); qmlRegisterType<DeveloperModeSettings>(uri, 1, 0, "DeveloperModeSettings");
qmlRegisterType<CertificateModel>(uri, 1, 0, "CertificateModel"); qmlRegisterType<CertificateModel>(uri, 1, 0, "CertificateModel");
qRegisterMetaType<DeveloperModeSettings::Status>("DeveloperModeSettings::Status"); qRegisterMetaType<DeveloperModeSettings::Status>("DeveloperModeSettings::Status");
......
...@@ -19,7 +19,6 @@ SOURCES += \ ...@@ -19,7 +19,6 @@ SOURCES += \
displaysettings.cpp \ displaysettings.cpp \
aboutsettings.cpp \ aboutsettings.cpp \
certificatemodel.cpp \ certificatemodel.cpp \
devicelockiface.cpp \
developermodesettings.cpp \ developermodesettings.cpp \
diskusage.cpp \ diskusage.cpp \
diskusage_impl.cpp \ diskusage_impl.cpp \
...@@ -36,7 +35,6 @@ PUBLIC_HEADERS = \ ...@@ -36,7 +35,6 @@ PUBLIC_HEADERS = \
displaysettings.h \ displaysettings.h \
aboutsettings.h \ aboutsettings.h \
certificatemodel.h \ certificatemodel.h \
devicelockiface.h \
developermodesettings.h \ developermodesettings.h \
diskusage.h \ diskusage.h \
partition.h \ partition.h \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment