Android14 SystemUI 启动流程(2)
/frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
启动实现了CoreStartable的实体类:如CentralSurfacesImpl等等,去start,去onBootCompleted/*** Makes sure that all the SystemUI services are running. If they are already running, this is a* no-op. This is needed to conditinally start all the services, as we only need to have it in* the main process.* <p>This method must only be called from the main thread.</p>*/public void startServicesIfNeeded() {final String vendorComponent = mInitializer.getVendorComponent(getResources());// Sort the startables so that we get a deterministic ordering.// TODO: make #start idempotent and require users of CoreStartable to call it.Map<Class<?>, Provider<CoreStartable>> sortedStartables = new TreeMap<>(Comparator.comparing(Class::getName));sortedStartables.putAll(mSysUIComponent.getStartables());sortedStartables.putAll(mSysUIComponent.getPerUserStartables());startServicesIfNeeded(sortedStartables, "StartServices", vendorComponent);}
1.这里通过依赖注入将CoreStartable实现类保存这个Map中!
/frameworks/base/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
/*** Returns {@link CoreStartable}s that should be started with the application.*/Map<Class<?>, Provider<CoreStartable>> getStartables();
2.这里是对super_notification_shade.xml(整个下拉菜单栏布局文件)
和status_bar.xml(桌面状态栏)
和navigation_bar.xml(导航栏)
等布局进行初始化
/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/dagger/StartCentralSurfacesModule.kt
@Module
interface StartCentralSurfacesModule {/** Start the CentralSurfaces */@Binds@IntoMap :将这个实现类注入到Map<Class<?>, Provider<CoreStartable>>中取@ClassKey(CentralSurfaces::class) :map的键是CentralSurfaces.classabstract fun bindsCentralSurfaces(centralSurfaces: CentralSurfacesImpl): CoreStartable
}
/frameworks/base/packages/SystemUI/src/com/android/systemui/dagger/SystemUICoreStartableModule.kt
/*** Collection of {@link CoreStartable}s that should be run on AOSP.*/
@Module(includes = [MultiUserUtilsModule::class,StartControlsStartableModule::class,StartBinderLoggerModule::class,WallpaperModule::class,
])
abstract class SystemUICoreStartableModule {/** Inject into AuthController. */@Binds@IntoMap@ClassKey(AuthController::class)abstract fun bindAuthController(service: AuthController): CoreStartable/** Inject into BiometricNotificationService */@Binds@IntoMap@ClassKey(BiometricNotificationService::class)abstract fun bindBiometricNotificationService(service: BiometricNotificationService): CoreStartable/** Inject into ClipboardListener. */@Binds@IntoMap@ClassKey(ClipboardListener::class)abstract fun bindClipboardListener(sysui: ClipboardListener): CoreStartable/** Inject into GlobalActionsComponent. */@Binds@IntoMap@ClassKey(GlobalActionsComponent::class)abstract fun bindGlobalActionsComponent(sysui: GlobalActionsComponent): CoreStartable/** Inject into InstantAppNotifier. */@Binds@IntoMap@ClassKey(InstantAppNotifier::class)abstract fun bindInstantAppNotifier(sysui: InstantAppNotifier): CoreStartable/** Inject into KeyboardUI. */@Binds@IntoMap@ClassKey(KeyboardUI::class)abstract fun bindKeyboardUI(sysui: KeyboardUI): CoreStartable/** Inject into MediaProjectionTaskSwitcherCoreStartable. */@Binds@IntoMap@ClassKey(MediaProjectionTaskSwitcherCoreStartable::class)abstract fun bindProjectedTaskListener(sysui: MediaProjectionTaskSwitcherCoreStartable): CoreStartable/** Inject into KeyguardBiometricLockoutLogger */@Binds@IntoMap@ClassKey(KeyguardBiometricLockoutLogger::class)abstract fun bindKeyguardBiometricLockoutLogger(sysui: KeyguardBiometricLockoutLogger): CoreStartable/** Inject into KeyguardViewMediator. */@Binds@IntoMap@ClassKey(KeyguardViewMediator::class)abstract fun bindKeyguardViewMediator(sysui: KeyguardViewMediator): CoreStartable/** Inject into LatencyTests. */@Binds@IntoMap@ClassKey(LatencyTester::class)abstract fun bindLatencyTester(sysui: LatencyTester): CoreStartable/** Inject into NotificationChannels. */@Binds@IntoMap@ClassKey(NotificationChannels::class)@PerUserabstract fun bindNotificationChannels(sysui: NotificationChannels): CoreStartable/** Inject into PowerUI. */@Binds@IntoMap@ClassKey(PowerUI::class)abstract fun bindPowerUI(sysui: PowerUI): CoreStartable/** Inject into Recents. */@Binds@IntoMap@ClassKey(Recents::class)abstract fun bindRecents(sysui: Recents): CoreStartable/** Inject into ImmersiveModeConfirmation. */@Binds@IntoMap@ClassKey(ImmersiveModeConfirmation::class)abstract fun bindImmersiveModeConfirmation(sysui: ImmersiveModeConfirmation): CoreStartable/** Inject into RingtonePlayer. */@Binds@IntoMap@ClassKey(RingtonePlayer::class)abstract fun bind(sysui: RingtonePlayer): CoreStartable/** Inject into ScreenDecorations. */@Binds@IntoMap@ClassKey(ScreenDecorations::class)abstract fun bindScreenDecorations(sysui: ScreenDecorations): CoreStartable/** Inject into GesturePointerEventHandler. */@Binds@IntoMap@ClassKey(GesturePointerEventListener::class)abstract fun bindGesturePointerEventListener(sysui: GesturePointerEventListener): CoreStartable/** Inject into SessionTracker. */@Binds@IntoMap@ClassKey(SessionTracker::class)abstract fun bindSessionTracker(service: SessionTracker): CoreStartable/** Inject into ShortcutKeyDispatcher. */@Binds@IntoMap@ClassKey(ShortcutKeyDispatcher::class)abstract fun bindShortcutKeyDispatcher(sysui: ShortcutKeyDispatcher): CoreStartable/** Inject into SliceBroadcastRelayHandler. */@Binds@IntoMap@ClassKey(SliceBroadcastRelayHandler::class)abstract fun bindSliceBroadcastRelayHandler(sysui: SliceBroadcastRelayHandler): CoreStartable/** Inject into StorageNotification. */@Binds@IntoMap@ClassKey(StorageNotification::class)abstract fun bindStorageNotification(sysui: StorageNotification): CoreStartable/** Inject into SystemActions. */@Binds@IntoMap@ClassKey(SystemActions::class)abstract fun bindSystemActions(sysui: SystemActions): CoreStartable/** Inject into ThemeOverlayController. */@Binds@IntoMap@ClassKey(ThemeOverlayController::class)abstract fun bindThemeOverlayController(sysui: ThemeOverlayController): CoreStartable/** Inject into ToastUI. */@Binds@IntoMap@ClassKey(ToastUI::class)abstract fun bindToastUI(service: ToastUI): CoreStartable/** Inject into MediaOutputSwitcherDialogUI. */@Binds@IntoMap@ClassKey(MediaOutputSwitcherDialogUI::class)abstract fun MediaOutputSwitcherDialogUI(sysui: MediaOutputSwitcherDialogUI): CoreStartable/** Inject into VolumeUI. */@Binds@IntoMap@ClassKey(VolumeUI::class)abstract fun bindVolumeUI(sysui: VolumeUI): CoreStartable/** Inject into WindowMagnification. */@Binds@IntoMap@ClassKey(WindowMagnification::class)abstract fun bindWindowMagnification(sysui: WindowMagnification): CoreStartable/** Inject into WMShell. */@Binds@IntoMap@ClassKey(WMShell::class)abstract fun bindWMShell(sysui: WMShell): CoreStartable/** Inject into KeyguardLiftController. */@Binds@IntoMap@ClassKey(KeyguardLiftController::class)abstract fun bindKeyguardLiftController(sysui: KeyguardLiftController): CoreStartable/** Inject into MediaTttSenderCoordinator. */@Binds@IntoMap@ClassKey(MediaTttSenderCoordinator::class)abstract fun bindMediaTttSenderCoordinator(sysui: MediaTttSenderCoordinator): CoreStartable/** Inject into MediaTttChipControllerReceiver. */@Binds@IntoMap@ClassKey(MediaTttChipControllerReceiver::class)abstract fun bindMediaTttChipControllerReceiver(sysui: MediaTttChipControllerReceiver): CoreStartable/** Inject into MediaTttCommandLineHelper. */@Binds@IntoMap@ClassKey(MediaTttCommandLineHelper::class)abstract fun bindMediaTttCommandLineHelper(sysui: MediaTttCommandLineHelper): CoreStartable/** Inject into ChipbarCoordinator. */@Binds@IntoMap@ClassKey(ChipbarCoordinator::class)abstract fun bindChipbarController(sysui: ChipbarCoordinator): CoreStartable/** Inject into RearDisplayDialogController) */@Binds@IntoMap@ClassKey(RearDisplayDialogController::class)abstract fun bindRearDisplayDialogController(sysui: RearDisplayDialogController): CoreStartable/** Inject into StylusUsiPowerStartable) */@Binds@IntoMap@ClassKey(StylusUsiPowerStartable::class)abstract fun bindStylusUsiPowerStartable(sysui: StylusUsiPowerStartable): CoreStartable@Binds@IntoMap@ClassKey(PhysicalKeyboardCoreStartable::class)abstract fun bindKeyboardCoreStartable(listener: PhysicalKeyboardCoreStartable): CoreStartable/** Inject into MuteQuickAffordanceCoreStartable*/@Binds@IntoMap@ClassKey(MuteQuickAffordanceCoreStartable::class)abstract fun bindMuteQuickAffordanceCoreStartable(sysui: MuteQuickAffordanceCoreStartable): CoreStartable/**Inject into DreamMonitor */@Binds@IntoMap@ClassKey(DreamMonitor::class)abstract fun bindDreamMonitor(sysui: DreamMonitor): CoreStartable/**Inject into AssistantAttentionMonitor */@Binds@IntoMap@ClassKey(AssistantAttentionMonitor::class)abstract fun bindAssistantAttentionMonitor(sysui: AssistantAttentionMonitor): CoreStartable@Binds@IntoMap@ClassKey(KeyguardViewConfigurator::class)abstract fun bindKeyguardViewConfigurator(impl: KeyguardViewConfigurator): CoreStartable@Binds@IntoMap@ClassKey(LockscreenWallpaper::class)abstract fun bindLockscreenWallpaper(impl: LockscreenWallpaper): CoreStartable@Binds@IntoMap@ClassKey(ScrimController::class)abstract fun bindScrimController(impl: ScrimController): CoreStartable@Binds@IntoMap@ClassKey(StatusBarHeadsUpChangeListener::class)abstract fun bindStatusBarHeadsUpChangeListener(impl: StatusBarHeadsUpChangeListener): CoreStartable
}
startable.start();启动每个CoreStartable实现类的start()方法
/frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
private void startServicesIfNeeded(Map<Class<?>, Provider<CoreStartable>> startables,String metricsPrefix,String vendorComponent) {if (mServicesStarted) {return;}mServices = new CoreStartable[startables.size() + (vendorComponent == null ? 0 : 1)];int i = 0;for (Map.Entry<Class<?>, Provider<CoreStartable>> entry : startables.entrySet()) {String clsName = entry.getKey().getName();int j = i; // Copied to make lambda happy.timeInitialization(clsName,() -> mServices[j] = startStartable(clsName, entry.getValue()),log,metricsPrefix);i++;}for (i = 0; i < mServices.length; i++) {CoreStartable service = mServices[i];if (mBootCompleteCache.isBootComplete()) {notifyBootCompleted(service);}if (service.isDumpCritical()) {dumpManager.registerCriticalDumpable(service.getClass().getName(), service);} else {dumpManager.registerNormalDumpable(service.getClass().getName(), service);}}}private static CoreStartable startStartable(String clsName, Provider<CoreStartable> provider) {if (DEBUG) Log.d(TAG, "loading: " + clsName);if (Trace.isEnabled()) {Trace.traceBegin(Trace.TRACE_TAG_APP, "Provider<" + clsName + ">.get()");}CoreStartable startable = provider.get();Trace.endSection();return startStartable(startable);}private static CoreStartable startStartable(CoreStartable startable) {if (DEBUG) Log.d(TAG, "running: " + startable);if (Trace.isEnabled()) {Trace.traceBegin(Trace.TRACE_TAG_APP, startable.getClass().getSimpleName() + ".start()");}startable.start();Trace.endSection();return startable;}