Skip to content

SharePlugin: Configure receiving directory in plugin permission mechanism

Anjani Kumar requested to merge anjani/kdeconnect-android:share into master

Summary

Fixes 422330

On Android 10 receiving files fail when we use the default storage location as returned by Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS). This happens to be the cause of this failure.

2020-04-25 12:58:53.713 18328-18602/org.kde.kdeconnect_tp E/Shareplugin: Error receiving file
    java.lang.RuntimeException: Cannot create file 01 The Nights (Avicii By Avicii).mp3
        at org.kde.kdeconnect.Plugins.SharePlugin.CompositeReceiveFileJob.getDocumentFileFor(CompositeReceiveFileJob.java:285)
        at org.kde.kdeconnect.Plugins.SharePlugin.CompositeReceiveFileJob.run(CompositeReceiveFileJob.java:152)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)

and destinationFolderDocument.createFile(mimeType, displayName) always returns null which leads to the exception. This might be because Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) is deprecated in API 29 or Android 10 and paths returned by it are not writable by the app.

Receiving files start working when the custom directory is configured from Share and receive settings which uses a recommended approach to get a writable path Intent.ACTION_OPEN_DOCUMENT_TREE as per Android documentation https://developer.android.com/reference/android/os/Environment#getExternalStoragePublicDirectory(java.lang.String

To avoid this, we should set the writable directory when the user is allowing plugin permissions on Android 10. When Storage permission is granted during plugin setup, this patch opens a directory selector and saves it as a custom location which avoids null when calling destinationFolderDocument.createFile(mimeType, displayName) because the path is now writable.

Screenshot_20200425-133134

Test Plan

Before:

Send a file/files from a desktop. A notification appears on the phone showing failure.

Screenshot_20200425-121746

After:

Receiving files now work.

Edited by Anjani Kumar

Merge request reports

Loading