Android Boot Process

Source: Internet
Author: User

Below is the Android Launcher to interface display flowchart




The 1:linux kernel starts the 2:init process. 3:Local System services,Java System service startup: 1): Init starts Service Manager, which is responsible for the registry management of the system services, including "Java System Services", "Local System Services" 2): Init starts Media server, which is responsible for initiating the " Local System services. 3): Init starts zygote, this process starts the system server process, which starts the Java system service---[including Power Manager Service,sensor Service] 4): In addition Init starts the system /bin the various daemons below
4:home BOOT.
-------------------------------------------First step: Linux kernel boot this ominous detail
Step two: Start Linux's first process init

kernel/init/main.casmlinkage void __init start_kernel (void)//This is the entrance of kernel, Head-common. S assembly code will be connected. {... ftrace_init ();/* Do the rest non-__init ' Ed, we ' re now alive */rest_init ();} static noinline void __init_refok rest_init (void) {.../* * We need to spawn Init first so it obtains PID 1, Howeve  R * The init task would end up wanting to create kthreads, which, if * We schedule it before we create Kthreadd, would OOPS. */kernel_thread (Kernel_init, NULL, CLONE_FS | Clone_sighand), ...............} static int __init kernel_init (void * unused) {...) if (!ramdisk_execute_command) <span style= "color: #ff0000;" >ramdisk_execute_command = "/init" </span>;//specifies the location of the init file if (sys_access (const char __user *) Ramdisk_execute_ command, 0)! = 0) {Ramdisk_execute_command = Null;prepare_namespace ();} /* * Ok, we have completed the initial bootup, and * we ' re essentially up and running. Get rid of the * initmem segments and start the user-mode stuff. */init_post (); return 0;} Static Noinline int init_post (void) {/* need to finish all async __init code before freeing the memory */async_synchronize_full (); FR Ee_initmem (); Mark_rodata_ro (); system_state = System_running;numa_default_policy (); Current->signal->flags |= Signal_unkillable;if (Ramdisk_execute_command) {run_init_process (Ramdisk_execute_command);//Call run_init_process function , the Init process runs up PRINTK (kern_warning "Failed to execute%s\n", Ramdisk_execute_command);} ...........}

Step Three: Start the service Manager process
Init process starts Service Manager process with INIT.RC configuration
[Init.rc]service servicemanager/system/bin/servicemanager//See, Class Core User system group system critical    Onrestart Restart HEALTHD onrestart Restart zygote onrestart Restart media onrestart Restart Surfaceflinger Onrestart Restart drmframeworks/native/cmds/servicemanager/service_manager.c//The following is the process code, which manages the local system service and the Java system service. Provides the basis for the registration of the Java system service below for local system services. [C]void *do_find_service (struct binder_state *bs, uint16_t *s, unsigned len, unsigned uid) {}int do_add_service (struct bin Der_state *bs, uint16_t *s, unsigned len, void *ptr, unsigned uid, int allow_isolated)    {}int main (int argc, char **argv) {struct binder_state *bs;    void *svcmgr = Binder_service_manager;    BS = Binder_open (128*1024);        if (Binder_become_context_manager (BS)) {Aloge ("Cannot become context Manager (%s) \ n", Strerror (errno));    return-1;    } svcmgr_handle = Svcmgr;    Binder_loop (BS, Svcmgr_handler); return 0;}


init process starts Media server with init.rc configuration
Service Media/system/bin/mediaserver    class main    user Media    Group Audio camera inet NET_BT net_bt_admin net_ Bw_acct drmrpc mediadrm qcom_diag    Ioprio RT 4frameworks/av/media/mediaserver/main_mediaserver.cpp
Start a series of local system services
</pre><pre>

