summaryrefslogtreecommitdiffstats
path: root/src/lib/qotaclient.cpp
blob: feb5bb00a0b16653f912c68fcae2c27129837805 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the Qt OTA Update module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qotaclientasync_p.h"
#include "qotaclient_p.h"
#include "qotarepositoryconfig_p.h"
#include "qotarepositoryconfig.h"
#include "qotaclient.h"

#include <QtCore/QFile>
#include <QtCore/QJsonObject>
#include <QtCore/QDir>
#include <QtCore/QThread>

QT_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(qota, "b2qt.ota", QtWarningMsg)

const QString repoConfigPath(QStringLiteral("/etc/ostree/remotes.d/qt-os.conf"));

QOtaClientPrivate::QOtaClientPrivate(QOtaClient *client) :
    q_ptr(client),
    m_updateAvailable(false),
    m_rollbackAvailable(false),
    m_restartRequired(false)
{
    // https://github.com/ostreedev/ostree/issues/480
    m_otaEnabled = QFile().exists(QStringLiteral("/ostree/deploy"));
    if (m_otaEnabled) {
        m_otaAsyncThread = new QThread();
        m_otaAsyncThread->start();
        m_otaAsync.reset(new QOtaClientAsync());
        m_otaAsync->moveToThread(m_otaAsyncThread);
    }
}

QOtaClientPrivate::~QOtaClientPrivate()
{
    if (m_otaEnabled) {
        if (m_otaAsyncThread->isRunning()) {
            m_otaAsyncThread->quit();
            if (!Q_UNLIKELY(m_otaAsyncThread->wait(4000)))
                qCWarning(qota) << "Timed out waiting for worker thread to exit.";
        }
        delete m_otaAsyncThread;
    }
}

static void updateInfoMembers(const QJsonDocument &json, QByteArray *info, QString *version, QString *description)
{
    if (json.isNull())
        return;

    *info = json.toJson();
    QJsonObject root = json.object();
    *version = root.value(QStringLiteral("version")).toString(QStringLiteral("unknown"));
    *description = root.value(QStringLiteral("description")).toString(QStringLiteral("unknown"));
}

void QOtaClientPrivate::handleStateChanges()
{
    Q_Q(QOtaClient);

    bool updateAvailable = m_defaultRev != m_remoteRev && m_remoteRev != m_bootedRev;
    if (m_updateAvailable != updateAvailable) {
        m_updateAvailable = updateAvailable;
        emit q->updateAvailableChanged(m_updateAvailable);
    }

    bool restartRequired = m_bootedRev != m_defaultRev;
    if (m_restartRequired != restartRequired) {
        m_restartRequired = restartRequired;
        emit q->restartRequiredChanged(m_restartRequired);
    }
}

void QOtaClientPrivate::setBootedInfo(QString &bootedRev, const QJsonDocument &bootedInfo)
{
    Q_Q(QOtaClient);
    m_bootedRev = bootedRev;
    updateInfoMembers(bootedInfo, &m_bootedInfo, &m_bootedVersion, &m_bootedDescription);
}

void QOtaClientPrivate::statusStringChanged(const QString &status)
{
    Q_Q(QOtaClient);
    m_status = status;
    emit q->statusStringChanged(m_status);
}

void QOtaClientPrivate::errorOccurred(const QString &error)
{
    Q_Q(QOtaClient);
    m_error = error;
    emit q->errorOccurred(m_error);
}

bool QOtaClientPrivate::verifyPathExist(const QString &path)
{
    if (!QDir().exists(path)) {
        errorOccurred(path + QLatin1String(" does not exist"));
        return false;
    }
    return true;
}

void QOtaClientPrivate::rollbackInfoChanged(const QString &rollbackRev, const QJsonDocument &rollbackInfo, int treeCount)
{
    Q_Q(QOtaClient);
    if (!m_rollbackAvailable && treeCount > 1) {
        m_rollbackAvailable = true;
        emit q->rollbackAvailableChanged();
    }
    m_rollbackRev = rollbackRev;
    updateInfoMembers(rollbackInfo, &m_rollbackInfo, &m_rollbackVersion, &m_rollbackDescription);
    q->rollbackInfoChanged();
}

