当前位置:网站首页>AMS Series 1 - AMS startup process
AMS Series 1 - AMS startup process
2022-07-03 11:10:00 【MrPeng1991】
1. Start process
https://www.cnblogs.com/fanglongxiang/p/13594986.html
The system starts , AMS Before the starting point :
After system startup Zygote Process first fork Out SystemServer process , Enter into SystemServer:main()->run()->startBootstrapServices() Start boot service , And then complete AMS Start of
ZygoteInit.java:main()->forkSystemServer()->Zygote.java:forkSystemServer()->nativeForkSystemServer()->com_android_internal_os_Zygote.cpp:com_android_internal_os_Zygote_nativeForkSystemServer()->ZygoteInit.java->handleSystemServerProcess()
1. by SystemServer Process creation Android Running environment ,
createSystemContext() -> new ActvityThread()-->attach ->getSystemContext ->createSystemContext
2. start-up AMS
3. take SystemServer The process is incorporated into AMS In the process management system setSystemProcess()// take framewok-res.apk Information added to SystemServer Process LoadedApk in , structure SystemServe Process ProcessRecord, Save to AMS in , In order to AMS Unified Process Management
installSystemProvider() // install SystemServer In process SettingsProvider.apk
4. AMS Start up , Notify the service or application to complete the follow-up work , Or start a new process directly .AMS.systemReady() // Many services or application processes have to wait AMS After the start-up work , To start or carry out some follow-up work ,AMS Is in the SystemReady() in , Notify or start these waiting services and application processes , For example, start the desktop . etc.
Several important classes :
- Activity.java all Activity Parent class of
- ActivityManager AMS The client of , Provided to the user for calling api
- ActiveService control service start-up Restart, etc.
- ProcessRecord Record the information of each process
- ActivityRecord activity Record of object information
- ActivityStack management activity Lifecycle and stack
- TaskRecord Task stack record , Manage the application of a task activity
- ActivityTaskManagerService/ActivityTaskManagerInternal management activity Start up and scheduling of
1.1 SystemSserver start-up
SystemServer.java
public static void main(String[] args) {
new SystemServer().run();
}
private void run() {
...
//1. initialization System Context
createSystemContext();
//2. establish SystemServiceManager object , Mainly used for management SystemService The creation and start-up of ,
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.setStartInfo(mRuntimeRestart,
mRuntimeStartElapsedTime, mRuntimeStartUptime);
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
...
//3. Start the service
startBootstrapServices(); // Start boot service , In which ATM and AMS service , adopt AMS install Installer、 initialization Power, Set the system process, etc .
startCoreServices(); // Start core services , I will focus on
startOtherServices(); // Start other services ,AMS After starting , Complete subsequent desktop startup and other operations
...
}
1.2 System Context initialization
1.2.1 createSystemContext
stay SystemServer Of run Function , Start up AMS Before , Called createSystemContext Letter , Mainly used for initialization System Context and SystemUi Context, And set the theme
call createSystemContext After the completion of , Complete the following
- Get one ActivityThread object , Represents the current process ( This is the system process ) The main thread
- Get one Context object , Yes SystemServer for , It contains application The running environment and framewokr-res.apk of .
private void createSystemContext() {
ActivityThread activityThread = ActivityThread.systemMain(); // Reference resources [4.2.1]
// obtain system context
mSystemContext = activityThread.getSystemContext();
// Set system theme
mSystemContext.setTheme(DEFAULT_SYSTEM_THEME);
// obtain systemui context
final Context systemUiContext = activityThread.getSystemUiContext();
// Set up systemUI The theme
systemUiContext.setTheme(DEFAULT_SYSTEM_THEME);
}
createSystemContext() Created two contexts , System context and SystemUi context. These two are very important , It will pass in AMS in , This is where they were created .
Next, let's take a look at... When creating two contexts above systemMain()
//ActivityThread.java
public static ActivityThread systemMain() {
// The system process on low-memory devices do not get to use hardware
// accelerated drawing, since this can add too much overhead to the
// process.
if (!ActivityManager.isHighEndGfx()) {
ThreadedRenderer.disable(true);
} else {
ThreadedRenderer.enableForegroundTrimming();
}
// obtain ActivityThread object
ActivityThread thread = new ActivityThread();
thread.attach(true, 0);
return thread;
}
1.2.2 ActivityThread objects creating
ActivityThread Is the main thread of the current process ,SystemServer On initialization ,ActivityThread.systemMain() What is created is the system process SystemServer The main thread , because SystemServer There are also some systems running in APK, for example framewor-res.apk,SettingsProvider.apk, therefore SystemServer It can also be regarded as a special application process .
AMS Responsible for managing and scheduling processes , therefore AMS Need to pass through Binder Mechanism and application process communication , So Android Provides a IppliactionThread structure , This interface defines AMS And the interaction function between application processes .
AcitityThread The constructor of is relatively simple , obtain ResourceManager Singleton object , The key is its member variables .
public final class ActivityThread extends ClientTransactionHandler {
...
// Defined AMS Interface with application communication , Get ApplicationThread The object of
final ApplicationThread mAppThread = new ApplicationThread();
// Own your own looper, explain ActivityThread It can really represent the event processing thread
final Looper mLooper = Looper.myLooper();
//H Inherit Handler,ActivityThread A large number of event processing rely on this Handler
final H mH = new H();
// Used to save the process ActivityRecord
final ArrayMap<IBinder, ActivityClientRecord> mActivities = new ArrayMap<>();
// Used to save Service
final ArrayMap<IBinder, Service> mServices = new ArrayMap<>();
Used to save Application
final ArrayList<Application> mAllApplications
= new ArrayList<Application>();
// Constructors
@UnsupportedAppUsage
ActivityThread() {
mResourcesManager = ResourcesManager.getInstance();
}
}
1.2.3 [ActivityThread.java] attach
For system processes ,ActivityThread Of attach The most important work of function , Is to create Instrumentation,Application and Context
attach(true,0) Here is the system process ( Application startup will also go ,system by false It's the application process ), establish ActivityThread Key members of :Instrumentation、 Application and Context
private void attach(boolean system, long startSeq) {
mSystemThread = system;
// Incoming system by 0
if (!system) {
// Processing flow of application process
...
} else {
// Processing flow of system process , This situation only exists in SystemServer In dealing with
// establish ActivityThread Key members of :Instrumentation、 Application and Context
mInstrumentation = new Instrumentation();
mInstrumentation.basicInit(this);
// Create a system of Context,
ContextImpl context = ContextImpl.createAppContext(
this, getSystemContext().mPackageInfo);
// call LoadedApk Of makeApplication function
mInitialApplication = context.mPackageInfo.makeApplication(true, null);
mInitialApplication.onCreate();
}
}
- Instrumentation: Very important base class , Other classes will be initialized first , The system creates it first , Then create other components through it . Allow the detection system to interact with all applications . application AndroidManifest.xml Label definition implementation .
- Context: Context ,context yes Android An abstract class in , It is used to maintain the global information of the application running environment . adopt Context You can access the resources and classes of the application , Even system level operations , For example, start Activity, Send a broadcast, etc .ActivityThread Of attach Function through this line of code to create the application corresponding Context
ContextImpl context = ContextImpl.createAppContext(this, getSystemContext().mPackageInfo);
What is created here is a LoadApk(packagenam yes android, namely framewor-res.apk), In this way, we get Context object - Application: Save the global state of the application , stay ActivityThread in , For system processes , The following code creates the initial Application
mInitialApplication = context.mPackageInfo.makeApplication(true, null);
mInitialApplication.onCreate();
1.2.4 [ContextImpl.java] getSystemContext()
public ContextImpl getSystemContext() {
synchronized (this) {
if (mSystemContext == null) {
// call ContextImpl The static function of createSystemContext
mSystemContext = ContextImpl.createSystemContext(this);
}
return mSystemContext;
}
}
createSysteContext The content of is to create a LoadApk, Then initialize a ContextImpl object . Created LoadApk Corresponding packageName by ’‘android’, That is to say framewok-res.apk. Because of the APK Only for SystemServer process , So create Context Is defined as System Context, Now it's time to LoadApk I haven't got frame-res.apk Actual information .
When pkms start-up , After the corresponding parsing ,ams Will reset this LoadedApk.
static ContextImpl createSystemContext(ActivityThread mainThread) {
// establish LoadedApk class , Represents a loaded into the system APK
// Pay attention to the LoadedApk It's just an empty shell
//PKMS It's not started yet , Cannot get effective ApplicationInfo
LoadedApk packageInfo = new LoadedApk(mainThread);
// Get ContextImpl The object of
ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, null, 0,
null, null);
// Initialize resource information
context.setResources(packageInfo.getResources());
context.mResources.updateConfiguration(context.mResourcesManager.getConfiguration(),
context.mResourcesManager.getDisplayMetrics());
return context;
}
1.3 SystemServiceManager establish
systemServiceManager Objects are mainly used to manage SystemService The creation of , Start the life cycle ,SystemService Class is an abstract class .
stay SystemServiceManager Are created through reflection SystemService Object's , And in startService(@NonNull final SystemService service) In the method , Will SystemService Add to mServices in , And call onStart() Method
private void run() {
...
//1. establish SystemServiceManager object , Reference resources [4.3.1]
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.setStartInfo(mRuntimeRestart,
mRuntimeStartElapsedTime, mRuntimeStartUptime);
//2. start-up SystemServiceManager service , Reference resources [4.3.2]
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
...
}
public class SystemServiceManager {
...
private final Context mContext;
private final ArrayList<SystemService> mServices = new ArrayList<SystemService>();
...
SystemServiceManager(Context context) {
mContext = context;
}
public SystemService startService(String className) {
final Class<SystemService> serviceClass;
try {
// By reflection, according to the class name , Get class object
serviceClass = (Class<SystemService>)Class.forName(className);
} catch (ClassNotFoundException ex) {
Slog.i(TAG, "Starting " + className);
...
}
return startService(serviceClass);
}
public <T extends SystemService> T startService(Class<T> serviceClass) {
try {
final String name = serviceClass.getName();
// Create the service.
final T service;
...
service = constructor.newInstance(mContext);
...
startService(service);
return service;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}
}
public void startService(@NonNull final SystemService service) {
// Register it.
mServices.add(service);
// Start it.
long time = SystemClock.elapsedRealtime();
try {
service.onStart(); // Call onStart() Method to complete the service startup
} catch (RuntimeException ex) {
throw new RuntimeException("Failed to start service " + service.getClass().getName()
+ ": onStart threw an exception", ex);
}
}
}
[LocalServices.java] addService(SystemServiceManager.class, mSystemServiceManager);
hold SystemServiceManager The object of is added to the global registry of the local service
public final class LocalServices {
private LocalServices() {
}
private static final ArrayMap<Class<?>, Object> sLocalServiceObjects =
new ArrayMap<Class<?>, Object>();
// Return the local service instance object that implements the specified interface
@SuppressWarnings("unchecked")
public static <T> T getService(Class<T> type) {
synchronized (sLocalServiceObjects) {
return (T) sLocalServiceObjects.get(type);
}
}
// Add the service instance of the specified interface to the global registry of the local service
public static <T> void addService(Class<T> type, T service) {
synchronized (sLocalServiceObjects) {
if (sLocalServiceObjects.containsKey(type)) {
throw new IllegalStateException("Overriding service registration");
}
sLocalServiceObjects.put(type, service);
}
}
// Delete service instance , Can only be used in testing .
public static <T> void removeServiceForTest(Class<T> type) {
synchronized (sLocalServiceObjects) {
sLocalServiceObjects.remove(type);
}
}
}
private void run() {
...
//1. establish SystemServiceManager object , Reference resources [4.3.1]
mSystemServiceManager = new SystemServiceManager(mSystemContext);
mSystemServiceManager.setStartInfo(mRuntimeRestart,
mRuntimeStartElapsedTime, mRuntimeStartUptime);
//2. start-up SystemServiceManager service , Reference resources [4.3.2]
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
...
}
private void startBootstrapServices() {
...
/*ActivityTaskManagerService yes Android 10 Newly introduced changes , It is also a system service , Used to manage Activity Start up and scheduling , Including its container (task、stacks、displays etc. ). This article is mainly about AMS Start of , Android 10 Put the original AMS Chinese vs activity The management and scheduling of have moved to ActivityTaskManagerService in , The position is placed wm Next ( See the full path above ), therefore AMS Responsible for the other of the four components 3 individual (service, broadcast, contentprovider) Management and scheduling of .*/
atm = mSystemServiceManager.startService(
ActivityTaskManagerService.Lifecycle.class).getService();
// Start the service ActivityManagerService, abbreviation AMS
//Lifecycle yes AMS The inner class of ActivityManagerService.Lifecycle.startService() The final return is mService, That is, the created AMS object .
mActivityManagerService = ActivityManagerService.Lifecycle.startService(
mSystemServiceManager, atm);
// install Installer
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
// initialization PowerManager
mActivityManagerService.initPowerManagement();
// Set system process
mActivityManagerService.setSystemProcess();
}
private void startOtherServices() {
...
// install SettingsProvider.apk
mActivityManagerService.installSystemProviders();
mActivityManagerService.setWindowManager(wm);
//AMS Start up , Finish the follow-up work , For example, start the desktop
mActivityManagerService.systemReady(() -> {
...
}, BOOT_TIMINGS_TRACE_LOG);
...
}
//frameworks/base/services/core/java/com/android/server/SystemServiceManager.java
public <T extends SystemService> T startService(Class<T> serviceClass) {
try {
final String name = serviceClass.getName();
// Create the service.
if (!SystemService.class.isAssignableFrom(serviceClass)) {
throw new RuntimeException("Failed to create " + name
+ ": service must extend " + SystemService.class.getName());
}
final T service;
try {
Constructor<T> constructor = serviceClass.getConstructor(Context.class);
service = constructor.newInstance(mContext);
} ......
startService(service);
return service;
}
}
public void startService(@NonNull final SystemService service) {
// Register it.
mServices.add(service);
// Start it.
long time = SystemClock.elapsedRealtime();
try {
service.onStart();
} catch (RuntimeException ex) {
......
}
warnIfTooLong(SystemClock.elapsedRealtime() - time, service, "onStart");
}
SystemServiceManager Through reflection , Called ActivityManagerService.Lifecycle Construction method of , then startService(service) And finally called service.onStart(), namely ActivityManagerService.Lifecycle.onStart().
Call by reflection ActivityManagerService.Lifecycle Construction method of , The main new ActivityManagerService() establish AMS object , What have you done? You need to know ;ActivityManagerService.Lifecycle.onStart() It's a direct call AMS Of start() Method ;
new ActivityManagerService()
// Note: This method is invoked on the main thread but may need to attach various
// handlers to other threads. So take care to be explicit about the looper.
public ActivityManagerService(Context systemContext, ActivityTaskManagerService atm) {
LockGuard.installLock(this, LockGuard.INDEX_ACTIVITY);
mInjector = new Injector();
// System context , Is in SystemServer process fork Come out and pass createSystemContext() Created , I.e SystemServer The process is consistent
mContext = systemContext;
mFactoryTest = FactoryTest.getMode();
// The main thread of the system process sCurrentActivityThread, Here is systemMain() Created in the ActivityThread object . I.e. also with SystemServer Same .
mSystemThread = ActivityThread.currentActivityThread();
mUiContext = mSystemThread.getSystemUiContext();
Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());
mHandlerThread = new ServiceThread(TAG,
THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
mHandlerThread.start();
// Handle AMS News handle
mHandler = new MainHandler(mHandlerThread.getLooper());
//UiHandler Corresponding to Android Medium Ui Threads
mUiHandler = mInjector.getUiHandler(this);
mProcStartHandlerThread = new ServiceThread(TAG + ":procStart",
THREAD_PRIORITY_FOREGROUND, false /* allowIo */);
mProcStartHandlerThread.start();
mProcStartHandler = new Handler(mProcStartHandlerThread.getLooper());
mConstants = new ActivityManagerConstants(mContext, this, mHandler);
final ActiveUids activeUids = new ActiveUids(this, true /* postChangesToAtm */);
mProcessList.init(this, activeUids);
mLowMemDetector = new LowMemDetector(this);
mOomAdjuster = new OomAdjuster(this, mProcessList, activeUids);
// Broadcast policy parameters
final BroadcastConstants foreConstants = new BroadcastConstants(
Settings.Global.BROADCAST_FG_CONSTANTS);
foreConstants.TIMEOUT = BROADCAST_FG_TIMEOUT;//10s
final BroadcastConstants backConstants = new BroadcastConstants(
Settings.Global.BROADCAST_BG_CONSTANTS);
backConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;//60s
final BroadcastConstants offloadConstants = new BroadcastConstants(
Settings.Global.BROADCAST_OFFLOAD_CONSTANTS);
offloadConstants.TIMEOUT = BROADCAST_BG_TIMEOUT;
// by default, no "slow" policy in this queue
offloadConstants.SLOW_TIME = Integer.MAX_VALUE;
mEnableOffloadQueue = SystemProperties.getBoolean(
"persist.device_config.activity_manager_native_boot.offload_queue_enabled", false);
// Create several broadcast related objects , Foreground broadcast 、 Background broadcast 、offload I don't know TODO.
mFgBroadcastQueue = new BroadcastQueue(this, mHandler,
"foreground", foreConstants, false);
mBgBroadcastQueue = new BroadcastQueue(this, mHandler,
"background", backConstants, true);
mOffloadBroadcastQueue = new BroadcastQueue(this, mHandler,
"offload", offloadConstants, true);
mBroadcastQueues[0] = mFgBroadcastQueue;
mBroadcastQueues[1] = mBgBroadcastQueue;
mBroadcastQueues[2] = mOffloadBroadcastQueue;
// establish ActiveServices object , management ServiceRecord
mServices = new ActiveServices(this);
// establish ProviderMap object , management ContentProviderRecord
mProviderMap = new ProviderMap(this);
mPackageWatchdog = PackageWatchdog.getInstance(mUiContext);
mAppErrors = new AppErrors(mUiContext, this, mPackageWatchdog);
final File systemDir = SystemServiceManager.ensureSystemDir();
// TODO: Move creation of battery stats service outside of activity manager service.
mBatteryStatsService = new BatteryStatsService(systemContext, systemDir,
BackgroundThread.get().getHandler());
mBatteryStatsService.getActiveStatistics().readLocked();
mBatteryStatsService.scheduleWriteToDisk();
mOnBattery = DEBUG_POWER ? true
: mBatteryStatsService.getActiveStatistics().getIsOnBattery();
mBatteryStatsService.getActiveStatistics().setCallback(this);
mOomAdjProfiler.batteryPowerChanged(mOnBattery);
mProcessStats = new ProcessStatsService(this, new File(systemDir, "procstats"));
mAppOpsService = mInjector.getAppOpsService(new File(systemDir, "appops.xml"), mHandler);
mUgmInternal = LocalServices.getService(UriGrantsManagerInternal.class);
mUserController = new UserController(this);
mPendingIntentController = new PendingIntentController(
mHandlerThread.getLooper(), mUserController);
if (SystemProperties.getInt("sys.use_fifo_ui", 0) != 0) {
mUseFifoUiScheduling = true;
}
mTrackingAssociations = "1".equals(SystemProperties.get("debug.track-associations"));
mIntentFirewall = new IntentFirewall(new IntentFirewallInterface(), mHandler);
// obtain ActivityTaskManagerService The object of , call ATM.initialize
mActivityTaskManager = atm;
mActivityTaskManager.initialize(mIntentFirewall, mPendingIntentController,
DisplayThread.get().getLooper());
mAtmInternal = LocalServices.getService(ActivityTaskManagerInternal.class);
mProcessCpuThread = new Thread("CpuTracker") {
......
};
mHiddenApiBlacklist = new HiddenApiSettings(mHandler, mContext);
// Join in Watchdog Monitoring of
Watchdog.getInstance().addMonitor(this);
Watchdog.getInstance().addThread(mHandler);
// bind background threads to little cores
// this is expected to fail inside of framework tests because apps can't touch cpusets directly
// make sure we've already adjusted system_server's internal view of itself first
updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE);
try {
Process.setThreadGroupAndCpuset(BackgroundThread.get().getThreadId(),
Process.THREAD_GROUP_SYSTEM);
Process.setThreadGroupAndCpuset(
mOomAdjuster.mAppCompact.mCompactionThread.getThreadId(),
Process.THREAD_GROUP_SYSTEM);
} catch (Exception e) {
Slog.w(TAG, "Setting background thread cpuset failed");
}
}
AMS Construction method of , It mainly completes the construction of some objects and the initialization of variables , You can see the notes above .
- Of the three components (service、broadcast、provider) Management and scheduling (activity Moved to ActivityTaskManagerService in , But it is bound here ActivityTaskManagerService object ).
- Monitor memory 、 The battery 、 jurisdiction ( You can see appops.xml) And performance related objects or variables .mLowMemDetector、mBatteryStatsService、mProcessStats、mAppOpsService、mProcessCpuThread etc. .
AMS Of start()
private void start() {
// Remove all process groups
removeAllProcessGroups();
// start-up CPU Monitor threads
mProcessCpuThread.start();
// Register battery 、 Rights management related services
mBatteryStatsService.publish();
mAppOpsService.publish(mContext);
Slog.d("AppOps", "AppOpsService published");
LocalServices.addService(ActivityManagerInternal.class, new LocalService());
mActivityTaskManager.onActivityManagerInternalAdded();
mUgmInternal.onActivityManagerInternalAdded();
mPendingIntentController.onActivityManagerInternalAdded();
// Wait for the synchronized block started in mProcessCpuThread,
// so that any other access to mProcessCpuTracker from main thread
// will be blocked during mProcessCpuTracker initialization.
try {
mProcessCpuInitLatch.await();
} catch (InterruptedException e) {
Slog.wtf(TAG, "Interrupted wait during start", e);
Thread.currentThread().interrupt();
throw new IllegalStateException("Interrupted wait during start");
}
}
//=============================================================================
ActivityManagerService.java:
public void setSystemServiceManager(SystemServiceManager mgr) {
mSystemServiceManager = mgr;
}
//=============================================================================
ActivityManagerService.java:
public void setInstaller(Installer installer) {
mInstaller = installer;
}
//=============================================================================
ActivityManagerService.java:
public void initPowerManagement() {
mActivityTaskManager.onInitPowerManagement();
mBatteryStatsService.initPowerManagement();
mLocalPowerManager = LocalServices.getService(PowerManagerInternal.class);
}
//=============================================================================
public void setSystemProcess() {
try {
// Registration service activity
ServiceManager.addService(Context.ACTIVITY_SERVICE, this, /* allowIsolated= */ true,
DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PRIORITY_NORMAL | DUMP_FLAG_PROTO);
// Registration service procstats, Process status
ServiceManager.addService(ProcessStats.SERVICE_NAME, mProcessStats);
// Registration service meminfo, Memory information
ServiceManager.addService("meminfo", new MemBinder(this), /* allowIsolated= */ false,
DUMP_FLAG_PRIORITY_HIGH);
// Registration service gfxinfo, Image information
ServiceManager.addService("gfxinfo", new GraphicsBinder(this));
// Registration service dbinfo, database information
ServiceManager.addService("dbinfo", new DbBinder(this));
if (MONITOR_CPU_USAGE) {
// Registration service cpuinfo,cpu Information
ServiceManager.addService("cpuinfo", new CpuBinder(this),
/* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL);
}
// Registration service permission and processinfo, Permissions and process information
ServiceManager.addService("permission", new PermissionController(this));
ServiceManager.addService("processinfo", new ProcessInfoService(this));
// obtain “android” Applied ApplicationInfo, And load it into mSystemThread
ApplicationInfo info = mContext.getPackageManager().getApplicationInfo(
"android", STOCK_PM_FLAGS | MATCH_SYSTEM_ONLY);
mSystemThread.installSystemApplicationInfo(info, getClass().getClassLoader());
// establish ProcessRecord Maintain information about the process
synchronized (this) {
ProcessRecord app = mProcessList.newProcessRecordLocked(info, info.processName,
false,
0,
new HostingRecord("system"));
app.setPersistent(true);
app.pid = MY_PID;//
app.getWindowProcessController().setPid(MY_PID);
app.maxAdj = ProcessList.SYSTEM_ADJ;
app.makeActive(mSystemThread.getApplicationThread(), mProcessStats);
mPidsSelfLocked.put(app);//
mProcessList.updateLruProcessLocked(app, false, null);
updateOomAdjLocked(OomAdjuster.OOM_ADJ_REASON_NONE);
}
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(
"Unable to find android system package", e);
}
// Start watching app ops after we and the package manager are up and running.
mAppOpsService.startWatchingMode(AppOpsManager.OP_RUN_IN_BACKGROUND, null,
new IAppOpsCallback.Stub() {
@Override public void opChanged(int op, int uid, String packageName) {
if (op == AppOpsManager.OP_RUN_IN_BACKGROUND && packageName != null) {
if (mAppOpsService.checkOperation(op, uid, packageName)
!= AppOpsManager.MODE_ALLOWED) {
runInBackgroundDisabled(uid);
}
}
}
});
}
What is mentioned above is startBootstrapServices(),AMS The startup of is in it . Last , When guiding services 、 Core services 、 After other services are completed , Would call AMS Medium systemReady() Method .
summary :
- After system startup Zygote Process first fork Out of SystemServer process
- SystemServer->run()->createSystemContext(), establish ActivityThread object , Running environment mSystemContext,systemUiContext
- SystemServer->sun->startBootstrapService()->ActivityManagerService.Lifecycle.startService:AMS In the boot service startup method , By constructor new ActivityManagerService Do some object creation and initialization , except act The outer three components manage and schedule object creation , Memory , The battery , jurisdiction , performance ,cpu And other related objects such as monitoring ,start Start the service ( Remove process group , start-up cpu Threads , Registration rights , Battery and other services ).
- SystemServer->run()->startBootstrapServices()->setSystemServiceManager().setInstaller,initPowerManagerment(),setSystemProcess(),AMS After creation, a series of related initialization and settings are performed .setSystemProcess(): take framework-res.apk, Information added to SystemServer Process LoadedApk in , And created SystemServer Process ProcessRecord, Add to mPidSelfLocked from AMS Unified management .
- startOtherServices() AMS Follow up work after startup , Main call systemReady() Method ,systemui stay goingCallback Finish in , When the desktop application starts , Send the power on broadcast ACTION_BOOT_COMPLETED Only this and nothing more .
边栏推荐
- 如何让让别人畏惧你
- 我对测试工作的一些认识(资深测试人员总结)
- Crawl with requests
- Qt:qss custom qgroupbox instance
- php如何解决高并发问题
- 2021 reading summary (continuously updating)
- 嵌入式軟件測試怎麼實現自動化測試?
- How did I grow up in the past eight years as a test engineer of meituan? I hope technicians can gain something after reading it
- 做软件测试三年,薪资不到20K,今天,我提出了辞职…
- POI excel 单元格换行
猜你喜欢
封装一个koa分布式锁中间件来解决幂等或重复请求的问题
The normal one inch is 25.4 cm, and the image field is 16 cm
T5 attempt
Do you really need automated testing?
Redis notes 01: Introduction
QT: QSS custom qtreeview instance
有赞CTO崔玉松:有赞Jarvis核心目标是使产品变得更加聪明和可靠
Basic theoretical knowledge of software testing -- app testing
独家分析 | 关于简历和面试的真 相
字节跳动大裁员,测试工程师差点遭团灭:大厂招人背后的套路,有多可怕?
随机推荐
Internet Socket (非)阻塞write/read n个字节
《通信软件开发与应用》
Test what the leader should do
Cause: org. apache. ibatis. builder. Builderexception: error parsing SQL mapper configuration problem analysis
IIS修改配置信息后不生效
17K薪资要什么水平?来看看95后测试工程师的面试全过程…
Comment réaliser des tests automatisés pour les tests logiciels embarqués?
公司里只有一个测试是什么体验?听听他们怎么说吧
What are the strengths of "testers"?
My understanding of testing (summarized by senior testers)
Crawl with requests
QT: QSS custom qtoolbutton instance
如何让让别人畏惧你
Qt:qss custom qlistview instance
Qt:qss custom qmenubar instance
Qt:qss custom qgroupbox instance
Qt:qss custom qlineedit instance
软件测试工程师的5年之痒,讲述两年突破瓶颈经验
Extern keyword
php如何解决高并发问题