Writable directories#

App confinement is part of the Ubuntu Touch security concept. Data can be exchanged between apps only according to the AppArmor policies, mainly using the ContentHub. This being said, apps can only read and write files that are located in one of three app specific directories explained in this guide.

Standard Paths#

Besides the write access to the app directories explained below, the app can write debug messages into the app log file located at /home/phablet/.cache/upstart/application-click-<fullappname>_<appname>_<version>.log. To append messages to the log file, use the Qt debug functions.

Config#

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

This is the place to store configurations files to. The music app for example stores its configuration to /home/phablet/.config/com.ubuntu.music/com.ubuntu.music.conf.

Cache#

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

This is the place to cache data for later use. The cache is also used by the Content Hub. Files that have been shared with the music app for example can be found in /home/phablet/.cache/com.ubuntu.music/HubIncoming/.

Not

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 data#

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

This is where your app stores any data. The music app for example stores its data bases to /home/phablet/.local/share/com.ubuntu.music/Databases/.

Using Standard Paths 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.

Uyarı

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.

Using Standard Paths 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++.