Android architecture

What is the android architecture?

Android architecture is the arrangement of software code that runs on the hardware. Software is arranged in layers so that if there is a change in one layer the other layers are not impacted. It is a common practice to layer the software in a bigger organisation as it is easy to maintain and analysing code becomes easy. Android is a open source software code that was started in 

The Android operating system is a layer of software components which is divided into five sections and four important layers as shown below in the architecture diagram.

Application layer

Java api framework

Native libraries                  Android Runtime

Hardware Abstraction Layer (HAL)

Linux Kernel

Power Management

 

Linux kernel

At the bottom of the layers is Linux 3.6 or higher version that is mostly the low level software performing communication with chipsets and other bus peripherals. with approximately 200 units. This provides a level of abstraction between the device hardware and it contains all the essential hardware device drivers like camera, keypad, display etc. Also, the kernel implements all the things that Linux is really good at such as networking and a vast array of device drivers, which take the pain out of interfacing to peripheral hardware.

Libraries

On top of Linux kernel there is a group of libraries also called as middleware libraries like open-source SQLite database which is used for storage and sharing of application data, there are other libraries to play audio and video and as well as to record, SSL libraries responsible for Internet security etc. socket libraries to handle network stuff. These libraries talk to the upper layer or the lower level linux kernel via apis. Some of the libraries are shared libraries usually with (.so for dynamic, .a for static).

Libraries are usually located in the following path 

  • system/app/<name>/lib/<arch>
  • system/priv-app/<name>/lib/<arch>
  • system/lib
  • system/lib64
  • system/vendor/lib
  • system/vendor/lib64

Path of some of the libraries are shown below.

  • defcontainer_jni
  • cronet.so
  • google_speech_jni 
  • google_speech_micro_jni
  • vcdecoder_jni
  • EGL_swiftshader
  • GLESv1_CM_swiftshader
  • GLESv2_swiftshader
  • frsdk

Android Libraries

These are Java-based libraries that are specific to Android application development. These libraries help android developers to facilitate application development these libraries support various GUI api’s developers use these api and include the library in their program to design some graphical like button or swipe or non graphical running in the background to perform some activity. These libraries have improvements over time so they have different API numbers for every android version. For example, the android version of kitkat uses API level 19 which means all user needs to develop application using API level 19 if they are working on a kitkat version of android and the API number will change with change in android version due to the improves in libraries, with adding features or bug fixes. The latest version is android 10 with API level 29

Although there are hundreds of libraries a few of them are below.

  • android.app − provides a gui version of the application and is the main component of any application in android.
  • android.content – provides communication between different applications and its libraries by publishing messages or events.
  • android.database − used to store data used by the application the data can be user data or can be application specific data. Most of the database is a SQL database.
  • android.opengl − provides a Java based api to rendering 2D and 3D vector graphics. These api will interact with graphical processing units.
  • android.os − provide inter process communication needed between application, task, thread and so on. Useful components in operating system ipc mechanisms like pipe, queue, semaphore, stack, file, memory sharing for synchronous operation of the application.
  • android.text − provides apis to render the text on display.
  • android.view − provides display functionality for your application.
  • android.widget − provides various components needed to design an application like button, window, progressbar, listview, gridview, framelayout and many more .
  • android.webkit − provides a set of classes intended to allow web-browsing capabilities to be built into applications.

Additionally there are C/C++ libraries apart from android java libraries in this layer itself.

Android Runtime

This is a component of Android that provides a virtual machine called Dalvik or DVM . This machine is used by android runtime to compile and run various applications. The Dalvik virtual machine is used to convert application bytecode into native instruction or ISA specific instruction that will run on the target cpu. It performs various activities during run time like 

  • Ahead of time compilation which improves app performance. 
  • Improved garbage collection useful to clean unused memory.
  • Application debugging like stacktrace.
  • Improved diagnostic details and crash reports.  

Application Framework

The Application Framework layer exposes various api via Java classes. Developers can build their application using these framework api

The Android framework includes the following −

  • Activity Manager − Is responsible to manage the lifecycle of the application and also to track back in case of crash.
  • Content Providers − Allows your application to share data or to get data from other applications.
  • Resource Manager − Provides use of non code resources such as strings, layout files and graphics.
  • Notifications Manager − Allow all applications to notify users or alerts something else.
  • View System − As discussed earlier view libraries provide a set of views to the user like gridview, listview and many others.

Applications

Applications reside on the top layer and are the main source for user interaction; all applications are installed in this layer. All applications are java based and some of the applications are pre developed and installed by android during compilation. Developers can too install their own application and use all of the above layer and libraries as per their requirements.