SystemUI启动
SystemUI的启动是在systemServer(frameworks/base/services/java/com/android/server/SystemServer.java)中启动的,当ActivityManagerService启动完毕之后开始运行:
static final void startSystemUi(Context context, WindowManagerService windowManager) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.systemui",
"com.android.systemui.SystemUIService"));
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
//Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.SYSTEM);
windowManager.onSystemUiStarted();
}
设置好包名和service类名后启动服务。
回到SystemUI的工程中(frameworks/base/packages/SystemUI)在启动SystemUIService之前先启动Application,SystemUIApplication中的onCreate方法
//全套流程
private final Class<?>[] SERVICES = new Class[] {
Dependency.class, // 对其他模块提供组件支持
NotificationChannels.class, //
CommandQueue.CommandQueueStart.class,
KeyguardViewMediator.class, // 锁屏界面
Recents.class, //最近使用的Activity
VolumeUI.class, //音量相关的UI
Divider.class, // 多窗口分屏
SystemBars.class, //系统状态栏,包括 StatusBar 、 NavigationBar、下拉消息、快捷菜单等等
StorageNotification.class, //存储相关的通知
PowerUI.class, //电池电量弹窗
RingtonePlayer.class, // 铃声控制
KeyboardUI.class, //外接键盘UI
PipUI.class,
ShortcutKeyDispatcher.class,
VendorServices.class,
GarbageMonitor.Service.class,
LatencyTester.class,
GlobalActionsComponent.class,
RoundedCorners.class, //
};
//子流程
private final Class<?>[] SERVICES_PER_USER = new Class[] {
Dependency.class,
NotificationChannels.class,
Recents.class
};
...
@Override
public void onCreate() {
super.onCreate();
if (Process.myUserHandle().equals(UserHandle.SYSTEM)) {
//如果是由系统启动的
//注册开机完成广播,保证开机完成后能对每个mServices[i]调用onBootCompleted()
} else {
//非由系统启动的
startServicesIfNeeded(SERVICES_PER_USER); //只启动一些子流程
}
}
再查看SystemUIService类中onCreate方法:
((SystemUIApplication) getApplication()).startServicesIfNeeded();
继续跟进至SystemUIApplication类
public void startServicesIfNeeded() {
startServicesIfNeeded(SERVICES); //启动全套流程
}
private void startServicesIfNeeded(Class<?>[] services) {
...
final int N = services.length;
for (int i = 0; i < N; i++) {
mServices[i].start();
if (mBootCompleted) {
mServices[i].onBootCompleted();
}
}
...
//当有组件连接移除时候的回调
}
至此SystemUI启动完成,其实就是依次执行每个模块的start方法和onBootCompleted方法。