Android is an open-source operating system built on a modified version of the Linux kernel. It utilizes a modified Linux kernel that incorporates additional drivers and features to support the Android operating environment. Key components of Android include a custom virtual machine called Dalvik that executes applications, core libraries for Java programming, and a set of middleware, frameworks and APIs that allow applications to access device features like sensors and networking.
2. Android
Android can best be described as a complete solution
stack, incorporating the OS, middle wear components, and
applications. In Android, the modified Linux 2.6 kernel acts as the
hardware abstraction layer (HAL).
To summarize, the Android operating environment can be labeled as:
An open platform for mobile development
A hardware reference design for mobile devices
A system powered by a modified Linux 2.6 kernel
A run time environment
An application and user interface (UI) framework
Android utilize a modified Linux 2.6 kernel that is incorporated into the
Android operating environment.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
4. Linux Kernel
Android is built on the Linux kernel, but Android is not Linux
No native windowing system
No glibc support
Does not include the full set of standard Linux utilities
Patch of “kernel enhancements” to support Android
Great memory and process management
Permissions-based security model
Proven driver model
Support for shared libraries
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
5. Kernel Enhancements
Used as the foundation of the Android system
Numerous additions from the stock Ashmem
Linux, including new IPC (Inter-Process Binder
Communication) mechanisms, alternative power Alarm
management mechanism, new drivers and various Power Management
additions across the kernel Low Memory Killer
These changes are beginning to go into the staging/ Kernel Debugger
area of the kernel, as of 3.3, after being a complete Logger
fork for a long time
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
6. Changes
introduced in the
Android Kernel
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
7. Android Linux Kernel Modifications
Android is built on the Linux kernel, but Android is not Linux Kernel Enhancements
No native windowing system
No glibc support Alarm
Does not include the full set of standard Linux utilities Ashmem
Standard Linux 2.6.24 Kernel Binder
Patch of “kernel enhancements” to support Android Power Management
Great memory and process management Low Memory Killer
Permissions-based security model Kernel Debugger
Proven driver model Logger
Support for shared libraries
It‟s a open source!
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
11. Android Libraries
Gather a lot of Android-specifc libraries to interact at a low-level with the
system, but third-parties libraries as well
Bionic is the C library, SurfaceManager is used for drawing surfaces on the
screen, etc.
But also WebKit, SQLite, OpenSSL coming from the free software world
Android Runtime
Handles the execution of Android applications
Almost entirely written from scratch by Google
Contains Dalvik, the virtual machine that executes every application that you
run on Android, and the core library for the Java runtime, coming from Apache
Harmony project
Also contains system daemons, init executable, basic binaries, etc.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
12. • Bionic Libc :- Custom libc implementation, optimized for embedded use.
• Function Libraries
• Native Servers
• Hardware Abstraction Libraries
WebKit
Based on open source WebKit browser: http://webkit.org
Renders pages in full (desktop) view
Full CSS, Javascript, DOM, AJAX support
Support for single-column and adaptive view rendering
Media Framework
Based on PacketVideo OpenCORE platform
Supports standard video, audio, still-frame formats
Support for hardware / software codec plug-ins
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
13. Android Source code organization
Bionic/ Android's standard C library is stored
contains code samples regarding the boot of an Android device. In this
folder, protocol used by all Android bootloaders and a recovery image
Bootable/ holds the core components of the build system.
Build/ Holds the core components of the build system
CTS/ The Compatibility Test Suite
Dalvik/ Contains the source code of the Dalvik virtual machine.
Development/ Holds the development tools, debug applications, API samples, etc
device/ Contains the device-specifc components
One of the largest folders in the source code, it contains all the external
External/ projects used in the Android code
Frameworks/ Holds the source code of the various parts of the framework
Hardware/ contains all the hardware abstraction layers
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
16. Android HAL
Hardware Abstraction Layer which provides a layer to protect proprietary software
from licensing point of view.
Android applications communicate with the underlying hardware through Java API‟s
not by system calls.
The Hardware Abstraction Layer or HAL is the glue between any device (part of the
kernel) and the corresponding JNI interface.
HAL source code reside under the hardware folder
/** Base path of the hal modules */
#define HAL_LIBRARY_PATH1 "/system/lib/hw“
#define HAL_LIBRARY_PATH2 "/vendor/lib/hw"
User space C/C++ library layer
Defines the interface that Android requires hardware “drivers” to implement
Separates the Android platform logic from the hardware interface
Libraries are loaded dynamically at runtime as needed
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
17. Audio Flinger
Manages all audio output devices
Processes multiple audio streams into PCM audio out paths
Handles audio routing to various outputs
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
18. Android HAL
Above figure provide a clear view on connections between the Kernel, HAL
( libhxxx.so ) , C++ headers, JNI binding and finally the JAVA API. Consider the
complete audio subsystem in Android and in particular the OMAP 35xx applications
processor.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
20. Android's Camera Sub System
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
21. Android's Camera Sub System
Android's camera
application connect with
android HAL through
camera binding interface.
HAL in turns connect
physical camera sensor and
provides control & data
interface between
application and camera
sensor.
The diagram illustrates the
structure of the camera
subsystem. In the diagram
proprietary camera libraries
are nothing but camera
HAL
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
22. Android Camera HAL brief
To implement a camera HAL ( also consider as driver between android
camera subsystem and V4L2 kernel driver) ; one need to create a shared
library (named as libcamera.so) that implements the interface defined at
“android/frameworks/base/include/camera/CameraHardwareInterface.h”.
Location of the shared library should be at
“android/hardware/<vendor>/<boardname>/camera”
Create source files and implement interface defined at
'CameraHardwareInterface.h'.
android/hardware/ti/omap3/camera/CameraHardware.cpp
android/hardware/ti/omap3/camera/CameraHardware.h
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
23. Interface‟s defined under camera HAL
/* constructor */ CameraHardware::CameraHardware(){}
/* destructor */ CameraHardware::~CameraHardware(){}
sp<IMemoryHeap> CameraHardware::getPreviewHeap() const{}
void CameraHardware::setCallbacks(notify_callback notify_cb, data_callback
data_cb, data_callback_timestamp data_cb_timestamp, void* user){/* store callback to local
pointers, need to callback at the time of preview/image capture */}
void CameraHardware::enableMsgType(int32_t msgType) {/* set local message flag.
Application will give this notification to perform certain action while previewing. ex.start
video, image caputure etc. */}
void CameraHardware::disableMsgType(int32_t msgType){}
bool CameraHardware::msgTypeEnabled(int32_t msgType){}
Create and configure
void CameraHardware::stopPreview() { /* stop preview */ } android.mk file
status_t CameraHardware::startRecording() { /* configure device & start record thread */ Compile android system
/* record thread - check message type - if message type contains - Go to module directory $cd /projects/my-
CAMERA_MSG_VIDEO_FRAME then call 'mDataCbTimestamp' with video frame android/hardware/ti/omap3/camera
captured */ } $source
void CameraHardware::stopRecording() { /* stop recording */ } <ANDROID_ROOT>/build/envsetup.sh
status_t CameraHardware::takePicture() $mm TARGET_PRODUCT=
{ /* - configure camera device - take a current frame - check message type - call callback */ <TARGET PRODUCT NAME>
} e.g.$ mm
status_t CameraHardware::setParameters(const CameraParameters& params) { /* - TARGET_PRODUCT=beagleboard
configure device as per parameters */ } copy libcamera.so to
out/target/product/<boardname>/system/l
CameraParameters CameraHardware::getParameters() const ib
{ /* - return current value of parameter set */ }
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
29. Android Power Management
Linux Power Management
Android Power Management Design
Wake Locks
System Sleep (Suspend)
Battery Service
• Home Entertainment .
• Security devices
Designed for mobile devices • Multimedia Devices,
Goal is to prolong battery life
Build on top of Linux Power Management
• Handheld Devices
Not directly suitable for a mobile device
• Tablets
Designed for devices which have a 'default-off' behavior
The phone is not supposed to be on when we do not want to use it.
Powered on only when requested to be run, off by default.
• Multimedia Streaming
Unlike PC, which has a default on behavior. • Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
30. Linux Power Management
Power mode interface is on sysfs
/sys/power/state
sysfs is a virtual file system provided by Linux. •sysfs exports
Home Entertainment .
• Security devices
information about devices and drivers from the kernel device model to
• Multimedia Devices,
user space, and is also used for configuration
• Handheld Devices
Changing state done by • Tablets
# echo mem > /sys/power/state
# echo disk > /sys/power/state
# echo standby > /sys/power/state • Multimedia Streaming
• Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
31. Linux Power Management
• Home Entertainment .
• Security devices
• Multimedia Devices,
• Handheld Devices
• Tablets
• Multimedia Streaming
• Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
32. Android Power Management
Built as a wrapper to Linux Power Management
In the Kernel
Added 'on' state in the power state
Added Early Suspend framework
Added Partial Wake Lock mechanism
• Home Entertainment .
• Security devices
Apps and services must request CPU resource with • Multimedia Devices, the
„wake locks‟ through
Android application framework and native Linux libraries in order to keep power
on, otherwise Android will shut down the CPU.
• Handheld Devices
Android PM uses wake locks and time out mechanism to switch state of system
• Tablets
power, so that system power consumption decreases
• Multimedia Streaming
Android demands that applications and services request CPU resources via
• and native Linux
wake locks through the Android application frameworkConnected Navigation
• shutdown the
libraries. If there are no active wake locks, Android willIn-car Wi-Fi processor.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
33. Wake Locks
By default, Android tries to put the system into a sleep or better a suspend mode as
soon as possible
Applications running in the Dalvik VM can prevent the system from entering a sleep
or suspend state, i.e. applications can assure that the screen stays on or the CPU stays
awake to react quickly to interrupts
The means Android provides for this task is wake locks
If there are no active wake locks, CPU will be turned off Home Entertainment .
•
If there are partial wake locks, screen and keyboard will• be turneddevices
Security off
• Multimedia Devices,
Types of Wake Locks
PARTIAL_WAKE_LOCK
Ensures that the CPU is running • Handheld Devices
The screen might not be on • Tablets
SCREEN_DIM_WAKE_LOCK
Wake lock that ensures that the screen is on, but the keyboard backlight will be allowed to go
off, and the screen backlight will be allowed to go dim
SCREEN_BRIGHT_WAKE_LOCK
Wake lock that ensures that the screen is on at full brightness; the keyboard backlight will be
allowed to go off
FULL_WAKE_LOCK
Full device ON, including backlight and screen
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
34. Android PM Design
Android implements an application framework on top of the kernel called Android
Power Management Applications Framework
The Android PM Framework is like a driver. It is written in Java which connects
to Android power driver through JNI
Currently Android only supports screen, keyboard, buttons backlight, and the
brightness of screen
Through the framework, user
space applications can use
„PowerManger‟ class to control
the power state of the device
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
35. Android PM Implementation
Android PM Framework provides a service for user space applications through the
class PowerManger to achieve power saving
The flow of exploring Wake locks are :
Acquire handle to the PowerManager service by calling Context.getSystemService()
Create a wake lock and specify the power management flags for screen, timeout, etc.
Acquire wake lock
• Home Entertainment .
Perform operation such as play MP3
• Security devices
Release wake lock • Multimedia Devices,
How are Wake Locks Managed • Handheld Devices
Wake Locks are mainly managed in Java layer • Tablets
When an android application takes a wake lock, a new instance of wake lock is
registered in the PowerManagerService
PowerManagerService is running in the java layer • Multimedia Streaming
Registered wake locks are put in a list • Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
36. Acquiring a Wake lock
The flow when a Wake Lock is acquired
Request sent to PowerManager to acquire a wake lock
PowerManagerService to take a wake lock
Add wake lock to the list
Set the power state • Home Entertainment .
• Security devices
For a FULL_WAKE_LOCK, PowerState would be set to ON • Multimedia Devices,
For taking Partial wake lock, if it is the first partial wake lock, a kernel
wake lock is taken. This will protect all the partial wake locks. For
• Handheld Devices
subsequent requests, kernel wake lock is not taken, but just added to the
• Tablets
list
• Multimedia Streaming
• Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
38. Battery Service
The BatteryService monitors the battery status, level, temperature etc.
A Battery Driver in the kernel interacts with the physical battery via ADC [to read
battery voltage] and I²C ( Inter-Integrated Circuit: a multi-master serial single-ended
computer bus used to attach low-speed peripherals to an electronic device)
Whenever BatteryService receives information from the BatteryDriver, it will act
accordingly • Home Entertainment .
E.g. if battery level is low, it will ask system to shutdown • Security devices
• Multimedia Devices,
Using power supply class in Linux Kernel
/sys/class/power_supply • Handheld Devices
Utilize uevent mechanism to update battery status • Tablets
uevent : An asynchronous communication channel for kernel
Battery Service will monitor the battery status based on received uevent from the
kernel • Multimedia Streaming
• Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
41. Sensors on Android
A sensor(also called detector) is a device that measures a physical quantity
and converts it into a signal which can be read by an observer or by an
instrument.
• Handheld Devices
• Tablets
• Multimedia Streaming
• Connected Navigation
• In-car Wi-Fi
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
43. Android sensor sub system overview
Application Framework
Sensor Applications uses the Sensor application
framework to get the sensor data. It communicates
with C++ layer through sensor Java native interface
(JNI)
Sensor Libraries
Sensor middle layer mainly consists of Sensor
Manager, Sensor service and Sensor hardware • Home Entertainment .
abstraction layer. • Security devices
Input Subsystem • Multimedia Devices,
This is a generic Linux framework for all input
devices like keyboard, mouse, touchscreen and
defines a standard set of events. It interfaces to user
space through /sys/class/input interface. • Handheld Devices
Evdev • Tablets
Evdev provides a generic way for input device
events to be accessible under /dev/input/eventX .
LIS331DLH Accelerometer Driver • Multimedia Streaming
This driver communicates with LIS331DLH • Connected Navigation
accelerometer chip via GPIO and I2C bus. GPIO
line is used for generating interrupts while I2C bus • In-car Wi-Fi
for accessing and configuring accelerometer
registers.
Fig: Android subsystem overview
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
52. Android Boot Sequence
Init it very first process, we can say it is root
process or grandmother of all processes. init
process has two responsibilities.
1. mount directories like /sys, /dev, /proc and
2. run init.rc script.
Android has specific format and rules
for init.rc files. In Android we call it as
“Android Init Language”
The Android Init Language consists of
four broad classes of statements,
which are
1. Actions,
2. Commands,
3. Services,
4. Options.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
53. Action : Actions are named sequences of commands. Actions have a trigger
which is used to determine when the action should occur.
Syntax
on <trigger>
<command>
<command>
<command>
Service : Services are programs which init launches and (optionally) restarts
when they exit. Syntax
service <name> <pathname> [ <argument> ]*
<option>
<option>
...
Options : Options are modifiers to services. They affect how and when init runs
the service.
Let‟s take a look of default init.rc file. Here I have listed only major events and
services.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
54. Zygote Process
Zygote is a VM process Action / Service Description
that starts at system boot on early-init Set init and its forked children's oom_adj.
time. Set the security context for the init process.
Zygote preloads and on init setup the global environment
initialize core library Create cgroup mount point for cpu
classes. Normally there accounting
core classes are read-only and many
and part of Android SDK or on fs mount mtd partitions
Core frameworks. In Java change permissions of system directories
on post-fs
VM each instance has it‟s
own copy of core library on post-fs-data change permission of /data folders and sub
folders
class files and heap objects.
on boot basic network init ,Memory Management
,etc
service start system manager to manage all native
servicemanager services like location, audio, shared
preference etc..
service zygote start zygote as app_process
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
56. Zygote loading process
1. Load ZygoteInit class,
Source Code :<Android Source>
/frameworks/base/core/java/com/android/internal/os/ZygoteInit.java
2. registerZygoteSocket() - Registers a server socket for zygote command
connections
3. preloadClasses() - “preloaded-classes” is simple text file contains list of
classes that need to be preloaded, you cna find “preloaded-classes” file at
<Android Source>/frameworks/base
4. preloadResources() - preloadReaources means native themes and
layouts, everything that include android.R file will be load using this
method.
At this time you can see bootanimation
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
57. Android System Service or Services
System Service or Services Core Services:
1. Starting Power Manager
After complete above steps, runtime request 2. Creating Activity Manager
Zygote to launch system servers. System 3. Starting Telephony Registry
Servers are written in native and java 4. Starting Package Manager
both, System servers we can consider as 5. Set Activity Manager Service as
process, The same system server is available as System Process
System Services in Android SDK. System 6. Starting Context Manager
server contain all system services. 7. Starting System Context Providers
8. Starting Battery Service
9. Starting Alarm Manager
Zygote fork new process to launch system 10. Starting Sensor Service
services. You can find source code in 11. Starting Window Manager
ZygoteInit class and “startSystemServer” 12. Starting Bluetooth Service
method. 13. Starting Mount Service
Boot Completed
Once System Services up and running in memory, Android has completed
booting process, At this time “ACTION_BOOT_COMPLETED” standard
broadcast action will fire.
E-mail: info@zeelogic.com; http://www.zeelogic.com Phone : 91-9535072845
58. Corporate And Custom Training
For IT Professionals and Graduates
http://www.zeelogic.com