Just An Application

August 19, 2009

A Standalone Android Runtime: Getting Started

So what do you need to run an Android application ? At a minimum it looks like you need the System Server which is implemented by the class

    com.android.server.SystemServer

which is in

    $(ANDROID_SRC)/frameworks/base/services/java/com/android/server/SystemServer.java

Usefully it has a main(String[]) method, which doesn’t look very complicated at all, so what happens if we call it ?

It falls over.

The first thing it does is invoke the

     dalvik.system.VMRuntime.setTargetHeapUtilization(float)

method. This is in turn calls the

    dalvik.system.VMRuntime.nativeSetTargetHeapUtilization(float)

which unsuprisingly turns out to be a native method, which we don’t have.

We don’t want any Dalvik dependencies, and we don’t want any native code, but for the moment we’ll just replace the native call with a print statement so we don’t forget we have to do something about it later.

The main(String[]) method then wants to load the android_servers native library. We don’t have one of those, so we’ll comment that out.

Finally it calls the init1(String[]) static method. This is a native method so we could comment it out as well, but then we wouldn’t have a whole lot of functionality.

The init1(String[]) method is defined in

    $(ANDROID_SRC)/frameworks/base/services/jni/com_android_server_SystemServer.cpp

and it turns out to be a call to the

    system_init()

function and nothing more.

The system_init() function is defined in

    $(ANDROID_SRC)/frameworks/base/cmds/system_server/library/system_init.cpp

This does some interesting things we don’t quite undestand yet, and then calls back into Java, invoking the

    com.android.server.SystemServer.init2()

static method.

The comment for the main(String[]) method does actually say that this is what happens but comments have been known to get out of sync with the code so it is worth checking, and we also need to see what else is being done, just in case it turns out that anything else important gets done natively at this point.

Possibly it does but at the moment its not clear what, so we will short-cut the long and roundabout method of calling the init2() method and call it directly from main. It might work.

The init2() method simply forks a thread implemented by the class

    com.android.server.ServerThread

and then the fun really starts


Copyright (c) 2009 By Simon Lewis. All Rights Reserved.

Advertisements

1 Comment »


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: