nextcloud / android

📱 Nextcloud Android app
https://play.google.com/store/apps/details?id=com.nextcloud.client
GNU General Public License v2.0
4.16k stars 1.75k forks source link

ACTION_OPEN_DOCUMENT_TREE: DocumentFile.createFile returns null #7350

Closed MerlinB closed 3 years ago

MerlinB commented 3 years ago

This issue has already been discussed (https://github.com/nextcloud/android/issues/303 after this comment) but the same problem still occurs in the most recent app version (3.13.1). Also see this comment for a more detailed traceback.

Steps to reproduce

I used the Aegis 2FA app for this but I expect the issue to be unrelated to it

  1. Choose Backup directory (uses ACTION_OPEN_DOCUMENT_TREE)
  2. Select a Nextcloud directory
  3. Trigger backup

Actual behaviour

ManagerException: createFile returned null is being thrown.

Environment data

Android version: 10

Device model: Pixel 4a

Stock or customized system: Custom (CalyxOS 1.0.0)

Nextcloud app version: 3.13.1

tobiasKaminsky commented 3 years ago

@grote pinging again you as you did great work on this :-) (if you do not want/have time, just say it and I will not ping you again)

grote commented 3 years ago

@MerlinB does it still happen with 3.14.0? Do you have a full stacktrace for the ManagerException?

MerlinB commented 3 years ago

Its not working with 3.14.0 RC2. Will let you know about 3.14 release when it hits FDroid. Here is the full system log:

11-20 15:55:15.147 28802 28820 D OwnCloudClient #0: REQUEST PUT /nextcloud/remote.php/webdav/Backups/OTP/aegis-backup-20201120-155515.json
11-20 15:55:15.148 28802 28820 D AdvancedSslSocketFactory: Creating SSL Socket with remote [nextcloudserverurl]:443, local null:0, params: org.apache.commons.httpclient.params.HttpConnectionParams@2dc628a
11-20 15:55:15.149 28802 28820 D AdvancedSslSocketFactory:  ... with connection timeout 5000 and socket timeout 40000
11-20 15:55:15.150 28802 28820 E DocumentsStorageProvider: RemoteOperationResult(mSuccess=false, mHttpCode=-1, mHttpPhrase=null, mException=android.os.NetworkOnMainThreadException, mCode=HOST_NOT_AVAILABLE, getLogMessage=Unexpected exception)
11-20 15:55:15.150 28802 28820 E DatabaseUtils: Writing exception to parcel
11-20 15:55:15.150 28802 28820 E DatabaseUtils: android.os.ParcelableException: java.io.FileNotFoundException: Failed to upload document with path /Backups/OTP/aegis-backup-20201120-155515.json
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.provider.DocumentsProvider.call(DocumentsProvider.java:1069)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.content.ContentProvider.call(ContentProvider.java:2152)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.content.ContentProvider$Transport.call(ContentProvider.java:477)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:277)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.os.Binder.execTransactInternal(Binder.java:1021)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.os.Binder.execTransact(Binder.java:994)
11-20 15:55:15.150 28802 28820 E DatabaseUtils: Caused by: java.io.FileNotFoundException: Failed to upload document with path /Backups/OTP/aegis-backup-20201120-155515.json
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at com.owncloud.android.providers.DocumentsStorageProvider.createFile(DocumentsStorageProvider.java:519)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at com.owncloud.android.providers.DocumentsStorageProvider.createDocument(DocumentsStorageProvider.java:440)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.provider.DocumentsProvider.callUnchecked(DocumentsProvider.java:1121)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         at android.provider.DocumentsProvider.call(DocumentsProvider.java:1067)
11-20 15:55:15.150 28802 28820 E DatabaseUtils:         ... 5 more
11-20 15:55:15.152 24489 24489 W DocumentsContract: Failed to create document
11-20 15:55:15.152 24489 24489 W DocumentsContract: android.os.ParcelableException: java.io.FileNotFoundException: Failed to upload document with path /Backups/OTP/aegis-backup-20201120-155515.json
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.ParcelableException$1.createFromParcel(ParcelableException.java:82)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.ParcelableException$1.createFromParcel(ParcelableException.java:79)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.Parcel.readParcelable(Parcel.java:2973)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.Parcel.createException(Parcel.java:2066)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.Parcel.readException(Parcel.java:2039)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:188)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:140)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.content.ContentProviderProxy.call(ContentProviderNative.java:658)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.content.ContentResolver.call(ContentResolver.java:2042)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.provider.DocumentsContract.createDocument(DocumentsContract.java:1327)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at com.beemdevelopment.aegis.vault.VaultManager.backup(VaultManager.java:22)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at com.beemdevelopment.aegis.ui.PreferencesFragment.lambda$onCreatePreferences$12$PreferencesFragment(PreferencesFragment.java:2)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at com.beemdevelopment.aegis.ui.-$$Lambda$PreferencesFragment$Osh943DITxojoWiG7V9qQjE0MFM.onPreferenceClick(Unknown Source:2)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at androidx.preference.Preference.performClick(Preference.java:4)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at androidx.preference.Preference$1.onClick(Preference.java:1)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.view.View.performClick(View.java:7259)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.view.View.performClickInternal(View.java:7236)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.view.View.access$3600(View.java:801)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.view.View$PerformClick.run(View.java:27892)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.Handler.handleCallback(Handler.java:883)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.Handler.dispatchMessage(Handler.java:100)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.Looper.loop(Looper.java:214)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.app.ActivityThread.main(ActivityThread.java:7356)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at java.lang.reflect.Method.invoke(Native Method)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
11-20 15:55:15.152 24489 24489 W DocumentsContract: Caused by: java.io.FileNotFoundException: Failed to upload document with path /Backups/OTP/aegis-backup-20201120-155515.json
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at java.lang.reflect.Constructor.newInstance0(Native Method)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     at android.os.ParcelableException.readFromParcel(ParcelableException.java:56)
11-20 15:55:15.152 24489 24489 W DocumentsContract:     ... 26 more
11-20 15:55:15.152 24489 24489 E VaultBackupManager: Unable to create file for backup, createFile returned null
11-20 15:55:15.152 24489 24489 W System.err: com.beemdevelopment.aegis.vault.VaultManagerException: createFile returned null
11-20 15:55:15.152 24489 24489 W System.err:    at com.beemdevelopment.aegis.vault.VaultManager.backup(VaultManager.java:69)
11-20 15:55:15.152 24489 24489 W System.err:    at com.beemdevelopment.aegis.ui.PreferencesFragment.lambda$onCreatePreferences$12$PreferencesFragment(PreferencesFragment.java:2)
11-20 15:55:15.152 24489 24489 W System.err:    at com.beemdevelopment.aegis.ui.-$$Lambda$PreferencesFragment$Osh943DITxojoWiG7V9qQjE0MFM.onPreferenceClick(Unknown Source:2)
11-20 15:55:15.152 24489 24489 W System.err:    at androidx.preference.Preference.performClick(Preference.java:4)
11-20 15:55:15.152 24489 24489 W System.err:    at androidx.preference.Preference$1.onClick(Preference.java:1)
11-20 15:55:15.152 24489 24489 W System.err:    at android.view.View.performClick(View.java:7259)
11-20 15:55:15.152 24489 24489 W System.err:    at android.view.View.performClickInternal(View.java:7236)
11-20 15:55:15.152 24489 24489 W System.err:    at android.view.View.access$3600(View.java:801)
11-20 15:55:15.152 24489 24489 W System.err:    at android.view.View$PerformClick.run(View.java:27892)
11-20 15:55:15.152 24489 24489 W System.err:    at android.os.Handler.handleCallback(Handler.java:883)
11-20 15:55:15.152 24489 24489 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:100)
11-20 15:55:15.152 24489 24489 W System.err:    at android.os.Looper.loop(Looper.java:214)
11-20 15:55:15.152 24489 24489 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:7356)
11-20 15:55:15.152 24489 24489 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
11-20 15:55:15.152 24489 24489 W System.err:    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:491)
11-20 15:55:15.152 24489 24489 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
11-20 15:55:15.185   759 29901 E ResolverController: No valid NAT64 prefix (190, <unspecified>/0)
grote commented 3 years ago

