So, this is my first development related blog post. It will be about the current state of kio-mtp, why it is not in KDE SC 4.11 and most likely won’t be in 4.12, as well as the roadmap for the future.
The 3 quick answers (a.k.a. tl;dr):
- The good news: It works as designed. However the MTP implementation on some devices is creating problems. Sadly this affects quite a lot of users.
- This results in issues which I didn’t have time to solve as I moved into my first own flat and the problem is not trivial. Plus, it affects other programs too, so I’d like to do it right and have it solved in general.
- In the future there will be a daemon that will expose a DBus interface that will handle all session and device related stuff and maybe do some scheduling for (pseudo)parallel access. There will also be a Qt library that will abstract those DBus calls so that not everyone has to fiddle with that.
The current state
Ok, so it works? Yes it does. At least for Google Nexus Android devices. Or those devices using the builtin MTP Stack of Android. Or those that don’t expect Windows-like behaviour. Basically those who put some handling of unexpected states in their code. Which Samsung didn’t when they wrote their own.
Ok, enough with the short sentences. I do not want to point fingers. Samsung’s MTP stack is what it is, and it works fine at first as long as nothing unexpected happens. And yes, they have good reasons to implement their own stack (additional features for KIES for example that would probably never make it into the official Android stack) and the expectation that most users will access the device using Windows, which is a valid assumption.
So what exactly is this Windows-like behavior and how is it different to what we do in Linux? Windows simply connects to a MTP device once it detects one and drops the connection once it is unplugged. All applications then access this device through this existing connection. LIBMTP, the no 1 way of accessing MTP devices under Linux however provides low level access. So we have to do everything ourselves.
Ok, so we have to create a connection to the device ourselves. Yes, a little more low level, but we Linux developers are used to that kind of thing. And it really isn’t hard as the API is nice and clean once you understand it. The problem is in the system: Every Application creates its own connection as it is not aware if another program is accessing the device at the moment. As more than one connection per device is not supported, the previous connection should be dropped and the new one established. Which creates problems, but we can recover from a broken file transfer. An the Google stack supports this nicely. Samsung’s MTP stack however cannot recover from the fact that a new connection was opened. So
all hell breaks loose the MTP stack freezes. And the only thing you can do is to unplug the device and plug it in again. Which is, mildly put, not a nice user experience.
So: This happens when you access the device from other applications? Yes, but also when you create a second instance of the same program, in this case the kio slave. When browsing files, for example using Dolphin, this is not a problem: You can instruct kio to only use one instance and this is done in kio-mtp. For some reason however when you open a device from the device notifier plasmoid, another instance is created. And it doesn’t close the session before the instance opened by Dolphin tries to open a new one -> Crash Boom Bang…
So: Yes, I should have opened a bug report against kio. But, as stated above, I did not have time to work on it much the last couple of months. Also: There are a lot more things that should be fixed in kio but will mostly have to wait for Frameworks 5 due to the corresponding freeze. Plus the problem is best solved for all users and programs and not just the kio slave.
So, when discussing these problems on the LIBMTP mailing list my proposal for a MTP DBus Daemon were happily commented on. Linus Walleij, the lead developer of LIBMTP was happy to incorporate the project directly in LIBMTP. Philip Langdale, who wrote the GNOME VFS backend for MTP, and Matěj Laitl, who is currently rewriting the Amarok MTP support, were and are very helpful. Philip provided the initial setup of the subfolder and the required adjustments to the autotools build system, Matěj and I reworked some of the DBus API specifications during the Akademy in Bilbao.
So this is what I will work on for the foreseeable future. Once the daemon is finished I will start libmtpd-qt(4|5) that will provide a nice Qt API to the whole thing. kio-mtp and Amarok will then be adapted to make use of this API if it is present. I will try and post updates regarding the process whenever I have time and there is something to report.
If you want to contribute, just ping me (hefeweiz3n) on IRC in #kde-devel on freenode or write me a mail. The address can be found in the licence part of the daemon source files (subfolder daemon in LIBMTP). Be sure to switch to the mtp-daemon branch to get it . Regarding the branch: I hope to be able to push some usable stuff in the near future. So: Exiting times!