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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2022-02-26 18:28:58 +00:00
parent 43ed2e1224
commit 83d6143f97
2 changed files with 21 additions and 2 deletions

View file

@ -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

View file

@ -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<jboolean>("shareFiles",
"(Ljava/lang/String;Ljava/lang/String;)Z", // two string arguments, return bool
applogfilepath.object<jstring>(), libdcfilepath.object<jstring>());
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");