Thanks, that's helpful!

Look like the app can't upload the created file for some reason: NetworkOnMainThreadException

@MerlinB I am not sure, are you supposed to interact with DocumentProviders on the UIThread?

MerlinB commented 3 years ago

Ah yes, that is interesting. I use OpenVPN and block most services, maybe I block one that I shouldn't? Nextcloud is allowed, of course. I will try to find out if that is the case. I can't really answer your question, this is where my knowledge of Android ends.

alexbakker commented 3 years ago

Related issue: https://github.com/beemdevelopment/Aegis/issues/610.

@MerlinB Could you test the patch proposed in the issue above?

@grote I don't recall reading anything about threading in the SAF documentation, so I suspect that's why a lot of apps don't bother to call SAF from a different thread. Of course, performing blocking work on the UI thread is not great practice, so we'll fix that on Aegis' end. That said, it may still be a good idea for Nextcloud to move network operations to a background thread and wait for them to finish before returning from DocumentsProvider calls. That way, the DocumentsProvider calls can remain synchronous, without inadvertently performing network operations on the main thread and running into NetworkOnMainThreadException.

MerlinB commented 3 years ago

@alexbakker Your patch does work!

grote commented 3 years ago

it may still be a good idea for Nextcloud to move network operations to a background thread and wait for them to finish before returning from DocumentsProvider calls.

Wouldn't that still block the calling thread? DocumentsProvider interactions cause I/O so I'd say it is obvious to not do them on the main thread.

/me unsubscribing again

alexbakker commented 3 years ago

Wouldn't that still block the calling thread?

Yes, it would. The goal would be to prevent NetworkOnMainThreadException from occurring, even if an app is calling from the main thread. Just a suggestion. In the case of Aegis, this issue will be fixed in its next release.

stale[bot] commented 3 years ago

This bug report did not receive an update in the last 4 weeks. Please take a look again and update the issue with new details, otherwise the issue will be automatically closed in 2 weeks. Thank you!