SlideShare a Scribd company logo
Android Anatomy and Physiology
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Android Anatomy
Applications
Home Dialer
Contacts
SMS/MMS
Email
IM
Calendar
Browser
Media Player Albums
Camera
Clock
Calculator
…Voice Dial
Alarm
Android Runtime
DalvikVirtual Machine
Core Libraries
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
FreeType
SGL SSL
SQLite
WebKit
Libc
Surface Manager
OpenGL|ES
Media Framework
Libraries
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
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
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Linux Kernel
• Standard Linux 2.6.24 Kernel
• Patch of “kernel enhancements” to support Android
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Why Linux Kernel?
• Great memory and process management
• Permissions-based security model
• Proven driver model
• Support for shared libraries
• Itʼs already open source!
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Kernel Enhancements
• Alarm
• Ashmem
• Binder
• Power Management
• Low Memory Killer
• Kernel Debugger
• Logger
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Binder: Problem
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
• Applications and Services may run in separate processes
but must communicate and share data
• IPC can introduce significant processing overhead and
security holes
Binder: Solution
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
• Driver to facilitate inter-process communication (IPC)
• High performance through shared memory
• Per-process thread pool for processing requests
• Reference counting, and mapping of object references
across processes
• Synchronous calls between processes
Process BProcess A
Binder in Action
App A Service B
Process A Process B
Binder in Action
App A Service BContext
Process BProcess A
Binder in Action
App A Service BContext
get service
Process BProcess A
Binder in Action
Binder DriverApp A Service BContext
get service
service
Process BProcess A
Binder in Action
Binder DriverApp A Service BContext
get service
service
Process BProcess A
Binder in Action
Binder DriverApp A Service BContext
get service
call foo(object)
service
Process BProcess A
Binder in Action
Binder DriverApp A Service BContext
get service
marshal proxy
object
call foo(object)
service
Process BProcess A
Binder in Action
Binder DriverApp A Service BContext
get service
relay to
IPC threads
marshal proxy
object
call foo(object)
service
Process BProcess A
Binder in Action
Binder DriverApp A Service BContext
get service
relay to
IPC threads
marshal proxy
object
call return
call foo(object)
service
Binder
Android Interface Definition Language (AIDL)
• http://code.google.com/android/reference/aidl.html
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
PM Problem
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
• Mobile devices run on battery power
• Batteries have limited capacity
PM Solution
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
• Built on top of standard Linux Power Management (PM)
• More aggressive power management policy
• Components make requests to keep the power on through
“wake locks”
• Supports different types of wake locks
Android PM in Action
PM DriverApp A PowerManager
Android PM in Action
PM DriverApp A PowerManager
new wake lock
PARTIAL
Android PM in Action
PM DriverApp A PowerManager
new wake lock
PARTIAL create wake lock
Android PM in Action
PM DriverApp A PowerManager
new wake lock
PARTIAL create wake lock
Turn off
LCD
Android PM in Action
PM DriverApp A PowerManager
new wake lock
PARTIAL create wake lock
Turn off
LCD
release
release
Android PM in Action
PM DriverApp A PowerManager
new wake lock
PARTIAL create wake lock
Turn off
LCD
release
release
Turn off
CPU
Android PM
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
android.os.PowerManager
• Use wake locks carefully!
• userActivity(long when, …);
Kernel
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
The Android kernel source is available today
at:
http://git.android.com
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Android Anatomy
FreeType
SGL SSL
SQLite
WebKit
Libc
Surface Manager
OpenGL|ES
Media Framework
Libraries
Native Libraries
• Bionic Libc
• Function Libraries
• Native Servers
• Hardware Abstraction Libraries
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Native Libraries
• Bionic Libc
• Function Libraries
• Native Servers
• Hardware Abstraction Libraries
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
What is Bionic?
• What is bionic?
• Custom libc implementation, optimized for embedded use.
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Why Bionic?
Why build a custom libc library?
• License: we want to keep GPL out of user-space
• Size: will load in each process, so it needs to be small
• Fast: limited CPU power means we need to be fast
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Bionic libc
• BSD License
• Small size and fast code paths
• Very fast and small custom pthread implementation
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Bionic libc
• Built-in support for important Android-specific services
• system properties

 getprop(“my.system.property”, buff, default);
