Android system important component WMS

WMS is the window management subsystem of the Android system, responsible for managing all windows of the Android application. One of the main responsibilities of WMS is to display the application window on the screen and handle user input events.

The working principle of WMS is that for each application window, WMS will create a Window object for it, and maintain a Window list to manage all Window objects. Each Window object has a corresponding Surface object for rendering graphics to the screen.

When processing window switching, WMS will schedule according to the priority of the application and the window situation on the current screen. WMS is also responsible for handling system-level windows, such as the status bar, notification bar, and virtual buttons.

For developers, WMS has a certain impact on the design and implementation of Android applications. For example, when designing a multi-window application, one should consider how to interact with the WMS for a better user experience. At the same time, the understanding of WMS also helps to better understand the working principle of the Android system, so as to better debug and solve problems.

1. Principle of Android WMS

Android Window Manager Service is an important service running in the system process, responsible for managing and controlling the position, size, hierarchical relationship, animation and interaction of all windows in the Android system. Window Manager Service receives and processes window requests sent by applications to the system, and then arranges windows on the screen according to policies and rules.

Its main workflow is as follows:

  1. Receive application window requests: When an application program requests the system to create, delete or modify windows, the Window Manager Service will receive these window requests and save them in a window list.

  2. Manage the position, size and hierarchical relationship of windows: Window Manager Service will manage the position, size and hierarchical relationship of all windows. In this way, it ensures that windows do not overlap, but are laid out with priority and weight, allowing all applications to use screen real estate more efficiently.

  3. Handle the user's window interaction: At the same time, the Window Manager Service can also respond to the user's various window interaction behaviors, such as touch, scroll, zoom, swipe, etc., so as to send correct events and messages to the application.

  4. Control the animation effect of the window: Window Manager Service can handle the animation effect of the window, such as the transition effect when the application starts, to ensure the smooth animation effect of the user interface.

  5. Optimize operating efficiency: In order to ensure the smoothness and efficiency of the system, Window Manager Service will optimize the display and rendering of all windows, and minimize unnecessary window operations to improve the operating speed of the system.

In general, Android Window Manager Service is a very important system service, which is responsible for managing and controlling the layout and interaction of all windows, and also plays a vital role in user experience and system efficiency.

Two, Android WMS code analysis

WMS (Window Manager Service) is a very important service in the Android system. It is responsible for managing the entire window system, including window creation, destruction, movement, and hierarchical relationships. The following is the core code analysis of WMS:

  1. WindowManagerService.java

This file is the main implementation of WindowManagerService, which includes the main logic implementation of WMS, such as window creation, drawing, updating, response to events, etc., and also includes the management of input devices, touch events, keyboard input, etc.

  1. WindowState.java

This file represents the state and properties of the window, which contains information such as the position, size, and visibility of the window, and is responsible for displaying and hiding the window.

  1. DisplayContent.java

This file is the manager of the content displayed on the screen. It contains multiple Display objects. Each Display manages its corresponding windows on the screen, and performs window addition, deletion and update operations as needed.

  1. WindowManagerGlobal.java

This file mainly provides the interface for external access of WMS and related configuration information.

  1. InputMonitor.java

This file is mainly responsible for monitoring input events, including touch events, keyboard events, mouse events, etc., and is used to pass input events to corresponding windows.

Summary:
WMS is a very core service in the Android system. Its main responsibility is to manage the entire window system, including the creation, destruction, movement and hierarchical relationship of windows. The WMS code contains multiple classes, among which WindowManagerService.java is the main logic implementation, while WindowState.java represents the state and properties of the window.

3. Common methods of Android WMS

WMS (Window Manager Service) is one of the core components for window management and display in the Android system. It controls the creation, destruction, position, size, Z-axis order, display, and hiding of windows, and is responsible for handling user input events.

Here are some common WMS methods and their brief explanations:

  1. addWindow(LayouParams): Add a window to the window manager. LayoutParam is a parameter that defines the layout of the window.

  2. removeWindow(): Removes a window that has been added to the window manager.

  3. updateWindowLayout(): Update window layout parameters.

  4. moveWindow(): Move the added window to a new location.

  5. setFocusedWindow(): Set the current focus window.

  6. injectPointerEvent(): Inject the touch event into the specified window.

  7. setInputMethodWindowVisible(): Show or hide the input method window.

  8. freezeRotation(): Stops the screen rotation.

  9. thawRotation(): Allows screen rotation.

  10. setAnimationScale(): Set the scale of window animation, for debugging and testing.

  11. updateWindow - update the display content of a window

  12. performLayoutAndPlaceSurfaces - perform layout and drawing on all windows

  13. handleTapOutsideTask - handles user taps outside an inactive window

The above are commonly used WMS methods. Understanding these methods can help developers better understand the mechanism of Android window management.

Guess you like

Origin blog.csdn.net/weixin_44008788/article/details/130017927