开机,init->init.rc->zygote->启动system_server进程. SystemServer->run()->startOtherService()->ActivityManagerService.systemReady()->startSystemUI();
public static void main(String[] args) {
new SystemServer().run();
}
// Start services.
try {
t.traceBegin("StartServices");
startBootstrapServices(t);
startCoreServices(t);
startOtherServices(t);
} catch (Throwable ex) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting system services", ex);
throw ex;
} finally {
t.traceEnd(); // StartServices
}
mActivityManagerService.systemReady(() -> {
t.traceBegin("StartSystemUI");
try {
startSystemUi(context, windowManagerF);
} catch (Throwable e) {
reportWtf("starting System UI", e);
}
t.traceEnd();
}, t);
private static void startSystemUi(Context context, WindowManagerService windowManager) {
PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
Intent intent = new Intent();
//PMS的内部类PackageManagerInternalImpl实现了PackageManagerInternal
intent.setComponent(pm.getSystemUiServiceComponent());
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
//Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.SYSTEM);
windowManager.onSystemUiStarted();
}
---PackageManagerService.PackageManagerInternalImpl
@Override
public ComponentName getSystemUiServiceComponent() {
return ComponentName.unflattenFromString(mContext.getResources().getString(
com.android.internal.R.string.config_systemUIServiceComponent));
}
<!-- SystemUi service component -->
<string name="config_systemUIServiceComponent" translatable="false"
>com.android.systemui/com.android.systemui.SystemUIService</string>
启动SystemUIService->SystemUIService.onCreate->SystemUIApplication.startServicesIfNeeded()->读取配置config_systemUIServiceComponents中的组件,依次调用这些组件的start()来启动状态栏,导航栏等组件 。
@Override
public void onCreate() {
super.onCreate();
// Start all of SystemUI
((SystemUIApplication) getApplication()).startServicesIfNeeded();
}
public void startServicesIfNeeded() {
String[] names = SystemUIFactory.getInstance().getSystemUIServiceComponents(getResources());
startServicesIfNeeded(/* metricsPrefix= */ "StartServices", names);
}
public String[] getSystemUIServiceComponents(Resources resources) {
return resources.getStringArray(R.array.config_systemUIServiceComponents);
}
<string-array name="config_systemUIServiceComponents" translatable="false">
315 <item>com.android.systemui.util.NotificationChannels</item>
316 <item>com.android.systemui.keyguard.KeyguardViewMediator</item>
317 <item>com.android.systemui.recents.Recents</item>
318 <item>com.android.systemui.volume.VolumeUI</item>
319 <item>com.android.systemui.statusbar.phone.StatusBar</item>
320 <item>com.android.systemui.usb.StorageNotification</item>
321 <item>com.android.systemui.power.PowerUI</item>
322 <item>com.android.systemui.media.RingtonePlayer</item>
323 <item>com.android.systemui.keyboard.KeyboardUI</item>
324 <item>com.android.systemui.shortcut.ShortcutKeyDispatcher</item>
325 <item>@string/config_systemUIVendorServiceComponent</item>
326 <item>com.android.systemui.util.leak.GarbageMonitor$Service</item>
327 <item>com.android.systemui.LatencyTester</item>
328 <item>com.android.systemui.globalactions.GlobalActionsComponent</item>
329 <item>com.android.systemui.ScreenDecorations</item>
330 <item>com.android.systemui.biometrics.AuthController</item>
331 <item>com.android.systemui.SliceBroadcastRelayHandler</item>
332<item>com.android.systemui.statusbar.notification.InstantAppNotifier</item>
333<item>com.android.systemui.theme.ThemeOverlayController</item>
334 <item>com.android.systemui.accessibility.WindowMagnification</item>
335 <item>com.android.systemui.accessibility.SystemActions</item>
336 <item>com.android.systemui.toast.ToastUI</item>
337 <item>com.android.systemui.wmshell.WMShell</item>
338 </string-array>