Thursday, February 16, 2012

Why Headless Android?

I have been asked several times, “What is the point of headless Android?” It’s not hard to see why the question is asked. Android, in essence, is a specialized user interface for a phone or tablet platform that runs on the Linux kernel. The Android development team has done a fantastic job to create a platform that application developers can build great apps for phones and tablets. Because they focused on the platform under the applications, just as much as they focused on the applications themselves, the Android team also developed a world class platform framework.

For some, using headless Android comes down to commonality. If you have development efforts where you have two products (for example), one with a UI and one without, then keeping those platforms consistent from a development stand point just makes sense. Being able to write code that you can share between the two platforms is essential for maintenance.

While that use case is an interesting one, it is by no means (in my opinion) the biggest reason developers should care about headless Android. I’ll tell you why.

Five years ago, if you asked just about any embedded developer what they were going to use as the operating system for their embedded hardware (with or without a UI), most of them would say Linux. It was a smart choice. Having control of your destiny (so to speak) can be absolutely critical to the success of a project, especially if you aren’t one of the 800 pound gorillas. For smaller companies building embedded devices, Linux offered the freedom to succeed despite the common road blocks that often beset embedded projects. For example, if I have access to the kernel source, I can debug that lousy DMA controller bug that is preventing my audio from working. It was a wonderful world, if you liked that sort of thing.

Fast forward to today. While embedded Linux is still a fantastic choice for embedded devices, more and more companies are looking for ways to improve over the roll-your-own custom Linux environment that most embedded Linux developers work in. Sure, there are companies that build BSPs that have common utilities and libraries, but that can only get you so far.

Enter Android. For phone developers it is like what embedded Linux was to embedded developers ten years ago. A boon! Finally a widely popular development environment that included an Integrated Development Environment (IDE), a great set of debugging tools, a rich set of off-the-shelf libraries, and a killer user interface. PLUS, you can modify it to your hearts content. Power to the programmers!

As a non-phone developer and embedded Linux fanatic, I have to admit that for phones Android is great, but what about all the millions of devices that aren’t phones, and for that matter aren’t tablets, and may not even have a user interface? With a bit of work, those of us not doing phones can have our cake and eat it too...

There are three reasons I believe headless Android will catch on in popularity as more developers begin to use it.

1. Development Tools - Having an IDE and graphical debugger that “just work” with an easy way to deploy, test, debug, and package your software is a huge time saver.

2. The Platform - Leveraging the built in Android system services architecture can save a huge amount of time and effort. Built in IPC, memory management, service “keep-alive” code, and package management also saves a lot of time and effort. Every embedded devices needs most, if not all of these things, so leveraging a system that is already proven has huge advantages.

3. Knowledge - Since Android is a popular platform, there is a growing community of knowledgeable software engineers that understand the in’s and out’s of the system. Training someone on a roll-your-own solution can take months. Leveraging a known platform can dramatically increase productivity. Along with this the number of books and websites devoted to Android is growing all the time.

There are many other reasons for utilizing the platform offered by the Android system. Why reinvent the wheel? Especially when the wheels work so great and come with tires, axles, and a power train?

Cyborgstack

One of the interesting things I picked up from the Android Builders Summit was a project that Karim Yaghmour of Opersys started to make a completely open Android distribution. The point of the project is to open Android up to the many other markets that may want to use it.

I will be sharing the patches for the headless Android work that I've been doing with the Cyborstack project, so there will be a good repository that everyone can get to. Given that I work in an industry that isn't related to phones or tablets in any way, I'm excited to have a group of people looking at what I'm looking at.

Take a look at it and see what you think.

Cyborgstack

Wednesday, February 15, 2012

Karim's Post on Headless Android

Karim posted on Headless Android. You can see his post here:

http://www.opersys.com/blog/headless-android-1

Karim Yaghmour's Headless Android Presentation

The highlight of the Android Builders Summit (ABS) for me was Karim's session on Headless Android (that was probably pretty obvious.) He gave a great presentation on actually stripping out all the stuff that depends on the UI, like the WindowManager and SurfaceFlinger.

He showed a running system with his modifications with no UI and it was a beautiful thing. When I saw the code running, I got a tear in my eye and started asking if anyone had a tissue!

With Karim's permission, I'm posting a link to his presentation.

Headless Android Slides from ABS

The folks at the Linux Foundation that hosted ABS will have the presentations and videos up by Monday on their site. I'll post links when they show up.

If you want to download the git repository with the headless android changes that Karim did, then here are the commands:
$ repo init -u git://github.com/cyborgstack/android.git -b headless
$ repo sync
 
I wanted to thank Karim for his work on this front! 

Tuesday, January 24, 2012

New Patches Page

I am hacking my way through the process to develop a good set of patches to disable non-critical UI based (and telephony based) sub-systems. I created a Patches page where I posted my first patch.

http://headlessandroid.blogspot.com/p/gingerbread-android-patches.html

I've got a lot more to do, but I've got some other work for the next couple of weeks that will take a bit of  my time. Stripping out the dependance on the UI is the next piece of work to tackle. I'm hoping to get some tips at the conference in a couple of weeks that will make that job much easier.

Until then...

Friday, January 20, 2012

Debugging Android over a Network

While the ADB debugging option over a USB port is very convenient, sometimes being able to debug over a network connection can not be beat. This is one place where Android and ADB are amazingly easy, once you know the right commands.

