"Android Framework" Androidmanagerservice initialization process

Source: Internet
Author: User

Source code based on Android 4.4. The initialization of System_server System_server is managed by AMS and is responsible for initiating framework-res.apk and settingsprovider.apk. System_server calls the AMS interface to initialize the required members.

System_server.java::serverthread.run ()


context = Activitymanagerservice.main ();                        //Get a context, provided to System_server to do the operating environment--athread THR = new Athread (). Start ();                          //Create the AMS object, this thread is named activitymanager-- --new Activitymanagerservice (); ———— Lopper.loop ();                          ,         &NB Sp                //message loop--activitymanagerservice m = Thr.mservice;                          ,         &NB Sp         //The AMS instance obtained by running athread--mself = m;--activitythread at = Activitythread.systemmain ();      //Create Activitythread object, provided to System_server to do the running environment ———— activitythread thread = new Activitythread (); ———— Thread.attach ();                              ,         &N Bsp          //Create instrumentation,application and Context (Contextimpl) objects. A process supports multiple application, saved in Mapplications —————— app.oncreate ();                          ,         &NB Sp      //Call application's OnCreate function--m.mcontext = at.Getsystemcontext(); Get a context object for the system, Singleton mode(only initialized when null)———— loadedapk info = newloadapk ();                                                     Represents an apk loaded into the system ———— context.init (); //here initialization is not bound applicationinfo, just create a run environment--m.mainstact = new Activitystack ();                          //activitystack manage activity start-up and scheduling- -m.startrunning ();                          ,         &NB Sp                  //tag variable, start Systemready () (this time does not start) ———— Systemready ();  Activitymanagerservice.setsystemprocess ();                    // This system_server can be added to AMs, and managed by him--servicemanager.addservice ();                                //Tim Add activity,meminfo,gfxinfo,cpuinfo,permission service--application info = MSelf.mContext.getPackageManager (). Getapplicationinfo ("Android", Stock_pm_flags)    //Using AMS's context object, query the ApplicationInfo named Android, namely Frameworks-res.apk--msystemthread.installsystemapplicationinfo ();        //Loading framework-res.apk ———— Contextimpl context = getsystemcontext ();      //and the System contxt obtained in the main of AMS are the same context, since the above has been initialized, here is the direct return Msystemcontext ———— Context.init ();                          ,         &NB Sp                //re-Initialize here, add the ApplicationInfo from framewrok-res.apk--processrecord app = mself.newprocessrecordlocked (); The information for the process is stored here, where the Processrecord is named system. Processrecord initializes the power statistics Batterystats,applicationinfo, the process name ProcessName, and the iapplicationthread that interacts with the application process (callingschddulelaunchactivity, schedulestopactivity, etc.), scheduling priority, OOM_ADJ, whether the process is resident persistent (AMS is set for System_server)--mself.mprocessnames.put (app. ..);                           //Save Processrecord objects --mself.mpidsselflocked.put (App ...);                          //save Processrecord Object--msel f.updatelruprocesslocked (APP);                        //adjust process scheduling priorities and OOM_ADJ ACTIVITYMANAG Erservice.installsystemproviders ();              //put Settingsprovider on the system The _server process comes running, and framework-res.apk runs together, which is where multiple apk runs on a thread instance--processrecord app = MSelf.mProcessNames.get ("System", PROCESS.SYSTEM_UID);    //Query The Providerinfo information that satisfies the condition, and save him to AMs and Processrecord respectively--providers = mself.generateapplicationprociderslocked (APP);                //return Providerinfo liSt--msystemthread.installsystemprividers (providers);                                // , this is settingsprovider, because the UID for Settingsprovider is Android.uid.system,processname system. The same is true in framework-res.apk. These two apk are placed in the same process, improving communication efficiency. The system process or application process is no longer differentiated here, only interacting with Activitythread  activitymanagerservice.self (). Setwindowmanager ();        //Internal save wms//No Analysis  activitymanagerservice.self (). Systemready (); first stage--new Intent (intent.action_pre _boot_completed);--broadcastintentlocked ();                          ,         &NB Sp        //sends action_pre_boot_completed broadcasts, where it is temporarily not receiving the broadcast, and is estimated to be related to the system upgrade. Phase II--removeprocesslocked ();                          ,         &NB Sp        //Kill the application process that started before AMS is complete. --retrievesettings ();                          ,         &NB Sp           &NBSP      //Get configuration information from the settings database, only 4 settings are obtained: Debug_app,wait_for_debugger,always_finish_activities,font_ Scale Phase III--goingcallback.run ();                          ,         &NB Sp                //call callback function ———— Startsystemui ();                          ,         &NB Sp              //start systemui.apk, i.e. the status bar of the system ———— *.systemready ();                          ,         &NB Sp              //calls other services Systemready () ———— watchdog.getinstance (). Start ();                 Watchdog--addapplocke          //start-up------ D (info);                 &NBSP                      //        Applica start-up, and so on Tioninfo the process in which the corresponding application is located. In this case, the persistent 1 app will be launched. --mmainstack.resumetopactivitylocked (NULL);              //start the activity at the top of activitystack, and if empty, start home ———— Mservice.starthomeacgtivitylocked ();                //Because this is the initial boot of the system, Activitystack is empty. Mservice is AMS —————— (Activitystack.java) activityidleinternal ()        //after the HOME activity is started, the function is called ———————— mservice.finishbooting (); finishbooting function of AMS —————————— broadcasrintentlocked (New Intent (intent.action_boot_completed))//Send action_boot_completed 

Copyright, reproduced Please specify the source:

Http://www.cnblogs.com/sickworm/p/4220149.html

"Android Framework" Androidmanagerservice initialization process

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.