android internals

23
Android Internals Android Montreal – November 3 rd 2010 Karim Yaghmour / @karimyaghmour

Upload: opersys-inc

Post on 22-May-2015

29.871 views

Category:

Technology


3 download

DESCRIPTION

Android Internals talk given ad Android Montreal on Nov. 3rd 2010 by Karim Yaghmour (author of O'Reilly's "Building Embedded Linux Systems.")

TRANSCRIPT

Page 1: Android Internals

Android Internals

Android Montreal – November 3rd 2010

Karim Yaghmour / @karimyaghmour

Page 2: Android Internals

● Overall Architecture● System startup● Linux Kernel● Hardware Support● Native User-Space● Dalvik● JNI● System Server

● Activity Manager● Binder● Stock Android Apps● Hacking

Page 3: Android Internals

Overall Architecture

Page 4: Android Internals

Arch vs. ToolsSDK, Eclipse, .apk

Manifest: Perms / SDK ver.

.dex, ddms

NDK, rootfs, initrc, adb

GNU toolchain

(fastboot)

Page 5: Android Internals

System Startup

● Bootloader● Kernel● Init● Zygote● System Server● Activity Manager● Launcher (Home)

Page 6: Android Internals

Startup - Bootloader

● CPU fetches first instruction from bootloader● Bootloader boots kernel from flash:

0x000003860000­0x000003900000 : "misc"0x000003900000­0x000003e00000 : "recovery"0x000003e00000­0x000004300000 : "boot"0x000004300000­0x00000c300000 : "system"0x00000c300000­0x0000183c0000 : "userdata"0x0000183c0000­0x00001dd20000 : "cache"0x00001dd20000­0x00001df20000 : "kpanic"0x00001df20000­0x00001df60000 : "dinfo"0x00001df60000­0x00001dfc0000 : "setupdata"0x00001dfc0000­0x00001e040000 : "splash1"0x000000300000­0x000001680000 : "modem"

From Acer Liquid-E

Kernel/system/data/cache

Page 7: Android Internals

Startup - Kernel

● Core kernel initialization● Device drivers initialization● Root filesystem mounting● Execution of “/init”

Page 8: Android Internals

Startup - Init

● Open, parses, and runs /init.rc:● Create mountpoints and mount filesystems● Set up filesystem permissions● Set OOM adjustments properties● Start daemons:

– adbd

– servicemanager (binder)

– vold

– netd

– rild

– app_process -Xzygote (Zygote)

– mediaserver

– ...

Page 9: Android Internals

Startup – Zygote, etc.● app_main:

● runtime.start(“com.android.internal.os.Zygote”, ...)

– startVM()– Call Zygote's main()

● preloadClasses()● startSystemServer()● ... magic ...● Call SystemServer's run()

– Start all system services/managers– Start ActivityManager:

● Send Intent.CATEGORY_HOME● Launcher2 kicks in

Page 10: Android Internals

Linux Kernel – Generic Features

Page 11: Android Internals

Linux Kernel - Androidisms

● Wakelocks● lowmem handler● Binder● RAM console● Logger● ...

Page 12: Android Internals

Hardware SupportGPS

Display

Lights

KeyboardButtonsBatteryNotificationsAttention

AudioCameraPower ManagementSensors

AccelerometerMagnetic FieldOrientationGyroscopeLightPressureTemperatureProximity

Radio Layer Interface

Bluetooth BlueZ through D-BUS IPC (to avoid GPL contamination it seems)Manufacturer-provided libgps.so

Wifi wpa_supplicantStd framebuffer driver (/dev/fb0)

Keymaps and Keyboards Std input event (/dev/event0)Manufacturer-provided liblights.so

Backlight

Manufacturer-provided libaudio.so (could use ALSA underneath ... at least as illustrated in their porting guide)Manufacturer-provided libcamera.so (could use V4L2 kernel driver underneath ... again as illustrated in porting guide)“Wakelocks” kernel patchManufacturer-provided libsensors.so

Manufacturer-provided libril-<companyname>-<RIL version>.so

