Android 5.1 _ SystemUI detailed analysis of the startup process, android5.1systemui
Preface:Getting started with Android, for the SystemUI startup process, refer to many posts on the Internet, most of which are Android2.3 and Android4.0 ICS posts. They are also very detailed, but for Android, some details are not mentioned. As a result, I wrote my own experiences on the SystemUI Startup Process of Android5.1 based on my posts.
Because the Startup Process of SystemUI is designed with many things, it is impossible to analyze all the details in place at the moment. In view of the shortcomings in the post, you are welcome to stamp them, then make a good learning and correction.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If the status bar needs real-time feedback on the system status, it will survive in the system. In android, only services are running in the system. In this case, the status bar is a process that runs permanently.Service, It isSystem Service.
When the system services of ActivityManager are started in AndroidSystemServerWill startSystemUIService(That is, the status bar service), which runs the status bar service in the system process for a long time.
Path of the code of the status bar in the Android source code: \ frameworks \ base \ package \ SystemUI
Next, let's take a look at the class structure of SystemUI:
From the above class diagram, we can see that:
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(1) The State core class is StatuBar, which is an abstract class. Its start () method defines the specific steps when the status bar starts.
// This start () method inherits from SystemUI. In the figure, PhoneStatusBar inherits BaseStatusBar and SystemUI.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(2) BaseStatusBar inherits from SystemUI, SystemUI is called by SystemUIService, and SystemUIService inherits services, so StatuBar is also a Service.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(3) BaseStatusBar implements CommandQueue. callbacks interface, you can also find that CommandQueue inherits from IStatusBar. stub remote interface, while IStatusBar. the methods of the Stub interface are implemented through the Callbacks interface of CommandQueue. Therefore, BaseStatusBar is also an IStatusBar. implementation class of the stub remote interface.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(4) If StatuBar is an abstract class, how can we implement the methods in the IStatusBar. stub interface? It is very simple. We can use two sub-classes of StatuBar: PhoneStatusBar and TabletStatusBar.
// PhoneStatusBar: Mobile Phone status bar operation type TabletStatusBar: tablet status bar Operation Type
Composition of SystemUI:
· Phone: StatusBar status bar + NavigationBar navigation bar
· Tablet/TV: CombinedBar (including StatusBar and NavigationBar)
// For different devices, the composition of SystemUI is also different.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Next, let's take a look at how SystemUI is started and give the sequence diagram:
Bytes ------------------------------------------------------------------------------------------Process AnalysisBytes ------------------------------------------------------------------------------------------
(1) After the kernel is started, run init --> ServiceManager --> Zygote --> SystemServer (this is only a process for starting Android, and no details need to be tangle, details will be analyzed later ).
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(2) Start SystemUIService through the startSystemUi () method in SystemServer.
// Source Code address:./services/java/com/android/server/SystemServer. java
Using context. startServiceAsUser --> call ContextImpl. java --------------------------------------------------------------
---------------------------------------------------------------------------------- Jump to startServiceCommon restart ------------------------------------------------------------------------------------
ActivityManagerNative. startService () in this program starts the SystemUIService service.
// For the above Code, you only need to have a brief understanding of the call process, without specific analysis
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(3) In the source code, we find that SystemServer initializes the Java layer service in the Android system:
// There are a lot of services at the Java layer. Here we only list some of them. You don't have to worry about the details. I will analyze them later.
These services can be added to ServiceManager management through the addService () method of ServiceManager.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(4) Let's track SystemUIService and observe the onCreate () method.
· OnCreate () ----> start PhoneStatusBar by default --> call the start () method
// StartServicesIfNeeded () ---> call SystemUIApplication. java ---> start many sub-threads (services)
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(5) We track the super. start () method in PhoneStatusBar and enter its parent class:
· Call the start () method ----> call super. start () ----> BaseStatusBar. java class
// Submit the specific startup steps of the status bar to start () of the parent class --> handled by BaseStatusBar. java class
// The operation on the status bar is implemented by the corresponding status bar implementation class.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(6)Track super. start () to enter BaseStatusBar. java, and analyze the start () method:
// The following program is PhoneStatusBar. java
Start () ---> createAndAddWindows () ---> makeStatusBarView --> PhoneStatusBar. java
// MakeStatusBarView is an abstract method implemented by the sub-class PhoneStatusBar.
Next we will go back to PhoneStatusBar to observe the program:
We can find that the returned object is PhoneStatusBarView, and PhoneStatusBarView is the core of StatusBar, responsible for icons and ticker.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
(7) Start PowerUI:Some tips for handling Power status are concentrated --> inherit SystemUI
Oncreate () of SystemUIService starts PowerUI after PhoneStatusBar is started.
// The detailed analysis of PowerUI will be analyzed later.
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------