android4.0 statusbar的启动

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"));

//启动SystemUIservice

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就是这样启动的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值