Wednesday, June 29, 2011

Android Internals


Lars Vogel

Version 0.2
16.03.2011
Revision History
Revision 0.112.02.2011Lars Vogel
Created
Revision 0.216.03.2011Lars Vogel
updated and bugfixed
Android Internal
This articles looks at the internals of Androids and describes a little bit the architecture of Android.

1. Android Development

1.1. Android Operation System

Android is an operating system based on a modified Linux 2.6 with a Java programming interface. Also several drivers and libraries have been modified to allow Android to run efficient on mobile devices.
It provides tools, e.g. a compiler, debugger and a device emulator as well as its own Java Virtual machine (Dalvik Virtual Machine - DVM).Android is created by the Open Handset Alliance which is lead by Google.
Android uses a special virtual machine, e.g. the Dalvik Virtual Machine. Dalvik uses special bytecode. Therefore you cannot run standard Java bytecode on Android. Android provides a tool "dx" which allows to convert Java Class files into "dex" (Dalvik Executable) files. Android applications are packed into an .apk (Android Package) file by the program "aapt" (Android Asset Packaging Tool). To simplify development Google provides the Android Development Tools (ADT) for Eclipse . The ADT performs automatically the conversion from class to dex files and creates the apk during deployment.
For an introduction into Android development please see the Android Development Tutorial . The rest of this article tries to look inside the Android runtime system.

2. Internals

During startup of the Android system the Linux kernel first calls the process "init". init reads the files "/init.rc" and "init.device.rc". "init.device.rc" is device specific, on the virtual device this file is called "init.goldfish.rc".
init.rc starts the process "Zygote" via the program "/system/bin/app_process". Zygote loads the core Java classes and performs initial processing of them. These classes can be reused by Android application and therefore this step makes them faster to start. Once the initial work of Zygote is done, the process listens to a socket and waits for requests.
A special driver called "Binder" allow an efficient interprocess communications (IPC)) in which allow references to objects are passed between processes. The real objects are stored in Shared Memory. This way the communication between the processes is optimized as less data must be transferred.
Android does not provide a swap space like other Linux systems therefore the amound of available memory is limited to the memory on the device.
Androids uses a special C library "Bionic" instead of the standard Glibc. This library is not compatible with Glibs but requires less memory. Bionic contains a special thread implementation which optimizes the memory consumption of each thread and reduces the start time of new threads.
As of Android 2.3 the Android system uses Ext4, the standard file system for Linux. Before that it used the YAFFS file system. Some vendors replaces the standard file system by their own one.
As all application have their own Linux user application data can per default only be accesses from the application. To share data you cansave files which are accessible by other applications . Alternatively application can define their own content provider . Applications which are signed with the same certificate can also define in the "AndroidManifest.mf" a "android:sharedUserId". Application with a shared user id are running in the same process and with the same user id and can access files from similar applications.
The .apk file of installed applications can be found in the folder "data/app". Using the file manager or the adb pull / push command you can download the application or install it on a device. Payed applications or application from the market which have the option "Copy Protection" selected can be found in the folder "data/app-private" which the user cannot access per default.
To further protect an application from illegal copies you can use the library "Licence Verification Library" which checks for a paid application if it has been purchased from the Android Market.
The maximum size of Android application is currently typically 16 or 24 Megabyte. How large the application can be is defined at compile time of the Android system.

3. Thank you

No comments:

Post a Comment