Page 13: Android Internals

Native User-Space

● Rootfs:● /system● /data

● Libs:

Bionic, SQLite, SSL, OpenGL|ES,

Non-Posix: limited Pthreads support, no SysV IPC● Toolbox● Daemons:

vold, rild, netd, adbd, ...

Page 14: Android Internals

Dalvik● Sun-Java =

Java language + JVM + JDK libs● Android Java =

Java language + Dalvik + Apache Harmony● Target:

● Slow CPU● Relatively low RAM● OS without swap space● Battery powered

● Now has JIT

Page 15: Android Internals

Dalvik's .dex files

● JVM munches on “.class” files● Dalvik munches on “.dex” files● .dex file = .class files post-processed by “dx”

utility● Uncompressed .dex = 0.5 * Uncompressed .jar

Page 16: Android Internals

JNI – Java Native Interface

● Call gate for other languages, such as C, C++● Equivalent to .NET's pinvoke● Usage: include and call native code from App● Tools = NDK ... samples included● Check out “JNI Programmer's Guide and

Specification” - freely available PDF

Page 17: Android Internals

System Server

Entropy Service Device Policy Audio ServicePower Manager Status Bar Headset ObserverActivity Manager Clipboard Service Dock ObserverTelephone Registry Input Method Service UI Mode Manager ServicePackage Manager Backup ServiceAccount ManagerContent Manager Connectivity Service Recognition ServiceSystem Content Providers Throttle Service Status Bar IconsBattery Service Accessibility ManagerLights Service Mount Service ADB Settings ObserverVibrator Service Notification ManagerAlarm Manager Device Storage Monitor

Location ManagerSensor Service Search ServiceWindow Manager

Wallpaper Service

NetStat ServiceNetworkManagement Service AppWidget Service

DiskStats Service

Init Watchdog

DropBox ServiceBluetooth Service

Page 18: Android Internals

Activity Manager

● Start new Activities, Services● Fetch Content Providers● Intent broadcasting● OOM adj. maintenance● Application Not Responding● Ex. starting new app from Launcher:

onClick(Launcher)->startActivity(Activity.java)->Binder->ActivityManagerService->startViaZygote(Process.java)->Socket->Zygote

Page 19: Android Internals

Binder

● CORBA/COM-like IPC● Data sent through “parcels” in “transactions”● Kernel-supported mechanism● Check /proc/binder/*

Page 20: Android Internals

Stock Android Apps – from AOSP

/packages/apps /packages/providers

Launcher2

MusicBrowserCalculatorCalendar ProvisionCamera

SettingsContacts

EmailGallery

/packages/inputmethods

AccountsAndSettings ApplicationProvider LatinIMEAlarmClock Mms CalendarProvider OpenWnnBluetooth ContactsProvider PinyinIME

PackageInstaller DownloadProviderProtips DrmProvider

GoogleContactsProviderQuickSearchBox MediaProvider

CertInstaller TelephonyProviderSoundRecorder UserDictionaryProvider

DeskClock SpeechRecorderStkVoiceDialer

HTMLViewer

Page 21: Android Internals

Hacking

● Source:● AOSP -- source.android.com / android.git.kernel.org● Cyanogenmod -- www.cyanogenmod.com● Moders sites ... aplenty ...

● Tools:● repo / git● fastboot● recovery● Kernel privilege escalation exploits -- “one-click root”● ...

Page 22: Android Internals

AOSP contents

bionic C library replacement

build Build systemCompatibility Test Suite

development Development toolsdevice Device-specific files and componentsexternal Copy of external projects used by AOSPframeworkshardware

Apache HarmonyThe NDK

packages Stock Android apps, providers, etc.

The SDKsystem

bootable Reference bootloader

ctsdalvik Dalvik VM

System services, android.*, Android-related cmds, etc.Hardware support libs

libcorendk

prebuilt Prebuilt binariessdk

pieces of the world that are the core of the embedded linux platform at the heart of Android.

Page 23: Android Internals

Thank you ...

[email protected]