Sunday, 3 July 2016

Android Architecture - High level components

      I have worked on a project as part of my Masters thesis work that requires decent level of study on Android Operating System. As part this, I did a detailed study on Android OS internals. This post talks about the high level architecture of Android OS.

   Android is an open source operating system for mobile devices, originally developed by Android Inc., currently under development by Google Inc. along with Open Handset Alliance. Android is intended to be a complete software stack that includes every thing from the operating system through middleware layer and finally the applications. Android uses the Linux kernel at the lowest level though its not the standard Linux kernel.

Software layers of Android
Android architecture can be described as five layers
1. Androidized Linux kernel
2. Native Libraries
3. Android run time(ART)
4. Application framework
5. Applications

1. Androidized Linux kernel
   The lowest layer that performs all the basic system functionality like process management, memory management and device management is the Linux kernel. Android is based on Linux kernel but the Linux kernel used here is not the standard one. The Linux kernel in Android contain several hundred patches over the standard kernel, often to provide certain device-specific functionality, fixes, and enhancements to above layers. Thus some people call it as androidized Linux kernel. There is no glibc, instead it uses its own C library called Bionic libc. It does not support windowing system, bash shell and busy box. Significant enhancements in this context includes wavelock mechanism(a memory management mechanism that is more aggressive in preserving memory), low memory killer, binder IPC mechanism(an IPC mechanism that allows the processes to communicate with one another), ashmem(anonymous shared memory), logger. Most of these enhancements are extended through drivers. The security model of android will heavily depends on the security model followed at this kernel level.










Image: Android architecture - The purple colored layer is written in Java and green colored layer is written C and C++.

2. Native libraries and daemons
   The next layer above the kernel is the Android native libraries, daemons and services. This layer enables the device to handle different types of data. These libraries are written in C or C++ language and are specific for a particular hardware. It provides different abstractions to the layer above it. To provide uniform interface for all the devices, Android system expects the device vendors to implement certain hardware abstractions over the device drivers that collectively form the hardware abstraction layer. This layer includes many of the open source project libraries such as Bionic libc, OpenGL, webkit browser, SQLite Database mechanism, native servers like surface flinger, audio flinger and LLVM tools etc.

3. Run Time Environment
   It is the application run time environment where the compilation and execution of applications happens. It contains all compilation and optimization tools such as java compiler, dex tool, dex2opt tool and java libraries. I will present more detailed explanation about the android run time(ART) in my next blog.

4. Application Framework
   This acts as an API to the Android application developers so that applications can interact directly with the API. This framework will take care of the launching and shutting down the applications. The framework contains the managers and libraries that are high level abstractions above the native library. These programs manage the basic functions like resource management, voice call management etc. Important blocks of this framework includes content manager, activity manager, resource manager and location manager.

5. Applications
   The highest layer of the Android stack is Android applications. Android applications are available in APK(.apk) files. APK is a package of DEX files, XML files and some AIDL fies. Here, DEX is the byte code that ART will interpret and execute, XML files like Manifest.xml describe the starting point of the application and provides the permission details needed to interact with the other applications, and AIDL is the interface description language through which developer can define the programming interface so that both the client and service agree upon the communication between the two using IPC. The programming language used for android application development is the java language. These java source files are given to the java compiler to generate the .class files and these .class files will be merged and translated to DEX code by dex tool of run time. And finally these DEX files along with some application resources will be bundled to form an Android Application Package(APK) file.

No comments:

Post a Comment