当前位置:   article > 正文

Android13 SystemUI启动过程_android13 systemui启动流程

android13 systemui启动流程

SystemServer会启动系统运行所需的众多核心服务和普通服务,systemui由System Server启动

  1. private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
  2. t.traceBegin("startOtherServices");
  3. mSystemServiceManager.updateOtherServicesStartIndex();
  4. ......
  5. t.traceBegin("StartSystemUI");
  6. try {
  7. startSystemUi(context, windowManagerF);
  8. } catch (Throwable e) {
  9. reportWtf("starting System UI", e);
  10. }
  11. t.traceEnd();
  12. t.traceEnd(); // startOtherServices
  13. }
  14. private static void startSystemUi(Context context, WindowManagerService windowManager) {
  15. PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
  16. Intent intent = new Intent();
  17. intent.setComponent(pm.getSystemUiServiceComponent());
  18. intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
  19. //Slog.d(TAG, "Starting service: " + intent);
  20. context.startServiceAsUser(intent, UserHandle.SYSTEM);
  21. windowManager.onSystemUiStarted();
  22. }

pm.getSystemUiServiceComponent()在frameworks/base/services/core/java/com/android/server/pm/PackageManagerInternalBase.java

  1. @Override
  2. @Deprecated
  3. public final ComponentName getSystemUiServiceComponent() {
  4. return ComponentName.unflattenFromString(getContext().getResources().getString(
  5. com.android.internal.R.string.config_systemUIServiceComponent));
  6. }

config_systemUIServiceComponent定义在frameworks/base/core/res/res/values/config.xml

  1. <!-- SystemUi service component -->
  2. <string name="config_systemUIServiceComponent" translatable="false"
  3. >com.android.systemui/com.android.systemui.SystemUIService</string>

SystemUI代码路径在AOSP/framework/base/packages/SystemUI

SystemServer启动SystemUIService,在onCreate()中通过ystemUIApplication启动相关service

frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java

  1. public void onCreate() {
  2. super.onCreate();
  3. // Start all of SystemUI
  4. ((SystemUIApplication) getApplication()).startServicesIfNeeded();
  5. // Finish initializing dump logic
  6. mLogBufferFreezer.attach(mBroadcastDispatcher);
  7. mDumpHandler.init();
  8. // If configured, set up a battery notification
  9. if (getResources().getBoolean(R.bool.config_showNotificationForUnknownBatteryState)) {
  10. mBatteryStateNotifier.startListening();
  11. }
  12. // For debugging RescueParty
  13. if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) {
  14. throw new RuntimeException();
  15. }
  16. if (Build.IS_DEBUGGABLE) {
  17. // b/71353150 - looking for leaked binder proxies
  18. BinderInternal.nSetBinderProxyCountEnabled(true);
  19. BinderInternal.nSetBinderProxyCountWatermarks(1000,900);
  20. BinderInternal.setBinderProxyCountCallback(
  21.         new BinderInternal.BinderProxyLimitListener() {
  22.                     @Override
  23.                     public void onLimitReached(int uid) {
  24.                         Slog.w(SystemUIApplication.TAG,
  25.                                 "uid " + uid + " sent too many Binder proxies to uid "
  26.                                 + Process.myUid());
  27.                     }
  28.                 }, mMainHandler);
  29.     }
  30.     // Bind the dump service so we can dump extra info during a bug report
  31.     startServiceAsUser(
  32.             new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
  33.             UserHandle.SYSTEM);
  34. }

frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java

  1. public void startServicesIfNeeded() {
  2.     final String vendorComponent = SystemUIFactory.getInstance()
  3.             .getVendorComponent(getResources());
  4.     // Sort the startables so that we get a deterministic ordering.
  5.     // TODO: make #start idempotent and require users of CoreStartable to call it.
  6.     Map<Class<?>, Provider<CoreStartable>> sortedStartables = new TreeMap<>(
  7.             Comparator.comparing(Class::getName));
  8.     sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponents());
  9.     sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponentsPerUser());
  10.     startServicesIfNeeded(
  11.             sortedStartables, "StartServices", vendorComponent);
  12. }

sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponents())这地方和之前的版本不一样,这里的 sortedStartables 是一个Map,里面存放待启动的各种SystemUI服务。

frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java

  1. /**
  2. * Returns the list of {@link CoreStartable} components that should be started at startup.
  3. */
  4. public Map<Class<?>, Provider<CoreStartable>> getStartableComponents() {
  5.     return mSysUIComponent.getStartables();//这里将会返回要启动的组件列表
  6. }

