PackageManager QML Type

The package installation/removal/update part of the application manager. More...

Import Statement: import QtApplicationManager.SystemUI 2.0

Properties

Signals

Methods

Detailed Description

The PackageManager singleton type handles the package installation part of the application manager. It provides both a DBus and QML APIs for all of its functionality.

Note: Unlike the deprecated ApplicationInstaller class, the PackageManager singleton and its corresponding DBus API are always available. Disabling the installer functionality via the application manager's Configuration will just lead to package (de-) installations failing instantly.

The type is derived from QAbstractListModel, so it can be used directly as a model from QML.

The following roles are available in this model:

Role nameTypeDescription
packageIdstringThe unique ID of a package, represented as a string (e.g. Browser or com.pelagicore.music)
namestringThe name of the package. If possible, already translated to the current locale.
iconstringThe URL of the package's icon.
isBlockedboolA boolean value that gets set when the application manager needs to block any application within this package from running: this is normally only the case while an update is being applied.
isUpdatingboolA boolean value indicating whether the package is currently being installed or updated. If true, the updateProgress can be used to track the actual progress.
isRemovableboolA boolean value indicating whether this package is user-removable; true for all dynamically installed third party packages and false for all system packages.
updateProgressrealWhile isUpdating is true, querying this role returns the actual progress as a floating-point value in the 0.0 to 1.0 range.
categorieslist<string>The categories this package is registered for via its meta-data file.
versionstringThe currently installed version of this package.
packagePackageThe underlying package object for quick access to the properties outside of a model delegate.

The following table describes all possible states that a background task could be in:

Task StateDescription
QueuedThe task was created and is now queued up for execution.
ExecutingThe task is being executed.
FinishedThe task was executed successfully.
FailedThe task failed to execute successfully.
AwaitingAcknowledgeInstallation tasks only! The task is currently halted, waiting for either acknowledgePackageInstallation() or cancelTask() to continue. See startPackageInstallation() for more information on the installation workflow.
InstallingInstallation tasks only! The installation was acknowledged via acknowledgePackageInstallation() and the final installation phase is now running.
CleaningUpInstallation tasks only! The installation has finished, and previous installations as well as temporary files are being cleaned up.

The normal workflow for tasks is: QueuedExecutingFinished. The task can enter the Failed state at any point though - either by being canceled via cancelTask() or simply by failing due to an error.

Installation tasks are a bit more complex due to the acknowledgment: QueuedExecutingAwaitingAcknowledge (this state may be skipped if acknowledgePackageInstallation() was called already) → InstallingCleanupFinished. Again, the task can fail at any point.

Property Documentation

documentLocation : object

Returns an object describing the location under which per-user document directories are created in detail.

The returned object has the same members as described in PackageManager::installationLocation.


installationLocation : object

Returns an object describing the location under which packages are installed in detail.

The returned object has the following members:

NameTypeDescription
pathstringThe absolute file-system path to the base directory.
deviceSizeintThe size of the device holding path in bytes.
deviceFreeintThe amount of bytes available on the device holding path.

Returns an empty object in case the installer component is disabled.


Signal Documentation

taskBlockingUntilInstallationAcknowledge(string taskId)

This signal is emitted when the installation task identified by taskId cannot continue due to a missing acknowledgePackageInstallation() call for the task.

Note: The corresponding handler is onTaskBlockingUntilInstallationAcknowledge.

See also taskStateChanged() and acknowledgePackageInstallation().


taskFailed(string taskId)

This signal is emitted when the task identified by taskId enters the Failed state.

Note: The corresponding handler is onTaskFailed.

See also taskStateChanged().


taskFinished(string taskId)

This signal is emitted when the task identified by taskId enters the Finished state.

Note: The corresponding handler is onTaskFinished.

See also taskStateChanged().


taskProgressChanged(string taskId, qreal progress)

This signal is emitted whenever the task identified by taskId makes progress towards its completion. The progress is reported as a floating-point number ranging from 0.0 to 1.0.

Note: The corresponding handler is onTaskProgressChanged.

See also taskStateChanged().


taskRequestingInstallationAcknowledge(string taskId, PackageObject package, object packageExtraMetaData, object packageExtraSignedMetaData)

This signal is emitted when the installation task identified by taskId has received enough meta-data to be able to emit this signal. The task may be in either Executing or AwaitingAcknowledge state.

A temporary PackageObject is supplied via package. Please note, that this object is just constructed on the fly for this signal emission and is not part of the PackageManager model. The package object is destroyed again after the signal callback returns. Another permanent PackageObject that is also part of the model will be constructed later in the installation process.

In addition, the package's extra meta-data (signed and unsinged) is also supplied via packageExtraMetaData and packageExtraSignedMetaData respectively as JavaScript objects. Both these objects are optional and need to be explicitly either populated during an application's packaging step or added by an intermediary app-store server. By default, both will just be empty.

Following this signal, either cancelTask() or acknowledgePackageInstallation() has to be called for this taskId, to either cancel the installation or try to complete it.

The PackageManager has two convenience functions to help the System UI with verifying the meta-data: compareVersions() and, in case you are using reverse-DNS notation for application-ids, validateDnsName().

Note: The corresponding handler is onTaskRequestingInstallationAcknowledge.

See also taskStateChanged() and startPackageInstallation().


taskStarted(string taskId)

This signal is emitted when the task identified by taskId enters the Executing state.

