The final step in starting your system is to launch an application called the Launcher that displays the applications you have installed on your system. During the startup process, the PackageManagerService is asked to return information about installed applications to the system. The information is encapsulated into a list of shortcut ICONS and displayed on the screen. These ICONS enable users to launch applications.

Launcher is the Android system desktop, a shortcut icon for launching applications, managing applications, and other desktop components.

Launcher Process

The entry point to start the Launcher is AMS ‘systemReady method. Called in the SystemServer startOtherServices method.

SystemReady method invokes the ActivityStackSupervisor resumeFocusedStackTopActivityLocked method, Then call ActivityStack resumeTopActivityUncheckedLocked method. ActivityStack is used to describe the Activity stack. Finally, all the way through to AMS’s Starthome Active Locked method.

In Startroom Active Locked methods the operating mode and the Action value on Elasticity are determined. The operating mode of the system is divided into three types, namely non-factory mode, low-level factory mode and advanced factory mode. The default value for Action is intent.action_main. Check whether the operation mode is low-level factory mode and Action is null. If both are true, return false.

Then call the getHomeIntent method to create the Intent for the Launcher. The getHomeIntent method creates an Intent, passes in an Action, determines whether the system is running in low-level factory mode, sets the Category of the Intent to intent.category_HOME, and returns the Intent.

It then determines whether an application with Action intent.action_main and Category intent.category_HOME is started. If it is not started, the startHomeActivityLocked method of ActivityStarter is called to start the Launcher.

The startHomeActivityLocked method puts the Launcher into the HomeStack, which is the variable defined in ActivityStackSupervisor to store the Launcher. The startActivityLocked method is then called to start the Launcher. At this point, the Launcher is ready to launch.

The application Launcher icon display process

A lot of work goes into starting the Launcher, so let’s start with Laucher’s onCreate method.

The LauncherAppState instance is retrieved in the onCreate method, and its setLauncher method is called to pass in the Launcher object. In the setLauncher method, the incoming Launcher instance is wrapped as a weak reference.

The LauncherModel’s startLoader method is then called. Create a HandlerThread and Handler in this method and pass the Looper of the HandlerThread to this Handler. The purpose of this Handler is to send messages to the HandlerThread. Then create a LoaderTask and pass it through a Handler to the HandlerThread.

LoaderTask implements the Runnable interface and calls the Run method when a message described by LoaderTask is processed. LoaderTask is an internal class of LauncherModel.

The Launcher displays an application in the form of a workspace. Each workspace describes an abstract desktop consisting of n screens, each of which is divided into n cells, each of which is used to display an application icon.

The loadWorkspace and bingdWorkSpace methods are called in the run method to load and bind workspace information. The loadAllApps method is then called to load the information about the installed applications on the system. Finally, we call the bindAllApplications method of the Launcher.

The method calls the setApps method of the mAppsView of type AllAppsContainerView, passing in the list apps containing the application information. Internally, you set apps to mApps, which is a AlphabeticalAppsList object of type. And then the method goes to the onFinishInflate method of AllAppsContainerView. This method is called after the AllAppsContainerView has loaded the XML layout, gets the mAppsRecyclerView in the onFinishInflate method, sets the mApps in it, and sets the Adapter so that the application is displayed on the screen.

The whole process of getting here to the Launcher is over.