Android boot process

1, Android startup overview

       The Android system startup can be basically divided into three stages: Bootloader startup, linux startup, and Android startup.

1.1, Bootloader starts     

       The system boots the bootloader (bootable/bootloader/* u-boot/*), after power-on, the CPU executes the bootloader program first, starts the system normally, and loads the boot.img, which contains the kernel.

       Source code: bootable/bootloader/* , Description: After power-on, the CPU will execute the bootloader program first. There are three options here:
       a: Press Camera+Power to boot to fastboot, that is, command or SD card programming mode, without loading the kernel And file system, you can do factory mode programming
       b: Boot into recovery mode by pressing Home+Power, load recovery.img, recovery.img contains kernel, basic file system, used for programming in engineering mode
       c: Press Power to start the phone, start the system normally, load boot.img, boot.img contains the kernel, the basic file system, and is used to start the phone normally (the following only analyzes the normal startup)

1.2, linux boot

         The kernel is loaded by the bootloader, the kernel is self-extracted, initialized, loaded with the built-in driver, and the startup is completed. After the kernel is started, several kernel threads are created, and then the program /sbin/init/ is loaded and executed, the init process is loaded, and the user-space is switched.

1.3, Android start

1.3.1, the init process starts

        Source code: system/core/init/*
        Configuration file: system/rootdir/init.rc
        Description: init is a user-level process started by the kernel, which is executed according to the settings in init.rc: start the service (the service here refers to linux The underlying services, such as adbd provides adb support, vold provides SD card mounting, etc.), execute commands and perform corresponding functions according to the configuration statements therein.

1.3.2, the zygote service starts

       Source code: frameworks/base/cmds/app_main.cpp, etc.
       Description: zygote is a service specified to be started in init.rc, and the command corresponding to this service is /system/bin/app_process.
       Function: establish Java Runtime, establish virtual machine; establish Socket to receive the request of ActivityManangerService for Fork application; start System Server.

1.3.3, the systemserver service starts

       Source code: frameworks/base/services/java/com/android/server/SystemServer.java
       Description: Started by zygote, android services are managed through System Manager (services here refer to services under frameworks/base/services, such as satellite positioning services , clipboard service, etc.).

1.3.4, launcher desktop starts

       Source code: ActivityManagerService.java is the entry, implemented in packages/apps/launcher*.
       Description: After the system starts successfully, SystemServer uses xxx.systemReady() to notify each service that the system is ready. The desktop program Home is created during the notification process of ActivityManagerService.systemReady(), and finally calls startHomeActivityLocked() to start the launcher.

1.3.5, lockscreen starts

       Source code: frameworks/policies/base/phone/com/android/internal/policy/impl/*lock*
       Description: After the system starts successfully, SystemServer calls wm.systemReady() to notify WindowManagerService, and then calls PhoneWindowManager, and finally displays the unlock interface through LockPatternKeyguardView. The tracking code can see that the unlock interface is not an Activity, it is just drawing to a specific layer, and its code is stored in a special location.

1.3.6, othersapp start

       Source code: frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
       Description: After the system starts successfully, SystemServer calls ActivityManagerNative.getDefault().systemReady() to notify ActivityManager that the startup is successful. ActivityManager will set the variable mBooting, Notify it to another thread that sends the broadcast android.intent.action.BOOT_COMPLETED to tell registered third-party programs to start automatically at boot.

 

 

Reprinted from: http://www.fx114.net/qa-271-90076.aspx

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326314947&siteId=291194637