Android Zygote Startup

adb shell进去到andorid OS, 发现了这个名字的进程“Zygote”.

Here are some miscellaneous notes on Android startup of the zygote process.

This information is true for eclair, as of August 2010.

Sequence of Zygote startup steps

  • init runs the C++ program /system/bin/app_process, and gives the resulting process the name “zygote”
    • This is based on the line from init.rc:
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start
  • app_process executes, and executes a runtime environment for a dalvik class
    • app_process usage claims to be:
Usage: app_process [java-options] cmd-dir start-class-name [options]
    • but you can specify –zygote in place of the start-class-name.
    • In the bootup case, –zygote is used
    • source for ‘app_process is in frameworks/base/cmds/app_process/app_main.cpp
    • this is the program to debug when debugging zygote/dalvik itself
  • app_process does a ‘runtime.start(“”, startSystemServer)
    • the startSystemServer flag is passed as a parameter on to app_process, to indicate whether to start the system server (duh)
  • runtime is an instance of class AppRuntime, which is sub-classed from AndroidRuntime
  • AndroidRuntime is the main class for starting the dalvik runtime environment
    • source is in frameworks/base/core/jni/AndroidRuntime.cpp
    • the start() method starts the virtual machine
      • LOG_BOOT_PROGRESS_START is emitted, with systemTime(SYSTEM_TIME_MONOTONIC)
      • startVM() is called
      • eventually, callStaticVoidMethod() is called, to actually start executing the start class with method “main” in Dalvik code
  • starts executing
    • source is at: frameworks/base/core/java/com/android/internal/os/
  • the profiler is started
  • the Zygote socket is registered (for later communication to start apps)
  • classes and resources are preloaded
  • if startSystemServer is set, then the system server is started
    • the command line to the system server is:
--setuid=1000 --setgid=1000 \
--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,3001,3002,3003 \
--capabilities=130104352,130104352 \
--runtime-init \
--nice-name=system_server \
    • the class which starts executing is:
    • a call is made to Zygote.forkSystemServer() to actually start this other process
  • zygote runs in “select loop mode”, where a single process spins waiting for communication to start subsequent apps
    • see runSelectLoopMode()
      • new connections are accepted (and put into array “peers”)
      • the spawn command received over the network is executed by calling the runOnce() method
      • source code for this is at: frameworks/base/core/java/com/android/internal/os/
  • eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking

Sequence of system_server (or SystemServer)

startup steps

Source for the SystemServer is in:frameworks/base/services/java/com/android/server/

in the “ServerThread::run()” method, the following startup occurs:

  • Lots of critical services are started:
    • Entropy Service
    • Power Manager
    • Activity Manager
    • Telephony Registry
    • Package Manager
    • Account Manager
    • Content Manager
    • System Content Providers
    • Battery Service
    • Hardware Service
    • Alarm Manager
    • Init Watchdog
    • Sensor Service
    • Window Manager
  • Additional services may be started as well:
    • Status Bar
    • Clipboard Service
    • Input Method Service
    • NetStat Service
    • Connectivity Service
    • Accessibility Manager
    • Notification Manager
    • Mount Service
    • Device Storage Monitor
    • Location Manager
    • Search Service
    • Checkin Service
    • Wallpaper Service
    • Audio Service
    • Headset Observer
    • Dock Observer
    • Backup Service
    • AppWidget Service


此篇文章已被阅读2233 次

Add a Comment

邮箱地址不会被公开。 必填项已用*标注