From 83d6143f9768f203156df431bb90756854ece86b Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 26 Feb 2022 18:28:58 +0000 Subject: [PATCH] Android: use shareFile for support email This way we can have attachment of fairly arbitrary size (which should be extremely useful for long libdivecomputer logs). This isn't quite as intuitive as what we did before - the user needs to pick an email app to share with), but that doesn't seem too bad - and also... this way they can share logfiles via Dropbox or analyze them in other apps). If the file share fails for some reason, we fall back to the old method with passing the combined logs as body to the support message. As an implementation detail this keeps the correct path for the app log file around (this was stupidly overwritten before). Signed-off-by: Dirk Hohndel --- CHANGELOG.md | 1 + mobile-widgets/qmlmanager.cpp | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6408bc455..081206075 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ - core: avoid crash with corrupted cloud storage +- mobile/Android: add logfiles as attachment to support emails - planner: make ESC (cancel plan) work when moving handles - dive list: make dive guide visible in dive list [#3382] - general: rename dive master to dive guide diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index bff3ebc70..18052b2b9 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -263,7 +263,8 @@ QMLManager::QMLManager() : 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"); + QString libdcLogFileName = appLogFileName; + libdcLogFileName = libdcLogFileName.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(); @@ -491,8 +492,25 @@ void QMLManager::copyAppLogToClipboard() bool QMLManager::createSupportEmail() { + QString messageBody = "Please describe your issue here and keep the logs below:\n\n\n\n"; +#if defined(Q_OS_ANDROID) + // let's use our nifty Java shareFile function + QAndroidJniObject activity = QtAndroid::androidActivity(); + if (activity.isValid()) { + QAndroidJniObject applogfilepath = QAndroidJniObject::fromString(appLogFileName); + QAndroidJniObject libdcfilepath = QAndroidJniObject::fromString(logfile_name); + bool success = activity.callMethod("shareFiles", + "(Ljava/lang/String;Ljava/lang/String;)Z", // two string arguments, return bool + applogfilepath.object(), libdcfilepath.object()); + qDebug() << __FUNCTION__ << "shareFiles" << (success ? "succeeded" : "failed"); + if (success) + return true; + } + qDebug() << __FUNCTION__ << "failed to share the logFiles via intent, use the fall-back mail body method"; +#endif QString mailToLink = "mailto:in-app-support@subsurface-divelog.org?subject=Subsurface-mobile support request"; - mailToLink += "&body=Please describe your issue here and keep the logs below:\n\n\n\n"; + mailToLink += "&body="; + mailToLink += messageBody; mailToLink += getCombinedLogs(); if (QDesktopServices::openUrl(QUrl(mailToLink))) { appendTextToLog("OS accepted support email");