Wednesday, January 1, 2020

Android Software Stack

Android Software Stack

Android as implementation is a complete software stack.

It is a combination of several open-source technologies in order to achieve the complete Android platform as an open-source.

A broad picture of having all components is as follows.

Power Management:

Power management is the core issue of the development of smartphone devices because these devices are powered by small batteries. The size of the battery can’t be big because of device size and weight constraint. Each volt, amperes, and watts are extremely limited with these batteries. The operating system written for a smartphone device must be extremely optimized for power consumption. Power management is the core issue in the development of Android. The lowest layer of the Android software stack is Power management.

Linux Kernel:

Android’s kernel as an operating system is not written from scratch. Since Linux is an open-source operating system. It is secure, robust, and powerful. Linux kernel is used for common operating system task like memory management, binder services, multi-tasking, USB, Shared memory, etc.

Hardware Abstraction Layer(HAL):

This thin layer of software provides interfaces to access hardware. This layer provides a framework to access features like camera, audio, display, USB, Wi-Fi, and Bluetooth programmatically. This layer provides a platform for Android Runtime and C/C++ native libraries. HAL provides an abstraction level to hardware features.

Native C/C++ Libraries and ART:

This layer is comprised of two parts. The first part C/C++ Libraries is a collection of libraries. Many components of Android like HAL, Linux Kernel and ART(Android Runtime) are written and implemented in C/C++, so these libraries provide an interface between these components and the JAVA API framework layer.

Developers can work at this level and create their own native code using NDK (Native development kit). However, most of the time an app developed in NDK does not increase the speed of execution.

It can also increase complexity sometimes. This is the reason that not all of the Android apps are developed using NDK. Only a few of them use NDK like where we want to access sensors and hardware of devices in more detail.

There are several libraries like libc, libc++, SQLite (an integrated lightweight database management system with Android System to manage data locally), Open GL, OpenGL ES, Media framework, WebKit, FreeType, SSL, OpenMAX AL etc.

These all are open-source libraries or almost open source technologies.

ART is an Android runtime. It is a predecessor of ART is DVM, DalvikVirtual Machine.

This is something like JVM (Java Virtual Machine).Byte-code (an intermediary highly optimized code in terms of memory management, efficiency and speed of execution for Java) is executed on JVM.

For Android devices, we have few more issues like limited battery size and power management so we need an intermediary code optimized for these issues. We also have several class files in an Android project.


DEX is Dalvik Executable code is an optimized intermediary code for Android projects. Dalvik compiler converts multiple class files into a single .dex file. This .dex file is executed on DVM (Dalvik Virtual Machine). However, before the Android version <5.0 had Dalvik Virtual Machine as their official platform but after version 5.0 ART was introduced.
ART has the following components

  • JIT (Just-in-time Compiler) and AOT (Ahead of the time compiler)
  • Core libraries to support ART
  • Automatic and Optimized Garbage collection
  • Debugging support, dedicated sampling profiler and diagnostic support for exception and crash reporting
Although, Outputs are still Dalvik executable. ART is designed to provide a minimum memory footprint. Apps build with ART are much responsive, fast, and smooth but the consumption of RAM during the build process is very high. Each App runs its own process and creates its own instance to run on Virtual Machine. Build toolchains like Jack build .dex executable for ART.

If an app is created and run on ART it will run on Android <5.0 versions, but the reverse may not be true.

Java API Framework:

This is the actual interface to work on for Android App developers. This layer is the collection of several Managers for different components in Android, Android View System, and Content Providers. This API provides the programmers to access the features, services, and resources provided by the Android System.

System/User Apps:

This layer is concerned with users. Users can download, install, and use these apps.

Some apps like Chrome, Gmail, SMS, camera, home, google play, etc. are supplied with Operating system itself, So when users boots their device first time these apps are available in their device along with Android Operating System. Users can install Apps of their own interest. All the pre- installed and user-installed Apps have the same priority generally. However, some Apps may have higher priory as well like settings app.