SystemServer.java
public static final void init2() {
//启动ServerThread
Thread thr = new ServerThread();
thr.setName("android.server.ServerThread");
thr.start();
}
ServerThread中
public void run() {
//启动SystemUi service
startSystemUi(contextF);
……
}
static final void startSystemUi(Context context) {
Intent intent = new Intent();
//component第一个参数是包名,第二个参数类名
intent.setComponent(new ComponentName("com.android.systemui",
"com.android.systemui.SystemUIService"));
//启动SystemUI的service
context.startService(intent);
}
SystemUIService.java
public class SystemUIService extends Service {
//在此,final代表SERVICES这个指针的指向不可变,但是指针指向的空间保存值可变
final Object[] SERVICES = new Object[] {
//要启动的Servic,将在下面加进去
0,
com.android.systemui.power.PowerUI.class,
};
//这个函数比较牛逼,主要是根据o来决定load 哪个class,不是对象!
private Class chooseClass(Object o) {
if (o instanceof Integer) {
final String cl = getString((Integer)o);
try {
return getClassLoader().loadClass(cl);
} catch (ClassNotFoundException ex) {
throw new RuntimeException(ex);
}
} else if (o instanceof Class) {
return (Class)o;
} else {
throw new RuntimeException("Unknown system ui service: " + o);
}
}
public void onCreate() {
IWindowManager wm = IWindowManager.Stub.asInterface(
ServiceManager.getService(Context.WINDOW_SERVICE));
try {
//根据statusbar是否隐藏决定要启动的service name
SERVICES[0] = wm.canStatusBarHide()
? R.string.config_statusBarComponent
: R.string.config_systemBarComponent;
} catch (RemoteException e) {
}
final int N = SERVICES.length;
mServices = new SystemUI[N];
for (int i=0; i<N; i++) {
Class cl = chooseClass(SERVICES[i]);
try {
//初始化实例对象
mServices[i] = (SystemUI)cl.newInstance();
} catch (IllegalAccessException ex) {
throw new RuntimeException(ex);
} catch (InstantiationException ex) {
throw new RuntimeException(ex);
}
mServices[i].mContext = this;
//从start启动
mServices[i].start();
}
}
}
之后开始了启动PhoneStatusBar.class和com.android.systemui.power.PowerUI.class
StatusBar和PowerUI就是这样启动的