Top Banner
Android Anatomy and Physiology
119
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Android Anatomy

Android Anatomy and Physiology

Page 2: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Android Runtime

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 3: Android Anatomy

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Android AnatomyApplications

Home Dialer

Contacts

SMS/MMS

Email

IM

Calendar

Browser

Media Player Albums

Camera

Clock

Calculator

…Voice Dial

Alarm

Android Runtime

Dalvik Virtual Machine

Core Libraries

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

FreeType

SGL SSL

SQLite

WebKit

Libc

Surface Manager

OpenGL|ES

Media Framework

Libraries

Page 4: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Android Runtime

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 5: Android Anatomy

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 KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Page 6: Android Anatomy

Linux Kernel

• Standard Linux 2.6.24 Kernel

• Patch of “kernel enhancements” to support Android

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Page 7: Android Anatomy

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 KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Page 8: Android Anatomy

Kernel Enhancements• Alarm

• Ashmem

• Binder

• Power Management

• Low Memory Killer

• Kernel Debugger

• Logger

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Page 9: Android Anatomy

Binder: Problem

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB 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

Page 10: Android Anatomy

Binder: Solution

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB 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

Page 11: Android Anatomy

Process BProcess A

Binder in Action

App A Service B

Page 12: Android Anatomy

Process A Process B

Binder in Action

App A Service BContext

Page 13: Android Anatomy

Process BProcess A

Binder in Action

App A Service BContext

get service

Page 14: Android Anatomy

Process BProcess A

Binder in Action

Binder DriverApp A Service BContext

get service

service

Page 15: Android Anatomy

Process BProcess A

Binder in Action

Binder DriverApp A Service BContext

get service

service

Page 16: Android Anatomy

Process BProcess A

Binder in Action

Binder DriverApp A Service BContext

get service

call foo(object)

service

Page 17: Android Anatomy

Process BProcess A

Binder in Action

Binder DriverApp A Service BContext

get service

marshal proxy object

call foo(object)

service

Page 18: Android Anatomy

Process BProcess A

Binder in Action

Binder DriverApp A Service BContext

get service

relay toIPC threads

marshal proxy object

call foo(object)

service

Page 19: Android Anatomy

Process BProcess A

Binder in Action

Binder DriverApp A Service BContext

get service

relay toIPC threads

marshal proxy object

call return

call foo(object)

service

Page 20: Android Anatomy

Binder

Android Interface Definition Language (AIDL)

• http://code.google.com/android/reference/aidl.html

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Page 21: Android Anatomy

PM Problem

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

• Mobile devices run on battery power

• Batteries have limited capacity

Page 22: Android Anatomy

PM Solution

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB 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

Page 23: Android Anatomy

Android PM in ActionPM DriverApp A PowerManager

Page 24: Android Anatomy

Android PM in ActionPM DriverApp A PowerManager

new wake lock

PARTIAL

Page 25: Android Anatomy

Android PM in ActionPM DriverApp A PowerManager

new wake lock

PARTIAL create wake lock

Page 26: Android Anatomy

Android PM in ActionPM DriverApp A PowerManager

new wake lock

PARTIAL create wake lock

Turn off LCD

Page 27: Android Anatomy

Android PM in ActionPM DriverApp A PowerManager

new wake lock

PARTIAL create wake lock

Turn off LCD

release

release

Page 28: Android Anatomy

Android PM in ActionPM DriverApp A PowerManager

new wake lock

PARTIAL create wake lock

Turn off LCD

release

release

Turn off CPU

Page 29: Android Anatomy

Android PM

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

android.os.PowerManager• Use wake locks carefully!

• userActivity(long when, …);

Page 30: Android Anatomy

Kernel

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

The Android kernel source is available today at:

http://git.android.com

Page 31: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Android Runtime

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 32: Android Anatomy

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Android Anatomy

FreeType

SGL SSL

SQLite

WebKit

Libc

Surface Manager

OpenGL|ES

Media Framework

Libraries

Page 33: Android Anatomy

Native Libraries• Bionic Libc

• Function Libraries

• Native Servers

• Hardware Abstraction Libraries

Libraries

FreeType SSL

SQLite WebKit LibcSurface Manager

OpenGL|ES

Media Framework

Audio Manager …

Page 34: Android Anatomy

Native Libraries• Bionic Libc

• Function Libraries

• Native Servers

• Hardware Abstraction Libraries

Libraries

FreeType SSL

SQLite WebKit LibcSurface Manager

OpenGL|ES