void QOtaClientPrivate::remoteInfoChanged(const QString &remoteRev, const QJsonDocument &remoteInfo)
{
    Q_Q(QOtaClient);
    if (m_remoteRev == remoteRev)
        return;

    m_remoteRev = remoteRev;
    updateInfoMembers(remoteInfo, &m_remoteInfo, &m_remoteVersion, &m_remoteDescription);
    handleStateChanges();

    emit q->remoteInfoChanged();
}

void QOtaClientPrivate::defaultRevisionChanged(const QString &defaultRevision)
{
    if (m_defaultRev == defaultRevision)
        return;

    m_defaultRev = defaultRevision;
    handleStateChanges();
}

/*!
    \class QOtaClient
    \inmodule qtotaupdate
    \brief Main interface to the OTA functionality.

    QOtaClient
//! [client-description]
    provides an API to execute Over-the-Air update tasks. Offline
    operations include querying the booted and rollback system version details,
    and atomically performing rollbacks. Online operations include fetching a
    new system version from a remote server, and atomically performing system
    updates. Using this API is safe and won't leave the system in an inconsistent
    state, even if the power fails half-way through.

    A remote needs to be configured for a device to be able to locate a server
    that is hosting an OTA update, see setRepositoryConfig().

    When utilizing this API from several processes, precautions need to be taken
    to ensure that the processes' view of the system state and metadata is up to date.
    This can be achieved by using any IPC mechanism of choice to ensure that this
    information is being modified by only a single process at a time.

    Methods that modify the system's state and/or metadata are marked as such. In a
    multi-process scenario, refreshInfo() updates the processes' view of the system state
    and metadata. A typical example would be a daemon that periodically checks a remote
    server (with fetchRemoteInfo()) for system updates, and then uses IPC (such as a push
    notification) to let the system's main GUI know when a new version is available.

//! [client-description]
*/

/*!
    \fn void QOtaClient::fetchRemoteInfoFinished(bool success)

    A notifier signal for fetchRemoteInfo(). The \a success argument indicates
    whether the operation was successful.
*/

/*!
    \fn void QOtaClient::updateFinished(bool success)

    A notifier signal for update(). The \a success argument indicates whether
    the operation was successful.
*/

/*!
    \fn void QOtaClient::rollbackFinished(bool success)

    This is a notifier signal for rollback(). The \a success argument
    indicates whether the operation was successful.
*/

/*!
    \fn void QOtaClient::updateOfflineFinished(bool success)

    This is a notifier signal for updateOffline(). The \a success argument
    indicates whether the operation was successful.
*/

/*!
    \fn void QOtaClient::updateRemoteInfoOfflineFinished(bool success)

    This is a notifier signal for updateRemoteInfoOffline(). The \a success argument
    indicates whether the operation was successful.
*/

/*!
    \fn void QOtaClient::remoteInfoChanged()
//! [remoteinfochanged-description]
    Remote info can change when calling fetchRemoteInfo() or updateRemoteInfoOffline().
    If OTA metadata on the remote server is different from the local cache, the local
    cache is updated and this signal is emitted.
//! [remoteinfochanged-description]
*/

/*!
    \fn void QOtaClient::rollbackInfoChanged()

    This signal is emitted when rollback info changes. Rollback info changes
    when calling rollback().
*/

/*!
    \fn void QOtaClient::updateAvailableChanged(bool available)

    This signal is emitted when the value of updateAvailable changes. The
    \a available argument holds whether a system update is available for
    the default system.
*/

/*!
    \fn void QOtaClient::rollbackAvailableChanged()

    This signal is emitted when the value of rollbackAvailable changes. A rollback
    system becomes available when a device has performed at least one system update.
*/

/*!
    \fn void QOtaClient::restartRequiredChanged(bool required)

    This signal is emitted when the value of restartRequired changes. The
    \a required argument holds whether a reboot is required.
*/

/*!
    \fn void QOtaClient::statusStringChanged(const QString &status)
//! [statusstringchanged-description]
    This signal is emitted when an additional status information is available
    (for example, when a program is busy performing a long operation). The
    \a status argument holds the status message.
//! [statusstringchanged-description]
*/

