A dive into Jolla AppSupport

You might be aware of Jolla, a Finnish company that emerged after Nokia decided to stop using MeeGo and went with Windows Phone instead. Around 2012 Jolla started out by making their own hardware (these days they no longer do) and they have their own OS based on the MeeGo stack, SailfishOS.

Because the app availability on Sailfish OS is rather slim, Jolla has built excellent middleware to run Android apps on Sailfish OS: AppSupport, known as Aliendalvik internally in Sailfish OS. Conceptually, Aliendalvik is a lot like Waydroid: It runs a modified Android system inside an LXC container, sharing the kernel with the host system. Compared to Waydroid, Aliendalvik has much better integration with the host. It shows Android apps as individual Wayland windows, it forwards notifications and MPRIS from Android, syncs Contacts from the host into Android, uses the native on-screen keyboard, and much much more.

Sailfish OS itself is free software and Jolla appears to be quite proud of this and their connection with the community (they have a forum where developers hang out and even implement ideas from users regularly). However, Aliendalvik is unfortunately proprietary: You only get binaries, no source code, and it’s only shipped as part of the images for their officially supported phones. To try it you first have to get your hands on one of these four Sony Xperia phones and then buy the Sailfish OS image in the Jolla online shop.

That said, once you bought and installed that image, you can play around with Sailfish OS and Aliendalvik. My initial experience was that Sailfish OS works fairly well and feels a lot more mature than what we have with GNOME Shell Mobile or Phosh (that’s not really a surprise given that it’s largely the same stack that was powering the N900, whereas our stack is completely different and a lot more work-in-progress). What blew me away though was how seamless the Aliendalvik integration is: Once you managed to install an Android app store, these Android apps feel almost completely native. If you didn’t know better you couldn’t tell it’s actually a containerized second OS.

Naturally, this sparked my interest in reverse engineering. After all, the Sailfish OS stack is so similar to ours that this thing might run on different distros, too. So I SSHed (yes, you can enable SSH in developer options!) into the phone and started exploring the internals of the OS a bit more in depth.

Diving into the Sailfish OS stack

The Sailfish userspace is mostly based on the same technologies that GNOME and KDE use: glibc, systemd, DBus, RPM and PackageKit, PulseAudio, BlueZ, Wayland, and Qt. They run their own Wayland compositor (lipstick, based on QtCompositor), apps run sandboxed using Firejail, networking is handled by ConnMan, the modem is handled by oFono, and sensors (apparently together with various other things) are handled using MCE, which is probably the furthest away from our stack.

The interesting thing here is that due to the fairly standard userspace Sailfish is using, the Android integration is mostly using standard freedesktop APIs to integrate with the host OS: Running Android apps are exposed as individual Wayland surfaces/windows, notifications from Android appear as org.freedesktop.Notification messages on DBus, music player controls are exposed using MPRIS, and even text input for android apps can be provided using the Wayland text input protocol.

This means that basically Aliendalvik should work just as well on a standard Linux distribution like Fedora, Arch Linux, or Debian. The Android container can be started using standard linux container tooling and the host integration binaries are compiled for ARM64 and mostly link to various open source Qt libraries.

Running it on Arch

So yeah, by now you probably have an idea where this is going: I replaced the underlying OS with Arch Linux ARM, and after a day or two I had bootup logs from the Android container. Another few days of getting all the system services inside Android to start and I had the Android settings app popping up as a Wayland window in GNOME Shell. By then I was pretty much hooked and wanted to get all the host integration working.

With a bunch of DBus API shimming, providing Qt libraries needed by the host-integration and small adjustments in the compositor and libwayland, the whole thing “just works”.

I’ve documented the reverse engineering work on this Github repo, including a very rough step-by-step manual of how to run things. Obviously I can’t share any binaries or other files proprietary to Jolla.

It’s closed source, how is any of this useful?

Well, first of all, reverse engineering is fun, and getting software like Aliendalvik to run on GNOME is a great challenge. From my personal standpoint, this is already enough justification 🙂

The usefulness of this work to the greater community depends on what Jolla will do going forward.

The Linux mobile community is growing, there’s better upstream software and hardware support than ever, and we have amazing communities of talented people; postmarketOS, KDE, GNOME, UBPorts, to name just a few. I’m convinced though that if we want Linux on phones to become an option for everyone, there’s no way around the need for well-integrated support for Android apps.

One option might be for Jolla to officially support running Aliendalvik on other desktop environments than Sailfish OS and offer the Aliendalvik binaries using a third-party repo. Users could then buy the software and get personalized access credentials to this repo, similar to how it works on Sailfish OS (Aliendalvik itself already implements a bunch of Wayland protocols which aren’t used in Lipstick, so it’s probably running under different compositors and trying to be a standard-compliant Wayland client already).

But in my opinion, the real potential for Aliendalvik would be in making it part of the open source community. Availability to the broader Linux community would mean we could work together and help fixing bugs, implement new features, and cooperate on the underlying stack to better meet Aliendalvik’s needs. And while Waydroid as the current FLOSS solution is great already, getting it to the point where Aliendalvik currently is at will take a lot of time and effort. It’s a shame we’ll have to redo that work when there’s a great solution out there already.

What’s next?

I’d like this post to be seen as invitation to both the FLOSS community and to Jolla.

As a community I think we should put more focus on Waydroid, sadly development there has slowed down recently. We need Android app compatibility if we want to get anywhere close to competing with Apple and Google. Every day we leave this problem unsolved is a win for them and a loss for the rest of the world.

On the other hand, I’d like to invite Jolla (or whoever actually owns Aliendalvik) to get in touch with the community about this. The industry is moving towards open source solutions, these days faster than ever. FLOSS software has become the standard in basically all areas. Aliendalvik could profit a lot from making this step, too.

Thanks for reading! If you have any insights or want to help figuring this problem out, please reach out to me at verdre@v0yd.nl.