1. What do YOU need WMS for

Window is a Window. Manager is a Manager. From SurfaceFlinger’s point of view, WM is a Layer that carries data and attributes related to the interface. From the PERSPECTIVE of WMS, WM is a WindowState that manages the state associated with the interface. Whether it’s SurfaceFlinger or WMS, they’re all trying to do a better job of managing Windows today. From a computer I/O perspective, WMS needs to do at least two things:

  • Global Window Management (Output)

    From a computer architecture perspective, “window management” is the output part, where application displays and requests are sequentially output to the physical screen or other display device with the assistance of SurfaceFlinger and WMS.

  • Global Event Management dispatch (Input)

    SurfaceFlinger only does “display” related issues, WMS also needs to take care of event input dispatch. Keyboards (out of date), touch screens (mainstream), mice (out of date), trackballs (out of date) all fall into this category

1. Window management

The WMS is the window manager, responsible for starting, adding, and deleting Windows. The size and hierarchy of Windows are also managed by WMS. The core members of window management are DisplayContent, WindowToken, and WindowState.Copy the code

2. Window animation

The use of animations for window-switching can be more window-switching, which is done by WMS's animation subsystem, which is managed by the WindowAnimator.Copy the code

3. Enter the system transfer station

Touch events are generated by touching a window. InputManagerService(IMS) processes the touch events by looking for the most appropriate window to process the touch feedback. WMS is the window manager, and it is a perfect hub for the input system.Copy the code

4. Surface management

Windows do not have drawing function, so each window needs a Surface to draw, and WMS is responsible for assigning Surface to each window.Copy the code

2. Design ideas of WMS

2.1 Overview of WMS

2.1.1 Basic PROPERTIES of WMS

WMS is a system-level service that should have the following attributes.

  • By the SystemServer startup
  • Do not exit until the system is shut down
  • Be sure to have your own restart capability in the event of a WMS crash

2.1.2 surfaceFlinger

SurfaceFlinger and WMS have many current connections

2.1.3 Application program displayed in the window

Different application Windows have a priority

2.1.4 InputManagerService

WMS is the best candidate for distributing system keystroke and touch messages

2.1.5 AMS

There is some interaction between AMS and WMS.

2.1.6 Binder communication

SurfaceFlinger, AMS and WMS communicate with each other using the Binder.

2.1.7 WMS core functions summary

  • Add and delete Windows

    When a process (general application and system application) needs a display, it can request WMS to add a window and remove it when it is no longer needed

  • Launch window

  • Window animation

  • Window size

  • Window hierarchy

  • Dispatching events

2.2 WMS startup

WMS is one of the many services in SystemServer, which can be seen in the systemServer.java source code.

2.3 Basic functions of WMS

The function of the WMS is too complex, can view IWindowManagerService. Java interface source code.

2.4 Working mode of WMS

2.4.1 Event Delivery

The WMS communicates with the wmHandlerThread and processes the event through a queue.

2.4.2 Direct Call

WSM determines whether the screen lock interface is directly implemented by WMS rather than indirectly invoked by handler.

public boolean isKeyguardLocked() {

return mPolicy.isKeyguardLocked()

}

2.5 WMS, the relationship between AMS and Activity

An activity startup process requires multiple system services, the most famous of which are AMS and WMS

2.5.1 IPC communication

2.5.1 Internal organization mode

When a new Activity is started (startActivity), it first needs to be registered with AMS — at this point, AMS internally generates an ActivityRecord of the Activity, and because the Activity is one of the four components dedicated to UI display, So, WMS logs it as well – in Windows State.

In addition to using WindowState to hold information about a “window,” WMS uses AppWindowToken to correspond to an ActivityRecord in AMS. So the three can form a very tight connection.

2.6 Window Properties