/*!
    \fn void QOtaClient::errorOccurred(const QString &error)

    This signal is emitted when an error occurs. The \a error argument holds
    the error message.
*/

/*!
    \fn void QOtaClient::repositoryConfigChanged(QOtaRepositoryConfig *repository)

    This signal is emitted when the configuration file was updated (\a repository
    holds a pointer to the new configuration) or removed (\a repository holds the
    \c nullptr value).
*/

QOtaClient::QOtaClient() :
    d_ptr(new QOtaClientPrivate(this))
{
    Q_D(QOtaClient);
    if (d->m_otaEnabled) {
        QOtaClientAsync *async = d->m_otaAsync.data();
        connect(async, &QOtaClientAsync::fetchRemoteInfoFinished, this, &QOtaClient::fetchRemoteInfoFinished);
        connect(async, &QOtaClientAsync::updateFinished, this, &QOtaClient::updateFinished);
        connect(async, &QOtaClientAsync::rollbackFinished, this, &QOtaClient::rollbackFinished);
        connect(async, &QOtaClientAsync::updateOfflineFinished, this, &QOtaClient::updateOfflineFinished);
        connect(async, &QOtaClientAsync::updateRemoteInfoOfflineFinished, this, &QOtaClient::updateRemoteInfoOfflineFinished);
        connect(async, &QOtaClientAsync::errorOccurred, d, &QOtaClientPrivate::errorOccurred);
        connect(async, &QOtaClientAsync::statusStringChanged, d, &QOtaClientPrivate::statusStringChanged);
        connect(async, &QOtaClientAsync::rollbackInfoChanged, d, &QOtaClientPrivate::rollbackInfoChanged);
        connect(async, &QOtaClientAsync::remoteInfoChanged, d, &QOtaClientPrivate::remoteInfoChanged);
        connect(async, &QOtaClientAsync::defaultRevisionChanged, d, &QOtaClientPrivate::defaultRevisionChanged);
        d->m_otaAsync->refreshInfo(d);
    }
}

QOtaClient::~QOtaClient()
{
    delete d_ptr;
}

/*!
    Returns a singleton instance of QOtaClient.
*/
QOtaClient& QOtaClient::instance()
{
    static QOtaClient otaClient;
    return otaClient;
}

/*!
//! [fetchremoteinfo-description]
    Fetches OTA metadata from a remote server and updates the local metadata
    cache. This metadata contains information on what system version is available
    on a server. The cache is persistent as it is stored on the disk.

    This method is asynchronous and returns immediately. The return value
    holds whether the operation was started successfully.

    \note This method mutates system's state/metadata.
//! [fetchremoteinfo-description]

    \sa fetchRemoteInfoFinished(), updateAvailable, remoteInfo
*/
bool QOtaClient::fetchRemoteInfo()
{
    Q_D(QOtaClient);
    if (!d->m_otaEnabled)
        return false;

    d->m_otaAsync->fetchRemoteInfo();
    return true;
}

/*!
//! [update-description]
    Fetches an OTA update from a remote and performs the system update.

    This method is asynchronous and returns immediately. The return value
    holds whether the operation was started successfully.

    \note This method mutates system's state/metadata.
//! [update-description]

    \sa updateFinished(), fetchRemoteInfo, restartRequired, setRepositoryConfig
*/
bool QOtaClient::update()
{

    Q_D(const QOtaClient);
    if (!d->m_otaEnabled || !updateAvailable())
        return false;

    d->m_otaAsync->update(d->m_remoteRev);
    return true;
}

/*!
    Rollback to the previous system version.

    This method is asynchronous and returns immediately. The return value
    holds whether the operation was started successfully.

    \note This method mutates system's state/metadata.
    \sa rollbackFinished(), restartRequired
*/
bool QOtaClient::rollback()
{
    Q_D(QOtaClient);
    if (!d->m_otaEnabled)
        return false;

    d->m_otaAsync->rollback();
    return true;
}

