Android is one of the most successful product of Google after search engine. Google’s decision to buy Android.inc back in 2005 turned out to be a huge success for them. For the first time, Android came in HTC Dream in 2008, since then the proud Android owners have been eagerly waiting for Pastries’ names or more precisely Google Android updates like Cupcake, Donut, Eclair, Froyo, Gingerbread and now Icecream Sandwich. I covered last article on Android Rooting and Flashing and this time I want to give you an insight on this amazing product from an application developer’s eye.
There are broadly two sections of development, one is Android OS development and other is Android application development. I will try to cover this article with intent to anatomize Android from a developer’s context and later on giving a head-on for development with help of tools and platform. Android app market is huge with approximately more than 20 million applications, as a result there are infinite opportunities in area of application development.
Let us revisit the Android architecture. Radically starting from the root let us get inside the neogenic design of it.
As shown in Figure 1(Figure 1: Android Bus), the Android bus has wheels which represent Linux based kernel which is responsible for moving the Open source head of Android.
Android has a Linux heart. Its kernel is based on the Linux kernel release 2.6.X(X varying with new releases), based on the Android version releases. But it is not full fledged Linux, as Android was envisioned for high performance, optimized for minimum possible system resources consumption. Certain components have been removed from base Linux kernel and at the same time few new patches have been added also. The primary reason for this is that the Linux kernel, that Android has adopted, was for desktop version as compared to Android’s mobile platform(and Tabs). So, patches on basic Linux kernel drivers have been affixed. Some of the enhancements were necessary, like adding Power Management component. Since, the basic Linux kernel was designed for Desktops which are maximum times connected to direct power, so separate Power Management code was written to optimize power consumption; like wake locks are used to keep extracting power for activity. All these components sum-up for better Power Management.
Some of the additional components of Android kernel are:
Logger & Kernel Debugging:
Logging and debugging activity for better debug process and tracing.
Low Memory Killer:
To save active system memory, special code components have been written. For instance if an application which is not in use is consuming power, then kernel program for Power management will kill that program freeing Power and CPU resources.
Binder IPC program:
Since many applications can share system resources and usually interact with each other for process communication, binder IPC program facilitates IPC calls for this purpose. There are other components like Alarm etc but I won’t be discussing them here in this article.
People who are interested in Android OS development can find the code online as it is an Open Source.
Moving up on to the next layer in architecture, which is named native libraries. These are set of libraries specially written to hold various vital components and inbuilt functionalities of Android. For instance SQLite is very light and efficient Relational Database. It is very simple DB designed to hold data storage. WebKit is responsible for application framework for Browser support in Android. WebKit is itself an OpenSource product. This is a very interesting fact about Android that various components which make up Android are themselves OpenSource. WebKit is composite package for any browser’s framework as shown Miren, Dolphin and Opera in Figure 2(Figure 2:Native Libraries) and also, is responsible for many contemporary browsers’ structure. Mediaframework library is for rendering audio/video managing media support for Android through PacketVideo openCORE platform for popular audio/video codecs. Plus there is a hardware acceleration support coded too. And also there is a Surface manager responsible for carrying out “surface rendering” of all activities and bringing them into a single frame. Similar to this, there is Audio flinger which is responsible to give single frame to all audio inputs(Like Bluetooth, media and system sounds). libc library is actually Bionic libc in Android. It is custom, rewritten version, especially prepared for embedded purposes. It is smaller in size and faster in implementation, and licensed to BSD. libc is one package for all important libraries bundled up together. Bionic libc has special inside support for native functionalities of Android. Then there are core hardware libraries essential for implementation of Android hardware.
3. Dalvic Virtual Machine:
Android processes are themselves executed as separate Virtual Machines. That means each application is executed as a separate process, which again means that a separate stack of execution is made in which a seprate libc component, and system resources are allocated. The reason for making each application an independent entity is that, Android has been designed to rely on minimum possible system resources and it is easier to manage them as VMs. It executes Dalvik Executables .dex files, which are zipped in .apk files. It has byte code converter especially designed to support different platforms depending on the manufacturers.
4. Core Libraries:
These are core group of libraries of Java made for application development platform.
5. Application Framework:
This layer is active behind your working Mobile’s screen, behind the screen or scene because applications do not access them directly. Hardware services like Telephony Manager also constitutes this. Hardware services provide access to lower level hardware APIs like Bluetooth, telephony, radio etc. Activity manager deals with application lifecycle. There are various other managing components too.
Since Android is Linux based, so when you switch on your phone, the bootloader loads the kernel which in turn starts init process, responsible for starting first Dalvic cache process called zygote, various daemons like usbd(USB), adbd(Android Debug Bridge), debuggerd and rild(Radio Interface Layer Daemon). Zygote is responsible for starting-up, initializing Dalvic Virtual Machine, listening requests for applications for new VM processes. Also it initializes the Run time managers like Surface flinger and Audio Flinger which are responsible for managing single visual frame for various visual inputs like Wallpaper, widgets and toolbars etc. and similarly for redirecting audio stream. Runtime services start Service manager, which is also responsible for surface flinger as well as audio flinger. All the Android services like Telephony manager, Bluetooth manager, Activity manager, Window Manager, Package manager and Power manager are registered under Service manger. So now when an application is started a separate stack is started for it having separate VM machine and resources as shown in Figure 4(Figure 4:Application Stack).
Switching on an Android…Behind the Scene!
Inside an Application:
There are four major components of applications:
Activity, Service, Content provider and Receivers
An activity can be explained as one view of an application like login page of an application which can be called as Activity.
Following is a piece of demo for invoking activity in Java class:
Java methods like OnCreate(), OnStart(), OnResume(), OnPause(), OnStop() and OnDestroy() are involved in an Activity’s initialization.
In Figure 5(Figure 5: Switching between apps) shows you a scenario from switching from a music player and coming back; it can be applicable for removing and plugging in earphones also which enables and disables the music playing.
Service is something which runs in background. Services contain all the services which are running in background to support what is projected in foreground. For e.g. running music in background is a service.
Service class must be extended for a new service.
Content provider is shared set of data that can be utilized by an application. This shared data can live in SQLite, data store or XML.
Receiver is responsible for listening to alerts and broadcasts. Alert can be something like Less Battery or USB connected and broadcast message is like receiving a new message.
There is a wide variety of tools and services available for application developers.
If you want to go into application development for Android then you need to be educated about the following points and tools.
First of all we need to install SDK or Software Development Kit, Android Development Tools and then set up a platform for this. So let me give you an overview the process of development.
First you need to install SDK depending on the platform version you want to work on. Then you need to download eclipse plugin or any other available IDEs for Android development. Then one has to set up a virtual device (AVD) which is connected through ADB (Android Development Bridge) to an emulator to run the application. After developing a project, you can test it on emulator by running your application. Then comes the debugging part; DDMS (Dalvik Debug Monitor Server) which not only can be used to debug the program but also for checking various action points and allocation of system resources like memory.
There is one more development kit called IntelliJ IDEA from Netbeans.of Java.
There is a list of Emulators beside the basic SDK emulator, which can be used for the purpose of testing:
• Marvin ZX Spectrum
• Frodo C64
• Snes9x EX
• PC Engine
• FPSE ps1 emulator
• N64oid – N64.
Please note that many of them are used by game developers and highly enthusiastic gamers to test games. SDK tools itself contains a wide variety of tools which are responsible for different purposes altogether.
Some of them are:
Dmtracedump, Draw 9-patch(Graphical tool), Hierarchy Viewer (Debug and optimize an UI), mksdcard, monkeyrunner(API for writing programs), sqlite3(Access the SQLite data).