Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

App crashes when Nextcloud directory is selected #190

Open
3 tasks done
antrmn opened this issue Aug 21, 2023 · 14 comments
Open
3 tasks done

App crashes when Nextcloud directory is selected #190

antrmn opened this issue Aug 21, 2023 · 14 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@antrmn
Copy link

antrmn commented Aug 21, 2023

Steps to reproduce

  1. Choose a directory from Nextcloud document provider as directory
  2. Try to record

Expected behavior

Recording should start. File should be saved in Nextcloud.

Actual behavior

App crashes

Record You version

7.0 (15)

Android version

Android 12

Other details

No response

Acknowledgements

  • I have searched the existing issues and this is a new ticket, NOT a duplicate or related to another open issue.
  • I have written a short but informative title.
  • I will fill out all of the requested information in this form.
@antrmn antrmn added the bug Something isn't working label Aug 21, 2023
@Bnyro
Copy link
Member

Bnyro commented Sep 2, 2023

Could you please try to obtain a crash log? (You most likely want to use a debug build from the GitHub actions tab for that).

@antrmn
Copy link
Author

antrmn commented Sep 2, 2023

Could you please try to obtain a crash log? (You most likely want to use a debug build from the GitHub actions tab for that).

Sure, I got the latest artifact from Actions and followed the steps mentioned above. Here is the output of adb logcat --pid=$(adb shell pidof -s com.bnyro.recorder.debug):

--------- beginning of main
09-02 21:23:38.920  3393  3455 D OpenGLRenderer: endAllActiveAnimators on 0xb400007a3e869a40 (UnprojectedRipple) with handle 0xb40000794e8932f0
09-02 21:23:54.916  3393  3393 D CompatibilityChangeReporter: Compat change id reported: 160794467; UID 10752; state: ENABLED
09-02 21:23:54.930  3393  3393 I AudioManager: In startbluetoothSco(), calling application: com.bnyro.recorder.debug
09-02 21:23:55.636  3393  3393 I Choreographer: Skipped 39 frames!  The application may be doing too much work on its main thread.
09-02 21:23:59.712  3393  3393 E MediaRecorder: stop failed: -1007
09-02 21:23:59.731  3393  3393 I AudioManager: In stopBluetoothSco(), calling application: com.bnyro.recorder.debug
09-02 21:23:59.784  3393  3393 I AudioManager: In stopBluetoothSco(), calling application: com.bnyro.recorder.debug
09-02 21:24:03.806  3393  3455 D OpenGLRenderer: endAllActiveAnimators on 0xb400007a3e86cdc0 (UnprojectedRipple) with handle 0xb40000794e893530
09-02 21:24:23.793  3393  3393 I AudioManager: In stopBluetoothSco(), calling application: com.bnyro.recorder.debug
09-02 21:24:30.015  3393  3393 I AudioManager: In stopBluetoothSco(), calling application: com.bnyro.recorder.debug
09-02 21:24:30.022  3393  3393 I AudioManager: In startbluetoothSco(), calling application: com.bnyro.recorder.debug
09-02 21:24:30.204  3393  3393 W DocumentsContract: Failed to create document
09-02 21:24:30.204  3393  3393 W DocumentsContract: android.os.ParcelableException: java.io.FileNotFoundException: Failed to upload document with path /Record You/2023-09-02_21-24-30.m4a
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.ParcelableException$1.createFromParcel(ParcelableException.java:82)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.ParcelableException$1.createFromParcel(ParcelableException.java:79)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Parcel.readParcelable(Parcel.java:3400)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Parcel.createExceptionOrNull(Parcel.java:2462)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Parcel.createException(Parcel.java:2449)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Parcel.readException(Parcel.java:2432)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.content.ContentProviderProxy.call(ContentProviderNative.java:732)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.content.ContentResolver.call(ContentResolver.java:2453)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.provider.DocumentsContract.createDocument(DocumentsContract.java:1380)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at androidx.documentfile.provider.TreeDocumentFile.createFile(TreeDocumentFile.java:53)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at androidx.documentfile.provider.TreeDocumentFile.createFile(TreeDocumentFile.java:45)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at com.bnyro.recorder.util.FileRepositoryImpl.getOutputFile(FileRepository.kt:91)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at com.bnyro.recorder.util.FileRepository$DefaultImpls.getOutputFile$default(FileRepository.kt:21)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at com.bnyro.recorder.services.AudioRecorderService.start(AudioRecorderService.kt:41)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at com.bnyro.recorder.ui.models.RecorderModel$connection$1.onServiceConnected(RecorderModel.kt:55)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2088)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2121)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Handler.handleCallback(Handler.java:938)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Looper.loopOnce(Looper.java:346)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.Looper.loop(Looper.java:475)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.app.ActivityThread.main(ActivityThread.java:7889)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at java.lang.reflect.Method.invoke(Native Method)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009)
09-02 21:24:30.204  3393  3393 W DocumentsContract: Caused by: java.io.FileNotFoundException: Failed to upload document with path /Record You/2023-09-02_21-24-30.m4a
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at java.lang.reflect.Constructor.newInstance0(Native Method)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	at android.os.ParcelableException.readFromParcel(ParcelableException.java:56)
09-02 21:24:30.204  3393  3393 W DocumentsContract: 	... 27 more
09-02 21:24:30.204  3393  3393 D AndroidRuntime: Shutting down VM
--------- beginning of crash
09-02 21:24:30.205  3393  3393 E AndroidRuntime: FATAL EXCEPTION: main
09-02 21:24:30.205  3393  3393 E AndroidRuntime: Process: com.bnyro.recorder.debug, PID: 3393
09-02 21:24:30.205  3393  3393 E AndroidRuntime: java.lang.NullPointerException
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at com.bnyro.recorder.util.FileRepositoryImpl.getOutputFile(FileRepository.kt:92)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at com.bnyro.recorder.util.FileRepository$DefaultImpls.getOutp
utFile$default(FileRepository.kt:21)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at com.bnyro.recorder.services.AudioRecorderService.start(AudioRecorderService.kt:41)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at com.bnyro.recorder.ui.models.RecorderModel$connection$1.onServiceConnected(RecorderModel.kt:55)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:2088)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	
      at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:2121)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at android.os.Handler.handleCallback(Handler.java:938)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at android.os.Handler.dispatchMessage(Handler.java:99)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at android.os.Looper.loopOnce(Looper.java:346)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at android.os.Looper.loop(Looper.java:475)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at android.app.ActivityThread.main(ActivityThread.java:7889)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at java.lang.reflect.Method.invoke(Native Method)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
