android launcher startup process

 Android system startup

1, "Introduction to the Android System Startup Process"

2, "Android init process startup process"

3. "Android zygote process startup process"

4. "Android SystemServer Process Startup Process"

5. "Android launcher startup process"

6. "Detailed Explanation of Android Activity Startup Process"

Android System Development Preparation

1, "Android Source Code Download and Compilation"

2. "Android 11 source code compilation and pixel3 flashing"

3. "Android Framework Code IDE Loading and Debugging"

Android System Development Practice

1. "Android Setting Default Input Method"

2, "android framework prefabricated APK application"

3. "Detailed Explanation of Restricting Apps from Starting at the Android System Level"

4. "Android compiles the framework module separately and pushes it"

5. "Android Framework Development System Problem Analysis"

Android System Development Core Knowledge Reserve

1, "Android Compilation System - envsetup and lunch code articles"

2. "Android Compilation System - Concept"

3. "Detailed Explanation of Android Log System"

4. "Android System Handler Detailed Explanation"

5. "Android System Binder Detailed Explanation"

6. "Detailed Explanation of the Relationship between Activity, View and Window in Android"

7. "Detailed Explanation of the Android View Drawing Process"

8. "Detailed Explanation of Android Reading System Attributes"

9. "Detailed Explanation of Android Window Management Mechanism"

10. "Acquaintance with Android System"

11. "The communication method of AMS process in android notifying Zygote process fork new process"

Detailed explanation of Android core functions

1. "Android application market click to download APK installation details"

2, "Android gesture navigation (swipe from bottom to top to enter the multitasking page)"

3. "Android Gesture Analysis (Swipe left to right on the application interface to exit the application)"

4. "Detailed Explanation of Android Application Installation Process"

5, "android11 ​​installation application triggers desktop icon refresh process"

6. "Detailed Explanation of Android System Multitasking Recents"

7. "Android System Navigation Bar View Analysis"

———————————————————————————————————————————

Table of contents

1. Background introduction

Two, source code analysis


1. Background introduction

        In Android, the desktop application Launcher has evolved from Launcher to Launcher2, and now to Launcher3, Google has also made many changes.

    Launcher does not support desktop gadget animation effects. Launcher2 adds animation effects and 3D preliminary effect support. Starting from Android 4.4 (KK), Launcher uses Launcher3 by default. Launcher3 adds a transparent status bar and an overview mode, which can adjust the front and rear of pages on the workspace order, the number of screens can be dynamically managed, and the widget list and app list can be displayed separately.

  We mainly study the startup process of Launcher3 of android11.

Two, source code analysis

  Path: /frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java

public void systemReady(final Runnable goingCallback, @NonNull TimingsTraceAndSlog t) {
       //......
      if (bootingSystemUser) {
                t.traceBegin("startHomeOnAllDisplays");
                mAtmInternal.startHomeOnAllDisplays(currentUserId, "systemReady");
                t.traceEnd();
            }
    //......
}

        ActivityTaskManagerInternal is an abstract class of ActivityTaskManagerService, the current implementation is in ActivityTaskManagerService,

Path: /frameworks/base/services/core/java/com/android/server/wm/ActivityTaskManagerService.java

 @Override
        public boolean startHomeOnAllDisplays(int userId, String reason) {
            synchronized (mGlobalLock) {
                return mRootWindowContainer.startHomeOnAllDisplays(userId, reason);
            }
        }

Path: /frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java

    boolean startHomeOnAllDisplays(int userId, String reason) {
        boolean homeStarted = false;
        for (int i = getChildCount() - 1; i >= 0; i--) {
            final int displayId = getChildAt(i).mDisplayId;
            homeStarted |= startHomeOnDisplay(userId, reason, displayId);
        }
        return homeStarted;
    }

Here we will focus on explaining the window structure hierarchy.

 1. RootWindowContainer: The root window container, the root of the tree is it. By traversing through it, you can find windows on the window tree. Its child is DisplayContent.