• log capabilities

 LOGI(“Logging a message with priority ‘Info’”);
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Bionic libc
• Doesn't support certain POSIX features
• Not compatible with Gnu Libc (glibc)
• All native code must be compiled against bionic
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Native Libraries
• Bionic Libc
• Function Libraries
• Native Servers
• Hardware Abstraction Libraries
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
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
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Media Framework
• Based on PacketVideo OpenCORE platform
• Supports standard video, audio, still-frame formats
• Support for hardware / software codec plug-ins
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
SQLite
• Light-weight transactional data store
• Back end for most platform data storage
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Native Libraries
• Bionic Libc
• Function Libraries
• Native Servers
• Hardware Abstraction Libraries
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
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
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
App
Surface
Surface
Surface
Surface Flinger
Frame
Buffer
App
Surface Flinger
• Surfaces passed as buffers via Binder IPC calls
• Can use OpenGL ES and 2D hardware accelerator for its
compositions
• Double-buffering using page-flip
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Audio Flinger
• Manages all audio output devices
• Processes multiple audio streams into PCM audio out paths
• Handles audio routing to various outputs
Libraries
FreeType SSL
SQLite WebKit LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
App
Tone
Audio
Media
Player
Game Audio
Audio Flinger
App
Earpeace
Speaker
Bluetooth
Native Libraries
• Bionic Libc
• Function Libraries
• Native Servers
• Hardware Abstraction Libraries
Libraries
FreeType SSL
SQLite LibWebCore LibcSurface Manager
OpenGL|ES
Media Framework
Audio Manager …
Hardware Abstraction Layer
Linux Kernel
Display Driver Camera Driver Bluetooth Driver
Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Applications
Home Dialer
Contacts
SMS/MMS
Email
IM
Calendar
Browser
Media Player Photo Album
Camera
Clock
Calculator
…Voice Dial
Alarm
Android Runtime
DalvikVirtual Machine
Core Libraries
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
Libraries
FreeType SSL
SQLite WebKit Libc
Surface
Manager
OpenGL|ES
Media
Framework
Audio
Manager …
Hardware Abstraction Layer
Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
Hardware Abstraction Libraries
• 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
Hardware Abstraction Layer
Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
Hardware Abstraction Libraries
Why do we need a user-space HAL?
• Not all components have standardized kernel driver interfaces
• Kernel drivers are GPL which exposes any proprietary IP
• Android has specific requirements for hardware drivers
Hardware Abstraction Layer
Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
HAL Header Example
// must be provided by each Acme hardware implementation
typedef struct {
int (*foo)( void );

 char (*bar)( void );

 …

} AcmeFunctions;
const AcmeFunctions *Acme_Init(const struct Env *env, int argc, char
**argv);
Hardware Abstraction Layer
Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
Hardware Abstraction Libraries
• Libraries are loaded dynamically at runtime as needed
dlHandle = dlopen(“/system/lib/libacme.so”, RTLD_NOW);
...
acmeInit = (const AcmeFunctions *(*)(const struct Env *,
int, char **))dlsym(dlHandle, ”Acme_Init");
...
acmeFuncs = acmeInit(&env, argc, argv);
Hardware Abstraction Layer
Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Android Anatomy
Android Runtime
DalvikVirtual Machine
Core Libraries
FreeType
SGL SSL
SQLite
WebKit
Libc
Surface Manager
OpenGL|ES
Media Framework
Libraries
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
Android Runtime
DalvikVirtual Machine
Core Libraries
Dalvik Virtual Machine
• Designed for embedded environment
• Supports multiple virtual machine processes per device
• Highly CPU-optimized bytecode interpreter
• Uses runtime memory very efficiently
Android Runtime
DalvikVirtual Machine
Core Libraries
Core Libraries
• Core APIs for Java language provide a powerful, yet
simple and familiar development platform
• Data structures
• Utilities
• File access
• Network Access
• Graphics
• …
Android Runtime
DalvikVirtual Machine
Core Libraries
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Android Anatomy
Libraries
FreeType
SGL SSL
SQLite
WebKit
Libc
Surface Manager
OpenGL|ES
Media Framework
Android Runtime
DalvikVirtual Machine
Core Libraries
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
• Services that are essential to the Android platform
• Behind the scenes - applications typically donʼt access them
directly
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
Core Platform Services
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
• Activity Manager
Core Platform Services
• Activity Manager
• Package Manager
Core Platform Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Activity Manager
• Package Manager
• Window Manager
Core Platform Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Activity Manager
• Package Manager
• Window Manager
• Resource Manager
Core Platform Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Activity Manager
• Package Manager
• Window Manager
• Resource Manager
• Content Providers
Core Platform Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Activity Manager
• Package Manager
• Window Manager
• Resource Manager
• Content Providers
• View System
Core Platform Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Provide access to lower-level hardware APIs
Hardware Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Provide access to lower-level hardware APIs
• Typically accessed through local Manager object
LocationManager lm = (LocationManager)
Context.getSystemService(Context.LOCATION_SERVICE);
Hardware Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Telephony Service
Hardware Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Telephony Service
• Location Service
Hardware Services
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
• Telephony Service
• Location Service
• Bluetooth Service
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
• WiFi Service
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
• WiFi Service
• USB Service
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
• WiFi Service
• USB Service
• Sensor Service
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
Hardware Services
More Information
• At Google I/O
• “Inside the Android Application Framework”
• Online
• http://code.google.com/android
Application Framework
View
SystemContent Providers
Resource Manager
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager …
Application Framework
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Android Anatomy
Applications
Home Dialer
Contacts
SMS/MMS
Email
IM
Calendar
Browser
Media Player Albums
Camera
Clock
Calculator
…Voice Dial
Alarm
Android Runtime
DalvikVirtual Machine
Core Libraries
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
FreeType
SGL SSL
SQLite
WebKit
Libc
Surface Manager
OpenGL|ES
Media Framework
Libraries
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Runtime 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.
Init
Linux Kernel
Runtime 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
Init
usbd adbd debuggerd rild
Runtime 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
usbdadbddebuggerddaemons
Init
Zygote
Runtime 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
runtime
Service
Manager
usbdadbddebuggerddaemons
Init
Zygote
Runtime Walkthrough
Runtime process sends request for Zygote to start System
Service
runtime
Service
Manager
usbdadbddebuggerddaemons
Init
Zygote
Runtime 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
Zygote DalvikVM
usbdadbddebuggerddaemons
System
Server
runtime
Service
Manager
Init
Runtime Walkthrough
System Service starts the native system servers, including:
• Surface Flinger
• Audio Flinger
usbdadbddebuggerddaemons Zygoteruntime
Service
Manager
DalvikVM
System
Server
Init
Surface
Flinger
Audio Flinger
Runtime Walkthrough
Native system servers register with Service Manager as IPC
service targets:
Zygoteruntime
Service
Manager
usbdadbddebuggerddaemons
Init
DalvikVM
System
Server
Surface
Flinger
Audio Flinger
Runtime Walkthrough
System Service starts the Android managed services:
usbdadbddebuggerddaemons Zygoteruntime
Service
Manager
DalvikVM
System
Server
Init
Window
Manager
Activity
Manager
Package
Manager
Power
Manager …
Content
Manager
Telephony
Service
Bluetooth
Service
Connectivity
Service
Location
Manager
Camera
ServiceSurface
Flinger
Runtime Walkthrough
Android managed Services register with Service Manager:
usbdadbddebuggerddaemons
Camera
Service
Zygoteruntime
Service
Manager
DalvikVM
System
Server
Init
Window
Manager
Activity
Manager
Package
Manager
Power
Manager …
Service
Manager
Content
Manager
Telephony
Service
Bluetooth
Service
Connectivity
Service
Location
Manager
Camera
ServiceSurface
Flinger
…
Runtime Walkthrough
usbdadbddebuggerddaemons Zygoteruntime
Service
Manager
DalvikVM
System
Server
Init
Power
ManagerActivity
Manager
Camera
ServiceSurface
Flinger
Runtime Walkthrough
After system server loads all services, the system is ready…
Init System
Server
Surface
Flinger
Audio
Flinger
DalvikVM
Window
Manager
Activity
Manager
Package
Manager
…
Init
Daemon
Processes
usbdadbddebuggerddaemons
runtime
runtime
Zygote
Zygote
Runtime Walkthrough
After system server loads all services, the system is ready…
Init
Init
Daemon
Processes
usbdadbddebuggerddaemons
runtime
runtime
Zygote
Zygote
Home
DalvikVM
Home
System
Server
Surface
Flinger
Audio
Flinger
DalvikVM
Window
Manager
Activity
Manager
Package
Manager
…
Runtime Walkthrough
After system server loads all services, the system is ready…
Init
Init
Daemon
Processes
usbdadbddebuggerddaemons
runtime
runtime
Zygote
Zygote
Home
DalvikVM
Home
libc libc libc libc libc
System
Server
Surface
Flinger
Audio
Flinger
DalvikVM
Window
Manager
Activity
Manager
Package
Manager
libc
…
Runtime Walkthrough
Each subsequent application is launched in itʼs own process
System
Server
Surface
Flinger
Audio
Flinger
DalvikVM
Window
Manager
Activity
Manager
Package
Manager
libc
…
Daemon
Processes
usbdadbddebuggerddaemons
runtime
runtime
Zygote
Zygote
Home
DalvikVM
Home
libc libc libc libc
Contacts
DalvikVM
Contacts
libc
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Framework Services
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Layer Interaction
There are 3 main flavors of Android layer cake:
• App  Runtime Service  lib
• App  Runtime Service  Native Service  lib
• App  Runtime Service  Native Daemon  lib
Layer Interaction
There are 3 main flavors of Android layer cake:
• App  Runtime Service  lib
• App  Runtime Service  Native Service  lib
• App  Runtime Service  Native Daemon  lib
Libraries
Linux Kernel
Applications
Application Framework
Android Runtime Services
Binder IPC
Application
Runtime Service
Kernel Driver
Libraries
Applications
Application Framework
JNI
Android Runtime Services
Binder IPC
Application
Runtime Service
Native Service Binding
Linux Kernel
Kernel Driver
Libraries
Linux Kernel
Applications
Application Framework
JNI
Android Runtime Services
Binder IPC
Dynamic load
Application
Runtime Service
Native Service Binding
HAL Library
Kernel Driver
Libraries
Linux Kernel
Applications
Application Framework
JNI
Android Runtime Services
Binder IPC
Dynamic load
Application
Runtime Service
Native Service Binding
HAL Library
Kernel Driver
Libraries
Linux Kernel
Applications
Application Framework
JNI
Example: Location Manager
Dynamic load
Location Manager Service
GpsLocationProvider
libgps.so
GpsLocationProvider
Binder IPC
Application
Kernel Driver
Layer Interaction
There are 3 main flavors of Android layer cake:
• App  Runtime Service  lib
• App  Runtime Service  Native Service  lib
• App  Runtime Service  Native Daemon  lib
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Application
Runtime
Service
Native Service
Binding
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Application
Runtime
Service
Native Service
Binding Native Service
Binder IPC
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Application
Runtime
Service
Native Service
Binding
HAL Library
Native Service
Binder IPC
Dynamic load
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Application
Runtime
Service
Native Service
Binding
HAL Library
Kernel Driver
Native Service
Binder IPC
Dynamic load
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Dynamic load
Application
MediaPlayer
MediaPlayer
libaudio.so
Kernel Driver
AudioFlinger
Binder IPC
Media
Framework
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Dynamic load
Application
MediaPlayer
MediaPlayer
libaudio.so
AudioFlinger
Binder IPC
Media
Framework
ALSA
Kernel Driver
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Android Native Services
Dynamic load
Application
MediaPlayer
MediaPlayer
libaudio.so
AudioFlinger
Binder IPC
Media
Framework
Proprietary
Audio Driver
Layer Interaction
There are 3 main flavors of Android layer cake:
• App  Runtime Service  lib
• App  Runtime Service  Native Service  lib
• App  Runtime Service  Native Daemon  lib
Daemon Connection
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Application
Runtime
Service
Native Service
Binding
Kernel Driver
Daemon Connection
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Application
Runtime
Service
Native Service
Binding
Kernel Driver
Daemon
sockets
Daemon Connection
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Dynamic load
Application
Runtime
Service
Native Service
Binding
HAL Library
Kernel Driver
Daemon
sockets
Daemon Connection
Libraries
Linux Kernel
Applications
Application
Framework
JNI
Dynamic load
Application
Telephony Manager
Telephony
Manager
libril.so
Kernel Driver
rild
sockets
Layer Interaction
There are 3 main flavors of Android layer cake:
• App  Runtime Service  lib
• App  Runtime Service  Native Service  lib
• App  Runtime Service  Native Daemon  lib
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory
Driver Binder (IPC) Driver
Power
ManagementUSB Driver Keypad Driver WiFi Driver
Audio
Drivers
Android Anatomy
Applications
Home Dialer
Contacts
SMS/MMS
Email
IM
Calendar
Browser
Media Player Albums
Camera
Clock
Calculator
…Voice Dial
Alarm
Android Runtime
DalvikVirtual Machine
Core Libraries
Application Framework
View
SystemContent Providers
Resource Manager …
Activity Manager
Package Manager
Window
Manager
Notification
Manager
Location
Manager
Telephony
Manager
FreeType
SGL SSL
SQLite
WebKit
Libc
Surface Manager
OpenGL|ES
Media Framework
Libraries
The End
code.google.com
Questions
Q&A

More Related Content

PDF
DevOpsCon 2015 - DevOps in Mobile Games
PDF
The anatomy and philosophy of Android - Google I/O 2009
PPT
Inside the Android application framework - Google I/O 2009
PPTX
Containers, Serverless and Functions in a nutshell
PPTX
DockerCon SF 2015: Cultural Change using Docker
PPTX
Microcontainers and Tools for Hardcore Container Debugging
PDF
A Deep Dive into Open Source Android Development
PPTX
An Integrated Pipeline for Private and Public Clouds with Jenkins, Artifactor...
DevOpsCon 2015 - DevOps in Mobile Games
The anatomy and philosophy of Android - Google I/O 2009
Inside the Android application framework - Google I/O 2009
Containers, Serverless and Functions in a nutshell
DockerCon SF 2015: Cultural Change using Docker
Microcontainers and Tools for Hardcore Container Debugging
A Deep Dive into Open Source Android Development
An Integrated Pipeline for Private and Public Clouds with Jenkins, Artifactor...

What's hot (19)

PDF
Disruption from within
PDF
The tools & technologies behind Resin.io
PPT
Android Anatomy
PPTX
Docker for the enterprise
PPTX
DockerCon SF 2015: Using Docker to Keep Houses Warm: Highly Distributed Micro...
PDF
Containers docker-docker hub-azureacr-azure aci
PPT
Getting Started with Docker
PPTX
Moby KubeCon 2017
PDF
DCSF19 Containerized Databases for Enterprise Applications
PDF
Bringing DevOps to Routing with evolved XR: an overview
PDF
321 codeincontainer brewbox
PPTX
Oscon 2017: Build your own container-based system with the Moby project
PDF
DCSF 19 Mitigating Legacy Windows Operating System Vulnerabilities with Docke...
PPTX
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
PDF
56k.cloud training
PDF
Preparing your dockerised application for production deployment
PDF
TUG 2009 Roadmap
PPTX
Webinar Docker Tri Series
PPTX
Reduce Your Configuration Management Nightmare with Docker - Jonah Horowitz -...
Disruption from within
The tools & technologies behind Resin.io
Android Anatomy
Docker for the enterprise
DockerCon SF 2015: Using Docker to Keep Houses Warm: Highly Distributed Micro...
Containers docker-docker hub-azureacr-azure aci
Getting Started with Docker
Moby KubeCon 2017
DCSF19 Containerized Databases for Enterprise Applications
Bringing DevOps to Routing with evolved XR: an overview
321 codeincontainer brewbox
Oscon 2017: Build your own container-based system with the Moby project
DCSF 19 Mitigating Legacy Windows Operating System Vulnerabilities with Docke...
CT Software Developers Meetup: Using Docker and Vagrant Within A GitHub Pull ...
56k.cloud training
Preparing your dockerised application for production deployment
TUG 2009 Roadmap
Webinar Docker Tri Series
Reduce Your Configuration Management Nightmare with Docker - Jonah Horowitz -...
Ad

Similar to Android Anatomy google io 2008 (20)

PDF
Android presentation
PDF
14180203 an-introduction-to-android
PPT
Portinig Application, Drivers And Os
PDF
Android application development
PPT
My androidpresentation
PDF
Embedded Android : System Development - Part I
PDF
Usergroup 02 Berlin Windows7
PPTX
BigBlueButton Platform Components
PPTX
Android - Application Framework
PDF
Google Io Introduction To Android
PDF
Windows container security
PPT
Android OS
PPTX
Crosswalk and the Intel XDK
PPSX
Android Introduction
PPTX
Android and Intel Inside
PPT
Android General information
PDF
Introduction to Android platform
PDF
QNX, C/C++, Qt, Cascades, HTML5… So what’s now BlackBerry 10 application deve...
PPTX
Docker Deep Dive Understanding Docker Engine Docker for DevOps
PPTX
OpenStack Summit
Android presentation
14180203 an-introduction-to-android
Portinig Application, Drivers And Os
Android application development
My androidpresentation
Embedded Android : System Development - Part I
Usergroup 02 Berlin Windows7
BigBlueButton Platform Components
Android - Application Framework
Google Io Introduction To Android
Windows container security
Android OS
Crosswalk and the Intel XDK
Android Introduction
Android and Intel Inside
Android General information
Introduction to Android platform
QNX, C/C++, Qt, Cascades, HTML5… So what’s now BlackBerry 10 application deve...
Docker Deep Dive Understanding Docker Engine Docker for DevOps
OpenStack Summit
Ad

Recently uploaded (6)

PDF
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
DOC
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
DOC
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
PPTX
ASMS Telecommunication company Profile
PPTX
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
6-UseCfgfhgfhgfhgfhgfhfhhaseActivity.pdf
Camb毕业证学历认证,格罗斯泰斯特主教大学毕业证仿冒文凭毕业证
证书学历UoA毕业证,澳大利亚中汇学院毕业证国外大学毕业证
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
ASMS Telecommunication company Profile
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx

Android Anatomy google io 2008

  • 1. Android Anatomy and Physiology
  • 2. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Android Runtime • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 3. Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Android Anatomy Applications Home Dialer Contacts SMS/MMS Email IM Calendar Browser Media Player Albums Camera Clock Calculator …Voice Dial Alarm Android Runtime DalvikVirtual Machine Core Libraries Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager FreeType SGL SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Libraries
  • 4. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Android Runtime • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 5. 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 Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers
  • 6. Linux Kernel • Standard Linux 2.6.24 Kernel • Patch of “kernel enhancements” to support Android Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers
  • 7. Why Linux Kernel? • Great memory and process management • Permissions-based security model • Proven driver model • Support for shared libraries • Itʼs already open source! Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers
  • 8. Kernel Enhancements • Alarm • Ashmem • Binder • Power Management • Low Memory Killer • Kernel Debugger • Logger Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers
  • 9. Binder: Problem Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers • Applications and Services may run in separate processes but must communicate and share data • IPC can introduce significant processing overhead and security holes
  • 10. Binder: Solution Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers • Driver to facilitate inter-process communication (IPC) • High performance through shared memory • Per-process thread pool for processing requests • Reference counting, and mapping of object references across processes • Synchronous calls between processes
  • 11. Process BProcess A Binder in Action App A Service B
  • 12. Process A Process B Binder in Action App A Service BContext
  • 13. Process BProcess A Binder in Action App A Service BContext get service
  • 14. Process BProcess A Binder in Action Binder DriverApp A Service BContext get service service
  • 15. Process BProcess A Binder in Action Binder DriverApp A Service BContext get service service
  • 16. Process BProcess A Binder in Action Binder DriverApp A Service BContext get service call foo(object) service
  • 17. Process BProcess A Binder in Action Binder DriverApp A Service BContext get service marshal proxy object call foo(object) service
  • 18. Process BProcess A Binder in Action Binder DriverApp A Service BContext get service relay to IPC threads marshal proxy object call foo(object) service
  • 19. Process BProcess A Binder in Action Binder DriverApp A Service BContext get service relay to IPC threads marshal proxy object call return call foo(object) service
  • 20. Binder Android Interface Definition Language (AIDL) • http://code.google.com/android/reference/aidl.html Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers
  • 21. PM Problem Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers • Mobile devices run on battery power • Batteries have limited capacity
  • 22. PM Solution Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers • Built on top of standard Linux Power Management (PM) • More aggressive power management policy • Components make requests to keep the power on through “wake locks” • Supports different types of wake locks
  • 23. Android PM in Action PM DriverApp A PowerManager
  • 24. Android PM in Action PM DriverApp A PowerManager new wake lock PARTIAL
  • 25. Android PM in Action PM DriverApp A PowerManager new wake lock PARTIAL create wake lock
  • 26. Android PM in Action PM DriverApp A PowerManager new wake lock PARTIAL create wake lock Turn off LCD
  • 27. Android PM in Action PM DriverApp A PowerManager new wake lock PARTIAL create wake lock Turn off LCD release release
  • 28. Android PM in Action PM DriverApp A PowerManager new wake lock PARTIAL create wake lock Turn off LCD release release Turn off CPU
  • 29. Android PM Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers android.os.PowerManager • Use wake locks carefully! • userActivity(long when, …);
  • 30. Kernel Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers The Android kernel source is available today at: http://git.android.com
  • 31. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Android Runtime • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 32. Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Android Anatomy FreeType SGL SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Libraries
  • 33. Native Libraries • Bionic Libc • Function Libraries • Native Servers • Hardware Abstraction Libraries Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 34. Native Libraries • Bionic Libc • Function Libraries • Native Servers • Hardware Abstraction Libraries Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 35. What is Bionic? • What is bionic? • Custom libc implementation, optimized for embedded use. Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 36. Why Bionic? Why build a custom libc library? • License: we want to keep GPL out of user-space • Size: will load in each process, so it needs to be small • Fast: limited CPU power means we need to be fast Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 37. Bionic libc • BSD License • Small size and fast code paths • Very fast and small custom pthread implementation Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 38. Bionic libc • Built-in support for important Android-specific services • system properties getprop(“my.system.property”, buff, default); • log capabilities LOGI(“Logging a message with priority ‘Info’”); Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 39. Bionic libc • Doesn't support certain POSIX features • Not compatible with Gnu Libc (glibc) • All native code must be compiled against bionic Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 40. Native Libraries • Bionic Libc • Function Libraries • Native Servers • Hardware Abstraction Libraries Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 41. 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 Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 42. Media Framework • Based on PacketVideo OpenCORE platform • Supports standard video, audio, still-frame formats • Support for hardware / software codec plug-ins Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 43. SQLite • Light-weight transactional data store • Back end for most platform data storage Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 44. Native Libraries • Bionic Libc • Function Libraries • Native Servers • Hardware Abstraction Libraries Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 45. 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 Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager … App Surface Surface Surface Surface Flinger Frame Buffer App
  • 46. Surface Flinger • Surfaces passed as buffers via Binder IPC calls • Can use OpenGL ES and 2D hardware accelerator for its compositions • Double-buffering using page-flip Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 47. Audio Flinger • Manages all audio output devices • Processes multiple audio streams into PCM audio out paths • Handles audio routing to various outputs Libraries FreeType SSL SQLite WebKit LibcSurface Manager OpenGL|ES Media Framework Audio Manager … App Tone Audio Media Player Game Audio Audio Flinger App Earpeace Speaker Bluetooth
  • 48. Native Libraries • Bionic Libc • Function Libraries • Native Servers • Hardware Abstraction Libraries Libraries FreeType SSL SQLite LibWebCore LibcSurface Manager OpenGL|ES Media Framework Audio Manager …
  • 49. Hardware Abstraction Layer Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Applications Home Dialer Contacts SMS/MMS Email IM Calendar Browser Media Player Photo Album Camera Clock Calculator …Voice Dial Alarm Android Runtime DalvikVirtual Machine Core Libraries Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager Libraries FreeType SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Audio Manager … Hardware Abstraction Layer Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
  • 50. Hardware Abstraction Libraries • 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 Hardware Abstraction Layer Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
  • 51. Hardware Abstraction Libraries Why do we need a user-space HAL? • Not all components have standardized kernel driver interfaces • Kernel drivers are GPL which exposes any proprietary IP • Android has specific requirements for hardware drivers Hardware Abstraction Layer Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
  • 52. HAL Header Example // must be provided by each Acme hardware implementation typedef struct { int (*foo)( void ); char (*bar)( void ); … } AcmeFunctions; const AcmeFunctions *Acme_Init(const struct Env *env, int argc, char **argv); Hardware Abstraction Layer Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
  • 53. Hardware Abstraction Libraries • Libraries are loaded dynamically at runtime as needed dlHandle = dlopen(“/system/lib/libacme.so”, RTLD_NOW); ... acmeInit = (const AcmeFunctions *(*)(const struct Env *, int, char **))dlsym(dlHandle, ”Acme_Init"); ... acmeFuncs = acmeInit(&env, argc, argv); Hardware Abstraction Layer Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …
  • 54. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Android Runtime • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 55. Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Android Anatomy Android Runtime DalvikVirtual Machine Core Libraries FreeType SGL SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Libraries
  • 56. 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 Android Runtime DalvikVirtual Machine Core Libraries
  • 57. Dalvik Virtual Machine • Designed for embedded environment • Supports multiple virtual machine processes per device • Highly CPU-optimized bytecode interpreter • Uses runtime memory very efficiently Android Runtime DalvikVirtual Machine Core Libraries
  • 58. Core Libraries • Core APIs for Java language provide a powerful, yet simple and familiar development platform • Data structures • Utilities • File access • Network Access • Graphics • … Android Runtime DalvikVirtual Machine Core Libraries
  • 59. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Android Runtime • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 60. Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Android Anatomy Libraries FreeType SGL SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Android Runtime DalvikVirtual Machine Core Libraries Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager
  • 61. • Services that are essential to the Android platform • Behind the scenes - applications typically donʼt access them directly Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager Core Platform Services
  • 62. Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager • Activity Manager Core Platform Services
  • 63. • Activity Manager • Package Manager Core Platform Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 64. • Activity Manager • Package Manager • Window Manager Core Platform Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 65. • Activity Manager • Package Manager • Window Manager • Resource Manager Core Platform Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 66. • Activity Manager • Package Manager • Window Manager • Resource Manager • Content Providers Core Platform Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 67. • Activity Manager • Package Manager • Window Manager • Resource Manager • Content Providers • View System Core Platform Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 68. • Provide access to lower-level hardware APIs Hardware Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 69. • Provide access to lower-level hardware APIs • Typically accessed through local Manager object LocationManager lm = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE); Hardware Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 70. • Telephony Service Hardware Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 71. • Telephony Service • Location Service Hardware Services Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager …
  • 72. • Telephony Service • Location Service • Bluetooth Service Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager … Hardware Services
  • 73. • Telephony Service • Location Service • Bluetooth Service • WiFi Service Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager … Hardware Services
  • 74. • Telephony Service • Location Service • Bluetooth Service • WiFi Service • USB Service Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager … Hardware Services
  • 75. • Telephony Service • Location Service • Bluetooth Service • WiFi Service • USB Service • Sensor Service Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager … Hardware Services
  • 76. More Information • At Google I/O • “Inside the Android Application Framework” • Online • http://code.google.com/android Application Framework View SystemContent Providers Resource Manager Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager … Application Framework
  • 77. Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Android Anatomy Applications Home Dialer Contacts SMS/MMS Email IM Calendar Browser Media Player Albums Camera Clock Calculator …Voice Dial Alarm Android Runtime DalvikVirtual Machine Core Libraries Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager FreeType SGL SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Libraries
  • 78. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 79. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Application Framework • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 80. Runtime 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. Init Linux Kernel
  • 81. Runtime 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 Init usbd adbd debuggerd rild
  • 82. Runtime 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 usbdadbddebuggerddaemons Init Zygote
  • 83. Runtime 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 runtime Service Manager usbdadbddebuggerddaemons Init Zygote
  • 84. Runtime Walkthrough Runtime process sends request for Zygote to start System Service runtime Service Manager usbdadbddebuggerddaemons Init Zygote
  • 85. Runtime 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 Zygote DalvikVM usbdadbddebuggerddaemons System Server runtime Service Manager Init
  • 86. Runtime Walkthrough System Service starts the native system servers, including: • Surface Flinger • Audio Flinger usbdadbddebuggerddaemons Zygoteruntime Service Manager DalvikVM System Server Init Surface Flinger Audio Flinger
  • 87. Runtime Walkthrough Native system servers register with Service Manager as IPC service targets: Zygoteruntime Service Manager usbdadbddebuggerddaemons Init DalvikVM System Server Surface Flinger Audio Flinger
  • 88. Runtime Walkthrough System Service starts the Android managed services: usbdadbddebuggerddaemons Zygoteruntime Service Manager DalvikVM System Server Init Window Manager Activity Manager Package Manager Power Manager … Content Manager Telephony Service Bluetooth Service Connectivity Service Location Manager Camera ServiceSurface Flinger
  • 89. Runtime Walkthrough Android managed Services register with Service Manager: usbdadbddebuggerddaemons Camera Service Zygoteruntime Service Manager DalvikVM System Server Init Window Manager Activity Manager Package Manager Power Manager … Service Manager Content Manager Telephony Service Bluetooth Service Connectivity Service Location Manager Camera ServiceSurface Flinger
  • 91. Runtime Walkthrough After system server loads all services, the system is ready… Init System Server Surface Flinger Audio Flinger DalvikVM Window Manager Activity Manager Package Manager … Init Daemon Processes usbdadbddebuggerddaemons runtime runtime Zygote Zygote
  • 92. Runtime Walkthrough After system server loads all services, the system is ready… Init Init Daemon Processes usbdadbddebuggerddaemons runtime runtime Zygote Zygote Home DalvikVM Home System Server Surface Flinger Audio Flinger DalvikVM Window Manager Activity Manager Package Manager …
  • 93. Runtime Walkthrough After system server loads all services, the system is ready… Init Init Daemon Processes usbdadbddebuggerddaemons runtime runtime Zygote Zygote Home DalvikVM Home libc libc libc libc libc System Server Surface Flinger Audio Flinger DalvikVM Window Manager Activity Manager Package Manager libc …
  • 94. Runtime Walkthrough Each subsequent application is launched in itʼs own process System Server Surface Flinger Audio Flinger DalvikVM Window Manager Activity Manager Package Manager libc … Daemon Processes usbdadbddebuggerddaemons runtime runtime Zygote Zygote Home DalvikVM Home libc libc libc libc Contacts DalvikVM Contacts libc
  • 95. Agenda • Android Anatomy • Linux Kernel • Native Libraries • Framework Services • Android Physiology • Start-up Walkthrough • Layer Interaction
  • 96. Layer Interaction There are 3 main flavors of Android layer cake: • App  Runtime Service  lib • App  Runtime Service  Native Service  lib • App  Runtime Service  Native Daemon  lib
  • 97. Layer Interaction There are 3 main flavors of Android layer cake: • App  Runtime Service  lib • App  Runtime Service  Native Service  lib • App  Runtime Service  Native Daemon  lib
  • 98. Libraries Linux Kernel Applications Application Framework Android Runtime Services Binder IPC Application Runtime Service Kernel Driver
  • 99. Libraries Applications Application Framework JNI Android Runtime Services Binder IPC Application Runtime Service Native Service Binding Linux Kernel Kernel Driver
  • 100. Libraries Linux Kernel Applications Application Framework JNI Android Runtime Services Binder IPC Dynamic load Application Runtime Service Native Service Binding HAL Library Kernel Driver
  • 101. Libraries Linux Kernel Applications Application Framework JNI Android Runtime Services Binder IPC Dynamic load Application Runtime Service Native Service Binding HAL Library Kernel Driver
  • 102. Libraries Linux Kernel Applications Application Framework JNI Example: Location Manager Dynamic load Location Manager Service GpsLocationProvider libgps.so GpsLocationProvider Binder IPC Application Kernel Driver
  • 103. Layer Interaction There are 3 main flavors of Android layer cake: • App  Runtime Service  lib • App  Runtime Service  Native Service  lib • App  Runtime Service  Native Daemon  lib
  • 104. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Application Runtime Service Native Service Binding
  • 105. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Application Runtime Service Native Service Binding Native Service Binder IPC
  • 106. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Application Runtime Service Native Service Binding HAL Library Native Service Binder IPC Dynamic load
  • 107. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Application Runtime Service Native Service Binding HAL Library Kernel Driver Native Service Binder IPC Dynamic load
  • 108. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Dynamic load Application MediaPlayer MediaPlayer libaudio.so Kernel Driver AudioFlinger Binder IPC Media Framework
  • 109. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Dynamic load Application MediaPlayer MediaPlayer libaudio.so AudioFlinger Binder IPC Media Framework ALSA Kernel Driver
  • 110. Libraries Linux Kernel Applications Application Framework JNI Android Native Services Dynamic load Application MediaPlayer MediaPlayer libaudio.so AudioFlinger Binder IPC Media Framework Proprietary Audio Driver
  • 111. Layer Interaction There are 3 main flavors of Android layer cake: • App  Runtime Service  lib • App  Runtime Service  Native Service  lib • App  Runtime Service  Native Daemon  lib
  • 114. Daemon Connection Libraries Linux Kernel Applications Application Framework JNI Dynamic load Application Runtime Service Native Service Binding HAL Library Kernel Driver Daemon sockets
  • 115. Daemon Connection Libraries Linux Kernel Applications Application Framework JNI Dynamic load Application Telephony Manager Telephony Manager libril.so Kernel Driver rild sockets
  • 116. Layer Interaction There are 3 main flavors of Android layer cake: • App  Runtime Service  lib • App  Runtime Service  Native Service  lib • App  Runtime Service  Native Daemon  lib
  • 117. Linux Kernel Display Driver Camera Driver Bluetooth Driver Shared Memory Driver Binder (IPC) Driver Power ManagementUSB Driver Keypad Driver WiFi Driver Audio Drivers Android Anatomy Applications Home Dialer Contacts SMS/MMS Email IM Calendar Browser Media Player Albums Camera Clock Calculator …Voice Dial Alarm Android Runtime DalvikVirtual Machine Core Libraries Application Framework View SystemContent Providers Resource Manager … Activity Manager Package Manager Window Manager Notification Manager Location Manager Telephony Manager FreeType SGL SSL SQLite WebKit Libc Surface Manager OpenGL|ES Media Framework Libraries