frameworks/base/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java

  1. @SysUISingleton
  2. @Subcomponent(modules = {
  3.         DefaultComponentBinder.class,
  4.         DependencyProvider.class,
  5.         SystemUIBinder.class,
  6.         SystemUIModule.class,
  7.         SystemUICoreStartableModule.class,
  8.         ReferenceSystemUIModule.class})
  9. public interface SysUIComponent {
  10.     ......
  11.     /**
  12.     * Returns {@link CoreStartable}s that should be started with the application.
  13.     */
  14.     Map<Class<?>, Provider<CoreStartable>> getStartables();
  15.     ......
  16. }

使用了dagger的 @IntoMap注入相关类。只要是 继承 CoreStartable 类的都将会被注入。SystemUICoreStartableModule.class这个module中说明哪些类需要注入

  1. com.android.keyguard.KeyguardBiometricLockoutLogger
  2. com.android.systemui.LatencyTester
  3. com.android.systemui.ScreenDecorations
  4. com.android.systemui.SliceBroadcastRelayHandler
  5. com.android.systemui.accessibility.SystemActions
  6. com.android.systemui.accessibility.WindowMagnification
  7. com.android.systemui.biometrics.AuthController
  8. com.android.systemui.broadcast.BroadcastDispatcherStartable
  9. com.android.systemui.clipboardoverlay.ClipboardListener
  10. com.android.systemui.globalactions.GlobalActionsComponent
  11. com.android.systemui.keyboard.KeyboardUI
  12. com.android.systemui.keyguard.KeyguardViewMediator
  13. com.android.systemui.log.SessionTracker
  14. com.android.systemui.media.RingtonePlayer
  15. com.android.systemui.power.PowerUI
  16. com.android.systemui.recents.Recents
  17. com.android.systemui.shortcut.ShortcutKeyDispatcher
  18. com.android.systemui.statusbar.notification.InstantAppNotifier
  19. com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider
  20. com.android.systemui.statusbar.phone.CentralSurfaces
  21. com.android.systemui.statusbar.phone.KeyguardLiftController
  22. com.android.systemui.theme.ThemeOverlayController
  23. com.android.systemui.toast.ToastUI
  24. com.android.systemui.usb.StorageNotification
  25. com.android.systemui.util.NotificationChannels
  26. com.android.systemui.util.leak.GarbageMonitor
  27. com.android.systemui.volume.VolumeUI
  28. com.android.systemui.wmshell.WMShell

上面是SystemUI加载的的类。

接着回到 SystemUIApplication 的 startServicesIfNeeded() 方法

  1. private void startServicesIfNeeded(
  2.         Map<Class<?>, Provider<CoreStartable>> startables,
  3.         String metricsPrefix,
  4.         String vendorComponent) {
  5.     if (mServicesStarted) {
  6.         return;
  7.     }
  8.     mServices = new CoreStartable[startables.size() + (vendorComponent == null ? 0 : 1)];
  9.     if (!mBootCompleteCache.isBootComplete()) {
  10.         // check to see if maybe it was already completed long before we began
  11.         // see ActivityManagerService.finishBooting()
  12.         if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
  13.             mBootCompleteCache.setBootComplete();
  14.             if (DEBUG) {
  15.                 Log.v(TAG, "BOOT_COMPLETED was already sent");
  16.             }
  17.         }
  18.     }
  19.     mDumpManager = mSysUIComponent.createDumpManager();
  20.     Log.v(TAG, "Starting SystemUI services for user " +
  21.             Process.myUserHandle().getIdentifier() + ".");
  22.     TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
  23.             Trace.TRACE_TAG_APP);
  24.     log.traceBegin(metricsPrefix);
  25.     int i = 0;
  26.     for (Map.Entry<Class<?>, Provider<CoreStartable>> entry : startables.entrySet()) {
  27.         String clsName = entry.getKey().getName();
  28.         int j = i; // Copied to make lambda happy.
  29.         timeInitialization(
  30.                 clsName,
  31.                 () -> mServices[j] = startStartable(clsName, entry.getValue()),// 这里就和之前版本一样,调用start()方法启动对应服务。
  32.                 log,
  33.                 metricsPrefix);
  34.         i++;
  35.     }
  36.     if (vendorComponent != null) {
  37.         timeInitialization(
  38.                 vendorComponent,
  39.                 () -> mServices[mServices.length - 1] =
  40.                         startAdditionalStartable(vendorComponent),
  41.                 log,
  42.                 metricsPrefix);
  43.     }
  44.     for (i = 0; i < mServices.length; i++) {
  45.         if (mBootCompleteCache.isBootComplete()) {
  46.             mServices[i].onBootCompleted();
  47.         }
  48.         mDumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
  49.     }
  50.     mSysUIComponent.getInitController().executePostInitTasks();
  51.     log.traceEnd();
  52.     mServicesStarted = true;
  53.     FeatureOptions.sShouldShowUI = true;
  54. }

先写到这里,后面看明白了记录

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号