Android Architecture as shown in below image can be subdivided into five layers: The kernel and low level tools, native libraries, the Android Runtime, the framework layer and on top of all the applications.
Green items are written in C/C++, blue items are written in Java and run in the Dalvik VM
Following are the different layers in the Android stack:
- Linux Kernel Layer
- Native Layer
- Application Framework Layer
- Applications layer
At the bottom of the Android stack is the Linux Kernel. It never really interacts with the users and developers, but is at the heart of the whole system. Its importance stems from the fact that it provides the following functions in the Android system:
- Hardware abstraction
- Memory management programs
- Security settings
- Power management software
- Other hardware drivers (Drivers are programs that control hardware devices.)
- Support for shared libraries
- Network stack
With the evolution of Android, the Linux kernels it runs on have evolved too. Here is a table highlighting the different kernel versions.
The kernel in use is a Linux 2.6 series kernel, modified for special needs in power management, memory management and the runtime environment. Right above the kernel run some Linux typical daemons like bluez for Bluetooth support and wpa supplicant for WiFi encryption.
Native Libraries Layer
As Android is supposed to run on devices with little main memory and low powered CPUs, the libraries for CPU and GPU intensive tasks are compiled to device optimized native code. Basic libraries like the libc or libm were developed especially for low memory consumption and because of licensing issues on Android. In this layer the surface manager handles screen access for the window manager from the framework layer. Opposing to other frameworks, the media framework resides in this layer, as it includes audio and video codecs that have to be heavily optimized.
Open Source Libraries:
- Surface Manager: composing windows on the screen
- SGL: 2D Graphics
- Open GL|ES: 3D Library
- Media Framework: Supports playbacks and recording of various audio, video and picture formats.
- Free Type: Font Rendering
- WebKit: Browser Engine
- libc (System C libraries)
- Open SSL
What is Dalvik VM?
Dalvik is open-source software. Dan Bornstein, who named it after the fishing village of Dalvík in Eyjafjörður, Iceland, where some of his ancestors lived, originally wrote Dalvic VM. It is the software responsible for running apps on Android devices.
- It is a Register based Virtual Machine.
- It is optimized for low memory requirements.
- It has been designed to allow multiple VM instances to run at once.
- Relies on the underlying OS for process isolation, memory management and threading support.
- Operates on DEX files.
Located on the same level as the libraries layer, the Android runtime layer includes a set of core Java libraries as well. Android application programmers build their apps using the Java programming language. It also includes the Dalvik Virtual Machine.
Application Framework Layer
Important blocks of Application Framework:
- Activity Manager: Manages the activity life cycle of applications
- Content Providers: Manage the data sharing between applications
- Telephony Manager: Manages all voice calls. We use telephony manager if we want to access voice calls in our application.
- Location Manager: Location management, using GPS or cell tower
- Resource Manager: Manage the various types of resources we use in our Application
Frameworks in the Application Framework layer are written in Java and provide abstractions of the underlying native libraries and Dalvik capabilities to applications. Android applications run in their own sandboxed Dalvik VM and can consist of multiple components: Activities, services, broadcast receivers and content providers. Components can interact with other components of the same or a different application via intents.
The Android Runtime consists of the Dalvik virtual machine and the Java core libraries. The Dalvik virtual machine is an interpreter for byte code that has been transformed from Java byte code to Dalvik byte code. Dalvik itself is compiled to native code whereas the the core libraries are written in Java, thus interpreted by Dalvik.
The applications are at the topmost layer of the Android stack. An average user of the Android device would mostly interact with this layer (for basic functions, such as making phone calls, accessing the Web browser etc.). The layers further down are accessed mostly by developers, programmers and the likes.
Several standard applications come installed with every device, such as:
- SMS client app
- Web browser
- Contact manager