SystemServer.java
publicstaticfinalvoidinit2(){
//启动ServerThread
Threadthr=newServerThread();
thr.setName("android.server.ServerThread");
thr.start();
}
ServerThread中
publicvoidrun(){
//启动SystemUiservice
startSystemUi(contextF);
……
}
staticfinalvoidstartSystemUi(Contextcontext){
Intentintent=newIntent();
//component第一个参数是包名,第二个参数类名
intent.setComponent(newComponentName("com.android.systemui",
"com.android.systemui.SystemUIService"));
//启动SystemUI的service
context.startService(intent);
}
SystemUIService.java
publicclassSystemUIServiceextendsService{
//在此,final代表SERVICES这个指针的指向不可变,但是指针指向的空间保存值可变
finalObject[]SERVICES=newObject[]{
//要启动的Servic,将在下面加进去
0,
com.android.systemui.power.PowerUI.class,
};
//这个函数比较牛逼,主要是根据o来决定load哪个class,不是对象!
privateClasschooseClass(Objecto){
if(oinstanceofInteger){
finalStringcl=getString((Integer)o);
try{
returngetClassLoader().loadClass(cl);
}catch(ClassNotFoundExceptionex){
thrownewRuntimeException(ex);
}
}elseif(oinstanceofClass){
return(Class)o;
}else{
thrownewRuntimeException("Unknownsystemuiservice:"+o);
}
}
publicvoidonCreate(){
IWindowManagerwm=IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
try{
//根据statusbar是否隐藏决定要启动的servicename
SERVICES[0]=wm.canStatusBarHide()
?R.string.config_statusBarComponent
:R.string.config_systemBarComponent;
}catch(RemoteExceptione){
}
finalintN=SERVICES.length;
mServices=newSystemUI[N];
for(inti=0;i<N;i++){
Classcl=chooseClass(SERVICES[i]);
try{
//初始化实例对象
mServices[i]=(SystemUI)cl.newInstance();
}catch(IllegalAccessExceptionex){
thrownewRuntimeException(ex);
}catch(InstantiationExceptionex){
thrownewRuntimeException(ex);
}
mServices[i].mContext=this;
//从start启动
mServices[i].start();
}
}
}
之后开始了启动PhoneStatusBar.class和com.android.systemui.power.PowerUI.class
StatusBar和PowerUI就是这样启动的