SlideShare a Scribd company logo
1 of 25
Download to read offline
Understanding the Android
     System Server

     AnDevCon – March 9th 2011

  Karim Yaghmour / @karimyaghmour
About ...
●   Author of:




●   Introduced Linux Trace Toolkit in 1999
●   Originated Adeos and relayfs (kernel/relay.c)
1. Architecture recap
2. Bootup sequence
3. Services run by the System Server
4. Observing the System Server in action
5. Binder
6. Calling on System Services
7. Inside a few System Services
8. Creating your own System Service
1. Architecture recap
2. Bootup sequence
●   Init:
    ●   app_process -Xzygote (Zygote)
●   frameworks/base/cmds/app_process/app_main.cpp:
    ●   runtime.start(“com.android.internal.os.Zygote”, ...
●   frameworks/base/core/jni/AndroidRuntime.cpp:
    ●   startVM()
    ●   Call Zygote's main()
●   frameworks/base/core/java/com/android/internal/os/Zy
    goteInit.java:
    ●   ...
●   preloadClasses()
    ●   startSystemServer()
    ●   ... magic ...
    ●   Call SystemServer's run()
●   frameworks/base/services/java/com/android/server
    /SystemServer.java:
    ●   Start all system services/managers
    ●   Start ActivityManager:
         –   Send Intent.CATEGORY_HOME
         –   Launcher2 kicks in
3. Services run by the System
                    Server
Entropy Service            Device Policy               Audio Service
Power Manager              Status Bar                  Headset Observer
Activity Manager           Clipboard Service           Dock Observer
Telephone Registry         Input Method Service        UI Mode Manager Service
Package Manager            NetStat Service             Backup Service
Account Manager            NetworkManagement Service   AppWidget Service
Content Manager            Connectivity Service        Recognition Service
System Content Providers   Throttle Service            Status Bar Icons
Battery Service            Accessibility Manager       DiskStats Service
Lights Service             Mount Service               ADB Settings Observer
Vibrator Service           Notification Manager
Alarm Manager              Device Storage Monitor
Init Watchdog              Location Manager
Sensor Service             Search Service
Window Manager             DropBox Service
Bluetooth Service          Wallpaper Service
3.1. Some stats
●   frameworks/base/services/java/com/android/ser
    ver:
    ●   3.5 M
    ●   ~100 files
    ●   85 kloc
●   Activity manager:
    ●   920K
    ●   30+ files
    ●   20 kloc
4. Observing the System Server in
                   action
 ●   Find the System Server's PID
          $ adb shell ps | grep system_server
          system 63 32 120160 35408 ffffffff afd0c738 S system_server
 ●   Look for its output:
          $ adb logcat | grep “63)”
