Escolar Documentos
Profissional Documentos
Cultura Documentos
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Android Anatomy
Applications
Home Dialer SMS/MMS IM Browser Camera Alarm Calculator
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory Binder (IPC) Driver
Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
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 glibc support
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Linux Kernel
• Standard Linux 2.6.24 Kernel
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Why Linux Kernel?
• Great memory and process management
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Kernel Enhancements
• Alarm
• Low Memory Killer
• Ashmem
• Kernel Debugger
• Binder
• Logger
• Power Management
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Binder: Problem
• Applications and Services may run in separate processes
but must communicate and share data
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Binder: Solution
• Driver to facilitate inter-process communication (IPC)
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Binder in Action
Process A Process B
App A Service B
Binder in Action
Process A Process B
relay to
IPC threads
Binder in Action
Process A Process B
relay to
IPC threads
call return
Binder
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
PM Problem
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
PM Solution
• Built on top of standard Linux Power Management (PM)
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Android PM in Action
App A PowerManager PM Driver
Android PM in Action
App A PowerManager PM Driver
new wake lock
PARTIAL
Android PM in Action
App A PowerManager PM Driver
new wake lock
Turn off
LCD
Android PM in Action
App A PowerManager PM Driver
new wake lock
Turn off
LCD
release
release
Android PM in Action
App A PowerManager PM Driver
new wake lock
Turn off
LCD
release
release
Turn off
CPU
Android PM
android.os.PowerManager
• Use wake locks carefully!
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Kernel
The Android kernel source is available today
at:
http://git.android.com
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Android Anatomy
Libraries
Surface Manager Media Framework SQLite
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory Binder (IPC) Driver
Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Native Libraries
• Bionic Libc
• Function Libraries
• Native Servers
Libraries
Surface Manager Media Framework SQLite WebKit Libc
• Function Libraries
• Native Servers
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
• log capabilities
LOGI(“Logging a message with priority ‘Info’”);
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
• Function Libraries
• Native Servers
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
• Function Libraries
• Native Servers
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
Libraries
Surface Manager Media Framework SQLite WebKit Libc
• Function Libraries
• Native Servers
Libraries
Surface Manager Media Framework SQLite LibWebCore Libc
Contacts Voice Dial Email Calendar Media Player Photo Album Clock …
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Audio
OpenGL|ES Manager FreeType SSL … Dalvik Virtual Machine
Linux Kernel
Shared Memory
Display Driver Camera Driver Bluetooth Driver Driver Binder (IPC) Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Hardware Abstraction Libraries
• User space C/C++ library layer
...
...
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Android Anatomy
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory Binder (IPC) Driver
Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Dalvik Virtual Machine
• Androidʼs custom clean-room implementation virtual
machine
• Provides application portability and runtime consistency
Android Runtime
Core Libraries
Android Runtime
Core Libraries
• Utilities
• File access
• Network Access
• Graphics
• …
Android Runtime
Core Libraries
• Android Anatomy
• Linux Kernel
• Native Libraries
• Android Runtime
• Application Framework
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Android Anatomy
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory Binder (IPC) Driver
Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
Core Platform Services
• Services that are essential to the Android platform
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Core Platform Services
• Activity Manager
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Core Platform Services
• Activity Manager
• Package Manager
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Core Platform Services
• Activity Manager
• Package Manager
• Window Manager
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Core Platform Services
• Activity Manager
• Package Manager
• Window Manager
• Resource Manager
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Core Platform Services
• Activity Manager
• Package Manager
• Window Manager
• Resource Manager
• Content Providers
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Core Platform Services
• Activity Manager
• Package Manager
• Window Manager
• Resource Manager
• Content Providers
• View System
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Provide access to lower-level hardware APIs
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Provide access to lower-level hardware APIs
LocationManager lm = (LocationManager)
Context.getSystemService(Context.LOCATION_SERVICE);
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Telephony Service
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Telephony Service
• Location Service
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
• WiFi Service
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
• WiFi Service
• USB Service
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Hardware Services
• Telephony Service
• Location Service
• Bluetooth Service
• WiFi Service
• USB Service
• Sensor Service
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Application Framework
More Information
• At Google I/O
• “Inside the Android Application Framework”
• Online
• http://code.google.com/android
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Android Anatomy
Applications
Home Dialer SMS/MMS IM Browser Camera Alarm Calculator
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory Binder (IPC) Driver
Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
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…
Init
Linux Kernel
Runtime Walkthrough
Init starts Linux daemons, including:
• USB Daemon (usbd) to manage USB connections
Init
Runtime Walkthrough
Init process starts the zygote process:
• A nascent process which initializes a Dalvik VM instance
usbd
adbd
debuggerd
daemons Zygote
Init
Runtime Walkthrough
Init starts runtime process:
Service
Manager
usbd
adbd
debuggerd
daemons runtime Zygote
Init
Runtime Walkthrough
Runtime process sends request for Zygote to start System
Service
Service
Manager
usbd
adbd
debuggerd
daemons runtime Zygote
Init
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
Service System
Manager Server
usbd
adbd
debuggerd
daemons runtime Zygote Dalvik VM
Init
Runtime Walkthrough
System Service starts the native system servers, including:
• Surface Flinger
• Audio Flinger
Audio Flinger
Surface
Flinger
Service System
Manager Server
usbd
adbd
debuggerd
daemons runtime Zygote Dalvik VM
Init
Runtime Walkthrough
Native system servers register with Service Manager as IPC
service targets:
Audio Flinger
Surface
Flinger
Service System
Manager Server
usbd
adbd
debuggerd
daemons runtime Zygote Dalvik VM
Init
Runtime Walkthrough
System Service starts the Android managed services:
Content Telephony Bluetooth Connectivity Location
Manager Service Service Service Manager
Window Activity Package Power
Manager Manager Manager Manager …
Camera
Surface
Service
Flinger
Service System
Manager Server
usbd
adbd
debuggerd
daemons runtime Zygote Dalvik VM
Init
Runtime Walkthrough
Android managed Services register with Service Manager:
Content Telephony Bluetooth Connectivity Location
Manager Service Service Service Manager
Window Activity Package Power
Manager Manager Manager Manager …
Service
Camera
Manager
Service Camera
Surface
Service
Flinger
Service System
Manager Server
usbd
adbd
debuggerd
daemons runtime Zygote Dalvik VM
Init
Runtime Walkthrough
…
Power
Manager
Activity
Manager
Camera
Surface
Service
Flinger
Service System
Manager Server
usbd
adbd
debuggerd
daemons runtime Zygote Dalvik VM
Init
Runtime Walkthrough
After system server loads all services, the system is ready…
Init Daemon runtime Zygote System
Processes Server
Activity
Manager
Package
Manager
Window
Manager
…
Dalvik VM
Surface
Flinger
usbd
adbd
Init debuggerd
daemons runtime Zygote Audio
Flinger
Runtime Walkthrough
After system server loads all services, the system is ready…
Init Daemon runtime Zygote System Home
Processes Server
Home
Activity
Manager Dalvik VM
Package
Manager
Window
Manager
…
Dalvik VM
Surface
Flinger
usbd
adbd
Init debuggerd
daemons runtime Zygote Audio
Flinger
Runtime Walkthrough
After system server loads all services, the system is ready…
Init Daemon runtime Zygote System Home
Processes Server
Activity Home
Manager
Package Dalvik VM
Manager
Window
Manager
…
Dalvik VM
Surface
Flinger
usbd
adbd
Init debuggerd
daemons runtime Zygote Audio
Flinger
libc libc libc libc libc libc
Runtime Walkthrough
Each subsequent application is launched in itʼs own process
Daemon runtime Zygote System Home Contacts
Processes Server
Dalvik VM
Surface
Flinger
usbd
adbd
debuggerd
daemons runtime Zygote Audio
Flinger
libc libc libc libc libc libc
Agenda
• Android Anatomy
• Linux Kernel
• Native Libraries
• Framework Services
• Android Physiology
• Start-up Walkthrough
• Layer Interaction
Layer Interaction
Application Framework
Runtime Service
Libraries
Linux Kernel
Kernel Driver
Android Runtime Services
Applications
Application
Binder IPC
Application Framework
Runtime Service
JNI
Libraries
Native Service Binding
Linux Kernel
Kernel Driver
Android Runtime Services
Applications
Application
Binder IPC
Application Framework
Runtime Service
JNI
Libraries
Native Service Binding
Dynamic load
HAL Library
Linux Kernel
Kernel Driver
Android Runtime Services
Applications
Application
Binder IPC
Application Framework
Runtime Service
JNI
Libraries
Native Service Binding
Dynamic load
HAL Library
Linux Kernel
Kernel Driver
Example: Location Manager
Applications
Binder IPC
Application
Application Framework
Location Manager Service
GpsLocationProvider
JNI
Libraries
GpsLocationProvider
Dynamic load
libgps.so
Linux Kernel
Kernel Driver
Layer Interaction
Application
Application
Framework Runtime
Service
JNI
Libraries
Native Service
Binding
Linux Kernel
Android Native Services
Applications
Application
Application
Framework Runtime
Service
JNI
Libraries
Binder IPC
Native Service Native Service
Binding
Linux Kernel
Android Native Services
Applications
Application
Application
Framework Runtime
Service
JNI
Libraries
Binder IPC
Native Service Native Service
Binding
Dynamic load
HAL Library
Linux Kernel
Android Native Services
Applications
Application
Application
Framework Runtime
Service
JNI
Libraries
Binder IPC
Native Service Native Service
Binding
Dynamic load
HAL Library
Linux Kernel
Kernel Driver
Android Native Services
Applications
Application
Application
Framework MediaPlayer
JNI
Libraries
Binder IPC
MediaPlayer AudioFlinger
Dynamic load
Media
Framework libaudio.so
Linux Kernel
Kernel Driver
Android Native Services
Applications
Application
Application
Framework MediaPlayer
JNI
Libraries
Binder IPC
MediaPlayer AudioFlinger
Dynamic load
Media libaudio.so
Framework
ALSA
Linux Kernel
Kernel Driver
Android Native Services
Applications
Application
Application
Framework MediaPlayer
JNI
Libraries
Binder IPC
MediaPlayer AudioFlinger
Dynamic load
Media libaudio.so
Framework
Proprietary
Audio Driver
Linux Kernel
Layer Interaction
Application
Application
Framework Runtime
Service
JNI
Libraries
Native Service
Binding
Linux Kernel
Kernel Driver
Daemon Connection
Applications
Application
Application
Framework Runtime
Service
JNI
Libraries
sockets
Native Service Daemon
Binding
Linux Kernel
Kernel Driver
Daemon Connection
Applications
Application
Application
Framework Runtime
Service
JNI
Libraries
sockets
Native Service Daemon
Binding
Dynamic load
HAL Library
Linux Kernel
Kernel Driver
Daemon Connection
Applications
Application
Application
Framework Telephony Manager
JNI
Libraries
sockets
Telephony rild
Manager
Dynamic load
libril.so
Linux Kernel
Kernel Driver
Layer Interaction
Application Framework
Activity Manager Window View Notification
Manager Content Providers System Manager
Telephony Location
Package Manager Manager Resource Manager Manager …
Linux Kernel
Display Driver Camera Driver Bluetooth Driver Shared Memory Binder (IPC) Driver
Driver
Audio Power
USB Driver Keypad Driver WiFi Driver Drivers Management
The End
code.google.com
Questions
Q&A