summaryrefslogtreecommitdiffstats
path: root/mobile-widgets
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-15 12:27:10 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-16 07:58:20 -0700
commit0b72495413e8b060b58b96aa6d6a0ce96baa168c (patch)
tree6517fa914d2ffd9ba1317e100e8f92f419990430 /mobile-widgets
parent4619b4932eb2f75f8026b79e8a810ddf5f5fd7e9 (diff)
downloadsubsurface-0b72495413e8b060b58b96aa6d6a0ce96baa168c.tar.gz
android/usb: simply restart the download after receiving permission
If the user tries to download from a device that he hasn't given the app permission to read from, Android will pop up a dialogue asking for that permission. With this after giving the permission we continue (well, technically, restart) the download which is likely the expected behavior. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'mobile-widgets')
-rw-r--r--mobile-widgets/qml/DownloadFromDiveComputer.qml25
-rw-r--r--mobile-widgets/qmlmanager.cpp24
-rw-r--r--mobile-widgets/qmlmanager.h2
3 files changed, 42 insertions, 9 deletions
diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml
index 8ef4520a2..5a732b73f 100644
--- a/mobile-widgets/qml/DownloadFromDiveComputer.qml
+++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml
@@ -293,6 +293,24 @@ Kirigami.Page {
Layout.fillWidth: true
Layout.topMargin: Kirigami.Units.smallSpacing
spacing: Kirigami.Units.smallSpacing
+
+
+ function doDownload() {
+ var message = "DCDownloadThread started for " + manager.DC_vendor + " " + manager.DC_product + " on " + manager.DC_devName;
+ message += " downloading " + (manager.DC_forceDownload ? "all" : "only new" ) + " dives";
+ manager.appendTextToLog(message)
+ progressBar.visible = true
+ divesDownloaded = false // this allows the progressMessage to be displayed
+ importModel.startDownload()
+ }
+
+ Connections {
+ target: manager
+ onRestartDownloadSignal: {
+ buttonBar.doDownload()
+ }
+ }
+
TemplateButton {
id: download
text: qsTr("Download")
@@ -322,12 +340,7 @@ Kirigami.Page {
manager.DC_bluetoothMode = false;
manager.DC_devName = connectionString;
}
- var message = "DCDownloadThread started for " + manager.DC_vendor + " " + manager.DC_product + " on " + manager.DC_devName;
- message += " downloading " + (manager.DC_forceDownload ? "all" : "only new" ) + " dives";
- manager.appendTextToLog(message)
- progressBar.visible = true
- divesDownloaded = false // this allows the progressMessage to be displayed
- importModel.startDownload()
+ buttonBar.doDownload()
}
}
TemplateButton {
diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp
index b271af6ea..184ce023f 100644
--- a/mobile-widgets/qmlmanager.cpp
+++ b/mobile-widgets/qmlmanager.cpp
@@ -2120,9 +2120,8 @@ void QMLManager::androidUsbPopoulateConnections()
void QMLManager::showDownloadPage(QAndroidJniObject usbDevice)
{
if (!usbDevice.isValid()) {
- // this happens if we get called by the permission granted intent
- // if that happens, just make sure the DownloadPage is reopened
- m_pluggedInDeviceName = QString("reopen");
+ // this really shouldn't happen anymore, but just in case...
+ m_pluggedInDeviceName = "";
} else {
// repopulate the connection list
rescanConnections();
@@ -2135,6 +2134,25 @@ void QMLManager::showDownloadPage(QAndroidJniObject usbDevice)
}
emit pluggedInDeviceNameChanged();
}
+
+void QMLManager::restartDownload(QAndroidJniObject usbDevice)
+{
+ // this gets called if we received a permission intent after
+ // already trying to download from USB
+ if (!usbDevice.isValid()) {
+ appendTextToLog("permission intent with invalid UsbDevice - ignoring");
+ } else {
+ // inform that QML code that it should retry downloading
+ // we get the usbDevice again and could verify that this is
+ // still the same - but I don't see how this could change while we are waiting
+ // for permission
+ android_usb_serial_device_descriptor usbDeviceDescriptor = getDescriptor(usbDevice);
+ appendTextToLog(QString("got permission from Android, restarting download for %1")
+ .arg(QString::fromStdString(usbDeviceDescriptor.uiRepresentation)));
+ emit restartDownloadSignal();
+ }
+}
+
#endif
void QMLManager::setFilter(const QString filterText, int index)
diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h
index c0d036aec..7bd9e5e89 100644
--- a/mobile-widgets/qmlmanager.h
+++ b/mobile-widgets/qmlmanager.h
@@ -235,6 +235,7 @@ public slots:
void rescanConnections();
#if defined(Q_OS_ANDROID)
void showDownloadPage(QAndroidJniObject usbDevice);
+ void restartDownload(QAndroidJniObject usbDevice);
void androidUsbPopoulateConnections();
QString getProductVendorConnectionIdx(android_usb_serial_device_descriptor descriptor);
#endif
@@ -307,6 +308,7 @@ signals:
void oldStatusChanged();
void undoTextChanged();
void redoTextChanged();
+ void restartDownloadSignal();
// From upload process
void uploadFinish(bool success, const QString &text);