mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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:
parent
4619b4932e
commit
0b72495413
5 changed files with 70 additions and 12 deletions
|
@ -28,6 +28,7 @@ public class SubsurfaceMobileActivity extends QtActivity
|
|||
public static boolean isInitialized;
|
||||
private static final String TAG = "subsurfacedivelog.mobile";
|
||||
public static native void setUsbDevice(UsbDevice usbDevice);
|
||||
public static native void restartDownload(UsbDevice usbDevice);
|
||||
private static Context appContext;
|
||||
|
||||
// we need to provide two endpoints:
|
||||
|
@ -116,8 +117,13 @@ public class SubsurfaceMobileActivity extends QtActivity
|
|||
if ("org.subsurfacedivelog.mobile.USB_PERMISSION".equals(action)) {
|
||||
synchronized (this) {
|
||||
if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
|
||||
Log.d(TAG, "USB device permission granted");
|
||||
setUsbDevice(null);
|
||||
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
|
||||
if (device == null) {
|
||||
Log.i(TAG, " permission granted but null device");
|
||||
return;
|
||||
}
|
||||
Log.d(TAG, "USB device permission granted for " + device.getDeviceName());
|
||||
restartDownload(device);
|
||||
} else {
|
||||
Log.d(TAG, "USB device permission denied");
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ Java_org_subsurfacedivelog_mobile_SubsurfaceMobileActivity_setUsbDevice(JNIEnv *
|
|||
if (usbDevice.isValid()) {
|
||||
android_usb_serial_device_descriptor descriptor = getDescriptor(usbDevice);
|
||||
|
||||
LOG(QString("called by intent for device %1").arg(QString::fromStdString(descriptor.uiRepresentation)));
|
||||
LOG(QString("called by connect intent for device %1").arg(QString::fromStdString(descriptor.uiRepresentation)));
|
||||
}
|
||||
#if defined(SUBSURFACE_MOBILE)
|
||||
QMLManager::instance()->showDownloadPage(usbDevice);
|
||||
|
@ -189,6 +189,25 @@ Java_org_subsurfacedivelog_mobile_SubsurfaceMobileActivity_setUsbDevice(JNIEnv *
|
|||
return;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_subsurfacedivelog_mobile_SubsurfaceMobileActivity_restartDownload(JNIEnv *env,
|
||||
jobject obj,
|
||||
jobject javaUsbDevice)
|
||||
{
|
||||
Q_UNUSED (obj)
|
||||
Q_UNUSED (env)
|
||||
QAndroidJniObject usbDevice(javaUsbDevice);
|
||||
if (usbDevice.isValid()) {
|
||||
android_usb_serial_device_descriptor descriptor = getDescriptor(usbDevice);
|
||||
|
||||
LOG(QString("called by permission granted intent for device %1").arg(QString::fromStdString(descriptor.uiRepresentation)));
|
||||
}
|
||||
#if defined(SUBSURFACE_MOBILE)
|
||||
QMLManager::instance()->restartDownload(usbDevice);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* NOP wrappers to comform with windows.c */
|
||||
int subsurface_rename(const char *path, const char *newpath)
|
||||
{
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue