Start up sequence of system server of Android (memo)

This is memo of start up sequence of system server, which starts various services.
(as of android-2.3.3_r1 source code)
(Japanese version of this page)

start app_process from init

init.rc

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
    socket zygote stream 666
    onrestart write /sys/android_power/request_state wake
    onrestart write /sys/power/state on
    onrestart restart media
    onrestart restart netd

frameworks/base/cmds/app_process/app_main.cpp::main

        if (0 == strcmp("--zygote", arg)) {
            bool startSystemServer = (i < argc) ? 
                    strcmp(argv[i], "--start-system-server") == 0 : false;
            setArgv0(argv0, "zygote");
            set_process_name("zygote");
            runtime.start("com.android.internal.os.ZygoteInit",
                startSystemServer);
        } else {

frameworks/base/core/jni/AndroidRuntime.cpp::start

void AndroidRuntime::start(const char* className, const bool startSystemServer)
{
    LOGD("\n>>>>>> AndroidRuntime START %s <<<<<<\n",
            className != NULL ? className : "(unknown)");

    ...
    JNI恧callStatic
    com.android.internal.os.ZygoteInit#main

frameworks/base/core/java/com/android/internal/os/ZygoteInit.java#main

            if (argv[1].equals("true")) {
                startSystemServer();
            } else if (!argv[1].equals("false")) {
                throw new RuntimeException(argv[0] + USAGE_STRING);
            }

frameworks/base/core/java/com/android/internal/os/ZygoteInit.java#startSystemServer

        String args[] = {
            "--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",
            "com.android.server.SystemServer",
        };
        ...
        try {
            parsedArgs = new ZygoteConnection.Arguments(args);

            ...
            /* Request to fork the system server process */
            pid = Zygote.forkSystemServer(
                    parsedArgs.uid, parsedArgs.gid,
                    parsedArgs.gids, debugFlags, null,
                    parsedArgs.permittedCapabilities,
                    parsedArgs.effectiveCapabilities);

framesorks/base/services/java/com/android/server/SystemServer.java
SystemServer#main

    public static void main(String[] args) {

        ...        

        System.loadLibrary("android_servers");
        init1(args);  // <-- native method
    }

frameworks/base/services/jni/com_android_server_SystemServer.cpp

static void android_server_SystemServer_init1(JNIEnv* env, jobject clazz)
{
    system_init();
}

frameworks/base/cmds/system_server/library/system_init.cpp
system_init

Start services written in C++
– SurfaceFlinger
– SensorService
– AudioFlinger
– MediaPlayerService
– CameraService
– AudioPolicyService

callStatic by JNI com/android/server/SystemServer#init2

framesorks/base/services/java/com/android/server/SystemServer.java

    public static final void init2() {
        Slog.i(TAG, "Entered the Android system server!");
        Thread thr = new ServerThread();
        thr.setName("android.server.ServerThread");
        thr.start();
    }

ServerThread#run

Start services written in Java
– Entropy Service
– Power Manager
– Activity Manager
– Telephony Registry
– Package Manager
– Account Manager
– Content Manger
– System Content Providers
– Battery Service
– Lights Service
– Vibrator Service
– Alarm Manager
– Init Watchdog
– Window Manager
– Bluetooth Service
– Device Policy
– Status Bar
– Clipboard Service
– Input Method Service
– NetStat Service
– NetworkMnagement Service
– Connectivity Service
– Throttle Service
– Accessibility Manager
– Mount Service
– Notification Manager
– Device Storage Monitor
– Location Manager
– Search Service
– DropBox Service
– Wallpaper Service
– Audio Service
– Headset Observer
– Dock Observer
– USB Observer
– UI Mode Manager Service
– Backup Service
– AppWidget Service
– Recognition Service
– DiskStats Service

These services create threads as needs. All those threads are running in the System Server process.

In the normal Linux system, these services are independent process.

Links

Android Zygote Startup – eLinux.org

Advertisements

About tetsu_koba

Engineer.
This entry was posted in Android. Bookmark the permalink.

4 Responses to Start up sequence of system server of Android (memo)

  1. Eric CABRET says:

    Many many thanks, Tetsuyuki Kobayashi, for this very clear & exact information that were very helpful for me.
    Best regards.
    Eric.

  2. Gourob Saha says:

    hellow there , Nice post Very helpful . I want to know if i want to stop zygote process by commenting out in init.rc file and want to start console in real device
    after build is it possiable ? Another thing the multiuser system is off in android . UserID and Groupid concepts is being used in application though . If i want to add multiuser do i have change the filesystem of android ? .

  3. Gourob Saha says:

    here is my Init.rc file’s section . I modify it and build itto samsung p62wifi (tab) but console is not running after build . Please help me here

    class_start default

    ## Daemon processes to be run by init.
    ##
    service ueventd /sbin/ueventd
    critical

    service console /system/bin/sh
    console

    service pvr /system/bin/sgx/rc.pvr start

    # adbd is controlled by the persist.service.adb.enable system property
    service adbd /sbin/adbd
    disabled

    # adbd on at boot in emulator
    on property:ro.kernel.qemu=1
    start adbd

    on property:persist.service.adb.enable=1
    start adbd

    on property:persist.service.adb.enable=0
    stop adbd

    service servicemanager /system/bin/servicemanager
    user system
    critical
    onrestart restart zygote
    onrestart restart media

    service vold /system/bin/vold
    socket vold stream 0660 root mount
    ioprio be 2

    service netd /system/bin/netd
    socket netd stream 0660 root system

    service debuggerd /system/bin/debuggerd

    service ril-daemon /system/bin/rild
    socket rild stream 660 root radio
    socket rild-debug stream 660 radio system
    user root
    group radio cache inet misc audio

    service zygote /system/bin/app_process -Xzygote /system/bin –zygote –start-system-server
    socket zygote stream 666
    onrestart write /sys/android_power/request_state wake
    onrestart write /sys/power/state on
    onrestart restart media

    service media /system/bin/mediaserver
    user media
    group system audio camera graphics inet net_bt net_bt_admin net_raw sdcard_rw
    ioprio rt 4

    service bootanim /system/bin/bootanimation
    user graphics
    group graphics
    disabled
    oneshot

    service dbus /system/bin/dbus-daemon –system –nofork
    socket dbus stream 660 bluetooth bluetooth
    user bluetooth
    group bluetooth net_bt_admin

    service bluetoothd /system/bin/bluetoothd -n
    socket bluetooth stream 660 bluetooth bluetooth
    socket dbus_bluetooth stream 660 bluetooth bluetooth

    # init.rc does not yet support applying capabilities, so run as root and
    # let bluetoothd drop uid to bluetooth with the right linux capabilities
    group bluetooth net_bt_admin misc
    disabled

    service hfag /system/bin/sdptool add –channel=10 HFAG
    user bluetooth
    group bluetooth net_bt_admin
    disabled
    oneshot

    service hsag /system/bin/sdptool add –channel=11 HSAG
    user bluetooth
    group bluetooth net_bt_admin
    disabled
    oneshot

    service opush /system/bin/sdptool add –channel=12 OPUSH
    user bluetooth
    group bluetooth net_bt_admin
    disabled
    oneshot

    service pbap /system/bin/sdptool add –channel=19 PBAP
    user bluetooth
    group bluetooth net_bt_admin
    disabled
    oneshot

    service installd /system/bin/installd
    socket installd stream 600 system system

    service flash_recovery /system/etc/install-recovery.sh
    oneshot

    service racoon /system/bin/racoon
    socket racoon stream 600 system system
    # racoon will setuid to vpn after getting necessary resources.
    group net_admin
    disabled
    oneshot

    service mtpd /system/bin/mtpd
    socket mtpd stream 600 system system
    user vpn
    group vpn net_admin net_raw
    disabled
    oneshot

    service keystore /system/bin/keystore /data/misc/keystore
    user keystore
    group keystore
    socket keystore stream 666

    service dumpstate /system/bin/dumpstate -s
    socket dumpstate stream 0660 shell log
    disabled
    oneshot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s