summaryrefslogtreecommitdiffstats
path: root/mobile-widgets
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-06-28 04:54:08 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-06-28 06:17:31 -0700
commitbcde65b152f2fdbf0e068c3a9dfabe138be2efca (patch)
treee95c5cb50f2cdebec476c8c4cd1c52e33fc0aa60 /mobile-widgets
parent1161782f3b8b6f0cebe62626e3c065f74b85bc07 (diff)
downloadsubsurface-bcde65b152f2fdbf0e068c3a9dfabe138be2efca.tar.gz
iOS and Android: try more logfile locations
On some devices (e.g., a Sony Xperia phone) the GenericDataLocation is not app writeable. Instead of just giving app, try a few other default locations as well (and since all of these are actually string lists, try all of the options that Qt gives us). Reasonably, we should only set the libdivecomputer logfile name if we found a writeable location. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r--mobile-widgets/qmlmanager.cpp48
1 files changed, 32 insertions, 16 deletions
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index 3ac55c4f8..a3a4fffad 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -149,27 +149,43 @@ QMLManager::QMLManager() : m_locationServiceEnabled(false),
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
#if defined(Q_OS_ANDROID)
- appLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/subsurface.log";
- QString libdcLogFileName = QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation).first() + "/libdivecomputer.log";
+ // on Android we first try the GenericDataLocation (typically /storage/emulated/0) and if that fails
+ // (as happened e.g. on a Sony Xperia phone) we try several other default locations, with the TempLocation as last resort
+ QStringList fileLocations =
+ QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation) +
+ QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation) +
+ QStandardPaths::standardLocations(QStandardPaths::DownloadLocation) +
+ QStandardPaths::standardLocations(QStandardPaths::TempLocation);
#elif defined(Q_OS_IOS)
// on iOS we should save the data to the DocumentsLocation so it becomes accessible to the user
- appLogFileName = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first() + "/subsurface.log";
- QString libdcLogFileName = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation).first() + "/libdivecomputer.log";
+ QStringList fileLocations =
+ QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
#endif
- // remove the existing libdivecomputer logfile so we don't copy an old one by mistake
- QFile libdcLog(libdcLogFileName);
- libdcLog.remove();
- logfile_name = copy_qstring(libdcLogFileName);
- appLogFile.setFileName(appLogFileName);
- if (!appLogFile.open(QIODevice::ReadWrite|QIODevice::Truncate)) {
- appLogFileOpen = false;
- appendTextToLog("Failed to open logfile " + appLogFileName
- + " at " + QDateTime::currentDateTime().toString()
- + " error: " + appLogFile.errorString());
- } else {
- appLogFileOpen = true;
+ appLogFileOpen = false;
+ for (const QString &fileLocation : fileLocations) {
+ appLogFileName = fileLocation + "/subsurface.log";
+ appLogFile.setFileName(appLogFileName);
+ if (!appLogFile.open(QIODevice::ReadWrite|QIODevice::Truncate)) {
+ appendTextToLog("Failed to open logfile " + appLogFileName
+ + " at " + QDateTime::currentDateTime().toString()
+ + " error: " + appLogFile.errorString());
+ } else {
+ // found a directory that works
+ appLogFileOpen = true;
+ break;
+ }
+ }
+ if (appLogFileOpen) {
appendTextToLog("Successfully opened logfile " + appLogFileName
+ " at " + QDateTime::currentDateTime().toString());
+ // if we were able to write the overall logfile, also write the libdivecomputer logfile
+ QString libdcLogFileName = appLogFileName.replace("/subsurface.log", "/libdivecomputer.log");
+ // remove the existing libdivecomputer logfile so we don't copy an old one by mistake
+ QFile libdcLog(libdcLogFileName);
+ libdcLog.remove();
+ logfile_name = copy_qstring(libdcLogFileName);
+ } else {
+ appendTextToLog("No writeable location found, in-memory log only and no libdivecomputer log");
}
#endif
LOG_STP("qmlmgr log started");