Android Source Code Analysis (vii) Launcher Desktop program start analysis

Source: Internet
Author: User
Tags call back home screen

I. Preface:

Init process –> zygote process –> systemserver process –> Launcher Desktop program-our app

Init process: Linux root process, Android system is based on Linux system, so it can be counted as the first process of the entire Android operating system;

Zygote process: Root process of Android system, main function: can function zygote process fork out systemserver process and various application processes;

Systemservice process: Mainly in this process to start the system of various services, such as activitymanagerservice,packagemanagerservice,windowmanagerservice services, etc.;

Launcher Desktop Program: is the desktop program that we usually see, it is actually an Android application, but this application is the system by default the first launch of the application.

Two. Launcher Desktop program Startup

Launcher Program is the desktop program that we usually see, it is actually an Android application, but this application is the system by default the first launch of the application.

In the previous article, we knew that during the startup of the Systemserver process, its main static method was called, and the starting process for the entire systemserver was started. The Startotherservice method is called by calling the Mactivitymanagerservice.systemready () method.

//Systemserver.javaPrivate voidstartotherservices () {...//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.Mactivitymanagerservice.systemready () ...}
//Activitymanagerservice.java Public voidSystemready (FinalRunnable Goingcallback, Boottimingstracelog tracelog) {... starthomeactivitylocked (Currentuserid,"Systemready"); ......}BooleanStarthomeactivitylocked (intuserId, String reason) {        if(Mfactorytest = =Factorytest.factory_test_low_level&& Mtopaction = =NULL) {            //We is running in factory test mode, but unable to find//the factory test app, so just sit around displaying the//error message and don ' t try to start anything.            return false; } Intent Intent=gethomeintent (); Activityinfo Ainfo=Resolveactivityinfo (Intent, stock_pm_flags, userId); if(Ainfo! =NULL) {intent.setcomponent (Newcomponentname (AInfo.applicationInfo.packageName, ainfo.name)); //Don ' t do this if the Home app is currently being//instrumented.Ainfo =NewActivityinfo (Ainfo); Ainfo.applicationinfo=Getappinfoforuser (Ainfo.applicationinfo, userId); Processrecord app=getprocessrecordlocked (Ainfo.processname, AInfo.applicationInfo.uid,true); if(App = =NULL|| App.instr = =NULL) {intent.setflags (Intent.getflags ()|intent.flag_activity_new_task); Final intResolveduserid =Userhandle.getuserid (AINFO.APPLICATIONINFO.UID); //For ANR Debugging to verify if the user activity are the one that actually//launched.                FinalString Myreason = reason + ":" + userId + ":" +Resolveduserid;            Mactivitystarter.starthomeactivitylocked (Intent, Ainfo, Myreason); }        } Else{slog.wtf (TAG,"No Home screen found for" + intent,Newthrowable ()); }        return true; } Intent gethomeintent () {Intent Intent=NewIntent (mtopaction, Mtopdata! =NULL? Uri.parse (Mtopdata):NULL);        Intent.setcomponent (mtopcomponent);        Intent.addflags (intent.flag_debug_triaged_missing); if(Mfactorytest! =factorytest.factory_test_low_level)        {intent.addcategory (intent.category_home); }        returnIntent; }
//Activitystarter.java    voidstarthomeactivitylocked (Intent Intent, Activityinfo ainfo, String reason) {Msupervisor.movehomestacktasktotop        (reason); Mlasthomeactivitystartresult= Startactivitylocked (NULL /*Caller*/, Intent,NULL /*ephemeralintent*/,NULL /*Resolvedtype*/, Ainfo,NULL /*Rinfo*/,                NULL /*voicesession*/,NULL /*Voiceinteractor*/,NULL /*Resultto*/,                NULL /*resultwho*/, 0/*Requestcode*/, 0/*Callingpid*/, 0/*Callinguid*/,                NULL /*Callingpackage*/, 0/*Realcallingpid*/, 0/*Realcallinguid*/,                0/*Startflags*/,NULL /*Options*/,false /*ignoretargetsecurity*/,                false /*componentspecified*/, Mlasthomeactivitystartrecord/*outactivity*/,                NULL /*Container*/,NULL /*Intask*/, "starthomeactivity:" +reason); if(msupervisor.inresumetopactivity) {//If We is in the Resume section already, home activity would be initialized, and not//resumed (to avoid recursive resume) and would stay that is until something pokes it//again. We need to schedule another resume.msupervisor.scheduleresumetopactivities (); }    }

After that, the activation process of the activity is entered.

Android Source Code Analysis (vii) Launcher Desktop program start analysis

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.