最近看了一个wifi, ethernet切换,状态栏图表显示的问题。记录一下追踪由于网络状态变化,SystemUI 状态栏网络图标显示的流程。
先看一下SystemUI这边:
/frameworks/base/services/java/com/android/server/SystemServer.java
/**
* Starts a miscellaneous grab bag of stuff that has yet to be refactored and organized.
*/
private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
......
......
2236 // We now tell the activity manager it is okay to run third party
2237 // code. It will call back into us once it has gotten to the state
2238 // where third party code can really run (but before it has actually
2239 // started launching the initial applications), for us to complete our
2240 // initialization.
2241 mActivityManagerService.systemReady(() -> {
......
......
2276 t.traceBegin("StartSystemUI");
2277 try {
2278 startSystemUi(context, windowManagerF);
2279 } catch (Throwable e) {
2280 reportWtf("starting System UI", e);
2281 }
2282 t.traceEnd();
......
......
}
private static void startSystemUi(Context context, WindowManagerService windowManager) {
2534 PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
2535 Intent intent = new Intent();
2536 intent.setComponent(pm.getSystemUiServiceComponent());
2537 intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
2538 //Slog.d(TAG, "Starting service: " + intent);
2539 context.startServiceAsUser(intent, UserHandle.SYSTEM);
2540 windowManager.onSystemUiStarted();
}
/frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java
public SystemUIService(
50 @Main Handler mainHandler,
51 DumpHandler dumpHandler,
52 BroadcastDispatcher broadcastDispatcher,
53 LogBufferFreezer logBufferFreezer) {
54 super();
55 mMainHandler = mainHandler;
56 mDumpHandler = dumpHandler;
57 mBroadcastDispatcher = broadcastDispatcher;
58 mLogBufferFreezer = logBufferFreezer;
59 }
60
61 @Override
62 public void onCreate() {
63 super.onCreate();
64
65 // Start all of SystemUI
66 ((SystemUIApplication) getApplication()).startServicesIfNeeded();
67
68 // Finish initializing dump logic
69 mLogBufferFreezer.attach(mBroadcastDispatcher);
70
71 // For debugging RescueParty
72 if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) {
73 throw new RuntimeException();
74 }
75
76 if (Build.IS_DEBUGGABLE) {
77 // b/71353150 - looking for leaked binder proxies
78 BinderInternal.nSetBinderProxyCountEnabled(true);
79 BinderInternal.nSetBinderProxyCountWatermarks(1000,900);
80 BinderInternal.setBinderProxyCountCallback(
81 new BinderInternal.BinderProxyLimitListener() {
82 @Override
83 public void onLimitReached(int uid) {
84 Slog.w(SystemUIApplication.TAG,
85 "uid " + uid + " sent too many Binder proxies to uid "
86 + Process.myUid());
87 }
88 }, mMainHandler);
89 }
90
91 // Bind the dump service so we can dump extra info during a bug report
92 startServiceAsUser(
93 new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
94 UserHandle.SYSTEM);
}
/**
* 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() {
142 String[] names = SystemUIFactory.getInstance().getSystemUIServiceComponents(getResources());
143 startServicesIfNeeded(/* metricsPrefix= */ "StartServices", names);
}
SystemUI 要启动的所有服务都是在数组 config_systemUIServiceComponents
中定义
127 /** Returns the list of system UI components that should be started. */
128 public String[] getSystemUIServiceComponents(Resources resources) {
129 return resources.getStringArray(R.array.config_systemUIServiceComponents);
130 }
/frameworks/base/packages/SystemUI/res/values/config.xml
302 <!-- SystemUI Services: The classes of the stuff to start. -->
303 <string-array name="config_systemUIServiceComponents" translatable="false">
304 <item>com.android.systemui.util.NotificationChannels</item>
305 <item>com.android.systemui.keyguard.KeyguardViewMediator</item>
306 <item>com.android.systemui.recents.Recents</item>
307 <item>com.android.systemui.volume.VolumeUI</item>
308 <item>com.android.systemui.stackdivider.Divider</item>
309 <item>com.android.systemui.statusbar.phone.StatusBar</item>
310 <item>com.android.systemui.usb.StorageNotification</item>
311 <item>com.android.sys