Android's build environment only supports Linux and Mac Os,google recommended 64-bit operating system, # # # Android Launcher># # # # # # # # # # # # # # # When the boot program starts the Linux kernel, it loads a variety of drivers and data structures, and when it's driven, start the Android system and load the user-level first process init (SYSTEM\CORE\INIT.C) code as follows:intMainintargcChar**argv) { //Creating folder MountsMount"Tmpfs","/ Dev","Tmpfs",0,"mode=0755"); mkdir ("/dev/pts",0755); //Punch -in logsLog_init (); INFO ("reading config file\n"); //load the init.rc configuration fileInit_parse_config_file ("/init.rc"); } ># # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # init.rc file, start a zygote process/system/bin/app_process-xzygote/system/bin--zygote--start-system-Server socket zygote stream666Onrestart Write/sys/android_power/request_state Wake Onrestart Write/sys/power/State on onrestart Restart media onrestart restart netd> # from C + +the code is transferred to the Java code:intMainintargcConst Char*Constargv[]) { ... //Android Run-time environmentAppruntime Runtime; ... //Next arg is startup classname or "--zygote" if(I <argc) {arg= argv[i++]; if(0= = strcmp ("--zygote", Arg)) { BOOLStartsystemserver = (i < ARGC)?strcmp (Argv[i],"--start-system-server") ==0:false; SetArgv0 (Argv0,"zygote"); Set_process_name ("zygote"); //Start Java codeRuntime.start ("Com.android.internal.os.ZygoteInit", ... }># # # # Zygoteinit.java Code: Public Static voidMain (String argv[]) {Try{vmruntime.getruntime (). Setminimumheapsize (5*1024x768*1024x768); //loading Android-dependent classespreloadclasses (); //cacheregistermaps ();preloadresources (); ... if(argv[1].equals ("true")) { //Start System ServicesStartsystemserver (); } Else if(!argv[1].equals ("false")) { ... } Private Staticboolean startsystemserver () ... args=Newstring[] {"--setuid=1000", "--setgid=1000", "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,3001,3002,3003,3006", "--capabilities=130104352,130104352", "--rlimit=8,", "--runtime-init", "--nice-name=system_server", "Com.android.server.SystemServer", ... /*Request to fork the system server process*/ //parent process starts fork service start SystemserverPID =zygote.forksystemserver (Parsedargs.uid, Parsedargs.gid, Parsedargs.gids, debug Flags, Rlimits, Parsedargs.permittedcapabilities, parsedargs.effectivecapabilities); .. }># # # # Systemserver.java Code Public Static voidMain (string[] args) {...//loading the JNI librarySystem.loadlibrary ("android_servers"); //calling the native methodinit1 (args); } Native Public Static voidinit1 (string[] args);> # # # Systemserver corresponding C + +The Code com_android_server_systemserver.cpp code is as follows://Java-like abstract methods extern "C" intSystem_init (); Static voidAndroid_server_systemserver_init1 (jnienv*env, Jobject clazz) { //TransposeSystem_init (); } /** JNI registration. */ StaticJninativemethod gmethods[] = { /*name, signature, Funcptr*/ //The function pointer maps the INIT1 method to the Android_server_systemserver_init1{"init1","([ljava/lang/string;) V", (void*) android_server_systemserver_init1},};># # # # # System_init is implemented in the System_init.cpp code as follows:extern "C"status_t system_init () {...//services that start hardware if(strcmp (Propbuf,"1") ==0) { //Start the Surfaceflingersurfaceflinger::instantiate (); } androidruntime* Runtime =Androidruntime::getruntime (); Logi ("System server:starting Android services.\n"); //After you start the hardware service, return to the Systemserver Init2 methodRuntime->callstatic ("Com/android/server/systemserver","Init2"); ... }># # # # # # of Systemserver Init2 method code: Public StaticFinalvoidInit2 () {slog.i (TAG,"entered the Android system server!"); Thread THR=NewServerthread (); Thr.setname ("Android.server.ServerThread"); Thr.start (); }># # # # Serverthread's Run method: Public voidrun () {...//turn on Android services and add to ServiceManager to manageSLOG.I (TAG,"Device Policy"); Devicepolicy=NewDevicepolicymanagerservice (context); Servicemanager.addservice (Context.device_policy_service, Ottle= ... //We now tell the activity manager It's okay to run third party//code. It would call back into us once it had gotten to the state//where third party code can really run (but the before it has actually//started launching the initial applications), for US//initialization. //call Activitymanagerservice.systemready after various services are turned on( (Activitymanagerservice) Activitymanagernative.getdefault ()). Systemready (NewRunnable () { Public voidrun () {slog.i (TAG,"Making Services Ready");># # # # # # Activitymangerservice's Systemready method: Public voidSystemready (Final Runnable goingcallback) {...//Open the first activityMmainstack.resumetopactivitylocked (NULL); } }># # # # # # Activitystack Resumetopactivitylocked Method Final Boolean resumetopactivitylocked (Activityrecord prev) { //Find the first activity that's not finishing. //no already open activity next is nullActivityrecord next = toprunningactivitylocked (NULL); //Remember How we'll process this pause/resume situation, and ensure//That's the state was reset however we wind up proceeding.Final Boolean userleaving =muserleaving; Muserleaving=false; if(Next = =NULL) { //There is no more activities! Let's just start up the//Launcher ... if(mmainstack) {//start the Lucher app's lock screen returnmservice.starthomeactivitylocked (); } }># # # # # Android system started and opened the home screen of the Luncher app.
android130 Android Launcher