Upload
marakana-inc
View
4.793
Download
5
Tags:
Embed Size (px)
DESCRIPTION
Presented at Android Builders Summit on February 14th in Redwood Shores, CA by Aleksandar (Saša) Gargenta, from Marakana Inc.For the complete slides from this talk go to http://mrkn.co/munz7"The most interesting part of Android stack are the Android System Services. The 60+ such services expose the low level functionality, such as Power Management, Wifi, Camera, Sensors, GPS, Display, Audio, Media, and so on, all the hardware all the way up to the application layer. While each one is different, the all have certain similarities, namely the way they rely on Binder (Android's IPC mechanism), use JNI to cross Java-C boundary, and use of shared libraries to abstract the Linux drivers. In this talk, we'll explore the common system services in Android and discuss their architecture. You will get to see the diagrams of the inner workings of some of the previously undocumented parts of the Android stack. By the end of the talk, you should have a better understanding of the underpinnings of the backbone of Android OS."https://events.linuxfoundation.org/events/android-builders-summit/gargentaa
Citation preview
Android Services Black Magicby Aleksandar (Saša) Gargenta, Marakana Inc.
Android Builders SummitFebruary 14th, 2012
Redwood Shores, CA
Screencast @http://mrkn.co/munz7
About
Aleksandar (Saša) Gargenta• Developer and instructor of Android Internals and Security training at Marakana• Founder and co-organizer of San Francisco Android User Group (sfandroid.org)• Founder and co-organizer of San Francisco Java User Group (sfjava.org)• Co-founder and co-organizer of San Francisco HTML5 User Group (sfhtml5.org)• Speaker at AnDevCon, AndroidOpen, Android Builders Summit, etc.• Server-side Java and Linux, since 1997• Android/embedded Java and Linux, since 2009• Worked on SMS, WAP Push, MMS, OTA provisioning in previous life• @agargenta on Twitter• [email protected] on Google+
Marakana - Helping people get better at what they do• Training on cutting edge open source software (like Android!)• Rockstar team of experts, on staff• Content is king• http://marakana.com/
Native Layer
Linux Kernel
Application Framework
Applications
Home Contacts Phone Browser
Activity Service
Window Service
ContentProviders
Vibrator Service
PackageService
TelephonyService
Resource Manager
LocationService
NotificationService
Surface Flinger
OpenGL
libwifi
Media Framework
vold
libcamera
SSL
WebKit
libc
Android Runtime
Core Libs
Dalvik VM
DisplayDriver
KeypadDriver
CameraDriver
WiFiDriver
GPSDriver
AudioDriver
BinderDriver
PowerMgmt
SQLite
netd
libgps
WiFiService
BatteryService
Android Stack
Kernel
system_server
DalvikVM
com.example.app (/data/app/ExampleApp.apk)
DalvikVM
/system/framework/framework.jar
android.os.Vibrator
android.os.IVibratorService.Stub.Proxy
/dev/binder /sys/class/timed_output/vibrator/enable
/system/framework/framework.jar
android.os.IVibratorService.Stub
/system/lib/libhardware_legacy.sovibrator.c
/system/lib/libandroid_servers.so
com_android_server_VibratorService.cpp
/system/framework/services.jar
com.android.server.VibratorService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex
com.example.app.ExampleActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"vib
rato
r" se
rvic
e vi
a SM
registers as binder context manager
refe
renc
es
calls
uses
(cal
ls)
uses
(io
writ
e)ex
tend
sca
llsca
lls/li
nks
to
crea
tes
regi
ster
s "v
ibra
tor"
serv
ice
via
Serv
iceM
anag
er
refe
renc
esin
voke
s tra
nsac
tion
Vibrator on Android
gets a reference to the ServiceManager (handle=0)
Power on Android
Kernel
system_server
DalvikVM
com.example.app (/data/app/ExampleApp.apk)
DalvikVM
/system/framework/framework.jar
android.os.PowerManager
android.os.IPowerManager.Stub.Proxy
/dev/binder /sys/power/wake_lock
/system/framework/framework.jarandroid.os.IPowerManager.Stub
/system/lib/libhardware_legacy.sopower.c
/system/lib/libandroid_runtime.so
android_os_Power.cpp
/system/framework/services.jar
com.android.server.PowerManagerService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex
com.example.app.ExampleActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"pow
er" s
ervi
ce v
ia S
M
registers as binder context manager
refe
renc
es
crea
tes
uses
(cal
ls)
uses
(io
writ
e)ex
tend
sca
llsca
lls/li
nks
to
crea
tes
regi
ster
s "p
ower
" ser
vice
via
Ser
vice
Man
ager
refe
renc
esin
voke
s
android.os.PowerManager.WakeLockcalls
android.os.Power
calls
gets a reference to the ServiceManager (handle=0)
Alarm on Android
Kernel
system_server
DalvikVM
com.android.deskclock (/system/app/DeskClock.apk)
DalvikVM
/system/framework/framework.jar
android.app.AlarmManager
android.app.IAlarmManager.Stub.Proxy
/dev/binder /dev/alarm
/system/framework/framework.jarandroid.app.IAlarmManager.Stub
/system/lib/libandroid_servers.so
com_android_server_AlarmManagerService.cpp
/system/framework/services.jar
.AlarmManagerService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex
com.android.deskclock.AlarmClock
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)lo
oks
up "a
larm
" ser
vice
via
SM
registers as binder context manager
refe
renc
es
uses
(cal
ls)
uses
(ioc
tl)ex
tend
sca
lls/li
nks
to
crea
tes
regi
ster
s "a
larm
" ser
vice
via
Ser
vice
Man
ager
refe
renc
esin
voke
s
gets a reference to the ServiceManager (handle=0)
com.android.deskclock.Alarms
calls
android.app.ContextImpl
uses
calls
Kernel
system_server
DalvikVM
com.android.packageinstaller(/system/app/PackageInstaller.apk)
DalvikVM
/system/framework/framework.jarandroid.content.pm.PackageManager
android.content.pm.IPackageManager.Stub.Proxy
/dev/binder
/system/framework/framework.jar
android.content.pm.IPackageManager.Stub
/system/framework/services.jar
com.android.server.pm.PackageManagerService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex.PackageInstallerActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"pac
kage
" ser
vice
via
SM
registers as binder context manager
refe
renc
es
calls
uses
(cal
ls)
exte
nds
crea
tes
regi
ster
s "p
acka
ge" s
ervi
ce v
ia S
Mre
fere
nces
invo
kes
trans
actio
n
Package Manager on Android
gets a reference to the ServiceManager (handle=0)
.InstallAppProgress
calls
android.app.ApplicationPackageManager
exte
nds
com.android.server.pm.Installer
installdinstalld.c
/dev/socket/installd
calls
send
mes
sage
s
get messages
WiFi Management on Androidcom.example.app (/data/app/ExampleApp.apk)
Kernel
system_serverDalvikVMDalvikVM
/system/framework/framework.jar
android.net.wifi.WifiManager
android.net.wifi.IWifiManager.Stub.Proxy
/dev/binder
/system/framework/framework.jar
android.net.wifi.IWifiManager.Stub
/system/lib/libhardware_legacy.sowifi.c
/system/lib/libandroid_servers.soandroid_net_wifi_Wifi.cpp
/system/framework/services.jar
com.android.server.WifiService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex
com.example.app.ExampleActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/lib*.soservice_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"wifi
" ser
vice
via
SM
registers as binder context manager
refe
renc
es
calls
uses
(cal
ls)
exte
nds
calls
calls
/link
s to
creates
regi
ster
s "w
ifi" s
ervi
ce v
ia S
Mre
fere
nces
invo
kes
android.net.wifi.WifiNative
android.net.wifi.WifiStateMachine
/dev/socket/wpa_wlan0
/system/lib/libwpa_client.sowpa_ctrl.c
wpa_supplicant
calls
calls
bcmdhd
send
s co
mm
ands
read commandscalls (ioctl)as nl80211
calls
Location on Android
Kernel
system_server
DalvikVM
com.example.app (/data/app/ExampleApp.apk)
DalvikVM
/system/framework/framework.jar
android.location.LocationManager
.LocationManager.Stub.Proxy
/dev/binder /dev/ttyo0
/system/framework/framework.jar
.LocationManager.Stub
/vendor/lib/hw/gps.omap4.soimpl of include/hardware/gps.h
/system/lib/libandroid_servers.so_location_GpsLocationProvider.cpp
/system/framework/services.jar
.LocationManagerService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex
com.example.app.ExampleActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"loc
atio
n" s
ervi
ce v
ia S
M
registers as binder context manager
refe
renc
es
calls
uses
(cal
ls)
uses
(io)
load
sca
lls
regi
ster
s "lo
catio
n" s
ervi
ce v
ia S
Mre
fere
nces
invo
kes
.location.GpsLocationProvider
crea
tes
calls
/system/lib/libhardware.so
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
exte
nds
links
toca
lls
mediaserver
Audio Policy on Android
Kernel
system_serverDalvikVM
com.example.app (/data/app/ExampleApp.apk)
DalvikVM
/system/framework/framework.jar
android.media.AudioManager
android.media.IAudioService.Stub.Proxy
/dev/binder /dev/snd/controlC0 (ALSA)
/system/framework/framework.jar
android.media.IAudioService.Stub
/system/lib/libmedia.soandroid.AudioSystem
/system/lib/libandroid_runtime.soandroid_media_AudioSystem.cpp
/system/framework/services.jar
android.media.AudioService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex
com.example.app.ExampleActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
calls
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"aud
io" s
ervi
ce v
ia S
M
registers as binder context managerreferences
calls
uses
(cal
ls)
uses
(ioc
tl)ex
tend
sca
llslin
ks to
/cal
lscrea
tes
regi
ster
s "a
udio
" ser
vice
via
SM
refe
renc
esin
voke
s
android.media.AudioSystem calls
/system/lib/hw/audio_policy.default.soandroid_audio_legacy.AudioPolicyManagerDefault
/system/lib/hw/audio.primary.tuna.soaudio_hw.c
/system/lib/libtinyalsa.so mixer.c ca
llsca
lls
android.BpAudioPolicyService
/system/lib/libaudioflinger.soandroid.AudioPolicyService
/system/lib/libmedia.soandroid.BnAudioPolicyService
calls
calls
exte
nds
calls
looks up "media.audio_policy"
Audio Playback on Android
Kernel
mediaservercom.ex.app (/data/app/ExampleApp.apk)DalvikVM
/system/framework/framework.jarandroid.media.MediaPlayer
/dev/binder /dev/snd/pcmC0D0p (ALSA)
/system/lib/hw/audio.primary.tuna.soaudio_hw.c
/system/lib/libstagefright.so.AwesomePlayer
/system/bin/servicemanager
classes.dexcom.ex.app.ExampleActivity
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
/system/lib/libmedia_jni.soandroid_media_MediaPlayer.cpp
/system/lib/libmedia.soandroid.BpMediaPlayer
/system/lib/libmedia.soandroid.BnMediaPlayerService
/system/lib/libmediaplayerservice.soandroid.MediaPlayerService
android.MediaPlayerService.Client
android.BpMediaPlayerService
android.BnMediaPlayer
android.StagefrightPlayer
.MediaPlayerService.AudioOutput
.MP3Extractor
.MP3Source
.OMXCodec
.AudioPlayer
.AudioTrack
/system/lib/hw/audio_policy.default.soandroid_audio_legacy.AudioPolicyManagerDefault
/system/lib/libtinyalsa.sopcm.c
/system/lib/libaudioflinger.so.AudioFlinger
/system/lib/libstagefrighthw.soandroid.TIOMXPlugin
.AudioSystem
/system/lib/libstagefright_soft_mp3dec.soandroid.SoftMP3
.AudioPolicyService
.MediaSource
/system/lib/libOMX_Core.so
OMX_Core.c
/dev/snd/controlC0 (ALSA)
Telephony on Android
rild
PhoneApp (/system/app/Phone.apk)
Kernel
DalvikVM
/system/framework/framework.jar
com.android.internal.telephony.CallManager
classes.dex
PhoneUtils
com.android.internal.telephony.Phone
com.android.internal.telephony.gsm.GSMPhone
RIL
RILSender RILReceiver
Socket messages Socket messages
/dev/ttys0
calls
implements
system_server
DalvikVM
GsmCallTracker
Audio drivers
CallController
CallController
/dev/socket/rild
/vendor/lib/libsec-ril.so
/system/lib/libril.so
rild.c
/system/lib/libsecril-client.so
Sock
et m
essa
ges ca
lls
uses
useslo
ads
calls
android.media.AudioManagercalls
/system/framework/framework.jarandroid.media.AudioServiceuses
Kernel
system_server
DalvikVM
com.example.enterpriseapp(/data/app/EnterpriseApp.apk)
DalvikVM
/system/framework/framework.jarandroid.app.admin.DevicePolicyManager
android.app.admin.DevicePolicyManager.Stub.Proxy
/dev/binder
/system/framework/framework.jarandroid.app.admin.DevicePolicyManager.Stub
/system/framework/services.jar
com.android.server.DevicePolicyManagerService
com.android.server.SystemServer
/system/bin/servicemanager
classes.dex.ExampleActivity
/system/lib/libandroid_runtime.so
/system/lib/libbinder.so
/system/lib/lib*.so
/system/lib/lib*.so
service_manager.c
/system/lib/lib*.so
gets
a re
fere
nce
to th
e Se
rvic
eMan
ager
(han
dle=
0)
look
s up
"dev
ice_
polic
y" s
ervi
ce v
ia S
M
registers as binder context manager
refe
renc
es
calls
uses
(cal
ls)
exte
nds
crea
tes
regi
ster
s "d
evic
e_po
licy"
ser
vice
via
SM
refe
renc
esin
voke
s tra
nsac
tion
DevicePolicy on Android
gets a reference to the ServiceManager (handle=0)
calls android.os.RecoverySystem
recoveryrecovery.c
/cache/recovery/command
calls
calls
read
s
com.android.server.PowerManagerService
android.os.PowerManager
com.android.internal.app.ShutdownThread
android.os.Power
/system/lib/libandroid_runtime.soandroid_os_Power.cpp
calls
calls
calls
writ
es
links
to/c
alls
rebo
ot
/dev/block/platform/omap/omap_hsmmc.0/by-name/userdata erasesformats
Thank You
@agargenta on [email protected] on G+
For the complete screencast of this presentation go tohttp://mrkn.co/munz7