[Cpp]int Main (int argc, char** argv) {            ...        Audioflinger::instantiate ();        Mediaplayerservice::instantiate ();        Cameraservice::instantiate (); #ifdef qcom_listen_feature_enable        alogi ("Listenservice instantiated");        Listenservice::instantiate (); #endif        audiopolicyservice::instantiate (); #ifdef Resource_manager        Alogi (" Resourcemanagerservice instantiated ");        Resourcemanagerservice::instantiate (); #endif        registerextensions ();        Processstate::self ()->startthreadpool ();        Ipcthreadstate::self ()->jointhreadpool ();}    }

init process starts with INIT.RC configurationZygote
service Zygote/system/bin/app_process-xzygote/system/bin--zygote--start-system-server//zygote is initiated through the app_process process, Note: zygote is a Java code Process class main socket zygote stream 660 root system Onrestart Write/sys/android_power/request_sta Te Wake Onrestart write/sys/power/state on onrestart Restart media onrestart restart netd 
Frameworks/base/cmds/app_process/app_main.cpp[cpp]int Main (int argc, char* const argv[]) {<span style= "color:# ff0000; " >//build Android Runtime and then start the zygote process </span>runtime.start ("Com.android.internal.os.ZygoteInit", starts Ystemserver? "Start-system-server": "")}frameworks/base/core/jni/androidruntime.cppruntime the virtual machine, then starts the zygote process void Androidruntime::start (const char* className, const char* options) {<span style= "color: #ff0000;"    >//runtime Build Virtual Machine,</span>/* Start the virtual machines */jnienv* env;    if (STARTVM (&AMP;MJAVAVM, &env)! = 0) {return;       } onvmcreated (env);  Start the Java process, the zygote/* * Start VM mentioned above.     This thread becomes the main thread of the VM, and would * not return until the VM exits.    */char* Slashclassname = Toslashclassname (className);    Jclass Startclass = Env->findclass (slashclassname);     if (Startclass = = NULL) {aloge ("JAVAVM Unable to locate class '%s ' \ n", slashclassname);   /* Keep going */} else {Jmethodid Startmeth = Env->getstaticmethodid (Startclass, "main", "([L        java/lang/string;) V ");            if (Startmeth = = NULL) {aloge ("JAVAVM Unable to find main () in '%s ' \ n", className);            /* Keep going */} else {Env->callstaticvoidmethod (Startclass, Startmeth, strarray); #if 0 if (Env->exceptioncheck ()) threadexituncaughtexception (env); #endif}}

ZygoteStart the system server process
Frameworks/base/core/java/com/android/internal/os/zygoteinit.java public static void Main (String argv[]) {try {            Start profiling the zygote initialization.           Samplingprofilerintegration.start (); <span style= "color: #ff0000;"                > Registerzygotesocket ();//Register Listner Interface </span> eventlog.writeevent (Log_boot_progress_preload_start,            Systemclock.uptimemillis ());            Preload ();            Eventlog.writeevent (Log_boot_progress_preload_end, Systemclock.uptimemillis ()); 20131109 add for Bootprof begin Addbootevent (New String ("Zygote:preload Start");//20131109 Add for Bootpro            F End//Finish profiling the zygote initialization.            Samplingprofilerintegration.writezygotesnapshot ();            Do a initial GC to clean up after startup GC ();     Disable tracing So, forked processes do not inherit stale tracing tags from       Zygote.            Trace.settracingenabled (FALSE); If requested, start system server directly from Zygote if (argv.length! = 2) {throw new Runt            Imeexception (Argv[0] + usage_string); }//20131109 add for Bootprof begin Addbootevent (New String ("Zygote:preload End");//20131109 add F or Bootprof End if (argv[1].equals ("Start-system-server")) {startsystemserver ();//Kai Dynamic System Server} else if (!argv[1].equals ("")) {throw new RuntimeException (Argv[0] + Usage_stri            NG);            } log.i (TAG, "accepting command socket connections");            Runselectloop ();        Closeserversocket ();        } catch (Methodandargscaller caller) {Caller.run ();            } catch (RuntimeException ex) {LOG.E (TAG, "Zygote died with exception", ex);            Closeserversocket ();        Throw ex; }    }

Note: Zygote starts the system server process, also registers the Scoket channel, receives the request from Activitymanagerservice, and fork the application


Frameworks/base/services/java/com/android/server/systemserver.java//starts a series of Java system Services public class Systemserver {     private static final String TAG = "Systemserver", .../** * Called to initialize native system services.    */private static native void Nativeinit ();        public static void Main (string[] args) {...//Initialize native services.        Nativeinit ();        This used to was its own separate thread, and now it's//Just the loop we run on the main thread.        Serverthread thr = new Serverthread ();    Thr.initandloop ();    }}class Serverthread {private static final String TAG = "Systemserver";    private static final String encrypting_state = "Trigger_restart_min_framework";    private static final String encrypted_state = "1";    Contentresolver Mcontentresolver;        void Reportwtf (String msg, throwable e) {SLOG.W (TAG, "***********************************************");    LOG.WTF (TAG, "BOOT FAILURE" + MSG, E); } public VOID Initandloop () {.....            SLOG.I (TAG, "Content Manager");            Contentservice = Contentservice.main (context, factorytest = = Systemserver.factory_test_low_level);            SLOG.I (TAG, "System Content Providers");            Activitymanagerservice.installsystemproviders ();            SLOG.I (TAG, "Lights Service");            Lights = new Lightsservice (context);            SLOG.I (TAG, "Battery Service");            Battery = new Batteryservice (context, lights);            Servicemanager.addservice ("Battery", battery);            SLOG.I (TAG, "Vibrator Service");            Vibrator = new Vibratorservice (context);            Servicemanager.addservice ("Vibrator", vibrator);            SLOG.I (TAG, "Consumer IR Service");            Consumerir = new Consumerirservice (context); Servicemanager.addservice (Context.consumer_ir_service, Consumerir); ...}}


Fourth Step home Launch


After Frameworks/base/services/java/com/android/server/am/activitymanagerservice.javasystem server starts the Java system service, Will issue a systemrready notice.        Activitymanagerservice Systemready function callback emits userswitch broadcast start home public void Systemready (final Runnable goingcallback) {                Synchronized (this) {if (Msystemready) {if (goingcallback! = null) Goingcallback.run ();            Return            } mstacksupervisor.resumetopactivitieslocked ();        Senduserswitchbroadcastslocked ( -1, Mcurrentuserid); }} @Override public boolean switchuser (final int userId) {Boolean homeinfront = Mstacksupervisor.switchuserlocke                D (userId, USS); if (homeinfront) {<span style= "color: #ff0000;" >starthomeactivitylocked (userId);</span>} else {Mstacksupervisor.resumetopact                Ivitieslocked (); }}

Finish







Android Boot Process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.