2. DisplayContent: This class corresponds to the display screen. Android supports multiple screens, so there may be multiple 3. DisplayContent objects. The above picture only draws the structure of one object, and the structure of other objects is similar to the structure of the drawn object.
4. TaskDisplayArea: It is a child of DisplayContent, corresponding to the second layer of the window hierarchy. The second layer is the application layer, see its definition: int APPLICATION_LAYER = 2, the window of the application layer is in the second layer. The child of TaskDisplayArea is the Task class. In fact, its child type can also be TaskDisplayArea. The child of Task can be 5, ActivityRecord, or Task.
6. Tokens: It is the child of DisplayContent, and its child is WindowToken. The child of WindowToken is 7, the WindowState object. WindowState corresponds to a window. In the structure diagram, DisplayContent contains not only one Tokens, but also two. In fact, ImeContainer is also inherited from Tokens.
8. ImeContainer: It is also the child of DisplayContent, it is the container of the input method window, and its child is of type WindowToken. The child of WindowToken is the WindowState type, and the WindowState type corresponds to the input method window.
9. Task: Task, its child can be Task or ActivityRecord type.
10. ActivityRecord: It corresponds to the Activity in the application process. ActivityRecord inherits WindowToken, and its child type is WindowState.
11. WindowState: WindowState corresponds to a window.
        In the structural diagram, DisplayContent has 5 children. From top to bottom in the figure, the first one is Tokens, corresponding to window layers 0 and 1. The second is TaskDisplayArea, which corresponds to window layer 2. The third is Tokens, corresponding to window layers 3 to 14. The fourth is ImeContainer, which corresponds to window layers 15 to 16. The fifth is Tokens, corresponding to window layers 17 to 36.

        Going back to the code, startHomeOnDisplay(userId, reason, displayId) starts the launcher desktop according to the physical display screen, that is to say, android itself supports multi-screen display.

 boolean startHomeOnTaskDisplayArea(int userId, String reason, TaskDisplayArea taskDisplayArea,
            boolean allowInstrumenting, boolean fromHomeKey) {

    if (!canStartHomeOnDisplayArea(aInfo, taskDisplayArea, allowInstrumenting)) {
            return false;
        }

     mService.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason,taskDisplayArea);
}

canStartHomeOnDisplayArea detects whether the home activity supports display on multiple screens, and startHomeActivity is the one that actually starts the home activity

void startHomeActivity(Intent intent, ActivityInfo aInfo, String reason, int displayId) {
    ....
    //返回一个 ActivityStarter 对象,它负责 Activity 的启动
    //一系列 setXXX() 方法传入启动所需的各种参数,最后的 execute() 是真正的启动逻辑
    //最后执行 ActivityStarter的execute方法
    mLastHomeActivityStartResult = obtainStarter(intent, "startHomeActivity: " + reason)
            .setOutActivity(tmpOutRecord)
            .setCallingUid(0)
            .setActivityInfo(aInfo)
            .setActivityOptions(options.toBundle())
            .execute();  //参考[4.3.1]
    mLastHomeActivityStartRecord = tmpOutRecord[0];
    final ActivityDisplay display =
            mService.mRootActivityContainer.getActivityDisplay(displayId);
    final ActivityStack homeStack = display != null ? display.getHomeStack() : null;
 
    if (homeStack != null && homeStack.mInResumeTopActivity) {
        //如果home activity 处于顶层的resume activity中,则Home Activity 将被初始化,但不会被恢复(以避免递归恢复),
        //并将保持这种状态,直到有东西再次触发它。我们需要进行另一次恢复。
        mSupervisor.scheduleResumeTopActivities();
    }
}

execute is the real startup logic,

Path: /frameworks/base/services/core/java/com/android/server/wm/ActivityStarter.java

Guess you like

Origin blog.csdn.net/allen_xu_2012_new/article/details/130759962