you-apps / RecordYou

Privacy focused recorder app built with MD3
https://you-apps.net
GNU General Public License v3.0
727 stars 30 forks source link

App crashes when Nextcloud directory is selected #190

Open antrmn opened 1 year ago

antrmn commented 1 year ago

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

Bnyro commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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:

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 commented 12 months ago

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 commented 12 months ago

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 commented 11 months ago

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 commented 11 months ago

I wonder if this crash and mine are related. https://github.com/you-apps/RecordYou/issues/194 I will have to try the debug version and see what I can discover.

No pressure, though; have a great vacation!

SilverPuppy commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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 commented 11 months ago

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.

SilverPuppy commented 11 months ago

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 commented 11 months ago

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.