Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[factoryreset] Add an option to completely wipe factory reset partiti…
…ons. Contributes to JB#37515
  • Loading branch information
adenexter committed Feb 20, 2017
1 parent 0c31122 commit 2a5b486
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
15 changes: 12 additions & 3 deletions src/nemo-devicelock/devicereset.cpp
Expand Up @@ -40,6 +40,14 @@ namespace NemoDeviceLock
\brief The DeviceReset class provides an interface for requesting the device be reset to factory settings.
*/

/*!
\enum NemoDeviceLock::DeviceReset::Option
\value Shutdown Shutdown the device after reset.
\value Reboot Reboot the device after reset.
\value WipePartitions Zero all bytes not overwritten by the factory image.
*/

/*!
Constructs a new device reset instance which is a child of \a parent.
*/
Expand Down Expand Up @@ -85,15 +93,16 @@ Authorization *DeviceReset::authorization()
/*!
Requests a reset of the device to factory settings.
Depending on the \a mode the device may be restarted or shutdown once the reset is completed.
Use the \a options parameter to supply Additional instructions like whether to reboot the device
after a reset is compleleted or if the data partitions should be completely wiped .
The reset authorization challenge code must be authenticated before this is called and the
\a authenticationToken produced passed as an argument.
*/
void DeviceReset::clearDevice(const QVariant &authenticationToken, ResetMode mode)
void DeviceReset::clearDevice(const QVariant &authenticationToken, Options options)
{
if (m_authorization.status() == Authorization::ChallengeIssued) {
auto response = call(QStringLiteral("ClearDevice"), m_localPath, authenticationToken, uint(mode));
auto response = call(QStringLiteral("ClearDevice"), m_localPath, authenticationToken, uint(options));

response->onFinished([this]() {
emit clearingDevice();
Expand Down
14 changes: 9 additions & 5 deletions src/nemo-devicelock/devicereset.h
Expand Up @@ -42,19 +42,21 @@ class NEMODEVICELOCK_EXPORT DeviceReset : public QObject, private ConnectionClie
{
Q_OBJECT
Q_PROPERTY(NemoDeviceLock::Authorization *authorization READ authorization CONSTANT)
Q_ENUMS(ResetMode)
public:
enum ResetMode {
Shutdown,
Reboot
enum Option {
Shutdown = 0x00,
Reboot = 0x01,
WipePartitions = 0x02
};
Q_DECLARE_FLAGS(Options, Option)
Q_FLAG(Options)

explicit DeviceReset(QObject *parent = nullptr);
~DeviceReset();

Authorization *authorization();

Q_INVOKABLE void clearDevice(const QVariant &authenticationToken, ResetMode mode = Shutdown);
Q_INVOKABLE void clearDevice(const QVariant &authenticationToken, Options options = Shutdown);

signals:
void clearingDevice();
Expand All @@ -69,4 +71,6 @@ class NEMODEVICELOCK_EXPORT DeviceReset : public QObject, private ConnectionClie

}

Q_DECLARE_OPERATORS_FOR_FLAGS(NemoDeviceLock::DeviceReset::Options)

#endif
7 changes: 5 additions & 2 deletions src/nemo-devicelock/host/cli/clidevicereset.cpp
Expand Up @@ -52,14 +52,17 @@ CliDeviceReset::~CliDeviceReset()
}

void CliDeviceReset::clearDevice(
const QString &, const QVariant &authenticationToken, DeviceReset::ResetMode mode)
const QString &, const QVariant &authenticationToken, DeviceReset::Options options)
{
QStringList arguments = QStringList()
<< QStringLiteral("--clear-device")
<< authenticationToken.toString();
if (mode == DeviceReset::Reboot) {
if (options & DeviceReset::Reboot) {
arguments << QStringLiteral("--reboot");
}
if (options & DeviceReset::WipePartitions) {
arguments << QStringLiteral("--wipe");
}

if (m_watcher->runPlugin(arguments) != HostAuthenticationInput::Success) {
QDBusContext::sendErrorReply(QDBusError::InternalError);
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/cli/clidevicereset.h
Expand Up @@ -49,7 +49,7 @@ class CliDeviceReset : public HostDeviceReset
~CliDeviceReset();

void clearDevice(
const QString &requestor, const QVariant &authenticationToken, DeviceReset::ResetMode mode);
const QString &requestor, const QVariant &authenticationToken, DeviceReset::Options options);

private:
QExplicitlySharedDataPointer<LockCodeWatcher> m_watcher;
Expand Down
4 changes: 2 additions & 2 deletions src/nemo-devicelock/host/hostdevicereset.cpp
Expand Up @@ -44,7 +44,7 @@ HostDeviceResetAdaptor::HostDeviceResetAdaptor(HostDeviceReset *reset)
void HostDeviceResetAdaptor::ClearDevice(
const QDBusObjectPath &path, const QDBusVariant &authenticationToken, uint mode)
{
m_reset->clearDevice(path.path(), authenticationToken.variant(), DeviceReset::ResetMode(mode));
m_reset->clearDevice(path.path(), authenticationToken.variant(), DeviceReset::Options(mode));
}

HostDeviceReset::HostDeviceReset(QObject *parent)
Expand All @@ -62,7 +62,7 @@ HostDeviceReset::~HostDeviceReset()
{
}

void HostDeviceReset::clearDevice(const QString &, const QVariant &, DeviceReset::ResetMode)
void HostDeviceReset::clearDevice(const QString &, const QVariant &, DeviceReset::Options)
{
QDBusContext::sendErrorReply(QDBusError::NotSupported);
}
Expand Down
2 changes: 1 addition & 1 deletion src/nemo-devicelock/host/hostdevicereset.h
Expand Up @@ -66,7 +66,7 @@ class HostDeviceReset : public HostAuthorization

protected:
virtual void clearDevice(
const QString &client, const QVariant &authenticationToken, DeviceReset::ResetMode mode);
const QString &client, const QVariant &authenticationToken, DeviceReset::Options mode);

private:
friend class HostDeviceResetAdaptor;
Expand Down

0 comments on commit 2a5b486

Please sign in to comment.