We know that system Mui is a system-level application and will start during boot-up. Specifically, it is started by the startOther Service () method in the System Server process.
startOtherService(){ ... startSystemUi(context,windowManagerf); ... }
In the startSystemUi() method, the operation to start the SystemUIService service is done.
static final void startSystemUi()(Context context ,WMS,wm){ Intent intent = new Intent(); intent.setComponent(new ComponentName("com.android.systemui","com.android.systemui.SystemService")); intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING); context.startServiceAsUser(intent,UserHandle.SYSTEM); wm.onSystemUiStarted();
It's worth noting that the startOther Service () method has not been completed yet. So for the time being, ACTION_BOOT_COMPLETE broadcasting will not be sent, which is sent in finishBooting() in AMS. (The broadcast is monitored in our System UI Service to determine whether the system is booted or not.)
Back in the System UI, we will go into the System UI Service service and call it in the onCreate() method.
(SystemUIApplication)getApplication()).startServicesIfNeeded();
This is processed in System UI Application. As for why startService() goes to Service's onCreate() method, a special article will be devoted to service startup (similar to Activity startup). gityuan The blog has special explanations on the four major components to start up, which will not be discussed here for the time being.
For SystemUI Application, let's first look at the onCreate() method (the onCreate() method has been executed by SystemUI Application before getApplication(), specifically, the onCreate() method in the application of the SystemUI process comes up when the SystemUI process starts.
setTheme(R.style.systemui_theme); SystemUIFactory.createFromConfig(this); if(Process.myUserHandle().equals(UserHandle.SYSTEM)){ ... //Register ACTION_BOOT_COMPLATETED Broadcast IntentFilter filter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED); regitsterReceiver(new BroadCastReceiver()){ public void onReceive(Context context,Intent intent){ if(mBootCompleted) return;//If the system is up and running, return directly. unregisterReceiver(this); mBootCompleted = true; //If service is turned on, onBootCompleted is executed if(mServicesStarted){ for(;;){ mServices[i].onBootCompleted(); } } } },filter); }
The code in onRecevie() above is executed after the system has been started, and then look at the previous code executed in System UI Service.
private void startServiceIfNeeded(class<?>[] services){ ... for(;;){ Obtain relevant service service instances by reflection mServices[i].start(); // start service, StatusBar status bar service corresponds to System Bars } ... mServiceStarted = true; }
In this way, the process goes to the start() method in SystemBars.
createStatusBarFromConfig();
This method retrieves the StatusBar instance by reflection again.
private SystemUI mStatusBar; cls = mContext.getClassLoader().loadClass("com.android.systemui.statusbar.phone.StatusBar"); mStatusBar = (SystemUI)cls.newInstance();//StatusBar inherits from System UI, reflects and generates StatusBar-type objects, and refers to System UI-type references.
Here, it should be noted that the SystemBars and StatusBar classes are inherited from the SystemUI. The former is used to interact with the SystemUI Application when the system Mui process starts, and contains a SystemUI attribute to point to a StatusBar object and start() the object. Summarize the role of SystemBars
- Get SystemBars instance by reflection in SystemUI Application
- Obtain StatusBar instance by reflection
- start StatusBar instance, enter the status bar
After all the above preparations are completed, the next step is to load our status bar, starting with the StatusBar.start() method.
//1. Instantiate the control class of the shortcut panel to notify data initialization mXXXController = Dependency.get(xxx); mNotificationData = new NotificationData(); //2. Access to System Services mWindowManagerService = ... mDevicePolicyManager = ... mPowerManager = ... //3. Register a series of ContentObserver s mContext.getContentResolver().registerContentObserver(...); //4. Get the Status Bar Manager Service mBarService = IStatusBarService.Stub.asInterface(SM.getService(string)); //5. Get the CommandQueue instance and register it as a parameter in mBarService to interact with StatusBarManagerService mCommandQueue = ... mBarService.registerStatusBar(mCommandQueue,,,,); //6. Create Status Bar window createAndAddWindows(); //7. Register Notification Listener Service mNotificationListenerService.registerAsSystemService(,,,); //8. A series of radio monitoring. ... //9. Lock screen related initialization ...
over