Zygote service가 하는 일


 A zygote (from Greek ζυγωτός zygōtos "joined" or "yoked", from ζυγοῦν zygoun "to join" or "to yoke"), [1] or zygocyte, is the initial cell formed when a new organism is produced by means of sexual reproduction.



출처: http://blog.chinaunix.net/u2/85805/showart_1421736.html

Zygote service does the following tasks step by step:

1. Create JAVA VM.

2. Register android native function for JAVA VM.

3. Call the main function in the JAVA class named com.android.internal.os.ZygoteInit whose

    source is frameworks/base/core/java/com/android/internal/os/ZygoteInit.java.

    a) Load ZygoteInit class

    b) Register zygote socket

    c) Load preload classes(the default file is frameworks/base/preloaded-classes)

    d) Load preload resources

    e) Call Zygote::forkSystemServer (implemented in  

       dalvik/vm/native/dalvik_system_Zygote.c) to fork a new process. In the new

       process, call the main function in the JAVA class named com.android.server.SystemServer,

       whose source is in frameworks/base/services/java/com/android/server.

         i.  Load libandroid_servers.so

         ii. Call JNI native init1 function implemented in frameworks/base/services/jni.

             It only calls system_init implemented in


              - If running on simulator, instantiate AudioFlinger, MediaPlayerService and

                CameraService here.

              Call init2 function in JAVA class named com.android.server.SystemServer, whose

                source is in frameworks/base/services/java/com/android/server. This function is

                very critical for Android because it start all of Android JAVA services.

              - If not running on simulator, call IPCThreadState::self()->joinThreadPool() to enter

                into service dispatcher.


SystemServer::init2 will start a new thread to start all JAVA services as follows:

Core Services:

1.     Starting Power Manager

2.     Creating Activity Manager

3.     Starting Telephony Registry

4.     Starting Package Manager

5.     Set Activity Manager Service as System Process

6.     Starting Context Manager

7.     Starting System Context Providers

8.     Starting Battery Service

9.     Starting Alarm Manager

10.   Starting Sensor Service

11.   Starting Window Manager

12.   Starting Bluetooth Service

13.   Starting Mount Service

Other services

1.     Starting Status Bar Service

2.     Starting Hardware Service

3.     Starting NetStat Service

4.     Starting Connectivity Service

5.     Starting Notification Manager

6.     Starting DeviceStorageMonitor Service

7.     Starting Location Manager

8.     Starting Search Service

9.     Starting Clipboard Service

10.   Starting Checkin Service

11.   Starting Wallpaper Service

12.   Starting Audio Service

13.   Starting HeadsetObserver

14.   Starting AdbSettingsObserver

Finally SystemServer::init2 will call ActivityManagerService.systemReady to launch the first activity by senting Intent.CATEGORY_HOME intent.


There is another way to start system server, which is through a program named system_server whose source is frameworks/base/cmds/system_server/system_main.cpp. It also calls system_init to start system services. So there is a question: why does Android have two methods to start system services? My guess is that directly start system_server may have synchronous problem with zygote because system_server will call JNI to start SystemServer::init2, while at that time zygote may not start JAVA VM yet. So Android uses another method. After zygote is initialized, fork a new process to start system services. 

[출처] zygote service|작성자 베사메

'Android > 개발정보' 카테고리의 다른 글

Zygote 정보  (0) 2010.09.07
SQLite 함수모음  (0) 2010.08.20
Posted by 사우람

티스토리 툴바