Troubleshoot SD-card access issue

Andy Holmes andrew.g.r.holmes at gmail.com
Tue Apr 17 18:05:36 UTC 2018


I see now what you're getting at.

> a) Where in the code is the piece that triggers that invocation the first time?

SimpleSftpServer is what it appears to be, the simplest of
implementations of org.apache.sshd.SshServer. What's actually
"triggering" it is the sshfs client on the desktop side making a
request.

> b) Could it be that after KDE has received the inital response via device.sendPacket() that it does not communicate to KDE connect on the phone anymore
but that it opens a ssh connection to the sshd server running in the background?

Yes, that's exactly what happens. The phone receives notice over port
1716 that the desktop wants to browse, the phone starts the sshd and
responds over port 1716 what port in the 1739-1764 range the sshd will
accept connections, the desktop starts sshfs connecting over the port
(in the 1739-1764 range) it's just been given. From there no more ssh
related communication happens over port 1716, it's all done by
sshfs->apache sshd.

> The point is, that if my assumption in b) is correct then we need to tell Apache sshd that there are Android specifics in reading a filesystem, e.g.
special handling of .android_secure. Either that is possible by
overwriting some more methods, or a newer version of sshd-core is
handling this better. For example
if I use Termux on my phone and list the directory of my SD card, then
I simply get a permission denied for .android_secure.

My understanding of .android_secure is that it's used to store files
from another place in the internal storage (eg, App2SD) and shouldn't
be accessed by way of the SD card at all. Investigating how other
android apps handle sftp/ssh servers, and .android_secure
specifically, would probably be a good place to start.

> If neither works, then I would assume that doing this via ssh is the wrong way.

I'm not sure using a different protocol could solve the local
filesystem problem.

Regards,
Andy

On Tue, Apr 17, 2018 at 4:13 AM,  <karl-heinz-1950 at web.de> wrote:
> Maybe I wasn't clear enough. On what you describe we can basically agree -
> until your "and so on".
>
> To make it a bit clearer I have attached a picture to this mail showing the
> process.
>
> Until "Response to KDE via device.sendPacket()" we both agree on what is
> going on. On the debugger in Android studio the next of
> my breakpoints kicking in is in createFileSystemView(). That breakpoint is
> reached without me doing any additional input. It overwrites a method
> of the apache sshd-core package. What I wanted to ask, is the following:
>
> a) Where in the code is the piece that triggers that invocation the first
> time?
> b) Could it be that after KDE has received the inital response via
> device.sendPacket() that it does not communicate to KDE connect on the phone
> anymore
> but that it opens a ssh connection to the sshd server running in the
> background?
>
> The point is, that if my assumption in b) is correct then we need to tell
> Apache sshd that there are Android specifics in reading a filesystem, e.g.
> special handling of .android_secure. Either that is possible by overwriting
> some more methods, or a newer version of sshd-core is handling this better.
> For example
> if I use Termux on my phone and list the directory of my SD card, then I
> simply get a permission denied for .android_secure. If neither works, then I
> would assume that doing this via ssh is the wrong way.
>
> I wonder if with some overwriting of methods we can change in SftpSubsystem
> the process() method for SSH_FXP_READDIR, that is the one causing the issue
> with the .android_secure directory
>
> Gesendet: Sonntag, 15. April 2018 um 21:52 Uhr
> Von: "Andy Holmes" <andrew.g.r.holmes at gmail.com>
> An: kdeconnect at kde.org
> Betreff: Re: Re: Troubleshoot SD-card access issue
> I'm not quite sure which debugger you're referring to, or what exactly
> you mean by entry point, but here's a rundown of what happens:
>
> 1) Desktop sends 'startBrowsing' packet as described above
> 2) Android app receives packet:
> https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java#L67
> a) if the server has not already started, it is started, a
> password is generated and a port opened:
> https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java#L104
> b) Plugin reads password/port from server (regardless of whether
> this is the first request) into the packet:
> https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java#L72-L75
> c) Paths are determined and attached to the packet:
> https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java#L84-L122
> d) Android app sends response packet to Desktop:
> https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SftpPlugin.java#L124
> 3) Desktop receives response packet:
> https://github.com/KDE/kdeconnect-kde/blob/master/plugins/sftp/sftpplugin.cpp#L128-L151
>
> And so on...I'm a bit unclear on exactly what you're asking, but you
> can follow the process fairly easily (I don't even know C++ or Java
> myself). Basically the Desktop tells the Android app it wants to
> browse. The android app start a ssh server and responds with the
> connect information. The desktop starts a sshfs process using that
> information, and that's it.
>
> As far as the SSH server goes it should all be in:
>
> https://github.com/KDE/kdeconnect-android/blob/master/src/org/kde/kdeconnect/Plugins/SftpPlugin/SimpleSftpServer.java
>
> Regards,
> Andy
>
> On Sun, Apr 15, 2018 at 10:45 AM, <karl-heinz-1950 at web.de> wrote:
>> Thanks, a good start.
>>
>>> 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
>>
>> You refer to method onPacketReceived. If I haven't made a mistake I would
>> claim that the onPacketReceived method is only called when I click the very
>> first time in Dolphin on the device. When I navigate back to my home drive
>> (or any other PC local drive) and then go back to the phone device in
>> Dolphin I don't see that onPacketReceived is being called again. I see in
>> the debugger that all kind of other code is being executed, so the second
>> time the directories are being displayed in Dolphin it is not taken from
>> some local cache in KDE.
>>
>> I assume that means there must be an earlier entry point in the android
>> app. Should the kde connect app receive the same JSON message with
>> startBrowsing true in the second access?
>>
>>


More information about the KDEConnect mailing list