Can't use auto export db from Gadgetbridge to Nextcloud
- Dominant language
- Kotlin
- Stars
- 5.6k
- Forks
- 2k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 92
Description
I use the Gadgetbridge app and have it configured to export its db every few hours to Nextcloud. This worked well until some time ago when it ceased to work. Judging from version dates, it was most probably with the update to v3.14.0 (maybe related to changes in #6917, but I don't know enough to affirm it).
In the logcat I can see that a NetworkOnMainThreadException is thrown, thus I guess it's closely related to #7350. Looking in the Gadgetbridge code the exception is thrown when trying to create an OutputStream on the Nextcloud URI, in a call like this:
```
OutputStream out = context.getContentResolver().openOutputStream(dstUri)
```
Note that this works with things like Dropbox, that's why I think it can be considered a bug in Nextcloud, although I can also report these details to Gadgetbridge.
### Steps to reproduce
(Assuming that it can be reproduced with a just created Gadgetbridge database)
1. Install Gadgetbridge
2. Configure an auto export location to Nextcloud
3. Go to Database management
4. Click on Run AutoExport Now
### Expected behaviour
- Database is exported and synchronized to the server.
### Actual behaviour
- On step 2 an empty file is created and synchronized to the server.
- On step 4 it fails with a generic error (if logcat is not inspected).
### Can you reproduce this problem on https://try.nextcloud.com?
- Irrelevant
### Environment data
Android version: 7.1.2
Device model: LG H870
Stock or customized system: LineageOS 14.1
Nextcloud app version: 3.14.2
Nextcloud server version: 19.0.2.2
Reverse proxy: none
### Logs
#### Logcat log
```
01-13 17:40:12.107 I/nodomain.freeyourgadget.gadgetbridge.util.GB(4389): Exportant base de dades…
01-13 17:40:12.110 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): Exporting DB
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): Download of /Gadgetbridge/database.db to /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/tmp/XXXXXXXXXX/Gadgetbridge/database.db: Unexpected exception
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): android.os.NetworkOnMainThreadException
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at java.net.Inet6AddressImpl.lookupHostByName(Inet6AddressImpl.java:86)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at java.net.Inet6AddressImpl.lookupAllHostAddr(Inet6AddressImpl.java:74)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at java.net.InetAddress.getByName(InetAddress.java:708)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.common.network.AdvancedSslSocketFactory.getInetAddressForHost(AdvancedSslSocketFactory.java:192)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.common.network.AdvancedSslSocketFactory.createSocket(AdvancedSslSocketFactory.java:182)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.common.OwnCloudClient.executeMethod(OwnCloudClient.java:219)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.resources.files.DownloadFileRemoteOperation.downloadFile(DownloadFileRemoteOperation.java:111)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.resources.files.DownloadFileRemoteOperation.run(DownloadFileRemoteOperation.java:88)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.common.operations.RemoteOperation.execute(RemoteOperation.java:184)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.operations.DownloadFileOperation.run(DownloadFileOperation.java:168)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.lib.common.operations.RemoteOperation.execute(RemoteOperation.java:184)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at com.owncloud.android.providers.DocumentsStorageProvider.openDocument(DocumentsStorageProvider.java:204)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at android.provider.DocumentsProvider.openAssetFile(DocumentsProvider.java:921)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at android.content.ContentProvider$Transport.openAssetFile(ContentProvider.java:389)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:262)
01-13 17:40:12.138 E/DownloadFileRemoteOperation(18945): at android.os.Binder.execTransact(Binder.java:565)
01-13 17:40:12.139 I/DownloadFileOperation(18945): Download of /Gadgetbridge/database.db to /storage/emulated/0/Android/media/com.nextcloud.client/nextcloud/XXXXXXXXXX/Gadgetbridge/database.db: Unexpected exception
01-13 17:40:12.139 E/DocumentsStorageProvider(18945): RemoteOperationResult(mSuccess=false, mHttpCode=-1, mHttpPhrase=null, mException=android.os.NetworkOnMainThreadException, mCode=HOST_NOT_AVAILABLE, getLogMessage=Unexpected exception)
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): Exception while exporting DB: java.io.FileNotFoundException: Error downloading file: database.db
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:144) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:621) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1004) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.content.ContentResolver.openOutputStream(ContentResolver.java:746) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.content.ContentResolver.openOutputStream(ContentResolver.java:722) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter.onReceive(PeriodicExporter.java:84) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.app.ActivityThread.handleReceiver(ActivityThread.java:3065) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.app.ActivityThread.-wrap18(ActivityThread.java) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1580) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.os.Handler.dispatchMessage(Handler.java:102) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.os.Looper.loop(Looper.java:154) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at android.app.ActivityThread.main(ActivityThread.java:6186) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at java.lang.reflect.Method.invoke(Native Method) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889) ~[na:0.0]
01-13 17:40:12.147 I/nodomain.freeyourgadget.gadgetbridge.database.PeriodicExporter(4389): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779) ~[na:0.0]
```
Contributor guide
Assessment
This issue has not been assessed yet.