Android Layer Interaction: Application to Kernel

Like any other OS platform, Android also designed in layered approach. Theoretically explaining the software layer interaction is bit difficult. So let me share my understanding, with an simple Vibrator application example. In this, we will see the control flow from application to kernel.

Application User Interface:


Application Source Code:

 public class MyActivity extends Activity{
 Vibrator vs;
 Button bn1;
 public void onCreate(Bundle savedInstanceState){
  vs = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
  bn1 = (Button) findViewById(;
  bn1.setOnClickListener(new OnClickListener(){
    public void onClick(View arg0){

Layer Interaction or Control Flow:
To access the vibrator service, first we are getting the local manager object or handler (vs). In Application Layer, vibrator service is getting called inside onClick() of the Button1. After calling vs.vibrate(), the control goes into vibrator service (Framework Layer), thru the binder interface.

Vibrator Service source code is in the following path:

Control reach the below function:
public void vibrate(long milliseconds, IBinder token)

Inside vibrate():

  1. Check for Permission
  2. Check the value (!= 0) and object (currently no vibration activity going on)
  3. Create Vibration object
  4. Start the vibration – startVibrationLocked(vib)

Inside startVibrationLocked():

  1. If mTimeout != 0, then call the native/JNI function vibratorOn().
  2. else, call the code, which handle the rhythmic vibration pattern, (Let us not worry about rhythmic vibration), which intern call the vibratorOn().

Next, to execute the vibratorOn(), control goes into the Native Layer thru JNI.

Native layer code is in the below path:

Control reach the below function:
static void vibratorOn(JNIEnv *env, jobject clazz, jlong timeout_ms)

Inside vibratorOn():

  1. Call the vibrator_on(), which is a HAL (Hardware Abstraction Layer) function.

HAL code is in the below path:

Control reach the below function:
int vibrator_on()

Inside vibrator_on():

  1. Call sendit().
  2. In sendit, we will open the vibrator device file and write the time-out value into it, which intern pass the value to vibrator device driver (Kernel Layer).
  3. The driver can activate the vibrator thru some hardware interface like I2C, GPIO (Hardware Layer).

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: