Android源码分析--启动时序图

为什么Android系统启动比较慢

Build的产物中最重要的是三个镜像文件,位于/out/target/product//目录下
ramdisk.img:在启动时将被Linux内核挂载为只读分区,它包含了/init文件和一些配置文件。它用来挂载其他系统镜像并启动init进程。


解析步骤:

Init.c (system\core\init)    
Init.c
{
main(
......
init_parse_config_file("/init.rc");
)
}
在/init.rc中找关键字 -Xzygote
service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server
    class main
    socket zygote stream 660 root system
    onrestart write /sys/android_power/request_state wake
    onrestart write /sys/power/state on
    onrestart restart media
    onrestart restart netd


步骤二

App_main.cpp (frameworks\base\cmds\app_process)    5397    2013/4/24
    if (zygote) {
           AndroidRuntime  runtime;
        runtime.start("com.android.internal.os.ZygoteInit",
                startSystemServer ? "start-system-server" : "");
}

ZygoteInit.java (frameworks\base\core\java\com\android\internal\os)    
   if (argv[1].equals("start-system-server")) {
                startSystemServer();//启动native和监听事件有关系
    }
startSystemServer(){
com.android.server.SystemServer
}
SystemServer.java (frameworks\base\services\java\com\android\server)
main{
init1 ;//native   com.android.server.SystemServer.cpp
}

步骤三

com_android_server_SystemServer.cpp (frameworks\base\services\jni)    
init
com.android.server.SystemServer.cpp
{
      extern "C" int system_init();
}
System_init.cpp (frameworks\base\cmds\system_server\library)    

system_init(){
    Native开启
    
    init2();
}

步骤四:

SystemService.java (frameworks\base\core\java\android\os)
  public static final void init2() {
        Slog.i(TAG, "Entered the Android system server!");
        Thread thr = new ServerThread();
        thr.setName("android.server.ServerThread");
        thr.start();
    }   
            Slog.i(TAG, "Init Watchdog");
            Watchdog.getInstance().init(context, battery, power, alarm,
                    ActivityManagerService.self());

system_init(){
Native 开启

runtime->callStatic("com/android/server/SystemServer","init2");
}

ServerThread  extends Thread
 public void run() {
Activity Manager
Package  Manager
 }


时序图附件:

http://download.csdn.net/detail/javamov/7568845



=============================================

init.c

挂载

    mkdir("/dev", 0755);
    mkdir("/proc", 0755);
    mkdir("/sys", 0755);

    mount("tmpfs", "/dev", "tmpfs", MS_NOSUID, "mode=0755");
    mkdir("/dev/pts", 0755);
    mkdir("/dev/socket", 0755);
    mount("devpts", "/dev/pts", "devpts", 0, NULL);
    mount("proc", "/proc", "proc", 0, NULL);
    mount("sysfs", "/sys", "sysfs", 0, NULL);




=====================关键点(android启动慢):

ZygoteInit.java

             细节:

                  在main方法会预加载进2000类,通过反射proloadClasses();








































你可能感兴趣的:(Android源码分析,Android源码分析)