|
Cyril Sermon (@admin) |
Understanding the Android Software Stack
The Android software stack is composed of the elements shown in Figure 1-1 and described in further detail below it. Put simply, a Linux kernel and a collection of C/C++ libraries are exposed through an application framework that provides services for, and management of, the run time and applications.
❑Linux Kernel Core services (including hardware drivers, process and memory management, security, network, and power management) are handled by a Linux 2.6 kernel. The kernel also provides an abstraction layer between the hardware and the remainder of the stack.
❑Libraries Running on top of the kernel, Android includes various C/C++ core libraries such as libc and SSL, as well as:
❑ A media library for playback of audio and video media ❑ A Surface manager to provide display management
❑ Graphics libraries that include SGL and OpenGL for 2D and 3D graphics ❑ SQLite for native database support
❑SSL and WebKit for integrated web browser and Internet security
❑Android Run Time What makes an Android phone an Android phone rather than a mobile Linux implementation is the Android run time. Including the core libraries and the Dalvik vir-tual machine, the Android run time is the engine that powers your applications and, along with the libraries, forms the basis for the application framework.
❑Core Libraries While Android development is done in Java, Dalvik is not a Java VM. The core Android libraries provide most of the functionality available in the core Java libraries as well as the Android-specific libraries.
❑Dalvik Virtual Machine Dalvik is a register-based virtual machine that’s been opti-mized to ensure that a device can run multiple instances efficiently. It relies on the Linux kernel for threading and low-level memory management.
❑Application Framework The application framework provides the classes used to create Android applications. It also provides a generic abstraction for hardware access and manages the user interface and application resources.
❑Application Layer All applications, both native and third party, are built on the application layer using the same API libraries. The application layer runs within the Android run time using the classes and services made available from the application framework.
One of the key elements of Android is the Dalvik virtual machine. Rather than use a traditional Java virtual machine (VM) such as Java ME (Java Mobile Edition), Android uses its own custom VM designed to ensure that multiple instances run efficiently on a single device.
The Dalvik VM uses the device’s underlying Linux kernel to handle low-level functionality including security, threading, and process and memory management. It’s also possible to write C/C++ applica-tions that run directly on the underlying Linux OS. While you can do this, in most cases there’s no rea-son you should need to.
This book focuses exclusively on writing applications that run within Dalvik. If your inclinations run toward exploring the Linux kernel and C/C++ underbelly of Android, modifying Dalvik, or otherwise tinkering with things under the hood, check out the Android Internals Google Group at
http://groups.google.com/group/android-internals
All Android hardware and system service access is managed using Dalvik as a middle tier. By using a VM to host application execution, developers have an abstraction layer that ensures they never have to worry about a particular hardware implementation.
The Dalvik VM executes Dalvik executable files, a format optimized to ensure minimal memory foot-print. The .dex executables are created by transforming Java language compiled classes using the tools supplied within the SDK. You’ll learn more about how to create Dalvik executables in the next chapter.
Android’s architecture encourages the concept of component reuse, allowing you to publish and share activities, services, and data with other applications with access managed by the security restrictions you put in place.
The same mechanism that lets you produce a replacement contact manager or phone dialer can let you expose your application components to let other developers create new UI front ends and functionality extensions, or otherwise build on them.
The following application services are the architectural cornerstones of all Android applications, pro-viding the framework you’ll be using for your own software:
❑Activity Manager Controls the life cycle of your activities, including management of the activ-ity stack described in Chapter 3.
❑Views Are used to construct the user interfaces for your activities as described in Chapter 4.
❑Notification Manager Provides a consistent and non-intrusive mechanism for signaling your users as described in Chapter 8.
❑Content Providers Lets your applications share data between applications as described in Chapter 6.
❑Resource Manager Supports non-code resources like strings and graphics to be externalized as shown in Chapter 3.