Saturday, April 20, 2013

Execution of Android programs

Android is a Linux based OS which forms an encapsulation shell around Linux kernel. All system calls and sub-routines from/to users (say an application component) are intercepted by Android Application Framework via core libraries assisted by Android run-time. Android runtime is composed of several core libraries and a virtual machine (VM). Every Java program is compiled into Java byte code which can be executed on a VM. Android is no exception.
Each Android program runs on separate instance of specialized Virtual Machines (VM) commonly known as Dalvik Virtual Machine (DVM) and Android programs are compiled into 'Dalvik Byte Codes'. DVMs are optimized for space and time complexities of code blocks. Virtual machines are just like your physical computer but equipped with virtual processor. So, its like a bunch of processors hooked up together to perform a task. Unlike traditional Java VMs (like Java ME), DVMs are designed to ensure that multiple instances run efficiently on a single device.

Dalvik Virtual Machine

The Dalvik VM uses the device’s underlying Linux kernel to handle low-level functionality, including security, threading, and process and memory management. It’s also possible to write C/C++ applications that run closer to the underlying Linux OS (this will be covered in advanced section of Android programing. Instead of using SDK, Android NDK is used where you need fast code execution time). In other words, Dalvik and the Android run time sit on top of a Linux kernel that handles low-level hardware interaction, including drivers and memory management, while a set of APIs provides access to all the underlying services, features, and hardware. Refer to the next section for better understanding.

Android Software Stack
Fig 1.3 Android Software Stack

This is gonna be your world! Any android application you see around you is a part of this stack. In simple terms, Android software stack is a bundle of underlying Linux kernel (for handling low level system calls intended to control actual hardware) and a collection of C/C++ core libraries. This section will introduce Android software stack in detail.

1. Linux kernel: Core services (hardware drivers, process and memory management, etc). This also provides a layer of abstraction to upper stack component. So, your application can run smoothly on any device as long as the system calls are successfully resolved by kernel layer.
2. Libraries: Running on top of the kernel, Android includes various C/C++ libraries. These libraries have content that can be shared among various application component running at the front/back end. Of course, appropriate permission is required to access shared library components. Various libraries are: 
a. A media library for playback of audio and video media
b. A surface manager to provide display management
c. Graphics libraries that include SGL and OpenGL for 2D and 3D graphics
d. SQLite for native database support
e. SSL and WebKit for integrated web browser and Internet security
3. Android Runtime: It is composed of two parts:
a. Core libraries - The core Android libraries provide most of the functionality available in the core Java libraries, as well as the Android specific libraries.
b. Dalvik VM - Dalvik is a register-based Virtual Machine that’s been optimized to ensure that a device can run multiple instances efficiently. It relies on the Linux kernel for threading and low-level memory management. 
4. Application Framework: The application framework provides the classes used to create Android applications. It also provides a generic abstraction for hardware access and manages the user interface and application resources.
5. Application Layer: Your Android application runs in this layer. It uses the class and hardware services provided by lower abstraction layers 


No comments:

Post a Comment