赞
踩
SystemServer会启动系统运行所需的众多核心服务和普通服务,systemui由System Server启动
- private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
- t.traceBegin("startOtherServices");
- mSystemServiceManager.updateOtherServicesStartIndex();
- ......
- t.traceBegin("StartSystemUI");
- try {
- startSystemUi(context, windowManagerF);
- } catch (Throwable e) {
- reportWtf("starting System UI", e);
- }
- t.traceEnd();
- t.traceEnd(); // startOtherServices
- }
-
- 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();
- }
pm.getSystemUiServiceComponent()在frameworks/base/services/core/java/com/android/server/pm/PackageManagerInternalBase.java
- @Override
- @Deprecated
- public final ComponentName getSystemUiServiceComponent() {
- return ComponentName.unflattenFromString(getContext().getResources().getString(
- com.android.internal.R.string.config_systemUIServiceComponent));
- }
config_systemUIServiceComponent定义在frameworks/base/core/res/res/values/config.xml
- <!-- SystemUi service component -->
- <string name="config_systemUIServiceComponent" translatable="false"
- >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
- public void onCreate() {
- super.onCreate();
-
- // Start all of SystemUI
- ((SystemUIApplication) getApplication()).startServicesIfNeeded();
-
- // Finish initializing dump logic
- mLogBufferFreezer.attach(mBroadcastDispatcher);
- mDumpHandler.init();
-
- // If configured, set up a battery notification
- if (getResources().getBoolean(R.bool.config_showNotificationForUnknownBatteryState)) {
- mBatteryStateNotifier.startListening();
- }
-
- // For debugging RescueParty
- if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) {
- throw new RuntimeException();
- }
-
- if (Build.IS_DEBUGGABLE) {
- // b/71353150 - looking for leaked binder proxies
- BinderInternal.nSetBinderProxyCountEnabled(true);
- BinderInternal.nSetBinderProxyCountWatermarks(1000,900);
- BinderInternal.setBinderProxyCountCallback(
- new BinderInternal.BinderProxyLimitListener() {
- @Override
- public void onLimitReached(int uid) {
- Slog.w(SystemUIApplication.TAG,
- "uid " + uid + " sent too many Binder proxies to uid "
- + Process.myUid());
- }
- }, mMainHandler);
- }
-
- // Bind the dump service so we can dump extra info during a bug report
- startServiceAsUser(
- new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
- UserHandle.SYSTEM);
- }
frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
- public void startServicesIfNeeded() {
- final String vendorComponent = SystemUIFactory.getInstance()
- .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(SystemUIFactory.getInstance().getStartableComponents());
- sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponentsPerUser());
- startServicesIfNeeded(
- sortedStartables, "StartServices", vendorComponent);
- }
sortedStartables.putAll(SystemUIFactory.getInstance().getStartableComponents())这地方和之前的版本不一样,这里的 sortedStartables 是一个Map,里面存放待启动的各种SystemUI服务。
frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIFactory.java
- /**
- * Returns the list of {@link CoreStartable} components that should be started at startup.
- */
- public Map<Class<?>, Provider<CoreStartable>> getStartableComponents() {
- return mSysUIComponent.getStartables();//这里将会返回要启动的组件列表
- }
frameworks/base/packages/SystemUI/src/com/android/systemui/dagger/SysUIComponent.java
- @SysUISingleton
- @Subcomponent(modules = {
- DefaultComponentBinder.class,
- DependencyProvider.class,
- SystemUIBinder.class,
- SystemUIModule.class,
- SystemUICoreStartableModule.class,
- ReferenceSystemUIModule.class})
- public interface SysUIComponent {
- ......
- /**
- * Returns {@link CoreStartable}s that should be started with the application.
- */
- Map<Class<?>, Provider<CoreStartable>> getStartables();
- ......
- }
使用了dagger的 @IntoMap注入相关类。只要是 继承 CoreStartable 类的都将会被注入。SystemUICoreStartableModule.class这个module中说明哪些类需要注入
com.android.keyguard.KeyguardBiometricLockoutLogger com.android.systemui.LatencyTester com.android.systemui.ScreenDecorations com.android.systemui.SliceBroadcastRelayHandler com.android.systemui.accessibility.SystemActions com.android.systemui.accessibility.WindowMagnification com.android.systemui.biometrics.AuthController com.android.systemui.broadcast.BroadcastDispatcherStartable com.android.systemui.clipboardoverlay.ClipboardListener com.android.systemui.globalactions.GlobalActionsComponent com.android.systemui.keyboard.KeyboardUI com.android.systemui.keyguard.KeyguardViewMediator com.android.systemui.log.SessionTracker com.android.systemui.media.RingtonePlayer com.android.systemui.power.PowerUI com.android.systemui.recents.Recents com.android.systemui.shortcut.ShortcutKeyDispatcher com.android.systemui.statusbar.notification.InstantAppNotifier com.android.systemui.statusbar.notification.interruption.KeyguardNotificationVisibilityProvider com.android.systemui.statusbar.phone.CentralSurfaces com.android.systemui.statusbar.phone.KeyguardLiftController com.android.systemui.theme.ThemeOverlayController com.android.systemui.toast.ToastUI com.android.systemui.usb.StorageNotification com.android.systemui.util.NotificationChannels com.android.systemui.util.leak.GarbageMonitor com.android.systemui.volume.VolumeUI com.android.systemui.wmshell.WMShell
上面是SystemUI加载的的类。
接着回到 SystemUIApplication 的 startServicesIfNeeded() 方法
- private void startServicesIfNeeded(
- Map<Class<?>, Provider<CoreStartable>> startables,
- String metricsPrefix,
- String vendorComponent) {
- if (mServicesStarted) {
- return;
- }
- mServices = new CoreStartable[startables.size() + (vendorComponent == null ? 0 : 1)];
-
- 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");
- }
- }
- }
-
- mDumpManager = 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);
-
- 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()),// 这里就和之前版本一样,调用start()方法启动对应服务。
- log,
- metricsPrefix);
- i++;
- }
-
- if (vendorComponent != null) {
- timeInitialization(
- vendorComponent,
- () -> mServices[mServices.length - 1] =
- startAdditionalStartable(vendorComponent),
- log,
- metricsPrefix);
- }
-
- for (i = 0; i < mServices.length; i++) {
- if (mBootCompleteCache.isBootComplete()) {
- mServices[i].onBootCompleted();
- }
-
- mDumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
- }
- mSysUIComponent.getInitController().executePostInitTasks();
- log.traceEnd();
-
- mServicesStarted = true;
- FeatureOptions.sShouldShowUI = true;
- }
先写到这里,后面看明白了记录
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。