/*!
//! [update-offline]
    Uses the provided self-contained update package to update the system.
    Updates the local metadata cache, if it has not been already updated
    by calling updateRemoteInfoOffline().

    This method is asynchronous and returns immediately. The return value
    holds whether the operation was started successfully. The \a packagePath
    argument holds a path to the update package.

    \note This method mutates system's state/metadata.
//! [update-offline]

    \sa updateOfflineFinished()
*/
bool QOtaClient::updateOffline(const QString &packagePath)
{
    Q_D(QOtaClient);
    if (!d->m_otaEnabled)
        return false;

    QString package = QFileInfo(packagePath).absoluteFilePath();
    if (!d->verifyPathExist(package))
        return false;

    d->m_otaAsync->updateOffline(package);
    return true;
}

/*!
//! [update-remote-offline]
    Uses the provided self-contained update package to update local metadata cache.
    This metadata contains information on what system version is available on a server.
    The cache is persistent as it is stored on the disk. This method is an offline
    counterpart for fetchRemoteInfo().

    This method is asynchronous and returns immediately. The return value
    holds whether the operation was started successfully. The \a packagePath
    argument holds a path to the update package.

    \note This method mutates system's state/metadata.
//! [update-remote-offline]

    \sa remoteInfoChanged
*/
bool QOtaClient::updateRemoteInfoOffline(const QString &packagePath)
{
    Q_D(QOtaClient);
    if (!d->m_otaEnabled)
        return false;

    QFileInfo package(packagePath);
    if (!package.exists()) {
        d->errorOccurred(QString(QStringLiteral("The package %1 does not exist"))
                         .arg(package.absoluteFilePath()));
        return false;
    }

    d->m_otaAsync->updateRemoteInfoOffline(package.absoluteFilePath());
    return true;
}

/*!
//! [refresh-info]
    Refreshes the instances view of the system's state from the local metadata cache.
    Returns \c true if info is refreshed successfully; otherwise returns \c false.

    Using this method is not required when only one process is responsible for all OTA tasks.

//! [refresh-info]
*/
bool QOtaClient::refreshInfo()
{
    Q_D(QOtaClient);
    if (!d->m_otaEnabled)
        return false;

    return d->m_otaAsync->refreshInfo();
}

/*!
//! [remove-repository-config]
    Remove a configuration file for the repository.

    The repository configuration is stored on a file system in \c {/etc/ostree/remotes.d/*.conf}

    If the configuration file does not exist, this function returns \c true.
    If the configuration file exists, this function returns \c true if the file
    is removed successfully; otherwise returns \c false.
//! [remove-repository-config]

    \sa setRepositoryConfig(), repositoryConfigChanged
*/
bool QOtaClient::removeRepositoryConfig()
{
    Q_D(QOtaClient);
    if (!otaEnabled() || !QDir().exists(repoConfigPath))
        return true;

    bool removed = QDir().remove(repoConfigPath);
    if (removed)
        emit repositoryConfigChanged(nullptr);
    else
        d->errorOccurred(QStringLiteral("Failed to remove repository configuration"));

    return removed;
}

/*!
//! [is-repository-config-set]

    Returns \c true if the configuration \a config is already set; otherwise returns \c false.

//! [is-repository-config-set]
*/
bool QOtaClient::isRepositoryConfigSet(QOtaRepositoryConfig *config) const
{
    QOtaRepositoryConfig *currentConfig = repositoryConfig();

    bool isSet = currentConfig && config && currentConfig->url() == config->url() &&
                 currentConfig->gpgVerify() == config->gpgVerify() &&
                 currentConfig->tlsPermissive() == config->tlsPermissive() &&
                 currentConfig->tlsClientCertPath() == config->tlsClientCertPath() &&
                 currentConfig->tlsClientKeyPath() == config->tlsClientKeyPath() &&
                 currentConfig->tlsCaPath() == config->tlsCaPath();

    return isSet;
}

