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>
This commit is contained in:
Dirk Hohndel 2020-03-15 12:27:10 -07:00
parent 4619b4932e
commit 0b72495413
5 changed files with 70 additions and 12 deletions

View file

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