Fix the SFTP plugin on some phones (use Android Storage Access Framework?)
Closed, ResolvedPublic

Description

Like LG4

albertvaka renamed this task from Use Android Storage Access Framework for the SFTP plugin to Fix the SFTP plugin (use Android Storage Access Framework?).May 25 2017, 9:17 AM
albertvaka renamed this task from Fix the SFTP plugin (use Android Storage Access Framework?) to Fix the SFTP plugin on some phones (use Android Storage Access Framework?).Jul 26 2017, 10:11 PM
albertvaka updated the task description. (Show Details)
jeanv added a subscriber: jeanv.Aug 3 2017, 7:45 AM

I noticed I don't have write access on my SD card with the SFTP plugin, is it part of this task?

Well, this task is about doing anything necessary to make it work :P On some phones, kdeconnect doesn't have access to the sdcard, indeed, and that's big part of the problem. I don't know why it happens though nor how to fix it.

jeanv added a comment.Aug 7 2017, 9:14 AM

These two stackoverflow discussions, here and here, seem to answer how to write to external storage with the Storage Access Framework. Android also provides docs for the SAF, but it's not great imo.

I don't plan on working on this, as I don't have any experience on Android, and the SAF in particular is not very appealing. But that's what I found.

jeanv claimed this task.Aug 26 2017, 1:49 PM

I lied, I've actually been working on this. I'm far from done yet, but at least I managed to write to the SD card, which wasn't possible before. I'm currently trying to make it work through the SFTP plugin. I'll upload a diff when I have a somewhat working version to get some feedback.

:D To make it work, do you first need to make the user select the SD root directory from the app, to obtain permissions to access it? That's what I thought would be necessary, but I'm curious to know if you found a different way :)

jeanv added a comment.Aug 26 2017, 3:35 PM

That's what I did, yes. I don't think there is any other way, Android really doesn't want anyone to access the filesystem without their API :/

We could ask the user for it the same way we ask for permissions... The wording could be something like "Please select the root directory of your phone to make it available from your PC" maybe?

jeanv added a comment.Aug 29 2017, 4:35 PM

That's what I had in mind too. Right now there's an intermediate screen with the FindMyPhone UI because I copy-pasted so it looks stupid but I couldn't be bothered :D

Progress report: creating a new empty file, renaming and deleting work (although it's definitely not pretty or optimised) but I can't get transferring or modifying files to work. Something with the write() method in SftpSubsystem or createOutputStream(). And I can override createOutputStream() which is what I'm working on but I can't override write(). With my own streams and write(), writing data to files actually works.

Beside rewriting a big portion of SftpSubsystem which is not really desirable, I don't have a lead for now. I'll post more details here (and maybe on StackOverflow) if I keep being stuck.

I haven't been working on this lately because even though quite a few features work (permissions, creating new files, renaming, moving, deleting...), I was stuck on several major problems, in particular transferred files are empty until the device is rebooted (an outputstream doesn't close properly or something like that I think).

On top of that, working with the Android API is very frustrating, especially when it comes to filesystems.

Here is my private repository if someone wants to see (I worked on the storage-access-framework branch): https://gitlab.com/jean-sh/kdeconnect-a-private. The entire AndroidSftpSubsystem class is just a copy of SftpSubsystem so that I can test modifying stuff in it.

I might give it another go later so I won't abandon the task for now...

Thanks for sharing the code :)

jeanv removed jeanv as the assignee of this task.Mar 5 2018, 8:19 PM
eduisters added a subscriber: eduisters.

Should be fixed by D18212

eduisters closed this task as Resolved.May 3 2019, 4:27 PM

Fixed by D18212