Android GWES window system

Source: http://www.verydemo.com/demo_c131_i148388.html

1. Basic Architecture Principles

Android's window management is C/S mode. The main View is added to WindowManager, and WM uses WindowState to correspond to this main View.

 

 

Client joins window to WindowManager through WindowSession. A complete window concept spans View, ViewRoot, and WindowManager Service.


 

The Activity of the client side establishes a dialogue with the WindowManager through the Session session, and the WindowManager accesses the Client through the IWindow interface, transmits the message to the client side, and transmits the message to the processing function OnXXX through the message distribution channel.

2. Client

2.1 View

The really important concept in Activity is View. The following is Google's official definition of View:

....................................................................

rectangular area on the screen and isresponsible for drawing and event handling. View is the baseclass for widget,which are used to create interactive UI components (buttons, text

fields, etc.). The ViewGroup subclass isthe base class for layouts, which are invisible containers that hold otherViews (or other ViewGroups)and define their layout properties.

The composition of the client:


 

When the Activity is in performLaunchActivity, it will use Activity.attach() to create a PhoneWindow main window. handleResumeActivity really wants to start an Activity

When adding the PhoneWindow main window to the WindowManager, of course, not the main window itself, but the DecorView of the main window is added to the WindowManager. The abstract concept of the real Window core exists in View, ViewRoot, WindowState in WindowManger. The main View is the Top-Level View of the window. The main View and View want to be right, and the main View is attached to the main window. The general View exists in the main View.

View, GroupView, DecorView, and ViewRoot all exist on the client side, and only the concept of WindowState exists on the Window Manager Service side.

DecorView is actually a ViewGroup. DecorView is Top-LevelView.View, and the member variable mParent of View is used to manage the superior relationship of View. ViewGroup builds focus management and an array of child View nodes. The direct relationship network of View in Android is constructed through mParent of View and mChildren of ViewGroup.


 

2.2 Focus Path

Foucs Path is the route passed by KeyEvent. The KeyEvent is passed to the focus View through the View's focus record relationship in the main loop. For example, in the figure below, View22 is the focus. We find the final path formed from the topmost View through the relationship chain of mFcous, which is the Focus Path.


 

2.3 ViewRoot,Window Manager Proxy

The core of ViewRoot and Window Manager is IWindowSession and IWindow. ViewRoot via

IWindowSession adds a window to the WindowManager. And IWindow is the channel through which Window Manager distributes messages to Client ViewRoot. Use the AIDL interface for interprocess communication.


 

 

ViewRoot establishes the bridge between the main View and WindowsManger communication. ViewRoot is essentially a Handler. The basic function of Handler is to handle callbacks and send messages.

Activity uses getSystemService to obtain WindowManagerImpl and creates a

An instance of WindowManagerImpl, a proxy for the WindowManager service:

wm=(WindowManagerImpl)context.getSystemService(Context.WINDOW_SERVICE);并调用

wm.addview Add window to WMService.

In the Window Manager Proxy, the corresponding relationship table of View, Layout and ViewRoot is established. Constructing a ViewRoot will open a session and use IWindowSession to establish a session context.

 

 

 

4 Window Manager Service

The window managed by Window Manager is the Top-level window of the application.

Why should the main window be managed on the Service side? Why not put it on the Client side? main window

Put together management is to calculate the Z-order sequence, according to the state of the application to show or hide the application's window. When Android designers consider designing a window system, they first consider:

Window z-order management

Calculation of the active window, and notification of its changes

Window ownership (which app belongs to)

Input method management

Window Service generally implements the following functions:,

(1) Z-ordered maintenance function

(2) Input method management

(3)AddWindow/RemoveWindow

(4)Layerout

(5) Token management, AppToken

(6) Active window management (FocusWindow)

(7) Activity application management (FocusAPP)

(8) Transition animation

(9) System message collection thread

(11) System message distribution thread

The window object on the server side is called WindowState. WindowState has a member variable called mClient to record the client IWindow instance, IWindow is the bridge between Service and View. A mWindow array is maintained in the Service, and this mWindow is the Z-order array of Window. mWindowMap is used to record <Client: Binder, WindowState object>.

(1) How is the FocusWindow active window calculated?

The basic principle is to search (FousActivity) and find the main window belonging to the FousActivity (AppToken) in the same Z-Order sequence. This window is the calculated Focus Window.

(2) Why propose the concept of Token?

How to identify that the window belongs to an Activity, Andoid designers put forward the concept of AppToken. Description of AppToken in essence: <Token: IBinder, allWindows>, find allWindows belonging to this Token through Token. Show and hide all windows of the application using Token.

(3) System message collection and processing

Service's system message collection mode and its distribution mode. The service uses keyq as a dedicated message queue.

The system has two threads: the KeyQ thread, which polls the device through the Navite function readEvent, and places the read results in the KeyQ queue. The system dispatcher waits on the KeyQ message queue. Once the message is obtained from the message queue, it will be delivered to the client through the dispatch function through mClient.

 


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326566718&siteId=291194637