Principle Analysis of the Launcher Startup Process in the Android Framework Study Guide

foreword

Launcher is an application program used to display the installed applications in the system. During the startup process, the Launcher will request PackageManagerService to return the information of the installed applications in the system, and encapsulate the information into a list of shortcut icons to display on the system screen. In this way, the user can start the corresponding application program by clicking these shortcut icons. It has two main functions: one is to start the application program, and the other is to display and manage the shortcut icons of the application program or other desktop components.

Analyze Launcher startup

The startup entry is in the startOtherServices function of SystemServer.java, we can see that the meaning of the above comment is probably this

picture

We clicked into the systemReady method and found that a method named startHomeActivityLocked was called on line 14282

picture

We found a call to getHomeIntent in the startHomeActivityLocked method

picture

We clicked into the getHomeIntent method and found that if mFactoryTest is not FactoryTest.FACTORY_TEST_LOW_LEVEL (low-level factory mode), a Category of Intent.CATEGORY_HOME will be added

picture

Then we add Log printing to this line of ActivityManagerService.java

picture

It is found that the printed package name is com.android.settings and not launcher

picture

Then we found two Activity with android.intent.category.HOME tag in AndroidManifest.xml in settings

picture

Then we add Log printing to the onCreate method in the two Activities

picture

picture

After compiling and running, we found that the print is FallbackHome

picture

image.png

We opened FallbackHome.java and found that the code is relatively small. One of the methods is used to detect whether the real HomeActivity is found. I added a line of Toast code here to display the package name of the real HomeActivity.

picture

Then we compile the source code and run the emulator, and we find that launcher3 is displayed (ps: I changed the default launcher to launcher3 here, so launcher3 is displayed here)

picture

Guess you like

Origin blog.csdn.net/m0_70749039/article/details/130536429