What is Android FrameWork, please introduce it?

What is Framework

Framework means "framework" in Chinese. In software development, it usually refers to the development framework. It is above the kernel layer in a system and provides interfaces for top-level applications. It is designed to help developers quickly develop top-level applications without caring about the system. The operating mechanism of the kernel, usually the Framework will hide the main function and other necessary components of the application, and developers only need to focus on the realization of the function code.

Android Framework

The Android Framework is built between the top-level application and the C/C++ library, and mainly consists of three parts: server, client, and Linux driver. Their main contents are shown in the figure below:

The running process of the APK program

The running process of the APK program is roughly shown in the figure below:

What needs to be emphasized is that ActivityThread is a class, the thread where the instance is located is the UI main thread, and the main method is in the ActivityThread class, which is the entry point of the Android application. The prepareMainLooper() method called before the ActivityThread object is created will instantiate a Looper object, and the Looper object will create a message queue. After calling the loop() method, the UI thread will enter the message loop body, continuously extract and process messages from the message queue . The execution process of ActivityThread does not actively create an Activity, but creates an ApplicationThread Binder to listen to the IPC calls from the remote AmS, and only starts to create a main Activity when receiving the Create Activity message. The specific process of creating an Activity is as follows:

It is worth noting that the W class inherits the Binder class, which is responsible for receiving the IPC call from WmS and sending the message to DectorView. If DectorView does not process it, it will pass it to PhoneWindow. If PhoneWindow does not process it, it will continue to pass it to Activity. Activity passes Handler to handle this message.

The summary is as follows: An Android application will create a total of three threads at the beginning of its operation: ActivityThread, ApplicationThread, W. Among them, ActivityThread is a UI thread, which continuously extracts and processes messages by binding a Looper. Both ApplicationThread and W are Binder classes, responsible for communicating with remote servers. ApplicationThread is created before the creation of the main Activity, and is responsible for monitoring the creation of Activity messages from AmS. After the Activity is created, W is responsible for listening to the message sent by WmS and passing the message to the Activity.

Service-Terminal

The design of the server side is to provide a global service for many top-level applications running on the Android machine. It is mainly composed of WmS and AmS. WmS is mainly responsible for monitoring and processing window-related events (such as monitoring user clicks and gestures), and AmS is mainly responsible for Manage Activity (such as creating Activity). When the user triggers an event on the Android machine, the server will first obtain the event, and if it is found that the event belongs to a running application, it will be sent to the application for processing using the Binder mechanism.

WmS mainly consists of two classes: KeyQ class and InputDispatcherThread class. These two create a thread respectively. The KeyQ class is responsible for continuously storing user messages in the QueueEvent message queue, and InputDispatcherThread is responsible for continuously taking out messages from QueueEvent for processing or distributing them to corresponding applications.

There are many knowledge points like Android Framework, such as:

  1. Activity life cycle: manage the creation, destruction, suspension, recovery and other states of Activity in the Android application to ensure that the application can correctly respond to user operations.
  2. Fragment: Allows multiple UI component layouts to be combined in one Activity, supporting flexible UI layouts.
  3. Service: Allows long-running tasks or operations to be performed in the background, such as playing music, checking email, etc.
  4. BroadcastReceiver: monitors system broadcasts and custom broadcasts, and is responsible for receiving and processing when broadcast messages are sent.
  5. ContentProvider: manages the data in the application, provides data storage and access services, and realizes the sharing of multiple application data.
  6. Intent: Pass messages and data between applications, start other application components, such as Activity, Service and BroadcastReceiver.
  7. AndroidManifest.xml file: stores the basic information and configuration of the application, including the name, version, permissions, etc. of the application.
  8. R.java file: A class automatically generated by Android for accessing resource identifiers in the application, such as layouts, strings, images, etc.
  9. Rights Management: Ensures apps can only access the data and system functions they are authorized to access, preventing apps from damaging or abusing the device.
  10. System services: Provide various shared system-level functions and services, such as network access services, notification prompt services, storage management services, etc.
  11. View and ViewGroup: The basic unit of UI controls in Android, used to build the application interface and user interaction.
  12. State preservation and restoration: Responsible for saving and restoring the state and data of the application when the application is suspended or resumed.
  13. Resource management: Manage application resources, such as pictures, layouts, strings, etc., to ensure that resource files can be dynamically loaded, modified, and unloaded.
  14. Event processing: handle various user input events, such as touch screen, key events, etc., and respond to user operations.
  15. Multi-threaded programming: Allow applications to perform tasks in multiple threads, make full use of hardware resources, and improve the performance and response speed of applications.
  16. Security management: Ensure that applications can run normally and protect users' data and devices from external threats and attacks.
  17. Animations: increase user experience and visibility, making applications more lively and engaging.
  18. Custom View: Extend the UI functionality of the application to achieve complex UI effects and fluency.
  19. Notifications and Push: Provide notifications and push messages to users to improve users' attention to the application and use experience.
  20. Debugging and Testing: Ensure application stability and correctness, and reduce the risk of application problems.
  21. ……

So in order to help everyone better understand the knowledge points in the Android Framework framework, here is a large amount of material to consult, and the Android Framework core knowledge points manual has been sorted out, which records: Handler, Binder, AMS, WMS, PMS, Event distribution mechanism, UI drawing... etc., almost all the knowledge points related to Framework are recorded in the book

"Framework Core Knowledge Point Summary Manual" :https://qr18.cn/AQpN4J

Part of the implementation principle of the Handler mechanism:
1. Macro-theoretical analysis and Message source code analysis
2. MessageQueue source code analysis
3. Looper source code analysis
4. Handler source code analysis
5. Summary

Binder principle:
1. Knowledge points that must be understood before learning Binder
2. Binder mechanism in ServiceManager
3. System service registration process
4. ServiceManager startup process
5. System service acquisition process
6. Java Binder initialization
7. Java The registration process of system services in Binder

Zygote :

  1. The startup process of the Android system and the startup process of Zygote
  2. The startup process of the application process

AMS source code analysis:

  1. Activity life cycle management
  2. onActivityResult execution process
  3. Detailed Explanation of Activity Stack Management in AMS

In-depth PMS source code:

1. PMS startup process and execution process
2. APK installation and uninstallation source code analysis
3. Intent-filter matching structure in PMS

WMS:
1. The birth of WMS
2. The important members of WMS and the addition process of Window
3. The deletion process of Window

"Android Framework Study Manual":https://qr18.cn/AQpN4J

  1. Boot Init process
  2. Start the Zygote process at boot
  3. Start the SystemServer process at boot
  4. Binder driver
  5. AMS startup process
  6. The startup process of the PMS
  7. Launcher's startup process
  8. The four major components of Android
  9. Android system service - distribution process of Input event
  10. Android underlying rendering-screen refresh mechanism source code analysis
  11. Android source code analysis in practice

Guess you like

Origin blog.csdn.net/weixin_61845324/article/details/130071395