SystemUI启动流程梳理

SystemUI简介:
SystemU包含功能有:导航栏,状态栏,通知栏,近期列表等(R.array.config_systemUIServiceComponents)
所有 SystemUIService 都是继承自 SystemUI.class , SystemUI.class 是一个抽象类
- <item>com.android.systemui.util.NotificationChannels</item> 通知信息
- <item>com.android.systemui.keyguard.KeyguardViewMediator</item> 锁屏
- <item>com.android.systemui.recents.Recents</item> 近期列表
- Android 10之后近期列表的显示被移到Launcher里面了。在Launcher3的一个 类中TouchInteractionService.java IBinder mMyBinder = new IOverviewProxy.Stub() 通过AIDL的方法与systemUI通信
- ————————————————
- <item>com.android.systemui.volume.VolumeUI</item> 声音UI显示
- <item>com.android.systemui.statusbar.phone.StatusBar</item> 状态栏及下拉面板
- <item>com.android.systemui.usb.StorageNotification</item> usb通知管理
- <item>com.android.systemui.power.PowerUI</item> 电源UI显示管理
- <item>com.android.systemui.media.RingtonePlayer</item> 播放铃声
- <item>com.android.systemui.keyboard.KeyboardUI</item>键盘UI
- <item>com.android.systemui.shortcut.ShortcutKeyDispatcher</item>快捷方式
- <item>@string/config_systemUIVendorServiceComponent</item>厂商相关定制
- <item>com.android.systemui.util.leak.GarbageMonitor$Service</item>垃圾监测器
- <item>com.android.systemui.LatencyTester</item> 延迟测试仪
- <item>com.android.systemui.globalactions.GlobalActionsComponent</item> 关机界面的显示、全局控制
- <item>com.android.systemui.ScreenDecorations</item>屏幕装饰
- <item>com.android.systemui.biometrics.AuthController</item>生物识别
- <item>com.android.systemui.SliceBroadcastRelayHandler</item> 切片广播
- <item>com.android.systemui.statusbar.notification.InstantAppNotifier</item>
- <item>com.android.systemui.theme.ThemeOverlayController</item>
- <item>com.android.systemui.accessibility.WindowMagnification</item>
- <item>com.android.systemui.accessibility.SystemActions</item>
- <item>com.android.systemui.toast.ToastUI</item> Toast
- <item>com.android.systemui.wmshell.WMShell</item>
|
二、代码控制流程
2.1、相关类
- frameworks/base/services/java/com/android/server/SystemServer.java
- frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
- SystemUI/src/com/android/systemui/SystemUIService.java
- frameworks/base/packages/SystemUI/res/values/config.xml
- frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUI.ja
|
2.2、启动流程
navigation_bar_window.xml:
SystemServer.startSystemUi()
- private static void startSystemUi(Context context, WindowManagerService windowManager) {
- PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
- Intent intent = new Intent();
- intent.setComponent(pm.getSystemUiServiceComponent());
- intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
- //Slog.d(TAG, "Starting service: " + intent);
- context.startServiceAsUser(intent, UserHandle.SYSTEM);
- windowManager.onSystemUiStarted();
- }
|
SystemUIService.onCreate()
- public void onCreate() {
- super.onCreate();
-
- // Start all of SystemUI
- ((SystemUIApplication) getApplication()).startServicesIfNeeded();
-
- // Finish initializing dump logic
- mLogBufferFreezer.attach(mBroadcastDispatcher);
-
- // If configured, set up a battery notification
- if (getResources().getBoolean(R.bool.config_showNotificationForUnknownBatteryState)) {
- mBatteryStateNotifier.startListening();
- }
- ……
- // Bind the dump service so we can dump extra info during a bug report
- startServiceAsUser(
- new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
- UserHandle.SYSTEM);
- }
SystemUIApplication. startServicesIfNeeded()
- private void startServicesIfNeeded(String metricsPrefix, String[] services) {
- if (mServicesStarted) {
- return;
- }
- mServices = new SystemUI[services.length];
-
- if (!mBootCompleteCache.isBootComplete()) {
- // check to see if maybe it was already completed long before we began
- // see ActivityManagerService.finishBooting()
- if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
- mBootCompleteCache.setBootComplete();
- if (DEBUG) {
- Log.v(TAG, "BOOT_COMPLETED was already sent");
- }
- }
- }
-
- final DumpManager dumpManager = mSysUIComponent.createDumpManager();
-
- Log.v(TAG, "Starting SystemUI services for user " +
- Process.myUserHandle().getIdentifier() + ".");
- TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
- Trace.TRACE_TAG_APP);
- log.traceBegin(metricsPrefix);
- final int N = services.length;
- for (int i = 0; i < N; i++) {
- String clsName = services[i];
- if (DEBUG) Log.d(TAG, "loading: " + clsName);
- log.traceBegin(metricsPrefix + clsName);
- long ti = System.currentTimeMillis();
- try {
- SystemUI obj = mComponentHelper.resolveSystemUI(clsName);
- if (obj == null) {
- Constructor constructor = Class.forName(clsName).getConstructor(Context.class);
- obj = (SystemUI) constructor.newInstance(this);
- }
- mServices[i] = obj;
- } catch (ClassNotFoundException
- | NoSuchMethodException
- | IllegalAccessException
- | InstantiationException
- | InvocationTargetException ex) {
- throw new RuntimeException(ex);
- }
-
- if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
- mServices[i].start();
- log.traceEnd();
-
- // Warn if initialization of component takes too long
- ti = System.currentTimeMillis() - ti;
- if (ti > 1000) {
- Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms");
- }
- if (mBootCompleteCache.isBootComplete()) {
- mServices[i].onBootCompleted();
- }
-
- dumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
- }
- mSysUIComponent.getInitController().executePostInitTasks();
- log.traceEnd();
-
- mServicesStarted = true;
- }
|