android1

写在之前的话:

因为之前有段时间不上班了,近期决定找工作,需要重新复习下,涉及到的代码是android 9.

android系统流程:BootLoader-->linux os-->init-->zygote-->SystemServer

A、init进程会创建挂载文件、初始化一系列的属性、启动zygote进程

B、zygote进程创建DVM、ART,fork各种进程,此处最后会通过JNI调用ZygoteInit的main方法,从native层进入java层

public static void main(String argv[]) {
    ………………
    ZygoteServer zygoteServer = new ZygoteServer();
    //TODO 创建Service Socket
    zygoteServer.registerServerSocketFromEnv(socketName);
    //TODO 预加载类和资源
    preload(bootTimingsTraceLog);
    //TODO fork SystemServer进程
    Runnable r = forkSystemServer(abiList, socketName, zygoteServer);
    //TODO 通过runSelectLoop方法等待AMS的请求来创建新的应用程序进程
    caller = zygoteServer.runSelectLoop(abiList);
    }
    private static Runnable forkSystemServer(String abiList, String socketName, ZygoteServer zygoteServer){
        //TODO 关闭zygote
        zygoteServer.closeServerSocket();
        //TODO 启动SystemServer进程
        return handleSystemServerProcess(parsedArgs);
        }
    }
    private static Runnable handleSystemServerProcess(ZygoteConnection.Arguments parsedArgs){
        //TODO 创建PathClassLoader
        cl=createPathClassLoader(systemServerClasspath,parsedArgs.targetSdkVersion);
        return ZygoteInit.zygoteInit(parsedArgs.targetSdkVersion,parsedArgs.remainingArgs,cl);
        }

    public static final Runnable zygoteInit(int targetSdkVersion, String[] argv, ClassLoader classLoader) {
        //TODO native层启动Binder,就可以用Binder进行通信了
        ZygoteInit.nativeZygoteInit();
        //TODO 启动SystemServer……………………
        return RuntimeInit.applicationInit(targetSdkVersion, argv, classLoader);
        }

C、SystemServer启动AMS、WMS、PkMS等系统服务

        private void run(){
            //TODO Prepare the main looper thread (this thread).
            Looper.prepareMainLooper();
            System.loadLibrary("android_servers");//TODO 加载动态库
            //TODO Create the system service manager.
            mSystemServiceManager = new SystemServiceManager(mSystemContext);
            //TODO 启动各种服务
            startBootstrapServices();
            startCoreServices();
            startOtherServices();
        }

 

你可能感兴趣的:(技术)