...
D/PowerManagerService( 63): bootCompleted
I/TelephonyRegistry( 63): notifyServiceState: 0 home Android Android 310260 UMTS CSS not supp...
I/TelephonyRegistry( 63): notifyDataConnection: state=0 isDataConnectivityPossible=false reason=null
interfaceName=null networkType=3
I/SearchManagerService( 63): Building list of searchable activities
I/WifiService( 63): WifiService trying to setNumAllowed to 11 with persist set to true
I/ActivityManager( 63): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 ...
I/TelephonyRegistry( 63): notifyMessageWaitingChanged: false
I/TelephonyRegistry( 63): notifyCallForwardingChanged: false
I/TelephonyRegistry( 63): notifyDataConnection: state=1 isDataConnectivityPossible=true reason=simL...
I/TelephonyRegistry( 63): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=simL...
D/Tethering( 63): MasterInitialState.processMessage what=3
I/ActivityManager( 63): Start proc android.process.media for broadcast
com.android.providers.downloads/.DownloadReceiver: pid=223 uid=10002 gids={1015, 2001, 3003}
I/RecoverySystem( 63): No recovery log file
W/WindowManager( 63): App freeze timeout expired.
...
5. Binder
●   CORBA/COM-like IPC
●   Data sent through “parcels” in “transactions”
●   Kernel-supported mechanism
●   Check /proc/binder/*
●   android.* API connected to System Server
    through Binder.
6. Calling on System Services
●   Use getSystemServer
●   Ex: NotificationManager Object reference:
     String ns = Context.NOTIFICATION_SERVICE;
     NotificationManager mNotificationManager = (NotificationManager)
     getSystemServService(ns);

●   Prepare your content
●   Call on the object:
     mNotificationManager.notify(HELLO_ID, notification);
7. Inside a few System Services
●   Get the AOSP ... repo, etc.
●   Tricks:
    ●   Import into Eclipse and collapse methods
    ●   Use reverse-engineering tools:
        –   Imagix
        –   Rationale
        –   Lattix
        –   Scitools
        –   ...
●   Be patient, this isn't documented anywhere ...
7.1. ActivityManager
●   Start new Activities, Services
●   Fetch Content Providers
●   Intent broadcasting
●   OOM adj. maintenance
●   Application Not Responding
●   Permissions
●   Task management
●   Lifecycle management
●   Ex. starting new app from Launcher:
      ●   onClick(Launcher)
      ●   startActivity(Activity.java)
      ●   <Binder>
      ●   ActivityManagerService
      ●   startViaZygote(Process.java)
      ●   <Socket>
      ●   Zygote
7.2. Package Manager
●   10 kloc
●   450 K
●   Installation / removal
●   Permissions
●   Intent resolution (also IntentResolver.java)
●   Called by Activity Manager
7.3. Window Manager
●   Main thread
●   Window manipulation
●   Wallpaper handling
●   Orientation
●   Focus
●   Layering
●   Input event management
7.4. Notification Manager
●   Toasts
●   Notifications
●   Sound playback (see NotificationPlayer.java)
7.5. Power Manager
●   Wakelocks
●   Sleep
●   Brightness
●   Lock
7.6. Network Management Service
●   Talks to “netd” /system/netd
●   Interface configuration
●   Tethering
●   DNS
7.7. Mount Service
●   Mount / Unmount
●   Format
●   USB mass storage
●   OBB
7.8. Location Manager
●   Manage location providers
●   getBestProvider()
●   Proximity alerts
●   Last known location
7.9. Status Bar Manager
●   Expand / collapse
●   Icon visibility
●   Reveal callbacks
●   Callbacks for notification manager
7.10. Backup Manager
●   Enable / disable
●   Transport management
●   backupNow()
●   ...
8. Creating your own System
                    Service
●   Have new funky hardware?
●   Add your code to:
    frameworks/base/services/java/com/android/server/
●   Have the SystemServer.java init your service
●   Expose through:
    ●   frameworks/base/core/java/android/os/[server].aidl
●   Call on native “driver” code through JNI
●   Create an app that calls on service
●   May need to generate custom SDK ...
Thank you ...



karim.yaghmour@opersys.com




     www.opersys.com

More Related Content

What's hot

Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Opersys inc.
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time OptimizationKan-Ru Chen
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for LinuxYu-Hsin Hung
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debuggingAshish Agrawal
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia FrameworkOpersys inc.
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia FrameworkPicker Weng
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverNanik Tolaram
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)Nanik Tolaram
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh KhetanRajesh Khetan
 

What's hot (20)

Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
Android Binder: Deep Dive
Android Binder: Deep DiveAndroid Binder: Deep Dive
Android Binder: Deep Dive
 
Android Binder IPC for Linux
Android Binder IPC for LinuxAndroid Binder IPC for Linux
Android Binder IPC for Linux
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
 
Android Multimedia Framework
Android Multimedia FrameworkAndroid Multimedia Framework
Android Multimedia Framework
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device Driver
 
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
"Learning AOSP" - Android Hardware Abstraction Layer (HAL)
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh Khetan
 
Android Booting Scenarios
Android Booting ScenariosAndroid Booting Scenarios
Android Booting Scenarios
 

Similar to Understanding the Android System Server

Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Opersys inc.
 
IBM Monitoring and Diagnostic Tools - GCMV 2.8
IBM Monitoring and Diagnostic Tools - GCMV 2.8IBM Monitoring and Diagnostic Tools - GCMV 2.8
IBM Monitoring and Diagnostic Tools - GCMV 2.8Chris Bailey
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...Paris Open Source Summit
 
Opencensus with prometheus and kubernetes
Opencensus with prometheus and kubernetesOpencensus with prometheus and kubernetes
Opencensus with prometheus and kubernetesJinwoong Kim
 
A165 tools for java and javascript
A165 tools for java and javascriptA165 tools for java and javascript
A165 tools for java and javascriptToby Corbin
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen Chen
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAkshaya Mahapatra
 
Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Opersys inc.
 
Monitoring Your AWS EKS Environment with Datadog
Monitoring Your AWS EKS Environment with DatadogMonitoring Your AWS EKS Environment with Datadog
Monitoring Your AWS EKS Environment with DatadogDevOps.com
 
Fabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkFabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkShashank Gautam
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetesRishabh Indoria
 
Android. behind the scenes_programatica 2012
Android. behind the scenes_programatica 2012Android. behind the scenes_programatica 2012
Android. behind the scenes_programatica 2012Agora Group
 
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Puppet
 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UIOpersys inc.
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixManish Pandit
 
Assisted-Installer-DevConf-US-2021
Assisted-Installer-DevConf-US-2021Assisted-Installer-DevConf-US-2021
Assisted-Installer-DevConf-US-2021Nir Magnezi
 
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021Freddy Rolland
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debuggingUtkarsh Mankad
 
OpenStack Nova Scheduler
OpenStack Nova Scheduler OpenStack Nova Scheduler
OpenStack Nova Scheduler Peeyush Gupta
 

Similar to Understanding the Android System Server (20)

Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013Android Internals at Linaro Connect Asia 2013
Android Internals at Linaro Connect Asia 2013
 
IBM Monitoring and Diagnostic Tools - GCMV 2.8
IBM Monitoring and Diagnostic Tools - GCMV 2.8IBM Monitoring and Diagnostic Tools - GCMV 2.8
IBM Monitoring and Diagnostic Tools - GCMV 2.8
 
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
OWF12/PAUG Conf Days Android tools for developpeurs, paul marois, design and ...
 
Opencensus with prometheus and kubernetes
Opencensus with prometheus and kubernetesOpencensus with prometheus and kubernetes
Opencensus with prometheus and kubernetes
 
A165 tools for java and javascript
A165 tools for java and javascriptA165 tools for java and javascript
A165 tools for java and javascript
 
Jollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-levelJollen's Presentation: Introducing Android low-level
Jollen's Presentation: Introducing Android low-level
 
Android101
Android101Android101
Android101
 
Automating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps ApproachAutomating Software Development Life Cycle - A DevOps Approach
Automating Software Development Life Cycle - A DevOps Approach
 
Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013
 
Monitoring Your AWS EKS Environment with Datadog
Monitoring Your AWS EKS Environment with DatadogMonitoring Your AWS EKS Environment with Datadog
Monitoring Your AWS EKS Environment with Datadog
 
Fabric - Realtime stream processing framework
Fabric - Realtime stream processing frameworkFabric - Realtime stream processing framework
Fabric - Realtime stream processing framework
 
Introduction to kubernetes
Introduction to kubernetesIntroduction to kubernetes
Introduction to kubernetes
 
Android. behind the scenes_programatica 2012
Android. behind the scenes_programatica 2012Android. behind the scenes_programatica 2012
Android. behind the scenes_programatica 2012
 
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
Exploring the Final Frontier of Data Center Orchestration: Network Elements -...
 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UI
 
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at NetflixOSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
OSCON 2014 - API Ecosystem with Scala, Scalatra, and Swagger at Netflix
 
Assisted-Installer-DevConf-US-2021
Assisted-Installer-DevConf-US-2021Assisted-Installer-DevConf-US-2021
Assisted-Installer-DevConf-US-2021
 
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
"Look Ma, no hands! Zero Touch Provisioning for OpenShift" DevConf.US 2021
 
Android booting sequece and setup and debugging
Android booting sequece and setup and debuggingAndroid booting sequece and setup and debugging
Android booting sequece and setup and debugging
 
OpenStack Nova Scheduler
OpenStack Nova Scheduler OpenStack Nova Scheduler
OpenStack Nova Scheduler
 

More from Opersys inc.

Android Automotive
Android AutomotiveAndroid Automotive
Android AutomotiveOpersys inc.
 
Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals UpdateOpersys inc.
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with PieOpersys inc.
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Opersys inc.
 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with OreoOpersys inc.
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoTOpersys inc.
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things InternalsOpersys inc.
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in AndroidOpersys inc.
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave InternalsOpersys inc.
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in AndroidOpersys inc.
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with NougatOpersys inc.
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave InternalsOpersys inc.
 

More from Opersys inc. (20)

Android Automotive
Android AutomotiveAndroid Automotive
Android Automotive
 
Android 10 Internals Update
Android 10 Internals UpdateAndroid 10 Internals Update
Android 10 Internals Update
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with Pie
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?Android Treble: Blessing or Trouble?
Android Treble: Blessing or Trouble?
 
Embedded Android Workshop with Oreo
Embedded Android Workshop with OreoEmbedded Android Workshop with Oreo
Embedded Android Workshop with Oreo
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Android Things: Android for IoT
Android Things: Android for IoTAndroid Things: Android for IoT
Android Things: Android for IoT
 
Android Things Internals
Android Things InternalsAndroid Things Internals
Android Things Internals
 
Scheduling in Android
Scheduling in AndroidScheduling in Android
Scheduling in Android
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Memory Management in Android
Memory Management in AndroidMemory Management in Android
Memory Management in Android
 
Embedded Android Workshop with Nougat
Embedded Android Workshop with NougatEmbedded Android Workshop with Nougat
Embedded Android Workshop with Nougat
 
Brillo / Weave Internals
Brillo / Weave InternalsBrillo / Weave Internals
Brillo / Weave Internals
 

Understanding the Android System Server

  • 1. Understanding the Android System Server AnDevCon – March 9th 2011 Karim Yaghmour / @karimyaghmour
  • 2. About ... ● Author of: ● Introduced Linux Trace Toolkit in 1999 ● Originated Adeos and relayfs (kernel/relay.c)
  • 3. 1. Architecture recap 2. Bootup sequence 3. Services run by the System Server 4. Observing the System Server in action 5. Binder 6. Calling on System Services 7. Inside a few System Services 8. Creating your own System Service
  • 5. 2. Bootup sequence ● Init: ● app_process -Xzygote (Zygote) ● frameworks/base/cmds/app_process/app_main.cpp: ● runtime.start(“com.android.internal.os.Zygote”, ... ● frameworks/base/core/jni/AndroidRuntime.cpp: ● startVM() ● Call Zygote's main() ● frameworks/base/core/java/com/android/internal/os/Zy goteInit.java: ● ...
  • 6. preloadClasses() ● startSystemServer() ● ... magic ... ● Call SystemServer's run() ● frameworks/base/services/java/com/android/server /SystemServer.java: ● Start all system services/managers ● Start ActivityManager: – Send Intent.CATEGORY_HOME – Launcher2 kicks in
  • 7. 3. Services run by the System Server Entropy Service Device Policy Audio Service Power Manager Status Bar Headset Observer Activity Manager Clipboard Service Dock Observer Telephone Registry Input Method Service UI Mode Manager Service Package Manager NetStat Service Backup Service Account Manager NetworkManagement Service AppWidget Service Content Manager Connectivity Service Recognition Service System Content Providers Throttle Service Status Bar Icons Battery Service Accessibility Manager DiskStats Service Lights Service Mount Service ADB Settings Observer Vibrator Service Notification Manager Alarm Manager Device Storage Monitor Init Watchdog Location Manager Sensor Service Search Service Window Manager DropBox Service Bluetooth Service Wallpaper Service
  • 8. 3.1. Some stats ● frameworks/base/services/java/com/android/ser ver: ● 3.5 M ● ~100 files ● 85 kloc ● Activity manager: ● 920K ● 30+ files ● 20 kloc
  • 9. 4. Observing the System Server in action ● Find the System Server's PID $ adb shell ps | grep system_server system 63 32 120160 35408 ffffffff afd0c738 S system_server ● Look for its output: $ adb logcat | grep “63)” ... D/PowerManagerService( 63): bootCompleted I/TelephonyRegistry( 63): notifyServiceState: 0 home Android Android 310260 UMTS CSS not supp... I/TelephonyRegistry( 63): notifyDataConnection: state=0 isDataConnectivityPossible=false reason=null interfaceName=null networkType=3 I/SearchManagerService( 63): Building list of searchable activities I/WifiService( 63): WifiService trying to setNumAllowed to 11 with persist set to true I/ActivityManager( 63): Config changed: { scale=1.0 imsi=310/260 loc=en_US touch=3 keys=2/1/2 nav=3/1 ... I/TelephonyRegistry( 63): notifyMessageWaitingChanged: false I/TelephonyRegistry( 63): notifyCallForwardingChanged: false I/TelephonyRegistry( 63): notifyDataConnection: state=1 isDataConnectivityPossible=true reason=simL... I/TelephonyRegistry( 63): notifyDataConnection: state=2 isDataConnectivityPossible=true reason=simL... D/Tethering( 63): MasterInitialState.processMessage what=3 I/ActivityManager( 63): Start proc android.process.media for broadcast com.android.providers.downloads/.DownloadReceiver: pid=223 uid=10002 gids={1015, 2001, 3003} I/RecoverySystem( 63): No recovery log file W/WindowManager( 63): App freeze timeout expired. ...
  • 10. 5. Binder ● CORBA/COM-like IPC ● Data sent through “parcels” in “transactions” ● Kernel-supported mechanism ● Check /proc/binder/* ● android.* API connected to System Server through Binder.
  • 11. 6. Calling on System Services ● Use getSystemServer ● Ex: NotificationManager Object reference: String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) getSystemServService(ns); ● Prepare your content ● Call on the object: mNotificationManager.notify(HELLO_ID, notification);
  • 12. 7. Inside a few System Services ● Get the AOSP ... repo, etc. ● Tricks: ● Import into Eclipse and collapse methods ● Use reverse-engineering tools: – Imagix – Rationale – Lattix – Scitools – ... ● Be patient, this isn't documented anywhere ...
  • 13. 7.1. ActivityManager ● Start new Activities, Services ● Fetch Content Providers ● Intent broadcasting ● OOM adj. maintenance ● Application Not Responding ● Permissions ● Task management ● Lifecycle management
  • 14. Ex. starting new app from Launcher: ● onClick(Launcher) ● startActivity(Activity.java) ● <Binder> ● ActivityManagerService ● startViaZygote(Process.java) ● <Socket> ● Zygote
  • 15. 7.2. Package Manager ● 10 kloc ● 450 K ● Installation / removal ● Permissions ● Intent resolution (also IntentResolver.java) ● Called by Activity Manager
  • 16. 7.3. Window Manager ● Main thread ● Window manipulation ● Wallpaper handling ● Orientation ● Focus ● Layering ● Input event management
  • 17. 7.4. Notification Manager ● Toasts ● Notifications ● Sound playback (see NotificationPlayer.java)
  • 18. 7.5. Power Manager ● Wakelocks ● Sleep ● Brightness ● Lock
  • 19. 7.6. Network Management Service ● Talks to “netd” /system/netd ● Interface configuration ● Tethering ● DNS
  • 20. 7.7. Mount Service ● Mount / Unmount ● Format ● USB mass storage ● OBB
  • 21. 7.8. Location Manager ● Manage location providers ● getBestProvider() ● Proximity alerts ● Last known location
  • 22. 7.9. Status Bar Manager ● Expand / collapse ● Icon visibility ● Reveal callbacks ● Callbacks for notification manager
  • 23. 7.10. Backup Manager ● Enable / disable ● Transport management ● backupNow() ● ...
  • 24. 8. Creating your own System Service ● Have new funky hardware? ● Add your code to: frameworks/base/services/java/com/android/server/ ● Have the SystemServer.java init your service ● Expose through: ● frameworks/base/core/java/android/os/[server].aidl ● Call on native “driver” code through JNI ● Create an app that calls on service ● May need to generate custom SDK ...