ActivityManagerService boot up sequence analysis,
ActivityManagerService (AMS) is the core service in the android system. It is mainly responsible for the startup, switching, scheduling, and application management and scheduling of four major components, its responsibilities are similar to the process management and scheduling modules in the operating system.
The call track of ActivityManagerService in system server is divided into the following four parts:
Part 1: AMS. main
Part 2: AMS. setSystemProcess
Part 3: AMS. installSystemProviders
Part 4: AMS. self (). systemReady
Start Process 1
The secondary image is reprinted from the network. Note:
Start Process 2
Part 1: AMS Main Function
1. created an AMS object.
2. Create an ActivityThread object that represents
Main thread
3. Get a context object, which corresponds to the application environment and
Framework-res.apk related;
This function creates an android runtime environment for the system_server process, which is the same as the application process.
Part 1-1: Create AMS object
Part 1-2: Create ActivityThread & context
Part 1-2: Create ActivityThread & Context
Part 1-2: Create ActivityThread & Context
Part 1-3: Create ActivityStack
Part 2: setSystemProcess
1. register the following services, such as ActivityManagerService, meminfo, and gfxinfo, to ServiceManager.
ServiceManager. addService ("activity", m, true );
ServiceManager. addService ("meminfo", new MemBinder (m ));
ServiceManager. addService ("gfxinfo", new GraphicsBinder (m ));
ServiceManager. addService ("dbinfo", new DbBinder (m ));
ServiceManager. addService ("cpuinfo", new CpuBinder (m ));
ServiceManager. addService ("permission", new PermissionController (m ));
2. query ApplicationInfo about the framework-res.apk through PKMS and use this to initialize the anroid Runtime Environment
// Query the ApplicationInfo with the package name "android" from PKMS. PKMS and AMS are in the same process,
However, the android runtime environment context (AMS-> binder-> PKMS) is used for implementation,
Ensures interface uniformity and scalability
ApplicationInfo info = mSelf. mContext. getPackageManager (). getApplicationInfo (
"Android", STOCK_PM_FLAGS );
// Perform secondary Initialization on the context and bind it with the obtained applicatoninfo.
MSystemThread. installSystemApplicationInfo (info );
3. Create the ProcessRecord management structure representing the system_server process, and merge the systemserver process
AMS Management
ProcessRecord app = mSelf. newProcessRecordLocked (
MSystemThread. getApplicationThread (), info,
Info. processName, false); creates a processrecord that contains power statistics and application information,
Process name (system), oom_adj, IApplicationThread, and application process communication information.
App. persistent = true; (Resident Process)
App. pid = MY_PID; process ID of system_server
App. maxAdj = ProcessList. SYSTEM_ADJ; (-16) highest priority
The two member variable structures used to save and manage processRecord in AMS.
MSelf. mProcessNames. put (app. processName, app. uid, app );
MSelf. mPidsSelfLocked. put (app. pid, app );
Adjust the scheduling priority and OOM_ADJ according to the current status of the system.
MSelf. updateLruProcessLocked (app, true );
Part 3: installSystemProviders
SettingsProvider.apk contains SettingsProvider, which is placed in system_serever for convenient query of configuration information for each service
1 In android, data inventory is usually stored in/data/[application package name]/databases
Directory
2. perform operations through URI, for example, data with the ID specified as 1 contact in content: // contacts/people/1
3. Related operations include query, insert, update, and delete operations.