Note: The corresponding handler is onTaskStarted.

See also taskStateChanged().


taskStateChanged(string taskId, string newState)

This signal is emitted when the state of the task identified by taskId changes. The new state is supplied in the parameter newState.

Note: The corresponding handler is onTaskStateChanged.

See also taskState().


Method Documentation

void acknowledgePackageInstallation(string taskId)

Calling this function enables the installer to complete the installation task identified by taskId. Normally, this function is called after receiving the taskRequestingInstallationAcknowledge() signal, and the user and/or the program logic decided to proceed with the installation.

See also startPackageInstallation().


list<string> activeTaskIds()

Retuns a list of all currently active (as in not yet finished or failed) installation task ids.


bool cancelTask(string taskId)

Tries to cancel the installation task identified by taskId.

Returns true if the task was canceled, false otherwise.


int compareVersions(string version1, string version2)

Convenience method for app-store implementations or taskRequestingInstallationAcknowledge() callbacks for comparing version numbers, as the actual version comparison algorithm is not trivial.

Returns -1, 0 or 1 if version1 is smaller than, equal to, or greater than version2 (similar to how strcmp() works).


object get(string packageId)

Retrieves the model data for the package identified by packageId as a JavaScript object. See the role names for the expected object fields.

Returns an empty object if the specified packageId is invalid.


object get(int index)

Retrieves the model data at index as a JavaScript object. See the role names for the expected object fields.

Returns an empty object if the specified index is invalid.

Note: This is very inefficient if you only want to access a single property from QML; use package() instead to access the PackageObject's properties directly.


int indexOfPackage(string id)

Maps the package id to its position within the model.

Returns -1 if the specified id is invalid.


var installedPackageExtraMetaData(string packageId)

Returns a map of all extra metadata in the package header of the package identified by packageId.

Returns an empty map in case the package packageId is not valid, or the package is not installed.


var installedPackageExtraSignedMetaData(string packageId)

Returns a map of all signed extra metadata in the package header of the package identified by packageId.

Returns an empty map in case the package packageId is not valid, or the package is not installed.


int installedPackageSize(string packageId)

Returns the size in bytes that the package identified by packageId is occupying on the storage device.

Returns -1 in case the package packageId is not valid, or the package is not installed.


PackageObject package(string id)

Returns the PackageObject corresponding to the given package id, or null if the id does not exist.

Note: The object ownership of the returned PackageObject stays with the application manager. If you want to store this pointer, you can use the PackageManager's QAbstractListModel signals or the packageAboutToBeRemoved signal to get notified if the object is about to be deleted on the C++ side.


PackageObject package(int index)

Returns the PackageObject corresponding to the given index in the model, or null if the index is invalid.

Note: The object ownership of the returned PackageObject stays with the application manager. If you want to store this pointer, you can use the PackageManager's QAbstractListModel signals or the packageAboutToBeRemoved signal to get notified if the object is about to be deleted on the C++ side.


list<string> packageIds()

Returns a list of all available package ids. This can be used to further query for specific information via get().


string removePackage(string packageId, bool keepDocuments, bool force)

Uninstalls the package identified by packageId. Normally, the documents directory of the package is deleted on removal, but this can be prevented by setting keepDocuments to true.

The actual removal will happen asynchronously in the background. The PackageManager will emit the signals taskStarted, taskProgressChanged, taskFinished, taskFailed and taskStateChanged for the returned taskId when applicable.

Normally, force should only be set to true if a previous call to removePackage() failed. This may be necessary if the installation process was interrupted, or or has file-system issues.

Returns a unique taskId. This can also be an empty string, if the task could not be created (in this case, no signals will be emitted).


string startPackageInstallation(string sourceUrl)

Downloads an application package from sourceUrl and installs it.

The actual download and installation will happen asynchronously in the background. The PackageManager emits the signals taskStarted, taskProgressChanged, taskRequestingInstallationAcknowledge, taskFinished, taskFailed, and taskStateChanged for the returned taskId when applicable.

Note: Simply calling this function is not enough to complete a package installation: The taskRequestingInstallationAcknowledge() signal needs to be connected to a slot where the supplied package meta-data can be validated (either programmatically or by asking the user). If the validation is successful, the installation can be completed by calling acknowledgePackageInstallation() or, if the validation was unsuccessful, the installation should be canceled by calling cancelTask(). Failing to do one or the other will leave an unfinished "zombie" installation.

Returns a unique taskId. This can also be an empty string, if the task could not be created (in this case, no signals will be emitted).


string taskPackageId(string taskId)

Returns the package id associated with the task identified by taskId. The task may not have a valid package id at all times though and in this case the function will return an empty string (this will be the case for installations before the taskRequestingInstallationAcknowledge signal has been emitted).

Returns an empty string if the taskId is invalid.


enumeration taskState(string taskId)

Returns the current state of the installation task identified by taskId. See here for a list of valid task states.

Returns PackageManager.Invalid if the taskId is invalid.


int validateDnsName(string name, int minimalPartCount)

Convenience method for app-store implementations or taskRequestingInstallationAcknowledge() callbacks for checking if the given name is a valid DNS (or reverse-DNS) name according to RFC 1035/1123. If the optional parameter minimalPartCount is specified, this function will also check if name contains at least this amount of parts/sub-domains.

Returns true if the name is a valid DNS name or false otherwise.


© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.