Schreibbare Verzeichnisse#

App confinement ist Teil des Ubuntu Touch Sicherheitskonzepts. Der Datenaustausch zwischen Apps kann nur gemäß den AppArmor-Richtlinien erfolgen, hauptsächlich über den ContentHub. Allerdings können Apps nur Dateien lesen und schreiben, die sich in einem von drei app-spezifischen Verzeichnissen befinden, die in diesem Guide erläutert werden.

Standardpfade#

Neben dem Schreibzugriff auf die unten beschriebenen App-Verzeichnisse kann die App Debug-Meldungen in die App-Logdatei schreiben, die sich unter /home/phablet/.cache/upstart/application-click-<fullappname>_<appname>_<appname>_<version>.log befindet. Um Meldungen an die Protokolldatei anzuhängen, verwenden Sie die Funktionen Qt debug.

Konfiguration#

Pfad: /home/phablet/.config/<fullappname>/

Dies ist der Ort, an dem Sie Konfigurationsdateien speichern können. Die Musik-App speichert beispielsweise ihre Konfiguration unter /home/phablet/.config/com.ubuntu.music/com.ubuntu.music.conf.

Cache#

Pfad: /home/phablet/.cache/<fullappname>/

Dies ist der Ort, an dem Daten für die spätere Verwendung zwischengespeichert werden können. Der Cache wird auch vom Content Hub verwendet. Dateien, die beispielsweise mit der Musik-App geteilt wurden, finden Sie unter /home/phablet/.cache/com.ubuntu.music/HubIncoming/.

Bemerkung

Data in the cache directory should be treated as temporary and the app should still function normally if this directory is cleared - clearing cache is commonly done to recover some space on the device. Don’t store user account info here :)

App-Daten#

Pfad: /home/phablet/.local/share/<fullappname>/

Hier speichert Ihre App alle Daten. Die Musik-App speichert beispielsweise ihre Datenbanken unter /home/phablet/.local/share/com.ubuntu.music/Databases/.

Verwendung von Standardpfaden in C++#

The Qt header QStandardPaths provides the app’s writable locations in C++:

#include <QStandardPaths>
...
QString configPath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
QString cachePath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
QString appDataPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
...

Since the value of the QStandardPaths strings are decided by the Qt application name, this needs to be the same as the clickable application name.

Warnung

Setting the organizationName will change the paths returned by these functions too - if you need to do this, set it to the clickable application name as well, otherwise the paths won’t work on the device.

Verwendung von Standardpfaden in QML#

The Qt module Qt.labs.platform provides the app’s writable locations in QML:

import Qt.labs.platform 1.0
...
Label
{
    text: StandardPaths.writableLocation(StandardPaths.AppConfigLocation)
}
Label
{
    text: StandardPaths.writableLocation(StandardPaths.CacheLocation)
}
Label
{
    text: StandardPaths.writableLocation(StandardPaths.AppDataLocation)
}
...

Notice that QStandardPaths returns paths ('/phablet/home/...'), and QML StandardPaths returns urls ('file:///phablet/home/...'). This must be considered specially if the app is sharing location strings between QML and C++.