- zygote进程启动SystemServer进程(如何启动有待进一步研究)
2.在SystemServer.java的main()函数中启动SystemServer进程
/**
* The main entry point from zygote.
*/
public static void main(String[] args) {
new SystemServer().run();
}
- 在SystemServer.java的run()(430)方法中启动启动服务、核心服务和其他服务
590 startBootstrapServices(t);
591 startCoreServices(t);
592 startOtherServices(t);
- 在SystemServer.java的startBootstrapServices()(704)方法中启动了PMS(PMS做了哪些事情,后续分析)
//848行,通过PackageManagerService.main()函数启动PMS(实际上其并不是一个进程,没有纯main()方法,它的main方法是有参数的)
t.traceBegin("StartPackageManagerService");
try {
Watchdog.getInstance().pauseWatchingCurrentThread("packagemanagermain");
mPackageManagerService = PackageManagerService.main(mSystemContext, installer,
mFactoryTestMode != FactoryTest.FACTORY_TEST_OFF, mOnlyCore);
} finally {
Watchdog.getInstance().resumeWatchingCurrentThread("packagemanagermain");
}
通过PackageManagerService.main()函数启动PMS(实际上其并不是一个进程,没有纯main()方法),例如Systemserver.java就是开启了一个进程,看看其main方法,由zygote进程开启
/**
* The main entry point from zygote.
*/
public static void main(String[] args) {
new SystemServer().run();
}
- 在SystemServer.java的startBootstrapServices()(704)方法中启动了AMS
//755行
//通过ActivityManagerService.Lifecycle.startService()方法,并传入ActivityTaskManagerService实例
// Activity manager runs the show.
t.traceBegin("StartActivityManager");
// 通过SystemServiceManager.startService反射ActivityTaskManagerService.java的构造方法,并实例化
ActivityTaskManagerService atm = mSystemServiceManager.startService(
ActivityTaskManagerService.Lifecycle.class).getService();
//ActivityManagerService通过自己的Lifecycle.startService方法实例化,实际上也是通过SystemServiceManager反射实例化的
mActivityManagerService = ActivityManagerService.Lifecycle.startService(
mSystemServiceManager, atm);
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
mWindowManagerGlobalLock = atm.getGlobalLock();
t.traceEnd();
- SystemServiceManager.java中startService()(136)反射实例化的代码
public <T extends SystemService> T startService(Class<T> serviceClass) {
try {
final String name = serviceClass.getName();
...
final T service;
try {
Constructor<T> constructor = serviceClass.getConstructor(Context.class);
service = constructor.newInstance(mContext);
}
startService(service);
return service;
} finally {
Trace.traceEnd(Trace.TRACE_TAG_SYSTEM_SERVER);
}
}
- ActivityManagerService和ActivityTaskManagerService的关系
在实例化并开始AMS服务时,将ATMS传入到了AMS中,AMS代理了ATMS,工作都是由ATMS完成
类似:
@Override
public int startActivity(IApplicationThread caller, String callingPackage,
Intent intent, String resolvedType, IBinder resultTo, String resultWho, int requestCode,
int startFlags, ProfilerInfo profilerInfo, Bundle bOptions) {
return mActivityTaskManager.startActivity(caller, callingPackage, null, intent,
resolvedType, resultTo, resultWho, requestCode, startFlags, profilerInfo, bOptions);
}
网友评论