Android Architecture Layers:
1. Applications
Alarm / Browser / Calculator / Calendar / Camera / Clock / Contacts / Email / Home / Media Player / Photo Album / SMS / MMS / Voice Dial
The native applications provided with the particular Android implementation + the third party applications.
2. Android Framework
It provides a lot of classes and interfaces for android application development.
- Activity Manager – Controls all aspects of the application lifecycle and activity stack.
- Content Providers – Allows applications to publish and share data with other applications.
- Resource Manager – Provides access to non-code embedded resources such as strings, color settings and user interface layouts.
- Notifications Manager – Allows applications to display alerts and notifications to the user.
- View System – An extensible set of views used to create application user interfaces.
- Package Manager – The system by which applications are able to find out information about other applications currently installed on the device.
- Telephony Manager – Provides information to the application about the telephony services available on the device such as status and subscriber information.
- Location Manager – Provides access to the location services allowing an application to receive updates about location changes.
- Window Manager – Is responsible for managing the z-ordered list of windows, which windows are visible, and how they are laid out on screen. Among other things, it automatically performs window transitions and animations when opening or closing an app or rotating the screen.
3. Native Libraries
- libc – C runtime library;
- SQLite is responsible for database;
- SSL is responsible for Internet security;
- Surface Manager is responsible for composing windows on the screen;
- OpenGL/ES is responsible for 2D/3D drawing;
- WebKit is responsible for browser support;
- FreeType – is responsible for font support;
- Media Framework – is responsible for playing and recording audio and video formats.
4. Android Runtime
Core Libraries (Java) / ART / Dalvik VM
Until version 5.0, Android used Dalvik as a process virtual machine. Android 4.4 introduced Android Runtime (ART) as a new runtime environment, but it was an experimental feature and not enabled by default. It became the only runtime option in the next major version of Android, 5.0
Dalvik uses Just-In-time (JIT) compilation method to interpret the bytecode. JIT interprets the bytecode into machine language at it’s runtime (at the time when the apps are executed).
ART is written in C/C++ and uses Ahead-Of-Time (AOT) compilation to interpret bytecode. AOT compiles the code into machine language when the app is installed itself, means no compilation is done at the time of execution of app.
Advantages of ART:
- The apps launch speed is very fast because nothing is compiled at execution.
- Boot speed is faster because nothing is execued from dalvik partition as in case of odexed ROM in dalvik
- Increases battery backup by reducing CPU work due to absence of compilation work on apps execution.
Disadvantages of ART:
- It takes 10-20% more space upon installation than dalvik.
- Some apps are incompatible in ART.
5. HAL (Hardware Abstraction Layer)
Audio / Bluetooth / Camera / DRM / External Storage / Graphics / Input / Media / Sensors / TV
Only binary code is required.
6. Linux Kernel
Audio Drivers / Binder (IPC) Drivers / Bluetooth Driver / Camera Driver / Display Driver / Keypad Driver / Power Management / Shared Memory Driver / USB Driver / WiFi Driver
It is the heart of android architecture, that is responsible for device drivers, power management, memory management, device management and resource access.
Android File System
There are mainly 6 (plus /sdcard) partitions in Android devices. There might be some other partitions available, it differs from Model to Model. But 7 partitions can be found in any Android devices.
1. /boot
The boot partition. It includes the android kernel and the ramdisk. The device will not boot without this partition.
Wiping this partition from recovery should only be done if absolutely required and once done, the device must NOT be rebooted before installing a new one, which can be done by installing a ROM that includes a /boot partition.
2. /system
This partition contains the entire Android OS, other than the kernel and the ramdisk.
It includes the Android GUI and all the system applications that come pre-installed on the device.
Wiping this partition will remove Android from the device without rendering it unbootable, and user still be able to put the device into recovery or bootloader mode to install a new ROM.
3. /recovery
This partition is designed for backup. It can be considered as an alternative boot partition, that lets the device boot into a recovery console for performing advanced recovery and maintenance operations on it.
4. /data
This partition contains the user’s data like contacts, sms, settings and all android applications installed. If the user performs factory reset on device, this partition will be wiped out.
5. /cache
In this partition Android stores frequently accessed data and app components.
Wiping the cache doesn’t effect personal data but simply gets rid of the existing data there, which gets automatically rebuilt as user continues using the device.
6. /misc
This partition contains miscellaneous system settings in form of on/off switches. These settings may include CID (Carrier or Region ID), USB configuration and certain hardware settings etc. This is an important partition and if it is corrupt or missing, several of the device’s features will not function normally.
7. /sdcard
This is not a partition on the internal memory of the device but rather the SD card. This is a storage space for media, documents, ROMs etc.
On devices with both an internal and an external SD card the /sdcard partition always used referes to the internal SD card.
Wiping it is perfectly safe. Though several user-installed apps save their data and settings on the SD card and wiping this partition will make user lose all that data.
The Fundamental Components of Android:
1. Activity
An activity is a class that represents a single screen. It is like a Frame in AWT.
2. View
A view is the UI element such as button, label, text field etc. Anything that you see is a view.
3. Intent
Intent is used to invoke components. It is mainly used to:
- Start the service
- Launch an activity
- Display a web page
- Display a list of contacts
- Broadcast a message
- Dial a phone call etc.
Intent intent=new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.google.com")); startActivity(intent);
4. Service
Background process that can run for a long time. There are two types of services:
- local service is accessed from within the application
- remote service is accessed remotely from other applications running on the same device.
5. Content Provider
Used to share data between the applications.
6. Fragment
Like parts of activity. An activity can display one or more fragments on the screen at the same time.
7. AndroidManifest.xml
Contains informations about activities, content providers, permissions etc. It is like the web.xml file in Java EE.
8. Android Virtual Device (AVD)
Used to test the android app without the need for mobile or tablet etc. It can be created in different configurations to emulate different types of real devices.
Watchdog
A Watchdog timer is an electronic timer that is used to detect and recover from computer malfunctions.
It is a useful tool in helping a system recover from transient failures.
A Watchdog timer is used to trigger a system reset or other corrective actions, if the main program is unresponsive or hung.
Kicking the dog – The process of restarting the watchdog timer’s counter.
Watchdog is configured with a bark and a bite time.
If the watchdog is not “pet” at regular intervals, the system is assumed to have become non responsive and needs to be reset. A warning in the form of a bark timeout leads to a bark interrupt and a kernel panic. If the watchdog timer is still not reset, a bite timeout occurs, which is an interrupt in the secure mode, which leads to a reset of the SOC via the secure watchdog. The driver needs the petting time, and the bark timeout to be programmed into the watchdog, as well as the bark and bite irqs.
- Watchdog BITES – The process of expiry of a watch dog timer, which occurs when the watch dog timer is not feed/restarted before the time out period. Watchdog lets the user know that something is wrong.
- Watchdog BARKS – When the watchdog timer expires, it sends a signal to the micro controller or the PMU to restart the device as per design. A critical issues occurred, which (typically) ends with the system being reset.
Required parameters: - compatible : "qcom,msm-watchdog" - reg : offset and length of the register set for the watchdog block. - interrupts : should contain bark and bite irq numbers - qcom,pet-time : Non zero time interval at which watchdog should be pet in ms. - qcom,bark-time : Non zero timeout value for a watchdog bark in ms. - qcom,ipi-ping : send keep alive ping to other cpus if set to 1 else set to 0. Example: qcom,wdt@f9017000 { compatible = "qcom,msm-watchdog"; reg = <0xf9017000 0x1000>; interrupts = <0 3 0 0 4 0>; qcom,bark-time = <11000>; qcom,pet-time = <10000>; qcom,ipi-ping = <1>; };