/*!
//! [set-repository-config]
    Change the configuration for the repository. The repository configuration
    is stored on a file system in \c {/etc/ostree/remotes.d/*.conf}

    Returns \c true if the configuration file is changed successfully;
    otherwise returns \c false.
//! [set-repository-config]

    The \a config argument is documented in QOtaRepositoryConfig.

    \sa removeRepositoryConfig(), repositoryConfigChanged
*/
bool QOtaClient::setRepositoryConfig(QOtaRepositoryConfig *config)
{
    Q_D(QOtaClient);
    if (!d->m_otaEnabled || !config)
        return false;

    if (QDir().exists(repoConfigPath)) {
        d->errorOccurred(QStringLiteral("Repository configuration already exists"));
        return false;
    }
    // URL
    if (config->url().isEmpty()) {
        d->errorOccurred(QStringLiteral("Repository URL can not be empty"));
        return false;
    }

    // TLS client certs
    int tlsClientArgs = 0;
    if (!config->tlsClientCertPath().isEmpty()) {
        if (!d->verifyPathExist(config->tlsClientCertPath()))
            return false;
        ++tlsClientArgs;
    }
    if (!config->tlsClientKeyPath().isEmpty()) {
        if (!d->verifyPathExist(config->tlsClientKeyPath()))
            return false;
        ++tlsClientArgs;
    }
    if (tlsClientArgs == 1) {
        d->errorOccurred(QStringLiteral("Both tlsClientCertPath and tlsClientKeyPath are required"
                                        " for TLS client authentication functionality"));
        return false;
    }

    // FORMAT: ostree remote add [OPTION...] NAME URL [BRANCH...]
    QString cmd(QStringLiteral("ostree remote add"));
    // GPG
    cmd.append(QStringLiteral(" --set=gpg-verify="));
    config->gpgVerify() ? cmd.append(QStringLiteral("true")) : cmd.append(QStringLiteral("false"));
    // TLS client authentication
    if (!config->tlsClientCertPath().isEmpty()) {
        cmd.append(QStringLiteral(" --set=tls-client-cert-path="));
        cmd.append(config->tlsClientCertPath());
        cmd.append(QStringLiteral(" --set=tls-client-key-path="));
        cmd.append(config->tlsClientKeyPath());
    }
    // TLS server authentication
    cmd.append(QStringLiteral(" --set=tls-permissive="));
    config->tlsPermissive() ? cmd.append(QStringLiteral("true")) : cmd.append(QStringLiteral("false"));
    if (!config->tlsCaPath().isEmpty()) {
        if (!d->verifyPathExist(config->tlsCaPath()))
            return false;
        cmd.append(QStringLiteral(" --set=tls-ca-path="));
        cmd.append(config->tlsCaPath());
    }
    // NAME URL [BRANCH...]
    cmd.append(QString(QStringLiteral(" qt-os %1 linux/qt")).arg(config->url()));

    bool ok = true;
    d->m_otaAsync->ostree(cmd, &ok);
    if (ok)
        emit repositoryConfigChanged(config);

    return ok;
}

/*!
    Returns a configuration object for the repository or \c nullptr if the
    configuration file does not exist or could not be read. The caller is
    responsible for deleting the returned object.

    \sa setRepositoryConfig(), removeRepositoryConfig()
*/
QOtaRepositoryConfig *QOtaClient::repositoryConfig() const
{
    if (!otaEnabled())
        return nullptr;
    return QOtaRepositoryConfig().d_func()->repositoryConfigFromFile(repoConfigPath);
}

/*!
    \property QOtaClient::otaEnabled
    \brief whether a device supports OTA updates.
*/
bool QOtaClient::otaEnabled() const
{
    Q_D(const QOtaClient);
    return d->m_otaEnabled;
}

/*!
    \property QOtaClient::error
    \brief a string containing the last error occurred.
*/
QString QOtaClient::errorString() const
{
    Q_D(const QOtaClient);
    return d->m_error;
}

/*!
    \property QOtaClient::status
    \brief a string containing the last status message.

    Only selected operations update this property.
*/
QString QOtaClient::statusString() const
{
    Q_D(const QOtaClient);
    return d->m_status;
}

/*!
    \property QOtaClient::updateAvailable
    \brief whether a system update is available.

    This information is cached; to update the local cache, call
    fetchRemoteInfo().
*/
bool QOtaClient::updateAvailable() const
{
    Q_D(const QOtaClient);
    if (d->m_updateAvailable)
        Q_ASSERT(!d->m_remoteRev.isEmpty());
    return d->m_updateAvailable;
}