Media Framework

Audio Manager …

Page 35: Android Anatomy

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 …

Page 36: Android Anatomy

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 …

Page 37: Android Anatomy

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 …

Page 38: Android Anatomy

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 …

Page 39: Android Anatomy

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 …

Page 40: Android Anatomy

Native Libraries• Bionic Libc

• Function Libraries

• Native Servers

• Hardware Abstraction Libraries

Libraries

FreeType SSL

SQLite WebKit LibcSurface Manager

OpenGL|ES

Media Framework

Audio Manager …

Page 41: Android Anatomy

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 …

Page 42: Android Anatomy

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 …

Page 43: Android Anatomy

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 …

Page 44: Android Anatomy

Native Libraries• Bionic Libc

• Function Libraries

• Native Servers

• Hardware Abstraction Libraries

Libraries

FreeType SSL

SQLite WebKit LibcSurface Manager

OpenGL|ES

Media Framework

Audio Manager …

Page 45: Android Anatomy

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 …

AppSurface

Surface

Surface

Surface Flinger Frame Buffer

App

Page 46: Android Anatomy

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 …

Page 47: Android Anatomy

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

ToneAudioMedia Player

Game Audio

Audio FlingerApp

Earpeace

Speaker

Bluetooth

Page 48: Android Anatomy

Native Libraries• Bionic Libc

• Function Libraries

• Native Servers

• Hardware Abstraction Libraries

Libraries

FreeType SSL

SQLite LibWebCore LibcSurface Manager

OpenGL|ES

Media Framework

Audio Manager …

Page 49: Android Anatomy

Hardware Abstraction Layer

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

ApplicationsHome Dialer

Contacts

SMS/MMS

Email

IM

Calendar

Browser

Media Player Photo Album

Camera

Clock

Calculator

…Voice Dial

Alarm

Android Runtime

Dalvik Virtual Machine

Core Libraries

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

Libraries

FreeType SSL

SQLite WebKit LibcSurface Manager

OpenGL|ES

Media Framework

Audio Manager …

Hardware Abstraction Layer

Graphics Audio Camera Bluetooth GPS Radio (RIL) WiFi …

Page 50: Android Anatomy

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 …

Page 51: Android Anatomy

Hardware Abstraction LibrariesWhy 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 …

Page 52: Android Anatomy

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 …

Page 53: Android Anatomy

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 …

Page 54: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Android Runtime

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 55: Android Anatomy

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Android Anatomy

Android Runtime

Dalvik Virtual Machine

Core Libraries

FreeType

SGL SSL

SQLite

WebKit

Libc

Surface Manager

OpenGL|ES

Media Framework

Libraries

Page 56: Android Anatomy

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

Dalvik Virtual Machine

Core Libraries

Page 57: Android Anatomy

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

Dalvik Virtual Machine

Core Libraries

Page 58: Android Anatomy

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

Dalvik Virtual Machine

Core Libraries

Page 59: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Android Runtime

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 60: Android Anatomy

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Android Anatomy

Libraries

FreeType

SGL SSL

SQLite

WebKit

Libc

Surface Manager

OpenGL|ES

Media Framework

Android Runtime

Dalvik Virtual Machine

Core Libraries

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

Page 61: Android Anatomy

• Services that are essential to the Android platform

• Behind the scenes - applications typically donʼt access them directly

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

Core Platform Services

Page 62: Android Anatomy

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

• Activity ManagerCore Platform Services

Page 63: Android Anatomy

• Activity Manager

• Package Manager

Core Platform Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 64: Android Anatomy

• Activity Manager

• Package Manager

• Window Manager

Core Platform Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 65: Android Anatomy

• Activity Manager

• Package Manager

• Window Manager

• Resource Manager

Core Platform Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 66: Android Anatomy

• Activity Manager

• Package Manager

• Window Manager

• Resource Manager

• Content Providers

Core Platform Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 67: Android Anatomy

• Activity Manager

• Package Manager

• Window Manager

• Resource Manager

• Content Providers

• View System

Core Platform Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 68: Android Anatomy

• Provide access to lower-level hardware APIsHardware Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 69: Android Anatomy

• Provide access to lower-level hardware APIs

• Typically accessed through local Manager object

LocationManager lm = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);

Hardware Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 70: Android Anatomy

• Telephony ServiceHardware Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 71: Android Anatomy

• Telephony Service

• Location Service

Hardware Services

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Page 72: Android Anatomy

• Telephony Service

• Location Service

• Bluetooth Service

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Hardware Services

