Intoduction to Android OS 15 Oct 2011
TouchTour 2011 1
Introduction to Android
PRASANNAN.NANDROID CONSULTANT
Twitter : @tryprasannan
What is Android ?
� “Android is a complete set of software for mobile
devices, including an operating system, a middle-ware
and key mobile applications” (Google)
� It was initially developed by Android Inc.
(a firm later purchased by Google)
Oct 2011 2Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 2
Android - Overview
� First SDK : Nov 2007 & First Device : Oct 2008
� Technologically, Android includes middleware and
key/core applications, and uses a modified version of
the Linux kernel
� Allows developers to write managed code in Java
� Android Java = Java SE – AWT + Android API
Oct 2011 3Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Android Versions
Oct 2011 4Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 3
Version Name Kernel Release
1.1 - - 9 February 2009
1.5 Cupcake 2.6.27 30 April 2009
1.6 Donut 2.6.29 15 September 2009
2.0/2.1 Eclair 2.6.29 26 October 2009
2.2 Froyo 2.6.32 20 May 2010
2.3.x Gingerbread 2.6.35 6 December 2010
3.x Honeycomb 2.6.36 22 February 2011
Android Versions
Oct 2011 5Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Current DistributionPlatform API Level Distribution
Android 1.5 3 1.1 %
Android 1.6 4 1.4 %
Android 2.1 7 11.7 %
Android 2.2 8 45.3 %
Android 2.3 -
Android 2.3.2
9 0.5 %
Android 2.3.3 -
Android 2.3.4
10 38.2 %
Android 3.0 11 0.2 %
Data as on 3rd October 2011 found at http://developer.android.com/resources/dashboard/platform-versions.html
Oct 2011 6Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 4
Android Components
• Components
• Intents
• Lifecycle
• Manifest
• Processes
Oct 2011 7Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Components• 1 Application => N Components
• Applications can use components of other
applications
• Application processes lifecycle are managed by the
system
• N entry points, !1, and !main()
Oct 2011 8Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 5
Components
• Activities
• Services
• Broadcast Receivers
• Content Providers
Oct 2011 9Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intents• Intent = asynchronous messaging system
• Components interact with each other via intents
• May/may not have a designated target
• Intents’ “payload” held in Intent Object
• Intent Filters are specified in special XML file called
“Android Manifest”
Oct 2011 10Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 6
Component Lifecycle
• Android automagically starts/stops/kills processes
• Entire system behaviour predicated based on low
memory
• System triggers Lifecycle callback methods when
relevant
Oct 2011 11Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Manifest
• Registry of all the application components
• XML format
• Always called “AndroidManifest.xml”
• Activity = <activity> ... Static
• Service = <service> ... Static
• Broadcast Receiver:
• Static = <receiver>
• Dynamic = Context.registerReceiver()
• Content Provider = <provider> ... static
Oct 2011 12Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 7
Processes
• Default: all callbacks to any app Component are
issued to the main process thread
• <activity>—<service>—<reeiver>—<provider> have
process attribute to override default
• Do NOT perform blocking/long operations in main
process thread:
– Spawn threads instead
• Process termination/restart is at system’s discretion
Oct 2011 13Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Development Tools
• Eclipse + ADT Plugin (+ JDK v5 or later)
• SDK & Tools:
• android – manage AVDs and SDK components
• apkbuilder- creating .apk packages
• dx- recompile java class files to dalvik executable
• adb – debug bridge
• emulator – QEMU-based ARM emulator
• ...
Oct 2011 14Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 8
Android Architecture
• fs,df.sdf,a
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 9
Linux Kernel
� Android relies on Linux Kernel version 2.6 for core system
services such as
� Security
� Memory Management
� Process Management
� Network Stack, and
� Driver Model
Oct 2011 17Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Linux Kernel� The kernel acts as an abstraction layer between the
hardware and the rest of the software stack
� 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
Oct 2011 18Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 10
Why Linux Kernel?
� Great memory and process management
� Permissions-based security model
� Proven driver model
� Support for shared libraries
� Open source
Oct 2011 19Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Kernel Enhancements� Alarm
� Ashmem
� Binder
� Power Management
� Low Memory Killer
� Kernel Debugger
� Logger
Oct 2011 20Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 11
Native Libraries
� Android includes a set of C/C++ libraries used by various
components of the Android system.
� These capabilities are exposed to developers through the
Android application framework.
� Bionic - System C library
– super fast, small
– BSD-derived implementation of the standard C system library
(libc)
– Optimised for embedded Linux-based devices
Oct 2011 21Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Function Libraries - WebKit� WebKit
– Based on open source WebKit browser framework
– Customized by OS vendor
– Can render pages in full(desktop) view
– Full CSS, Javascript, DOM, AJAX support
– Support for single-column and adaptive view rendering
Oct 2011 22Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 12
Function Libraries – Media Framework
� Media Framework
– Based on PacketVideo OpenCORE platform
– Supports standard video, audio, still-frame formats
– Support for hardware / software codec plug-ins
Oct 2011 23Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Function Libraries – SQLite
� SQLite
– Light-weight transactional data store
– Back end for most platform data storage
Oct 2011 24Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 13
Native Servers – Surface Flinger� Surface Flinger
Oct 2011 25Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Native Servers – Surface Flinger� Surface Flinger
Oct 2011 26Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 14
Native Servers – Surface Flinger
� Provides system-wide surface “composer”, handling all surface
rendering to frame buffer device
� Can combine 2D and 3D surfaces and surfaces from multiple
applications
� Surfaces passed as buffers
Oct 2011 27Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Native Servers – Audio Flinger
Oct 2011 28Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 15
Native Servers – Audio Flinger
Oct 2011 29Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Native Servers – Audio Flinger
� Audio Flinger
– Manages all audio output devices
– Processes multiple audio streams into PCM audio out paths
– Handles audio routing to various outputs
Oct 2011 30Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 16
Android Runtime
Oct 201131
Intr
o to
And
roid
OS
@
Tou
ch
Tour
201
1 by
Android Runtime - Dalvik Virtual Machine
� Every Android application runs in its own process.
� Each one has its own instance of the Dalvik virtual machine.
Oct 2011 32Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 17
Dalvik• Oracle Java =
Java language + JVM
+ JDK libs
• Android Java =
Java language
+ Dalvik VM
+ Apache Harmony
• Supports JIT from v2.2 onwards (85% devices)
Oct 2011 33Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
dex - Dalvik Executable
• JVM runs “.class” files
• Dalvik runs “.dex” files
• dex file => .class files post-processed by “dx” utility
• Uncompressed .dex = 0.5 * Uncompressed .jar
• Odex = Optimised dex (specific to hw platform)
Oct 2011 34Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 18
Android Runtime - Dalvik VM� Run on a relatively slower CPU with relatively less RAM
� Run on a OS without swap-space
� Dalvik has been written so that a device can run multiple VMs
efficiently.
� The Dalvik VM executes files in the Dalvik Executable (.dex)
format.
� .dex is optimized for minimal memory footprint.
Oct 2011 35Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Android Runtime - Dalvik Virtual Machine
� The VM is register-based, and runs classes compiled by a Java
language compiler.
� Java classes are transformed into the .dex format by the included
"dx" tool.
� Dalvik relies on the Linux kernel for threading and low-level
memory management.
Oct 2011 36Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 19
Android Runtime - Dalvik Virtual Machine
� Android’s custom clean-room implementation virtual
machine
� Provides application portability and runtime consistency
� Runs optimized file format (.dex) and Dalvik bytecode
� Java .class / .jar files converted to .dex at build time
Oct 2011 37Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Android Runtime - Dalvik Virtual Machine
�Designed for embedded environment
� Supports multiple VM processes per device
� Highly CPU-optimized bytecode interpreter
� Uses runtime memory very efficiently
Oct 2011 38Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 20
Android OS Startup
39
Startup Sequence• Bootloader
• Linux Kernel
• Init
• Daemons
• Zygote
• System Server
• Activity Manager
• Launcher + Home
Oct 2011 40Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 21
OS Start-up Walkthrough
� It all starts with init…
� Similar to most Linux-based systems at startup
� The bootloader loads the Linux kernel and starts the init
process.
Oct 2011 41Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Start-up Walkthrough� Init starts Linux daemons, including:
– USB Daemon (usbd) to manage USB connections
– Android Debug Bridge (adbd) to manage ADB connections
– Debugger Daemon (debuggerd) to manage debug processes requests (dump memory,
etc.)
– Radio Interface Layer Daemon (rild) to manage communication with the radio
Oct 2011 42Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 22
OS Start-up Walkthrough
� Init process starts the zygote process
– A nascent process which initializes a Dalvik VM instance
– Loads classes and listens on socket for requests to spawn VMs
– Forks on request to create VM instances for managed processes
– Copy-on-write to maximize re-use and minimize footprint
Oct 2011 43Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Start-up Walkthrough� Init starts runtime process:
– Initializes Service Manager – the context manager for Binder that
handles service registration and lookup
– Registers Service Manager as default context manager for Binder
services
Oct 2011 44Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 23
OS Start-up Walkthrough
� Runtime process sends request for Zygote to start System
Server
– Zygote forks a new VM instance for the System Service process
and starts the service
Oct 2011 45Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Start-up Walkthrough� System Service starts the native system servers, including:
– Surface Flinger
– Audio Flinger
Oct 2011 46Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 24
OS Start-up Walkthrough
� Native system servers register with Service Manager as IPC
service targets:
Oct 2011 47Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Start-up Walkthrough
� System Service starts the Android managed services:
Oct 2011 48Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 25
OS Start-up Walkthrough
� Android managed Services register with Service Manager:
Oct 2011 49Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Start-up Walkthrough
Oct 2011 50Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 26
OS Start-up Walkthrough
� After system server loads all services, the system is ready…
Oct 2011 51Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Start-up Walkthrough
Oct 2011 52Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 27
OS Start-up Walkthrough� Each subsequent application is launched in its own process
Oct 2011 53Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
OS Layer Interaction
Oct 2011 54Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 28
OS Layer Interaction
� 3 Main Android layer interaction types
� Direct
– App > Runtime Service > lib
� via Native Service
– App > Runtime Service > Native Service > lib
� via Native Daemon
– App > Runtime Service > Native Daemon > lib
Oct 2011 55Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
App > Runtime Service > lib
Oct 2011 56Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 29
App > Runtime Service > lib
Oct 2011 57Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
App > Runtime Service > Native Service > lib
Oct 2011 58Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 30
App > Runtime Service > Native Service > lib
Oct 2011 59Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
App > Runtime Service > Native Daemon > lib
Oct 2011 60Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 31
App > Runtime Service > Native Daemon > lib
Oct 2011 61Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)
Queries ?
Intoduction to Android OS 15 Oct 2011
TouchTour 2011 32
Thank You.
Oct 2011 63Intro to Android OS @ Touch Tour 2011 by Prasannan.N (@tryprasannan)