/*!
    \property QOtaClient::rollbackAvailable
    \brief whether a rollback system is available.

    \sa rollbackAvailableChanged()
*/
bool QOtaClient::rollbackAvailable() const
{
    Q_D(const QOtaClient);
    return d->m_rollbackAvailable;
}

/*!
    \property QOtaClient::restartRequired
    \brief whether a reboot is required.

    Reboot is required after update(), updateOffline() and rollback(),
    to boot into the new default system.

*/
bool QOtaClient::restartRequired() const
{
    Q_D(const QOtaClient);
    return d->m_restartRequired;
}

/*!
    \property QOtaClient::bootedVersion
    \brief a QString containing the booted system's version.

    This is a convenience method.

    \sa bootedInfo
*/
QString QOtaClient::bootedVersion() const
{
    return d_func()->m_bootedVersion;
}

/*!
    \property QOtaClient::bootedDescription
    \brief a QString containing the booted system's description.

    This is a convenience method.

    \sa bootedInfo
*/
QString QOtaClient::bootedDescription() const
{
    return d_func()->m_bootedDescription;
}

/*!
    \property QOtaClient::bootedRevision
    \brief a QString containing the booted system's revision.

    A booted revision is a checksum in the OSTree repository.
*/
QString QOtaClient::bootedRevision() const
{
    return d_func()->m_bootedRev;
}

/*!
    \property QOtaClient::bootedInfo
    \brief a QByteArray containing the booted system's OTA metadata.

    Returns a JSON-formatted QByteArray containing OTA metadata for the booted
    system. Metadata is bundled with each system's version.
*/
QByteArray QOtaClient::bootedInfo() const
{
    return d_func()->m_bootedInfo;
}

/*!
    \property QOtaClient::remoteVersion
    \brief a QString containing the system's version on a server.

    This is a convenience method.

    \sa remoteInfo
*/
QString QOtaClient::remoteVersion() const
{
    return d_func()->m_remoteVersion;
}

/*!
    \property QOtaClient::remoteDescription
    \brief a QString containing the system's description on a server.

    This is a convenience method.

    \sa remoteInfo
*/
QString QOtaClient::remoteDescription() const
{
    return d_func()->m_remoteDescription;
}

/*!
    \property QOtaClient::remoteRevision
    \brief a QString containing the system's revision on a server.

    A checksum in the OSTree repository.
*/
QString QOtaClient::remoteRevision() const
{
    return d_func()->m_remoteRev;
}

/*!
    \property QOtaClient::remoteInfo
    \brief a QByteArray containing the system's OTA metadata on a server.

    Returns a JSON-formatted QByteArray containing OTA metadata for the system
    on a server. Metadata is bundled with each system's version.

    \sa fetchRemoteInfo()
*/
QByteArray QOtaClient::remoteInfo() const
{
    return d_func()->m_remoteInfo;
}

/*!
    \property QOtaClient::rollbackVersion
    \brief a QString containing the rollback system's version.

    This is a convenience method.

    \sa rollbackInfo
*/
QString QOtaClient::rollbackVersion() const
{
    return d_func()->m_rollbackVersion;
}

/*!
    \property QOtaClient::rollbackDescription
    \brief a QString containing the rollback system's description.

    This is a convenience method.

    \sa rollbackInfo
*/
QString QOtaClient::rollbackDescription() const
{
    return d_func()->m_rollbackDescription;
}

/*!
    \property QOtaClient::rollbackRevision
    \brief a QString containing the rollback system's revision.

    A checksum in the OSTree repository.
*/
QString QOtaClient::rollbackRevision() const
{
    return d_func()->m_rollbackRev;
}

/*!
    \property QOtaClient::rollbackInfo
    \brief a QByteArray containing the rollback system's OTA metadata.

    Returns a JSON-formatted QByteArray containing OTA metadata for the rollback
    system. Metadata is bundled with each system's version.

    \sa rollback()
*/
QByteArray QOtaClient::rollbackInfo() const
{
    return d_func()->m_rollbackInfo;
}

QT_END_NAMESPACE