Page 73: Android Anatomy

• Telephony Service

• Location Service

• Bluetooth Service

• WiFi Service

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Hardware Services

Page 74: Android Anatomy

• Telephony Service

• Location Service

• Bluetooth Service

• WiFi Service

• USB Service

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Hardware Services

Page 75: Android Anatomy

• Telephony Service

• Location Service

• Bluetooth Service

• WiFi Service

• USB Service

• Sensor Service

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Hardware Services

Page 76: Android Anatomy

More Information

• At Google I/O

• “Inside the Android Application Framework”

• Online

• http://code.google.com/android

Application FrameworkView

System Content Providers

Resource Manager

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager …

Application Framework

Page 77: Android Anatomy

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Android AnatomyApplications

Home Dialer

Contacts

SMS/MMS

Email

IM

Calendar

Browser

Media Player Albums

Camera

Clock

Calculator

…Voice Dial

Alarm

Android Runtime

Dalvik Virtual Machine

Core Libraries

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

FreeType

SGL SSL

SQLite

WebKit

Libc

Surface Manager

OpenGL|ES

Media Framework

Libraries

Page 78: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 79: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Application Framework

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 80: Android Anatomy

Runtime WalkthroughIt 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

Page 81: Android Anatomy

Runtime WalkthroughInit 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

Page 82: Android Anatomy

Runtime WalkthroughInit 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

Page 83: Android Anatomy

Runtime WalkthroughInit 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

Page 84: Android Anatomy

Runtime WalkthroughRuntime process sends request for Zygote to start System Service

runtime

Service Manager

usbdadbddebuggerddaemons

Init

Zygote

Page 85: Android Anatomy

Runtime WalkthroughRuntime 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 Dalvik VMusbdadbddebuggerddaemons

System Server

runtime

Service Manager

Init

Page 86: Android Anatomy

Runtime WalkthroughSystem Service starts the native system servers, including:

• Surface Flinger

• Audio Flinger

usbdadbddebuggerddaemons Zygoteruntime

Service Manager

Dalvik VM

System Server

Init

Surface Flinger

Audio Flinger

Page 87: Android Anatomy

Runtime WalkthroughNative system servers register with Service Manager as IPC service targets:

Zygoteruntime

Service Manager

usbdadbddebuggerddaemons

Init

Dalvik VM

System Server

Surface Flinger

Audio Flinger

Page 88: Android Anatomy

Runtime WalkthroughSystem Service starts the Android managed services:

usbdadbddebuggerddaemons Zygoteruntime

Service Manager

Dalvik VM

System Server

Init

Window Manager

Activity Manager

Package Manager

Power Manager …

Content Manager

Telephony Service

Bluetooth Service

Connectivity Service

Location Manager

Camera ServiceSurface

Flinger

Page 89: Android Anatomy

Runtime WalkthroughAndroid managed Services register with Service Manager:

usbdadbddebuggerddaemons

Camera Service

Zygoteruntime

Service Manager

Dalvik VM

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

Page 90: Android Anatomy

Runtime Walkthrough

usbdadbddebuggerddaemons Zygoteruntime

Service Manager

Dalvik VM

System Server

Init

Power ManagerActivity

Manager

Camera ServiceSurface

Flinger

Page 91: Android Anatomy

Runtime WalkthroughAfter system server loads all services, the system is ready…

Init System Server

Surface FlingerAudio Flinger

Dalvik VM

Window Manager

Activity ManagerPackage Manager

Init

Daemon Processes

usbdadbddebuggerddaemons

runtime

runtime

Zygote

Zygote

Page 92: Android Anatomy

Runtime WalkthroughAfter system server loads all services, the system is ready…

Init

Init

Daemon Processes

usbdadbddebuggerddaemons

runtime

runtime

Zygote

Zygote

Home

Dalvik VM

Home

System Server

Surface FlingerAudio Flinger

Dalvik VM

Window Manager

Activity ManagerPackage Manager

Page 93: Android Anatomy

Runtime WalkthroughAfter system server loads all services, the system is ready…

Init

Init

Daemon Processes

usbdadbddebuggerddaemons

runtime

runtime

Zygote

Zygote

Home

Dalvik VM

Home

libc libc libc libc libc

System Server

Surface FlingerAudio Flinger

Dalvik VM

Window Manager

Activity ManagerPackage Manager

libc

Page 94: Android Anatomy

Runtime WalkthroughEach subsequent application is launched in itʼs own process

System Server

Surface FlingerAudio Flinger

