1、概要
对于Phone来说SystemUI指的是:StatusBar(状态栏)、NavigationBar(导航栏)、Keyguard(锁屏)等等。
启动后Phone界面上的信号,蓝牙标志,Wifi标志等等这些状态显示标志都会在StatusBar上显示。当我们的设备开机后,首先需要给用户呈现的就是各种界面同时也包括了我们的SystemUI,因此对于整个Android系统来说,SystemUI都有举足轻重的作用。
本篇主要解析SystemUI中StatusBar的代码流程。
2、SystemUI截图
贴几张垃圾图,供新人更好的了解SystemUI
3、SystemUI的大致启动流程图(网上找的,与最新的处理流程并没有太大出入)
4、SystemUI启动流程代码解析
4.1、启动SystemUIService
SystemServer.java
从AndroidManifest.xml中可以看到SystemUIService,
<service android:name="SystemUIService"
android:exported="true"
/>
上面的SystemUIService是在SystemServer中启动的
static final void startSystemUi(Context context) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.systemui",
"com.android.systemui.SystemUIService"));
//Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.OWNER);
}
4.2、启动相应的服务
SystemUIService.java
在SystemUIService中的onCreate()方法中调用了SystemUIApplication的startServicesIfNeeded()方法.
public void onCreate() {
super.onCreate();
((SystemUIApplication) getApplication()).startServicesIfNeeded();
}
而在SystemUIApplication中,首先把需要启动的services添加到一个数组中
private final Class<?>[] SERVICES = new Class[] {
com.android.systemui.keyguard.KeyguardViewMediator.class,
com.android.systemui.recent.Recents.class,
com.android.systemui.volume.VolumeUI.class,
com.android.systemui.statusbar.SystemBars.class,
com.android.systemui.usb.StorageNotification.class,
com.android.systemui.power.PowerUI.class,
com.android.systemui.media.RingtonePlayer.class
};
然后实例化一个对象:
private final SystemUI[] mServices = new SystemUI[SERVICES.length];
然后正式启动需要的服务:
public void startServicesIfNeeded() {
.....
Log.v(TAG, "Starting SystemUI services.");
final int N = SERVICES.length;
for (int i=0; i<N; i++) {
Class<?> cl = SERVICES[i];
if (DEBUG) Log.d(TAG, "loading: " + cl);
try {