Troubleshoot SD-card access issue

Andy Holmes andrew.g.r.holmes at gmail.com
Sun Apr 15 11:58:38 UTC 2018


I'll try and help a little bit, since I was just looking at this yesterday.

> Question 1: When in dolphin clicking on the phone device, what is the type string? (org.kde.kdeconnect.Plugins.SftpPlugin ?) What is the body?

{ "id": 123456789, "type": "kdeconnect.sftp.request", "body": {
"startBrowsing": true } }

> Question 2: I am looking for the piece of code which is executed first on the phone when I click on that device in Dolphin. I assume it is somewhere in the Apache sshd. In other words, who is the first person touching that JSON?

Packet being handled (after being routed to the plugin):
https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java#L65

The server that gets started:
https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java

> Question 3: For my case I assume I only need the sftp plug-in. If my assumption in question 2 is correct, how (when and where) is the sftp plug-in being called?

Assuming the routed, handled packet contains "startBrowsing", just a
few lines later:
https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java#L68

then...
https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java#L103

> Question 4: Where in the code is this JSON being parsed the first time? (Probably the same answer as question 2?)

Yes, depending on what you mean by parsed. The packets are routed to
the handler/plugin using the type field, depending on whether the
plugin is actually loaded/supported.


I don't have an SD card myself, however there was an extended
conversation with some exploratory work done by users of my Gnome
Shell extension (I take no credit or blame for the usefulness):

https://github.com/andyholmes/gnome-shell-extension-gsconnect/issues/48

If I recall _some_ of the problems are related to directory
permissions on the phone, which sometimes causes the sshd server to
fail.

On Sat, Apr 14, 2018 at 10:38 PM,  <karl-heinz-1950 at web.de> wrote:
>
>
> Hello,
>
> I would like to help debug and sort out an issue that SD-Cards on the phone
> are not read properly and that write access doesn't work. I believe that
> this issue has been mentioned quite a few times (I myself can verify it on 4
> phones). Some of the reports about the issue I am (possibly) referring to
> are
>
> https://bugs.kde.org/show_bug.cgi?id=391464 (I commented that one already
> quite a bit)
> https://mail.kde.org/pipermail/kdeconnect/2018-April/003476.html
> https://bugs.kde.org/show_bug.cgi?id=389851
> https://bugs.kde.org/show_bug.cgi?id=377058
> https://bugs.kde.org/show_bug.cgi?id=380022
>
> =========== History what I have found so far ==============
>
> Let me wrap up what I believe what I have found so far. First of all we have
> two issues, hopefully both can get fixed with the same change.
>
> 1) SD-card shows as empty, but if you enter a known subdirectory it shows in
> Dolphin
> 2) Cannot write to SD-card
>
> For number 1) I can clearly see in the debugger that the issue is the
> .android_secure file. The Apache sshd has an issue to read it, because
> Android reports back that this is not a file and there doesn't seem to be
> proper exception handling in sshd. If in the debugger at the right position
> you can skip the loop for this file and the content is shown correctly.
> Unfortunately it seems that all this happens purely in the Apache sshd
> library. I have not found a piece of code in kde-connect where I can check
> for this directory and skip it. Android seems to handle this directory
> somehow special.
> I see that you use a very old Apache sshd. In the gradle file I see that you
> use version 0.8 and claim that 1.+ requires java.nio.file which doesn't exit
> in Android. It is there since API Level 26
> https://developer.android.com/reference/java/nio/file/package-summary.html
> which is Android 8.0. I tried to change the code to use sshd-core 1.7 (your
> version is about 6 years old). Unfortunately it seems that the package was
> refactored quite heavily in the past 6 years. Maybe that view issue would be
> solved by an update to sshd-core 1.7. I am pretty sure the write issue
> wouldn't. Nevertheless having a 6 years old component being used can of
> course lead to all kind of other issues (security patches?). For know I
> don't want to try to update this library, maybe someone knows it well and
> can give this a shot.
>
> For number 2) I strongly believe this has to do with the Android storage
> access framework (SAF).
>
> https://developer.android.com/guide/topics/providers/document-provider.html
> https://stackoverflow.com/questions/36862675/android-sd-card-write-permission-using-saf-storage-access-framework
>
> I can see that you seem to use the SAF when you send a file from the phone
> to KDE (which works fine for me). I don't see that you use SAF when you try
> to send a file from KDE to the phone. You seem to use everything natively
> within the sshd package. My understanding is that this will fail for sure
> for all devices Kitkat+.
>
> =========== What I need to know to troubleshoot this issue ==============
>
> Nicolas gave me in the first bug report the link to
> https://cgit.kde.org/kdeconnect-kde.git/about/ that is a good first step. I
> would like to understand the communication a bit better, of course for the
> case where dolphin tries to access the phone. You write that you exchange
> JSON files like
>
> { "id": 123456789, "type": "com.example.myplugin", "body": { }, "version": 5
> }
>
> Question 1: When in dolphin clicking on the phone device, what is the type
> string? (org.kde.kdeconnect.Plugins.SftpPlugin ?) What is the body?
>
> Question 2: I am looking for the piece of code which is executed first on
> the phone when I click on that device in Dolphin. I assume it is somewhere
> in the Apache sshd. In other words, who is the first person touching that
> JSON?
>
> Question 3: For my case I assume I only need the sftp plug-in. If my
> assumption in question 2 is correct, how (when and where) is the sftp
> plug-in being called?
>
> Question 4: Where in the code is this JSON being parsed the first time?
> (Probably the same answer as question 2?)
>
> So in essence I need to know the internal communication in _detail_. My idea
> is, once I understood that communication, to see where I can divert the
> communication back from the Apache sshd code to kdeconnect code. Once that
> is found I will try to do all the handling using SAF. I know it is not a 5
> minute job...
>
> Thanks so far
>     Joe
>


More information about the KDEConnect mailing list