anroid SystemServer启动中调用ActivityManagerService.main(int factoryTest)流程
来源:互联网 发布:在线程序员计算器 编辑:程序博客网 时间:2024/06/04 19:16
[1]android系统启动第一次调用ActivityManagerService中main方法设置系统上下环境,
并保存在 mContext成员变量中
SystemServer启动后会调用ActivityManagerService中的main函数:
frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
publicstatic final Context main(int factoryTest){
AThread thr=new AThread();//new了一个ActivityManagerService类保存在成员变量mService中
thr.start();
synchronized(thr){
while(thr.mService== null){
try{
thr.wait();
}catch(InterruptedException e){
}
}
}
ActivityManagerService m= thr.mService;//将AThread中的成员变量mService给ActivityManagerServer成员变量m
mSelf = m; //将ActivityManagerServer对象m附值给成员变量mSelf
ActivityThread at= ActivityThread.systemMain();//启动一个systemMain ActivityThread
mSystemThread= at;
Context context= at.getSystemContext(); //将systemMain的上下环境给context变量,之后再传给ActivityManagerServer成员变量mContext
m.mContext= context; //附值给mContext
m.mFactoryTest= factoryTest;
m.mMainStack=new ActivityStack(m, context,true);
m.mBatteryStatsService.publish(context);
m.mUsageStatsService.publish(context);
synchronized(thr){
thr.mReady=true;
thr.notifyAll();
}
m.startRunning(null, null, null, null);
return context;
}
[2] ActivityThread.systemMain:
framework/base/core/java/android/app/ActivityThread.java
publicstatic final ActivityThread systemMain(){
ActivityThread thread= new ActivityThread();//调用一个空的构造函数,生成对象,系统线程,此线程在Home Activity创建之前生成.
thread.attach(true);//
return thread;
}
[3]执行attach初始化context
private finalvoid attach(boolean system){
sThreadLocal.set(this);
mSystemThread= system;
if(!system){
ViewRoot.addFirstDrawHandler(new Runnable(){
publicvoid run(){
ensureJitEnabled();
}
});
android.ddm.DdmHandleAppName.setAppName("<pre-initialized>");
RuntimeInit.setApplicationObject(mAppThread.asBinder());
IActivityManager mgr= ActivityManagerNative.getDefault();
try{
mgr.attachApplication(mAppThread);
}catch(RemoteException ex){
}
}else{
// Don't set application object here -- if the system crashes,
// we can't display an alert, we just want to die die die.
android.ddm.DdmHandleAppName.setAppName("system_process");
try{
mInstrumentation =new Instrumentation();
ContextImpl context =new ContextImpl();
context.init(getSystemContext().mPackageInfo, null, this);
Application app = Instrumentation.newApplication(Application.class, context);
mAllApplications.add(app);
mInitialApplication = app;
app.onCreate();//启动app
}catch(Exception e){
thrownew RuntimeException(
"Unable to instantiate Application():"+ e.toString(), e);
}
}
ViewRoot.addConfigCallback(new ComponentCallbacks(){
publicvoid onConfigurationChanged(Configuration newConfig){
synchronized (mPackages){
// We need to apply this change to the resources
// immediately, because upon returning the view
// hierarchy will be informed about it.
if(applyConfigurationToResourcesLocked(newConfig)){
// This actually changed the resources! Tell
// everyone about it.
if(mPendingConfiguration== null||
mPendingConfiguration.isOtherSeqNewer(newConfig)){
mPendingConfiguration = newConfig;
queueOrSendMessage(H.CONFIGURATION_CHANGED, newConfig);
}
}
}
}
publicvoid onLowMemory(){
}
});
}
[4]接着看getSystemContext:
public ContextImpl getSystemContext(){
synchronized(this){
if(mSystemContext== null){
ContextImpl context =ContextImpl.createSystemContext(this);
//调用ContextImpl静态方法,生成当前对象的上下环境对象
LoadedApk info = new LoadedApk(this, "android", context, null);
context.init(info, null,this);
context.getResources().updateConfiguration(
getConfiguration(), getDisplayMetricsLocked(false));
mSystemContext = context;
//Slog.i(TAG, "Created system resources " + context.getResources()
// + ": " + context.getResources().getConfiguration());
}
}
return mSystemContext;
}
- anroid SystemServer启动中调用ActivityManagerService.main(int factoryTest)流程
- Android SystemServer 启动流程
- SystemServer 启动流程
- SystemServer进程启动流程
- Android SystemServer 启动流程
- ActivityManagerService启动流程
- android 启动流程到SystemServer
- SystemServer启动流程之SystemServer启动(二)
- SystemServer启动流程之SystemServer分析(三)
- Android启动流程分析(十二) SystemServer
- Android5 Zygote 与 SystemServer 启动流程分析
- Android SystemServer启动流程源码解析
- SystemServer进程启动流程的理解
- Android源码(2) --- SystemServer进程启动流程
- Android SystemServer启动流程源码解析
- ActivityManagerService分析——AMS启动流程
- SystemServer启动流程之Zygote启动(一)
- SystemServer中启动的android服务
- 外部类类名.this.varName 访问外部类实例属性 ; 通过 this.varName 访问外内部类实例的属性
- [UNIX环境高级编程]apue.h头文件的配置
- mysql将字符转换成数字
- 一个VC6的工程转换为VS2008的工程后,编译找不到而且不能升级vc90.pdb文件的问题解决方法 2010-9-28 14:00
- linux语言支持(关于在terminal中显示乱码的问题)
- anroid SystemServer启动中调用ActivityManagerService.main(int factoryTest)流程
- 60-思考题(3)-将1到9 这九个数字分成若干个数,满足一定的算式
- iOS ASIHTTPRequest详解
- 算法系列之一 : Google方程式
- jdk windows非官方下载路径
- CART算法学习及实现
- 关于const修饰符
- How to make an SDL window the child of another window in Win32
- C#好压命令行操作类