WindowManagerService(WMS) WindowManagerService is an important service in the Android system, which is responsible for managing the display and layout of windows. It is the window manager in the Android system, responsible for handling operations such as creating, displaying, hiding, moving, and resizing application windows. Key features include: - Window Management: WindowManagerService is responsible for managing the creation, display, and destruction of all application windows. It interacts with applications and window managers to implement functions such as window hierarchy management, window display order, and window layout.
- Window layout: WindowManagerService is responsible for calculating the position and size of the window, as well as the hierarchical relationship of the window. It places the window in the correct position based on the window's properties and layout parameters, and ensures that the overlap and occlusion relationship between windows is correct.
- Window interaction: WindowManagerService is responsible for handling user interaction with windows, such as clicking, sliding, zooming, etc. It passes the user's operation to the corresponding window by interacting with the processors of touch events and input events.
- Window animation: WindowManagerService supports window animation effects, such as window opening, closing, switching, etc. It interacts with the animation processor to achieve smooth transition and dynamic effects of the window.
WindowManagerService is an important service in the Android system, responsible for managing the display and layout of windows, and implementing functions such as window creation, display, hiding, moving, and resizing. It is one of the core components of the window manager in the Android system. Android Window Android Window is an important concept in the Android system, which represents the window interface of an application. Each Android application runs in an independent window, which can contain the user interface and interactive elements of the application. Window provides a series of methods and properties for managing the appearance and behavior of the window. Through the Window object, developers can set the window's title, background, size, position and other properties, and can also handle window life cycle events such as creation, destruction, suspension and resumption. In the development of Android applications, WindowManager is usually used to manage the creation and display of windows. WindowManager is a system service in the Android system, responsible for managing the display and layout of all windows. Developers can use WindowManager to create and manage application windows, including setting the window type, position, size, etc. Window is the window interface of Android application, which manages the appearance and behavior of the window through Window object and WindowManager. It is an important part of the interaction between Android application and user. Activity, AMS, WMS, IMS relationship - Activity is one of the basic components of Android applications, used to display the user interface and handle user interaction. Each Activity is managed by ActivityManagerService.
- ActivityManagerService (AMS) is one of the core services of the Android system, responsible for managing the life cycle and task stack of applications. It can start, stop, destroy and switch activities, and is responsible for handling communication and interaction between activities.
- WindowManagerService (WMS) is another core service of the Android system, responsible for managing the display of windows and interfaces. It is responsible for drawing the interface of the Activity and handling user touch events, key events, etc. WindowManagerService works closely with ActivityManagerService to ensure that the Activity interface is displayed correctly and responds to user operations.
- InputManagerService (IMS) is the input management service of the Android system, which is responsible for processing user input events, such as touch events, key events, etc. It passes the user's input events to the currently active window so that the corresponding Activity can process them.
There is a close collaborative relationship between Activity, ActivityManagerService, WindowManagerService and InputManagerService, which jointly implement functions such as interface display, user interaction and input event processing of Android applications. Activity,Window,View,WMS relationship - Activity: Activity is a component in an Android application that provides a user interface and interaction. Each Activity has a corresponding window.
- Window: Window is an abstract concept of Activity, which is used to carry and manage the display of the interface. Each Activity has a Window object, which is used to display the layout of the Activity and handle user input events.
- View: View is the basic UI component in Android, used to build the user interface. Each Window can contain multiple Views to display different UI elements, such as buttons, text boxes, etc.
- WindowManagerService: WindowManagerService is a service in the Android system that manages and controls the display and interaction of windows. It is responsible for operations such as window creation, display, hiding, and moving, and handles user input events.
Activity displays the interface through Window. Window contains multiple Views for building interface elements, and WindowManagerService is responsible for managing and controlling the display and interaction of the window. Activity, AMS, WMS data structure relationship - Activity: Activity is a basic component in Android applications, used to display the user interface and handle user interactions. It is used to manage the life cycle of Activity and handle related events. Activities can communicate and jump between each other through Intent.
- ActivityManagerService: ActivityManagerService is a system service in the Android system, responsible for managing and scheduling the application's activities. It maintains an activity stack to manage the launch, switch, and destroy of activities. ActivityManagerService is also responsible for handling system-level tasks such as process management and memory management.
- WindowManagerService: WindowManagerService is another system service in the Android system, responsible for managing and displaying application windows. It maintains a window stack to manage the display order and hierarchical relationship of windows. WindowManagerService is also responsible for handling user interface event distribution, window layout and drawing, and other operations.
In terms of data structure, both ActivityManagerService and WindowManagerService are service components in the Android system, and they communicate with other components through the Binder mechanism. ActivityManagerService maintains some data structures, such as Activity stack and process list, to manage and schedule the running of Activity. WindowManagerService maintains some data structures, such as window stack and window list, to manage and display application windows. WMS startup process - When the system starts, the init process starts the Zygote process, and the Zygote process forks the SystemServer process.
- The SystemServer process creates a WindowManagerService instance during startup and registers it with the system service.
- The initialization work of WindowManagerService mainly includes creating a DisplayManagerService instance, creating a PolicyManager instance, initializing WindowManagerPolicy, etc.
- WindowManagerService monitors the system's input events, including touch events, key events, etc.
- When a new application is started, WindowManagerService creates a corresponding Window object and adds it to the window list.
- WindowManagerService determines how and where to display the window based on the application's window type and properties.
- WindowManagerService will adjust the size, position and hierarchy of the window according to user operations.
- WindowManagerService is also responsible for handling window animation effects, window focus management, window screenshots and other functions.
Activity adds Window process - Call the setContentView() method: In the onCreate() method of the Activity, the setContentView() method is usually called to set the layout file of the Activity. This method parses the layout file into a View object and uses it as the content view of the Activity.
- Create a Window object: In the attach() method of Activity, a Window object is created. Window is an abstract concept that represents a visible window used to carry the content view of Activity.
- Add the content view to the Window: In the attach() method of the Activity, the content view is added to the Window. In this way, the content view will be displayed on the screen.
- Execute the Window drawing process: In the onResume() method of the Activity, the Window drawing process is executed. This process includes measuring, laying out, and drawing content views, and finally displaying the content on the screen.
The process of adding a window to an activity can be simplified into the following steps: call the setContentView() method -> create a window object -> add the content view to the window -> execute the drawing process of the window. In this way, the process of adding a window to the activity is completed. WMS layer z-order calculation process - First, WindowManagerService divides all windows into different layers according to the properties of the window (such as window type, visibility, etc.).
- Then, the windows in each layer are sorted according to their z-order values. The larger the z-order value, the higher the position of the window in the layer.
- After sorting, WindowManagerService will determine the final z-order value of the window based on the z-order value of each window and the order of the layers. Specifically, the larger the z-order value of a window in the same layer, the higher the position of the window in the entire window stack.
- Finally, WindowManagerService will determine the display order of the windows based on the final z-order values of the windows. Windows with larger z-order values will be placed above windows with smaller z-order values, thus achieving a stacking effect of windows.
In summary, the layer z-order calculation process of WindowManagerService is to determine the final z-order value of the window based on the window's properties and z-order value, and determine the display order of the windows based on the final z-order value. |