Finally, Android on the iPhone

Nick Lee
Tendigi
Published in
6 min readJun 7, 2016

--

You heard me. The holy war is over, brethren. At Tendigi, we’ve designed and built a case that allows iPhone devotees to sample the best Mountain View has to offer. Join me as I outline the steps taken to achieve this feat, as well as the numerous pitfalls encountered along the way.

(click video to play)

Background & Motivation

Here at Tendigi, we’re no strangers to putting strange operating systems on Apple hardware. After observing the overwhelming reaction to my last hack, it seemed only fitting to raise the stakes.

Testing the Concept

Despite some obvious drawbacks, Android has a killer feature that made this project possible: (virtually) the entire operating system is open-source. The Open Handset Alliance (a consortium of carriers, phone manufacturers, and software developers led by Google) maintains the Android Open Source Project. The AOSP is the foundation of all device-specific flavors of Android shipped on phones from manufacturers like Motorola, HTC, LG, etc. For a platform of its scale, it’s surprisingly easy to clone it out and build it on your local machine. From scratch, I was able to develop an efficient AOSP workflow in about two days.

Since we had an unused one laying around the office, I decided to target the LG Nexus 5 for my initial proof-of-concept. I ended up having to port (or outright build) the following components for Android:

  • libimobiledevice: An open-source suite of tools that enable native communication with iOS devices.
  • usbmuxd: An clone of Apple’s daemon of the same name, this service multiplexes TCP connections to sockets listening locally on the iPhone. In simpler terms, it allows you to use a USB cable to an iPhone as a high-speed network connection. Without this, I’d have probably resorted to Wi-Fi which would have resulted in lower frame rates and unpredictable latency.
  • screenstreamer: A daemon I wrote that connects to the usbmuxd service, transmitting the screen’s contents to the iPhone and emulating touch events on the Android side. This is where the magic happens. While there are many ways to capture the screen on Android, I achieved the best performance by connecting to the SurfaceFlinger service and reading screenshots from it. For more information, see this header file and this presentation. The droidVncServer repository on GitHub also contains some helpful pointers.

Once these components were individually tested and confirmed to work, I modified my AOSP build’s init script to launch the screenstreamer daemon on startup. After writing a simple iOS application that handles the incoming connection from Android, I was off to the races:

Eureka?

Choosing the Hardware

While there are many embedded Android development boards on the market, my criteria substantially narrowed the list of suitable candidates. I settled on the following requirements:

  • Horsepower: the device must capture, compress, and transmit the screen’s contents in realtime at high frame rates.
  • Compatibility: the device must run the latest version of Android (version 6.0.1 Marshmallow at the time of this writing).
  • Size: the board must be small and thin — approximately the dimensions of a credit card, the height of a USB connector.
  • Connectivity: The board needs built-in Wi-Fi and Bluetooth because I don’t want to write drivers to bridge these to the iPhone’s connections. Also, it needs built-in USB 2.0 for a high-speed, reliable connection to the host iPhone.

With these criteria in mind, I chose the Lemaker HiKey. While its 8-core, 64-bit ARM Cortex-A53 processor has more than enough power to run virtually any Android app on the market, it sports a unique party piece: it’s the official reference board of the Android Open Source Project. As a result, most of the HiKey’s necessary components are included directly in the AOSP source tree (a lifesaver). That said, getting my custom AOSP build to run successfully was still a tall order, requiring me to (among other things) recompile the kernel with performance-oriented tweaks to the USB driver.

Say hello to my little friend

For power, I purchased a 650 mAh lithium-polymer battery pack with an integrated protection circuit (to avoid this). Since the HiKey requires an 8–18 volt supply, I used a boost converter to increase the voltage from the battery pack’s native 3.7 volts.

Yo dawg, I heard you like mad power so I put a turbo on your turbo so you can boost while you boost

While the initial power-on was successful, complete system failure occurred upon connecting a lightning cable between my iPhone and the HiKey. After some multimeter-fueled investigation, I concluded that the iPhone was simply drawing too much current, and the battery couldn’t supply enough to run the HiKey and charge the phone. No biggie — I added a resistor between the USB port’s +5V pin and the lightning cable, limiting the current to a reasonable amount. I couldn’t simply clip the 5 volt line as iOS seems to disable USB data transfer unless power is also connected. Life lesson: V=IR is your friend.

Designing the Enclosure

As the electronic component of this project came together, one thing quickly became apparent: my original plan to gut a Mophie Juice Pack wasn’t going to work. Knowing that, I shifted my focus to the production of a 3D printed enclosure for the electronics. Starting with absolutely zero 3D modeling or printing knowledge, I was up-and-running with SketchUp in a matter of hours. Rather than model the case from scratch, I used this excellent iPhone 6 Plus case model from Thingiverse as a base, making modifications as needed.

Some early renders of the case’s parts

Once the models were complete, the next challenge presented itself: actually printing the thing. After calling a few 3D print shops in the NYC area, it became clear to me that (at $50+ per print) this would quickly become an expensive proposition, given the trial-and-error process I anticipated. Seeing no viable alternative, I bit the bullet and purchased an XYZprinting da Vinci 2.0 Duo 3D printer. Somehow, B&H manages to keep a huge assortment of 3D printers in stock at their Manhattan location. A short Uber ride later, I was in business.

The most awkward UberPOOL in history

Setting up the printer was relatively straightforward — I was able to make a test print within half an hour of unboxing it. What was not straightforward, however, was the process of exporting clean-looking models from SketchUp. In my case, the issue was that my model had many reversed faces (sometimes called inverted normals). If you plan to 3D print from SketchUp, I highly recommend reading this article: 3D Printing with SketchUp: 10 Tips and Tricks. Once my objects were sufficiently cleaned up, I hit the print button and crossed my fingers. A few hours later, I had a (very thick) iPhone case!

There’s a Gabriel Iglesias joke in here somewhere

The initial component placement went well — the HiKey board, boost converter, and battery fit well with plenty of room to spare. As a result, I was eventually able to shed the mid-nineties-putty-white-brick feel by printing a (much) thinner case.

Thick-cut bacon is my favorite snack

The Final Product

Once I had a clear idea of component size and layout, I scaled the 3D model to a more reasonable size and added openings for the SD card, HDMI and USB ports. It’s not too much thicker than the average battery case 🙃

About Tendigi

We are a mobile design and development studio located in Brooklyn, NY. If you’d like to learn how our award-winning process of strategy, design, and engineering can add value to your business, drop us a line at hello@tendigi.com. You may also contact me directly at nick@tendigi.com.

--

--