3. 3
• Open source attracts talent across the world.
• Apache license protects OEM’s business.
• Easy to use language and stable API improve
developer’s interest.
• Compatibility protects
Android’s Integrity.
• Rich Apps inspire
users’ interesting.
• GMS and data protect
Google’s interest.
Ecosystem
10. 10
Android Architecture
• Application
• SDK & NDK
• Framework & Runtime
• Hal
Application
SDK interface layer
Framework, Runtime and Libraries
Hal interface layer
HAL
Kernel
IPC
IPC
11. 11
SDK & NDK
• SDK API
Android.*
Dalvik.*
Java.*
Javax.*
• Soft API
Permissions
Build Parameters
Intent
• NDK
libaaudio.so, libandroid.so, libz, JNI interface, libc,
libcamera2ndk.so, libdl, libEGL.so, libGLESv2.so, libGLESv3.so,
libicuuc.so, libjnigraphics.so, libm.so, libRS.so, libstdc++,
libvulkan.so …
SDK interface layer
Framework
Application
SDK interface layer
Application
IPC IPC
Client
Sever Function service Function service
12. 12
Android Architecture
• Application
• SDK & NDK
• Framework & Runtime
• Hal
Application
SDK interface layer
Framework, Runtime and Libraries
Hal interface layer
HAL
Kernel
IPC
IPC
13. 13
Framework – Type of Services
Service Type Example Process Function Crash
recovery
System Java
Services
AMS/PMS/UMS/W
MS/DMS/CMS/LMS
/…
SystemServer Provide critical
system services
Restart by
system
System Native
Services
MediaServer/Rild/A
udioflinger/surfacefli
nger/logd/adbd/deb
uggerd/..
Dedicated
process
Provide critical
system services
Restart by
system
APK Services KeyGuardServices Dedicated
process
Provide
application level
services
Restart by
app itself.
14. 14
System Services Register and Query
Running in different
processes
ServiceManager
AMS UMS PMS WMS
DMS CMS LMS ...
adbd debuggerd rild logd
mediaserv
er
surfaceflin
ger
audiofling
er
Native service Daemons
Java system services
Client
Components
1 AddService(IPC)
2 getService(IPC)
3 Call the service
provied by UMS
Running in system
server process
15. 15
APK1
Client
Components
2 Send Intent to
start or bind a
service
APK2
ServiceRecor
d List
PackageManager
Service
SystemServer
3 Call the service
provied by APK1
APK services Register and Query
APK will define some
filter to declare which
intent its services will
proceed.
1 PMS will parser all
APK when it is
installed or system
boot time to get
services information
APK will define some
filter to declare which
intent its services will
proceed.
PMS will be
responsible for start
APK1 if APK1 is not
started
16. 16
Bionic
• Developed by Google
• BSD license
• Faster and smaller
• No compatibility with GUN libc
• Special function for Android, such as getprop
17. 17
DALVIK vs ART
• Installation Time
• Storage Usage
• Performance
• Battery
18. 18
Memory –Native Allocator
Application
System Runtime
System Kernel
Memory Allocator
Process Virtual Address Space Map Area Heap Area
malloc/calloc/realloc
Unit Unit
Unit Unit
brk/sbrkmmap/munmap
free
20. 20
From Java Method to Native Method
Function type
info is stored in
Dex/OAT file
21. 21
Process and Thread
Java APK NDK APK
zygote Java process
Native
Daemon
Framework
App
·
Thread
·
Thread
·
·
·
Fork
Process ProcessProcessProcess
Fork
Process
22. 22
System Boot up
Will parser init.rc to
start all daemons
and zygote
Partitions will be
mounted and verified
one by one
Init process creates
daemons according
to some stages: init-
>boot->fs->data
23. 23
Init
Fork
Start Linker
Load ELF and
depended lib
Zygote Process
Create
Heap
Init Art Vm in
libart.so
Create
Threads
Start Jit
Start GC Preload classes
Preload drawable
resource
Preload libraries
Enter loop to wait
for incoming
request
Fork request to
start system server
Split heap into two
heaps named
zygote and active
Start First Java Process - Zygote
Create one heap
named zygote using
Ashmem
First fork request will trigger
the heap split action to
improve GC performance
3000+ class and 400+
drawable will be loaded
in zygote so that they
can be shared across
all java processes
Create GC and other
threads
24. 24
Android Architecture
• Application
• SDK & NDK
• Framework & Runtime
• Hal
Application
SDK interface layer
Framework, Runtime and Libraries
Hal interface layer
HAL
Kernel
IPC
IPC