Dalvik VM

Window Manager

Activity ManagerPackage Manager

libc

Daemon Processes

usbdadbddebuggerddaemons

runtime

runtime

Zygote

Zygote

Home

Dalvik VM

Home

libc libc libc libc

Contacts

Dalvik VM

Contacts

libc

Page 95: Android Anatomy

Agenda

• Android Anatomy

• Linux Kernel

• Native Libraries

• Framework Services

• Android Physiology

• Start-up Walkthrough

• Layer Interaction

Page 96: Android Anatomy

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

Page 97: Android Anatomy

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

Page 98: Android Anatomy

Libraries

Linux Kernel

Applications

Application Framework

Android Runtime ServicesBinder IPC

Application

Runtime Service

Kernel Driver

Page 99: Android Anatomy

Libraries

Applications

Application Framework

JNI

Android Runtime ServicesBinder IPC

Application

Runtime Service

Native Service Binding

Linux Kernel

Kernel Driver

Page 100: Android Anatomy

Libraries

Linux Kernel

Applications

Application Framework

JNI

Android Runtime ServicesBinder IPC

Dynamic load

Application

Runtime Service

Native Service Binding

HAL Library

Kernel Driver

Page 101: Android Anatomy

Libraries

Linux Kernel

Applications

Application Framework

JNI

Android Runtime ServicesBinder IPC

Dynamic load

Application

Runtime Service

Native Service Binding

HAL Library

Kernel Driver

Page 102: Android Anatomy

Libraries

Linux Kernel

Applications

Application Framework

JNI

Example: Location Manager

Dynamic load

Location Manager Service

GpsLocationProvider

libgps.so

GpsLocationProvider

Binder IPCApplication

Kernel Driver

Page 103: Android Anatomy

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

Page 104: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native ServicesApplication

Runtime Service

Native Service Binding

Page 105: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native ServicesApplication

Runtime Service

Native Service Binding Native Service

Binder IPC

Page 106: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native ServicesApplication

Runtime Service

Native Service Binding

HAL Library

Native ServiceBinder IPC

Dynamic load

Page 107: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native ServicesApplication

Runtime Service

Native Service Binding

HAL Library

Kernel Driver

Native ServiceBinder IPC

Dynamic load

Page 108: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native Services

Dynamic load

Application

MediaPlayer

MediaPlayer

libaudio.so

Kernel Driver

AudioFlingerBinder IPC

Media Framework

Page 109: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native Services

Dynamic load

Application

MediaPlayer

MediaPlayer

libaudio.so

AudioFlingerBinder IPC

Media Framework

ALSA

Kernel Driver

Page 110: Android Anatomy

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Android Native Services

Dynamic load

Application

MediaPlayer

MediaPlayer

libaudio.so

AudioFlingerBinder IPC

Media Framework

Proprietary Audio Driver

Page 111: Android Anatomy

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

Page 112: Android Anatomy

Daemon Connection

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Application

Runtime Service

Native Service Binding

Kernel Driver

Page 113: Android Anatomy

Daemon Connection

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Application

Runtime Service

Native Service Binding

Kernel Driver

Daemonsockets

Page 114: Android Anatomy

Daemon Connection

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Dynamic load

Application

Runtime Service

Native Service Binding

HAL Library

Kernel Driver

Daemonsockets

Page 115: Android Anatomy

Daemon Connection

Libraries

Linux Kernel

Applications

ApplicationFramework

JNI

Dynamic load

Application

Telephony Manager

Telephony Manager

libril.so

Kernel Driver

rildsockets

Page 116: Android Anatomy

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

Page 117: Android Anatomy

Linux KernelDisplay Driver Camera Driver Bluetooth Driver Shared Memory

Driver Binder (IPC) Driver

PowerManagementUSB Driver Keypad Driver WiFi Driver Audio

Drivers

Android AnatomyApplications

Home Dialer

Contacts

SMS/MMS

Email

IM

Calendar

Browser

Media Player Albums

Camera

Clock

Calculator

…Voice Dial

Alarm

Android Runtime

Dalvik Virtual Machine

Core Libraries

Application FrameworkView

System Content Providers

Resource Manager …

Activity Manager

Package Manager

WindowManager

NotificationManager

LocationManager

TelephonyManager

FreeType

SGL SSL

SQLite

WebKit

Libc

Surface Manager

OpenGL|ES

Media Framework

Libraries

Page 118: Android Anatomy

The End

code.google.com

Page 119: Android Anatomy

Questions

Q&A