API Documentation

Documentation for developing SailfishOS applications

SoftwareUpdate Class

(Sailfish::Mdm::SoftwareUpdate)

The SoftwareUpdate class triggers OS software updates. More...

Header: #include <mdm-softwareupdate.h>

Public Functions

SoftwareUpdate(QObject *parent = 0)
~SoftwareUpdate()
void checkForSoftwareUpdate()
void downloadSoftwareUpdate(const QString &version = QStringLiteral( "latest" ))
void installSoftwareUpdate()
QString latestAvailableUpdateVersion() const
bool softwareUpdateIsAvailable() const

Signals

Detailed Description

The SoftwareUpdate class triggers OS software updates.

This class provides a convenience wrapper around system DBus APIs which are implemented by system services, whose operation depends on the system having a working seamless software update configuration. The configuration (including repositories, domains and authentication settings) is not exposed through this API.

To use this class, clients must add the following to their qmake project:

 CONFIG += link_pkgconfig
 PKGCONFIG += sailfishmdm

and then #include <mdm-softwareupdate.h>.

Example of usage:

 #include <mdm-softwareupdate.h>
 void installSoftwareUpdate(QObject *parent)
 {
     Sailfish::Mdm::SoftwareUpdate *sum = new Sailfish::Mdm::SoftwareUpdate(parent);
     QObject::connect(sum, &Sailfish::Mdm::SoftwareUpdate::softwareUpdateInfoChanged,
                     [sum] {
                         if (sum->softwareUpdateIsAvailable()) {
                             if (!sum->latestAvailableUpdateVersion().isEmpty()) {
                                 qInfo() << "OS update available, beginning software update process. Please wait...";
                                 sum->installSoftwareUpdate();
                             }
                         } else {
                             qInfo() << "OS update not available, not updating.";
                         }
                     });
     QObject::connect(sum, &Sailfish::Mdm::SoftwareUpdate::softwareUpdateDownloading,
                     [](const QString &version) { qInfo() << "OS update downloading; version:" << version; });
     QObject::connect(sum, &Sailfish::Mdm::SoftwareUpdate::softwareUpdateDownloadProgress,
                     [](int percent) { qInfo() << "OS update download progress:" << percent << "%"; });
     QObject::connect(sum, &Sailfish::Mdm::SoftwareUpdate::softwareUpdateDownloaded,
                     [] { qInfo() << "OS update downloaded!"; });
     QObject::connect(sum, &Sailfish::Mdm::SoftwareUpdate::softwareUpdateInstallationStarted,
                     [] { qInfo() << "OS update installation started!"; });
     QObject::connect(sum, &Sailfish::Mdm::SoftwareUpdate::softwareUpdateFailed,
                     [] { qInfo() << "OS update failed!"; });
     sum->checkForSoftwareUpdate();
 }

Member Function Documentation

SoftwareUpdate::SoftwareUpdate(QObject *parent = 0)

Default constructs an instance of SoftwareUpdate.

SoftwareUpdate::~SoftwareUpdate()

Destroys the instance of SoftwareUpdate.

void SoftwareUpdate::checkForSoftwareUpdate()

Triggers a check for software updates.

The check is asynchronous, and the softwareUpdateInfoChanged() signal will be emitted when the check has completed.

void SoftwareUpdate::downloadSoftwareUpdate(const QString &version = QStringLiteral( "latest" ))

Triggers downloading the software update with the given version.

The operation is asynchronous, and the following signals will be emitted at various stages of completion: softwareUpdateDownloading(), softwareUpdateDownloadProgress(), and softwareUpdateDownloaded().

If an error occurs during the download (e.g., due to network connectivity loss) the softwareUpdateFailed() signal will be emitted.

This method may be used if you wish to explicitly separate the downloading of the update from the installation, otherwise you should simply use the installSoftwareUpdate() method instead.

void SoftwareUpdate::installSoftwareUpdate()

Triggers downloading and installation of the software update.

The operation is asynchronous, and the following signals will be emitted at various stages of completion: softwareUpdateDownloading(), softwareUpdateDownloadProgress(), softwareUpdateDownloaded(), and softwareUpdateInstallationStarted().

Note that once the softwareInstallationStarted() signal is emitted, the device will go into a special run-mode during which the updated packages can be installed safely, and then the device will be restarted. The MDM application will not receive any further signals in this case.

If an error occurs during the download (e.g., due to network connectivity loss), or when the installation is started, the softwareUpdateFailed() signal will be emitted.

QString SoftwareUpdate::latestAvailableUpdateVersion() const

Returns the latest available software update version identifier.

For example: "2.1.2.261"

Note that if the device is in the "devel" domain, the value returned by this function is not necessarily reliable, as it may come from a cache (e.g. pkcon cache, zypper cache, ~/.cache/store-client/os-info cache) as opposed to queried from the store backend directly.

The return value of this method is only meaningful after a call to checkForSoftwareUpdate() has succeeded.

[signal] void SoftwareUpdate::softwareUpdateDownloadProgress(int percent)

This signal is emitted when a software update's download progress changes. The current download completion percentage is described by percent.

[signal] void SoftwareUpdate::softwareUpdateDownloaded()

This signal is emitted when the software update has completed downloading.

[signal] void SoftwareUpdate::softwareUpdateDownloading(const QString &version)

This signal is emitted when the latest software update becomes available due to a call to downloadSoftwareUpdate() or installSoftwareUpdate. The version specifies the version of the new software update.

[signal] void SoftwareUpdate::softwareUpdateFailed(const QString &reason)

This signal is emitted if the software update operation fails. The reason for the failure is provided in reason.

[signal] void SoftwareUpdate::softwareUpdateInfoChanged()

This signal is emitted when call to checkForSoftwareUpdate() completes which results in information about the latest software update becoming available.

[signal] void SoftwareUpdate::softwareUpdateInstallationStarted()

This signal is emitted when a software update installation is started as a result of a call to installSoftwareUpdate().

bool SoftwareUpdate::softwareUpdateIsAvailable() const

Returns true if a software update is available.

This function returns true if a newer software update version is available in the repositories used by this device.

The return value of this method is only meaningful after a call to checkForSoftwareUpdate() has succeeded.

We use cookies to improve your user experience and to help us to develop our services. By continuing to browse the site, you approve of our use of cookies.