You have to have console access to get this to work. First, from the Android console or adb shell, type in these commands:
setprop service.adb.tcp.port 5555
stop adbd
start adbd
Now use the netcfg command to find the IP address on your device. With that IP address, on your host computer you are debugging on, run the command:
adb connect <ip address of target board>
You should get a message that ADB is connected. You can now debug the device just like it was connected via the USB cable. Pretty slick!

Thursday, January 19, 2012

Quick Memory Footprint Savings

Following the TI link I mentioned in a previous post, my first pass at cutting out the "fat" for a Headless Android build resulted in a savings of 151 MB of resident memory. My process list went from (bolded processes removed):

system    2222  1     816    272   80343750 6fd0b6fc S /system/bin/servicemanager
root      2223  1     3872   588   ffffffff 6fd0bdac S /system/bin/vold
root      2224  1     3872   576   ffffffff 6fd0bdac S /system/bin/netd
root      2225  1     820    320   800e9ea4 6fd0b844 S /system/bin/dispd
root      2226  1     676    256   8037b6ac 6fd0c0cc S /system/bin/debuggerd
root      2227  1     83416  27164 800e9ea4 6fd0b844 S zygote
media     2228  1     26844  5836  ffffffff 6fd0b6fc S /system/bin/mediaserver
bluetooth 2229  1     1268   700   800e9ea4 6fd0c59c S /system/bin/dbus-daemon
root      2230  1     824    332   803fd98c 6fd0b45c S /system/bin/installd
keystore  2231  1     1752   424   8037b6ac 6fd0c0cc S /system/bin/keystore
radio     2232  1     5460   700   ffffffff 6fd0bdac S /system/bin/rild
system    2287  2227  189828 37796 ffffffff 6fd0b6fc S system_server
root      2297  2     0      0     8007cacc 00000000 S z1xx_workq
app_17    2443  2227  99264  19128 ffffffff 6fd0c51c S com.android.inputmethod.latin
radio     2449  2227  109920 20808 ffffffff 6fd0c51c S com.android.phone
system    2452  2227  129248 20960 ffffffff 6fd0c51c S com.android.systemui
app_16    2511  2227  97820  22068 ffffffff 6fd0c51c S com.android.launcher
app_1     2531  2227  103736 22144 ffffffff 6fd0c51c S android.process.acore
app_11    2555  2227  105400 17684 ffffffff 6fd0c51c S com.android.mms
app_12    2560  2227  93812  18940 ffffffff 6fd0c51c S android.process.media
app_20    2583  2227  94652  17988 ffffffff 6fd0c51c S com.android.email
app_21    2597  2227  93136  16192 ffffffff 6fd0c51c S com.android.deskclock
app_26    2611  2227  92336  16512 ffffffff 6fd0c51c S com.android.providers.calendar
app_30    2623  2227  92372  16300 ffffffff 6fd0c51c S com.android.bluetooth
app_19    2630  2227  93468  16576 ffffffff 6fd0c51c S com.cooliris.media
app_5     2643  2227  92172  15680 ffffffff 6fd0c51c S com.android.quicksearchbox
app_7     2650  2227  91804  14852 ffffffff 6fd0c51c S com.android.protips
app_10    2672  2227  92340  15000 ffffffff 6fd0c51c S com.android.music


To this:

system    2222  1     816    272   80343750 6fd0b6fc S /system/bin/servicemanager
root      2223  1     3872   588   ffffffff 6fd0bdac S /system/bin/vold
root      2224  1     3872   576   ffffffff 6fd0bdac S /system/bin/netd
root      2225  1     820    320   800e9ea4 6fd0b844 S /system/bin/dispd
root      2226  1     676    256   8037b6ac 6fd0c0cc S /system/bin/debuggerd
root      2227  1     83416  27160 800e9ea4 6fd0b844 S zygote
media     2228  1     24364  5320  ffffffff 6fd0b6fc S /system/bin/mediaserver
bluetooth 2229  1     1264   564   800e9ea4 6fd0c59c S /system/bin/dbus-daemon
root      2230  1     824    336   803fd98c 6fd0b45c S /system/bin/installd
keystore  2231  1     1752   424   8037b6ac 6fd0c0cc S /system/bin/keystore
radio     2232  1     4444   672   ffffffff 6fd0bdac S /system/bin/rild
system    2287  2227  183728 38644 ffffffff 6fd0b6fc S system_server
root      2297  2     0      0     8007cacc 00000000 S z1xx_workq
app_1     2355  2227  93116  17356 ffffffff 6fd0c51c S com.android.inputmethod.pinyin
system    2359  2227  146036 20748 ffffffff 6fd0c51c S com.android.systemui
app_16    2365  2227  96320  21116 ffffffff 6fd0c51c S com.android.launcher
app_12    2442  2227  94692  17864 ffffffff 6fd0c51c S android.process.media
app_5     2453  2227  92172  15676 ffffffff 6fd0c51c S com.android.quicksearchbox
app_7     2461  2227  91804  14848 ffffffff 6fd0c51c S com.android.protips

I know, I know, there are still a lot of processes to cut, like mediaserver, inputmethod.pinyin, launcher, media, quqicksearchbox, etc. However, the point I'm making is that with just minor modifications the system footprint can be reduced dramatically.

Nice.

One note to add, if you modify the files recommended in the TI link, which were:
build/target/product/core.mk
build/target/product/generic.mk
frameworks/base/services/java/com/android/server/SystemServer.java
You have to remember to make clean, then make again or the changes won't get picked up in the final build.