09-02 21:24:30.205  3393  3393 E AndroidRuntime: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1009)
09-02 21:24:30.220  3393  3393 I Process : Sending signal. PID: 3393 SIG: 9

@Bnyro
Copy link
Member

Bnyro commented Sep 2, 2023

Thanks for sharing the log!

Seems like the culprit comes from the returned path by the Android file picker.

Have you used any other app successfully yet that allows to save files to the Nextcloud folder (an open source would be nice so we can just see what they're doing differently)? For example apps like Seal should allow to set a custom download folder, or for example is it possible to download files via the Browser to the nextcloud folder?

@antrmn
Copy link
Author

antrmn commented Sep 2, 2023

Have you used any other app successfully yet that allows to save files to the Nextcloud folder (an open source would be nice so we can just see what they're doing differently)?

In the past month I've been actively searching for apps that could support accessing the Nextcloud document provider. I post a list of all the apps I've found right below.

There are many apps that do not support the ACTION_OPEN_DOCUMENT_TREE intent, and even less are the apps that properly support document providers such as Nextcloud.

For example apps like Seal should allow to set a custom download folder

Thank you for making me discover this app. It supports the ACTION_OPEN_DOCUMENT_TREE intent but unfortunately it is pretty restrictive on the folder choice (It seems you can't even select an sdcard directory) due to app design.

is it possible to download files via the Browser to the nextcloud folder?

Neither Firefox nor chrome allow to select a custom directory for downloads. However, on Firefox it is possible to use an external download manager such as Download Navi, which supports setting a Nextcloud directory as a final destination

Anyway, here's the list:

  • Download Navi: can set a Nextcloud directory in the "Move after download in" option.
    • There's another option called "Save downloads in" which is for not-yet-completed download and gives troubles if a Nextcloud directory is selected
  • Termux:API: master branch (no tagged release yet!) has some termux-saf- commands which allow accessing directories in document providers
  • Emacs for Android: M-x android-request-directory-access, then C-x C-f /content/storage/... contains trees for each selected directory. I feel like this is the most complete SAF implementation. The app in itself is quite complex because well, it's Emacs, but the Java glue code is quite thin and may be worth checking out, at least for the extensive commentary (Link)
  • Orgzly: you can select a Nextcloud directory as a repository
  • Material Files: FOSS file manager, can browse Nextcloud from here with no issues
  • Primitive ftpd: You can start a ftp server and share a document provider's content (like Nextcloud) from there
  • My Expenses: can select Nextcloud as a backup directory
  • Aegis: like above, can select Nextcloud as backup directory

There's also MiXplorer, but it's closed source.

I did not include apps which only supported other similar intents like ACTION_OPEN_DOCUMENT (which is for selecting a single file). One such example is KeepassDX

@Bnyro
Copy link
Member

Bnyro commented Sep 3, 2023

Thanks for the list!

I've started Nextcloud too recently, so I'm able to reproduce the issue as well now, which should make it easier (hopefully) to find a solution.

I'm linking this article with some useful info about the file system for myself or anyone who wants to look into it.

I'm in vacation currently however, so I won't be able to look into this too soon.

Again, thanks for your help so far!

@SuhasDissa
Copy link
Member

I don't know if we will be able to fix this issue or not.
Nevertheless we should at least fix the app crash and show a decent error message.

in the above log the NullPointerExeption is caused by this line

return recordingFile!!

As we try to return a nullable value as not null

@Bnyro
Copy link
Member

Bnyro commented Sep 7, 2023

I don't know if we will be able to fix this issue or not.
Nevertheless we should at least fix the app crash and show a decent error message.

I agree. The DocumentFile API doesnt seem to return a proper error message when trying to create a file unfortunately, so not sure how we display the cause of the issue (or just always say something like "File creation failed. Please select a different directory"?)

@SilverPuppy
Copy link

I wonder if this crash and mine are related. #194 I will have to try the debug version and see what I can discover.

No pressure, though; have a great vacation!

@SilverPuppy
Copy link

I don't know if we will be able to fix this issue or not.
Nevertheless we should at least fix the app crash and show a decent error message.

I agree. The DocumentFile API doesnt seem to return a proper error message when trying to create a file unfortunately, so not sure how we display the cause of the issue (or just always say something like "File creation failed. Please select a different directory"?)

I think that is a very viable short term solution that would yield benefits in other circumstances where an apparently writeable destination doesn't work, for whatever reason.

@Bnyro
Copy link
Member

Bnyro commented Sep 8, 2023

No pressure, though; have a great vacation!

Thank you! My vacation is already over unfortunately, but it's been really nice :)

We're now showing an error message when the directory can't be written too.
However, it's really strange that our code doesn't work, as I compared the code with Keypass, and we're literally doing exactly the same as they do. I'll try to spot the difference, but it's really not looking like there's anything obvious.

@SilverPuppy
Copy link

SilverPuppy commented Sep 8, 2023

No pressure, though; have a great vacation!

Thank you! My vacation is already over unfortunately, but it's been really nice :)

We're now showing an error message when the directory can't be written too. However, it's really strange that our code doesn't work, as I compared the code with Keypass, and we're literally doing exactly the same as they do. I'll try to spot the difference, but it's really not looking like there's anything obvious.

You are super awesome. I'm both sorry and glad you're back from vacation. I'll have to play with this version if I get a chance and see if it changes the behavior I'm experiencing. If I'm just patient or too busy, how quickly do commits like this get to Fdroid?

@Bnyro
Copy link
Member

Bnyro commented Sep 8, 2023

If I'm just patient or too busy, how quickly do commits like this get to Fdroid

That will last until the next release in some weeks, my goal is to fix the whole issue before it.

We have CI builds here, which allows to test the latest changes.

However, the only thing you will see is an error message, it's still not possible to use the Nextcloud folder properly.

@Bnyro Bnyro added the help wanted Extra attention is needed label Sep 8, 2023
@SilverPuppy
Copy link

Very helpful. Thank you. I'm not using a NextCloud synced folder, but wondering if perhaps the issue I experience occasionally isn't also connected to a peculiarity with writeability, in which case the error message would be both a stability improvement and an aid to troubleshooting.

@SilverPuppy
Copy link

I downloaded and installed the CI build, and note that the visualization and record clock in the app do not work, but everything else is working. I will continue to use this build as a test to see if the visualization or a writeability issue might be the cause of the issue I have been having, #194.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants